[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29897] branches/soc-2010-aligorith-2: Bullet SoC - More UI/Property Tweaks...

Joshua Leung aligorith at gmail.com
Sat Jul 3 13:19:55 CEST 2010


Revision: 29897
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29897
Author:   aligorith
Date:     2010-07-03 13:19:55 +0200 (Sat, 03 Jul 2010)

Log Message:
-----------
Bullet SoC - More UI/Property Tweaks...

* Revamped UI for Rigid Body Worlds and Rigid Body Objects, with the latter now being split into two panels (Rigid Body, and Rigid Body Collision) to hopefully reveal the structure of the settings better. I'm still not too sure about whether one or two tweaks there make things harder to quickly set in practice, but hopefully there shouldn't be any problems :)

* Revamped the Scene settings regarding substeps. These are now available in the UI, and can be used to improve collision accuracy. 
-- Added new RB-API call which accomodates these settings, leaving the other version to do default values only, though that isn't used now...
-- Any files saved previously may now have some problems with playback. For reference/manual fixing, the 'Substeps' parameters should be 1/60 and 10.

* Added 'Reset' operator for Rigid Body Worlds, which changes the current frame to the 'start' frame for the world or worlds based on its primary parameter. 
-- The version called from the Scene buttons resets with respect to the current/active world only
-- Search for the other operator to use it. It will take the earliest start-frame value for a Rigid Body World in the Scene

Modified Paths:
--------------
    branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
    branches/soc-2010-aligorith-2/release/scripts/ui/properties_scene.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_edit.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
    branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h
    branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp

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-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py	2010-07-03 11:19:55 UTC (rev 29897)
@@ -21,10 +21,16 @@
 
 narrowui = bpy.context.user_preferences.view.properties_width_check
 
-class PHYSICS_PT_rigid_body(bpy.types.Panel):
+##########################
+
+class PHYSICS_PT_rigidbody_panel(bpy.types.Panel):
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
     bl_context = "physics"
+
+##########################
+
+class PHYSICS_PT_rigid_body(PHYSICS_PT_rigidbody_panel):
     bl_label = "Rigid Body"
 
     def poll(self, context):
@@ -52,26 +58,50 @@
             else:
                 split = layout.split()
             split.prop(rbo, "type", text="")
-
-            if wide_ui:
-                split = layout.split(percentage=0.3)
-                split.label(text="Collision Shape:")
-            else:
-                split = layout.split()
-            split.prop(rbo, "collision_shape", text="")
-
-            split = layout.split()
             
-            col = split.column()
+            col = layout.column()
             col.prop(rbo, "mass")
-            col.prop(rbo, "friction")
-            col.prop(rbo, "bounciness")
-            col.prop(rbo, "collision_margin")
             
 
+class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel):
+    bl_label = "Rigid Body Collisions"
 
+    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.3)
+            split.label(text="Shape:")
+        else:
+            split = layout.split()
+        split.prop(rbo, "collision_shape", text="")
+        
+        if wide_ui:
+            split = layout.split()
+        else:
+            split = layout
+        
+        col = split.column()
+        col.label(text="Surface Response:")
+        col.prop(rbo, "friction")
+        col.prop(rbo, "bounciness")
+        
+        col = split.column()
+        col.label(text="Sensitivity")
+        col.prop(rbo, "collision_margin", text="Margin")
+        
+##########################
+
 classes = [
-    PHYSICS_PT_rigid_body
+    PHYSICS_PT_rigid_body,
+    PHYSICS_PT_rigid_body_collisions
 ]
 
 def 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-07-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/release/scripts/ui/properties_scene.py	2010-07-03 11:19:55 UTC (rev 29897)
@@ -210,7 +210,23 @@
         if rbw:
             col = layout.column()
             col.prop(rbw, "group")
-            col.prop(rbw, "force_update", toggle=True) # XXX - nasty hack
+            
+            if wide_ui:
+                split = layout.split()
+            else:
+                split = layout
+            
+            col = split.column()
+            col.label(text="Range:")
+            col.prop(rbw, "frame_start")
+            #col.prop(rbw, "use_preview_range") # XXX: this option uses preview range extents for resetting the sim...
+            col.operator("rigidbody.world_reset", "Reset World").only_active = True
+            
+            col = split.column()
+            col.label(text="Substeps:")
+            col.prop(rbw, "fixed_time_step", text="Size")
+            col.prop(rbw, "max_sub_steps", text="Max Steps")
+            #col.prop(rbw, "force_update", toggle=True) # XXX - nasty hack
 
 
 class SCENE_PT_simplify(SceneButtonsPanel):

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-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c	2010-07-03 11:19:55 UTC (rev 29897)
@@ -298,9 +298,8 @@
 	rbw->ltime = CFRA - 1;
 	rbw->sframe = PSFRA;
 	
-	// XXX: review these
-	rbw->max_timestep = 1.0f;
-	rbw->substeps = 10;
+	rbw->fixed_timestep = 1.0f/60.0f; // Bullet default (60 Hz)
+	rbw->max_substeps = 10; // Bullet 'Hello World' demo default
 	
 	/* return this sim world */
 	return rbw;
@@ -569,9 +568,9 @@
 	if (timestep >= 0) {
 		/* step simulation by the requested timestep 
 		 *	- stepping by timestep = 0 doesn't affect/skew velocities, 
-		 * 	  so this step should be fine
+		 * 	  so this step then too should be fine 
 		 */
-		rbStepSimulation(rbw->physics_world, timestep);
+		rbStepSimulationAdv(rbw->physics_world, timestep, rbw->max_substeps, rbw->fixed_timestep);
 		
 		/* grab current scene settings from the physics world */
 		// TODO: could some of this be automated using motionstates?

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-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_intern.h	2010-07-03 11:19:55 UTC (rev 29897)
@@ -110,6 +110,8 @@
 void RIGIDBODY_OT_world_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_world_remove(struct wmOperatorType *ot);
 
+void RIGIDBODY_OT_world_reset(struct wmOperatorType *ot);
+
 /* rigidbody_object.c */
 void RIGIDBODY_OT_object_buttons_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_object_buttons_remove(struct wmOperatorType *ot);

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-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/physics_ops.c	2010-07-03 11:19:55 UTC (rev 29897)
@@ -85,8 +85,10 @@
 	
 	
 	WM_operatortype_append(RIGIDBODY_OT_world_add);	
-	WM_operatortype_append(RIGIDBODY_OT_world_remove);	
+	WM_operatortype_append(RIGIDBODY_OT_world_remove);
 	
+	WM_operatortype_append(RIGIDBODY_OT_world_reset);	
+	
 	WM_operatortype_append(RIGIDBODY_OT_object_buttons_add);	
 	WM_operatortype_append(RIGIDBODY_OT_object_buttons_remove);
 	

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-07-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/source/blender/editors/physics/rigidbody_edit.c	2010-07-03 11:19:55 UTC (rev 29897)
@@ -47,6 +47,7 @@
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_rigidbody.h"
+#include "BKE_sound.h"
 #include "BKE_utildefines.h"
 
 #include "RNA_access.h"
@@ -71,9 +72,8 @@
 	return (scene && scene->active_rigidbody_world);
 }
 
-
 /* ********************************************** */
-/* OPERATORS */
+/* OPERATORS - Management */
 
 /* ********** Add RigidBody World **************** */
 // TODO: if a group is specified, try adding with that group, otherwise, add new group...
@@ -146,3 +146,64 @@
 }
 
 /* ********************************************** */
+/* UTILITY OPERATORS */
+
+/* ********** Reset RigidBody World ************* */
+
+static int rigidbody_world_reset_exec (bContext *C, wmOperator *op)
+{
+	Scene *scene = CTX_data_scene(C);
+	int sframe = MAXFRAME;
+	
+	/* sanity checks */
+	if ELEM(NULL, scene, scene->rigidbody_worlds.first) {
+		BKE_report(op->reports, RPT_ERROR, "No Rigid Body Worlds to reset");
+		return OPERATOR_CANCELLED;
+	}
+	
+	/* find the earliest frame, or just the active world's start-frame */
+	if (RNA_boolean_get(op->ptr, "only_active") == 0) {
+		RigidBodyWorld *rbw;
+		
+		for (rbw = scene->rigidbody_worlds.first; rbw; rbw = rbw->next) {
+			if (rbw->sframe < sframe)
+				sframe = rbw->sframe;
+		}
+	}
+	else {
+		RigidBodyWorld *rbw = BKE_rigidbody_get_active_world(scene, 0);
+		
+		/* the active world should exist, otherwise poll() would have failed */
+		sframe = rbw->sframe;
+	}
+	
+	/* set new start frame, and force a recalc */
+	// TODO: do we need to notify the user that the frame has changed?
+	CFRA = sframe;
+	
+	sound_seek_scene(C);
+	WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+	
+	/* done */
+	return OPERATOR_FINISHED;
+}
+
+void RIGIDBODY_OT_world_reset (wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->idname = "RIGIDBODY_OT_world_reset";
+	ot->name = "Reset Rigid Body World";
+	ot->description = "Reset Rigid Body simulation world(s) for the current scene by jumping to the simulation start frame";
+	
+	/* callbacks */
+	ot->exec = rigidbody_world_reset_exec;
+	ot->poll = ED_rigidbody_world_active_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+	
+	/* properties */
+	ot->prop = RNA_def_boolean(ot->srna, "only_active", 0, "Only Active", "Reset only current Rigid Body World");
+}
+
+/* ********************************************** */

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-07-03 10:01:41 UTC (rev 29896)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h	2010-07-03 11:19:55 UTC (rev 29897)
@@ -50,16 +50,17 @@
 	/* Sim World Settings ------------------------------------------------------------- */
 	struct Group *group;		/* Group containing objects to use for Rigid Bodies */
 	
-	short flag;					/* (eRigidBodyWorld_Flag) settings for this RigidBodyWorld */
-	short recalc;				/* (eRigidBodyWorld_Recalc) flags set via Depsgraph/eval */
+	int sframe;					/* start frame of simulation - can be different to scene sfra, to allow for preroll */
+	float ltime;				/* last frame world was evaluated for (internal) */
 	
-		/* XXX: review these... */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list