Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/physics/rigidbody_constraint.c')
-rw-r--r--source/blender/editors/physics/rigidbody_constraint.c220
1 files changed, 113 insertions, 107 deletions
diff --git a/source/blender/editors/physics/rigidbody_constraint.c b/source/blender/editors/physics/rigidbody_constraint.c
index 499a1d0e2e5..2d2c90f9391 100644
--- a/source/blender/editors/physics/rigidbody_constraint.c
+++ b/source/blender/editors/physics/rigidbody_constraint.c
@@ -56,54 +56,55 @@
static bool ED_operator_rigidbody_con_active_poll(bContext *C)
{
- if (ED_operator_object_active_editable(C)) {
- Object *ob = CTX_data_active_object(C);
- return (ob && ob->rigidbody_constraint);
- }
- else
- return 0;
+ if (ED_operator_object_active_editable(C)) {
+ Object *ob = CTX_data_active_object(C);
+ return (ob && ob->rigidbody_constraint);
+ }
+ else
+ return 0;
}
-
-bool ED_rigidbody_constraint_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports)
+bool ED_rigidbody_constraint_add(
+ Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports)
{
- RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
-
- /* check that object doesn't already have a constraint */
- if (ob->rigidbody_constraint) {
- BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
- return false;
- }
- /* create constraint group if it doesn't already exits */
- if (rbw->constraints == NULL) {
- rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints");
- id_fake_user_set(&rbw->constraints->id);
- }
- /* make rigidbody constraint settings */
- ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);
-
- /* add constraint to rigid body constraint group */
- BKE_collection_object_add(bmain, rbw->constraints, ob);
-
- DEG_relations_tag_update(bmain);
- DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
- DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE);
-
- return true;
+ RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
+
+ /* check that object doesn't already have a constraint */
+ if (ob->rigidbody_constraint) {
+ BKE_reportf(
+ reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
+ return false;
+ }
+ /* create constraint group if it doesn't already exits */
+ if (rbw->constraints == NULL) {
+ rbw->constraints = BKE_collection_add(bmain, NULL, "RigidBodyConstraints");
+ id_fake_user_set(&rbw->constraints->id);
+ }
+ /* make rigidbody constraint settings */
+ ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);
+
+ /* add constraint to rigid body constraint group */
+ BKE_collection_object_add(bmain, rbw->constraints, ob);
+
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+ DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE);
+
+ return true;
}
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);
- if (rbw) {
- BKE_collection_object_remove(bmain, rbw->constraints, ob, false);
- DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE);
- }
+ BKE_rigidbody_remove_constraint(scene, ob);
+ if (rbw) {
+ BKE_collection_object_remove(bmain, rbw->constraints, ob, false);
+ DEG_id_tag_update(&rbw->constraints->id, ID_RECALC_COPY_ON_WRITE);
+ }
- DEG_relations_tag_update(bmain);
- DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
}
/* ********************************************** */
@@ -113,88 +114,93 @@ void ED_rigidbody_constraint_remove(Main *bmain, Scene *scene, Object *ob)
static int rigidbody_con_add_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
- RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
- Object *ob = OBACT(view_layer);
- int type = RNA_enum_get(op->ptr, "type");
- bool changed;
-
- /* sanity checks */
- if (ELEM(NULL, scene, rbw)) {
- BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to");
- return OPERATOR_CANCELLED;
- }
- /* apply to active object */
- changed = ED_rigidbody_constraint_add(bmain, scene, ob, type, op->reports);
-
- if (changed) {
- /* send updates */
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-
- /* done */
- return OPERATOR_FINISHED;
- }
- else {
- return OPERATOR_CANCELLED;
- }
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
+ Object *ob = OBACT(view_layer);
+ int type = RNA_enum_get(op->ptr, "type");
+ bool changed;
+
+ /* sanity checks */
+ if (ELEM(NULL, scene, rbw)) {
+ BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to");
+ return OPERATOR_CANCELLED;
+ }
+ /* apply to active object */
+ changed = ED_rigidbody_constraint_add(bmain, scene, ob, type, op->reports);
+
+ if (changed) {
+ /* send updates */
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+
+ /* done */
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
}
void RIGIDBODY_OT_constraint_add(wmOperatorType *ot)
{
- /* identifiers */
- ot->idname = "RIGIDBODY_OT_constraint_add";
- ot->name = "Add Rigid Body Constraint";
- ot->description = "Add Rigid Body Constraint to active object";
-
- /* callbacks */
- ot->exec = rigidbody_con_add_exec;
- ot->poll = ED_operator_object_active_editable;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_rigidbody_constraint_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", "");
+ /* identifiers */
+ ot->idname = "RIGIDBODY_OT_constraint_add";
+ ot->name = "Add Rigid Body Constraint";
+ ot->description = "Add Rigid Body Constraint to active object";
+
+ /* callbacks */
+ ot->exec = rigidbody_con_add_exec;
+ ot->poll = ED_operator_object_active_editable;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna,
+ "type",
+ rna_enum_rigidbody_constraint_type_items,
+ RBC_TYPE_FIXED,
+ "Rigid Body Constraint Type",
+ "");
}
/* ************ Remove Rigid Body Constraint ************** */
static int rigidbody_con_remove_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
-
- /* apply to active object */
- if (ELEM(NULL, ob, ob->rigidbody_constraint)) {
- BKE_report(op->reports, RPT_ERROR, "Object has no Rigid Body Constraint to remove");
- return OPERATOR_CANCELLED;
- }
- else {
- ED_rigidbody_constraint_remove(bmain, scene, ob);
- }
-
- /* send updates */
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-
- /* done */
- return OPERATOR_FINISHED;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+
+ /* apply to active object */
+ if (ELEM(NULL, ob, ob->rigidbody_constraint)) {
+ BKE_report(op->reports, RPT_ERROR, "Object has no Rigid Body Constraint to remove");
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ ED_rigidbody_constraint_remove(bmain, scene, ob);
+ }
+
+ /* send updates */
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+
+ /* done */
+ return OPERATOR_FINISHED;
}
void RIGIDBODY_OT_constraint_remove(wmOperatorType *ot)
{
- /* identifiers */
- ot->idname = "RIGIDBODY_OT_constraint_remove";
- ot->name = "Remove Rigid Body Constraint";
- ot->description = "Remove Rigid Body Constraint from Object";
+ /* identifiers */
+ ot->idname = "RIGIDBODY_OT_constraint_remove";
+ ot->name = "Remove Rigid Body Constraint";
+ ot->description = "Remove Rigid Body Constraint from Object";
- /* callbacks */
- ot->exec = rigidbody_con_remove_exec;
- ot->poll = ED_operator_rigidbody_con_active_poll;
+ /* callbacks */
+ ot->exec = rigidbody_con_remove_exec;
+ ot->poll = ED_operator_rigidbody_con_active_poll;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}