mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 12:09:41 +00:00
Build a skeleton for Nifs that have a matching .kf file
This commit is contained in:
parent
bf94ffb839
commit
eb4daaf512
2 changed files with 39 additions and 20 deletions
|
@ -81,7 +81,7 @@ void NIFSkeletonLoader::loadResource(Ogre::Resource *resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ogre::SkeletonPtr NIFSkeletonLoader::createSkeleton(const std::string &name, const std::string &group, const Nif::Node *node)
|
bool NIFSkeletonLoader::needSkeleton(const Nif::Node *node)
|
||||||
{
|
{
|
||||||
/* We need to be a little aggressive here, since some NIFs have a crap-ton
|
/* We need to be a little aggressive here, since some NIFs have a crap-ton
|
||||||
* of nodes and Ogre only supports 256 bones. We will skip a skeleton if:
|
* of nodes and Ogre only supports 256 bones. We will skip a skeleton if:
|
||||||
|
@ -89,12 +89,12 @@ Ogre::SkeletonPtr NIFSkeletonLoader::createSkeleton(const std::string &name, con
|
||||||
* are no nodes named "AttachLight", and the tree consists of NiNode,
|
* are no nodes named "AttachLight", and the tree consists of NiNode,
|
||||||
* NiTriShape, and RootCollisionNode types only.
|
* NiTriShape, and RootCollisionNode types only.
|
||||||
*/
|
*/
|
||||||
if(!node->boneTrafo)
|
if(node->boneTrafo)
|
||||||
{
|
return true;
|
||||||
if(node->controller.empty() && node->name != "AttachLight")
|
|
||||||
{
|
if(!node->controller.empty() || node->name == "AttachLight")
|
||||||
if(node->recType == Nif::RC_NiTriShape)
|
return true;
|
||||||
return Ogre::SkeletonPtr();
|
|
||||||
if(node->recType == Nif::RC_NiNode || node->recType == Nif::RC_RootCollisionNode)
|
if(node->recType == Nif::RC_NiNode || node->recType == Nif::RC_RootCollisionNode)
|
||||||
{
|
{
|
||||||
const Nif::NiNode *ninode = static_cast<const Nif::NiNode*>(node);
|
const Nif::NiNode *ninode = static_cast<const Nif::NiNode*>(node);
|
||||||
|
@ -103,20 +103,37 @@ Ogre::SkeletonPtr NIFSkeletonLoader::createSkeleton(const std::string &name, con
|
||||||
{
|
{
|
||||||
if(!children[i].empty())
|
if(!children[i].empty())
|
||||||
{
|
{
|
||||||
Ogre::SkeletonPtr skel = createSkeleton(name, group, children[i].getPtr());
|
if(needSkeleton(children[i].getPtr()))
|
||||||
if(!skel.isNull())
|
return true;
|
||||||
return skel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ogre::SkeletonPtr();
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(node->recType == Nif::RC_NiTriShape)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ogre::SkeletonPtr NIFSkeletonLoader::createSkeleton(const std::string &name, const std::string &group, const Nif::Node *node)
|
||||||
|
{
|
||||||
|
bool forceskel = false;
|
||||||
|
std::string::size_type extpos = name.rfind('.');
|
||||||
|
if(extpos != std::string::npos && name.compare(extpos, name.size()-extpos, ".nif") == 0)
|
||||||
|
{
|
||||||
|
Ogre::ResourceGroupManager &resMgr = Ogre::ResourceGroupManager::getSingleton();
|
||||||
|
forceskel = resMgr.resourceExistsInAnyGroup(name.substr(0, extpos)+".kf");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(forceskel || needSkeleton(node))
|
||||||
|
{
|
||||||
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
|
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
|
||||||
return skelMgr.create(name, group, true, &sLoaders[name]);
|
return skelMgr.create(name, group, true, &sLoaders[name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Ogre::SkeletonPtr();
|
||||||
|
}
|
||||||
|
|
||||||
// Looks up an Ogre Bone handle ID from a NIF's record index. Should only be
|
// Looks up an Ogre Bone handle ID from a NIF's record index. Should only be
|
||||||
// used when the bone name is insufficient as this is a relatively slow lookup
|
// used when the bone name is insufficient as this is a relatively slow lookup
|
||||||
int NIFSkeletonLoader::lookupOgreBoneHandle(const std::string &nifname, int idx)
|
int NIFSkeletonLoader::lookupOgreBoneHandle(const std::string &nifname, int idx)
|
||||||
|
|
|
@ -38,6 +38,8 @@ class NIFSkeletonLoader : public Ogre::ManualResourceLoader
|
||||||
|
|
||||||
void buildBones(Ogre::Skeleton *skel, const Nif::Node *node, Ogre::Bone *parent=NULL);
|
void buildBones(Ogre::Skeleton *skel, const Nif::Node *node, Ogre::Bone *parent=NULL);
|
||||||
|
|
||||||
|
static bool needSkeleton(const Nif::Node *node);
|
||||||
|
|
||||||
// Lookup to retrieve an Ogre bone handle for a given Nif record index
|
// Lookup to retrieve an Ogre bone handle for a given Nif record index
|
||||||
std::map<int,int> mNifToOgreHandleMap;
|
std::map<int,int> mNifToOgreHandleMap;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue