mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-06-27 16:51:34 +00:00
Use nodemasks and visitors for detecting custom collision shapes
This commit is contained in:
parent
e91d1a2b42
commit
45fde84f4f
2 changed files with 14 additions and 8 deletions
|
@ -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
|
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
|
// Check first if there's a custom collision node
|
||||||
|
unsigned int visitAllNodesMask = 0xffffffff;
|
||||||
SceneUtil::FindByNameVisitor nameFinder("Collision");
|
SceneUtil::FindByNameVisitor nameFinder("Collision");
|
||||||
|
nameFinder.setTraversalMask(visitAllNodesMask);
|
||||||
|
nameFinder.setNodeMaskOverride(visitAllNodesMask);
|
||||||
node->accept(nameFinder);
|
node->accept(nameFinder);
|
||||||
if (nameFinder.mFoundNode)
|
if (nameFinder.mFoundNode)
|
||||||
{
|
{
|
||||||
NodeToShapeVisitor visitor;
|
NodeToShapeVisitor visitor;
|
||||||
|
visitor.setTraversalMask(visitAllNodesMask);
|
||||||
|
visitor.setNodeMaskOverride(visitAllNodesMask);
|
||||||
nameFinder.mFoundNode->accept(visitor);
|
nameFinder.mFoundNode->accept(visitor);
|
||||||
shape = visitor.getShape();
|
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
|
// Generate a collision shape from the mesh
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <components/sceneutil/util.hpp>
|
#include <components/sceneutil/util.hpp>
|
||||||
#include <components/sceneutil/controller.hpp>
|
#include <components/sceneutil/controller.hpp>
|
||||||
#include <components/sceneutil/optimizer.hpp>
|
#include <components/sceneutil/optimizer.hpp>
|
||||||
|
#include <components/sceneutil/visitor.hpp>
|
||||||
|
|
||||||
#include <components/shader/shadervisitor.hpp>
|
#include <components/shader/shadervisitor.hpp>
|
||||||
#include <components/shader/shadermanager.hpp>
|
#include <components/shader/shadermanager.hpp>
|
||||||
|
@ -373,6 +374,14 @@ namespace Resource
|
||||||
errormsg << "Error loading " << normalizedFilename << ": " << result.message() << " code " << result.status() << std::endl;
|
errormsg << "Error loading " << normalizedFilename << ": " << result.message() << " code " << result.status() << std::endl;
|
||||||
throw std::runtime_error(errormsg.str());
|
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();
|
return result.getNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue