diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/map.cc | 67 |
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) |