[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29836] branches/soc-2010-aligorith-2: Bullet SoC - Operator Work...
Joshua Leung
aligorith at gmail.com
Thu Jul 1 03:48:47 CEST 2010
Revision: 29836
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29836
Author: aligorith
Date: 2010-07-01 03:48:45 +0200 (Thu, 01 Jul 2010)
Log Message:
-----------
Bullet SoC - Operator Work...
* Added Add/Remove operators for the active object only, and also tweaked the UI so that the Rigid Body panel shows with these buttons as in all the other Physics Systems.
* Hooked up freeing code, so that there aren't warnings about unfreed stuff on exit anymore. Still need to double-check all that all the Bullet-side stuff does get freed, so I might need to make some tweaks there too
* Added operators to remove objects from RigidBody simulations
* Friction is now exposed in UI. Also, it gets a default value of 0.5 (which Bullet also seems to use). In Bullet code, there's a comment that this should be non-zero for the best results (i.e. in real-world terms, ice should have friction of 0 and is slippery/floaty...)
Modified Paths:
--------------
branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py
branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/object.c
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/scene.c
branches/soc-2010-aligorith-2/source/blender/editors/object/object_ops.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
Modified: branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py 2010-07-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py 2010-07-01 01:48:45 UTC (rev 29836)
@@ -28,7 +28,7 @@
bl_label = "Rigid Body"
def poll(self, context):
- return (context.object and context.object.rigid_body)
+ return (context.object)
def draw(self, context):
layout = self.layout
@@ -36,24 +36,37 @@
ob = context.object
rbo = ob.rigid_body
wide_ui = context.region.width > narrowui
-
- if wide_ui:
- split = layout.split(percentage=0.2)
- split.label(text="Type:")
+
+ split = layout.split()
+ if rbo:
+ split.operator("rigidbody.object_buttons_remove", text="Remove")
+ split.label(text=" ")
else:
- split = layout.split()
- split.prop(rbo, "type", text="")
+ split.operator("rigidbody.object_buttons_add", text="Add")
+ split.label(text=" ")
+
+ if rbo:
+ if wide_ui:
+ split = layout.split(percentage=0.3)
+ split.label(text="Type:")
+ else:
+ split = layout.split()
+ split.prop(rbo, "type", text="")
- if wide_ui:
- split = layout.split(percentage=0.2)
- split.label(text="Collision Shape:")
- else:
+ if wide_ui:
+ split = layout.split(percentage=0.2)
+ split.label(text="Collision Shape:")
+ else:
+ split = layout.split()
+ split.prop(rbo, "collision_shape", text="")
+
split = layout.split()
- split.prop(rbo, "collision_shape", text="")
+
+ col = split.column()
+ col.prop(rbo, "mass")
+ col.prop(rbo, "friction")
+
- split = layout.split()
- split.prop(rbo, "mass")
-
classes = [
PHYSICS_PT_rigid_body
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-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py 2010-07-01 01:48:45 UTC (rev 29836)
@@ -74,10 +74,12 @@
# FIXME: maybe should be on this list...
col = layout.column(align=True)
- col.label(text="Rigid Body:")
+ col.label(text="Rigid Bodies:")
row = col.row()
- row.operator("rigidbody.object_add", text="Add Active").type = 'ACTIVE'
- row.operator("rigidbody.object_add", text="Add Passive").type = 'PASSIVE'
+ row.operator("rigidbody.objects_add", text="Add Active").type = 'ACTIVE'
+ row.operator("rigidbody.objects_add", text="Add Passive").type = 'PASSIVE'
+ row = col.row()
+ row.operator("rigidbody.objects_remove", text="Remove")
# ********** default tools for editmode_mesh ****************
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h 2010-07-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h 2010-07-01 01:48:45 UTC (rev 29836)
@@ -43,7 +43,7 @@
void BKE_rigidbody_free_world(struct Scene *scene, struct RigidBodyWorld *rbw);
void BKE_rigidbody_free_worlds(struct Scene *scene);
-void BKE_rigidbody_free_object(struct Scene *scene, struct Object *ob);
+void BKE_rigidbody_free_object(struct Object *ob);
/* -------------- */
/* Setup */
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/object.c 2010-07-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/object.c 2010-07-01 01:48:45 UTC (rev 29836)
@@ -89,6 +89,7 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_property.h"
+#include "BKE_rigidbody.h"
#include "BKE_sca.h"
#include "BKE_scene.h"
#include "BKE_sequencer.h"
@@ -301,6 +302,7 @@
free_constraints(&ob->constraints);
free_partdeflect(ob->pd);
+ BKE_rigidbody_free_object(ob);
if(ob->soft) sbFree(ob->soft);
if(ob->bsoft) bsbFree(ob->bsoft);
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-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-07-01 01:48:45 UTC (rev 29836)
@@ -61,15 +61,27 @@
/* Freeing Methods --------------------- */
/* Free rigidbody world */
-// TODO: should we unlink any physics objects that current use this?
-// - what if they have multi-users (though that case isn't handled well yet)
void BKE_rigidbody_free_world (Scene *scene, RigidBodyWorld *rbw)
-{
+{
/* sanity checks */
if ELEM(NULL, scene, rbw)
return;
/* free physics references */
+ if (rbw->group) {
+ GroupObject *go;
+
+ for (go = rbw->group->gobject.first; go; go = go->next) {
+ if (go->ob && go->ob->rigidbodySettings) {
+ RigidBodyOb *rbo = go->ob->rigidbodySettings;
+
+ /* assume that all physics objects in group will have been added to world */
+ // XXX: double check whether this is true for multi-grouped objects
+ if (rbo->physics_object)
+ rbDWorldRemoveBody(rbw->physics_world, rbo->physics_object);
+ }
+ }
+ }
rbDWorldDelete(rbw->physics_world);
/* free rigidbody world itself */
@@ -93,36 +105,25 @@
}
-/* Free RigidBody collision object
- * < scene: Optional parameter. When available, each sim world using the object
- * will need to have it removed from its sim world
- * < ob: object with RigidBody data needing freeing
- */
-void BKE_rigidbody_free_object (Scene *scene, Object *ob)
+/* Free RigidBody settings and sim instances */
+void BKE_rigidbody_free_object (Object *ob)
{
RigidBodyOb *rbo = (ob) ? ob->rigidbodySettings : NULL;
/* sanity check */
if (rbo == NULL)
return;
-
+
/* free physics references */
-#if 0 // XXX: nice stuff to do later
- if (scene) {
- RigidBodyWorld *rbw;
-
- /* remove from any sim world that uses a group that object is in */
- for (rbw = scene->rigidbody_worlds; rbw; rbw = rbw->next) {
- // TODO...
- }
- }
-#endif
-
rbBodyDelete(rbo->physics_object);
rbo->physics_object = NULL;
rbShapeDelete(rbo->physics_shape);
rbo->physics_shape = NULL;
+
+ /* free data itself */
+ MEM_freeN(rbo);
+ ob->rigidbodySettings = NULL;
}
/* ************************************** */
@@ -343,7 +344,9 @@
/* set default settings */
rbo->type = type;
+
rbo->mass = 1.0f;
+ rbo->friction = 0.5f; // best when non-zero. 0.5 is Bullet default
rbo->shape = get_shape_from_boundbox(ob);
Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/scene.c 2010-07-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/scene.c 2010-07-01 01:48:45 UTC (rev 29836)
@@ -248,6 +248,8 @@
BKE_free_animdata((ID *)sce);
BKE_keyingsets_free(&sce->keyingsets);
+ BKE_rigidbody_free_worlds(sce);
+
if (sce->r.avicodecdata) {
free_avicodecdata(sce->r.avicodecdata);
MEM_freeN(sce->r.avicodecdata);
Modified: branches/soc-2010-aligorith-2/source/blender/editors/object/object_ops.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/object/object_ops.c 2010-07-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/source/blender/editors/object/object_ops.c 2010-07-01 01:48:45 UTC (rev 29836)
@@ -359,10 +359,11 @@
WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
// XXX: these hotkeys are very temporary still...
- kmi = WM_keymap_add_item(keymap, "RIGIDBODY_OT_object_add", RKEY, KM_PRESS, KM_CTRL, 0); // xxx active
- RNA_enum_set(kmi->ptr, "type", 0);
- kmi = WM_keymap_add_item(keymap, "RIGIDBODY_OT_object_add", RKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); // xxx passive
- RNA_enum_set(kmi->ptr, "type", 1);
+ kmi = WM_keymap_add_item(keymap, "RIGIDBODY_OT_objects_add", RKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "type", 0); /* active */
+ kmi = WM_keymap_add_item(keymap, "RIGIDBODY_OT_objects_add", RKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
+ RNA_enum_set(kmi->ptr, "type", 1); /* passive */
+ kmi = WM_keymap_add_item(keymap, "RIGIDBODY_OT_objects_remove", RKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
WM_keymap_add_menu(keymap, "VIEW3D_MT_object_specials", WKEY, KM_PRESS, 0, 0);
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-01 00:36:50 UTC (rev 29835)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h 2010-07-01 01:48:45 UTC (rev 29836)
@@ -111,7 +111,11 @@
void RIGIDBODY_OT_world_remove(struct wmOperatorType *ot);
/* rigidbody_object.c */
-void RIGIDBODY_OT_object_add(struct wmOperatorType *ot);
+void RIGIDBODY_OT_object_buttons_add(struct wmOperatorType *ot);
+void RIGIDBODY_OT_object_buttons_remove(struct wmOperatorType *ot);
+void RIGIDBODY_OT_objects_add(struct wmOperatorType *ot);
+void RIGIDBODY_OT_objects_remove(struct wmOperatorType *ot);
+
#endif /* ED_PHYSICS_INTERN_H */
Modified: branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_ops.c
===================================================================
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list