Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-23 21:53:02 +0000
committerStijn Buys <ingar@osirion.org>2008-07-23 21:53:02 +0000
commitc1874201ec49ac117f9ce47b29c30d45326b70b5 (patch)
treeff84a0f81a8292c065ae624600379448a5f04e5a /src
parent5c96b74c76b881b1533432a75d1a8cc42ecc5bda (diff)
transform brush faces into quads
Diffstat (limited to 'src')
-rw-r--r--src/model/map.cc67
1 files changed, 60 insertions, 7 deletions
diff --git a/src/model/map.cc b/src/model/map.cc
index 8260f10..405ce98 100644
--- a/src/model/map.cc
+++ b/src/model/map.cc
@@ -513,9 +513,28 @@ void Map::make_brushface(Plane *face)
}
}
- // split face into triangles
- // FIXME split off quads
- while (vl.size() >2) {
+ // split off quads
+ while (vl.size() > 3) {
+ std::vector<Vector3f *>::iterator v0 = vl.begin();
+ std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
+ std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
+ ++vn1;
+ std::vector<Vector3f *>::reverse_iterator vn2 = vl.rbegin();
+ ++vn2;
+ ++vn2;
+
+ Vector3f n(face->normal()*-1);
+ n.normalize();
+
+ primitives->add_quad(*(*vn2), *(*vn1), *(*vn), *(*v0), n, color, face->detail());
+ delete(*vn);
+ delete(*vn1);
+ vl.pop_back();
+ vl.pop_back();
+ }
+
+ // the remainder could be a triangle
+ if (vl.size() > 2) {
std::vector<Vector3f *>::iterator v0 = vl.begin();
std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
@@ -706,13 +725,47 @@ void Map::load_fragments(Model *model)
// add the fragment to the model
model->fragments().push_back(fragment);
}
+
+ // store quads
+ if (primitives->quads().size()) {
+ Fragment *fragment = new Fragment(Fragment::Quads, primitives->material());
+
+ // add structural triangles to the fragment
+ for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) {
+ Quad *quad = (*quad_it);
+ if (!quad->detail()) {
+ size_t count = 0;
+ count += fragment->add_vertex(quad->v0()-center, quad->normal(), quad->color(), false);
+ count += fragment->add_vertex(quad->v1()-center, quad->normal(), quad->color(), false);
+ count += fragment->add_vertex(quad->v2()-center, quad->normal(), quad->color(), false);
+ count += fragment->add_vertex(quad->v3()-center, quad->normal(), quad->color(), false);
+ if (count == 4)
+ model->model_quad_count++;
+ }
+ }
+
+ // add detail triangles to the fragment
+ for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) {
+ Quad *quad = (*quad_it);
+ if (quad->detail()) {
+ size_t count = 0;
+ count += fragment->add_vertex(quad->v0()-center, quad->normal(), quad->color(), false);
+ count += fragment->add_vertex(quad->v1()-center, quad->normal(), quad->color(), false);
+ count += fragment->add_vertex(quad->v2()-center, quad->normal(), quad->color(), false);
+ count += fragment->add_vertex(quad->v3()-center, quad->normal(), quad->color(), false);
+ if (count == 4) {
+ model->model_quad_count++;
+ model->model_quad_detail_count++;
+ }
+ }
+ }
+
+ // add the fragment to the model
+ model->fragments().push_back(fragment);
+ }
}
- if (model->model_tris_count + model->model_quad_count > 0) {
-
- }
-
}
Model * Map::load(std::string const &name)