From 1687737ca713cd0baeca3cf79950ef4877640c99 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 5 May 2011 18:08:45 +0000 Subject: Initial support for btCompoundShape and the infrastructure required to accomodate multiple meshes per collision model, added prototype files for signals --- src/model/mapfile.cc | 83 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 33 deletions(-) (limited to 'src/model/mapfile.cc') diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 20d4c5c..92349c0 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -174,6 +174,8 @@ void MapFile::clear_materials() delete(*mit).second; } map_materials.clear(); + + map_collisiontriangles.clear(); } bool MapFile::open(std::string const & mapname) @@ -357,12 +359,12 @@ bool MapFile::read_patchdef() std::string word; if (!(linestream >> word)) { - //con_debug << "Error reading trialing line ')'" << std::endl; + //con_debug << "Error reading trailing line ')'" << std::endl; return false; } if (word.compare(")") != 0) { - //con_debug << "No trialing line ')'" << std::endl; + //con_debug << "No trailing line ')'" << std::endl; return false; } } @@ -1300,8 +1302,25 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t } - // add the group to the model + // add the vertexgroup to the model model->add_group(group); + + // add collision triangles + if (map_load_clip) { + if (map_collisiontriangles.size()) { + CollisionMesh *collisionmesh = new CollisionMesh(); + + // add clip triangles to collision mesh + for (TriangleList::iterator it = map_collisiontriangles.begin(); it != map_collisiontriangles.end(); it++) { + Triangle *triangle = (*it); + collisionmesh->add_triangle(triangle->v0() - translation, triangle->v1() - translation, triangle->v2() - translation); + } + + // add the collision mesh to the collision model + model->collisionmodel()->add_mesh(collisionmesh); + } + } + } void MapFile::unknown_value() const @@ -1365,17 +1384,18 @@ Model * MapFile::load(std::string const &name) float r, s; std::string str; - // load clip into collision mesh - // if the model has been loaded before (e.g. on r_restart), the collision mesh won't be reloaded - // submodel clip will not be imported - model->set_collisionmesh(CollisionMesh::find(name)); - - if (CollisionMesh::initialized() && !model->collisionmesh()) { - mapfile.map_load_clip = true; + // load clip into collision meshes + // if the model has been loaded before (e.g. on r_restart), the collision model won't be reloaded + mapfile.map_collisionmodel = CollisionModel::find(name); + if (!mapfile.map_collisionmodel) { + mapfile.map_load_clip = true; + mapfile.map_collisionmodel = new CollisionModel(name); + CollisionModel::add(mapfile.map_collisionmodel); } else { mapfile.map_load_clip = false; } - + model->set_collisionmodel(mapfile.map_collisionmodel); + while (mapfile.getline()) { if (mapfile.got_classname("worldspawn")) { mapfile.clear_bbox(); @@ -1840,6 +1860,12 @@ Model * MapFile::load(std::string const &name) delete groupdst; } } + + /* TODO + * + * import submodel collision meshes + */ + // copy light tags for (Model::Lights::const_iterator lit = submodel_model->lights().begin(); lit != submodel_model->lights().end(); lit++) { @@ -1921,31 +1947,22 @@ Model * MapFile::load(std::string const &name) con_warn << mapfile.name() << " quake2 style brushes detected" << std::endl; con_debug << " " << mapfile.name() << " " << mapfile.map_brushes << " brushes " << - model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " << - model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl; + model->model_tris_count << " triangles " << + model->model_quad_count << " quads" << std::endl; - if (mapfile.map_load_clip) { - if (mapfile.map_collisiontriangles.size()) { - - CollisionMesh *collisionmesh = new CollisionMesh(name); - - // add clip triangles to collision mesh - for (TriangleList::iterator it = mapfile.map_collisiontriangles.begin(); it != mapfile.map_collisiontriangles.end(); it++) { - Triangle *triangle = (*it); - collisionmesh->add_triangle(triangle->v0() - map_center, triangle->v1() - map_center, triangle->v2() - map_center); - } - - // TODO merge submodel collision meshes - // seperate collision meshes for movers - - // register the mesh - CollisionMesh::add(collisionmesh); - model->set_collisionmesh(collisionmesh); - - con_debug << " " << mapfile.name() << " " << model->collisionmesh()->size() << " collision triangles" << std::endl; + if (mapfile.map_load_clip && model->collisionmodel() && model->collisionmodel()->meshes().size()) { + size_t collision_tris_count = 0; // total number of triangles in the collision model + size_t collision_mesh_count = 0; // number of meshes in the collision model + + for (CollisionModel::CollisionMeshes::const_iterator cmit = model->collisionmodel()->meshes().begin(); + cmit != model->collisionmodel()->meshes().end(); cmit++) { + collision_tris_count += (*cmit)->size(); + collision_mesh_count++; } + + con_debug << " " << mapfile.name() << " collision " << collision_tris_count << " triangles " << collision_mesh_count << " meshes" << std::endl; } - + return model; } -- cgit v1.2.3