From 2217847c5753be314a51b1b9263ecc7bdffbec76 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 18 Feb 2012 15:29:40 -0500 Subject: [PATCH] Fixing a crash --- components/nifogre/ogre_nif_loader.cpp | 23 +++++++++++++++++++++-- components/nifogre/ogre_nif_loader.hpp | 4 +++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 4e3864a67..2ac05f2c8 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -531,6 +531,8 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std { sub->addBoneAssignment(*it); } + if(mSkel.isNull()) + needBoneAssignments.push_back(sub); } // Helper math functions. Reinventing linear algebra for the win! @@ -945,7 +947,8 @@ void NIFLoader::handleNiTriShape(NiTriShape *shape, int flags, BoundsFinder &bou { // Add this vertex set to the bounding box bounds.add(optr, numVerts); - shapes.push_back(copy); + if(addShapes) + shapes.push_back(copy); // Create the submesh createOgreSubMesh(shape, material, vertexBoneAssignments); @@ -1066,9 +1069,11 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, //FIXME: "Bip01" isn't every time the root bone if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton { - + addShapes = true; mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); } + else if (!mSkel.isNull() && !parentBone) + addShapes = false; if (!mSkel.isNull()) //if there is a skeleton { @@ -1143,8 +1148,11 @@ void NIFLoader::handleNode(Nif::Node *node, int flags, void NIFLoader::loadResource(Resource *resource) { + addShapes = false; allanim.clear(); shapes.clear(); + needBoneAssignments.clear(); + // needBoneAssignments.clear(); mBoundingBox.setNull(); mesh = 0; mSkel.setNull(); @@ -1311,6 +1319,17 @@ void NIFLoader::loadResource(Resource *resource) if (!mSkel.isNull() ) { + for(std::vector::iterator iter = needBoneAssignments.begin(); iter != needBoneAssignments.end(); iter++) + { + int boneIndex = mSkel->getNumBones() - 1; + VertexBoneAssignment vba; + vba.boneIndex = boneIndex; + vba.vertexIndex = 0; + vba.weight = 1; + + + (*iter)->addBoneAssignment(vba); + } mesh->_notifySkeleton(mSkel); } } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b1e0943f5..1361ffaca 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -121,7 +121,7 @@ class NIFLoader : Ogre::ManualResourceLoader private: NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), - mFlipVertexWinding(false), mOutputAnimFiles(false) {} + mFlipVertexWinding(false), mOutputAnimFiles(false), addShapes(false) {} NIFLoader(NIFLoader& n) {} void calculateTransform(); @@ -189,6 +189,8 @@ class NIFLoader : Ogre::ManualResourceLoader std::map,ciLessBoost> allshapesmap; std::vector mAnim; std::vector mS; + std::vector needBoneAssignments; + bool addShapes; };