@ -137,13 +137,14 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
}
mBoneNodesVector . clear ( ) ;
for ( auto & bo und Pair : mBoneSphereVector - > mData )
for ( auto & bo ne Pair : mBoneSphereVector - > mData )
{
Bone * bone = mSkeleton - > getBone ( boundPair . name ) ;
const std : : string & boneName = bonePair . first ;
Bone * bone = mSkeleton - > getBone ( boneName ) ;
if ( ! bone )
{
mBoneNodesVector . push_back ( nullptr ) ;
Log ( Debug : : Error ) < < " Error: RigGeometry did not find bone " < < bo undPair. n ame;
Log ( Debug : : Error ) < < " Error: RigGeometry did not find bone " < < bo neN ame;
continue ;
}
@ -154,11 +155,12 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
{
for ( auto & weight : pair . first )
{
Bone * bone = mSkeleton - > getBone ( weight . boneName ) ;
const std : : string & boneName = weight . first . first ;
Bone * bone = mSkeleton - > getBone ( boneName ) ;
if ( ! bone )
{
mBoneNodesVector . push_back ( nullptr ) ;
Log ( Debug : : Error ) < < " Error: RigGeometry did not find bone " < < weight. boneName;
Log ( Debug : : Error ) < < " Error: RigGeometry did not find bone " < < boneName;
continue ;
}
@ -216,7 +218,7 @@ void RigGeometry::cull(osg::NodeVisitor* nv)
if ( bone = = nullptr )
continue ;
accumulateMatrix ( weight . bindMatrix , bone - > mMatrixInSkeletonSpace , weight . value , resultMat ) ;
accumulateMatrix ( weight . first. second , bone - > mMatrixInSkeletonSpace , weight . second , resultMat ) ;
index + + ;
}
@ -279,7 +281,7 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv)
continue ;
index + + ;
osg : : BoundingSpheref bs = boundPair . s pher e;
osg : : BoundingSpheref bs = boundPair . s econd ;
if ( mGeomToSkelMatrix )
transformBoundingSphere ( bone - > mMatrixInSkeletonSpace * ( * mGeomToSkelMatrix ) , bs ) ;
else
@ -335,21 +337,30 @@ void RigGeometry::setInfluenceMap(osg::ref_ptr<InfluenceMap> influenceMap)
{
mInfluenceMap = influenceMap ;
using Vertex2BoneMap = std : : map < unsigned short , std : : vector < BoneWeight > > ;
typedef std : : map < unsigned short , std : : vector < BoneWeight > > Vertex2BoneMap ;
Vertex2BoneMap vertex2BoneMap ;
mBoneSphereVector = new BoneSphereVector ;
mBoneSphereVector - > mData . reserve ( mInfluenceMap - > mData . size ( ) ) ;
mBone2VertexVector = new Bone2VertexVector ;
for ( const BoneData & bone : mInfluenceMap - > mData )
for ( auto& influencePair : mInfluenceMap - > mData )
{
mBoneSphereVector - > mData . push_back ( { bone . name , bone . influence . mBoundSphere } ) ;
for ( auto & weight : bone . influence . mWeights )
vertex2BoneMap [ weight . vertex ] . push_back ( { bone . name , bone . influence . mInvBindMatrix , weight . value } ) ;
const std : : string & boneName = influencePair . first ;
const BoneInfluence & bi = influencePair . second ;
mBoneSphereVector - > mData . emplace_back ( boneName , bi . mBoundSphere ) ;
for ( auto & weightPair : bi . mWeights )
{
std : : vector < BoneWeight > & vec = vertex2BoneMap [ weightPair . first ] ;
vec . emplace_back ( std : : make_pair ( boneName , bi . mInvBindMatrix ) , weightPair . second ) ;
}
}
Bone2VertexMap bone2VertexMap ;
for ( auto & vertexPair : vertex2BoneMap )
{
bone2VertexMap [ vertexPair . second ] . emplace_back ( vertexPair . first ) ;
}
mBone2VertexVector - > mData . reserve ( bone2VertexMap . size ( ) ) ;
mBone2VertexVector - > mData . assign ( bone2VertexMap . begin ( ) , bone2VertexMap . end ( ) ) ;