diff --git a/code/FindInvalidDataProcess.cpp b/code/FindInvalidDataProcess.cpp index e2e538520..ce87b7936 100644 --- a/code/FindInvalidDataProcess.cpp +++ b/code/FindInvalidDataProcess.cpp @@ -272,6 +272,9 @@ int FindInvalidDataProcess::ProcessAnimation (aiAnimation* 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; // Check whether all values are identical or whether there is just one keyframe diff --git a/include/aiMatrix4x4.inl b/include/aiMatrix4x4.inl index 571166e21..705420f85 100644 --- a/include/aiMatrix4x4.inl +++ b/include/aiMatrix4x4.inl @@ -58,12 +58,12 @@ inline aiMatrix4x4 aiMatrix4x4::operator* (const aiMatrix4x4& m) const // --------------------------------------------------------------------------- inline aiMatrix4x4& aiMatrix4x4::Transpose() { - std::swap( (float&)b1, (float&)a2); - std::swap( (float&)c1, (float&)a3); - std::swap( (float&)c2, (float&)b3); - std::swap( (float&)d1, (float&)a4); - std::swap( (float&)d2, (float&)b4); - std::swap( (float&)d3, (float&)c4); + std::swap( b1, a2); + std::swap( c1, a3); + std::swap( c2, b3); + std::swap( d1, a4); + std::swap( d2, b4); + std::swap( d3, c4); return *this; } diff --git a/tools/assimp_view/AnimEvaluator.cpp b/tools/assimp_view/AnimEvaluator.cpp index 965e7480e..9f86abc55 100644 --- a/tools/assimp_view/AnimEvaluator.cpp +++ b/tools/assimp_view/AnimEvaluator.cpp @@ -112,7 +112,7 @@ void AnimEvaluator::Evaluate( double pTime) } // ******** Scaling ********** - aiVector3D presentScaling( 0, 0, 0); + aiVector3D presentScaling( 1, 1, 1); if( channel->mNumScalingKeys > 0) { unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<2>() : 0; diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index e63053def..4966aec32 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -1830,22 +1830,19 @@ int CDisplay::RenderMaterialView() int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix, bool bAlpha /*= false*/) { - aiMatrix4x4 mTemp = piNode->mTransformation; - mTemp.Transpose(); - aiMatrix4x4 aiMe = mTemp * piMatrix; + aiMatrix4x4 aiMe = g_pcAsset->mAnimator->GetGlobalTransform( piNode->mName.data); + aiMe.Transpose(); + aiMe *= piMatrix; bool bChangedVM = false; if (VIEWMODE_NODE == this->m_iViewMode && this->m_pcCurrentNode) { 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 - for (unsigned int i = 0; i < piNode->mNumChildren;++i) - { - RenderNode(piNode->mChildren[i],aiMe,bAlpha ); - } + RenderNode(piNode->mChildren[i],piMatrix,bAlpha ); } return 1; } @@ -1975,7 +1972,7 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix, 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 - if( mesh->HasBones()) + if( mesh->HasBones() && helper->piEffect) { static float matrices[4*4*60]; float* tempmat = matrices; @@ -2041,7 +2038,7 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix, // render all child nodes 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? if (bChangedVM) diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index 26bd60256..3ff47d6a8 100644 --- a/tools/assimp_view/Material.cpp +++ b/tools/assimp_view/Material.cpp @@ -1117,21 +1117,6 @@ int CMaterialManager::CreateMaterial( 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; } //------------------------------------------------------------------------------- @@ -1159,11 +1144,11 @@ int CMaterialManager::SetupMaterial ( apcVec[0].x = g_avLightDirs[0].x; apcVec[0].y = g_avLightDirs[0].y; 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].y = g_avLightDirs[0].y * -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[1],&apcVec[1]); piEnd->SetVectorArray("afLightDir",apcVec,5); @@ -1173,19 +1158,19 @@ int CMaterialManager::SetupMaterial ( apcVec[0].z = ((g_avLightColors[0]) & 0xFF) / 255.0f; apcVec[0].w = 1.0f; - if( g_sOptions.b3Lights) - { - apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f; - apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f; - apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f; - apcVec[1].w = 0.0f; - } else - { - apcVec[1].x = 0.0f; - apcVec[1].y = 0.0f; - apcVec[1].z = 0.0f; - apcVec[1].w = 0.0f; - } + if( g_sOptions.b3Lights) + { + apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f; + apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f; + apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f; + apcVec[1].w = 0.0f; + } else + { + apcVec[1].x = 0.0f; + apcVec[1].y = 0.0f; + apcVec[1].z = 0.0f; + apcVec[1].w = 0.0f; + } apcVec[0] *= g_fLightIntensity; apcVec[1] *= g_fLightIntensity; diff --git a/tools/assimp_view/SceneAnimator.cpp b/tools/assimp_view/SceneAnimator.cpp index 10de3afef..735f8d4e5 100644 --- a/tools/assimp_view/SceneAnimator.cpp +++ b/tools/assimp_view/SceneAnimator.cpp @@ -82,7 +82,7 @@ void SceneAnimator::SetAnimIndex( size_t pAnimIndex) // 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 - mRootNode = CreateNodeTree( mScene->mRootNode); + mRootNode = CreateNodeTree( mScene->mRootNode, NULL); // invalid anim index if( mCurrentAnimIndex >= mScene->mNumAnimations) @@ -126,7 +126,7 @@ const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const std::string& pNodeNa if( it == mNodesByName.end()) return mIdentityMatrix; - return it->second->mLocalTransform; + return it->second->mGlobalTransform; } // ------------------------------------------------------------------------------------------------ @@ -151,7 +151,7 @@ const std::vector& SceneAnimator::GetBoneMatrices( const aiNode* pN { const aiBone* bone = mesh->mBones[a]; 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 @@ -160,10 +160,11 @@ const std::vector& SceneAnimator::GetBoneMatrices( const aiNode* pN // ------------------------------------------------------------------------------------------------ // 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 SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data); + internalNode->mParent = pParent; mNodesByName[std::string( pNode->mName.data)] = internalNode; // 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 for( unsigned int a = 0; a < pNode->mNumChildren; a++) { - SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a]); - childNode->mParent = internalNode; + SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a], internalNode); internalNode->mChildren.push_back( childNode); } @@ -224,7 +224,7 @@ void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode) SceneAnimNode* node = pInternalNode->mParent; while( node) { - pInternalNode->mGlobalTransform *= node->mLocalTransform; + pInternalNode->mGlobalTransform = node->mLocalTransform * pInternalNode->mGlobalTransform; node = node->mParent; } } diff --git a/tools/assimp_view/SceneAnimator.h b/tools/assimp_view/SceneAnimator.h index 63e1ead83..0d0129beb 100644 --- a/tools/assimp_view/SceneAnimator.h +++ b/tools/assimp_view/SceneAnimator.h @@ -129,7 +129,7 @@ public: protected: /** 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 */ void UpdateTransforms( SceneAnimNode* pNode, const std::vector& pTransforms);