Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/rigidbody.c
| Show First 20 Lines • Show All 1,170 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw, const int flag) | RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw, const int flag) | ||||
| { | { | ||||
| RigidBodyWorld *rbw_copy = MEM_dupallocN(rbw); | RigidBodyWorld *rbw_copy = MEM_dupallocN(rbw); | ||||
| if (rbw->effector_weights) { | if (rbw->effector_weights) { | ||||
| rbw_copy->effector_weights = MEM_dupallocN(rbw->effector_weights); | rbw_copy->effector_weights = MEM_dupallocN(rbw->effector_weights); | ||||
| if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { | |||||
| id_us_plus((ID *)rbw->effector_weights->group); | |||||
| } | |||||
| } | } | ||||
| if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { | if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { | ||||
| id_us_plus((ID *)rbw_copy->group); | id_us_plus((ID *)rbw_copy->group); | ||||
| id_us_plus((ID *)rbw_copy->constraints); | id_us_plus((ID *)rbw_copy->constraints); | ||||
| } | } | ||||
| if ((flag & LIB_ID_COPY_SET_COPIED_ON_WRITE) == 0) { | if ((flag & LIB_ID_COPY_SET_COPIED_ON_WRITE) == 0) { | ||||
| /* This is a regular copy, and not a CoW copy for depsgraph evaluation. */ | /* This is a regular copy, and not a CoW copy for depsgraph evaluation. */ | ||||
| Show All 13 Lines | |||||
| { | { | ||||
| ID_NEW_REMAP(rbw->group); | ID_NEW_REMAP(rbw->group); | ||||
| ID_NEW_REMAP(rbw->constraints); | ID_NEW_REMAP(rbw->constraints); | ||||
| ID_NEW_REMAP(rbw->effector_weights->group); | ID_NEW_REMAP(rbw->effector_weights->group); | ||||
| } | } | ||||
| void BKE_rigidbody_world_id_loop(RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata) | void BKE_rigidbody_world_id_loop(RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata) | ||||
| { | { | ||||
| func(rbw, (ID **)&rbw->group, userdata, IDWALK_CB_NOP); | func(rbw, (ID **)&rbw->group, userdata, IDWALK_CB_USER); | ||||
| func(rbw, (ID **)&rbw->constraints, userdata, IDWALK_CB_NOP); | func(rbw, (ID **)&rbw->constraints, userdata, IDWALK_CB_USER); | ||||
| func(rbw, (ID **)&rbw->effector_weights->group, userdata, IDWALK_CB_NOP); | func(rbw, (ID **)&rbw->effector_weights->group, userdata, IDWALK_CB_USER); | ||||
| if (rbw->objects) { | if (rbw->objects) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < rbw->numbodies; i++) { | for (i = 0; i < rbw->numbodies; i++) { | ||||
| func(rbw, (ID **)&rbw->objects[i], userdata, IDWALK_CB_NOP); | func(rbw, (ID **)&rbw->objects[i], userdata, IDWALK_CB_NOP); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | if (rbw == NULL) { | ||||
| } | } | ||||
| BKE_rigidbody_validate_sim_world(scene, rbw, false); | BKE_rigidbody_validate_sim_world(scene, rbw, false); | ||||
| scene->rigidbody_world = rbw; | scene->rigidbody_world = rbw; | ||||
| } | } | ||||
| if (rbw->group == NULL) { | if (rbw->group == NULL) { | ||||
| rbw->group = BKE_collection_add(bmain, NULL, "RigidBodyWorld"); | rbw->group = BKE_collection_add(bmain, NULL, "RigidBodyWorld"); | ||||
| id_fake_user_set(&rbw->group->id); | id_us_plus(&rbw->group->id); | ||||
| } | } | ||||
| /* Add object to rigid body group. */ | /* Add object to rigid body group. */ | ||||
| BKE_collection_object_add(bmain, rbw->group, ob); | BKE_collection_object_add(bmain, rbw->group, ob); | ||||
| BKE_rigidbody_cache_reset(rbw); | BKE_rigidbody_cache_reset(rbw); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| DEG_id_tag_update(&rbw->group->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&rbw->group->id, ID_RECALC_COPY_ON_WRITE); | ||||
| Show All 12 Lines | if (rbw == NULL) { | ||||
| } | } | ||||
| BKE_rigidbody_validate_sim_world(scene, rbw, false); | BKE_rigidbody_validate_sim_world(scene, rbw, false); | ||||
| scene->rigidbody_world = rbw; | scene->rigidbody_world = rbw; | ||||
| } | } | ||||
| if (rbw->constraints == NULL) { | if (rbw->constraints == NULL) { | ||||
| rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints"); | rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints"); | ||||
| id_fake_user_set(&rbw->constraints->id); | id_us_plus(&rbw->constraints->id); | ||||
| } | } | ||||
| /* Add object to rigid body group. */ | /* Add object to rigid body group. */ | ||||
| BKE_collection_object_add(bmain, rbw->constraints, ob); | BKE_collection_object_add(bmain, rbw->constraints, ob); | ||||
| BKE_rigidbody_cache_reset(rbw); | BKE_rigidbody_cache_reset(rbw); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE); | ||||
| ▲ Show 20 Lines • Show All 944 Lines • Show Last 20 Lines | |||||