From 84a92e665c3f8500c58128698daa04ec08b6e2b2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 02:18:44 +0100 Subject: [PATCH] Improve performance in RigGeometry by optimizing for the most common case of identity geomToSkelMatrix --- components/sceneutil/riggeometry.cpp | 25 +++++++++++++++++++------ components/sceneutil/riggeometry.hpp | 3 +-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/components/sceneutil/riggeometry.cpp b/components/sceneutil/riggeometry.cpp index 92780bfe9..2ad28affc 100644 --- a/components/sceneutil/riggeometry.cpp +++ b/components/sceneutil/riggeometry.cpp @@ -271,7 +271,8 @@ void RigGeometry::update(osg::NodeVisitor* nv) const osg::Matrixf& boneMatrix = bone->mMatrixInSkeletonSpace; accumulateMatrix(invBindMatrix, boneMatrix, weight, resultMat); } - resultMat = resultMat * mGeomToSkelMatrix; + if (mGeomToSkelMatrix) + resultMat *= (*mGeomToSkelMatrix); for (std::vector::const_iterator vertexIt = it->second.begin(); vertexIt != it->second.end(); ++vertexIt) { @@ -316,7 +317,10 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv) { Bone* bone = it->first; osg::BoundingSpheref bs = it->second; - transformBoundingSphere(bone->mMatrixInSkeletonSpace * mGeomToSkelMatrix, bs); + if (mGeomToSkelMatrix) + transformBoundingSphere(bone->mMatrixInSkeletonSpace * (*mGeomToSkelMatrix), bs); + else + transformBoundingSphere(bone->mMatrixInSkeletonSpace, bs); box.expandBy(bs); } @@ -332,19 +336,28 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv) void RigGeometry::updateGeomToSkelMatrix(const osg::NodePath& nodePath) { - mSkelToGeomPath.clear(); bool foundSkel = false; + osg::ref_ptr geomToSkelMatrix; for (osg::NodePath::const_iterator it = nodePath.begin(); it != nodePath.end(); ++it) { + osg::Node* node = *it; if (!foundSkel) { - if (*it == mSkeleton) + if (node == mSkeleton) foundSkel = true; } else - mSkelToGeomPath.push_back(*it); + { + if (osg::Transform* trans = node->asTransform()) + { + if (!geomToSkelMatrix) + geomToSkelMatrix = new osg::RefMatrixf; + trans->computeWorldToLocalMatrix(*geomToSkelMatrix, NULL); + } + } } - mGeomToSkelMatrix = osg::computeWorldToLocal(mSkelToGeomPath); + if (geomToSkelMatrix && !geomToSkelMatrix->isIdentity()) + mGeomToSkelMatrix = geomToSkelMatrix; } void RigGeometry::setInfluenceMap(osg::ref_ptr influenceMap) diff --git a/components/sceneutil/riggeometry.hpp b/components/sceneutil/riggeometry.hpp index 250c86b0e..83fd562de 100644 --- a/components/sceneutil/riggeometry.hpp +++ b/components/sceneutil/riggeometry.hpp @@ -56,8 +56,7 @@ namespace SceneUtil osg::ref_ptr mSourceTangents; Skeleton* mSkeleton; - osg::NodePath mSkelToGeomPath; - osg::Matrixf mGeomToSkelMatrix; + osg::ref_ptr mGeomToSkelMatrix; osg::ref_ptr mInfluenceMap;