[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29512] branches/soc-2010-aligorith-2: == Bullet SoC - Initial Commit of 'Prototype' ==

Joshua Leung aligorith at gmail.com
Thu Jun 17 06:44:21 CEST 2010


Revision: 29512
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29512
Author:   aligorith
Date:     2010-06-17 06:44:18 +0200 (Thu, 17 Jun 2010)

Log Message:
-----------
== Bullet SoC - Initial Commit of 'Prototype' ==

This commit is my first attempt at implemented the plan described in the design docs I posted. Most of the key architectural details mentioned there are implemented, however, this is really not intended for general user consumption yet.

What is done:
* Basic evaluation loop to run Bullet simulations within normal Blender, and see the results of this in realtime in the viewport
* A few operators to set up a simulation to run in this loop. Use 'Add Active' (Ctrl-R) to add an object controlled by Physics, and 'Add Passive' (Ctrl-Shift-R) to add an object controlled by AnimSys but affecting physics.
* Two basic collision shapes hacked in - cube and sphere. A more refined setup still needed for setting up other collision shapes.
* Basic/key parts of the framework proposed in the design doc - datastructures + core api's

Please be aware that this is a very WIP commit. There are many things missing, especially:
* File I/O Support - this includes undo. So, be very careful with this. Don't try saving out files with it yet, else you'll get some nasty surprises.
* Changing the parameters of the sim will not work yet force a refresh
* Gravity is currently hardcoded (it should take value from scene instead). This is done with a hack to Bullet's C-API, which should be removed later (see next point)
* A better C-API for interfacing with Bullet. I'm currently using the one Bullet supplies, but a new one, tailored better for Blender and more powerful will be the next target.
* Sims can currently only be run once. The new C-API should help with this...

Check the "Bullet SoC - Sneak Peek" post on my blog (http://aligorith.blogspot.com/) for more details and a few video demos...

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
    branches/soc-2010-aligorith-2/release/scripts/ui/properties_scene.py
    branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py
    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/makesdna/DNA_object_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2010-aligorith-2/source/blender/makesdna/intern/makesdna.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/RNA_access.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/RNA_enum_types.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/makesrna.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_internal.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_object.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2010-aligorith-2/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp

Added Paths:
-----------
    branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
    branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h
    branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_edit.c
    branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_object.c
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c

Modified: branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
===================================================================
--- branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp	2010-06-17 04:31:02 UTC (rev 29511)
+++ branches/soc-2010-aligorith-2/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp	2010-06-17 04:44:18 UTC (rev 29512)
@@ -97,8 +97,17 @@
 	mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
 	btConstraintSolver*			constraintSolver = new(mem) btSequentialImpulseConstraintSolver();
 
+#if 0 // xxx: original bullet code
 	mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
 	return (plDynamicsWorldHandle) new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
+#else // xxx: TEMP CODE TO CHECK THAT THIS ALL WORKS - Bullet SoC
+	mem = btAlignedAlloc(sizeof(btDiscreteDynamicsWorld),16);
+	btDynamicsWorld* 			dynamicsWorld = new (mem)btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration);
+
+	dynamicsWorld->setGravity(btVector3(0, 0, -10));
+	
+	return (plDynamicsWorldHandle)dynamicsWorld;
+#endif // xxx: TEMP CODE TO CHECK THAT THIS ALL WORKS - Bullet SoC
 }
 void           plDeleteDynamicsWorld(plDynamicsWorldHandle world)
 {

Added: branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py	                        (rev 0)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py	2010-06-17 04:44:18 UTC (rev 29512)
@@ -0,0 +1,74 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+import bpy
+
+narrowui = bpy.context.user_preferences.view.properties_width_check
+
+class PHYSICS_PT_rigid_body(bpy.types.Panel):
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "physics"
+    bl_label = "Rigid Body"
+
+    def poll(self, context):
+        return (context.object and context.object.rigid_body)
+        
+    def draw(self, context):
+        layout = self.layout
+
+        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:")
+        else:
+            split = layout.split()
+        split.prop(rbo, "type", text="")
+
+        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, "mass")
+        
+
+classes = [
+    PHYSICS_PT_rigid_body
+]
+
+def register():
+    register = bpy.types.register
+    for cls in classes:
+        register(cls)
+
+
+def unregister():
+    unregister = bpy.types.unregister
+    for cls in classes:
+        unregister(cls)
+
+if __name__ == "__main__":
+    register()

Modified: branches/soc-2010-aligorith-2/release/scripts/ui/properties_scene.py
===================================================================
--- branches/soc-2010-aligorith-2/release/scripts/ui/properties_scene.py	2010-06-17 04:31:02 UTC (rev 29511)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_scene.py	2010-06-17 04:44:18 UTC (rev 29512)
@@ -189,7 +189,30 @@
         else:
             layout.column().prop(scene, "gravity", text="")
 
+class SCENE_PT_rigid_body_worlds(SceneButtonsPanel):
+    bl_label = "Rigid Body Worlds"
 
+    def draw(self, context):
+        layout = self.layout
+
+        scene = context.scene
+        wide_ui = context.region.width > narrowui
+        row = layout.row()
+
+        col = row.column()
+        col.template_list(scene, "rigidbody_worlds", scene, "active_rigidbody_world_index", rows=2)
+
+        col = row.column(align=True)
+        col.operator("rigidbody.world_add", icon='ZOOMIN', text="")
+        col.operator("rigidbody.world_remove", icon='ZOOMOUT', text="")
+
+        rbw = scene.active_rigidbody_world
+        if rbw:
+            col = layout.column()
+            col.prop(rbw, "group")
+            col.prop(rbw, "force_update", toggle=True) # XXX - nasty hack
+
+
 class SCENE_PT_simplify(SceneButtonsPanel):
     bl_label = "Simplify"
     COMPAT_ENGINES = {'BLENDER_RENDER'}
@@ -342,6 +365,7 @@
     SCENE_PT_keying_sets,
     SCENE_PT_keying_set_paths,
     SCENE_PT_physics,
+    SCENE_PT_rigid_body_worlds,
     SCENE_PT_simplify,
 
     SCENE_PT_custom_props,

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-06-17 04:31:02 UTC (rev 29511)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/space_view3d_toolbar.py	2010-06-17 04:44:18 UTC (rev 29512)
@@ -71,6 +71,13 @@
         row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
         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 Body:")
+        row = col.row()
+        row.operator("rigidbody.object_add", text="Add Active").type = 'ACTIVE'
+        row.operator("rigidbody.object_add", text="Add Passive").type = 'PASSIVE'
 
 # ********** default tools for editmode_mesh ****************
 

Added: branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h	                        (rev 0)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h	2010-06-17 04:44:18 UTC (rev 29512)
@@ -0,0 +1,65 @@
+/**
+ * $Id: BKE_rigidbody.h $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation, Joshua Leung
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joshua Leung 
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef BKE_RIGIDBODY_H
+#define BKE_RIGIDBODY_H
+
+struct RigidBodyWorld;
+struct RigidBodyOb;
+
+struct Scene;
+struct Object;
+struct Group;
+
+/* -------------- */
+/* Memory Management */
+
+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);
+
+/* -------------- */
+/* Setup */
+
+struct RigidBodyWorld *BKE_rigidbody_make_world(struct Scene *scene, struct Group *group);
+struct RigidBodyOb *BKE_rigidbody_make_object(struct RigidBodyWorld *rbw, struct Object *ob);
+
+void BKE_rigidbody_update_object(struct RigidBodyWorld *rbw, struct Object *ob);
+
+/* -------------- */
+/* Utilities */
+
+struct RigidBodyWorld *BKE_rigidbody_group_get_world(struct Scene *scene, struct Group *group);
+
+/* -------------- */
+/* Simulation */
+
+void BKE_rigidbody_do_simulation(struct Scene *scene, struct RigidBodyWorld *rbw, float ctime);
+
+#endif // BKE_RIGIDBODY_H

Added: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	                        (rev 0)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-06-17 04:44:18 UTC (rev 29512)
@@ -0,0 +1,445 @@
+/**
+ * $Id: rigidbody.c $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation, Joshua Leung
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joshua Leung 
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stddef.h>
+#include <float.h>
+#include <math.h>
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list