diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 49 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files_link.c | 13 |
2 files changed, 52 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 1ea659b2d41..242bad163d8 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1473,16 +1473,51 @@ static bool rigidbody_add_object_to_scene(Main *bmain, Scene *scene, Object *ob) return true; } -void BKE_rigidbody_ensure_local_object(Main *bmain, Object *ob) +static bool rigidbody_add_constraint_to_scene(Main *bmain, Scene *scene, Object *ob) { - if (ob->rigidbody_object == NULL) { - return; + /* Add rigid body world and group if they don't exist for convenience */ + RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); + if (rbw == NULL) { + rbw = BKE_rigidbody_create_world(scene); + if (rbw == NULL) { + return false; + } + + BKE_rigidbody_validate_sim_world(scene, rbw, false); + scene->rigidbody_world = rbw; } - /* Add newly local object to scene. */ - for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - if (BKE_scene_object_find(scene, ob)) { - rigidbody_add_object_to_scene(bmain, scene, ob); + if (rbw->constraints == NULL) { + rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints"); + id_fake_user_set(&rbw->constraints->id); + } + + /* Add object to rigid body group. */ + BKE_collection_object_add(bmain, rbw->constraints, ob); + BKE_rigidbody_cache_reset(rbw); + + DEG_relations_tag_update(bmain); + DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE); + + return true; +} + +void BKE_rigidbody_ensure_local_object(Main *bmain, Object *ob) +{ + if (ob->rigidbody_object != NULL) { + /* Add newly local object to scene. */ + for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { + if (BKE_scene_object_find(scene, ob)) { + rigidbody_add_object_to_scene(bmain, scene, ob); + } + } + } + if (ob->rigidbody_constraint != NULL) { + /* Add newly local object to scene. */ + for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { + if (BKE_scene_object_find(scene, ob)) { + rigidbody_add_constraint_to_scene(bmain, scene, ob); + } } } } diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index a73bea31669..cf3536213d2 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -579,6 +579,16 @@ static void wm_append_loose_data_instantiate(WMLinkAppendData *lapp_data, id->tag &= ~LIB_TAG_DOIT; } + + /* Finally, add rigid body objects and constraints to current RB world(s). */ + for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) { + WMLinkAppendDataItem *item = itemlink->link; + ID *id = wm_append_loose_data_instantiate_process_check(item); + if (id == NULL || GS(id->name) != ID_OB) { + continue; + } + BKE_rigidbody_ensure_local_object(bmain, (Object *)id); + } } /** \} */ @@ -773,9 +783,6 @@ static void wm_append_do(WMLinkAppendData *lapp_data, local_appended_new_id); } - if (GS(local_appended_new_id->name) == ID_OB) { - BKE_rigidbody_ensure_local_object(bmain, (Object *)local_appended_new_id); - } if (set_fakeuser) { if (!ELEM(GS(local_appended_new_id->name), ID_OB, ID_GR)) { /* Do not set fake user on objects nor collections (instancing). */ |