Cleanup for instancing

This commit is contained in:
Marianne Gagnon 2014-03-23 18:55:45 -04:00
parent ae92b4007b
commit bb28e26eff
11 changed files with 73 additions and 54 deletions

View File

@ -301,7 +301,7 @@ src/tracks/check_manager.cpp
src/tracks/check_sphere.cpp src/tracks/check_sphere.cpp
src/tracks/check_structure.cpp src/tracks/check_structure.cpp
src/tracks/graph_node.cpp src/tracks/graph_node.cpp
src/tracks/lod_node_loader.cpp src/tracks/model_definition_loader.cpp
src/tracks/quad.cpp src/tracks/quad.cpp
src/tracks/quad_graph.cpp src/tracks/quad_graph.cpp
src/tracks/quad_set.cpp src/tracks/quad_set.cpp
@ -640,7 +640,7 @@ src/tracks/check_manager.hpp
src/tracks/check_sphere.hpp src/tracks/check_sphere.hpp
src/tracks/check_structure.hpp src/tracks/check_structure.hpp
src/tracks/graph_node.hpp src/tracks/graph_node.hpp
src/tracks/lod_node_loader.hpp src/tracks/model_definition_loader.hpp
src/tracks/quad.hpp src/tracks/quad.hpp
src/tracks/quad_graph.hpp src/tracks/quad_graph.hpp
src/tracks/quad_set.hpp src/tracks/quad_set.hpp

View File

@ -16,7 +16,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "tracks/lod_node_loader.hpp" #include "tracks/model_definition_loader.hpp"
using namespace irr; using namespace irr;
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
@ -30,14 +30,14 @@ using namespace irr;
#include <IMeshManipulator.h> #include <IMeshManipulator.h>
#include <algorithm> #include <algorithm>
LodNodeLoader::LodNodeLoader(Track* track) ModelDefinitionLoader::ModelDefinitionLoader(Track* track)
{ {
m_track = track; m_track = track;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void LodNodeLoader::addModelDefinition(const XMLNode* xml) void ModelDefinitionLoader::addModelDefinition(const XMLNode* xml)
{ {
float lod_distance = -1.0f; float lod_distance = -1.0f;
xml->get("lod_distance", &lod_distance); xml->get("lod_distance", &lod_distance);
@ -51,19 +51,19 @@ void LodNodeLoader::addModelDefinition(const XMLNode* xml)
std::string model_name; std::string model_name;
xml->get("model", &model_name); xml->get("model", &model_name);
m_lod_groups[lodgroup].push_back(LodModel(xml, (int)lod_distance, model_name, tangent)); m_lod_groups[lodgroup].push_back(ModelDefinition(xml, (int)lod_distance, model_name, tangent));
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
LODNode* LodNodeLoader::instanciateAsLOD(const XMLNode* node, scene::ISceneNode* parent) LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISceneNode* parent)
{ {
scene::ISceneManager* sm = irr_driver->getSceneManager(); scene::ISceneManager* sm = irr_driver->getSceneManager();
std::string groupname = ""; std::string groupname = "";
node->get("lod_group", &groupname); node->get("lod_group", &groupname);
std::vector< LodModel >& group = m_lod_groups[groupname]; std::vector< ModelDefinition >& group = m_lod_groups[groupname];
if (group.size() > 0) if (group.size() > 0)
{ {
@ -109,14 +109,14 @@ LODNode* LodNodeLoader::instanciateAsLOD(const XMLNode* node, scene::ISceneNode*
} }
else else
{ {
Log::warn("LodNodeLoader", "LOD group '%s' is empty", groupname.c_str()); Log::warn("ModelDefinitionLoader", "LOD group '%s' is empty", groupname.c_str());
return NULL; return NULL;
} }
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void LodNodeLoader::instanciate(const irr::core::vector3df& position, void ModelDefinitionLoader::instanciate(const irr::core::vector3df& position,
const irr::core::matrix4& transform, const irr::core::matrix4& transform,
const std::string& name) const std::string& name)
{ {
@ -138,7 +138,7 @@ void LodNodeLoader::instanciate(const irr::core::vector3df& position,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void LodNodeLoader::clear() void ModelDefinitionLoader::clear()
{ {
m_lod_groups.clear(); m_lod_groups.clear();
} }

View File

@ -38,23 +38,24 @@ namespace irr
} }
} }
struct ModelDefinition
struct LodModel
{ {
std::string m_model_file; std::string m_model_file;
bool m_tangent; bool m_tangent;
const XMLNode* m_xml; const XMLNode* m_xml;
/** For LOD */
int m_distance; int m_distance;
/** Constructor to allow storing this in STL containers */ /** Constructor to allow storing this in STL containers */
LodModel() ModelDefinition()
{ {
m_tangent = false; m_tangent = false;
m_distance = 0; m_distance = 0;
m_xml = NULL; m_xml = NULL;
} }
LodModel(const XMLNode* xml, int distance, std::string& model, bool tangent) ModelDefinition(const XMLNode* xml, int distance, std::string& model, bool tangent)
{ {
m_model_file = model; m_model_file = model;
m_tangent = tangent; m_tangent = tangent;
@ -62,23 +63,23 @@ struct LodModel
m_distance = distance; m_distance = distance;
} }
~LodModel() ~ModelDefinition()
{ {
} }
}; };
/** Utility class to load level-of-detail nodes /** Utility class to load level-of-detail nodes and instaincing nodes
* \ingroup tracks * \ingroup tracks
*/ */
class LodNodeLoader class ModelDefinitionLoader
{ {
private: private:
std::map< std::string, std::vector< LodModel > > m_lod_groups; std::map< std::string, std::vector< ModelDefinition > > m_lod_groups;
std::map< std::string, STKInstancedSceneNode* > m_instancing_nodes; std::map< std::string, STKInstancedSceneNode* > m_instancing_nodes;
Track* m_track; Track* m_track;
public: public:
LodNodeLoader(Track* track); ModelDefinitionLoader(Track* track);
void addModelDefinition(const XMLNode* xml); void addModelDefinition(const XMLNode* xml);
LODNode* instanciateAsLOD(const XMLNode* xml_node, scene::ISceneNode* parent); LODNode* instanciateAsLOD(const XMLNode* xml_node, scene::ISceneNode* parent);
@ -88,6 +89,6 @@ public:
void clear(); void clear();
}; // LodNodeLoader }; // ModelDefinitionLoader
#endif // HEADER_LOD_NODE_LOADER_HPP #endif // HEADER_LOD_NODE_LOADER_HPP

View File

@ -52,7 +52,7 @@
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
#include "tracks/bezier_curve.hpp" #include "tracks/bezier_curve.hpp"
#include "tracks/check_manager.hpp" #include "tracks/check_manager.hpp"
#include "tracks/lod_node_loader.hpp" #include "tracks/model_definition_loader.hpp"
#include "tracks/track_manager.hpp" #include "tracks/track_manager.hpp"
#include "tracks/quad_graph.hpp" #include "tracks/quad_graph.hpp"
#include "tracks/quad_set.hpp" #include "tracks/quad_set.hpp"
@ -880,7 +880,7 @@ bool Track::loadMainTrack(const XMLNode &root)
m_aabb_max.setY(m_aabb_max.getY()+30.0f); m_aabb_max.setY(m_aabb_max.getY()+30.0f);
World::getWorld()->getPhysics()->init(m_aabb_min, m_aabb_max); World::getWorld()->getPhysics()->init(m_aabb_min, m_aabb_max);
LodNodeLoader lodLoader(this); ModelDefinitionLoader lodLoader(this);
// Load LOD groups // Load LOD groups
const XMLNode *lod_xml_node = root.getNode("lod"); const XMLNode *lod_xml_node = root.getNode("lod");
@ -1538,7 +1538,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
loadMainTrack(*root); loadMainTrack(*root);
unsigned int main_track_count = m_all_nodes.size(); unsigned int main_track_count = m_all_nodes.size();
LodNodeLoader lod_loader(this); ModelDefinitionLoader model_def_loader(this);
// Load LOD groups // Load LOD groups
const XMLNode *lod_xml_node = root->getNode("lod"); const XMLNode *lod_xml_node = root->getNode("lod");
@ -1549,7 +1549,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
const XMLNode* lod_group_xml = lod_xml_node->getNode(i); const XMLNode* lod_group_xml = lod_xml_node->getNode(i);
for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++) for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++)
{ {
lod_loader.addModelDefinition(lod_group_xml->getNode(j)); model_def_loader.addModelDefinition(lod_group_xml->getNode(j));
} }
} }
} }
@ -1563,13 +1563,13 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
const XMLNode* lod_group_xml = instancing_xml_node->getNode(i); const XMLNode* lod_group_xml = instancing_xml_node->getNode(i);
for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++) for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++)
{ {
lod_loader.addModelDefinition(lod_group_xml->getNode(j)); model_def_loader.addModelDefinition(lod_group_xml->getNode(j));
} }
} }
} }
std::map<std::string, XMLNode*> library_nodes; std::map<std::string, XMLNode*> library_nodes;
loadObjects(root, path, lod_loader, true, NULL, library_nodes); loadObjects(root, path, model_def_loader, true, NULL, library_nodes);
// Cleanup library nodes // Cleanup library nodes
for (std::map<std::string, XMLNode*>::iterator it = library_nodes.begin(); for (std::map<std::string, XMLNode*>::iterator it = library_nodes.begin();
@ -1737,7 +1737,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoader& lod_loader, void Track::loadObjects(const XMLNode* root, const std::string& path, ModelDefinitionLoader& model_def_loader,
bool create_lod_definitions, scene::ISceneNode* parent, bool create_lod_definitions, scene::ISceneNode* parent,
std::map<std::string, XMLNode*>& library_nodes) std::map<std::string, XMLNode*>& library_nodes)
{ {
@ -1753,7 +1753,7 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoa
if (name == "track" || name == "default-start") continue; if (name == "track" || name == "default-start") continue;
if (name == "object") if (name == "object")
{ {
m_track_object_manager->add(*node, parent, lod_loader); m_track_object_manager->add(*node, parent, model_def_loader);
} }
else if (name == "library") else if (name == "library")
{ {
@ -1798,7 +1798,21 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoa
const XMLNode* lod_group_xml = lod_xml_node->getNode(i); const XMLNode* lod_group_xml = lod_xml_node->getNode(i);
for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++) for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++)
{ {
lod_loader.addModelDefinition(lod_group_xml->getNode(j)); model_def_loader.addModelDefinition(lod_group_xml->getNode(j));
}
}
}
// Load instancing definitions
const XMLNode *instancing_xml_node = libroot->getNode("instancing");
if (instancing_xml_node != NULL)
{
for (unsigned int i = 0; i < instancing_xml_node->getNumNodes(); i++)
{
const XMLNode* instancing_group_xml = instancing_xml_node->getNode(i);
for (unsigned int j = 0; j < instancing_group_xml->getNumNodes(); j++)
{
model_def_loader.addModelDefinition(instancing_group_xml->getNode(j));
} }
} }
} }
@ -1814,7 +1828,7 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoa
parent->setRotation(hpr); parent->setRotation(hpr);
parent->setScale(scale); parent->setScale(scale);
parent->updateAbsolutePosition(); parent->updateAbsolutePosition();
loadObjects(libroot, lib_path, lod_loader, create_lod_definitions, parent, library_nodes); loadObjects(libroot, lib_path, model_def_loader, create_lod_definitions, parent, library_nodes);
} }
else if (name == "water") else if (name == "water")
{ {
@ -1858,7 +1872,7 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoa
{ {
if (UserConfigParams::m_graphical_effects) if (UserConfigParams::m_graphical_effects)
{ {
m_track_object_manager->add(*node, parent, lod_loader); m_track_object_manager->add(*node, parent, model_def_loader);
} }
} }
else if (name == "sky-dome" || name == "sky-box" || name == "sky-color") else if (name == "sky-dome" || name == "sky-box" || name == "sky-color")
@ -1871,7 +1885,7 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoa
} }
else if (name == "light") else if (name == "light")
{ {
m_track_object_manager->add(*node, parent, lod_loader); m_track_object_manager->add(*node, parent, model_def_loader);
} }
else if (name == "weather") else if (name == "weather")
{ {
@ -1911,6 +1925,10 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, LodNodeLoa
{ {
// handled above // handled above
} }
else if (name == "instancing")
{
// handled above
}
else if (name == "subtitles") else if (name == "subtitles")
{ {
std::vector<XMLNode*> subtitles; std::vector<XMLNode*> subtitles;

View File

@ -35,7 +35,7 @@ namespace irr
namespace scene { class IMesh; class ILightSceneNode; } namespace scene { class IMesh; class ILightSceneNode; }
} }
using namespace irr; using namespace irr;
class LodNodeLoader; class ModelDefinitionLoader;
#include "LinearMath/btTransform.h" #include "LinearMath/btTransform.h"
@ -401,7 +401,7 @@ private:
std::vector<MusicInformation*>& m_music ); std::vector<MusicInformation*>& m_music );
void loadCurves(const XMLNode &node); void loadCurves(const XMLNode &node);
void handleSky(const XMLNode &root, const std::string &filename); void handleSky(const XMLNode &root, const std::string &filename);
void loadObjects(const XMLNode* root, const std::string& path, LodNodeLoader& lod_loader, void loadObjects(const XMLNode* root, const std::string& path, ModelDefinitionLoader& lod_loader,
bool create_lod_definitions, scene::ISceneNode* parent, bool create_lod_definitions, scene::ISceneNode* parent,
std::map<std::string, XMLNode*>& library_nodes); std::map<std::string, XMLNode*>& library_nodes);

View File

@ -39,9 +39,9 @@
* \param lod_node Lod node (defaults to NULL). * \param lod_node Lod node (defaults to NULL).
*/ */
TrackObject::TrackObject(const XMLNode &xml_node, scene::ISceneNode* parent, TrackObject::TrackObject(const XMLNode &xml_node, scene::ISceneNode* parent,
LodNodeLoader& lod_loader) ModelDefinitionLoader& model_def_loader)
{ {
init(xml_node, parent, lod_loader); init(xml_node, parent, model_def_loader);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -80,7 +80,7 @@ TrackObject::TrackObject(const core::vector3df& xyz, const core::vector3df& hpr,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent, void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
LodNodeLoader& lod_loader) ModelDefinitionLoader& model_def_loader)
{ {
m_init_xyz = core::vector3df(0,0,0); m_init_xyz = core::vector3df(0,0,0);
m_init_hpr = core::vector3df(0,0,0); m_init_hpr = core::vector3df(0,0,0);
@ -163,14 +163,14 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
{ {
m_type = "lod"; m_type = "lod";
TrackObjectPresentationInstancing* instancing_node = TrackObjectPresentationInstancing* instancing_node =
new TrackObjectPresentationInstancing(xml_node, parent, lod_loader); new TrackObjectPresentationInstancing(xml_node, parent, model_def_loader);
m_presentation = instancing_node; m_presentation = instancing_node;
} }
else if (lod_instance) else if (lod_instance)
{ {
m_type = "lod"; m_type = "lod";
TrackObjectPresentationLOD* lod_node = TrackObjectPresentationLOD* lod_node =
new TrackObjectPresentationLOD(xml_node, parent, lod_loader); new TrackObjectPresentationLOD(xml_node, parent, model_def_loader);
m_presentation = lod_node; m_presentation = lod_node;
glownode = ((LODNode*)lod_node->getNode())->getAllNodes()[0]; glownode = ((LODNode*)lod_node->getNode())->getAllNodes()[0];

View File

@ -31,7 +31,7 @@
class XMLNode; class XMLNode;
class ThreeDAnimation; class ThreeDAnimation;
class LodNodeLoader; class ModelDefinitionLoader;
/** /**
* \ingroup tracks * \ingroup tracks
@ -82,10 +82,10 @@ protected:
ThreeDAnimation* m_animator; ThreeDAnimation* m_animator;
void init(const XMLNode &xml_node, scene::ISceneNode* parent, LodNodeLoader& lod_loader); void init(const XMLNode &xml_node, scene::ISceneNode* parent, ModelDefinitionLoader& model_def_loader);
public: public:
TrackObject(const XMLNode &xml_node, scene::ISceneNode* parent, LodNodeLoader& lod_loader); TrackObject(const XMLNode &xml_node, scene::ISceneNode* parent, ModelDefinitionLoader& model_def_loader);
TrackObject(const core::vector3df& xyz, TrackObject(const core::vector3df& xyz,
const core::vector3df& hpr, const core::vector3df& hpr,

View File

@ -49,11 +49,11 @@ TrackObjectManager::~TrackObjectManager()
* in a separate section that's read before everything and remove all this * in a separate section that's read before everything and remove all this
* crap * crap
*/ */
void TrackObjectManager::add(const XMLNode &xml_node, scene::ISceneNode* parent, LodNodeLoader& lod_loader) void TrackObjectManager::add(const XMLNode &xml_node, scene::ISceneNode* parent, ModelDefinitionLoader& model_def_loader)
{ {
try try
{ {
m_all_objects.push_back(new TrackObject(xml_node, parent, lod_loader)); m_all_objects.push_back(new TrackObject(xml_node, parent, model_def_loader));
} }
catch (std::exception& e) catch (std::exception& e)
{ {

View File

@ -49,7 +49,7 @@ protected:
public: public:
TrackObjectManager(); TrackObjectManager();
~TrackObjectManager(); ~TrackObjectManager();
void add(const XMLNode &xml_node, scene::ISceneNode* parent, LodNodeLoader& lod_loader); void add(const XMLNode &xml_node, scene::ISceneNode* parent, ModelDefinitionLoader& model_def_loader);
void update(float dt); void update(float dt);
void handleExplosion(const Vec3 &pos, const PhysicalObject *mp, void handleExplosion(const Vec3 &pos, const PhysicalObject *mp,
bool secondary_hits=true); bool secondary_hits=true);

View File

@ -34,7 +34,7 @@
#include "modes/world.hpp" #include "modes/world.hpp"
#include "states_screens/dialogs/race_paused_dialog.hpp" #include "states_screens/dialogs/race_paused_dialog.hpp"
#include "states_screens/dialogs/tutorial_message_dialog.hpp" #include "states_screens/dialogs/tutorial_message_dialog.hpp"
#include "tracks/lod_node_loader.hpp" #include "tracks/model_definition_loader.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
#include <ISceneManager.h> #include <ISceneManager.h>
@ -138,10 +138,10 @@ TrackObjectPresentationEmpty::~TrackObjectPresentationEmpty()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
TrackObjectPresentationLOD::TrackObjectPresentationLOD(const XMLNode& xml_node, TrackObjectPresentationLOD::TrackObjectPresentationLOD(const XMLNode& xml_node,
scene::ISceneNode* parent, LodNodeLoader& lod_loader) : scene::ISceneNode* parent, ModelDefinitionLoader& model_def_loader) :
TrackObjectPresentationSceneNode(xml_node) TrackObjectPresentationSceneNode(xml_node)
{ {
m_node = lod_loader.instanciateAsLOD(&xml_node, parent); m_node = model_def_loader.instanciateAsLOD(&xml_node, parent);
if (m_node == NULL) throw std::runtime_error("Cannot load LOD node"); if (m_node == NULL) throw std::runtime_error("Cannot load LOD node");
m_node->setPosition(m_init_xyz); m_node->setPosition(m_init_xyz);
m_node->setRotation(m_init_hpr); m_node->setRotation(m_init_hpr);
@ -158,7 +158,7 @@ TrackObjectPresentationLOD::~TrackObjectPresentationLOD()
TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNode& xml_node, TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNode& xml_node,
scene::ISceneNode* parent, scene::ISceneNode* parent,
LodNodeLoader& lod_loader) : TrackObjectPresentationSceneNode(xml_node) ModelDefinitionLoader& model_def_loader) : TrackObjectPresentationSceneNode(xml_node)
{ {
std::string instancing_model; std::string instancing_model;
xml_node.get("instancing_model", &instancing_model); xml_node.get("instancing_model", &instancing_model);
@ -168,7 +168,7 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo
m_node->setRotation(m_init_hpr); m_node->setRotation(m_init_hpr);
m_node->setScale(m_init_scale); m_node->setScale(m_init_scale);
m_node->updateAbsolutePosition(); m_node->updateAbsolutePosition();
lod_loader.instanciate(m_node->getAbsolutePosition(), m_node->getAbsoluteTransformation(), instancing_model); model_def_loader.instanciate(m_node->getAbsolutePosition(), m_node->getAbsoluteTransformation(), instancing_model);
} }
TrackObjectPresentationInstancing::~TrackObjectPresentationInstancing() TrackObjectPresentationInstancing::~TrackObjectPresentationInstancing()

View File

@ -40,7 +40,7 @@ class SFXBase;
class ParticleEmitter; class ParticleEmitter;
class PhysicalObject; class PhysicalObject;
class ThreeDAnimation; class ThreeDAnimation;
class LodNodeLoader; class ModelDefinitionLoader;
/** /**
* \ingroup tracks * \ingroup tracks
@ -152,7 +152,7 @@ public:
TrackObjectPresentationLOD(const XMLNode& xml_node, TrackObjectPresentationLOD(const XMLNode& xml_node,
scene::ISceneNode* parent, scene::ISceneNode* parent,
LodNodeLoader& lod_loader); ModelDefinitionLoader& model_def_loader);
virtual ~TrackObjectPresentationLOD(); virtual ~TrackObjectPresentationLOD();
}; };
@ -162,7 +162,7 @@ public:
TrackObjectPresentationInstancing(const XMLNode& xml_node, TrackObjectPresentationInstancing(const XMLNode& xml_node,
scene::ISceneNode* parent, scene::ISceneNode* parent,
LodNodeLoader& lod_loader); ModelDefinitionLoader& model_def_loader);
virtual ~TrackObjectPresentationInstancing(); virtual ~TrackObjectPresentationInstancing();
}; };