[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54094] trunk/blender: rigidbody: Improve add/remove operators

Sergej Reich sergej.reich at googlemail.com
Fri Jan 25 07:26:40 CET 2013


Revision: 54094
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54094
Author:   sergof
Date:     2013-01-25 06:26:38 +0000 (Fri, 25 Jan 2013)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
    trunk/blender/source/blender/editors/physics/physics_intern.h
    trunk/blender/source/blender/editors/physics/physics_ops.c
    trunk/blender/source/blender/editors/physics/rigidbody_constraint.c
    trunk/blender/source/blender/editors/physics/rigidbody_object.c

Modified: trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-25 05:34:03 UTC (rev 54093)
+++ trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-25 06:26:38 UTC (rev 54094)
@@ -238,7 +238,7 @@
             else:
                 loc = (obj_act.location + obj.location) / 2.0
             bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=loc)
-            bpy.ops.rigidbody.constraint_group_add()
+            bpy.ops.rigidbody.constraint_add()
             con = context.active_object.rigid_body_constraint
             con.type = self.con_type
             con.object1 = obj_act

Modified: trunk/blender/source/blender/editors/physics/physics_intern.h
===================================================================
--- trunk/blender/source/blender/editors/physics/physics_intern.h	2013-01-25 05:34:03 UTC (rev 54093)
+++ trunk/blender/source/blender/editors/physics/physics_intern.h	2013-01-25 06:26:38 UTC (rev 54094)
@@ -117,7 +117,6 @@
 
 /* rigidbody_constraint.c */
 void RIGIDBODY_OT_constraint_add(struct wmOperatorType *ot);
-void RIGIDBODY_OT_constraint_group_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_constraint_remove(struct wmOperatorType *ot);
 
 /*rigidbody_world.c */

Modified: trunk/blender/source/blender/editors/physics/physics_ops.c
===================================================================
--- trunk/blender/source/blender/editors/physics/physics_ops.c	2013-01-25 05:34:03 UTC (rev 54093)
+++ trunk/blender/source/blender/editors/physics/physics_ops.c	2013-01-25 06:26:38 UTC (rev 54094)
@@ -97,7 +97,6 @@
 	WM_operatortype_append(RIGIDBODY_OT_mass_calculate);
 
 	WM_operatortype_append(RIGIDBODY_OT_constraint_add);
-	WM_operatortype_append(RIGIDBODY_OT_constraint_group_add);
 	WM_operatortype_append(RIGIDBODY_OT_constraint_remove);
 
 	WM_operatortype_append(RIGIDBODY_OT_world_add);

Modified: trunk/blender/source/blender/editors/physics/rigidbody_constraint.c
===================================================================
--- trunk/blender/source/blender/editors/physics/rigidbody_constraint.c	2013-01-25 05:34:03 UTC (rev 54093)
+++ trunk/blender/source/blender/editors/physics/rigidbody_constraint.c	2013-01-25 06:26:38 UTC (rev 54094)
@@ -78,20 +78,33 @@
 
 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 @@
 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 @@
 		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 @@
 	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 */

Modified: trunk/blender/source/blender/editors/physics/rigidbody_object.c
===================================================================
--- trunk/blender/source/blender/editors/physics/rigidbody_object.c	2013-01-25 05:34:03 UTC (rev 54093)
+++ trunk/blender/source/blender/editors/physics/rigidbody_object.c	2013-01-25 06:26:38 UTC (rev 54094)
@@ -90,6 +90,8 @@
 
 void ED_rigidbody_ob_add(wmOperator *op, Scene *scene, Object *ob, int type)
 {
+	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
+
 	/* check that object doesn't already belong to the current simulation */
 	if (ob->rigidbody_object) {
 		BKE_reportf(op->reports, RPT_INFO, "Object '%s' already has a Rigid Body", ob->id.name + 2);
@@ -104,14 +106,32 @@
 		return;
 	}
 
+	/* Add rigid body world and group if they don't exist for convenience */
+	if (rbw == NULL) {
+		rbw = BKE_rigidbody_create_world(scene);
+		BKE_rigidbody_validate_sim_world(scene, rbw, false);
+		scene->rigidbody_world = rbw;
+	}
+	if (rbw->group == NULL) {
+		rbw->group = add_group("RigidBodyWorld");
+	}
+
 	/* make rigidbody object settings */
 	ob->rigidbody_object = BKE_rigidbody_create_object(scene, ob, type);
 	ob->rigidbody_object->flag |= RBO_FLAG_NEEDS_VALIDATE;
+
+	/* add object to rigid body group */
+	add_to_group(rbw->group, ob, scene, NULL);
 }
 
 void ED_rigidbody_ob_remove(Scene *scene, Object *ob)
 {
+	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
+
 	BKE_rigidbody_remove_object(scene, ob);
+	if (rbw)
+		rem_from_group(rbw->group, ob, scene, NULL);
+
 	DAG_id_tag_update(&ob->id, OB_RECALC_OB);
 }
 
@@ -209,7 +229,6 @@
 static int rigidbody_obs_add_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
 	int type = RNA_enum_get(op->ptr, "type");
 
 	/* sanity check */
@@ -217,19 +236,9 @@
 		BKE_report(op->reports, RPT_ERROR, "No Scene to add Rigid Bodies to");
 		return OPERATOR_CANCELLED;
 	}
-	/* Add rigid body world and group if they don't exist for convenience */
-	if (rbw == NULL) {
-		rbw = BKE_rigidbody_create_world(scene);
-		BKE_rigidbody_validate_sim_world(scene, rbw, false);
-		scene->rigidbody_world = rbw;
-	}
-	if (rbw->group == NULL) {
-		rbw->group = add_group("RigidBodyWorld");
-	}
 	/* create rigid body objects and add them to the world's group */
 	CTX_DATA_BEGIN(C, Object *, ob, selected_objects) {
 		ED_rigidbody_ob_add(op, scene, ob, type);
-		add_to_group(rbw->group, ob, scene, NULL);
 	}
 	CTX_DATA_END;
 
@@ -266,7 +275,6 @@
 static int rigidbody_obs_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Scene *scene = CTX_data_scene(C);
-	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
 
 	/* sanity checks */
 	if (scene == NULL)
@@ -277,8 +285,6 @@
 	{
 		if (ob->rigidbody_object) {
 			ED_rigidbody_ob_remove(scene, ob);
-			if (rbw)
-				rem_from_group(rbw->group, ob, scene, NULL);
 		}
 	}
 	CTX_DATA_END;




More information about the Bf-blender-cvs mailing list