From c1874201ec49ac117f9ce47b29c30d45326b70b5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 23 Jul 2008 21:53:02 +0000 Subject: transform brush faces into quads --- src/model/map.cc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file 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::iterator v0 = vl.begin(); + std::vector::reverse_iterator vn = vl.rbegin(); + std::vector::reverse_iterator vn1 = vl.rbegin(); + ++vn1; + std::vector::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::iterator v0 = vl.begin(); std::vector::reverse_iterator vn = vl.rbegin(); std::vector::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) -- cgit v1.2.3