diff --git a/code/3DSConverter.cpp b/code/3DSConverter.cpp index 5471e2cd6..103e7234f 100644 --- a/code/3DSConverter.cpp +++ b/code/3DSConverter.cpp @@ -505,6 +505,12 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut, // Now build the transformation matrix of the node // ROTATION if (pcIn->aRotationKeys.size()){ + + // FIX to get to Assimp's quaternion conventions + for (std::vector::iterator it = pcIn->aRotationKeys.begin(); it != pcIn->aRotationKeys.end(); ++it) { + (*it).mValue.w *= -1.f; + } + pcOut->mTransformation = aiMatrix4x4( pcIn->aRotationKeys[0].mValue.GetMatrix() ); } else if (pcIn->aCameraRollKeys.size()) @@ -554,7 +560,9 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut, aiFloatKey& f = pcIn->aCameraRollKeys[i]; q.mTime = f.mTime; - q.mValue = aiQuaternion(0.f,0.f,AI_DEG_TO_RAD(- f.mValue)); + + // FIX to get to Assimp quaternion conventions + q.mValue = aiQuaternion(0.f,0.f,AI_DEG_TO_RAD( /*-*/ f.mValue)); } } #if 0 diff --git a/code/ASELoader.cpp b/code/ASELoader.cpp index 2cd1f71ec..a3f180a31 100644 --- a/code/ASELoader.cpp +++ b/code/ASELoader.cpp @@ -375,6 +375,9 @@ void ASEImporter::BuildAnimations() q.mValue = cur.Normalize(); } nd->mRotationKeys[a] = q; + + // need this to get to Assimp quaternion conventions + nd->mRotationKeys[a].mValue.w *= -1.f; } } // copy scaling keys diff --git a/code/LWOAnimation.cpp b/code/LWOAnimation.cpp index 80e52aee5..b48751b0b 100644 --- a/code/LWOAnimation.cpp +++ b/code/LWOAnimation.cpp @@ -507,6 +507,11 @@ void AnimResolver::ExtractAnimChannel(aiNodeAnim** out, unsigned int flags /*= 0 { *out = NULL; + + //FIXME: crashes if more than one component is animated at different timings, to be resolved. + return; + +#if 0 // If we have no envelopes, return NULL if (envelopes.empty()) { return; @@ -560,6 +565,7 @@ void AnimResolver::ExtractAnimChannel(aiNodeAnim** out, unsigned int flags /*= 0 anim->mScalingKeys = new aiVectorKey[ anim->mNumScalingKeys = keys.size() ]; std::copy(keys.begin(),keys.end(),anim->mScalingKeys); } +#endif } diff --git a/code/MD5Loader.cpp b/code/MD5Loader.cpp index 74939fa79..0b6e46663 100644 --- a/code/MD5Loader.cpp +++ b/code/MD5Loader.cpp @@ -246,6 +246,9 @@ void MD5Importer::AttachChilds_Mesh(int iParentID,aiNode* piParent, BoneList& bo aiQuaternion quat; MD5::ConvertQuaternion ( bones[i].mRotationQuat, quat ); + // FIX to get to Assimp's quaternion conventions + quat.w *= -1.f; + bones[i].mTransform = aiMatrix4x4 ( quat.GetMatrix()); bones[i].mTransform.a4 = bones[i].mPositionXYZ.x; bones[i].mTransform.b4 = bones[i].mPositionXYZ.y; @@ -612,6 +615,9 @@ void MD5Importer::LoadMD5AnimFile () MD5::ConvertQuaternion(vTemp, qKey->mValue); qKey->mTime = vKey->mTime = dTime; + + // we need this to get to Assimp quaternion conventions + qKey->mValue.w *= -1.f; } } diff --git a/code/XFileImporter.cpp b/code/XFileImporter.cpp index c56e2d955..7e429f8ae 100644 --- a/code/XFileImporter.cpp +++ b/code/XFileImporter.cpp @@ -504,6 +504,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData nbone->mRotationKeys[c].mTime = bone->mRotKeys[c].mTime; nbone->mRotationKeys[c].mValue = aiQuaternion( rotmat); + nbone->mRotationKeys[c].mValue.w *= -1.0f; // needs quat inversion } // scaling diff --git a/include/aiQuaternion.h b/include/aiQuaternion.h index a3dfab78c..53624a0e1 100644 --- a/include/aiQuaternion.h +++ b/include/aiQuaternion.h @@ -120,9 +120,9 @@ inline aiQuaternion::aiQuaternion( const aiMatrix3x3 &pRotMatrix) if( t > 0.001f) { float s = sqrt( t) * 2.0f; - x = (pRotMatrix.b3 - pRotMatrix.c2) / s; - y = (pRotMatrix.c1 - pRotMatrix.a3) / s; - z = (pRotMatrix.a2 - pRotMatrix.b1) / s; + x = (pRotMatrix.c2 - pRotMatrix.b3) / s; + y = (pRotMatrix.a3 - pRotMatrix.c1) / s; + z = (pRotMatrix.b1 - pRotMatrix.a2) / s; w = 0.25f * s; } // else we have to check several cases else if( pRotMatrix.a1 > pRotMatrix.b2 && pRotMatrix.a1 > pRotMatrix.c3 ) @@ -130,26 +130,26 @@ inline aiQuaternion::aiQuaternion( const aiMatrix3x3 &pRotMatrix) // Column 0: float s = sqrt( 1.0f + pRotMatrix.a1 - pRotMatrix.b2 - pRotMatrix.c3) * 2.0f; x = 0.25f * s; - y = (pRotMatrix.a2 + pRotMatrix.b1) / s; - z = (pRotMatrix.c1 + pRotMatrix.a3) / s; - w = (pRotMatrix.b3 - pRotMatrix.c2) / s; + y = (pRotMatrix.b1 + pRotMatrix.a2) / s; + z = (pRotMatrix.a3 + pRotMatrix.c1) / s; + w = (pRotMatrix.c2 - pRotMatrix.b3) / s; } else if( pRotMatrix.b2 > pRotMatrix.c3) { // Column 1: float s = sqrt( 1.0f + pRotMatrix.b2 - pRotMatrix.a1 - pRotMatrix.c3) * 2.0f; - x = (pRotMatrix.a2 + pRotMatrix.b1) / s; + x = (pRotMatrix.b1 + pRotMatrix.a2) / s; y = 0.25f * s; - z = (pRotMatrix.b3 + pRotMatrix.c2) / s; - w = (pRotMatrix.c1 - pRotMatrix.a3) / s; + z = (pRotMatrix.c2 + pRotMatrix.b3) / s; + w = (pRotMatrix.a3 - pRotMatrix.c1) / s; } else { // Column 2: float s = sqrt( 1.0f + pRotMatrix.c3 - pRotMatrix.a1 - pRotMatrix.b2) * 2.0f; - x = (pRotMatrix.c1 + pRotMatrix.a3) / s; - y = (pRotMatrix.b3 + pRotMatrix.c2) / s; + x = (pRotMatrix.a3 + pRotMatrix.c1) / s; + y = (pRotMatrix.c2 + pRotMatrix.b3) / s; z = 0.25f * s; - w = (pRotMatrix.a2 - pRotMatrix.b1) / s; + w = (pRotMatrix.b1 - pRotMatrix.a2) / s; } } @@ -177,13 +177,13 @@ inline aiMatrix3x3 aiQuaternion::GetMatrix() const { aiMatrix3x3 resMatrix; resMatrix.a1 = 1.0f - 2.0f * (y * y + z * z); - resMatrix.a2 = 2.0f * (x * y + z * w); - resMatrix.a3 = 2.0f * (x * z - y * w); - resMatrix.b1 = 2.0f * (x * y - z * w); + resMatrix.a2 = 2.0f * (x * y - z * w); + resMatrix.a3 = 2.0f * (x * z + y * w); + resMatrix.b1 = 2.0f * (x * y + z * w); resMatrix.b2 = 1.0f - 2.0f * (x * x + z * z); - resMatrix.b3 = 2.0f * (y * z + x * w); - resMatrix.c1 = 2.0f * (x * z + y * w); - resMatrix.c2 = 2.0f * (y * z - x * w); + resMatrix.b3 = 2.0f * (y * z - x * w); + resMatrix.c1 = 2.0f * (x * z - y * w); + resMatrix.c2 = 2.0f * (y * z + x * w); resMatrix.c3 = 1.0f - 2.0f * (x * x + y * y); return resMatrix; diff --git a/mkutil/revision.h b/mkutil/revision.h index 2be4c4f5c..16146ac9b 100644 --- a/mkutil/revision.h +++ b/mkutil/revision.h @@ -1 +1 @@ -#define SVNRevision 467 +#define SVNRevision 501