- Bugfix: animation scene tree is correctly created and traversed now

- Bugfix: viewer should not crash anymore when loading a second asset after a first asset with bones
- deactived invalid animation filtering for the moment


git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@213 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
ulfjorensen 2008-11-01 14:18:13 +00:00
parent 99e92472fc
commit c7e6fe3d73
7 changed files with 41 additions and 56 deletions

View File

@ -272,6 +272,9 @@ int FindInvalidDataProcess::ProcessAnimation (aiAnimation* anim)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
int FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim) int FindInvalidDataProcess::ProcessAnimationChannel (aiNodeAnim* anim)
{ {
// TODO: (thom) For some reason, even proper channels are deleted as well. Therefore deactivated it for the moment.
return 0;
int i = 0; int i = 0;
// Check whether all values are identical or whether there is just one keyframe // Check whether all values are identical or whether there is just one keyframe

View File

@ -58,12 +58,12 @@ inline aiMatrix4x4 aiMatrix4x4::operator* (const aiMatrix4x4& m) const
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
inline aiMatrix4x4& aiMatrix4x4::Transpose() inline aiMatrix4x4& aiMatrix4x4::Transpose()
{ {
std::swap( (float&)b1, (float&)a2); std::swap( b1, a2);
std::swap( (float&)c1, (float&)a3); std::swap( c1, a3);
std::swap( (float&)c2, (float&)b3); std::swap( c2, b3);
std::swap( (float&)d1, (float&)a4); std::swap( d1, a4);
std::swap( (float&)d2, (float&)b4); std::swap( d2, b4);
std::swap( (float&)d3, (float&)c4); std::swap( d3, c4);
return *this; return *this;
} }

View File

@ -112,7 +112,7 @@ void AnimEvaluator::Evaluate( double pTime)
} }
// ******** Scaling ********** // ******** Scaling **********
aiVector3D presentScaling( 0, 0, 0); aiVector3D presentScaling( 1, 1, 1);
if( channel->mNumScalingKeys > 0) if( channel->mNumScalingKeys > 0)
{ {
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<2>() : 0; unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<2>() : 0;

View File

@ -1830,22 +1830,19 @@ int CDisplay::RenderMaterialView()
int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix, int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
bool bAlpha /*= false*/) bool bAlpha /*= false*/)
{ {
aiMatrix4x4 mTemp = piNode->mTransformation; aiMatrix4x4 aiMe = g_pcAsset->mAnimator->GetGlobalTransform( piNode->mName.data);
mTemp.Transpose(); aiMe.Transpose();
aiMatrix4x4 aiMe = mTemp * piMatrix; aiMe *= piMatrix;
bool bChangedVM = false; bool bChangedVM = false;
if (VIEWMODE_NODE == this->m_iViewMode && this->m_pcCurrentNode) if (VIEWMODE_NODE == this->m_iViewMode && this->m_pcCurrentNode)
{ {
if (piNode != this->m_pcCurrentNode->psNode) if (piNode != this->m_pcCurrentNode->psNode)
{ {
if (0 != piNode->mNumChildren) // directly call our children
for (unsigned int i = 0; i < piNode->mNumChildren;++i)
{ {
// directly call our children RenderNode(piNode->mChildren[i],piMatrix,bAlpha );
for (unsigned int i = 0; i < piNode->mNumChildren;++i)
{
RenderNode(piNode->mChildren[i],aiMe,bAlpha );
}
} }
return 1; return 1;
} }
@ -1975,7 +1972,7 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
else if (bAlpha)continue; else if (bAlpha)continue;
// Upload bone matrices. This maybe is the wrong place to do it, but for the heck of it I don't understand this code flow // Upload bone matrices. This maybe is the wrong place to do it, but for the heck of it I don't understand this code flow
if( mesh->HasBones()) if( mesh->HasBones() && helper->piEffect)
{ {
static float matrices[4*4*60]; static float matrices[4*4*60];
float* tempmat = matrices; float* tempmat = matrices;
@ -2041,7 +2038,7 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
// render all child nodes // render all child nodes
for (unsigned int i = 0; i < piNode->mNumChildren;++i) for (unsigned int i = 0; i < piNode->mNumChildren;++i)
{ {
RenderNode(piNode->mChildren[i],aiMe,bAlpha ); RenderNode(piNode->mChildren[i],piMatrix,bAlpha );
} }
// need to reset the viewmode? // need to reset the viewmode?
if (bChangedVM) if (bChangedVM)

View File

@ -1117,21 +1117,6 @@ int CMaterialManager::CreateMaterial(
pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture()); pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
} }
// setup bones if neccessary
if( !pcSource->HasBones())
{
static float matrices[4*3*60];
float* tempmat = matrices;
for( unsigned int a = 0; a < 60; a++)
{
// HACK: (thom) set identity matrices for all bones for the moment so that you see something
*tempmat++ = 1.0f; *tempmat++ = 0.0f; *tempmat++ = 0.0f; *tempmat++ = 0.0f;
*tempmat++ = 0.0f; *tempmat++ = 1.0f; *tempmat++ = 0.0f; *tempmat++ = 0.0f;
*tempmat++ = 0.0f; *tempmat++ = 0.0f; *tempmat++ = 1.0f; *tempmat++ = 0.0f;
}
pcMesh->piEffect->SetVectorArray( "gBoneMatrix", (const D3DXVECTOR4*) matrices, 3*60);
}
return 1; return 1;
} }
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
@ -1159,11 +1144,11 @@ int CMaterialManager::SetupMaterial (
apcVec[0].x = g_avLightDirs[0].x; apcVec[0].x = g_avLightDirs[0].x;
apcVec[0].y = g_avLightDirs[0].y; apcVec[0].y = g_avLightDirs[0].y;
apcVec[0].z = g_avLightDirs[0].z; apcVec[0].z = g_avLightDirs[0].z;
apcVec[0].w = 0.0f; apcVec[0].w = 0.0f;
apcVec[1].x = g_avLightDirs[0].x * -1.0f; apcVec[1].x = g_avLightDirs[0].x * -1.0f;
apcVec[1].y = g_avLightDirs[0].y * -1.0f; apcVec[1].y = g_avLightDirs[0].y * -1.0f;
apcVec[1].z = g_avLightDirs[0].z * -1.0f; apcVec[1].z = g_avLightDirs[0].z * -1.0f;
apcVec[1].w = 0.0f; apcVec[1].w = 0.0f;
D3DXVec4Normalize(&apcVec[0],&apcVec[0]); D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
D3DXVec4Normalize(&apcVec[1],&apcVec[1]); D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
piEnd->SetVectorArray("afLightDir",apcVec,5); piEnd->SetVectorArray("afLightDir",apcVec,5);
@ -1173,19 +1158,19 @@ int CMaterialManager::SetupMaterial (
apcVec[0].z = ((g_avLightColors[0]) & 0xFF) / 255.0f; apcVec[0].z = ((g_avLightColors[0]) & 0xFF) / 255.0f;
apcVec[0].w = 1.0f; apcVec[0].w = 1.0f;
if( g_sOptions.b3Lights) if( g_sOptions.b3Lights)
{ {
apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f; apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f;
apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f; apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f;
apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f; apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f;
apcVec[1].w = 0.0f; apcVec[1].w = 0.0f;
} else } else
{ {
apcVec[1].x = 0.0f; apcVec[1].x = 0.0f;
apcVec[1].y = 0.0f; apcVec[1].y = 0.0f;
apcVec[1].z = 0.0f; apcVec[1].z = 0.0f;
apcVec[1].w = 0.0f; apcVec[1].w = 0.0f;
} }
apcVec[0] *= g_fLightIntensity; apcVec[0] *= g_fLightIntensity;
apcVec[1] *= g_fLightIntensity; apcVec[1] *= g_fLightIntensity;

View File

@ -82,7 +82,7 @@ void SceneAnimator::SetAnimIndex( size_t pAnimIndex)
// create the internal node tree. Do this even in case of invalid animation index // create the internal node tree. Do this even in case of invalid animation index
// so that the transformation matrices are properly set up to mimic the current scene // so that the transformation matrices are properly set up to mimic the current scene
mRootNode = CreateNodeTree( mScene->mRootNode); mRootNode = CreateNodeTree( mScene->mRootNode, NULL);
// invalid anim index // invalid anim index
if( mCurrentAnimIndex >= mScene->mNumAnimations) if( mCurrentAnimIndex >= mScene->mNumAnimations)
@ -126,7 +126,7 @@ const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const std::string& pNodeNa
if( it == mNodesByName.end()) if( it == mNodesByName.end())
return mIdentityMatrix; return mIdentityMatrix;
return it->second->mLocalTransform; return it->second->mGlobalTransform;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -151,7 +151,7 @@ const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pN
{ {
const aiBone* bone = mesh->mBones[a]; const aiBone* bone = mesh->mBones[a];
const aiMatrix4x4& currentGlobalTransform = GetGlobalTransform( std::string( bone->mName.data)); const aiMatrix4x4& currentGlobalTransform = GetGlobalTransform( std::string( bone->mName.data));
mTransforms[a] = bone->mOffsetMatrix * currentGlobalTransform * globalInverseMeshTransform; mTransforms[a] = globalInverseMeshTransform * currentGlobalTransform * bone->mOffsetMatrix;
} }
// and return the result // and return the result
@ -160,10 +160,11 @@ const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pN
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation. // Recursively creates an internal node structure matching the current scene and animation.
SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode) SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent)
{ {
// create a node // create a node
SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data); SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data);
internalNode->mParent = pParent;
mNodesByName[std::string( pNode->mName.data)] = internalNode; mNodesByName[std::string( pNode->mName.data)] = internalNode;
// copy its transformation // copy its transformation
@ -188,8 +189,7 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode)
// continue for all child nodes and assign the created internal nodes as our children // continue for all child nodes and assign the created internal nodes as our children
for( unsigned int a = 0; a < pNode->mNumChildren; a++) for( unsigned int a = 0; a < pNode->mNumChildren; a++)
{ {
SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a]); SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a], internalNode);
childNode->mParent = internalNode;
internalNode->mChildren.push_back( childNode); internalNode->mChildren.push_back( childNode);
} }
@ -224,7 +224,7 @@ void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode)
SceneAnimNode* node = pInternalNode->mParent; SceneAnimNode* node = pInternalNode->mParent;
while( node) while( node)
{ {
pInternalNode->mGlobalTransform *= node->mLocalTransform; pInternalNode->mGlobalTransform = node->mLocalTransform * pInternalNode->mGlobalTransform;
node = node->mParent; node = node->mParent;
} }
} }

View File

@ -129,7 +129,7 @@ public:
protected: protected:
/** Recursively creates an internal node structure matching the current scene and animation. */ /** Recursively creates an internal node structure matching the current scene and animation. */
SceneAnimNode* CreateNodeTree( aiNode* pNode); SceneAnimNode* CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent);
/** Recursively updates the internal node transformations from the given matrix array */ /** Recursively updates the internal node transformations from the given matrix array */
void UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms); void UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms);