Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
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/mapfile.cc
parent035653e94a3d74b8f18c993034199d7cd08a895a (diff)
Corrected the origin alignment of collision mesh bodies.
Diffstat (limited to 'src/model/mapfile.cc')
-rw-r--r--src/model/mapfile.cc93
1 files changed, 58 insertions, 35 deletions
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;