From 86ded891d92f4c4d13e6f5fde6b7920a9e8f9c73 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 22 Feb 2011 20:53:58 +0100 Subject: [PATCH] modified the nif loader for shapes used for raycasting only. --- components/nifbullet/bullet_nif_loader.cpp | 36 +++++++++++++++------- components/nifbullet/bullet_nif_loader.hpp | 6 ++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 6502dd629..3a97e0233 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -64,6 +64,7 @@ Ogre::Resource(creator, name, handle, group, isManual, loader) we have none as such. Full details can be set through scripts. */ Shape = NULL; + collide = true; createParamDictionary("BulletShape"); } @@ -197,6 +198,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) { cShape = static_cast(resource); resourceName = cShape->getName(); + cShape->collide = false; currentShape = new btCompoundShape(); cShape->Shape = currentShape; @@ -235,11 +237,18 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) return; } - handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,false); + //do a first pass + handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,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); + } } void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, - Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool isCollisionNode) + Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool isCollisionNode,bool raycastingOnly) { // Accumulate the flags from all the child nodes. This works for all // the flags we currently use, at least. @@ -259,14 +268,14 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, // affecting the entire subtree of this node Nif::NiStringExtraData *sd = (Nif::NiStringExtraData*)e; - if (sd->string == "NCO") + if (sd->string == "NCO" && !raycastingOnly) { // No collision. Use an internal flag setting to mark this. // We ignor this node! flags |= 0x800; return; } - else if (sd->string == "MRK") + else if (sd->string == "MRK" && !raycastingOnly) // Marker objects. These are only visible in the // editor. Until and unless we add an editor component to // the engine, just skip this entire node. @@ -297,11 +306,15 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, { if (list.has(i)) { - handleNode(&list[i], flags,finalRot,finalPos,finalScale,isCollisionNode); + handleNode(&list[i], flags,finalRot,finalPos,finalScale,isCollisionNode,raycastingOnly); } } - } - else if (node->recType == Nif::RC_NiTriShape && isCollisionNode) handleNiTriShape(dynamic_cast(node), flags,finalRot,finalPos,finalScale); + } + else if (node->recType == Nif::RC_NiTriShape && isCollisionNode) + { + cShape->collide = true; + handleNiTriShape(dynamic_cast(node), flags,finalRot,finalPos,finalScale,raycastingOnly); + } else if(node->recType == Nif::RC_RootCollisionNode) { Nif::NodeList &list = ((Nif::NiNode*)node)->children; @@ -309,12 +322,13 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags, for (int i=0; i