Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-01-26 15:56:10 +0000
committerStijn Buys <ingar@osirion.org>2011-01-26 15:56:10 +0000
commitc3182222bd3fef6009f98205c0203d61a7509b11 (patch)
tree32046ab6ae2d54f0930f8d5289f45a6807874635 /src/model
parent035653e94a3d74b8f18c993034199d7cd08a895a (diff)
Corrected the origin alignment of collision mesh bodies.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/Makefile.am2
-rw-r--r--src/model/collisionmesh.cc12
-rw-r--r--src/model/collisionmesh.h2
-rw-r--r--src/model/mapfile.cc93
-rw-r--r--src/model/mapfile.h2
-rw-r--r--src/model/trianglelist.cc43
-rw-r--r--src/model/trianglelist.h46
7 files changed, 165 insertions, 35 deletions
diff --git a/src/model/Makefile.am b/src/model/Makefile.am
index cba5c48..de6d902 100644
--- a/src/model/Makefile.am
+++ b/src/model/Makefile.am
@@ -15,6 +15,7 @@ noinst_HEADERS = \
quad.h \
tags.h \
triangle.h \
+ trianglelist.h \
vertexarray.h
libmodel_la_SOURCES = \
@@ -29,6 +30,7 @@ libmodel_la_SOURCES = \
quad.cc \
tags.cc \
triangle.cc \
+ trianglelist.cc \
vertexarray.cc
libmodel_la_DEPENDENCIES = \
diff --git a/src/model/collisionmesh.cc b/src/model/collisionmesh.cc
index 616ee0d..b20074f 100644
--- a/src/model/collisionmesh.cc
+++ b/src/model/collisionmesh.cc
@@ -73,4 +73,16 @@ void CollisionMesh::add_triangle(const math::Vector3f & v0, const math::Vector3f
collisionmesh_size += 1;
}
+void CollisionMesh::translate(const math::Vector3f translation)
+{
+ /*
+ IndexedMeshArray & indexes = collisionmesh_triangles->getIndexedMeshArray();
+ for (size_t i =0; i < indexes.size(); i++) {
+ btIndexedMesh & mesh = indexes[i];
+
+
+ }
+ */
+}
+
} // namespace model
diff --git a/src/model/collisionmesh.h b/src/model/collisionmesh.h
index 9efd21a..7329a0e 100644
--- a/src/model/collisionmesh.h
+++ b/src/model/collisionmesh.h
@@ -58,6 +58,8 @@ public:
* @brief add a triangle to the collision mesh
*/
void add_triangle(const math::Vector3f & v0, const math::Vector3f & v1, const math::Vector3f & v2);
+
+ void translate(const math::Vector3f translation);
/* ---- static ----------------------------------------------------- */
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index bfe19c0..c5e2964 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -511,27 +511,47 @@ bool MapFile::read_patchdef()
const math::Vector3f zero;
for (size_t i = 0; i < subdivide_u; i++) {
for (size_t j = 0; j < subdivide_v; j++) {
- Quad *quad = new Quad(
- mesh[i+1][j+1] * SCALE,
- mesh[i][j+1] * SCALE,
- mesh[i][j] * SCALE,
- mesh[i+1][j] * SCALE,
- zero
- );
-
- quad->n0().assign(meshnormals[i+1][j+1]);
- quad->t0().assign(meshtexcoords[i+1][j+1]);
-
- quad->n1().assign(meshnormals[i][j+1]);
- quad->t1().assign(meshtexcoords[i][j+1]);
-
- quad->n2().assign(meshnormals[i][j]);
- quad->t2().assign(meshtexcoords[i][j]);
-
- quad->n3().assign(meshnormals[i+1][j]);
- quad->t3().assign(meshtexcoords[i+1][j]);
-
- primitives->add_quad(quad);
+
+ if ((material->flags() & Material::Clip) == Material::Clip) {
+
+ // if the current material is clip, the patch needs to be converted to triangles
+ if (map_load_clip) {
+ Triangle *triangle = new Triangle(
+ mesh[i+1][j+1] * SCALE,
+ mesh[i][j+1] * SCALE,
+ mesh[i][j] * SCALE);
+ primitives->add_triangle(triangle);
+
+ triangle = new Triangle(
+ mesh[i+1][j+1] * SCALE,
+ mesh[i][j] * SCALE,
+ mesh[i+1][j] * SCALE);
+ map_collisiontriangles.add(*triangle);
+ }
+ } else {
+ // not clip, convert to quads
+ Quad *quad = new Quad(
+ mesh[i+1][j+1] * SCALE,
+ mesh[i][j+1] * SCALE,
+ mesh[i][j] * SCALE,
+ mesh[i+1][j] * SCALE,
+ zero
+ );
+
+ quad->n0().assign(meshnormals[i+1][j+1]);
+ quad->t0().assign(meshtexcoords[i+1][j+1]);
+
+ quad->n1().assign(meshnormals[i][j+1]);
+ quad->t1().assign(meshtexcoords[i][j+1]);
+
+ quad->n2().assign(meshnormals[i][j]);
+ quad->t2().assign(meshtexcoords[i][j]);
+
+ quad->n3().assign(meshnormals[i+1][j]);
+ quad->t3().assign(meshtexcoords[i+1][j]);
+
+ primitives->add_quad(quad);
+ }
}
}
}
@@ -1213,10 +1233,11 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
group->add_fragment(fragment);
} else if (map_load_clip) {
- // clip materials are loaded into the CollisionArray
+ // clip materials are loaded into the CollisionMesh
for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) {
- Triangle *triangle = (*tris_it);
- model->collisionmesh()->add_triangle(triangle->v0(), triangle->v1(), triangle->v2());
+ Triangle *triangle = (*tris_it);
+ //model->collisionmesh()->add_triangle(triangle->v0(), triangle->v1(), triangle->v2());
+ map_collisiontriangles.add(*triangle);
}
}
}
@@ -1333,11 +1354,7 @@ Model * MapFile::load(std::string const &name)
model->set_collisionmesh(CollisionMesh::find(name));
if (CollisionMesh::initialized() && !model->collisionmesh()) {
- mapfile.map_load_clip = true;
-
- // create a collision mesh instance for the model
- model->set_collisionmesh(new CollisionMesh(name));
-
+ mapfile.map_load_clip = true;
} else {
mapfile.map_load_clip = false;
}
@@ -1892,12 +1909,18 @@ Model * MapFile::load(std::string const &name)
model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " <<
model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl;
- if (mapfile.map_load_clip) {
- if (!model->collisionmesh()->size()) {
- // delete empty collision meshes
- delete model->collisionmesh();
- model->set_collisionmesh(0);
- } else {
+ if (mapfile.map_load_clip) {
+ if (mapfile.map_collisiontriangles.size()) {
+
+ // create a collision mesh instance for the model
+ model->set_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);
+ model->collisionmesh()->add_triangle(triangle->v0() - map_center, triangle->v1() - map_center, triangle->v2() - map_center);
+ }
+
// add the collision mesh to the registry
CollisionMesh::add(model->collisionmesh());
con_debug << " " << mapfile.name() << " " << model->collisionmesh()->size() << " collision triangles" << std::endl;
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index ed63ad2..b576384 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -14,6 +14,7 @@
#include "model/model.h"
#include "model/face.h"
#include "model/primitives.h"
+#include "model/trianglelist.h"
#include "filesystem/filestream.h"
namespace model
@@ -202,6 +203,7 @@ private:
bool class_engine;
Materials map_materials;
+ TriangleList map_collisiontriangles;
bool warning_q2brush;
diff --git a/src/model/trianglelist.cc b/src/model/trianglelist.cc
new file mode 100644
index 0000000..1b3cea2
--- /dev/null
+++ b/src/model/trianglelist.cc
@@ -0,0 +1,43 @@
+/*
+ model/trianglelist.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "model/trianglelist.h"
+
+namespace model {
+
+TriangleList::TriangleList()
+{
+}
+
+TriangleList::~TriangleList()
+{
+ clear();
+}
+
+void TriangleList::clear()
+{
+ for (TriangleList::iterator it = trianglelist_triangles.begin(); it != trianglelist_triangles.end(); it++) {
+ delete (*it);
+ }
+
+ trianglelist_triangles.clear();
+}
+
+Triangle *TriangleList::add(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2)
+{
+ Triangle *new_triangle = new Triangle(v0, v1, v2);
+ trianglelist_triangles.push_back(new_triangle);
+ return new_triangle;
+}
+
+Triangle *TriangleList::add(Triangle &triangle)
+{
+ Triangle *new_triangle = new Triangle(triangle.v0(), triangle.v1(), triangle.v2());
+ trianglelist_triangles.push_back(new_triangle);
+ return new_triangle;
+}
+
+} // namespace model
diff --git a/src/model/trianglelist.h b/src/model/trianglelist.h
new file mode 100644
index 0000000..5746fae
--- /dev/null
+++ b/src/model/trianglelist.h
@@ -0,0 +1,46 @@
+/*
+ model/trianglelist.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_MODEL_TRIANGLELIST_H__
+#define __INCLUDED_MODEL_TRIANGLELIST_H__
+
+#include <list>
+
+#include "model/triangle.h"
+
+namespace model
+{
+
+class TriangleList {
+public:
+ typedef std::list<Triangle *> Triangles;
+
+ typedef Triangles::iterator iterator;
+ typedef Triangles::const_iterator const_iterator;
+
+ TriangleList();
+ ~TriangleList();
+
+ void clear();
+
+ Triangle *add(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
+
+ Triangle *add(Triangle &triangle);
+
+ inline const size_t size() const { return trianglelist_triangles.size(); }
+
+ inline iterator begin() { return trianglelist_triangles.begin(); }
+
+ inline iterator end() { return trianglelist_triangles.end(); }
+
+private:
+ Triangles trianglelist_triangles;
+
+};
+
+} // namespace model
+
+#endif // __INCLUDED_MODEL_TRIANGLELIST_H__