mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Add option for custom collision node with non-nif files
This commit is contained in:
parent
bae27e8199
commit
384112746c
@ -115,6 +115,8 @@ namespace
|
||||
|
||||
std::string model = getModel(ptr, rendering.getResourceSystem()->getVFS());
|
||||
const auto rotation = makeNodeRotation(ptr, RotationOrder::direct);
|
||||
if (!physics.getObject(ptr))
|
||||
ptr.getClass().insertObject (ptr, model, rotation, physics);
|
||||
if (!onlyPhysics)
|
||||
{
|
||||
bool useAnim = ptr.getClass().useAnim();
|
||||
@ -134,8 +136,6 @@ namespace
|
||||
// Restore effect particles
|
||||
MWBase::Environment::get().getWorld()->applyLoopingParticles(ptr);
|
||||
}
|
||||
if (!physics.getObject(ptr))
|
||||
ptr.getClass().insertObject (ptr, model, rotation, physics);
|
||||
}
|
||||
|
||||
void addObject(const MWWorld::Ptr& ptr, const MWPhysics::PhysicsSystem& physics, DetourNavigator::Navigator& navigator)
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <BulletCollision/CollisionShapes/btTriangleMesh.h>
|
||||
|
||||
#include <components/sceneutil/visitor.hpp>
|
||||
#include <components/vfs/manager.hpp>
|
||||
|
||||
#include <components/nifbullet/bulletnifloader.hpp>
|
||||
@ -145,11 +146,34 @@ osg::ref_ptr<const BulletShape> BulletShapeManager::getShape(const std::string &
|
||||
|
||||
osg::ref_ptr<const osg::Node> constNode (mSceneManager->getTemplate(normalized));
|
||||
osg::ref_ptr<osg::Node> node (const_cast<osg::Node*>(constNode.get())); // const-trickery required because there is no const version of NodeVisitor
|
||||
NodeToShapeVisitor visitor;
|
||||
node->accept(visitor);
|
||||
shape = visitor.getShape();
|
||||
|
||||
// Check first if there's a custom collision node
|
||||
SceneUtil::FindByNameVisitor nameFinder("Collision");
|
||||
node->accept(nameFinder);
|
||||
if (nameFinder.mFoundNode)
|
||||
{
|
||||
NodeToShapeVisitor visitor;
|
||||
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
|
||||
if (!shape)
|
||||
return osg::ref_ptr<BulletShape>();
|
||||
{
|
||||
NodeToShapeVisitor visitor;
|
||||
node->accept(visitor);
|
||||
shape = visitor.getShape();
|
||||
if (!shape)
|
||||
return osg::ref_ptr<BulletShape>();
|
||||
}
|
||||
}
|
||||
|
||||
mCache->addEntryToObjectCache(normalized, shape);
|
||||
|
Loading…
x
Reference in New Issue
Block a user