Skip to content

Commit 1dac165

Browse files
committed
Merge branch 'precomputedbonematrices' into 'master'
Precompute bone matrices before skinning See merge request OpenMW/openmw!4467
2 parents 690de3c + 0f4e0ac commit 1dac165

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

components/sceneutil/riggeometry.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,26 @@ namespace SceneUtil
170170
osg::Vec3Array* normalDst = static_cast<osg::Vec3Array*>(geom.getNormalArray());
171171
osg::Vec4Array* tangentDst = static_cast<osg::Vec4Array*>(geom.getTexCoordArray(7));
172172

173+
std::vector<osg::Matrixf> boneMatrices(mNodes.size());
174+
std::vector<Bone*>::const_iterator bone = mNodes.begin();
175+
std::vector<BoneInfo>::const_iterator boneInfo = mData->mBones.begin();
176+
for (osg::Matrixf& boneMat : boneMatrices)
177+
{
178+
if (*bone != nullptr)
179+
boneMat = boneInfo->mInvBindMatrix * (*bone)->mMatrixInSkeletonSpace;
180+
++bone;
181+
++boneInfo;
182+
}
183+
173184
for (const auto& [influences, vertices] : mData->mInfluences)
174185
{
175186
osg::Matrixf resultMat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
176187

177188
for (const auto& [index, weight] : influences)
178189
{
179-
const Bone* bone = mNodes[index];
180-
if (bone == nullptr)
190+
if (mNodes[index] == nullptr)
181191
continue;
182-
183-
osg::Matrixf boneMat = mData->mBones[index].mInvBindMatrix * bone->mMatrixInSkeletonSpace;
184-
float* boneMatPtr = boneMat.ptr();
192+
const float* boneMatPtr = boneMatrices[index].ptr();
185193
float* resultMatPtr = resultMat.ptr();
186194
for (int i = 0; i < 16; ++i, ++resultMatPtr, ++boneMatPtr)
187195
if (i % 4 != 3)

0 commit comments

Comments
 (0)