Fixing a crash

actorid
Jason Hooks 13 years ago
parent 2d0e83a2cf
commit 2217847c57

@ -531,6 +531,8 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std
{ {
sub->addBoneAssignment(*it); sub->addBoneAssignment(*it);
} }
if(mSkel.isNull())
needBoneAssignments.push_back(sub);
} }
// Helper math functions. Reinventing linear algebra for the win! // 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 // Add this vertex set to the bounding box
bounds.add(optr, numVerts); bounds.add(optr, numVerts);
shapes.push_back(copy); if(addShapes)
shapes.push_back(copy);
// Create the submesh // Create the submesh
createOgreSubMesh(shape, material, vertexBoneAssignments); 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 //FIXME: "Bip01" isn't every time the root bone
if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton if (node->name == "Bip01" || node->name == "Root Bone") //root node, create a skeleton
{ {
addShapes = true;
mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true); mSkel = SkeletonManager::getSingleton().create(getSkeletonName(), resourceGroup, true);
} }
else if (!mSkel.isNull() && !parentBone)
addShapes = false;
if (!mSkel.isNull()) //if there is a skeleton 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) void NIFLoader::loadResource(Resource *resource)
{ {
addShapes = false;
allanim.clear(); allanim.clear();
shapes.clear(); shapes.clear();
needBoneAssignments.clear();
// needBoneAssignments.clear();
mBoundingBox.setNull(); mBoundingBox.setNull();
mesh = 0; mesh = 0;
mSkel.setNull(); mSkel.setNull();
@ -1311,6 +1319,17 @@ void NIFLoader::loadResource(Resource *resource)
if (!mSkel.isNull() ) if (!mSkel.isNull() )
{ {
for(std::vector<Ogre::SubMesh*>::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); mesh->_notifySkeleton(mSkel);
} }
} }

@ -121,7 +121,7 @@ class NIFLoader : Ogre::ManualResourceLoader
private: private:
NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false), NIFLoader() : mNormaliseNormals(false), resourceGroup("General"), resourceName(""), flip(false),
mFlipVertexWinding(false), mOutputAnimFiles(false) {} mFlipVertexWinding(false), mOutputAnimFiles(false), addShapes(false) {}
NIFLoader(NIFLoader& n) {} NIFLoader(NIFLoader& n) {}
void calculateTransform(); void calculateTransform();
@ -189,6 +189,8 @@ class NIFLoader : Ogre::ManualResourceLoader
std::map<std::string,std::vector<Nif::NiTriShapeCopy>,ciLessBoost> allshapesmap; std::map<std::string,std::vector<Nif::NiTriShapeCopy>,ciLessBoost> allshapesmap;
std::vector<Nif::NiKeyframeData> mAnim; std::vector<Nif::NiKeyframeData> mAnim;
std::vector<Nif::NiTriShapeCopy> mS; std::vector<Nif::NiTriShapeCopy> mS;
std::vector<Ogre::SubMesh*> needBoneAssignments;
bool addShapes;
}; };

Loading…
Cancel
Save