diff --git a/components/resource/bulletshapemanager.cpp b/components/resource/bulletshapemanager.cpp index aceb9bb35c..ad37eda0dd 100644 --- a/components/resource/bulletshapemanager.cpp +++ b/components/resource/bulletshapemanager.cpp @@ -148,21 +148,18 @@ osg::ref_ptr BulletShapeManager::getShape(const std::string & osg::ref_ptr node (const_cast(constNode.get())); // const-trickery required because there is no const version of NodeVisitor // Check first if there's a custom collision node + unsigned int visitAllNodesMask = 0xffffffff; SceneUtil::FindByNameVisitor nameFinder("Collision"); + nameFinder.setTraversalMask(visitAllNodesMask); + nameFinder.setNodeMaskOverride(visitAllNodesMask); node->accept(nameFinder); if (nameFinder.mFoundNode) { NodeToShapeVisitor visitor; + visitor.setTraversalMask(visitAllNodesMask); + visitor.setNodeMaskOverride(visitAllNodesMask); nameFinder.mFoundNode->accept(visitor); shape = visitor.getShape(); - for (unsigned int i = 0; i < nameFinder.mFoundNode->getNumParents(); ++i) - { - nameFinder.mFoundNode->getParent(i)->removeChild(nameFinder.mFoundNode); - } - - /* // CleanObjectRootVisitor is an alternative method - SceneUtil::CleanObjectRootVisitor cleanerVisitor; - nameFinder.mFoundNode->accept(cleanerVisitor);*/ } // Generate a collision shape from the mesh diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 70320760f5..19cc96433b 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -373,6 +374,14 @@ namespace Resource errormsg << "Error loading " << normalizedFilename << ": " << result.message() << " code " << result.status() << std::endl; throw std::runtime_error(errormsg.str()); } + + // Recognize and hide collision node + unsigned int hiddenNodeMask = 0; + SceneUtil::FindByNameVisitor nameFinder("Collision"); + result.getNode()->accept(nameFinder); + if (nameFinder.mFoundNode) + nameFinder.mFoundNode->setNodeMask(hiddenNodeMask); + return result.getNode(); } }