mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Avoid duplicating skeletons due to casing issues
Manually created resource names are apparently always case sensitive, causing some skeletons to get loaded multiple times.
This commit is contained in:
parent
ce1310614c
commit
bfe80bb8dc
3 changed files with 32 additions and 36 deletions
|
@ -53,8 +53,6 @@ void Animation::setAnimationSources(const std::vector<std::string> &names)
|
|||
if(!mEntityList.mSkelBase)
|
||||
return;
|
||||
|
||||
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
|
||||
|
||||
mCurrentAnim = NULL;
|
||||
mCurrentKeys = NULL;
|
||||
mAnimVelocity = 0.0f;
|
||||
|
@ -62,19 +60,14 @@ void Animation::setAnimationSources(const std::vector<std::string> &names)
|
|||
mNonAccumRoot = NULL;
|
||||
mSkeletonSources.clear();
|
||||
|
||||
std::vector<std::string>::const_iterator nameiter = names.begin();
|
||||
std::vector<std::string>::const_iterator nameiter;
|
||||
for(nameiter = names.begin();nameiter != names.end();nameiter++)
|
||||
{
|
||||
Ogre::SkeletonPtr skel = skelMgr.getByName(*nameiter);
|
||||
Ogre::SkeletonPtr skel = NifOgre::Loader::getSkeleton(*nameiter);
|
||||
if(skel.isNull())
|
||||
{
|
||||
NifOgre::Loader::createSkeleton(*nameiter);
|
||||
skel = skelMgr.getByName(*nameiter);
|
||||
if(skel.isNull())
|
||||
{
|
||||
std::cerr<< "Failed to get skeleton source "<<*nameiter <<std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cerr<< "Failed to get skeleton source "<<*nameiter <<std::endl;
|
||||
continue;
|
||||
}
|
||||
skel->touch();
|
||||
|
||||
|
|
|
@ -452,7 +452,8 @@ void loadResource(Ogre::Resource *resource)
|
|||
}
|
||||
}
|
||||
|
||||
bool createSkeleton(const std::string &name, const std::string &group, const Nif::Node *node)
|
||||
|
||||
static Ogre::SkeletonPtr createSkeleton(const std::string &name, const std::string &group, const Nif::Node *node)
|
||||
{
|
||||
/* 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:
|
||||
|
@ -463,7 +464,7 @@ bool createSkeleton(const std::string &name, const std::string &group, const Nif
|
|||
if(!node->boneTrafo)
|
||||
{
|
||||
if(node->recType == Nif::RC_NiTriShape)
|
||||
return false;
|
||||
return Ogre::SkeletonPtr();
|
||||
if(node->controller.empty() && node->name != "AttachLight")
|
||||
{
|
||||
if(node->recType == Nif::RC_NiNode || node->recType == Nif::RC_RootCollisionNode)
|
||||
|
@ -474,18 +475,18 @@ bool createSkeleton(const std::string &name, const std::string &group, const Nif
|
|||
{
|
||||
if(!children[i].empty())
|
||||
{
|
||||
if(createSkeleton(name, group, children[i].getPtr()))
|
||||
return true;
|
||||
Ogre::SkeletonPtr skel = createSkeleton(name, group, children[i].getPtr());
|
||||
if(!skel.isNull())
|
||||
return skel;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return Ogre::SkeletonPtr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::SkeletonManager &skelMgr = Ogre::SkeletonManager::getSingleton();
|
||||
skelMgr.create(name, group, true, &sLoaders[name]);
|
||||
return true;
|
||||
return skelMgr.create(name, group, true, &sLoaders[name]);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1140,10 +1141,7 @@ MeshInfoList Loader::load(const std::string &name, const std::string &group)
|
|||
|
||||
bool hasSkel = Ogre::SkeletonManager::getSingleton().resourceExists(name);
|
||||
if(!hasSkel)
|
||||
{
|
||||
NIFSkeletonLoader skelldr;
|
||||
hasSkel = skelldr.createSkeleton(name, group, node);
|
||||
}
|
||||
hasSkel = !NIFSkeletonLoader::createSkeleton(name, group, node).isNull();
|
||||
|
||||
NIFMeshLoader meshldr(name, group);
|
||||
if(hasSkel)
|
||||
|
@ -1253,30 +1251,35 @@ EntityList Loader::createEntities(Ogre::Entity *parent, const std::string &bonen
|
|||
}
|
||||
|
||||
|
||||
bool Loader::createSkeleton(const std::string &name, const std::string &group)
|
||||
Ogre::SkeletonPtr Loader::getSkeleton(std::string name, const std::string &group)
|
||||
{
|
||||
Nif::NIFFile::ptr pnif = Nif::NIFFile::create(name);
|
||||
Nif::NIFFile &nif = *pnif.get();
|
||||
if(nif.numRecords() < 1)
|
||||
Ogre::SkeletonPtr skel;
|
||||
|
||||
Misc::StringUtils::toLower(name);
|
||||
skel = Ogre::SkeletonManager::getSingleton().getByName(name);
|
||||
if(!skel.isNull())
|
||||
return skel;
|
||||
|
||||
Nif::NIFFile::ptr nif = Nif::NIFFile::create(name);
|
||||
if(nif->numRecords() < 1)
|
||||
{
|
||||
nif.warn("Found no NIF records in "+name+".");
|
||||
return false;
|
||||
nif->warn("Found no NIF records in "+name+".");
|
||||
return skel;
|
||||
}
|
||||
|
||||
// The first record is assumed to be the root node
|
||||
Nif::Record const *r = nif.getRecord(0);
|
||||
const Nif::Record *r = nif->getRecord(0);
|
||||
assert(r != NULL);
|
||||
|
||||
Nif::Node const *node = dynamic_cast<Nif::Node const *>(r);
|
||||
const Nif::Node *node = dynamic_cast<const Nif::Node*>(r);
|
||||
if(node == NULL)
|
||||
{
|
||||
nif.warn("First record in "+name+" was not a node, but a "+
|
||||
r->recName+".");
|
||||
return false;
|
||||
nif->warn("First record in "+name+" was not a node, but a "+
|
||||
r->recName+".");
|
||||
return skel;
|
||||
}
|
||||
|
||||
NIFSkeletonLoader skelldr;
|
||||
return skelldr.createSkeleton(name, group, node);
|
||||
return NIFSkeletonLoader::createSkeleton(name, group, node);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
std::string name,
|
||||
const std::string &group="General");
|
||||
|
||||
static bool createSkeleton(const std::string &name, const std::string &group="General");
|
||||
static Ogre::SkeletonPtr getSkeleton(std::string name, const std::string &group="General");
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue