Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/rigidbody_constraint.c
| Show All 31 Lines | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_rigidbody_types.h" | #include "DNA_rigidbody_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "BKE_collection.h" | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_group.h" | |||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_rigidbody.h" | #include "BKE_rigidbody.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| Show All 28 Lines | bool ED_rigidbody_constraint_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports) | ||||
| /* check that object doesn't already have a constraint */ | /* check that object doesn't already have a constraint */ | ||||
| if (ob->rigidbody_constraint) { | if (ob->rigidbody_constraint) { | ||||
| BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2); | BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2); | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* create constraint group if it doesn't already exits */ | /* create constraint group if it doesn't already exits */ | ||||
| if (rbw->constraints == NULL) { | if (rbw->constraints == NULL) { | ||||
| rbw->constraints = BKE_group_add(bmain, "RigidBodyConstraints"); | rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints"); | ||||
| } | } | ||||
| /* make rigidbody constraint settings */ | /* make rigidbody constraint settings */ | ||||
| ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type); | ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type); | ||||
| ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE; | ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE; | ||||
| /* add constraint to rigid body constraint group */ | /* add constraint to rigid body constraint group */ | ||||
| BKE_group_object_add(rbw->constraints, ob); | BKE_collection_object_add(bmain, rbw->constraints, ob); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_OB); | DEG_id_tag_update(&ob->id, OB_RECALC_OB); | ||||
| return true; | return true; | ||||
| } | } | ||||
| void ED_rigidbody_constraint_remove(Main *bmain, Scene *scene, Object *ob) | void ED_rigidbody_constraint_remove(Main *bmain, Scene *scene, Object *ob) | ||||
| { | { | ||||
| RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); | RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); | ||||
| BKE_rigidbody_remove_constraint(scene, ob); | BKE_rigidbody_remove_constraint(scene, ob); | ||||
| if (rbw) | if (rbw) | ||||
| BKE_group_object_unlink(rbw->constraints, ob); | BKE_collection_object_remove(bmain, rbw->constraints, ob, false); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_OB); | DEG_id_tag_update(&ob->id, OB_RECALC_OB); | ||||
| } | } | ||||
| /* ********************************************** */ | /* ********************************************** */ | ||||
| /* Active Object Add/Remove Operators */ | /* Active Object Add/Remove Operators */ | ||||
| ▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines | |||||