Use nodemasks and visitors for detecting custom collision shapes

symlink-ci
Nelsson Huotari 4 years ago
parent e91d1a2b42
commit 45fde84f4f

@ -148,21 +148,18 @@ osg::ref_ptr<const BulletShape> BulletShapeManager::getShape(const std::string &
osg::ref_ptr<osg::Node> node (const_cast<osg::Node*>(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

@ -25,6 +25,7 @@
#include <components/sceneutil/util.hpp>
#include <components/sceneutil/controller.hpp>
#include <components/sceneutil/optimizer.hpp>
#include <components/sceneutil/visitor.hpp>
#include <components/shader/shadervisitor.hpp>
#include <components/shader/shadermanager.hpp>
@ -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();
}
}

Loading…
Cancel
Save