|
From: <cn...@us...> - 2009-09-01 18:19:38
|
Revision: 532
http://hgengine.svn.sourceforge.net/hgengine/?rev=532&view=rev
Author: cnlohr
Date: 2009-09-01 18:19:31 +0000 (Tue, 01 Sep 2009)
Log Message:
-----------
progress!
Modified Paths:
--------------
Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
Modified: Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
===================================================================
--- Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-08-31 05:10:52 UTC (rev 531)
+++ Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-01 18:19:31 UTC (rev 532)
@@ -88,13 +88,52 @@
{
string sSynonym = geoitem.leaves["name"];
//Information about how to map things toegether.
- for( int i = 0; i < geoitem.children.size(); i++ )
+ for( unsigned i = 0; i < geoitem.children.size(); i++ )
{
XMLCog & idata = geoitem.children[i];
if( idata.data == "input" )
synonyms[sSynonym][idata.leaves["semantic"]] = idata.leaves["source"].substr(1);
}
}
+ else if( geoitem.data == "triangles" )
+ {
+ string matname = geoitem.leaves["material"];
+ //Find all the sources.
+ vector< string > vSources;
+ vector< string > vSemantics;
+
+ for( unsigned i = 0; i < geoitem.children.size(); i++ )
+ {
+ XMLCog & idata = geoitem.children[i];
+ if( idata.data == "input" )
+ {
+ int offset = atoi( idata.leaves["offset"].c_str() );
+ if( vSources.size() <= offset )
+ {
+ vSources.resize( offset+1 );
+ vSemantics.resize( offset+1 );
+ }
+ vSources[offset] = idata.leaves["source"].substr( 1 );
+ vSemantics[offset] = idata.leaves["semantic"];
+ }
+ }
+
+ //Extract actual indices
+ int p = geoitem.FindChild( "p" );
+ if( p == -1 )
+ {
+ fprintf( stderr, "Could not find list of indices for mesh with material \"%s\".", matname.c_str() );
+ exit( -3 );
+ }
+
+ string sList = geoitem.children[p].payload;
+
+ vector< vector< int > > m_vvLists;
+ for( unsigned i = 0; i < sList.length(); i++ )
+ {
+
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-09-03 05:57:58
|
Revision: 535
http://hgengine.svn.sourceforge.net/hgengine/?rev=535&view=rev
Author: cnlohr
Date: 2009-09-03 05:57:47 +0000 (Thu, 03 Sep 2009)
Log Message:
-----------
more progress, maybe?
Modified Paths:
--------------
Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
Modified: Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
===================================================================
--- Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-03 04:04:45 UTC (rev 534)
+++ Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-03 05:57:47 UTC (rev 535)
@@ -5,7 +5,93 @@
Model mout;
+int FindBone( vector< Bone > & bl, const string & sName )
+{
+ for( unsigned i = 0; i < bl.size(); i++ )
+ if( bl[i].sName == sName )
+ return i;
+ fprintf( stderr, "Warning: Could not find bone with name \"%s\".", sName.c_str() );
+ return -1;
+}
+
+//XXX: TODO: Actually use this function, since it's good and can reduce code.
+void IntParse( const string & sData, vector< int > & is )
+{
+ const char * c = sData.c_str();
+ string stmp = "";
+ for( unsigned i = 0; i <= sData.length(); i++ )
+ {
+ if( c[i] == ' ' )
+ {
+ is.push_back( atoi( stmp.c_str() ) );
+ stmp = "";
+ }
+ stmp += c[i];
+ }
+}
+
+void FloatParse( const string & sData, vector< float > & is )
+{
+ const char * c = sData.c_str();
+ string stmp = "";
+ for( unsigned i = 0; i <= sData.length(); i++ )
+ {
+ if( c[i] == ' ' )
+ {
+ is.push_back( atof( stmp.c_str() ) );
+ stmp = "";
+ }
+ stmp += c[i];
+ }
+}
+
+void SetupBone( XMLCog * tp, XMLCog * tc, vector< Bone > & bl )
+{
+ int oParent = -1;
+ int oThis = -1;
+
+ if( tp )
+ {
+ oParent = FindBone( bl, tp->leaves["name"] );
+ }
+
+ oThis = FindBone( bl, tc->leaves["name"] );
+
+ if( oThis == -1 )
+ {
+ fprintf( stderr, "Could not find bone \"%s\".", tc->leaves["name"].c_str() );
+ return;
+ }
+
+ //Setup "this" bone
+ bl[oThis].iParentIndex = oParent;
+ bl[oThis].iAssociatedMesh = -1;
+
+
+ //Setup all children bones.
+ for( unsigned i = 0; i < tc->children.size(); i++ )
+ {
+ if( tc->children[i].data == "node" && tc->children[i].leaves["type"] == "JOINT" )
+ SetupBone( tc, &tc->children[i], bl );
+ else if( tc->children[i].data == "matrix" )
+ {
+ string sMatrix = tc->children[i].payload;
+ vector< float > fd;
+ FloatParse( sMatrix, fd );
+ bl[oThis].pJointPos.x = fd[3];
+ bl[oThis].pJointPos.y = fd[7];
+ bl[oThis].pJointPos.z = fd[11];
+
+ bl[oThis].qJointRot.w = sqrtf( 1.0 + fd[0] + fd[5] + fd[10] );
+ float w4 = ( 4.0 * bl[oThis].qJointRot.w );
+ bl[oThis].qJointRot.x = (fd[6] - fd[9]) / w4;
+ bl[oThis].qJointRot.y = (fd[8] - fd[2]) / w4;
+ bl[oThis].qJointRot.z = (fd[1] - fd[4]) / w4;
+ }
+ }
+}
+
int main( int argc, char ** argv )
{
float maxx = -10000, maxy = -10000, maxz = -10000;
@@ -306,6 +392,155 @@
}
}
+ if( lcontrol != -1 )
+ {
+ XMLCog & skin = c.children[lcontrol].children[0].children[0];
+ XMLCog & lv = c.children[lvscenes].children[0].children[0];
+ //Setup all the bones now...
+ vector< Bone > & bl = mout.vBones;
+
+ //Enumerate All Bones
+ for( unsigned i = 0; i < skin.children.size(); i++ )
+ {
+ if( skin.children[i].data == "source" )
+ {
+ for( unsigned j = 0; j < skin.children[i].children.size(); j++ )
+ {
+ XMLCog & c = skin.children[i].children[j];
+ if( c.data == "Name_array" )
+ {
+ string bones = c.payload;
+
+ string sThisBone = "";
+ for( unsigned i = 0; i <= bones.length(); i++ )
+ {
+ if( bones.c_str()[i] == ' ' || bones.length() == i )
+ {
+ bl.resize( bl.size() + 1 );
+ bl[bl.size()-1].sName = sThisBone;
+ sThisBone = "";
+ }
+ else
+ sThisBone+= bones.c_str()[i];
+ }
+ }
+ }
+ }
+ }
+
+ printf( "Bones found: %d\n", bl.size() );
+
+ for( unsigned i = 0; i < lv.children.size(); i++ )
+ {
+ if( lv.children[i].data == "node" && lv.children[i].leaves["type"] == "JOINT" )
+ {
+ SetupBone( 0, &lv.children[i], bl );
+ }
+ }
+
+ map< string, vector< int > > sources;
+
+ for( unsigned i = 0; i < skin.children.size(); i++ )
+ {
+ if( skin.children[i].data == "source" )
+ {
+ string sName = skin.children[i].leaves["name"];
+ for( unsigned j = 0; j < skin.children[i].children.size(); j++ )
+ {
+ XMLCog & sid = skin.children[i].children[j];
+
+ if( sid.data == "float_array" )
+ {
+ const char * pl = sid.payload.c_str();
+ string stmp = "";
+ for( unsigned i = 0; i <= sid.payload.length(); i++ )
+ {
+ if( pl[i] == ' ' || i == sid.payload.length() )
+ {
+ sources[sName].push_back( atof( stmp.c_str() ) );
+ stmp = "";
+ }
+ else
+ {
+ stmp += pl[i];
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //Sources is now filled out, go find the vertex weight
+ for( unsigned i = 0; i < skin.children.size(); i++ )
+ {
+ if( skin.children[i].data == "vertex_weights" )
+ {
+ string jid = "";
+ string wid = "";
+
+ int jido = 0;
+ int wido = 1;
+
+ vector< int > vcount;
+ vector< int > vs;
+
+ for( unsigned j = 0; j < skin.children[i].children.size(); j++ )
+ {
+ XMLCog & c = skin.children[i].children[j];
+ if( c.data == "input" )
+ {
+ if( c.leaves["semantic"] == "JOINT" )
+ {
+ jid = c.leaves["source"].substr(1);
+ jido = atoi( c.leaves["offset"].c_str() );
+ }
+ if( c.leaves["semantic"] == "WEIGHT" )
+ {
+ wid = c.leaves["source"].substr(1);
+ wido = atoi( c.leaves["offset"].c_str() );
+ }
+ }
+
+ if( c.data == "vcount" )
+ IntParse( c.payload, vcount );
+ if( c.data == "v" )
+ IntParse( c.payload, vs );
+ }
+
+ int iCurVertex = 0;
+ int iTC = 0;
+
+ //Wooh, we have everything oriented by vertex...
+ for( unsigned i = 0; i < vs.size()/2; i++ )
+ {
+ iTC++;
+ if( vcount[iCurVertex] < iTC )
+ {
+ iCurVertex++;
+ iTC = 0;
+ }
+
+ int iJoint = vs[i*2+jido];
+ int iWeight = vs[i*2+wido];
+
+ if( iJoint >= bl.size() )
+ {
+ fprintf( stderr, "Warning. Attempting to access joint outside workable area (joint %d)\n", iJoint );
+ }
+ else
+ {
+ bl[iJoint].vAssignments.resize( bl[iJoint].vAssignments.size() + 1 );
+ bl[iJoint].vAssignments[bl[iJoint].vAssignments.size()-1].iMesh = 0;
+ bl[iJoint].vAssignments[bl[iJoint].vAssignments.size()-1].iVertex = iCurVertex;
+ bl[iJoint].vAssignments[bl[iJoint].vAssignments.size()-1].fWeight = sources[wid][iWeight];
+ }
+ }
+ }
+ }
+ }
+
+
+
printf( "Extents: %f %f %f -> %f %f %f\n", minx, miny, minz, maxx, maxy, maxz );
mout.SaveModel( argv[2] );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-09-03 18:19:15
|
Revision: 536
http://hgengine.svn.sourceforge.net/hgengine/?rev=536&view=rev
Author: cnlohr
Date: 2009-09-03 18:19:02 +0000 (Thu, 03 Sep 2009)
Log Message:
-----------
still not quite functional, but all of the ideas are down, at least.
Modified Paths:
--------------
Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
Modified: Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
===================================================================
--- Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-03 05:57:47 UTC (rev 535)
+++ Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-03 18:19:02 UTC (rev 536)
@@ -22,7 +22,7 @@
string stmp = "";
for( unsigned i = 0; i <= sData.length(); i++ )
{
- if( c[i] == ' ' )
+ if( c[i] == ' ' || i == sData.length() )
{
is.push_back( atoi( stmp.c_str() ) );
stmp = "";
@@ -37,7 +37,7 @@
string stmp = "";
for( unsigned i = 0; i <= sData.length(); i++ )
{
- if( c[i] == ' ' )
+ if( c[i] == ' ' || i == sData.length() )
{
is.push_back( atof( stmp.c_str() ) );
stmp = "";
@@ -162,23 +162,8 @@
return -3;
}
- const char * payload = geoitem.children[floatvalspos].payload.c_str();
- int payloadlen = geoitem.children[floatvalspos].payload.length();
- vector < float > & out = sourcevalues[name];
- string thisval = "";
- for( unsigned i = 0; i < payloadlen; i++ )
- {
- if( payload[i] == ' ' )
- {
- out.push_back( atof( thisval.c_str() ) );
- thisval = "";
- }
- else
- thisval += payload[i];
- }
- if( thisval.length() )
- out.push_back( atof( thisval.c_str() ) );
- printf( "%d values (%d verts) read for %s\n", out.size(), out.size()/3, name.c_str() );
+ FloatParse( geoitem.children[floatvalspos].payload, sourcevalues[name] );
+ printf( "%d values (%d verts) read for %s\n", sourcevalues[name].size(), sourcevalues[name].size()/3, name.c_str() );
}
else if( geoitem.data == "vertices" )
{
@@ -358,6 +343,7 @@
}
}
+ printf( "Adding new mesh: %d\n", mout.vMeshes.size() + 1 );
mout.vMeshes.resize( mout.vMeshes.size() + 1 );
Mesh & tm = mout.vMeshes[mout.vMeshes.size() - 1];
tm.sName = matname;
@@ -392,12 +378,14 @@
}
}
+
+ vector< Bone > & bl = mout.vBones;
+
if( lcontrol != -1 )
{
XMLCog & skin = c.children[lcontrol].children[0].children[0];
XMLCog & lv = c.children[lvscenes].children[0].children[0];
//Setup all the bones now...
- vector< Bone > & bl = mout.vBones;
//Enumerate All Bones
for( unsigned i = 0; i < skin.children.size(); i++ )
@@ -537,8 +525,116 @@
}
}
}
+
+ //Gotta load the animations...
+ if( lvanimations == -1 )
+ fprintf( stderr, "Could not find library_animations. No animations to load.\n" );
+ else
+ {
+ float fMaxTime = 0.0;
+ map< string, vector< AnimationKey > > mKeys;
+ map< string, vector< float > > mTimes;
+ map< string, vector< float > > mvVals;
+
+ for( unsigned i = 0; i < c.children[lvanimations].children.size(); i++ )
+ {
+ XMLCog & bt = c.children[lvanimations].children[i];
+ if( bt.data == "animation" )
+ {
+ map< string, vector< float > > mvVals;
+ string sAnimation = "";
+ for( unsigned i = 0; i < bt.leaves["id"].length(); i++ )
+ {
+ if( bt.leaves["id"].c_str()[i] == '.' )
+ break;
+ else
+ sAnimation += bt.leaves["id"].c_str()[i];
+ }
+
+ printf( "Animation: %s : ", sAnimation.c_str() );
+ if( FindBone( bl, sAnimation ) == -1 )
+ {
+ printf( "Ignore.\n" );
+ continue;
+ }
+ else
+ {
+ printf( "Use.\n" );
+ }
+
+ for( unsigned i = 0; i < bt.children.size(); i++ )
+ {
+ XMLCog & dt = bt.children[i];
+ if( dt.data == "source" )
+ {
+ int Technique = dt.FindChild( "technique_common" );
+ int FloatArray = dt.FindChild( "float_array" );
+ if( Technique == -1 || FloatArray == -1 )
+ continue;
+ XMLCog & Tech = dt.children[Technique].children[0];
+ XMLCog & Data = dt.children[FloatArray];
+ string sName = Tech.children[0].leaves["name"];
+ string sData = Data.payload;
+ FloatParse( sData, mvVals[sName] );
+ }
+ }
+
+ if( mvVals["TIME"].size() == 0 || mvVals["TRANSFORM"].size() == 0 )
+ {
+ fprintf( stderr, "Error: Missing Time or Transform for Animation: %s\n", sAnimation.c_str() );
+ exit( -3 );
+ }
+
+ mTimes[sAnimation] = mvVals["TIME"];
+ vector< AnimationKey > & k = mKeys[sAnimation];
+ int keys = mvVals["TIME"].size();
+ k.resize( keys );
+ for( unsigned i = 0; i < keys; i++ )
+ {
+ if( mvVals["TIME"][i] > fMaxTime )
+ fMaxTime = mvVals["TIME"][i];
+ float * fd = &mvVals["TRANSFORM"][i*12];
+ AnimationKey & tk = k[i];
+
+ tk.pPos.x = fd[3];
+ tk.pPos.y = fd[7];
+ tk.pPos.z = fd[11];
+
+ tk.qRot.w = sqrtf( 1.0 + fd[0] + fd[5] + fd[10] );
+ float w4 = ( 4.0 * tk.qRot.w );
+ tk.qRot.x = (fd[6] - fd[9]) / w4;
+ tk.qRot.y = (fd[8] - fd[2]) / w4;
+ tk.qRot.z = (fd[1] - fd[4]) / w4;
+ tk.fTime = mvVals["TIME"][i];
+ }
+ }
+ }
+
+// map< string, vector< AnimationKey > > mKeys;
+// map< string, vector< float > > mTimes;
+
+ //mTimes and mKeys is filled out, use them!
+
+ mout.vAnimations.resize(mout.vAnimations.size()+1);
+ Animation & RootAnimation = mout.vAnimations[0];
+
+ RootAnimation.sName = "default";
+ RootAnimation.fDuration = fMaxTime;
+
+ for( map< string, vector< AnimationKey > >::iterator i = mKeys.begin(); i != mKeys.end(); i++ )
+ {
+ string sBone = i->first;
+
+ RootAnimation.vTracks.resize( RootAnimation.vTracks.size() + 1 );
+ AnimationTrack & at = RootAnimation.vTracks[ RootAnimation.vTracks.size() - 1 ];
+
+ at.iBone = FindBone( bl, sBone );
+
+ at.vKeys = i->second;
+ }
+ printf( "Animations found, animations are %f long.\n", fMaxTime );
+ }
}
-
printf( "Extents: %f %f %f -> %f %f %f\n", minx, miny, minz, maxx, maxy, maxz );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-09-04 06:11:36
|
Revision: 538
http://hgengine.svn.sourceforge.net/hgengine/?rev=538&view=rev
Author: cnlohr
Date: 2009-09-04 06:11:23 +0000 (Fri, 04 Sep 2009)
Log Message:
-----------
more progress... The weights are still busted, as though they don't line up to the verts in the model... weird?
Modified Paths:
--------------
Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
Modified: Mercury2/tools/collada2hgmdl/ColladaConvert.cpp
===================================================================
--- Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-04 06:09:46 UTC (rev 537)
+++ Mercury2/tools/collada2hgmdl/ColladaConvert.cpp 2009-09-04 06:11:23 UTC (rev 538)
@@ -5,13 +5,25 @@
Model mout;
+#define m00 fd[0]
+#define m01 fd[1]
+#define m02 fd[2]
+
+#define m10 fd[4]
+#define m11 fd[5]
+#define m12 fd[6]
+
+#define m20 fd[8]
+#define m21 fd[9]
+#define m22 fd[10]
+
int FindBone( vector< Bone > & bl, const string & sName )
{
for( unsigned i = 0; i < bl.size(); i++ )
if( bl[i].sName == sName )
return i;
- fprintf( stderr, "Warning: Could not find bone with name \"%s\".", sName.c_str() );
+// fprintf( stderr, "Warning: Could not find bone with name \"%s\".", sName.c_str() );
return -1;
}
@@ -68,7 +80,6 @@
bl[oThis].iParentIndex = oParent;
bl[oThis].iAssociatedMesh = -1;
-
//Setup all children bones.
for( unsigned i = 0; i < tc->children.size(); i++ )
{
@@ -79,15 +90,55 @@
string sMatrix = tc->children[i].payload;
vector< float > fd;
FloatParse( sMatrix, fd );
+
bl[oThis].pJointPos.x = fd[3];
bl[oThis].pJointPos.y = fd[7];
bl[oThis].pJointPos.z = fd[11];
- bl[oThis].qJointRot.w = sqrtf( 1.0 + fd[0] + fd[5] + fd[10] );
- float w4 = ( 4.0 * bl[oThis].qJointRot.w );
- bl[oThis].qJointRot.x = (fd[6] - fd[9]) / w4;
- bl[oThis].qJointRot.y = (fd[8] - fd[2]) / w4;
- bl[oThis].qJointRot.z = (fd[1] - fd[4]) / w4;
+
+//http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
+ float qw, qx, qy, qz;
+ float tr = m00 + m11 + m22;
+
+ if (tr > 0) {
+ float S = sqrt(tr+1.0) * 2; // S=4*qw
+ qw = 0.25 * S;
+ qx = (m21 - m12) / S;
+ qy = (m02 - m20) / S;
+ qz = (m10 - m01) / S;
+ } else if ((m00 > m11)&(m00 > m22)) {
+ float S = sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx
+ qw = (m21 - m12) / S;
+ qx = 0.25 * S;
+ qy = (m01 + m10) / S;
+ qz = (m02 + m20) / S;
+ } else if (m11 > m22) {
+ float S = sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy
+ qw = (m02 - m20) / S;
+ qx = (m01 + m10) / S;
+ qy = 0.25 * S;
+ qz = (m12 + m21) / S;
+ } else {
+ float S = sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz
+ qw = (m10 - m01) / S;
+ qx = (m02 + m20) / S;
+ qy = (m12 + m21) / S;
+ qz = 0.25 * S;
+ }
+
+ bl[oThis].qJointRot.w = qw;
+ bl[oThis].qJointRot.x = qx;
+ bl[oThis].qJointRot.y = qy;
+ bl[oThis].qJointRot.z = qz;
+
+// for( unsigned i = 0; i < 4; i++ )
+// printf( "%f %f %f %f\n", fd[i*4+0], fd[i*4+1], fd[i*4+2], fd[i*4+3] );
+//
+// printf( "Bone: %s : %f %f %f %f %f %f %f\n",
+// tc->leaves["name"].c_str(), bl[oThis].pJointPos.x,
+// bl[oThis].pJointPos.y, bl[oThis].pJointPos.z,
+// bl[oThis].qJointRot.w, bl[oThis].qJointRot.x,
+// bl[oThis].qJointRot.y, bl[oThis].qJointRot.z );
}
}
}
@@ -384,7 +435,7 @@
if( lcontrol != -1 )
{
XMLCog & skin = c.children[lcontrol].children[0].children[0];
- XMLCog & lv = c.children[lvscenes].children[0].children[0];
+ XMLCog & lv = c.children[lvscenes].children[0];
//Setup all the bones now...
//Enumerate All Bones
@@ -418,7 +469,7 @@
printf( "Bones found: %d\n", bl.size() );
- for( unsigned i = 0; i < lv.children.size(); i++ )
+ for( unsigned i = 0; i < lv.children.size(); i++ )
{
if( lv.children[i].data == "node" && lv.children[i].leaves["type"] == "JOINT" )
{
@@ -426,7 +477,8 @@
}
}
- map< string, vector< int > > sources;
+ map< string, vector< float > > sources;
+ string sTransforms = "";
for( unsigned i = 0; i < skin.children.size(); i++ )
{
@@ -454,10 +506,70 @@
}
}
}
+ if( sid.data == "technique_common" )
+ {
+ string sPName = sid.children[0].children[0].leaves["name"];
+ if( sPName == "TRANSFORM" )
+ {
+ sTransforms = sName;
+ }
+ }
}
}
}
+/*
+ //Try setting up bones here...
+ if( sources[sTransforms].size() == 0 )
+ {
+ fprintf( stderr, "Error: You do not appear to have any bone matrices that are valid.\n" );
+ exit( -3 );
+ }
+ for( unsigned i = 0; i < bl.size(); i++ )
+ {
+ float * fd = &sources[sTransforms][i*16];
+ Bone & tk = bl[i];
+
+ tk.pJointPos.x = fd[3];
+ tk.pJointPos.y = fd[7];
+ tk.pJointPos.z = fd[11];
+
+ float qw, qx, qy, qz;
+ float tr = m00 + m11 + m22;
+
+ if (tr > 0) {
+ float S = sqrt(tr+1.0) * 2; // S=4*qw
+ qw = 0.25 * S;
+ qx = (m21 - m12) / S;
+ qy = (m02 - m20) / S;
+ qz = (m10 - m01) / S;
+ } else if ((m00 > m11)&(m00 > m22)) {
+ float S = sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx
+ qw = (m21 - m12) / S;
+ qx = 0.25 * S;
+ qy = (m01 + m10) / S;
+ qz = (m02 + m20) / S;
+ } else if (m11 > m22) {
+ float S = sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy
+ qw = (m02 - m20) / S;
+ qx = (m01 + m10) / S;
+ qy = 0.25 * S;
+ qz = (m12 + m21) / S;
+ } else {
+ float S = sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz
+ qw = (m10 - m01) / S;
+ qx = (m02 + m20) / S;
+ qy = (m12 + m21) / S;
+ qz = 0.25 * S;
+ }
+
+ tk.qJointRot.w = qw;
+ tk.qJointRot.x = qx;
+ tk.qJointRot.y = qy;
+ tk.qJointRot.z = qz;
+ }
+*/
+
//Sources is now filled out, go find the vertex weight
for( unsigned i = 0; i < skin.children.size(); i++ )
{
@@ -505,7 +617,7 @@
if( vcount[iCurVertex] < iTC )
{
iCurVertex++;
- iTC = 0;
+ iTC = 1;
}
int iJoint = vs[i*2+jido];
@@ -521,6 +633,7 @@
bl[iJoint].vAssignments[bl[iJoint].vAssignments.size()-1].iMesh = 0;
bl[iJoint].vAssignments[bl[iJoint].vAssignments.size()-1].iVertex = iCurVertex;
bl[iJoint].vAssignments[bl[iJoint].vAssignments.size()-1].fWeight = sources[wid][iWeight];
+ printf( "(%d) %s - %d %f\n", iCurVertex, bl[iJoint].sName.c_str(), iJoint, sources[wid][iWeight] );
}
}
}
@@ -551,17 +664,20 @@
sAnimation += bt.leaves["id"].c_str()[i];
}
- printf( "Animation: %s : ", sAnimation.c_str() );
- if( FindBone( bl, sAnimation ) == -1 )
+ int boneid = 0;
+// printf( "Animation: %s : ", sAnimation.c_str() );
+ if( ( boneid = FindBone( bl, sAnimation ) ) == -1 )
{
- printf( "Ignore.\n" );
+// printf( "Ignore.\n" );
continue;
}
else
{
- printf( "Use.\n" );
+// printf( "Use.\n" );
}
+ Bone & sourcebone = bl[boneid];
+
for( unsigned i = 0; i < bt.children.size(); i++ )
{
XMLCog & dt = bt.children[i];
@@ -589,23 +705,65 @@
vector< AnimationKey > & k = mKeys[sAnimation];
int keys = mvVals["TIME"].size();
k.resize( keys );
+
for( unsigned i = 0; i < keys; i++ )
{
- if( mvVals["TIME"][i] > fMaxTime )
- fMaxTime = mvVals["TIME"][i];
- float * fd = &mvVals["TRANSFORM"][i*12];
+ float * fd = &mvVals["TRANSFORM"][i*16];
AnimationKey & tk = k[i];
-
- tk.pPos.x = fd[3];
- tk.pPos.y = fd[7];
- tk.pPos.z = fd[11];
-
- tk.qRot.w = sqrtf( 1.0 + fd[0] + fd[5] + fd[10] );
- float w4 = ( 4.0 * tk.qRot.w );
- tk.qRot.x = (fd[6] - fd[9]) / w4;
- tk.qRot.y = (fd[8] - fd[2]) / w4;
- tk.qRot.z = (fd[1] - fd[4]) / w4;
- tk.fTime = mvVals["TIME"][i];
+
+ tk.pPos.x = fd[3] - sourcebone.pJointPos.x;
+ tk.pPos.y = fd[7] - sourcebone.pJointPos.y;
+ tk.pPos.z = fd[11] - sourcebone.pJointPos.z;
+
+ float qw, qx, qy, qz;
+ float tr = m00 + m11 + m22;
+
+ if (tr > 0) {
+ float S = sqrt(tr+1.0) * 2; // S=4*qw
+ qw = 0.25 * S;
+ qx = (m21 - m12) / S;
+ qy = (m02 - m20) / S;
+ qz = (m10 - m01) / S;
+ } else if ((m00 > m11)&(m00 > m22)) {
+ float S = sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx
+ qw = (m21 - m12) / S;
+ qx = 0.25 * S;
+ qy = (m01 + m10) / S;
+ qz = (m02 + m20) / S;
+ } else if (m11 > m22) {
+ float S = sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy
+ qw = (m02 - m20) / S;
+ qx = (m01 + m10) / S;
+ qy = 0.25 * S;
+ qz = (m12 + m21) / S;
+ } else {
+ float S = sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz
+ qw = (m10 - m01) / S;
+ qx = (m02 + m20) / S;
+ qy = (m12 + m21) / S;
+ qz = 0.25 * S;
+ }
+
+ tk.qRot.w = qw;
+ tk.qRot.x = qx;
+ tk.qRot.y = qy;
+ tk.qRot.z = qz;
+
+ //We actually need to un-rotate tk around the original axis...
+// printf( "QOrig: %f %f %f %f\n", qw, qx, qy, qz );
+// printf( "QBone: %f %f %f %f\n", sourcebone.qJointRot.w, sourcebone.qJointRot.x, sourcebone.qJointRot.y, sourcebone.qJointRot.z );
+
+ MQuaternion tdiff = sourcebone.qJointRot.reciprocal();//SLERP( norotation, sourcebone.qJointRot, -1. );
+
+ tk.qRot = tdiff * tk.qRot;
+
+// printf( "QFinl: %f %f %f %f\n", tk.qRot.w, tk.qRot.x, tk.qRot.y, tk.qRot.z );
+
+ tk.fTime = mvVals["TIME"][i]*10.;
+
+ if( tk.fTime > fMaxTime )
+ fMaxTime = tk.fTime;
+
}
}
}
@@ -634,6 +792,14 @@
}
printf( "Animations found, animations are %f long.\n", fMaxTime );
}
+
+ //Move bones around...
+ bl[0].pJointPos.x+=0;
+ bl[0].pJointPos.y+=-13.5;
+ bl[0].pJointPos.z+=0;
+
+ for( unsigned i = 0; i < bl.size(); i++ )
+ printf( ": %s\n", bl[i].sName.c_str() );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|