From 7686628401604098266f9f078194fac291592532 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Sat, 6 Dec 2014 19:51:46 -0500 Subject: [PATCH] Allow animated meshes in LOD, fixes #1747 --- src/tracks/model_definition_loader.cpp | 61 ++++++++++++++++++-------- src/tracks/model_definition_loader.hpp | 8 +++- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/tracks/model_definition_loader.cpp b/src/tracks/model_definition_loader.cpp index c6c29a17b..14fe029e2 100644 --- a/src/tracks/model_definition_loader.cpp +++ b/src/tracks/model_definition_loader.cpp @@ -45,13 +45,13 @@ void ModelDefinitionLoader::addModelDefinition(const XMLNode* xml) std::string lodgroup; xml->get("lod_group", &lodgroup); - bool tangent = false; - xml->get("tangents", &tangent); + bool skeletal_animation = false; + xml->get("skeletal-animation", &skeletal_animation); std::string model_name; xml->get("model", &model_name); - m_lod_groups[lodgroup].push_back(ModelDefinition(xml, (int)lod_distance, model_name, tangent)); + m_lod_groups[lodgroup].push_back(ModelDefinition(xml, (int)lod_distance, model_name, false, skeletal_animation)); } // ---------------------------------------------------------------------------- @@ -72,28 +72,51 @@ LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISc lod_node->updateAbsolutePosition(); for (unsigned int m=0; mgetMesh(group[m].m_model_file); - - if (!a_mesh) + if (group[m].m_skeletal_animation) { - Log::warn("LODNodeLoad", "Warning: object model '%s' not found, ignored.\n", - group[m].m_model_file.c_str()); - continue; + scene::IAnimatedMesh* a_mesh = irr_driver->getAnimatedMesh(group[m].m_model_file); + if (!a_mesh) + { + Log::warn("LODNodeLoad", "Warning: object model '%s' not found, ignored.\n", + group[m].m_model_file.c_str()); + continue; + } + + irr_driver->setAllMaterialFlags(a_mesh); + + a_mesh->grab(); + //cache.push_back(a_mesh); + irr_driver->grabAllTextures(a_mesh); + m_track->addCachedMesh(a_mesh); + scene::IAnimatedMeshSceneNode* scene_node = irr_driver->addAnimatedMesh(a_mesh, group[m].m_model_file); + + m_track->handleAnimatedTextures(scene_node, *group[m].m_xml); + + lod_node->add(group[m].m_distance, scene_node, true); } + else + { + scene::IMesh* a_mesh = irr_driver->getMesh(group[m].m_model_file); + if (!a_mesh) + { + Log::warn("LODNodeLoad", "Warning: object model '%s' not found, ignored.\n", + group[m].m_model_file.c_str()); + continue; + } - a_mesh = MeshTools::createMeshWithTangents(a_mesh, &MeshTools::isNormalMap); - irr_driver->setAllMaterialFlags(a_mesh); + a_mesh = MeshTools::createMeshWithTangents(a_mesh, &MeshTools::isNormalMap); + irr_driver->setAllMaterialFlags(a_mesh); - a_mesh->grab(); - //cache.push_back(a_mesh); - irr_driver->grabAllTextures(a_mesh); - m_track->addCachedMesh(a_mesh); - scene::IMeshSceneNode* scene_node = irr_driver->addMesh(a_mesh, group[m].m_model_file); + a_mesh->grab(); + //cache.push_back(a_mesh); + irr_driver->grabAllTextures(a_mesh); + m_track->addCachedMesh(a_mesh); + scene::IMeshSceneNode* scene_node = irr_driver->addMesh(a_mesh, group[m].m_model_file); - m_track->handleAnimatedTextures( scene_node, *group[m].m_xml ); + m_track->handleAnimatedTextures(scene_node, *group[m].m_xml); - lod_node->add( group[m].m_distance, scene_node, true ); + lod_node->add(group[m].m_distance, scene_node, true); + } } #ifdef DEBUG diff --git a/src/tracks/model_definition_loader.hpp b/src/tracks/model_definition_loader.hpp index f7c669362..bc4f48dcb 100644 --- a/src/tracks/model_definition_loader.hpp +++ b/src/tracks/model_definition_loader.hpp @@ -42,26 +42,30 @@ namespace irr struct ModelDefinition { std::string m_model_file; - bool m_tangent; + bool m_tangent; // obsolete, TODO remove const XMLNode* m_xml; /** For LOD */ int m_distance; + bool m_skeletal_animation; + /** Constructor to allow storing this in STL containers */ ModelDefinition() { m_tangent = false; + m_skeletal_animation = false; m_distance = 0; m_xml = NULL; } - ModelDefinition(const XMLNode* xml, int distance, std::string& model, bool tangent) + ModelDefinition(const XMLNode* xml, int distance, std::string& model, bool tangent, bool skeletal_animation) { m_model_file = model; m_tangent = tangent; m_xml = xml; m_distance = distance; + m_skeletal_animation = skeletal_animation; } ~ModelDefinition()