Skip to content

Commit

Permalink
Merge branch 'precomputedbonematrices' into 'master'
Browse files Browse the repository at this point in the history
Precompute bone matrices before skinning

See merge request OpenMW/openmw!4467
  • Loading branch information
psi29a committed Nov 26, 2024
2 parents 690de3c + 0f4e0ac commit 1dac165
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions components/sceneutil/riggeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,26 @@ namespace SceneUtil
osg::Vec3Array* normalDst = static_cast<osg::Vec3Array*>(geom.getNormalArray());
osg::Vec4Array* tangentDst = static_cast<osg::Vec4Array*>(geom.getTexCoordArray(7));

std::vector<osg::Matrixf> boneMatrices(mNodes.size());
std::vector<Bone*>::const_iterator bone = mNodes.begin();
std::vector<BoneInfo>::const_iterator boneInfo = mData->mBones.begin();
for (osg::Matrixf& boneMat : boneMatrices)
{
if (*bone != nullptr)
boneMat = boneInfo->mInvBindMatrix * (*bone)->mMatrixInSkeletonSpace;
++bone;
++boneInfo;
}

for (const auto& [influences, vertices] : mData->mInfluences)
{
osg::Matrixf resultMat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);

for (const auto& [index, weight] : influences)
{
const Bone* bone = mNodes[index];
if (bone == nullptr)
if (mNodes[index] == nullptr)
continue;

osg::Matrixf boneMat = mData->mBones[index].mInvBindMatrix * bone->mMatrixInSkeletonSpace;
float* boneMatPtr = boneMat.ptr();
const float* boneMatPtr = boneMatrices[index].ptr();
float* resultMatPtr = resultMat.ptr();
for (int i = 0; i < 16; ++i, ++resultMatPtr, ++boneMatPtr)
if (i % 4 != 3)
Expand Down

0 comments on commit 1dac165

Please sign in to comment.