Ticket #2026: cleanedup.patch
File cleanedup.patch, 4.4 KB (added by , 10 years ago) |
---|
-
Model.cpp
178 178 179 179 // extend bounds by vertex positions at the frame 180 180 for (size_t i=0;i<numverts;i++) 181 { 182 result += CModelDef::SkinPoint(verts[i], GetAnimatedBoneMatrices()); 183 } 181 CModelDef::SkinPoint(verts[i], GetAnimatedBoneMatrices(), result); 184 182 // advance to next frame 185 183 m_AnimTime += anim->GetFrameTime(); 186 184 } … … 424 424 425 425 if (m_BoneMatrices) 426 426 { 427 CMatrix3D* inverseBoneMatrices = m_pModelDef->GetInverseBindBoneMatrices(); 427 428 for (size_t i = 0; i < m_pModelDef->GetNumBones(); i++) 428 429 { 429 m_BoneMatrices[i] = m_BoneMatrices[i] * m_pModelDef->GetInverseBindBoneMatrices()[i];430 m_BoneMatrices[i] *= inverseBoneMatrices[i]; 430 431 } 431 432 432 433 // Note: there is a special case of joint influence, in which the vertex -
ModelDef.cpp
30 30 # include <xmmintrin.h> 31 31 #endif 32 32 33 CVector3D CModelDef::SkinPoint(const SModelVertex& vtx,34 const CMatrix3D newPoseMatrices[])33 void CModelDef::SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], 34 CVector3D &result) 35 35 { 36 CVector3D result (0, 0, 0);37 38 36 for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i) 39 {40 37 result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Transform(vtx.m_Coords) * vtx.m_Blend.m_Weight[i]; 41 } 38 39 } 42 40 43 return result; 41 void CModelDef::SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], 42 CBoundingBoxAligned &result) 43 { 44 for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i) 45 result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Transform(vtx.m_Coords) * vtx.m_Blend.m_Weight[i]; 46 44 47 } 45 48 46 CVector3D CModelDef::SkinNormal(const SModelVertex& vtx,47 const CMatrix3D newPoseMatrices[])49 void CModelDef::SkinNormal(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], 50 CVector3D &result) 48 51 { 49 52 // To be correct, the normal vectors apparently need to be multiplied by the 50 53 // inverse of the transpose. Unfortunately inverses are slow. … … 69 72 // (This isn't very good as a proof, but it's better than assuming M is 70 73 // orthogonal when it's clearly not.) 71 74 72 CVector3D result (0, 0, 0);73 74 75 for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i) 75 {76 76 result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Rotate(vtx.m_Norm) * vtx.m_Blend.m_Weight[i]; 77 }78 77 79 78 // If there was more than one influence, the result is probably not going 80 79 // to be of unit length (since it's a weighted sum of several independent … … 83 82 // optimise that case a bit.) 84 83 if (vtx.m_Blend.m_Bone[1] != 0xff) // if more than one influence 85 84 result.Normalize(); 86 87 return result;88 85 } 89 86 90 87 void CModelDef::SkinPointsAndNormals( … … 400 397 401 398 for (size_t i = 0; i < mdef->m_NumVertices; ++i) 402 399 { 403 mdef->m_pVertices[i].m_Coords = SkinPoint(mdef->m_pVertices[i], &bindPose[0]);404 mdef->m_pVertices[i].m_Norm = SkinNormal(mdef->m_pVertices[i], &bindPose[0]);400 SkinPoint(mdef->m_pVertices[i], &bindPose[0], mdef->m_pVertices[i].m_Coords); 401 SkinNormal(mdef->m_pVertices[i], &bindPose[0], mdef->m_pVertices[i].m_Norm); 405 402 } 406 403 } 407 404 } -
ModelDef.h
23 23 #define INCLUDED_MODELDEF 24 24 25 25 #include "ps/CStr.h" 26 #include "maths/BoundingBoxAligned.h" 26 27 #include "maths/Vector2D.h" 27 28 #include "maths/Vector3D.h" 28 29 #include "maths/Quaternion.h" … … 192 193 * 193 194 * @return new world-space vertex coordinates 194 195 */ 195 static CVector3D SkinPoint(const SModelVertex& vtx, 196 const CMatrix3D newPoseMatrices[]); 196 static void SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], 197 CVector3D &result); 198 static void SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], 199 CBoundingBoxAligned &result); 197 200 198 201 /** 199 202 * Transform the given vertex's normal from the bind pose into the new pose. 200 203 * 201 204 * @return new world-space vertex normal 202 205 */ 203 static CVector3D SkinNormal(const SModelVertex& vtx, 204 const CMatrix3D newPoseMatrices[]); 206 static void SkinNormal(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], CVector3D &result); 205 207 206 208 /** 207 209 * Transform vertices' positions and normals.