diff --git a/components/sceneutil/riggeometry.cpp b/components/sceneutil/riggeometry.cpp index 92e316d412..d93b88349d 100644 --- a/components/sceneutil/riggeometry.cpp +++ b/components/sceneutil/riggeometry.cpp @@ -170,18 +170,26 @@ namespace SceneUtil osg::Vec3Array* normalDst = static_cast(geom.getNormalArray()); osg::Vec4Array* tangentDst = static_cast(geom.getTexCoordArray(7)); + std::vector boneMatrices(mNodes.size()); + std::vector::const_iterator bone = mNodes.begin(); + std::vector::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)