Update ReaderWriterFBX.cpp
This commit is contained in:
parent
79120eb994
commit
24a856fa6e
@ -135,27 +135,31 @@ void resolveBindMatrices(
|
||||
nodeNames.insert(it->second->getName());
|
||||
}
|
||||
|
||||
for (BindMatrixMap::const_iterator it = boneBindMatrices.begin();
|
||||
it != boneBindMatrices.end();)
|
||||
for (BindMatrixMap::const_iterator it = boneBindMatrices.begin(); it != boneBindMatrices.end(); ++it)
|
||||
{
|
||||
FbxNode* const fbxBone = it->first.first;
|
||||
FbxNode* const fbxBone = it->first;
|
||||
std::map<FbxNode*, osg::Node*>::const_iterator nodeIt = nodeMap.find(fbxBone);
|
||||
if (nodeIt != nodeMap.end())
|
||||
{
|
||||
const osg::Matrix bindMatrix = it->second;
|
||||
osgAnimation::Bone& osgBone = dynamic_cast<osgAnimation::Bone&>(*nodeIt->second);
|
||||
osgBone.setInvBindMatrixInSkeletonSpace(bindMatrix);
|
||||
osgAnimation::Bone* originalBone = dynamic_cast<osgAnimation::Bone*>(nodeIt->second);
|
||||
|
||||
++it;
|
||||
for (; it != boneBindMatrices.end() && it->first.first == fbxBone; ++it)
|
||||
// Iterate bind matrices and create new bones if needed
|
||||
const BindMatrixGeometryMap& bindMatrixGeom = it->second;
|
||||
for ( BindMatrixGeometryMap::const_iterator bindIt = bindMatrixGeom.begin(); bindIt != bindMatrixGeom.end(); ++bindIt)
|
||||
{
|
||||
if (it->second != bindMatrix)
|
||||
// First matrix will use original bone
|
||||
if (bindIt == bindMatrixGeom.begin())
|
||||
{
|
||||
originalBone->setInvBindMatrixInSkeletonSpace(bindIt->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Additional matrices need new bone
|
||||
std::string name;
|
||||
for (int i = 0;; ++i)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << osgBone.getName() << '_' << i;
|
||||
ss << originalBone->getName() << '_' << i;
|
||||
name = ss.str();
|
||||
if (nodeNames.insert(name).second)
|
||||
{
|
||||
@ -164,14 +168,19 @@ void resolveBindMatrices(
|
||||
}
|
||||
osgAnimation::Bone* newBone = new osgAnimation::Bone(name);
|
||||
newBone->setDefaultUpdateCallback();
|
||||
newBone->setInvBindMatrixInSkeletonSpace(it->second);
|
||||
osgBone.addChild(newBone);
|
||||
newBone->setInvBindMatrixInSkeletonSpace(bindIt->first);
|
||||
originalBone->addChild(newBone);
|
||||
|
||||
osgAnimation::RigGeometry* pRigGeometry = it->first.second;
|
||||
// Update rig geometry with new bone names
|
||||
for (std::set<osgAnimation::RigGeometry*>::const_iterator rigIt = bindIt->second.begin();
|
||||
rigIt != bindIt->second.end();
|
||||
++rigIt)
|
||||
{
|
||||
osgAnimation::RigGeometry* pRigGeometry = (*rigIt);
|
||||
|
||||
osgAnimation::VertexInfluenceMap* vertexInfluences = pRigGeometry->getInfluenceMap();
|
||||
|
||||
osgAnimation::VertexInfluenceMap::iterator vimIt = vertexInfluences->find(osgBone.getName());
|
||||
osgAnimation::VertexInfluenceMap::iterator vimIt = vertexInfluences->find(originalBone->getName());
|
||||
if (vimIt != vertexInfluences->end())
|
||||
{
|
||||
osgAnimation::VertexInfluence vi;
|
||||
@ -183,7 +192,8 @@ void resolveBindMatrices(
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_WARN << "No vertex influences found for \"" << osgBone.getName() << "\"" << std::endl;
|
||||
OSG_WARN << "No vertex influences found for \"" << originalBone->getName() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user