[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29707] branches/soc-2010-aligorith-2/ source/blender: == Bullet SoC - (WIP Commit) New C-API...

Joshua Leung aligorith at gmail.com
Sat Jun 26 15:28:26 CEST 2010


Revision: 29707
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29707
Author:   aligorith
Date:     2010-06-26 15:28:26 +0200 (Sat, 26 Jun 2010)

Log Message:
-----------
== Bullet SoC - (WIP Commit) New C-API... ==

This is just a WIP commit for backup purposes. Nothing is guaranteed to compile, so syntax errors/typos are probably abound in this code.

What's done:
* Added new 'RigidBody' module in source/blender to contain our Bullet (and potential other Physics Engine) C-API plugins.
-- Only scons stuff is really setup nicely. I've copied across cmake stuff too, but that'll probably need checking. Makefiles are still missing, but probably best wait on that until I get scons working, to see everything that'll be needed then...

* Added most of the C-API necessary for Bullet. 
-- I've defined access for most of the settings which appear to be actually needed / understandable in physics terms (mass, friction, angular/linear velocities, and a few others)
-- Rigid Bodies are added and use MotionStates now. Hopefully this will get reverse playback working when hooked up
-- Access for all standard collision shapes is ready

* Missing from this API are:
-- Setting/disabling 'activation' - this has yet to be coded
-- Changing collision shape for an object - not yet defined yet
-- Creating collision shapes from meshes - not yet defined yet

* Moved helper function to get the active RigidBodyWorld from Editors to blenkernel

* Added 'start_frame' parameter to RigidBodyWorld, to be hooked up in due course. This should define the reference frame from which all sim parameters can get recalibrated to reduce numerical error accumulation.

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/source/blender/SConscript
    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/physics_intern.h
    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

Added Paths:
-----------
    branches/soc-2010-aligorith-2/source/blender/rigidbody/
    branches/soc-2010-aligorith-2/source/blender/rigidbody/CMakeLists.txt
    branches/soc-2010-aligorith-2/source/blender/rigidbody/SConscript
    branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_api.h
    branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp

Modified: branches/soc-2010-aligorith-2/source/blender/SConscript
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/SConscript	2010-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/SConscript	2010-06-26 13:28:26 UTC (rev 29707)
@@ -37,3 +37,6 @@
 
 if env['WITH_BF_COLLADA']:
     SConscript (['collada/SConscript'])
+
+#if env['WITH_BF_BULLET']:
+#	SConscript (['rigidbody/SConscript'])

Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h	2010-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/BKE_rigidbody.h	2010-06-26 13:28:26 UTC (rev 29707)
@@ -56,6 +56,7 @@
 /* Utilities */
 
 struct RigidBodyWorld *BKE_rigidbody_group_get_world(struct Scene *scene, struct Group *group);
+struct RigidBodyWorld *BKE_rigidbody_get_active_world(struct Scene *scene, short add);
 
 /* -------------- */
 /* Simulation */

Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-06-26 13:28:26 UTC (rev 29707)
@@ -194,6 +194,7 @@
 	
 	/* create new rigidbody object instance */
 	// XXX: what do we store for userdata (first arg)? set this to the object that this represents for now...
+	// XXX: mass should be calculated via some helper func to get 0.0 when we don't we want 'static' control
 	rbo->physics_object = plCreateRigidBody(ob, rbo->mass, rbo->physics_shape);
 }	
 
@@ -280,8 +281,11 @@
 	ob->rigidbodySettings = rbo;
 	
 	/* set default settings */
+	// XXX: this really depends on type...
 	rbo->mass = 1.0f;
 	
+	// TODO: collision shape from object bounds type? or simply reuse that setting instead?
+	
 	/* finally, make rigid body objects, and add these to the sim world... */
 	rigidbody_validate_sim_ob(ob, rbo, 1);
 	rigidbody_add_sim_ob(rbw, rbo);
@@ -307,7 +311,7 @@
 }
 
 /* ************************************** */
-/* Utilities */
+/* Utilities API */
 
 /* Get the simulation world that uses a specified group */
 RigidBodyWorld *BKE_rigidbody_group_get_world (Scene *scene, Group *group)
@@ -328,6 +332,35 @@
 	return NULL;
 }
 
+/* Get active RigidBody world for the given scene, creating one if needed when 'add' is set 
+ * < scene: Scene to find active Rigid Body world for
+ * < add: If non-zero, create a new RigidBody world if an active one does not exist 
+ */
+RigidBodyWorld *BKE_rigidbody_get_active_world (Scene *scene, short add)
+{
+	RigidBodyWorld *rbw;
+	
+	/* sanity check */
+	if (scene == NULL) 
+		return NULL;
+
+	/* get the rigidbody world indicated by the active index (i.e. the one currently being edited) */
+	rbw = BLI_findlink(&scene->rigidbody_worlds, scene->active_rigidbody_world-1);
+	
+	/* create if it doesn't exist and we need one */
+	if ((rbw == NULL) && (add)) {
+		/* create a new group, and make this the group used for a new sim world */
+		Group *group = add_group("RigidBodyWorld");
+		rbw = BKE_rigidbody_make_world(scene, group);
+		
+		/* set new active sim */
+		scene->active_rigidbody_world = BLI_countlist(&scene->rigidbody_worlds);
+	}
+	
+	/* return RigidBody world */
+	return rbw;
+}
+
 /* ************************************** */
 /* Simulation Interface - Bullet */
 
@@ -365,6 +398,7 @@
 #endif
 	
 	/* if flag to rebuild physics worlds is set, we must clear and then rebuild all relevant links */
+	// TODO: how can we fit the reset into something like this too?
 	if ((rbw->recalc & RBW_RECALC_REBUILD) || (rbw->physics_world == NULL)) {
 		/* rebuild physics world */
 		rigidbody_validate_sim_world(scene, rbw);

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-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h	2010-06-26 13:28:26 UTC (rev 29707)
@@ -107,8 +107,6 @@
 void PTCACHE_OT_remove(struct wmOperatorType *ot);
 
 /* rigidbody_edit.c */
-struct RigidBodyWorld *ED_rigidbody_get_active_world(struct Scene *scene, short verify);
-
 void RIGIDBODY_OT_world_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_world_remove(struct wmOperatorType *ot);
 

Modified: branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_edit.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_edit.c	2010-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_edit.c	2010-06-26 13:28:26 UTC (rev 29707)
@@ -71,33 +71,7 @@
 	return (scene && scene->active_rigidbody_world);
 }
 
-/* Get active RigidBody world, creating one if needed when verify is set */
-RigidBodyWorld *ED_rigidbody_get_active_world (Scene *scene, short verify)
-{
-	RigidBodyWorld *rbw;
-	
-	/* sanity check */
-	if (scene == NULL) 
-		return NULL;
 
-	/* get the rigidbody world indicated by the active index (i.e. the one currently being edited) */
-	rbw = BLI_findlink(&scene->rigidbody_worlds, scene->active_rigidbody_world-1);
-	
-	/* create if it doesn't exist and we need one */
-	if ((rbw == NULL) && (verify)) {
-		/* create a new group, and make this the group used for a new sim world */
-		Group *group = add_group("RigidBodyWorld");
-		rbw = BKE_rigidbody_make_world(scene, group);
-		
-		/* set new active sim */
-		scene->active_rigidbody_world = BLI_countlist(&scene->rigidbody_worlds);
-	}
-	
-	/* return RigidBody world */
-	return rbw;
-}
-
-
 /* ********************************************** */
 /* OPERATORS */
 
@@ -116,7 +90,7 @@
 	
 	/* hack: clear active world to force a new one to be created by get active world */
 	scene->active_rigidbody_world = 0;
-	ED_rigidbody_get_active_world(scene, 1);
+	BKE_rigidbody_get_active_world(scene, 1);
 	
 	return OPERATOR_FINISHED;
 }
@@ -141,7 +115,7 @@
 static int rigidbody_world_remove_exec (bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	RigidBodyWorld *rbw = ED_rigidbody_get_active_world(scene, 0);
+	RigidBodyWorld *rbw = BKE_rigidbody_get_active_world(scene, 0);
 	
 	/* sanity checks */
 	if ELEM(NULL, scene, rbw) {

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-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_object.c	2010-06-26 13:28:26 UTC (rev 29707)
@@ -68,7 +68,7 @@
 static int rigidbody_ob_add_exec (bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	RigidBodyWorld *rbw = ED_rigidbody_get_active_world(scene, 1);
+	RigidBodyWorld *rbw = BKE_rigidbody_get_active_world(scene, 1);
 	int type = RNA_enum_get(op->ptr, "type");
 	
 	/* sanity checks */
@@ -84,6 +84,7 @@
 		RigidBodyOb *rbo = BKE_rigidbody_make_object(rbw, ob);
 		
 		/* set default settings appropriate to the object being added */
+		// TODO: move this stuff to the make_object() function instead...
 		rbo->type = type;
 		if (rbo->type != RBO_TYPE_ACTIVE) {
 			/* inactive objects must not have any mass */

Modified: branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-06-26 13:28:26 UTC (rev 29707)
@@ -57,9 +57,10 @@
 	short max_timestep;			/* maximum timestep size to take */
 	short substeps;				/* number of sub-frame samples to take for more accurate results */
 	
+	float sframe;				/* start frame of simulation - can be different to scene sfra, to allow for preroll */
 	float ltime;				/* last frame world was evaluated for */
-	int pad;
 	
+	
 	// TODO: add settings for
 	//	- broadphase algorithm to use
 	
@@ -113,6 +114,7 @@
 
 /* Participation types for RigidBodyOb */
 // XXX: how do we represent objects switching between anim and sim? allow changing this during anim?
+// XXX: should we just dump this setting in favour of the 'dynamic' flag? or get rid of that instead? 
 typedef enum eRigidBodyOb_Type {
 	/* active geometry participant in simulation. is directly controlled by sim */
 	RBO_TYPE_ACTIVE	= 0,

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-06-26 13:24:52 UTC (rev 29706)
+++ branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c	2010-06-26 13:28:26 UTC (rev 29707)
@@ -49,6 +49,15 @@
 
 #ifdef RNA_RUNTIME
 
+static void rna_RigidBodyOb_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	// XXX: rigidbodyworld is needed when flushing, but can't flush under these conditions
+	RigidBodyWorld *rbw= NULL; //ED_rigidbody_get_active_world(scene, 0);
+	Object *ob= (Object*)ptr->id.data;
+	
+	BKE_rigidbody_update_object(rbw, ob);
+}
+
 #else
 
 static void rna_def_rigidbody_world(BlenderRNA *brna)
@@ -80,6 +89,14 @@
 	RNA_def_property_ui_text(prop, "Force Update Hack", "Hack to force sim settings to get rebuilt");
 	RNA_def_property_update(prop, NC_SCENE, NULL);
 	
+	/* start frame */
+	prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_int_sdna(prop, NULL, "sframe");
+	//RNA_def_property_int_funcs(prop, NULL, "rna_Scene_start_frame_set", NULL);
+	RNA_def_property_range(prop, MINFRAME, MAXFRAME);
+	RNA_def_property_ui_text(prop, "Start Frame", "Frame that simulation starts on (used as a reference point for resetting the sim)");
+	RNA_def_property_update(prop, NC_SCENE, NULL);
 	// TODO:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list