Improve behavior when using instancing with physics objects
This commit is contained in:
parent
91c4e9de94
commit
d08e81ab56
@ -25,6 +25,7 @@ using namespace irr;
|
||||
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/mesh_tools.hpp"
|
||||
#include "graphics/stkinstancedscenenode.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "modes/world.hpp"
|
||||
@ -243,6 +244,16 @@ void PhysicalObject::init()
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
else if (dynamic_cast<TrackObjectPresentationInstancing*>(presentation) != NULL)
|
||||
{
|
||||
TrackObjectPresentationInstancing* instancing = dynamic_cast<TrackObjectPresentationInstancing*>(presentation);
|
||||
STKInstancedSceneNode* instancing_group = instancing->getInstancingGroup();
|
||||
if (instancing_group != NULL)
|
||||
{
|
||||
scene::IMesh* mesh = instancing_group->getMesh();
|
||||
MeshTools::minMax3D(mesh, &min, &max);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[PhysicalObject] Unknown node type\n");
|
||||
|
@ -116,7 +116,7 @@ LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISc
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ModelDefinitionLoader::instanciate(const irr::core::vector3df& position,
|
||||
STKInstancedSceneNode* ModelDefinitionLoader::instanciate(const irr::core::vector3df& position,
|
||||
const irr::core::vector3df& rotation,
|
||||
const std::string& name)
|
||||
{
|
||||
@ -125,7 +125,7 @@ void ModelDefinitionLoader::instanciate(const irr::core::vector3df& position,
|
||||
if (m_lod_groups.find(name) == m_lod_groups.end())
|
||||
{
|
||||
Log::warn("Instancing", "Cannot find instancing model <%s>", name.c_str());
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
scene::IMesh* mesh = irr_driver->getMesh(m_lod_groups[name][0].m_model_file);
|
||||
@ -135,6 +135,7 @@ void ModelDefinitionLoader::instanciate(const irr::core::vector3df& position,
|
||||
}
|
||||
|
||||
m_instancing_nodes[name]->addInstance(position, rotation);
|
||||
return m_instancing_nodes[name];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -83,9 +83,9 @@ public:
|
||||
|
||||
void addModelDefinition(const XMLNode* xml);
|
||||
LODNode* instanciateAsLOD(const XMLNode* xml_node, scene::ISceneNode* parent);
|
||||
void instanciate(const core::vector3df& position,
|
||||
const irr::core::vector3df& rotation,
|
||||
const std::string& name);
|
||||
STKInstancedSceneNode* instanciate(const core::vector3df& position,
|
||||
const irr::core::vector3df& rotation,
|
||||
const std::string& name);
|
||||
|
||||
void clear();
|
||||
|
||||
|
@ -168,7 +168,7 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo
|
||||
m_node->setRotation(m_init_hpr);
|
||||
m_node->setScale(m_init_scale);
|
||||
m_node->updateAbsolutePosition();
|
||||
model_def_loader.instanciate(m_node->getAbsolutePosition(),
|
||||
m_instancing_group = model_def_loader.instanciate(m_node->getAbsolutePosition(),
|
||||
m_node->getAbsoluteTransformation().getRotationDegrees(),
|
||||
instancing_model);
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ class ParticleEmitter;
|
||||
class PhysicalObject;
|
||||
class ThreeDAnimation;
|
||||
class ModelDefinitionLoader;
|
||||
class STKInstancedSceneNode;
|
||||
|
||||
/**
|
||||
* \ingroup tracks
|
||||
@ -158,12 +159,15 @@ public:
|
||||
|
||||
class TrackObjectPresentationInstancing : public TrackObjectPresentationSceneNode
|
||||
{
|
||||
STKInstancedSceneNode* m_instancing_group;
|
||||
public:
|
||||
|
||||
TrackObjectPresentationInstancing(const XMLNode& xml_node,
|
||||
scene::ISceneNode* parent,
|
||||
ModelDefinitionLoader& model_def_loader);
|
||||
virtual ~TrackObjectPresentationInstancing();
|
||||
|
||||
STKInstancedSceneNode* getInstancingGroup() { return m_instancing_group; }
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user