Remove manual LOD code, it's now automatic

This commit is contained in:
Marianne Gagnon 2014-09-02 18:54:38 -04:00
parent 3083df450f
commit 102e517497
7 changed files with 3 additions and 179 deletions

View File

@ -241,16 +241,6 @@ void PhysicalObject::init()
Log::fatal("PhysicalObject", "Unknown node type");
}
}
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
{
Log::fatal("PhysicalObject", "Unknown node type");

View File

@ -111,35 +111,6 @@ LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISc
// ----------------------------------------------------------------------------
STKInstancedSceneNode* ModelDefinitionLoader::instanciate(const irr::core::vector3df& position,
const irr::core::vector3df& rotation,
const irr::core::vector3df scale,
const std::string& name)
{
if (m_instancing_nodes.find(name) == m_instancing_nodes.end())
{
if (m_lod_groups.find(name) == m_lod_groups.end())
{
Log::warn("Instancing", "Cannot find instancing model <%s>", name.c_str());
return NULL;
}
scene::IMesh* mesh = irr_driver->getMesh(m_lod_groups[name][0].m_model_file);
mesh = MeshTools::createMeshWithTangents(mesh, &MeshTools::isNormalMap);
irr_driver->setAllMaterialFlags(mesh);
m_instancing_nodes[name] = new STKInstancedSceneNode(mesh,
irr_driver->getSceneManager()->getRootSceneNode(), irr_driver->getSceneManager(), -1);
m_track->addNode(m_instancing_nodes[name]);
}
m_instancing_nodes[name]->addInstance(position, rotation, scale);
m_instancing_nodes[name]->instanceGrab();
return m_instancing_nodes[name];
}
// ----------------------------------------------------------------------------
void ModelDefinitionLoader::clear()
{
m_lod_groups.clear();

View File

@ -83,10 +83,6 @@ public:
void addModelDefinition(const XMLNode* xml);
LODNode* instanciateAsLOD(const XMLNode* xml_node, scene::ISceneNode* parent);
STKInstancedSceneNode* instanciate(const core::vector3df& position,
const irr::core::vector3df& rotation,
const irr::core::vector3df scale,
const std::string& name);
void clear();

View File

@ -742,24 +742,10 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
node->updateAbsolutePosition();
std::vector<core::matrix4> matrices;
STKInstancedSceneNode* instancing_node = NULL;// dynamic_cast<STKInstancedSceneNode*>(node);
if (instancing_node != NULL)
{
int count = instancing_node->getInstanceCount();
for (int i = 0; i < count; i++)
{
matrices.push_back(instancing_node->getInstanceTransform(i));
}
}
else
{
matrices.push_back(node->getAbsoluteTransformation());
}
matrices.push_back(node->getAbsoluteTransformation());
const core::vector3df &pos = node->getAbsolutePosition();
scene::IMesh *mesh;
// In case of readonly materials we have to get the material from
// the mesh, otherwise from the node. This is esp. important for
@ -1063,20 +1049,6 @@ bool Track::loadMainTrack(const XMLNode &root)
}
}
// Load instancing models (for the moment they are loaded the same way as LOD to simplify implementation)
const XMLNode *instancing_xml_node = NULL;// root.getNode("instancing");
if (instancing_xml_node != NULL)
{
for (unsigned int i = 0; i < instancing_xml_node->getNumNodes(); i++)
{
const XMLNode* lod_group_xml = instancing_xml_node->getNode(i);
for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++)
{
lodLoader.addModelDefinition(lod_group_xml->getNode(j));
}
}
}
for (unsigned int i=0; i<track_node->getNumNodes(); i++)
{
const XMLNode *n=track_node->getNode(i);
@ -1756,20 +1728,6 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
}
}
// Load instancing models (for the moment they are loaded the same way as LOD to simplify implementation)
const XMLNode *instancing_xml_node = NULL;// root->getNode("instancing");
if (instancing_xml_node != NULL)
{
for (unsigned int i = 0; i < instancing_xml_node->getNumNodes(); i++)
{
const XMLNode* lod_group_xml = instancing_xml_node->getNode(i);
for (unsigned int j = 0; j < lod_group_xml->getNumNodes(); j++)
{
model_def_loader.addModelDefinition(lod_group_xml->getNode(j));
}
}
}
std::map<std::string, XMLNode*> library_nodes;
loadObjects(root, path, model_def_loader, true, NULL, library_nodes);
@ -2010,20 +1968,6 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, ModelDefin
}
}
}
// Load instancing definitions
const XMLNode *instancing_xml_node = NULL;// 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));
}
}
}
}
else
{
@ -2128,7 +2072,7 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, ModelDefin
}
else if (name == "instancing")
{
// handled above
// TODO: eventually remove, this is now automatic
}
else if (name == "subtitles")
{

View File

@ -103,9 +103,6 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
bool lod_instance = false;
xml_node.get("lod_instance", &lod_instance);
bool instancing = false;
// xml_node.get("instancing", &instancing);
m_soccer_ball = false;
xml_node.get("soccer_ball", &m_soccer_ball);
@ -159,14 +156,7 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
{
scene::ISceneNode *glownode = NULL;
if (instancing)
{
m_type = "lod";
TrackObjectPresentationInstancing* instancing_node =
new TrackObjectPresentationInstancing(xml_node, parent, model_def_loader);
m_presentation = instancing_node;
}
else if (lod_instance)
if (lod_instance)
{
m_type = "lod";
TrackObjectPresentationLOD* lod_node =

View File

@ -168,59 +168,6 @@ TrackObjectPresentationLOD::~TrackObjectPresentationLOD()
// ----------------------------------------------------------------------------
TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNode& xml_node,
scene::ISceneNode* parent,
ModelDefinitionLoader& model_def_loader) : TrackObjectPresentationSceneNode(xml_node)
{
m_instancing_group = NULL;
m_fallback_scene_node = NULL;
std::string instancing_model;
xml_node.get("instancing_model", &instancing_model);
m_node = irr_driver->getSceneManager()->addEmptySceneNode(parent);
m_node->setPosition(m_init_xyz);
m_node->setRotation(m_init_hpr);
m_node->setScale(m_init_scale);
m_node->updateAbsolutePosition();
if (irr_driver->isGLSL())
{
m_instancing_group = model_def_loader.instanciate(m_node->getAbsolutePosition(),
m_node->getAbsoluteTransformation().getRotationDegrees(), m_node->getAbsoluteTransformation().getScale(),
instancing_model);
}
else
{
scene::IMesh* mesh = model_def_loader.getFirstMeshFor(instancing_model);
scene::IMeshSceneNode* node = irr_driver->addMesh(mesh, m_node);
node->grab();
irr_driver->grabAllTextures(mesh);
mesh->grab();
World::getWorld()->getTrack()->addNode(node);
m_fallback_scene_node = node;
}
}
TrackObjectPresentationInstancing::~TrackObjectPresentationInstancing()
{
if (m_instancing_group != NULL)
m_instancing_group->instanceDrop();
if (m_fallback_scene_node != NULL)
{
scene::IMesh* mesh = m_fallback_scene_node->getMesh();
irr_driver->dropAllTextures(mesh);
mesh->drop();
if (mesh->getReferenceCount() == 1)
irr_driver->removeMeshFromCache(mesh);
m_fallback_scene_node->drop();
}
}
// ----------------------------------------------------------------------------
TrackObjectPresentationMesh::TrackObjectPresentationMesh(const XMLNode& xml_node,
bool enabled, scene::ISceneNode* parent) :
TrackObjectPresentationSceneNode(xml_node)

View File

@ -167,20 +167,6 @@ public:
virtual ~TrackObjectPresentationLOD();
};
class TrackObjectPresentationInstancing : public TrackObjectPresentationSceneNode
{
STKInstancedSceneNode* m_instancing_group;
scene::IMeshSceneNode* m_fallback_scene_node;
public:
TrackObjectPresentationInstancing(const XMLNode& xml_node,
scene::ISceneNode* parent,
ModelDefinitionLoader& model_def_loader);
virtual ~TrackObjectPresentationInstancing();
STKInstancedSceneNode* getInstancingGroup() { return m_instancing_group; }
};
/**
* \ingroup tracks
* A track object representation that consists of a mesh scene node.