From 660d73fd888f185b31bff036298a1d405060944f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 13 Jan 2013 06:56:58 -0800 Subject: [PATCH 1/2] Store the NIF index in the Record object --- components/nif/nif_file.cpp | 11 +++++------ components/nif/record.hpp | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/nif/nif_file.cpp b/components/nif/nif_file.cpp index 3db34e0cc6..6b024ab68e 100644 --- a/components/nif/nif_file.cpp +++ b/components/nif/nif_file.cpp @@ -39,9 +39,8 @@ //#include //#include -using namespace std; -using namespace Nif; -using namespace Misc; +namespace Nif +{ class NIFFile::LoadedCache { @@ -311,6 +310,7 @@ void NIFFile::parse() assert(r != NULL); assert(r->recType != RC_MISSING); r->recName = rec; + r->recIndex = i; records[i] = r; r->read(this); @@ -329,9 +329,6 @@ void NIFFile::parse() tree, but for the moment we ignore it. */ - // TODO: Set up kf file here first, if applicable. It needs its own - // code to link it up with the main NIF structure. - // Once parsing is done, do post-processing. for(int i=0; ipost(this); @@ -375,3 +372,5 @@ Ogre::Matrix4 Node::getWorldTransform() const return parent->getWorldTransform() * getLocalTransform(); return getLocalTransform(); } + +} diff --git a/components/nif/record.hpp b/components/nif/record.hpp index 5c4141fa98..d5f65e83a3 100644 --- a/components/nif/record.hpp +++ b/components/nif/record.hpp @@ -91,8 +91,9 @@ struct Record // Record type and type name int recType; std::string recName; + size_t recIndex; - Record() : recType(RC_MISSING) {} + Record() : recType(RC_MISSING), recIndex(~(size_t)0) {} /// Parses the record from file virtual void read(NIFFile *nif) = 0; From b23fcb260cc75aebd5f6f27485320e14e78c3d1c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 13 Jan 2013 08:00:04 -0800 Subject: [PATCH 2/2] Use the record index for finding the NiTriShape instead of the name --- components/nif/nif_file.cpp | 6 ++--- components/nif/nif_file.hpp | 2 +- components/nifogre/ogre_nif_loader.cpp | 32 +++++++++++++++----------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/components/nif/nif_file.cpp b/components/nif/nif_file.cpp index 6b024ab68e..e6d3182eda 100644 --- a/components/nif/nif_file.cpp +++ b/components/nif/nif_file.cpp @@ -206,7 +206,7 @@ void NIFFile::parse() fail("Unsupported NIF version"); // Number of records - int recNum = getInt(); + size_t recNum = getInt(); records.resize(recNum); /* The format for 10.0.1.0 seems to be a bit different. After the @@ -218,7 +218,7 @@ void NIFFile::parse() we do not support or plan to support other versions yet. */ - for(int i=0;ipost(this); } diff --git a/components/nif/nif_file.hpp b/components/nif/nif_file.hpp index ded3f7362d..e8884cd4d4 100644 --- a/components/nif/nif_file.hpp +++ b/components/nif/nif_file.hpp @@ -146,7 +146,7 @@ public: } /// Number of records - int numRecords() { return records.size(); } + size_t numRecords() { return records.size(); } /************************************************* Parser functions diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 777deabdf0..dfbc93ee90 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -695,9 +695,10 @@ class NIFMeshLoader : Ogre::ManualResourceLoader { std::string mName; std::string mGroup; - std::string mShapeName; - std::string mMaterialName; + size_t mShapeIndex; std::string mSkelName; + std::string mMaterialName; + std::string mShapeName; void warn(const std::string &msg) { @@ -805,7 +806,8 @@ class NIFMeshLoader : Ogre::ManualResourceLoader Ogre::VertexDeclaration *decl; int nextBuf = 0; - Ogre::SubMesh *sub = mesh->createSubMesh(shape->name); + Ogre::SubMesh *sub = ((mShapeName.length() > 0) ? mesh->createSubMesh(mShapeName) : + mesh->createSubMesh()); // Add vertices sub->useSharedVertices = false; @@ -912,13 +914,13 @@ class NIFMeshLoader : Ogre::ManualResourceLoader bool findTriShape(Ogre::Mesh *mesh, Nif::Node const *node) { - if(node->recType == Nif::RC_NiTriShape && mShapeName == node->name) + if(node->recType == Nif::RC_NiTriShape && mShapeIndex == node->recIndex) { - handleNiTriShape(mesh, dynamic_cast(node)); + handleNiTriShape(mesh, dynamic_cast(node)); return true; } - Nif::NiNode const *ninode = dynamic_cast(node); + const Nif::NiNode *ninode = dynamic_cast(node); if(ninode) { Nif::NodeList const &children = ninode->children; @@ -942,7 +944,7 @@ public: NIFMeshLoader() { } NIFMeshLoader(const std::string &name, const std::string &group, const std::string skelName) - : mName(name), mGroup(group), mSkelName(skelName) + : mName(name), mGroup(group), mShapeIndex(~(size_t)0), mSkelName(skelName) { } virtual void loadResource(Ogre::Resource *resource) @@ -950,15 +952,14 @@ public: Ogre::Mesh *mesh = dynamic_cast(resource); assert(mesh && "Attempting to load a mesh into a non-mesh resource!"); - if(!mShapeName.length()) + Nif::NIFFile::ptr nif = Nif::NIFFile::create(mName); + if(mShapeIndex >= nif->numRecords()) { - if(mSkelName.length() > 0) - mesh->setSkeletonName(mSkelName); + mesh->setSkeletonName(mSkelName); return; } - Nif::NIFFile::ptr nif = Nif::NIFFile::create (mName); - Nif::Node const *node = dynamic_cast(nif->getRecord(0)); + Nif::Node const *node = dynamic_cast(nif->getRecord(mShapeIndex)); findTriShape(mesh, node); } @@ -999,9 +1000,12 @@ public: if(node->recType == Nif::RC_NiTriShape) { const Nif::NiTriShape *shape = dynamic_cast(node); + mShapeName = shape->name; Ogre::MeshManager &meshMgr = Ogre::MeshManager::getSingleton(); - std::string fullname = mName+"@shape="+shape->name; + std::string fullname = mName+"@index="+Ogre::StringConverter::toString(shape->recIndex); + if(mShapeName.length() > 0) + fullname += "@shape="+mShapeName; if(mSkelName.length() > 0 && mName != mSkelName) fullname += "@skel="+mSkelName; @@ -1013,7 +1017,7 @@ public: *loader = *this; if(!(flags&0x01)) // Not hidden { - loader->mShapeName = shape->name; + loader->mShapeIndex = shape->recIndex; loader->mMaterialName = NIFMaterialLoader::getMaterial(shape, fullname, mGroup); }