Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/rigidbody_constraint.c
| Show All 39 Lines | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_group.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 "DEG_depsgraph_query.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| Show All 11 Lines | if (ED_operator_object_active_editable(C)) { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| return (ob && ob->rigidbody_constraint); | return (ob && ob->rigidbody_constraint); | ||||
| } | } | ||||
| else | else | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| bool ED_rigidbody_constraint_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports) | bool ED_rigidbody_constraint_add(Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports) | ||||
| { | { | ||||
| RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); | RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); | ||||
| /* 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_group_add(bmain, "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(depsgraph, 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_group_object_add(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; | ||||
| Show All 13 Lines | |||||
| /* ********************************************** */ | /* ********************************************** */ | ||||
| /* Active Object Add/Remove Operators */ | /* Active Object Add/Remove Operators */ | ||||
| /* ************ Add Rigid Body Constraint ************** */ | /* ************ Add Rigid Body Constraint ************** */ | ||||
| static int rigidbody_con_add_exec(bContext *C, wmOperator *op) | static int rigidbody_con_add_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); | RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene); | ||||
| Object *ob = OBACT(view_layer); | Object *ob = OBACT(view_layer); | ||||
| int type = RNA_enum_get(op->ptr, "type"); | int type = RNA_enum_get(op->ptr, "type"); | ||||
| bool changed; | bool changed; | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, scene, rbw)) { | if (ELEM(NULL, scene, rbw)) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to"); | BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* apply to active object */ | /* apply to active object */ | ||||
| changed = ED_rigidbody_constraint_add(bmain, scene, ob, type, op->reports); | changed = ED_rigidbody_constraint_add(depsgraph, bmain, scene, ob, type, op->reports); | ||||
| if (changed) { | if (changed) { | ||||
| /* send updates */ | /* send updates */ | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); | WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); | ||||
| /* done */ | /* done */ | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines | |||||