Reduce skinned shape code duplication

pull/541/head
capostrophic 5 years ago
parent bd6c455fd4
commit 7cc70ffb50

@ -599,28 +599,16 @@ namespace NifOsg
const bool isMarker = hasMarkers && !nodeName.compare(0, markerName.size(), markerName); const bool isMarker = hasMarkers && !nodeName.compare(0, markerName.size(), markerName);
if (!isMarker && nodeName.compare(0, shadowName.size(), shadowName) && nodeName.compare(0, shadowName2.size(), shadowName2)) if (!isMarker && nodeName.compare(0, shadowName.size(), shadowName) && nodeName.compare(0, shadowName2.size(), shadowName2))
{ {
bool skinned = false; Nif::NiSkinInstancePtr skin;
if (nifNode->recType == Nif::RC_NiTriShape) if (nifNode->recType == Nif::RC_NiTriShape)
{ skin = static_cast<const Nif::NiTriShape*>(nifNode)->skin;
const Nif::NiTriShape* triShape = static_cast<const Nif::NiTriShape*>(nifNode);
if (!triShape->skin.empty())
{
skinned = true;
handleSkinnedTriShape(triShape, node, composite, boundTextures, animflags);
}
}
else // if (nifNode->recType == Nif::RC_NiTriStrips) else // if (nifNode->recType == Nif::RC_NiTriStrips)
{ skin = static_cast<const Nif::NiTriStrips*>(nifNode)->skin;
const Nif::NiTriStrips* triStrips = static_cast<const Nif::NiTriStrips*>(nifNode);
if (!triStrips->skin.empty())
{
skinned = true;
handleSkinnedTriStrips(triStrips, node, composite, boundTextures, animflags);
}
}
if (!skinned) if (skin.empty())
handleTriShape(nifNode, node, composite, boundTextures, animflags); handleTriShape(nifNode, node, composite, boundTextures, animflags);
else
handleSkinnedTriShape(nifNode, node, composite, boundTextures, animflags);
if (!nifNode->controller.empty()) if (!nifNode->controller.empty())
handleMeshControllers(nifNode, node, composite, boundTextures, animflags); handleMeshControllers(nifNode, node, composite, boundTextures, animflags);
@ -1206,58 +1194,34 @@ namespace NifOsg
return morphGeom; return morphGeom;
} }
void handleSkinnedTriShape(const Nif::NiTriShape *triShape, osg::Group *parentNode, SceneUtil::CompositeStateSetUpdater* composite, void handleSkinnedTriShape(const Nif::Node *nifNode, osg::Group *parentNode, SceneUtil::CompositeStateSetUpdater* composite,
const std::vector<int>& boundTextures, int animflags) const std::vector<int>& boundTextures, int animflags)
{ {
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry); if (nifNode->recType != Nif::RC_NiTriShape && nifNode->recType != Nif::RC_NiTriStrips)
triShapeToGeometry(triShape, geometry, parentNode, composite, boundTextures, animflags); return;
osg::ref_ptr<SceneUtil::RigGeometry> rig(new SceneUtil::RigGeometry);
rig->setSourceGeometry(geometry);
rig->setName(triShape->name);
const Nif::NiSkinInstance *skin = triShape->skin.getPtr();
// Assign bone weights
osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map (new SceneUtil::RigGeometry::InfluenceMap);
const Nif::NiSkinData *data = skin->data.getPtr(); osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry);
const Nif::NodeList &bones = skin->bones; Nif::NiSkinInstancePtr skinPtr;
for(size_t i = 0;i < bones.length();i++) if (nifNode->recType != Nif::RC_NiTriShape)
{ {
std::string boneName = Misc::StringUtils::lowerCase(bones[i].getPtr()->name); const Nif::NiTriShape* triShape = static_cast<const Nif::NiTriShape*>(nifNode);
triShapeToGeometry(triShape, geometry, parentNode, composite, boundTextures, animflags);
SceneUtil::RigGeometry::BoneInfluence influence; skinPtr = triShape->skin;
const std::vector<Nif::NiSkinData::VertWeight> &weights = data->bones[i].weights; }
for(size_t j = 0;j < weights.size();j++) else
{ {
influence.mWeights.emplace_back(weights[j].vertex, weights[j].weight); const Nif::NiTriStrips* triStrips = static_cast<const Nif::NiTriStrips*>(nifNode);
} triStripsToGeometry(triStrips, geometry, parentNode, composite, boundTextures, animflags);
influence.mInvBindMatrix = data->bones[i].trafo.toMatrix(); skinPtr = triStrips->skin;
influence.mBoundSphere = osg::BoundingSpheref(data->bones[i].boundSphereCenter, data->bones[i].boundSphereRadius);
map->mData.emplace_back(boneName, influence);
} }
rig->setInfluenceMap(map);
parentNode->addChild(rig);
}
void handleSkinnedTriStrips(const Nif::NiTriStrips *triStrips, osg::Group *parentNode, SceneUtil::CompositeStateSetUpdater* composite,
const std::vector<int>& boundTextures, int animflags)
{
osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry);
triStripsToGeometry(triStrips, geometry, parentNode, composite, boundTextures, animflags);
osg::ref_ptr<SceneUtil::RigGeometry> rig(new SceneUtil::RigGeometry); osg::ref_ptr<SceneUtil::RigGeometry> rig(new SceneUtil::RigGeometry);
rig->setSourceGeometry(geometry); rig->setSourceGeometry(geometry);
rig->setName(triStrips->name); rig->setName(nifNode->name);
const Nif::NiSkinInstance *skin = triStrips->skin.getPtr();
// Assign bone weights // Assign bone weights
osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map (new SceneUtil::RigGeometry::InfluenceMap); osg::ref_ptr<SceneUtil::RigGeometry::InfluenceMap> map (new SceneUtil::RigGeometry::InfluenceMap);
const Nif::NiSkinInstance *skin = skinPtr.getPtr();
const Nif::NiSkinData *data = skin->data.getPtr(); const Nif::NiSkinData *data = skin->data.getPtr();
const Nif::NodeList &bones = skin->bones; const Nif::NodeList &bones = skin->bones;
for(size_t i = 0;i < bones.length();i++) for(size_t i = 0;i < bones.length();i++)
@ -1280,7 +1244,6 @@ namespace NifOsg
parentNode->addChild(rig); parentNode->addChild(rig);
} }
osg::BlendFunc::BlendFuncMode getBlendMode(int mode) osg::BlendFunc::BlendFuncMode getBlendMode(int mode)
{ {
switch(mode) switch(mode)

Loading…
Cancel
Save