Properly read and use the NIF root record list

actorid
Chris Robinson 12 years ago
parent e50b6b1cfe
commit ebcb4c66c3

@ -345,10 +345,14 @@ void NIFFile::parse()
} }
} }
/* After the data, the nif contains an int N and then a list of N size_t rootNum = nif.getUInt();
ints following it. This might be a list of the root nodes in the roots.resize(rootNum);
tree, but for the moment we ignore it.
*/ 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. // Once parsing is done, do post-processing.
for(size_t i=0; i<recNum; i++) for(size_t i=0; i<recNum; i++)

@ -66,6 +66,9 @@ class NIFFile
/// Record list /// Record list
std::vector<Record*> records; std::vector<Record*> records;
/// Root list
std::vector<Record*> roots;
/// Parse the file /// Parse the file
void parse(); void parse();
@ -115,9 +118,18 @@ public:
assert(res != NULL); assert(res != NULL);
return res; return res;
} }
/// Number of records /// Number of records
size_t numRecords() { return records.size(); } 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,20 +91,19 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
// likely a sign of incomplete code rather than faulty input. // 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::ptr pnif (Nif::NIFFile::create (resourceName.substr(0, resourceName.length()-7)));
Nif::NIFFile & nif = *pnif.get (); 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; return;
} }
// The first record is assumed to be the root node Nif::Record *r = nif.getRoot(0);
Nif::Record *r = nif.getRecord(0);
assert(r != NULL); assert(r != NULL);
Nif::Node *node = dynamic_cast<Nif::Node*>(r); Nif::Node *node = dynamic_cast<Nif::Node*>(r);
if (node == NULL) if (node == NULL)
{ {
warn("First record in file was not a node, but a " + warn("First root in file was not a node, but a " +
r->recName + ". Skipping file."); r->recName + ". Skipping file.");
return; return;
} }

@ -553,7 +553,7 @@ void loadResource(Ogre::Resource *resource)
OgreAssert(skel, "Attempting to load a skeleton into a non-skeleton resource!"); OgreAssert(skel, "Attempting to load a skeleton into a non-skeleton resource!");
Nif::NIFFile::ptr nif(Nif::NIFFile::create(skel->getName())); 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; std::vector<const Nif::NiKeyframeController*> ctrls;
Ogre::Bone *animroot = NULL; Ogre::Bone *animroot = NULL;
@ -1441,7 +1441,7 @@ class NIFMeshLoader : Ogre::ManualResourceLoader
return; 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); findTriShape(mesh, node);
} }
@ -1603,20 +1603,20 @@ public:
{ {
Nif::NIFFile::ptr pnif = Nif::NIFFile::create(name); Nif::NIFFile::ptr pnif = Nif::NIFFile::create(name);
Nif::NIFFile &nif = *pnif.get(); 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; return;
} }
// The first record is assumed to be the root node // 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); assert(r != NULL);
const Nif::Node *node = dynamic_cast<Nif::Node const *>(r); const Nif::Node *node = dynamic_cast<Nif::Node const *>(r);
if(node == NULL) if(node == NULL)
{ {
nif.warn("First record in "+name+" was not a node, but a "+ nif.warn("First root in "+name+" was not a node, but a "+
r->recName+"."); r->recName+".");
return; return;
} }
@ -1722,14 +1722,14 @@ Ogre::SkeletonPtr Loader::getSkeleton(std::string name, const std::string &group
return skel; return skel;
Nif::NIFFile::ptr nif = Nif::NIFFile::create(name); 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; return skel;
} }
// The first record is assumed to be the root node // 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); assert(r != NULL);
const Nif::Node *node = dynamic_cast<const Nif::Node*>(r); const Nif::Node *node = dynamic_cast<const Nif::Node*>(r);

Loading…
Cancel
Save