[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23122] branches/itasc/source/blender: BGE : don't use fixed number of substep.

Benoit Bolsee benoit.bolsee at online.be
Fri Sep 11 11:13:25 CEST 2009


Revision: 23122
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23122
Author:   ben2610
Date:     2009-09-11 11:13:25 +0200 (Fri, 11 Sep 2009)

Log Message:
-----------
BGE: don't use fixed number of substep. It doesn't make sense since the duration of frame is variable. Instead, convert the number of substeps into a target substep duration when creating the iTaSC scene.

Modified Paths:
--------------
    branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
    branches/itasc/source/blender/makesdna/DNA_action_types.h

Modified: branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
===================================================================
--- branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp	2009-09-11 09:09:54 UTC (rev 23121)
+++ branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp	2009-09-11 09:13:25 UTC (rev 23122)
@@ -675,7 +675,7 @@
 	iktarget->blenderConstraint->lin_error = (float)(values->values[0].y - values->values[0].yd);
 }
 
-static IK_Scene* convert_tree(Object *ob, bPoseChannel *pchan)
+static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan)
 {
 	PoseTree *tree = (PoseTree*)pchan->iktree.first;
 	PoseTarget *target;
@@ -709,8 +709,23 @@
 	if (!ingame)
 		ikscene->cache = new iTaSC::Cache();
 	ikparam = (bItasc*)ob->pose->ikparam;
-	if (!ikparam)
+	if (!ikparam) {
+		// you must have our own copy
 		ikparam = &DefIKParam;
+	} else if (ingame) {
+		// tweak the param when in game to have efficient stepping
+		// using fixed substep is not effecient since frames in the GE are often
+		// shorter than in animation => move to auto step automatically and set
+		// the target substep duration via min/max
+		if (!(ikparam->flag & ITASC_AUTO_STEP)) {
+			float timestep = blscene->r.frs_sec_base/blscene->r.frs_sec;
+			if (ikparam->numstep > 0)
+				timestep /= ikparam->numstep;
+			// with equal min and max, the algorythm will take this step and the indicative substep most of the time
+			ikparam->minstep = ikparam->maxstep = timestep;
+			ikparam->flag |= ITASC_AUTO_STEP;
+		}
+	}
 	switch (ikparam->solver) {
 	case ITASC_SOLVER_SDLS:
 		ikscene->solver = new iTaSC::WSDLSSolver();
@@ -1160,21 +1175,21 @@
 	return ikscene;
 }
 
-static void create_scene(Object *ob)
+static void create_scene(Scene *scene, Object *ob)
 {
 	bPoseChannel *pchan;
 
-	// create the scene
+	// create the IK scene
 	for(pchan= (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
 		// by construction there is only one tree
 		PoseTree *tree = (PoseTree*)pchan->iktree.first;
 		if (tree) {
 			// convert tree in iTaSC::Scene
-			IK_Scene* scene = convert_tree(ob, pchan);
-			if (scene) {
+			IK_Scene* ikscene = convert_tree(scene, ob, pchan);
+			if (ikscene) {
 				IK_Data* ikdata = get_ikdata(ob->pose);
-				scene->next = ikdata->first;
-				ikdata->first = scene;
+				ikscene->next = ikdata->first;
+				ikdata->first = ikscene;
 			}
 			// delete the trees once we are done
 			while(tree) {
@@ -1350,7 +1365,7 @@
 	}
 	// if at least one tree, create the scenes from the PoseTree stored in the channels 
 	if (count)
-		create_scene(ob);
+		create_scene(scene, ob);
 	itasc_update_param(ob->pose);
 	// make sure we don't rebuilt until the user changes something important
 	ob->pose->flag &= ~POSE_WAS_REBUILT;

Modified: branches/itasc/source/blender/makesdna/DNA_action_types.h
===================================================================
--- branches/itasc/source/blender/makesdna/DNA_action_types.h	2009-09-11 09:09:54 UTC (rev 23121)
+++ branches/itasc/source/blender/makesdna/DNA_action_types.h	2009-09-11 09:13:25 UTC (rev 23122)
@@ -210,7 +210,7 @@
 	/* NOTE: space is reserved here for 18 other possible 
 	 * euler rotation orders not implemented 
 	 */
-	PCHAN_ROT_MAX,	/* sentinel */
+	PCHAN_ROT_MAX,	/* sentinel for Py API*/
 		/* axis angle rotations */
 	PCHAN_ROT_AXISANGLE = -1
 } ePchan_RotMode;





More information about the Bf-blender-cvs mailing list