diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-25 03:09:25 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-25 03:09:25 +0400 |
commit | 2043d801e88c8f56b0153f8acf0cccb554f0fa0c (patch) | |
tree | bffa8f8ea9769d092e7e75b9817b9bd4be7e6862 /source/blender/blenkernel | |
parent | 11c6abe53b77baefa09737fa8f615f5c734f4b63 (diff) |
Fix #34806: rigid body world settings were not copied with a full scene copy.
Now copying a scene will also duplicate groups that consist entirely of objects
that are duplicated with the scene. The rigid body world will then also pointers
to these new groups.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_rigidbody.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_scene.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/group.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 37 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 10 |
5 files changed, 50 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h index 75647876419..ef5b8349d60 100644 --- a/source/blender/blenkernel/BKE_rigidbody.h +++ b/source/blender/blenkernel/BKE_rigidbody.h @@ -62,6 +62,10 @@ struct RigidBodyWorld *BKE_rigidbody_create_world(struct Scene *scene); struct RigidBodyOb *BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type); struct RigidBodyCon *BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type); +/* copy */ +struct RigidBodyWorld *BKE_rigidbody_world_copy(struct RigidBodyWorld *rbw); +void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw); + /* 'validate' (i.e. make new or replace old) Physics-Engine objects */ void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld *rbw, short rebuild); void BKE_rigidbody_validate_sim_object(struct RigidBodyWorld *rbw, struct Object *ob, short rebuild); diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 9bf0991272a..1171e42cad7 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -84,6 +84,7 @@ void BKE_scene_set_background(struct Main *bmain, struct Scene *sce); struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name); struct Scene *BKE_scene_copy(struct Scene *sce, int type); +void BKE_scene_groups_relink(struct Scene *sce); void BKE_scene_unlink(struct Main *bmain, struct Scene *sce, struct Scene *newsce); struct Object *BKE_scene_camera_find(struct Scene *sc); diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index b1d0e8df754..ad0aed4691a 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -148,7 +148,7 @@ Group *BKE_group_copy(Group *group) { Group *groupn; - groupn = MEM_dupallocN(group); + groupn = BKE_libblock_copy(&group->id); BLI_duplicatelist(&groupn->gobject, &group->gobject); return groupn; diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index ca7bb542598..879ba6651c2 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -58,12 +58,13 @@ #include "BKE_animsys.h" #include "BKE_cdderivedmesh.h" #include "BKE_effect.h" +#include "BKE_global.h" #include "BKE_group.h" -#include "BKE_object.h" +#include "BKE_library.h" #include "BKE_mesh.h" +#include "BKE_object.h" #include "BKE_pointcache.h" #include "BKE_rigidbody.h" -#include "BKE_global.h" #include "BKE_utildefines.h" #include "RNA_access.h" @@ -724,6 +725,36 @@ RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) return rbw; } +RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw) +{ + RigidBodyWorld *rbwn = MEM_dupallocN(rbw); + + if (rbw->effector_weights) + rbwn->effector_weights = MEM_dupallocN(rbw->effector_weights); + if (rbwn->group) + id_us_plus(&rbwn->group->id); + if (rbwn->constraints) + id_us_plus(&rbwn->constraints->id); + + rbwn->pointcache = BKE_ptcache_copy_list(&rbwn->ptcaches, &rbw->ptcaches, FALSE); + + rbwn->objects = NULL; + rbwn->physics_world = NULL; + rbwn->numbodies = 0; + + return rbwn; +} + +void BKE_rigidbody_world_groups_relink(RigidBodyWorld *rbw) +{ + if (rbw->group && rbw->group->id.newid) + rbw->group = (Group*)rbw->group->id.newid; + if (rbw->constraints && rbw->constraints->id.newid) + rbw->constraints = (Group*)rbw->constraints->id.newid; + if (rbw->effector_weights->group && rbw->effector_weights->group->id.newid) + rbw->effector_weights->group = (Group*)rbw->effector_weights->group->id.newid; +} + /* Add rigid body settings to the specified object */ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type) { @@ -1332,6 +1363,8 @@ void BKE_rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, short re void BKE_rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, short rebuild) {} void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, short rebuild) {} struct RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) { return NULL; } +struct RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw) { return NULL; } +void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw) {} struct RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type) { return NULL; } struct RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short type) { return NULL; } struct RigidBodyWorld *BKE_rigidbody_get_world(Scene *scene) { return NULL; } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 29396a7edfe..d140dfa6a2d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -176,7 +176,9 @@ Scene *BKE_scene_copy(Scene *sce, int type) scen->obedit = NULL; scen->stats = NULL; scen->fps_info = NULL; - scen->rigidbody_world = NULL; /* RB_TODO figure out a way of copying the rigid body world */ + + if(sce->rigidbody_world) + scen->rigidbody_world = BKE_rigidbody_world_copy(sce->rigidbody_world); BLI_duplicatelist(&(scen->markers), &(sce->markers)); BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces)); @@ -295,6 +297,12 @@ Scene *BKE_scene_copy(Scene *sce, int type) return scen; } +void BKE_scene_groups_relink(Scene *sce) +{ + if (sce->rigidbody_world) + BKE_rigidbody_world_groups_relink(sce->rigidbody_world); +} + /* do not free scene itself */ void BKE_scene_free(Scene *sce) { |