[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22801] branches/itasc: iTaSC: Complete rework of the Armature constraint system in the GE

Benoit Bolsee benoit.bolsee at online.be
Wed Aug 26 12:35:42 CEST 2009


Revision: 22801
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22801
Author:   ben2610
Date:     2009-08-26 12:35:42 +0200 (Wed, 26 Aug 2009)

Log Message:
-----------
iTaSC: Complete rework of the Armature constraint system in the GE

Previously, an Armature Actuator was necessary to get
a bone constraint working in the GE. This is no longer
necessary: all bone constraints are automatically
converted to BL_ArmatureConstraint objects and attached
to the Armature. This object is a proxy to the internal
bConstraint structure and links constraint targets to
game objects. It is also a Python 'aware' class which
will provide in a future release a complete API to access
the bone constraint in game scripts.
 
The BL_ArmatureConstraint object opens the door to
dynamically created constraints. For the time being, the
constraint are statically converted and individually
controllable but cannot be deleted or created on the fly.

The Armature actuator still exists but it simply used
to update the internal bConstraint structure via the
BL_ArmatureConstraint object. When the BL_ArmatureConstraint
Python API will be available, it will no longer be 
required to have Armature actuators to operate the constraints.
Five type of actions are now provided:
Run: this is the only persistent mode of the actuator. 
     Once activated, it stays active untill deactivated.
     It simply ensures that the armature will be updated
     during the next graphic frame.
     Note: the fact that the armature is only updated
     during a graphic frame is an issue that will be 
     resolved later.
Enable: the designated constraint is enabled.
     Note: constraints are enabled by default at
     conversion time.
Disable: the designated constraint is disabled. It will
     have no effect on the armature. Note that it also
     disables the update of the constraint error.
Set target: The constraint target and subtarget of the
     designated constraint are changed to different game
     objects.
Set weight: The weight of the designated constraint is
     changed. Setting the weight to 0 is equivalent to 
     disabling the constraint except that the constraint
     error keeps being updated.
     Note: this action is only meaningful to IK constraints.

Modified Paths:
--------------
    branches/itasc/intern/itasc/Distance.cpp
    branches/itasc/intern/itasc/Distance.hpp
    branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj
    branches/itasc/source/blender/editors/space_logic/logic_window.c
    branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
    branches/itasc/source/blender/makesdna/DNA_actuator_types.h
    branches/itasc/source/gameengine/Converter/BL_ArmatureActuator.cpp
    branches/itasc/source/gameengine/Converter/BL_ArmatureActuator.h
    branches/itasc/source/gameengine/Converter/BL_ArmatureObject.cpp
    branches/itasc/source/gameengine/Converter/BL_ArmatureObject.h
    branches/itasc/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/itasc/source/gameengine/Converter/KX_ConvertActuators.cpp
    branches/itasc/source/gameengine/GameLogic/SCA_IObject.cpp
    branches/itasc/source/gameengine/GameLogic/SCA_IObject.h
    branches/itasc/source/gameengine/SceneGraph/SG_DList.h

Added Paths:
-----------
    branches/itasc/source/gameengine/Converter/BL_ArmatureConstraint.cpp
    branches/itasc/source/gameengine/Converter/BL_ArmatureConstraint.h

Modified: branches/itasc/intern/itasc/Distance.cpp
===================================================================
--- branches/itasc/intern/itasc/Distance.cpp	2009-08-26 10:27:04 UTC (rev 22800)
+++ branches/itasc/intern/itasc/Distance.cpp	2009-08-26 10:35:42 UTC (rev 22801)
@@ -275,6 +275,19 @@
 	return true;
 }
 
+const ConstraintValues* Distance::getControlParameters(unsigned int* _nvalues)
+{
+	*(double*)&m_data.y = m_chi(2);
+	*(double*)&m_data.ydot = m_ydot(0);
+	m_data.yd = m_yd;
+	m_data.yddot = m_yddot;
+	m_data.action = 0;
+	m_values.action = 0;
+	if (_nvalues) 
+		*_nvalues=1; 
+	return &m_values; 
+}
+
 void Distance::updateControlOutput(const Timestamp& timestamp)
 {
 	bool cacheAvail = true;

Modified: branches/itasc/intern/itasc/Distance.hpp
===================================================================
--- branches/itasc/intern/itasc/Distance.hpp	2009-08-26 10:27:04 UTC (rev 22800)
+++ branches/itasc/intern/itasc/Distance.hpp	2009-08-26 10:35:42 UTC (rev 22801)
@@ -35,8 +35,7 @@
     virtual ~Distance();
 
 	virtual bool setControlParameters(struct ConstraintValues* _values, unsigned int _nvalues, double timestep);
-	virtual const ConstraintValues* getControlParameters(unsigned int* _nvalues) 
-		{ if (_nvalues) *_nvalues=1; return &m_values; }
+	virtual const ConstraintValues* getControlParameters(unsigned int* _nvalues);
 
 private:
 	bool computeChi(Frame& pose);

Modified: branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj
===================================================================
--- branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj	2009-08-26 10:27:04 UTC (rev 22800)
+++ branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj	2009-08-26 10:35:42 UTC (rev 22801)
@@ -485,6 +485,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureConstraint.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureObject.cpp"
 				>
 			</File>
@@ -566,6 +570,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureConstraint.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureObject.h"
 				>
 			</File>

Modified: branches/itasc/source/blender/editors/space_logic/logic_window.c
===================================================================
--- branches/itasc/source/blender/editors/space_logic/logic_window.c	2009-08-26 10:27:04 UTC (rev 22800)
+++ branches/itasc/source/blender/editors/space_logic/logic_window.c	2009-08-26 10:35:42 UTC (rev 22801)
@@ -1747,7 +1747,7 @@
 
 static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
 {
-	int shift= 0; // XXX
+	int shift= 1; // XXX
 	unsigned int *cont_mask = arg2_mask;
 	uiBut *but = arg1_but;
 
@@ -2811,26 +2811,42 @@
 	case ACT_ARMATURE:
   		armAct = act->data; 
 
-		ysize= 68; 
+		if (ob->type == OB_ARMATURE) {
+			str= "Constraint %t|Run armature %x0|Enable %x1|Disable %x2|Set target %x3|Set weight %x4";
+			uiDefButI(block, MENU, B_REDR, str,		xco+5, yco-24, (width-10)*0.35, 19, &armAct->type, 0.0, 0.0, 0, 0, ""); 
+
+			switch (armAct->type) {
+			case ACT_ARM_RUN:
+				ysize = 28;
+				break;
+			default:
+				uiBlockBeginAlign(block);
+				but = uiDefBut(block, TEX, 1, "Bone: ",
+						(xco+5), (yco-44), (width-10)/2, 19,
+						armAct->posechannel, 0, 31, 0, 0,
+						"Bone on which the constraint is defined");
+				uiButSetFunc(but, check_armature_actuator, but, armAct);
+				but = uiDefBut(block, TEX, 1, "Cons: ",
+						(xco+5)+(width-10)/2, (yco-44), (width-10)/2, 19,
+						armAct->constraint, 0, 31, 0, 0,
+						"Name of the constraint you want to controle");
+				uiButSetFunc(but, check_armature_actuator, but, armAct);
+				uiBlockEndAlign(block);
+				ysize = 48;
+				switch (armAct->type) {
+				case ACT_ARM_SETTARGET:
+					uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "Target: ",		xco+5, yco-64, (width-10), 19, &(armAct->target), "Set this object as the target of the constraint"); 
+					uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "Secondary Target: ",		xco+5, yco-84, (width-10), 19, &(armAct->subtarget), "Set this object as the secondary target of the constraint (only IK polar target at the moment)"); 
+					ysize += 40;
+					break;
+				case ACT_ARM_SETWEIGHT:
+					uiDefButF(block, NUM, B_REDR, "Weight:", xco+5+(width-10)*0.35,yco-24,(width-10)*0.65,19,&armAct->weight,0.0,1.0,0.0,0.0,"Set weight of this constraint");
+					break;
+				}
+			}
+  		}
 		glRects(xco, yco-ysize, xco+width, yco); 
 		uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
-		if (ob->type == OB_ARMATURE) {
-			uiBlockBeginAlign(block);
-			but = uiDefBut(block, TEX, 1, "Bone: ",
-					(xco+5), (yco-24), (width-10)/2, 19,
-					armAct->posechannel, 0, 31, 0, 0,
-					"Bone on which the constraint is defined");
-			uiButSetFunc(but, check_armature_actuator, but, armAct);
-			but = uiDefBut(block, TEX, 1, "Cons: ",
-					(xco+5)+(width-10)/2, (yco-24), (width-10)/2, 19,
-					armAct->constraint, 0, 31, 0, 0,
-					"Name of the constraint you want to controle");
-			uiButSetFunc(but, check_armature_actuator, but, armAct);
-			uiBlockEndAlign(block);
-			uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "Target: ",		xco+5, yco-44, (width-10), 19, &(armAct->target), "Set this object as the target of the constraint"); 
-			uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "Secondary Target: ",		xco+5, yco-64, (width-10), 19, &(armAct->subtarget), "Set this object as the secondary target of the constraint (only IK polar target at the moment)"); 
-  		}
-
   		yco-= ysize; 
   		break; 
 

Modified: branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
===================================================================
--- branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp	2009-08-26 10:27:04 UTC (rev 22800)
+++ branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp	2009-08-26 10:35:42 UTC (rev 22801)
@@ -74,6 +74,8 @@
 
 typedef float Vector3[3];
 typedef float Vector4[4];
+struct IK_Target;
+typedef void (*ErrorCallback)(const iTaSC::ConstraintValues* values, unsigned int nvalues, IK_Target* iktarget);
 
 // one structure for each target in the scene
 struct IK_Target
@@ -82,6 +84,7 @@
 	iTaSC::ConstraintSet*	constraint;
 	struct bConstraint*		blenderConstraint;
 	Object*					owner;			//for auto IK
+	ErrorCallback			errorCallback;
 	std::string				targetName;
 	std::string				constraintName;
 	unsigned int			controlType;
@@ -547,14 +550,47 @@
 	if (!ikparam) 
 		ikparam = &DefIKParam;
 
+	if (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) {
+		if (iktarget->controlType & iTaSC::CopyPose::CTL_POSITION) {
+			values->alpha = 0.0;
+			values->action = iTaSC::ACT_ALPHA;
+			values++;
+		}
+		if (iktarget->controlType & iTaSC::CopyPose::CTL_ROTATION) {
+			values->alpha = 0.0;
+			values->action = iTaSC::ACT_ALPHA;
+			values++;
+		}
+	} else {
+		if (iktarget->controlType & iTaSC::CopyPose::CTL_POSITION) {
+			// update error
+			values->alpha = condata->weight;
+			values->feedback = ikparam->feedback;
+			values->action = iTaSC::ACT_ALPHA|iTaSC::ACT_FEEDBACK;
+			values++;
+		}
+		if (iktarget->controlType & iTaSC::CopyPose::CTL_ROTATION) {
+			// update error
+			values->alpha = condata->orientweight;
+			values->feedback = ikparam->feedback;
+			values->action = iTaSC::ACT_ALPHA|iTaSC::ACT_FEEDBACK;
+			values++;
+		}
+	}
+	return true;
+}
+
+static void copypose_error(const iTaSC::ConstraintValues* values, unsigned int nvalues, IK_Target* iktarget)
+{
+	iTaSC::ConstraintSingleValue* value;
+	double error;
+	int i;
+
 	if (iktarget->controlType & iTaSC::CopyPose::CTL_POSITION) {
 		// update error
 		for (i=0, error=0.0, value=values->values; i<values->number; ++i, ++value)
 			error += KDL::sqr(value->y - value->yd);
 		iktarget->blenderConstraint->lin_error = (float)KDL::sqrt(error);
-		values->alpha = (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) ? 0.0 : condata->weight;
-		values->feedback = ikparam->feedback;
-		values->action = iTaSC::ACT_ALPHA|iTaSC::ACT_FEEDBACK;
 		values++;
 	}
 	if (iktarget->controlType & iTaSC::CopyPose::CTL_ROTATION) {
@@ -562,12 +598,8 @@
 		for (i=0, error=0.0, value=values->values; i<values->number; ++i, ++value)
 			error += KDL::sqr(value->y - value->yd);
 		iktarget->blenderConstraint->rot_error = (float)KDL::sqrt(error);
-		values->alpha = (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) ? 0.0 : condata->orientweight;
-		values->feedback = ikparam->feedback;
-		values->action = iTaSC::ACT_ALPHA|iTaSC::ACT_FEEDBACK;
 		values++;
 	}
-	return true;
 }
 
 static bool distance_callback(const iTaSC::Timestamp& timestamp, iTaSC::ConstraintValues* const _values, unsigned int _nvalues, void* _param)
@@ -595,29 +627,33 @@
 			values->alpha = condata->weight;
 			break;
 		}	
-	}
-	if (!timestamp.substep) {
-		// only update value on first timestep
-		iktarget->blenderConstraint->lin_error = (float)(values->values[0].y - values->values[0].yd);
-		switch (condata->mode) {
-		case LIMITDIST_INSIDE:
-			values->values[0].yd = condata->dist*0.95;
-			break;
-		case LIMITDIST_OUTSIDE:
-			values->values[0].yd = condata->dist*1.05;
-			break;
-		default:
-			values->values[0].yd = condata->dist;
-			break;
+		if (!timestamp.substep) {
+			// only update value on first timestep
+			switch (condata->mode) {
+			case LIMITDIST_INSIDE:
+				values->values[0].yd = condata->dist*0.95;
+				break;
+			case LIMITDIST_OUTSIDE:
+				values->values[0].yd = condata->dist*1.05;
+				break;
+			default:
+				values->values[0].yd = condata->dist;
+				break;
+			}
+			values->values[0].action = iTaSC::ACT_VALUE;
+			values->feedback = ikparam->feedback;
+			values->action |= iTaSC::ACT_FEEDBACK;
 		}
-		values->values[0].action = iTaSC::ACT_VALUE;
-		values->feedback = ikparam->feedback;
-		values->action |= iTaSC::ACT_FEEDBACK;
 	}
 	values->action |= iTaSC::ACT_ALPHA;
 	return true;
 }
 
+static void distance_error(const iTaSC::ConstraintValues* values, unsigned int _nvalues, IK_Target* iktarget)
+{
+	iktarget->blenderConstraint->lin_error = (float)(values->values[0].y - values->values[0].yd);
+}
+
 static IK_Scene* convert_tree(Object *ob, bPoseChannel *pchan)
 {
 	PoseTree *tree = (PoseTree*)pchan->iktree.first;
@@ -1104,6 +1140,7 @@
 				if (controltype & iTaSC::CopyPose::CTL_ROTATION)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list