From d08e81ab56f958d1ed3883afe39cbac10ae26a06 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sat, 29 Mar 2014 18:39:15 -0400 Subject: [PATCH] Improve behavior when using instancing with physics objects --- src/physics/physical_object.cpp | 11 +++++++++++ src/tracks/model_definition_loader.cpp | 5 +++-- src/tracks/model_definition_loader.hpp | 6 +++--- src/tracks/track_object_presentation.cpp | 2 +- src/tracks/track_object_presentation.hpp | 4 ++++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 1e9ebb9f4..4ebd43dff 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -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(presentation) != NULL) + { + TrackObjectPresentationInstancing* instancing = dynamic_cast(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"); diff --git a/src/tracks/model_definition_loader.cpp b/src/tracks/model_definition_loader.cpp index 378e178f4..8f25931f7 100644 --- a/src/tracks/model_definition_loader.cpp +++ b/src/tracks/model_definition_loader.cpp @@ -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]; } // ---------------------------------------------------------------------------- diff --git a/src/tracks/model_definition_loader.hpp b/src/tracks/model_definition_loader.hpp index ba28770c8..f8aaf4544 100644 --- a/src/tracks/model_definition_loader.hpp +++ b/src/tracks/model_definition_loader.hpp @@ -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(); diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 98c2efe2a..4abeb053e 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -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); } diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index 7da7fed47..469f7ce7d 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -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; } }; /**