[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30203] branches/soc-2010-aligorith-2: Bullet SoC - Collision Shape Tweaks
Joshua Leung
aligorith at gmail.com
Sun Jul 11 14:25:55 CEST 2010
Revision: 30203
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30203
Author: aligorith
Date: 2010-07-11 14:25:54 +0200 (Sun, 11 Jul 2010)
Log Message:
-----------
Bullet SoC - Collision Shape Tweaks
* Added operator to change the collision shapes on a bunch of selected objects at the same time. Currently only has a toolbar button (i.e. no hotkey), but makes working with several objects at a time faster.
* Added proper poll for RigidBody operators needing existing rigidbody data.
* When determining the initial collision shape for objects, there is now some fancy logic for determining if 'box' is used based on common cases:
-- if draw-bounds is enabled, then box shape will be used, as user explicitly asked for it
-- if ob is not a mesh, assume that box is the only usable option in this case
-- otherwise, use a MESH!, since user just wants collisions working without much effort.
Modified Paths:
--------------
branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h
branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_ops.c
branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_object.c
branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
Modified: branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py 2010-07-11 11:51:44 UTC (rev 30202)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py 2010-07-11 12:25:54 UTC (rev 30203)
@@ -72,7 +72,6 @@
row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
- # FIXME: maybe should be on this list...
col = layout.column(align=True)
col.label(text="Rigid Bodies:")
row = col.row()
@@ -80,6 +79,9 @@
row.operator("rigidbody.objects_add", text="Add Passive").type = 'PASSIVE'
row = col.row()
row.operator("rigidbody.objects_remove", text="Remove")
+
+ col = layout.column(align=True)
+ col.operator("rigidbody.shape_change", text="Change Shape")
# ********** default tools for editmode_mesh ****************
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-07-11 11:51:44 UTC (rev 30202)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-07-11 12:25:54 UTC (rev 30203)
@@ -346,17 +346,31 @@
static int get_shape_from_boundbox (Object *ob)
{
switch (ob->boundtype) {
- case OB_BOUND_BOX:
- return RB_SHAPE_BOX;
+ /* 1:1 mapping */
case OB_BOUND_SPHERE:
return RB_SHAPE_SPHERE;
case OB_BOUND_CYLINDER:
return RB_SHAPE_CYLINDER;
case OB_BOUND_CONE:
return RB_SHAPE_CONE;
-
- default: // XXX: is this an appropriate decision?
- return RB_SHAPE_BOX;
+
+ /* some fancy stuff */
+ case OB_BOUND_BOX:
+ /* this happens in threee cases:
+ * 1) assume that if draw_bounds is enabled, then user explicitly wants box
+ * 2) assume that if not a mesh (i.e. a curve), then box is the only safe option
+ * for now, despite boundboxes not being drawn
+ */
+ if ((ob->dtx & OB_BOUNDBOX) || (ob->type != OB_MESH))
+ return RB_SHAPE_BOX;
+ /* else
+ * 3) user hasn't touched this setting, so assume that a fancy default of 'mesh'
+ * should be used to get nicely functioning collisions working by default, so...
+ *
+ * !!!PASSTHROUGH!!!
+ */
+ default:
+ return RB_SHAPE_TRIMESH;
}
}
Modified: branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h 2010-07-11 11:51:44 UTC (rev 30202)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h 2010-07-11 12:25:54 UTC (rev 30203)
@@ -120,5 +120,7 @@
void RIGIDBODY_OT_objects_add(struct wmOperatorType *ot);
void RIGIDBODY_OT_objects_remove(struct wmOperatorType *ot);
+void RIGIDBODY_OT_shape_change(struct wmOperatorType *ot);
+
#endif /* ED_PHYSICS_INTERN_H */
Modified: branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_ops.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_ops.c 2010-07-11 11:51:44 UTC (rev 30202)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_ops.c 2010-07-11 12:25:54 UTC (rev 30203)
@@ -94,7 +94,9 @@
WM_operatortype_append(RIGIDBODY_OT_object_buttons_remove);
WM_operatortype_append(RIGIDBODY_OT_objects_add);
- WM_operatortype_append(RIGIDBODY_OT_objects_remove);
+ WM_operatortype_append(RIGIDBODY_OT_objects_remove);
+
+ WM_operatortype_append(RIGIDBODY_OT_shape_change);
}
static void keymap_particle(wmKeyConfig *keyconf)
Modified: branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_object.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_object.c 2010-07-11 11:51:44 UTC (rev 30202)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_object.c 2010-07-11 12:25:54 UTC (rev 30203)
@@ -64,6 +64,16 @@
/* ********************************************** */
/* Helper API's for RigidBody Objects Editing */
+int ED_operator_rigidbody_active_poll(bContext *C)
+{
+ if (ED_operator_object_active_editable(C))
+ return (CTX_data_active_object(C)->rigidbodySettings != NULL);
+ else
+ return 0;
+}
+
+/* ----------------- */
+
static void ed_rigidbody_ob_add (bContext *C, wmOperator *op, RigidBodyWorld *rbw, Object *ob, int type)
{
Scene *scene = CTX_data_scene(C);
@@ -217,7 +227,7 @@
/* callbacks */
ot->exec = rigidbody_ob_remove_exec;
- ot->poll = ED_operator_object_active_editable;
+ ot->poll = ED_operator_rigidbody_active_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -310,10 +320,63 @@
/* callbacks */
ot->exec = rigidbody_obs_remove_exec;
- ot->poll = ED_operator_object_active_editable; // XXX need special poll
+ ot->poll = ED_operator_rigidbody_active_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ********************************************** */
+/* Utility Operators */
+
+/* ************ Change Collision Shapes ************** */
+
+static int rigidbody_obs_shape_change_exec (bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ int shape = RNA_enum_get(op->ptr, "type");
+
+ /* sanity checks */
+ if (scene == NULL)
+ return OPERATOR_CANCELLED;
+
+ /* apply this to all selected objects... */
+ CTX_DATA_BEGIN(C, Object*, ob, selected_objects)
+ {
+ if (ob->rigidbodySettings) {
+ PointerRNA ptr;
+
+ /* use RNA-system to change the property and perform all necessary changes */
+ RNA_pointer_create(&ob->id, &RNA_RigidBodyObject, ob->rigidbodySettings, &ptr);
+ RNA_enum_set(&ptr, "collision_shape", shape);
+ }
+ }
+ CTX_DATA_END;
+
+ /* send updates */
+ WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); // XXX: wrong notifiers for now, but these also do the job...
+
+ /* done */
+ return OPERATOR_FINISHED;
+}
+
+void RIGIDBODY_OT_shape_change (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->idname = "RIGIDBODY_OT_shape_change";
+ ot->name = "Change Collision Shape";
+ ot->description = "Change collision shapes for selected Rigid Body Objects";
+
+ /* callbacks */
+ ot->invoke = WM_menu_invoke;
+ ot->exec = rigidbody_obs_shape_change_exec;
+ ot->poll = ED_operator_rigidbody_active_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_ob_shape_items, RB_SHAPE_TRIMESH, "Rigid Body Shape", "");
+}
+
+/* ********************************************** */
Modified: branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c 2010-07-11 11:51:44 UTC (rev 30202)
+++ branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c 2010-07-11 12:25:54 UTC (rev 30203)
@@ -51,8 +51,8 @@
{RB_SHAPE_CAPSULE, "CAPSULE", ICON_OUTLINER_OB_META, "Capsule", ""},
{RB_SHAPE_CYLINDER, "CYLINDER", ICON_MESH_TUBE, "Cylinder", ""},
{RB_SHAPE_CONE, "CONE", ICON_MESH_CONE, "Cone", ""},
- {0, "", 0, "", ""},
- {RB_SHAPE_TRIMESH, "MESH", ICON_MESH_MONKEY, "Mesh", "Convex Hull defined from vertices of mesh only. Best results with fewer vertoces"},
+ //{0, "", 0, "", ""},
+ {RB_SHAPE_TRIMESH, "MESH", ICON_MESH_MONKEY, "Mesh", "Convex Hull defined from vertices of mesh only. Best results with fewer vertices"},
// XXX: compound shapes have yet to be implemented
{0, NULL, 0, NULL, NULL}};
More information about the Bf-blender-cvs
mailing list