[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29782] branches/soc-2010-aligorith-2/ source/blender: Bullet SoC - RNA Tweaks:

Joshua Leung aligorith at gmail.com
Tue Jun 29 05:06:22 CEST 2010


Revision: 29782
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29782
Author:   aligorith
Date:     2010-06-29 05:06:21 +0200 (Tue, 29 Jun 2010)

Log Message:
-----------
Bullet SoC - RNA Tweaks:

Rigid Body Worlds
* Added 'Name' property, which just uses the name of the associated group usually, or a dummy
* List box widget now displays Rigid Body Worlds with their name (due to first change) and a checkbox to turn simulation on/off. Inverted name/purpose of the muting property to make this work

Rigid Bodies
* Mass can now be animated
* Added 'Friction' attribute, but this isn't exposed in UI yet
* Changing the type of the RigidBody now works, and can be animated like Mass

Building:
* RNA now depends on the RigidBody C-API too, since that allows the settings to be animated via RNA, and then only the changed properties will be updated by the Animation System (via RNA) instead of requiring a special property syncing step later.
NOTE: as with other changes, I've only tested/fixed this for scons only

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c
    branches/soc-2010-aligorith-2/source/blender/makesrna/SConscript
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp

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-28 23:55:31 UTC (rev 29781)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-06-29 03:06:21 UTC (rev 29782)
@@ -378,6 +378,9 @@
 	 */
 	// XXX: the standard object matrix has scaling included... for now, just make sure no scaling goes through...
 	//rbSetTransformMatrix(rbo->physics_object, ob->obmat);
+	
+	// NOTE: no other settings need to be explicitly updated here, 
+	// since RNA setters take care of the rest :)
 }
 
 /* .......... */

Modified: branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c	2010-06-28 23:55:31 UTC (rev 29781)
+++ branches/soc-2010-aligorith-2/source/blender/editors/interface/interface_templates.c	2010-06-29 03:06:21 UTC (rev 29782)
@@ -2142,6 +2142,11 @@
 		uiBlockSetEmboss(block, UI_EMBOSS);
 		uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "enabled", 0, 0, 0, 0, 0,  NULL);
 	}
+	else if(RNA_struct_is_a(itemptr->type, &RNA_RigidBodyWorld)) {
+		uiItemL(sub, name, icon);
+		uiBlockSetEmboss(block, UI_EMBOSS);
+		uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "enabled", 0, 0, 0, 0, 0,  NULL);
+	}
 	else if(itemptr->type == &RNA_ShapeKey) {
 		ob= (Object*)activeptr->data;
 

Modified: branches/soc-2010-aligorith-2/source/blender/makesrna/SConscript
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesrna/SConscript	2010-06-28 23:55:31 UTC (rev 29781)
+++ branches/soc-2010-aligorith-2/source/blender/makesrna/SConscript	2010-06-29 03:06:21 UTC (rev 29782)
@@ -9,6 +9,7 @@
 incs = '#/intern/guardedalloc #/intern/audaspace/intern ../blenkernel ../blenlib ../makesdna intern .'
 incs += ' ../windowmanager ../editors/include ../gpu ../imbuf ../ikplugin'
 incs += ' ../render/extern/include'
+incs += ' ../rigidbody'
 
 defs = []
 

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-28 23:55:31 UTC (rev 29781)
+++ branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c	2010-06-29 03:06:21 UTC (rev 29782)
@@ -23,11 +23,13 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "RNA_define.h"
 
 #include "rna_internal.h"
 
+#include "DNA_group_types.h"
 #include "DNA_object_types.h"
 #include "DNA_rigidbody_types.h"
 #include "DNA_scene_types.h"
@@ -48,17 +50,85 @@
 	// XXX: rest of shapes have yet to be implemented...
 	{0, NULL, 0, NULL, NULL}};
 
+
 #ifdef RNA_RUNTIME
 
-static void rna_RigidBodyOb_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+#include "RBI_api.h"
+
+/* ******************************** */
+
+static void rna_RigidBodyWorld_name_get(PointerRNA *ptr, char *value)
 {
-	// 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;
+	RigidBodyWorld *rbw = (RigidBodyWorld *)ptr->data;
+
+	if (rbw->group)
+		strcpy(value, rbw->group->id.name+2);
+	else
+		strcpy(value, "<Empty World>");
+}
+
+static int rna_RigidBodyWorld_name_length(PointerRNA *ptr)
+{
+	RigidBodyWorld *rbw = (RigidBodyWorld *)ptr->data;
 	
-	//BKE_rigidbody_update_object(rbw, ob);
+	if (rbw->group)
+		return strlen(rbw->group->id.name+2);
+	else
+		return strlen("<Empty World>");
 }
 
+/* ******************************** */
+
+static void rna_RigidBodyOb_type_set(PointerRNA *ptr, int value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* set new type of object */
+	rbo->type = value;
+	
+	/* do physics sim updates */
+	if (rbo->physics_object) {
+		/* 'mass' that gets used by RigidBody depends on type - only dynamic/active RB's have mass */
+		// TODO: abstract this a bit - maybe with a simple macro...
+		if (rbo->type == RBO_TYPE_ACTIVE)
+			rbBodySetMass(rbo->physics_object, rbo->mass);
+		else
+			rbBodySetMass(rbo->physics_object, 0.0f);
+	}
+}
+
+static void rna_RigidBodyOb_shape_set(PointerRNA *ptr, int value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	Object *ob = (Object *)ptr->id.data;
+	
+	/* set new shape type */
+	// FIMXE: need an API call for this...
+	rbo->shape = value;
+}
+
+
+static void rna_RigidBodyOb_mass_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* store new mass */
+	rbo->mass = value;
+	
+	/* update mass if necessary - only active bodies need the mass */
+	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE))
+		rbBodySetMass(rbo->physics_object, value);
+}
+
+static void rna_RigidBodyOb_friction_set(PointerRNA *ptr, float value)
+{
+	RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+	
+	/* need to update the RigidBody's copy as well as the stored value too */
+	rbo->friction = value;
+	rbBodySetFriction(rbo->physics_object, value);
+}
+
 #else
 
 static void rna_def_rigidbody_world(BlenderRNA *brna)
@@ -70,6 +140,17 @@
 	RNA_def_struct_sdna(srna, "RigidBodyWorld");
 	RNA_def_struct_ui_text(srna, "Rigid Body World", "Self-contained rigid body simulation environment and settings");
 	
+	/* name 
+	 *	- this refers to the name of the associated group only
+	 *	  so don't let this be editable for now...
+	 */
+	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+	RNA_def_property_string_funcs(prop, "rna_RigidBodyWorld_name_get", "rna_RigidBodyWorld_name_length", NULL);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Name", "Rigid Body World name");
+	RNA_def_property_update(prop, NC_SCENE, NULL);
+	RNA_def_struct_name_property(srna, prop);
+	
 	/* group */
 	// TODO: need to be able to check that same group isn't used more than once
 	prop= RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
@@ -79,9 +160,9 @@
 	RNA_def_property_update(prop, NC_SCENE, NULL);
 	
 	/* settings */
-	prop=RNA_def_property(srna, "muted", PROP_BOOLEAN, PROP_NONE); 
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", RBW_FLAG_MUTED);
-	RNA_def_property_ui_text(prop, "Muted", "Simulation will not be skipped during evaluation");
+	prop=RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE); 
+	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", RBW_FLAG_MUTED);
+	RNA_def_property_ui_text(prop, "Enabled", "Simulation will be evaluated");
 	RNA_def_property_update(prop, NC_SCENE, NULL);
 	
 	// XXX: temp setting... maybe we'll have a more elegant solution later when settings force updates automatically...
@@ -94,10 +175,10 @@
 	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:
 	//	- expose rest of settings relevant to sim world
 }
@@ -115,21 +196,32 @@
 	prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "type");
 	RNA_def_property_enum_items(prop, rigidbody_ob_type_items);
+	RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyOb_type_set", NULL);
 	RNA_def_property_ui_text(prop, "Type", "Role of object in Rigid Body Simulations");
 	// TODO: setup necessary updates for this setting
 	
 	prop= RNA_def_property(srna, "collision_shape", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "shape");
 	RNA_def_property_enum_items(prop, rigidbody_ob_shape_items);
+	RNA_def_property_enum_funcs(prop, NULL, "rna_RigidBodyOb_shape_set", NULL);
 	RNA_def_property_ui_text(prop, "Collision Shape", "Collision Shape of object in Rigid Body Simulations");
 	// TODO: setup necessary updates for this setting
 	
 	/* Physics Parameters */
 	prop= RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "mass");
-	RNA_def_property_ui_text(prop, "Mass", "");
+	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // range must always be positive (and non-zero)
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_mass_set", NULL);
+	RNA_def_property_ui_text(prop, "Mass", "How much the object 'weighs' irrespective of gravity");
 	// TODO: setup necessary updates for this setting
 	
+	prop= RNA_def_property(srna, "friction", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "friction");
+	RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // XXX: this needs checking
+	RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyOb_friction_set", NULL);
+	RNA_def_property_ui_text(prop, "Friction", "Resistance of object to movement");
+	// TODO: setup necessary updates for this setting
+	
 	// TODO:
 	//	- expose rest of settings relevant to sim ob
 }

Modified: branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp	2010-06-28 23:55:31 UTC (rev 29781)
+++ branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp	2010-06-29 03:06:21 UTC (rev 29782)
@@ -281,7 +281,6 @@
 
 void rbBodySetLinearDamping(rbRigidBody *object, float value)
 {
-	btRigidBody *body = reinterpret_cast<btRigidBody*>(object);
 	rbBodySetDamping(object, value, rbBodyGetLinearDamping(object));
 }
 
@@ -381,6 +380,7 @@
 void rbBodySetActivationState(rbRigidBody *object, int state)
 {
 	btRigidBody *body = reinterpret_cast<btRigidBody*>(object);
+	// XXX...
 }
 
 /* Simulation ----------------------- */





More information about the Bf-blender-cvs mailing list