Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/ModelDef.cpp
Show All 25 Lines | |||||
#include "lib/sysdep/arch/x86_x64/simd.h" | #include "lib/sysdep/arch/x86_x64/simd.h" | ||||
#include "ps/FileIo.h" | #include "ps/FileIo.h" | ||||
#include "maths/Vector4D.h" | #include "maths/Vector4D.h" | ||||
#if COMPILER_HAS_SSE | #if COMPILER_HAS_SSE | ||||
# include <xmmintrin.h> | # include <xmmintrin.h> | ||||
#endif | #endif | ||||
void CModelDef::GetMaxBounds(CSkeletonAnimDef* anim, bool loop, CBoundingBoxAligned& result) | |||||
{ | |||||
std::unordered_map<u32, CBoundingBoxAligned>::const_iterator it = m_MaxBoundsPerAnimDef.find(anim ? anim->m_UID : 0); | |||||
if (it != m_MaxBoundsPerAnimDef.end()) | |||||
{ | |||||
result = it->second; | |||||
return; | |||||
} | |||||
size_t numverts = GetNumVertices(); | |||||
SModelVertex* verts = GetVertices(); | |||||
if (!anim) | |||||
{ | |||||
for (size_t i = 0; i < numverts; ++i) | |||||
result += verts[i].m_Coords; | |||||
m_MaxBoundsPerAnimDef[0] = result; | |||||
return; | |||||
} | |||||
ENSURE(anim->m_UID != 0); | |||||
std::vector<CMatrix3D> boneMatrix(anim->GetNumKeys()); | |||||
// NB: by using frames, the bounds are technically pessimistic (since interpolation could end up outside of them). | |||||
for (size_t j = 0; j < anim->GetNumFrames(); ++j) | |||||
{ | |||||
anim->BuildBoneMatrices(j*anim->GetFrameTime(), boneMatrix.data(), loop); | |||||
for (size_t i = 0; i < numverts; ++i) | |||||
result += SkinPoint(verts[i], boneMatrix.data()); | |||||
} | |||||
m_MaxBoundsPerAnimDef[anim->m_UID] = result; | |||||
} | |||||
CVector3D CModelDef::SkinPoint(const SModelVertex& vtx, | CVector3D CModelDef::SkinPoint(const SModelVertex& vtx, | ||||
const CMatrix3D newPoseMatrices[]) | const CMatrix3D newPoseMatrices[]) | ||||
{ | { | ||||
CVector3D result (0, 0, 0); | CVector3D result (0, 0, 0); | ||||
for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i) | for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i) | ||||
{ | { | ||||
result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Transform(vtx.m_Coords) * vtx.m_Blend.m_Weight[i]; | result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Transform(vtx.m_Coords) * vtx.m_Blend.m_Weight[i]; | ||||
▲ Show 20 Lines • Show All 454 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator