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:
authorSergej Reich <sergej.reich@googlemail.com>2013-01-25 10:26:38 +0400
committerSergej Reich <sergej.reich@googlemail.com>2013-01-25 10:26:38 +0400
commit204ec89bff751092f0ca97320456e49107b6e15f (patch)
tree2e69d290d2d6374045f3e702b9b64d37187a5f47 /source/blender/editors/physics/rigidbody_constraint.c
parent5c8a978d1f3d7d887c2ecccfdfc5a198ac0d37d1 (diff)
rigidbody: Improve add/remove operators
Now all add/remove operators for rigid body objects and constraints automatically add objects to the appropriate groups and create groups if they don't exist yet. This makes handling rigid bodies easier but doesn't take away functionality. If users want to handle groups manually they just need to create them before adding any objects. The previous behaviour was confusing and was even considered to be a bug since clicking on rigid body in the physics tab seemed to do nothing.
Diffstat (limited to 'source/blender/editors/physics/rigidbody_constraint.c')
-rw-r--r--source/blender/editors/physics/rigidbody_constraint.c64
1 files changed, 18 insertions, 46 deletions
diff --git a/source/blender/editors/physics/rigidbody_constraint.c b/source/blender/editors/physics/rigidbody_constraint.c
index e4db1c91c2b..fac835a414a 100644
--- a/source/blender/editors/physics/rigidbody_constraint.c
+++ b/source/blender/editors/physics/rigidbody_constraint.c
@@ -78,20 +78,33 @@ static int ED_operator_rigidbody_con_active_poll(bContext *C)
void ED_rigidbody_con_add(wmOperator *op, Scene *scene, Object *ob, int type)
{
+ RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
+
/* check that object doesn't already have a constraint */
if (ob->rigidbody_constraint) {
BKE_reportf(op->reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
return;
}
-
+ /* create constraint group if it doesn't already exits */
+ if (rbw->constraints == NULL) {
+ rbw->constraints = add_group("RigidBodyConstraints");
+ }
/* make rigidbody constraint settings */
ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);
ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE;
+
+ /* add constraint to rigid body constraint group */
+ add_to_group(rbw->constraints, ob, scene, NULL);
}
void ED_rigidbody_con_remove(Scene *scene, Object *ob)
{
+ RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
+
BKE_rigidbody_remove_constraint(scene, ob);
+ if (rbw)
+ rem_from_group(rbw->constraints, ob, scene, NULL);
+
DAG_id_tag_update(&ob->id, OB_RECALC_OB);
}
@@ -103,43 +116,6 @@ void ED_rigidbody_con_remove(Scene *scene, Object *ob)
static int rigidbody_con_add_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- Object *ob = (scene) ? OBACT : NULL;
- int type = RNA_enum_get(op->ptr, "type");
-
- /* apply to active object */
- ED_rigidbody_con_add(op, scene, ob, type);
-
- /* send updates */
- DAG_ids_flush_update(CTX_data_main(C), 0);
-
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
-
- /* done */
- return OPERATOR_FINISHED;
-}
-
-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", rigidbody_con_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", "");
-}
-
-static int rigidbody_con_group_add_exec(bContext *C, wmOperator *op)
-{
- Scene *scene = CTX_data_scene(C);
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
Object *ob = (scene) ? OBACT : NULL;
int type = RNA_enum_get(op->ptr, "type");
@@ -149,12 +125,8 @@ static int rigidbody_con_group_add_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to");
return OPERATOR_CANCELLED;
}
- if (rbw->constraints == NULL) {
- rbw->constraints = add_group("RigidBodyConstraints");
- }
/* apply to active object */
ED_rigidbody_con_add(op, scene, ob, type);
- add_to_group(rbw->constraints, ob, scene, NULL);
/* send updates */
DAG_ids_flush_update(CTX_data_main(C), 0);
@@ -166,15 +138,15 @@ static int rigidbody_con_group_add_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-void RIGIDBODY_OT_constraint_group_add(wmOperatorType *ot)
+void RIGIDBODY_OT_constraint_add(wmOperatorType *ot)
{
/* identifiers */
- ot->idname = "RIGIDBODY_OT_constraint_group_add";
+ ot->idname = "RIGIDBODY_OT_constraint_add";
ot->name = "Add Rigid Body Constraint";
- ot->description = "Add Rigid Body Constraint to active object and world's group";
+ ot->description = "Add Rigid Body Constraint to active object";
/* callbacks */
- ot->exec = rigidbody_con_group_add_exec;
+ ot->exec = rigidbody_con_add_exec;
ot->poll = ED_operator_object_active_editable;
/* flags */