[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21827] branches/itasc: iTaSC: external contraint support in GE part 4: 2. 5 UI and support of CONSTRAINT_OFF in the solver.
Benoit Bolsee
benoit.bolsee at online.be
Thu Jul 23 23:29:25 CEST 2009
Revision: 21827
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21827
Author: ben2610
Date: 2009-07-23 23:29:25 +0200 (Thu, 23 Jul 2009)
Log Message:
-----------
iTaSC: external contraint support in GE part 4: 2.5 UI and support of CONSTRAINT_OFF in the solver. Fix a problem in iTaSC where the initial pose was not correctly set in the GE. Fix a bug in Constraint template with NULL pointer.
Modified Paths:
--------------
branches/itasc/release/ui/space_view3d_toolbar.py
branches/itasc/source/blender/blenkernel/intern/constraint.c
branches/itasc/source/blender/editors/interface/interface_templates.c
branches/itasc/source/blender/editors/space_logic/logic_window.c
branches/itasc/source/blender/ikplugin/intern/iksolver_plugin.c
branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
branches/itasc/source/blender/makesrna/intern/rna_actuator.c
Modified: branches/itasc/release/ui/space_view3d_toolbar.py
===================================================================
--- branches/itasc/release/ui/space_view3d_toolbar.py 2009-07-23 21:21:40 UTC (rev 21826)
+++ branches/itasc/release/ui/space_view3d_toolbar.py 2009-07-23 21:29:25 UTC (rev 21827)
@@ -17,11 +17,11 @@
layout.row().itemO("OBJECT_OT_duplicate")
layout.row().itemO("OBJECT_OT_delete")
+ layout.row().itemO("OBJECT_OT_primitive_add")
layout.row().itemO("OBJECT_OT_mesh_add")
layout.row().itemO("OBJECT_OT_curve_add")
layout.row().itemO("OBJECT_OT_text_add")
layout.row().itemO("OBJECT_OT_surface_add")
- layout.row().itemO("OBJECT_OT_armature_add")
# ********** default tools for editmode_mesh ****************
Modified: branches/itasc/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/itasc/source/blender/blenkernel/intern/constraint.c 2009-07-23 21:21:40 UTC (rev 21826)
+++ branches/itasc/source/blender/blenkernel/intern/constraint.c 2009-07-23 21:29:25 UTC (rev 21827)
@@ -3597,7 +3597,7 @@
/* these we can skip completely (invalid constraints...) */
if (cti == NULL) continue;
- if (con->flag & CONSTRAINT_DISABLE) continue;
+ if (con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF)) continue;
/* these constraints can't be evaluated anyway */
if (cti->evaluate_constraint == NULL) continue;
/* influence == 0 should be ignored */
Modified: branches/itasc/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/itasc/source/blender/editors/interface/interface_templates.c 2009-07-23 21:21:40 UTC (rev 21826)
+++ branches/itasc/source/blender/editors/interface/interface_templates.c 2009-07-23 21:29:25 UTC (rev 21827)
@@ -616,19 +616,15 @@
ED_object_constraint_set_active(ob_v, con_v);
}
-static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
+static void verify_constraint_name_func (bContext *C, void *con_v, void *dummy)
{
Object *ob= CTX_data_active_object(C);
bConstraint *con= con_v;
- char oldname[32];
if (!con)
return;
- /* put on the stack */
- BLI_strncpy(oldname, (char *)name_v, 32);
-
- ED_object_constraint_rename(ob, con, oldname);
+ ED_object_constraint_rename(ob, con, NULL);
ED_object_constraint_set_active(ob, con);
// XXX allqueue(REDRAWACTION, 0);
}
Modified: branches/itasc/source/blender/editors/space_logic/logic_window.c
===================================================================
--- branches/itasc/source/blender/editors/space_logic/logic_window.c 2009-07-23 21:21:40 UTC (rev 21826)
+++ branches/itasc/source/blender/editors/space_logic/logic_window.c 2009-07-23 21:29:25 UTC (rev 21827)
@@ -38,6 +38,9 @@
#include "DNA_screen_types.h"
#include "DNA_sensor_types.h"
#include "DNA_sound_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_action_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
@@ -734,6 +737,8 @@
return "Parent";
case ACT_STATE:
return "State";
+ case ACT_ARMATURE:
+ return "Armature";
}
return "unknown";
}
@@ -746,7 +751,7 @@
switch (owner->type)
{
case OB_ARMATURE:
- return "Actuators %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
+ return "Actuators %t|Action %x15|Armature %x23|Motion %x0|Constraint %x9|Ipo %x1"
"|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
"|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
"|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
@@ -1592,6 +1597,7 @@
case ACT_VISIBILITY: return TH_PANEL;
case ACT_CONSTRAINT: return TH_PANEL;
case ACT_STATE: return TH_PANEL;
+ case ACT_ARMATURE: return TH_PANEL;
default: return TH_PANEL;
}
}
@@ -1671,6 +1677,39 @@
but->retval = B_REDR;
}
+static void check_armature_actuator(bContext *C, void *arg1_but, void *arg2_act)
+{
+ bArmatureActuator *act = arg2_act;
+ uiBut *but = arg1_but;
+ Object *ob= CTX_data_active_object(C);
+
+ /* check that bone exist in the active object */
+ but->retval = B_REDR;
+ if (ob->type == OB_ARMATURE && ob->pose) {
+ bPoseChannel *pchan;
+ bPose *pose = ob->pose;
+ for (pchan=pose->chanbase.first; pchan; pchan=pchan->next) {
+ if (!strcmp(pchan->name, act->posechannel)) {
+ /* found it, now look for constraint channel */
+ bConstraint *con;
+ for (con=pchan->constraints.first; con; con=con->next) {
+ if (!strcmp(con->name, act->constraint)) {
+ /* found it, all ok */
+ return;
+ }
+ }
+ /* didn't find constraint, make empty */
+ act->constraint[0] = 0;
+ return;
+ }
+ }
+ }
+ /* didn't find any */
+ act->posechannel[0] = 0;
+ act->constraint[0] = 0;
+}
+
+
static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
{
bSoundActuator *sa = NULL;
@@ -1691,6 +1730,7 @@
bTwoDFilterActuator *tdfa = NULL;
bParentActuator *parAct = NULL;
bStateActuator *staAct = NULL;
+ bArmatureActuator *armAct = NULL;
float *fp;
short ysize = 0, wval;
@@ -2734,6 +2774,31 @@
yco-= ysize;
break;
+ case ACT_ARMATURE:
+ armAct = act->data;
+
+ ysize= 48;
+ 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");
+ }
+
+ yco-= ysize;
+ break;
+
default:
ysize= 4;
Modified: branches/itasc/source/blender/ikplugin/intern/iksolver_plugin.c
===================================================================
--- branches/itasc/source/blender/ikplugin/intern/iksolver_plugin.c 2009-07-23 21:21:40 UTC (rev 21826)
+++ branches/itasc/source/blender/ikplugin/intern/iksolver_plugin.c 2009-07-23 21:29:25 UTC (rev 21827)
@@ -63,7 +63,7 @@
if (data->flag & CONSTRAINT_IK_AUTO) break;
if (data->tar==NULL) continue;
if (data->tar->type==OB_ARMATURE && data->subtarget[0]==0) continue;
- if ((con->flag & CONSTRAINT_DISABLE)==0 && (con->enforce!=0.0)) break;
+ if ((con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF))==0 && (con->enforce!=0.0)) break;
}
}
if(con==NULL) return;
Modified: branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
===================================================================
--- branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp 2009-07-23 21:21:40 UTC (rev 21826)
+++ branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp 2009-07-23 21:29:25 UTC (rev 21827)
@@ -71,6 +71,7 @@
};
typedef float Vector3[3];
+typedef float Vector4[4];
// one structure for each target in the scene
struct IK_Target
@@ -450,12 +451,12 @@
bKinematicConstraint *condata = (bKinematicConstraint *)iktarget->blenderConstraint->data;
iTaSC::ConstraintValues* values = _values;
if (iktarget->controlType & iTaSC::CopyPose::CTL_POSITION) {
- values->alpha = condata->weight;
+ values->alpha = (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) ? 0.0 : condata->weight;
values->action = iTaSC::ACT_ALPHA;
values++;
}
if (iktarget->controlType & iTaSC::CopyPose::CTL_ROTATION) {
- values->alpha = condata->orientweight;
+ values->alpha = (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) ? 0.0 : condata->orientweight;
values->action = iTaSC::ACT_ALPHA;
values++;
}
@@ -472,10 +473,12 @@
IK_Scene* ikscene;
IK_Channel* ikchan;
KDL::Frame initPose;
+ KDL::Rotation boneRot;
Bone *bone;
int a, flag, hasstretch=0;
float length;
- bool ret = true;
+ bool ret = true, ingame;
+ double rot[3];
if (tree->totchannel == 0)
return NULL;
@@ -487,7 +490,8 @@
ikscene->numchan = tree->totchannel;
ikscene->armature = arm;
ikscene->scene = scene;
- if (!(ob->pose->flag & POSE_GAME_ENGINE))
+ ingame = (ob->pose->flag & POSE_GAME_ENGINE);
+ if (!ingame)
ikscene->cache = new iTaSC::Cache();;
ikscene->solver = new iTaSC::WSDLSSolver();
//ikscene->solver->setQmax(10.0);
@@ -558,7 +562,7 @@
fl[0][0], fl[1][0], fl[2][0],
fl[0][1], fl[1][1], fl[2][1],
fl[0][2], fl[1][2], fl[2][2]),
- KDL::Vector(bone->head[0], bone->head[1], bone->head[2]));
+ KDL::Vector(bone->head[0], bone->head[1], bone->head[2])*scale);
// take scaling into account
length= bone->length*scale;
@@ -578,6 +582,26 @@
weight[0] = 1.0/(1.0-pchan->stiffness[0]);
weight[1] = 1.0/(1.0-pchan->stiffness[1]);
weight[2] = 1.0/(1.0-pchan->stiffness[2]);
+ // in case of game engine, we should not start from the the rest pose
+ // but from the current pose, as there is no cache. This means that we
+ // must compute the initial value of the joints.
+ // this is done from the difference between the bone actuual pose and the
+ // bone rest pose when taking its parent actual pose
+ if (ingame) {
+ float rmat[4][4]; // rest pose of bone with parent taken into account
+ float bmat[4][4]; // difference
+ if (pchan->parent) {
+ Mat4One(bmat);
+ Mat4MulMat43(bmat, pchan->parent->pose_mat, bone->bone_mat);
+ } else {
+ Mat4CpyMat4(bmat, bone->arm_mat);
+ }
+ Mat4Invert(rmat, bmat);
+ Mat4MulMat4(bmat, pchan->pose_mat, rmat);
+ Mat4Ortho(bmat);
+ boneRot.setValue(bmat[0]);
+ }
+ rot[0] = rot[1] = rot[2] = 0.0;
switch (flag)
{
case 0:
@@ -587,55 +611,69 @@
break;
case IK_XDOF:
// RX only, get the X rotation
- //X = EulerAngleFromMatrix(bonerot, 0);
+ if (ingame)
+ rot[0] = EulerAngleFromMatrix(boneRot, 0);
joint += ":RX";
- ret = arm->addSegment(joint, parent, KDL::Joint::RotX, 0.0, tip);
+ ret = arm->addSegment(joint, parent, KDL::Joint::RotX, rot[0], tip);
weights.push_back(weight[0]);
break;
case IK_YDOF:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list