From b2194398a4a8745e3e6b94b822d3b1f11b6ea458 Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 23 Mar 2011 13:42:28 +0100 Subject: [PATCH] fixed a bug in loading. Every collision mesh is correctly loaded now. --- components/nifbullet/bullet_nif_loader.cpp | 42 ++++++++++++++++++---- components/nifbullet/bullet_nif_loader.hpp | 7 +++- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 074d4fb8ea..301060cd6f 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -125,18 +125,47 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) return; } + bool hasCollisionNode = hasRootCollisionNode(node); + //do a first pass - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,false,false); + handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,false); //if collide = false, then it does a second pass which create a shape for raycasting. if(cShape->collide == false) { - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,false,true); + std::cout << "collide = false "<recType == Nif::RC_NiNode) + { + Nif::NodeList &list = ((Nif::NiNode*)node)->children; + int n = list.length(); + for (int i=0; irecType == Nif::RC_NiTriShape) + { + return false; + } + else if(node->recType == Nif::RC_RootCollisionNode) + { + return true; + } + + return false; +} + void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool isCollisionNode,bool raycastingOnly) + Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly) { // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. @@ -194,11 +223,11 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, { if (list.has(i)) { - handleNode(&list[i], flags,finalRot,finalPos,finalScale,isCollisionNode,raycastingOnly); + handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,isCollisionNode,raycastingOnly); } } } - else if (node->recType == Nif::RC_NiTriShape && isCollisionNode) + else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode)) { cShape->collide = true; handleNiTriShape(dynamic_cast(node), flags,finalRot,finalPos,finalScale,raycastingOnly); @@ -210,7 +239,7 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, for (int i=0; iaddChildShape(tr,NodeShape); + std::cout << "tri"; } void ManualBulletShapeLoader::load(const std::string &name,const std::string &group) diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index 0900ecb9fc..6039e8d71c 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -105,7 +105,12 @@ private: *Parse a node. */ void handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool isCollisionNode,bool raycastingOnly); + Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly); + + /** + *Helpler function + */ + bool hasRootCollisionNode(Nif::Node* node); /** *convert a NiTriShape to a bullet trishape.