[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21825] branches/itasc: iTaSC: external contraint support in GE part 3: new BL_ArmatureActuator.

Benoit Bolsee benoit.bolsee at online.be
Thu Jul 23 23:19:39 CEST 2009


Revision: 21825
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21825
Author:   ben2610
Date:     2009-07-23 23:19:37 +0200 (Thu, 23 Jul 2009)

Log Message:
-----------
iTaSC: external contraint support in GE part 3: new BL_ArmatureActuator.

This actuator gives access to one constraint in the armature.
The parameters are bone name, constraint name and target object.
The constraint is identified by bone and constraint name.
The target object points to a game object that will be used
to update the constraint target during the game, allowing to 
track external objects.

By creating an actuator on a specific constraint, you disable
this constraint by default (the pose solver will skip it).
By making the actuator active, you force an evaluation of the
armature on each frame and you enable the corresponding 
constraint. You can enable/disable constraint during the game.

The actuator 'target' attribute can be used to change the target
during the game. You can pass an object reference or an object
name. 

Constraints can be mixed with Actions as long as they operate
on different bones. If an action updates a bone that is also
controlled by a constraint, the constraint overwrites the
action channel.

This feature works with the old and new solver.

Know limitations:
- There is no automatic translation of Armature constraints into
  Armature actuators. You must explicitely create an actuator
  and activate it if you want to activate a constraint with 
  external target in the GE. There is no need to create an
  actuator forr constraints with internal target (=armature itself).
- There is no automatic translation of Constraint target from 
  Blender to Actuator. You must manually put the same target in
  the Actuator if you want to enable the constraint in the GE
  and make it track the same object.
- A constraint with an external target but no Armature Actuator
  will stay active in the GE but will track the target at its
  Blender position and not GE position. However, the armature
  pose will be influenced by the armature position in the GE
  (new in this release). This creates a backward compatibility
  issue for games that were using constraints with external target
  (not frequent).
- Constraints with more than one target are not correctly 
  handled. Ex: IK constraint with polar target.

Modified Paths:
--------------
    branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj
    branches/itasc/source/blender/blenkernel/BKE_constraint.h
    branches/itasc/source/blender/blenkernel/intern/sca.c
    branches/itasc/source/blender/blenloader/intern/readfile.c
    branches/itasc/source/blender/blenloader/intern/writefile.c
    branches/itasc/source/blender/makesdna/DNA_actuator_types.h
    branches/itasc/source/blender/makesdna/DNA_constraint_types.h
    branches/itasc/source/gameengine/Converter/BL_ActionActuator.cpp
    branches/itasc/source/gameengine/Converter/BL_ArmatureObject.cpp
    branches/itasc/source/gameengine/Converter/BL_ArmatureObject.h
    branches/itasc/source/gameengine/Converter/KX_ConvertActuators.cpp

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

Modified: branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj
===================================================================
--- branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/projectfiles_vc9/gameengine/converter/KX_converter.vcproj	2009-07-23 21:19:37 UTC (rev 21825)
@@ -481,6 +481,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureActuator.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureObject.cpp"
 				>
 			</File>
@@ -558,6 +562,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureActuator.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Converter\BL_ArmatureObject.h"
 				>
 			</File>

Modified: branches/itasc/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- branches/itasc/source/blender/blenkernel/BKE_constraint.h	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/blender/blenkernel/BKE_constraint.h	2009-07-23 21:19:37 UTC (rev 21825)
@@ -38,6 +38,9 @@
 struct bPoseChannel;
 
 /* ---------------------------------------------------------------------------- */
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /* special struct for use in constraint evaluation */
 typedef struct bConstraintOb {
@@ -130,6 +133,9 @@
 void get_constraint_target_matrix(struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime);
 void solve_constraints(struct ListBase *conlist, struct bConstraintOb *cob, float ctime);
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif
 

Modified: branches/itasc/source/blender/blenkernel/intern/sca.c
===================================================================
--- branches/itasc/source/blender/blenkernel/intern/sca.c	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/blender/blenkernel/intern/sca.c	2009-07-23 21:19:37 UTC (rev 21825)
@@ -415,12 +415,10 @@
 	act->data= 0;
 	
 	switch(act->type) {
-#ifdef __NLA
 	case ACT_ACTION:
 	case ACT_SHAPEACTION:
 		act->data= MEM_callocN(sizeof(bActionActuator), "actionact");
 		break;
-#endif
 	case ACT_SOUND:
 		act->data= MEM_callocN(sizeof(bSoundActuator), "soundact");
 		break;
@@ -474,6 +472,9 @@
 	case ACT_STATE:
         act->data = MEM_callocN(sizeof( bStateActuator ), "state act");
         break;
+	case ACT_ARMATURE:
+        act->data = MEM_callocN(sizeof( bArmatureActuator ), "armature act");
+        break;
 	default:
 		; /* this is very severe... I cannot make any memory for this        */
 		/* logic brick...                                                    */

Modified: branches/itasc/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/itasc/source/blender/blenloader/intern/readfile.c	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/blender/blenloader/intern/readfile.c	2009-07-23 21:19:37 UTC (rev 21825)
@@ -3516,6 +3516,10 @@
 				else if(act->type==ACT_STATE) {
 					/* bStateActuator *statea = act->data; */
 				}
+				else if(act->type==ACT_ARMATURE) {
+					bArmatureActuator *arma= act->data;
+					arma->target= newlibadr(fd, ob->id.lib, arma->target);
+				}
 				act= act->next;
 			}
 			
@@ -10156,11 +10160,19 @@
 			bObjectActuator *oa= act->data;
 			expand_doit(fd, mainvar, oa->reference);
 		}
+		else if(act->type==ACT_ADD_OBJECT) {
+			bAddObjectActuator *aoa= act->data;
+			expand_doit(fd, mainvar, aoa->ob);
+		}
 		else if(act->type==ACT_SCENE) {
 			bSceneActuator *sa= act->data;
 			expand_doit(fd, mainvar, sa->camera);
 			expand_doit(fd, mainvar, sa->scene);
 		}
+		else if(act->type==ACT_2DFILTER) {
+			bTwoDFilterActuator *tdfa= act->data;
+			expand_doit(fd, mainvar, tdfa->text);
+		}
 		else if(act->type==ACT_ACTION) {
 			bActionActuator *aa= act->data;
 			expand_doit(fd, mainvar, aa->act);
@@ -10177,6 +10189,14 @@
 			bMessageActuator *ma= act->data;
 			expand_doit(fd, mainvar, ma->toObject);
 		}
+		else if(act->type==ACT_PARENT) {
+			bParentActuator *pa= act->data;
+			expand_doit(fd, mainvar, pa->ob);
+		}
+		else if(act->type==ACT_ARMATURE) {
+			bArmatureActuator *arma= act->data;
+			expand_doit(fd, mainvar, arma->target);
+		}
 		act= act->next;
 	}
 

Modified: branches/itasc/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/itasc/source/blender/blenloader/intern/writefile.c	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/blender/blenloader/intern/writefile.c	2009-07-23 21:19:37 UTC (rev 21825)
@@ -778,6 +778,9 @@
 		case ACT_STATE:
 			writestruct(wd, DATA, "bStateActuator", 1, act->data);
 			break;
+		case ACT_ARMATURE:
+			writestruct(wd, DATA, "bArmatureActuator", 1, act->data);
+			break;
 		default:
 			; /* error: don't know how to write this file */
 		}

Modified: branches/itasc/source/blender/makesdna/DNA_actuator_types.h
===================================================================
--- branches/itasc/source/blender/makesdna/DNA_actuator_types.h	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/blender/makesdna/DNA_actuator_types.h	2009-07-23 21:19:37 UTC (rev 21825)
@@ -144,7 +144,7 @@
 	char name[32];		/* property or groupkey */
 	
 	short pad[3], cur, butsta, butend;/* not referenced, can remove? */
-	struct Group *group;		/* only during game */
+	/* struct Group *group;		not used, remove */
 	
 } bGroupActuator;
 
@@ -226,6 +226,12 @@
 	unsigned int mask;	/* the bits to change */
 } bStateActuator;
 
+typedef struct bArmatureActuator {
+	char posechannel[32];
+	char constraint[32];
+	struct Object *target;
+} bArmatureActuator;
+
 typedef struct bActuator {
 	struct bActuator *next, *prev, *mynew;
 	short type;
@@ -298,6 +304,7 @@
 #define ACT_PARENT      20
 #define ACT_SHAPEACTION 21
 #define ACT_STATE		22
+#define ACT_ARMATURE	23
 
 /* actuator flag */
 #define ACT_SHOW		1

Modified: branches/itasc/source/blender/makesdna/DNA_constraint_types.h
===================================================================
--- branches/itasc/source/blender/makesdna/DNA_constraint_types.h	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/blender/makesdna/DNA_constraint_types.h	2009-07-23 21:19:37 UTC (rev 21825)
@@ -375,7 +375,9 @@
 		/* influence ipo is on constraint itself, not in action channel */
 	CONSTRAINT_OWN_IPO	= (1<<7),
 		/* indicates that constraint was added locally (i.e.  didn't come from the proxy-lib) */
-	CONSTRAINT_PROXY_LOCAL = (1<<8)
+	CONSTRAINT_PROXY_LOCAL = (1<<8),
+		/* indicates that constraint is temporarily disabled (only used in GE) */
+	CONSTRAINT_OFF = (1<<9)
 } B_CONSTRAINT_FLAG;
 
 /* bConstraint->ownspace/tarspace */

Modified: branches/itasc/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- branches/itasc/source/gameengine/Converter/BL_ActionActuator.cpp	2009-07-23 20:50:24 UTC (rev 21824)
+++ branches/itasc/source/gameengine/Converter/BL_ActionActuator.cpp	2009-07-23 21:19:37 UTC (rev 21825)
@@ -950,7 +950,7 @@
 		
 		if (!m_userpose) {
 			obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
-			game_copy_pose(&m_userpose, m_pose);
+			game_copy_pose(&m_userpose, m_pose, 0);
 		}
 		pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
 		
@@ -969,7 +969,7 @@
 		// same as above
 		if (!m_userpose) {
 			obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
-			game_copy_pose(&m_userpose, m_pose);
+			game_copy_pose(&m_userpose, m_pose, 0);
 		}
 		pchan= verify_pose_channel(m_userpose, string);
 		

Added: branches/itasc/source/gameengine/Converter/BL_ArmatureActuator.cpp
===================================================================
--- branches/itasc/source/gameengine/Converter/BL_ArmatureActuator.cpp	                        (rev 0)
+++ branches/itasc/source/gameengine/Converter/BL_ArmatureActuator.cpp	2009-07-23 21:19:37 UTC (rev 21825)
@@ -0,0 +1,267 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "DNA_action_types.h"
+#include "DNA_constraint_types.h"
+#include "BKE_constraint.h"
+#include "BLI_arithb.h"
+#include "BL_ArmatureActuator.h"
+
+/**
+ * This class is the conversion of the Pose channel constraint.
+ * It makes a link between the pose constraint and the KX scene.
+ * The main purpose is to give access to the constraint target 
+ * to link it to a game object. 
+ * It also allows to activate/deactivate constraints during the game.
+ * Later it will also be possible to create constraint on the fly
+ */
+
+BL_ArmatureActuator::BL_ArmatureActuator(SCA_IObject* obj,
+						const char *posechannel,
+						const char *constraintname,
+						KX_GameObject* targetobj) :
+	SCA_IActuator(obj, KX_ACT_ARMATURE),
+	m_constraint(NULL),
+	m_gametarget(targetobj),
+	m_posechannel(posechannel),
+	m_constraintname(constraintname),
+	m_blendtarget(NULL)
+{
+	if (m_gametarget)
+		m_gametarget->RegisterActuator(this);
+	memset(m_blendmat, 0, sizeof(m_blendmat));
+	FindConstraint();
+}
+
+BL_ArmatureActuator::~BL_ArmatureActuator()
+{
+	if (m_gametarget)
+		m_gametarget->UnregisterActuator(this);
+}
+
+void BL_ArmatureActuator::ProcessReplica()
+{
+	// the replica is tracking the same object => register it (this may be changed in Relnk())
+	if (m_gametarget)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list