forked from mirror/openmw-tes3mp
Properly read and use the NIF root record list
This commit is contained in:
parent
e50b6b1cfe
commit
ebcb4c66c3
4 changed files with 39 additions and 24 deletions
|
@ -345,14 +345,18 @@ void NIFFile::parse()
|
|||
}
|
||||
}
|
||||
|
||||
/* After the data, the nif contains an int N and then a list of N
|
||||
ints following it. This might be a list of the root nodes in the
|
||||
tree, but for the moment we ignore it.
|
||||
*/
|
||||
size_t rootNum = nif.getUInt();
|
||||
roots.resize(rootNum);
|
||||
|
||||
// Once parsing is done, do post-processing.
|
||||
for(size_t i=0; i<recNum; i++)
|
||||
records[i]->post(this);
|
||||
for(size_t i = 0;i < rootNum;i++)
|
||||
{
|
||||
intptr_t idx = nif.getInt();
|
||||
roots[i] = ((idx >= 0) ? records.at(idx) : NULL);
|
||||
}
|
||||
|
||||
// Once parsing is done, do post-processing.
|
||||
for(size_t i=0; i<recNum; i++)
|
||||
records[i]->post(this);
|
||||
}
|
||||
|
||||
/// \todo move to the write cpp file
|
||||
|
|
|
@ -66,6 +66,9 @@ class NIFFile
|
|||
/// Record list
|
||||
std::vector<Record*> records;
|
||||
|
||||
/// Root list
|
||||
std::vector<Record*> roots;
|
||||
|
||||
/// Parse the file
|
||||
void parse();
|
||||
|
||||
|
@ -115,9 +118,18 @@ public:
|
|||
assert(res != NULL);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Number of records
|
||||
size_t numRecords() { return records.size(); }
|
||||
|
||||
/// Get a given root
|
||||
Record *getRoot(size_t index=0)
|
||||
{
|
||||
Record *res = roots.at(index);
|
||||
assert(res != NULL);
|
||||
return res;
|
||||
}
|
||||
/// Number of roots
|
||||
size_t numRoots() { return roots.size(); }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -91,21 +91,20 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
|||
// likely a sign of incomplete code rather than faulty input.
|
||||
Nif::NIFFile::ptr pnif (Nif::NIFFile::create (resourceName.substr(0, resourceName.length()-7)));
|
||||
Nif::NIFFile & nif = *pnif.get ();
|
||||
if (nif.numRecords() < 1)
|
||||
if (nif.numRoots() < 1)
|
||||
{
|
||||
warn("Found no records in NIF.");
|
||||
warn("Found no root nodes in NIF.");
|
||||
return;
|
||||
}
|
||||
|
||||
// The first record is assumed to be the root node
|
||||
Nif::Record *r = nif.getRecord(0);
|
||||
Nif::Record *r = nif.getRoot(0);
|
||||
assert(r != NULL);
|
||||
|
||||
Nif::Node *node = dynamic_cast<Nif::Node*>(r);
|
||||
if (node == NULL)
|
||||
{
|
||||
warn("First record in file was not a node, but a " +
|
||||
r->recName + ". Skipping file.");
|
||||
warn("First root in file was not a node, but a " +
|
||||
r->recName + ". Skipping file.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -553,7 +553,7 @@ void loadResource(Ogre::Resource *resource)
|
|||
OgreAssert(skel, "Attempting to load a skeleton into a non-skeleton resource!");
|
||||
|
||||
Nif::NIFFile::ptr nif(Nif::NIFFile::create(skel->getName()));
|
||||
const Nif::Node *node = static_cast<const Nif::Node*>(nif->getRecord(0));
|
||||
const Nif::Node *node = static_cast<const Nif::Node*>(nif->getRoot(0));
|
||||
|
||||
std::vector<const Nif::NiKeyframeController*> ctrls;
|
||||
Ogre::Bone *animroot = NULL;
|
||||
|
@ -1441,7 +1441,7 @@ class NIFMeshLoader : Ogre::ManualResourceLoader
|
|||
return;
|
||||
}
|
||||
|
||||
const Nif::Node *node = dynamic_cast<const Nif::Node*>(nif->getRecord(0));
|
||||
const Nif::Node *node = dynamic_cast<const Nif::Node*>(nif->getRecord(mShapeIndex));
|
||||
findTriShape(mesh, node);
|
||||
}
|
||||
|
||||
|
@ -1603,21 +1603,21 @@ public:
|
|||
{
|
||||
Nif::NIFFile::ptr pnif = Nif::NIFFile::create(name);
|
||||
Nif::NIFFile &nif = *pnif.get();
|
||||
if(nif.numRecords() < 1)
|
||||
if(nif.numRoots() < 1)
|
||||
{
|
||||
nif.warn("Found no NIF records in "+name+".");
|
||||
nif.warn("Found no root nodes in "+name+".");
|
||||
return;
|
||||
}
|
||||
|
||||
// The first record is assumed to be the root node
|
||||
const Nif::Record *r = nif.getRecord(0);
|
||||
const Nif::Record *r = nif.getRoot(0);
|
||||
assert(r != NULL);
|
||||
|
||||
const Nif::Node *node = dynamic_cast<Nif::Node const *>(r);
|
||||
if(node == NULL)
|
||||
{
|
||||
nif.warn("First record in "+name+" was not a node, but a "+
|
||||
r->recName+".");
|
||||
nif.warn("First root in "+name+" was not a node, but a "+
|
||||
r->recName+".");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1722,14 +1722,14 @@ Ogre::SkeletonPtr Loader::getSkeleton(std::string name, const std::string &group
|
|||
return skel;
|
||||
|
||||
Nif::NIFFile::ptr nif = Nif::NIFFile::create(name);
|
||||
if(nif->numRecords() < 1)
|
||||
if(nif->numRoots() < 1)
|
||||
{
|
||||
nif->warn("Found no NIF records in "+name+".");
|
||||
nif->warn("Found no root nodes in "+name+".");
|
||||
return skel;
|
||||
}
|
||||
|
||||
// The first record is assumed to be the root node
|
||||
const Nif::Record *r = nif->getRecord(0);
|
||||
const Nif::Record *r = nif->getRoot(0);
|
||||
assert(r != NULL);
|
||||
|
||||
const Nif::Node *node = dynamic_cast<const Nif::Node*>(r);
|
||||
|
|
Loading…
Reference in a new issue