/* render/model.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #include "sys/sys.h" #include "model/model.h" #include "model/asefile.h" #include "model/mapfile.h" #include "model/vertexarray.h" namespace model { // static model registry Model::Registry Model::model_registry; Model::Model(const std::string & name) : model_enginecolor(1.0f, 0.0f, 0.0f), model_name(name) { model_radius = 0.5f; model_enginesound = 0; model_impulsesound = 0; model_tris_detail_count = 0; model_tris_count = 0; model_quad_detail_count = 0; model_quad_count = 0; } Model::~Model() { // delete all fragment groups for (Groups::iterator git = model_groups.begin(); git != model_groups.end(); git++) { delete (*git); } model_groups.clear(); // delete all docks for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); dit++) { delete (*dit); } model_docks.clear(); // delete all particle systems for (Model::ParticleSystems::iterator pit = model_particles.begin(); pit != model_particles.end(); pit++) { delete (*pit); } model_particles.clear(); // delete all lights for (Lights::iterator lit = model_lights.begin(); lit != model_lights.end(); lit++) { delete(*lit); } model_lights.clear(); // delete all flares for (Flares::iterator flit = model_flares.begin(); flit != model_flares.end(); flit++) { delete(*flit); } model_flares.clear(); } void Model::set_radius(const float radius) { model_radius = radius; } void Model::set_origin(const math::Vector3f &origin) { model_origin.assign(origin); } void Model::add_particles(Particles *particles) { model_particles.push_back(particles); } void Model::add_group(FragmentGroup *group) { model_groups.push_back(group); } void Model::add_light(Light *light) { model_lights.push_back(light); } void Model::add_flare(Flare *flare) { model_flares.push_back(flare); } void Model::add_dock(Dock *dock) { model_docks.push_back(dock); } Model *Model::find(const std::string & name) { Registry::iterator it = model_registry.find(name); if (it == model_registry.end()) return 0; else return (*it).second; } Model *Model::load(const std::string & name) { Model *model = find(name); if (!model) { // try loading the .map model model = MapFile::load(name); } if (!model) { // if it can't be found, try the ase model model = ASEFile::load(name); } if (!model) { con_warn << "Could not open model " << name << std::endl; } else { model_registry[model->name()] = model; } return model; } void Model::clear() { // delete all models in the registry for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) { delete(*mit).second; } model_registry.clear(); // clear the vertex array if (VertexArray::instance()) VertexArray::instance()->clear(); } void Model::list_model(Model *model) { size_t frags = 0; for (Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) { frags += (*git)->size(); } con_print << " " << model->name() << " " << frags << " frags " << model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " << model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl; } void Model::list() { for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) { list_model((*mit).second); } con_print << model_registry.size() << " registered models" << std::endl; if (VertexArray::instance()) { con_print << "vertex array " << VertexArray::instance()->index() * 3 * sizeof(float) / (1024*1024) << "/" << VertexArray::instance()->size() * 3 * sizeof(float) / (1024*1024) << "Mb " << VertexArray::instance()->index() / 3 << "/" << VertexArray::instance()->size() / 3 << " verts " << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size())<< "% used" << std::endl; } } }