From e7a0b54c4717afdfa12a8847d5bc72b7b68290b4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 6 May 2011 17:08:21 +0000 Subject: Import submodel clip --- src/model/collisionmesh.cc | 49 +++++++++++++++------------------------------ src/model/collisionmesh.h | 36 ++++----------------------------- src/model/collisionmodel.cc | 5 ++--- src/model/collisionmodel.h | 2 -- src/model/mapfile.cc | 23 ++++++++++++++++----- 5 files changed, 40 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/model/collisionmesh.cc b/src/model/collisionmesh.cc index e341e9f..808da63 100644 --- a/src/model/collisionmesh.cc +++ b/src/model/collisionmesh.cc @@ -9,53 +9,36 @@ namespace model { -CollisionMesh::Registry CollisionMesh::collisionmesh_registry; -bool CollisionMesh::collisionmesh_initialized = false; - -void CollisionMesh::init() -{ - clear(); - collisionmesh_initialized = true; -} - -void CollisionMesh::shutdown() -{ - clear(); - collisionmesh_initialized = false; -} - -void CollisionMesh::add(CollisionMesh *collisionmesh) -{ - collisionmesh_registry.push_back(collisionmesh); -} - -void CollisionMesh::clear() -{ - con_debug << " clearing collision meshes" << std::endl; - - for (Registry::iterator i = collisionmesh_registry.begin(); i != collisionmesh_registry.end(); ++i) { - delete (*i); - (*i) = 0; - } - - collisionmesh_registry.clear(); -} - CollisionMesh::CollisionMesh() { collisionmesh_type = FragmentGroup::None; collisionmesh_size = 0; // btTriangleMesh (bool use32bitIndices=true, bool use4componentVertices=true) collisionmesh_triangles = new btTriangleMesh(true, false); + collisionmesh_owns_triangles = true; collisionmesh_scale = 1.0f; collisionmesh_speed = 0.0f; collisionmesh_distance = 0.0f; } +CollisionMesh::CollisionMesh(const CollisionMesh &other) +{ + collisionmesh_type = other.type(); + collisionmesh_size = other.size(); + collisionmesh_triangles = other.collisionmesh_triangles; + collisionmesh_owns_triangles = false; + + collisionmesh_scale = other.scale(); + collisionmesh_speed = other.speed(); + collisionmesh_distance = other.distance(); +} CollisionMesh::~CollisionMesh() { - delete collisionmesh_triangles; + if (collisionmesh_owns_triangles) + delete collisionmesh_triangles; + + collisionmesh_triangles = 0; } void CollisionMesh::set_params(const FragmentGroup *group) diff --git a/src/model/collisionmesh.h b/src/model/collisionmesh.h index 4ab1c19..e80774d 100644 --- a/src/model/collisionmesh.h +++ b/src/model/collisionmesh.h @@ -30,6 +30,9 @@ public: typedef std::list Registry; CollisionMesh(); + + /// copy constructor + CollisionMesh(const CollisionMesh &other); ~CollisionMesh(); @@ -131,38 +134,6 @@ public: */ void add_triangle(const math::Vector3f & v0, const math::Vector3f & v1, const math::Vector3f & v2); - /* ---- static ----------------------------------------------------- */ - - /** - * @brief initialize collisionmesh registry - */ - static void init(); - - /** - * @brief shutdown collisionmesh registry - */ - static void shutdown(); - - /** - * @brief clear collisionmesh registry - */ - static void clear(); - - /** - * @brief find a collisionmesh in the registry - */ - static CollisionMesh *find(const std::string &name); - - /** - * @brief add a collisionmesh to the registry - */ - static void add(CollisionMesh *collisionmesh); - - - inline static bool initialized() { - return collisionmesh_initialized; - } - private: /// the materials registry @@ -180,6 +151,7 @@ private: float collisionmesh_scale; float collisionmesh_distance; + bool collisionmesh_owns_triangles; }; } // namespace model diff --git a/src/model/collisionmodel.cc b/src/model/collisionmodel.cc index d52c9bc..fd2f67b 100644 --- a/src/model/collisionmodel.cc +++ b/src/model/collisionmodel.cc @@ -17,8 +17,9 @@ CollisionModel::CollisionModel(const std::string & label) : CollisionModel::~CollisionModel() { - // clear the list of meshes, do not delete the meshes + // delete meshes for (CollisionMeshes::iterator it = collisionmodel_meshes.begin(); it != collisionmodel_meshes.end(); it++) { + delete (*it); (*it) = 0; } collisionmodel_meshes.clear(); @@ -35,14 +36,12 @@ CollisionModel::Registry CollisionModel::collisionmodel_registry; void CollisionModel::init() { - CollisionMesh::init(); clear(); } void CollisionModel::shutdown() { clear(); - CollisionMesh::shutdown(); } CollisionModel *CollisionModel::find(const std::string & label) diff --git a/src/model/collisionmodel.h b/src/model/collisionmodel.h index 04268d2..ecb8047 100644 --- a/src/model/collisionmodel.h +++ b/src/model/collisionmodel.h @@ -65,8 +65,6 @@ public: /** * @brief add a mesh to the CollisionModel - * CollisionModel does not take ownership of the COllisionMesh, - * the mesh should be registered with the CollisionMesh::registry * */ void add_mesh(CollisionMesh *mesh); diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index b05880f..0abbdbd 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -1864,11 +1864,23 @@ Model * MapFile::load(std::string const &name) } } - /* TODO - * - * import submodel collision meshes - */ - + // import submodel collisionmodel meshes + if (mapfile.map_load_clip && submodel_model->collisionmodel()) { + for (CollisionModel::CollisionMeshes::iterator cmit = submodel_model->collisionmodel()->meshes().begin(); + cmit != submodel_model->collisionmodel()->meshes().end(); cmit++) { + + CollisionMesh *meshsrc = (*cmit); + CollisionMesh *meshdst = new CollisionMesh(*meshsrc); + + meshdst->set_type(meshsrc->type()); + meshdst->set_scale(meshsrc->scale() * tag_submodel->scale()); + + meshdst->set_location(tag_submodel->location() + tag_submodel->axis() * (meshsrc->location() - submodel_model->origin()) * tag_submodel->scale()); + meshdst->set_axis(tag_submodel->axis() * meshsrc->axis()); + + model->collisionmodel()->add_mesh(meshdst); + } + } // copy light tags for (Model::Lights::const_iterator lit = submodel_model->lights().begin(); lit != submodel_model->lights().end(); lit++) { @@ -1906,6 +1918,7 @@ Model * MapFile::load(std::string const &name) tag_dock->get_location().assign(tag_submodel->location() + tag_submodel->axis() * (tag_dock->location() - submodel_model->origin()) * tag_submodel->scale()); } } + delete tag_submodel; } -- cgit v1.2.3