diff options
author | Stijn Buys <ingar@osirion.org> | 2008-07-23 15:16:56 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-07-23 15:16:56 +0000 |
commit | 426b766efbccdd8f5715de9526464db251fac30c (patch) | |
tree | f1abfea7c1d4d4f1e97bd534d447cb6907576e2f /src/model/map.cc | |
parent | 67517585e9b55967f5236ed5ebca77173eb2f2e3 (diff) |
preparing for fragment rendering
Diffstat (limited to 'src/model/map.cc')
-rw-r--r-- | src/model/map.cc | 668 |
1 files changed, 624 insertions, 44 deletions
diff --git a/src/model/map.cc b/src/model/map.cc index 192814c..220c723 100644 --- a/src/model/map.cc +++ b/src/model/map.cc @@ -1,17 +1,21 @@ /* - model/map.cc + filesystem/map.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ +#include "filesystem/filesystem.h" +#include "math/mathlib.h" #include "model/engine.h" #include "model/light.h" #include "model/map.h" -#include "model/mapfile.h" +#include "model/material.h" #include "model/vertexarray.h" - #include "sys/sys.h" +#include <sstream> +#include <string> + namespace model { // function to test spawnflags @@ -19,10 +23,13 @@ inline bool spawnflag_isset(unsigned int spawnflags, unsigned int flag) { return ((spawnflags & flag) == flag); } +const float MAX_BOUNDS = 16384; +const float MIN_DELTA = 10e-10; + Model * Map::load(std::string const &name) { // open the .map file - MapFile mapfile; + Map mapfile; if (!mapfile.open(name)) { return 0; @@ -157,108 +164,680 @@ Model * Map::load(std::string const &name) mapfile.close(); + mapfile.load_fragments(model); + + return model; +} + +Map::Map() {} + +Map::~Map() {} + +bool Map::open(std::string const & name) { + + last_read_was_classname = false; + last_read_was_key = false; + key_current = ""; + value_current = ""; + classname_current = ""; + line_number = 0; + parse_level = 0; + brushes = 0; + + mapfile_name.assign("maps/"); + mapfile_name.append(name); + mapfile_name.append(".map"); + + filesystem::File *f = filesystem::open(mapfile_name.c_str()); + if (!f) { + con_warn << "Could not open " << mapfile_name << std::endl; + return false; + } + + std::string fn = f->path(); + fn.append(f->name()); + filesystem::close(f); + + mapfile_ifs.open(fn.c_str()); + if (!mapfile_ifs.is_open()) { + con_warn << "Could not stream " << fn << "!\n"; + return false; + } + + return true; +} + + +bool Map::got_classname() const { + return last_read_was_classname; +} + +bool Map::got_classname(const char * classnamelabel) const { + return (last_read_was_classname && (classname_current.compare(classnamelabel) == 0)); +} + +bool Map::getline() { + using math::Vector3f; + + char data[1024]; + + last_read_was_classname = false; + last_read_was_key = false; + + key_current = ""; + value_current = ""; + + if (!mapfile_ifs.is_open()) + return false; + + if (mapfile_ifs.getline(data, 1023)) { + line_number++; + std::istringstream linestream(data); + std::string firstword; + + if (linestream >> firstword) { + if (!firstword.size()) { + return true; + + } else if (firstword == "//") { + return true; + + } else if (firstword == "{") { + parse_level++; + + } else if (firstword == "}") { + if ((parse_level == 2) && (classname_current == "worldspawn")) { + // brush + if (VertexArray::instance()) { + // for every face + for (std::vector<Plane *>::iterator face = planes.begin(); face != planes.end(); face++) { + make_brushface((*face)); + } + + // clean planes + for (std::vector<Plane *>::iterator it = planes.begin(); it != planes.end(); it++) { + delete(*it); + } + planes.clear(); + + brushes++; + } + value_current.clear(); + } + parse_level--; + + } else if (parse_level == 1) { + + if (firstword == "\"classname\"") { + classname_current.clear(); + + if (linestream >> classname_current) { + if (classname_current.size() > 2) { + classname_current.erase(0,1); + classname_current.erase(classname_current.size()-1, 1); + last_read_was_classname = true; + } else { + classname_current.clear(); + } + } + + } else if ((firstword.size() > 2) && (firstword[0] == '\"') && (firstword[firstword.size()-1] == '\"')) { + + key_current.assign(firstword); + key_current.erase(0,1); + key_current.erase(key_current.size()-1, 1); + + value_current.clear(); + char c; + while ((linestream.get(c)) && (c != '"')); + while ((linestream.get(c)) && (c != '"')) + value_current += c; + + last_read_was_key = true; + } + + } else if (parse_level == 2) { + + if ((firstword == "(") && (classname_current == "worldspawn")) { + // brush plane + if (VertexArray::instance()) { + Vector3f p1, p2, p3; + std::string tmp; + std::string texture; + int n = 0; + + linestream >> p1; + linestream >> tmp; // ) + linestream >> tmp; // ( + linestream >> p2; + linestream >> tmp; // ) + linestream >> tmp; // ( + linestream >> p3; + linestream >> tmp; // ) + linestream >> texture; + + // 5 numbers (texture alignment?) + for (int i=0; i < 5; i++) + linestream >> tmp; + + // content flags ? + if (!(linestream >> n)) + n = 0; + + Plane *plane = new Plane(p1, p2, p3); + plane->texture() = texture; + if (n > 0) + plane->detail() = true; + + // surface flags + if (!(linestream >> n)) + n = 0; + plane->surface_flags() = n; + + planes.push_back(plane); + } + value_current.clear(); + } + } + } + } else { + + return false; + } + + return true; +} + +void Map::make_brushface(Plane *face) +{ + using math::Vector3f; + + // ignore caulk + if (face->texture() == "common/caulk") { + return; + } + + // FIXME clip should be parsed as collision blocks + if (face->texture() == "common/clip") { + return; + } + + // using suggestions from + // http://www.flipcode.com/archives/Level_Editing.shtml + + // vertex list + std::vector<math::Vector3f *> vl; + + // calculate initial vertices on the bounding box + + // check if the face is x-axis oriented + if ((fabsf(face->normal().x) >= fabsf(face->normal().y)) && (fabsf(face->normal().x) >= fabsf(face->normal().z))) { + + if (face->normal().x >= 0) { + vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS)); + vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS)); + vl.push_back(new math::Vector3f(0, MAX_BOUNDS, MAX_BOUNDS)); + vl.push_back(new math::Vector3f(0, MAX_BOUNDS, -MAX_BOUNDS)); + } else { + vl.push_back(new math::Vector3f(0, MAX_BOUNDS, -MAX_BOUNDS)); + vl.push_back(new math::Vector3f(0, MAX_BOUNDS, MAX_BOUNDS)); + vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS)); + vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS)); + } + // calculate the x coordinate of each face vertex + for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { + (*it)->x = (-face->d() - + face->normal().z * (*it)->z - + face->normal().y * (*it)->y) / + face->normal().x; + } + } + + // check if the face is y-axis oriented + else if ((fabsf(face->normal().y) >= fabsf(face->normal().x)) && (fabsf(face->normal().y) >= fabsf(face->normal().z))) { + + if (face->normal().y >= 0) { + vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS)); + vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS)); + vl.push_back(new Vector3f(-MAX_BOUNDS, 0, MAX_BOUNDS)); + vl.push_back(new Vector3f(-MAX_BOUNDS, 0, -MAX_BOUNDS)); + } else { + vl.push_back(new Vector3f(-MAX_BOUNDS, 0, -MAX_BOUNDS)); + vl.push_back(new Vector3f(-MAX_BOUNDS, 0, MAX_BOUNDS)); + vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS)); + vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS)); + } + + // calculate the x coordinate of each face vertex + for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { + (*it)->y = (-face->d() - + face->normal().z * (*it)->z - + face->normal().x * (*it)->x) / + face->normal().y; + } + } + + // face must be z-axis oriented + else { + + if (face->normal().z >= 0) { + vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0)); + vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0)); + vl.push_back(new Vector3f(MAX_BOUNDS, MAX_BOUNDS, 0)); + vl.push_back(new Vector3f(MAX_BOUNDS, -MAX_BOUNDS, 0)); + } else { + vl.push_back(new Vector3f(MAX_BOUNDS, -MAX_BOUNDS, 0)); + vl.push_back(new Vector3f(MAX_BOUNDS, MAX_BOUNDS, 0)); + vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0)); + vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0)); + } + + // calculate the x coordinate of each face vertex + for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { + (*it)->z = (-face->d() - + face->normal().x * (*it)->x - + face->normal().y * (*it)->y) / + face->normal().z; + } + } + + + // intersect the face with every plane + for (std::vector<Plane *>::iterator pit = planes.begin(); pit != planes.end(); pit++) { + Plane *plane = (*pit); + if (plane == face) { + continue; + } + + Vector3f fn = crossproduct(face->point(1)-face->point(0), face->point(2)-face->point(0)); + Vector3f pn = crossproduct(plane->point(1)-plane->point(0), plane->point(2)-plane->point(0)); + + Vector3f t = crossproduct(fn, pn); + if ((t.x == 0) && (t.y == 0) && (t.z == 0)) { + continue; + } + + // intersect face with plane + for (int i=0; vl.size() - i > 0; i++) { + + Vector3f v(*vl.at(i)); + + Vector3f next; + if (vl.size() - i > 1) { + next = *vl.at(i+1); + } else { + next = *vl.front(); + } + + Vector3f prev; + if (i > 0) { + prev = *vl.at(i-1); + } else { + prev = *vl.back(); + } + + if ((v.x*plane->normal().x + v.y*plane->normal().y + v.z*plane->normal().z +plane->d()) < MIN_DELTA) { + + // find current + std::vector<Vector3f *>::iterator vit = vl.begin(); + while ((*vit) != vl.at(i)) { + vit++; + } + + // check if prev - v intersects with plane + if ((prev.x*plane->normal().x + prev.y*plane->normal().y + prev.z*plane->normal().z + plane->d()) > -MIN_DELTA) { + + // calculate intersection + float t1 = -plane->normal().x * prev.x - plane->normal().y * prev.y - plane->normal().z * prev.z -plane->d(); + float t2 = (plane->normal().x * v.x - plane->normal().x * prev.x + + plane->normal().y * v.y - plane->normal().y * prev.y + + plane->normal().z * v.z - plane->normal().z * prev.z); + + Vector3f *s = new Vector3f; + + if (t2 == 0) { + *s = v; + } else { + for (int j = 0; j < 3; j++) + (*s)[j] = prev [j] + t1 * (v[j] - prev[j]) / t2; + } + + vit = vl.insert(vit,s); + vit++; + i++; + } + + // check if next - v intersects with plane + if ((next.x*plane->normal().x + next.y*plane->normal().y + next.z*plane->normal().z + plane->d()) > -MIN_DELTA) { + + // calculate intersection + float t1 = -plane->normal().x * v.x - plane->normal().y * v.y - plane->normal().z * v.z -plane->d(); + float t2 = (plane->normal().x * next.x - plane->normal().x * v.x + + plane->normal().y * next.y - plane->normal().y * v.y + + plane->normal().z * next.z - plane->normal().z * v.z); + //cout << "next t2 " << t2 << std::endl; + Vector3f *s = new Vector3f; + + if (t2 == 0) { + *s = v; + } else { + for (int j = 0; j < 3; j++) + (*s)[j] = v [j] + t1 * (next[j] - v[j]) / t2; + } + + vit = vl.insert(vit,s); + vit++; + i++; + } + + // erase + delete *vit; + vl.erase(vit); + i--; + } + + } + } + + if (vl.size() > 2) { + + // default material is none + unsigned int material = 0; + + // default color makrs unknown textures hot pink + math::Color color(1.0f, 0.0, 1.0f, 1.0f); + + // translate texture names to color and material + if (face->texture() == "colors/white") { + color.assign(1.0f); + } else if (face->texture() == "colors/grey90") { + color.assign(0.9f); + } else if (face->texture() == "colors/grey75") { + color.assign(0.75f); + } else if (face->texture() == "colors/grey50") { + color.assign(0.5f); + } else if (face->texture() == "colors/grey25") { + color.assign(0.25f); + } else if (face->texture() == "colors/black") { + color.assign(0.0f); + } else if (face->texture() == "colors/red") { + color.assign(1, 0, 0); + } else if (face->texture() == "colors/green") { + color.assign(0, 1, 0); + } else if (face->texture() == "colors/blue") { + color.assign(0, 0, 1); + + } else if ((face->texture() == "common/entity") || (face->texture() == "common/primary")) { + material |= Material::Primary; + } else if (face->texture() == "common/primary_dark") { + material |= Material::Primary; + material |= Material::Dark; + + } else if (face->texture() == "common/secundary") { + material |= Material::Secondary; + } else if (face->texture() == "common/secundary_dark") { + material |= Material::Secondary; + material |= Material::Dark; + + } else if (face->texture() == "common/tertiary") { + material |= Material::Tertiary; + } else if (face->texture() == "common/tertiary_dark") { + material |= Material::Tertiary; + material |= Material::Dark; + } + + // translate surface flags to materials + + // surface flag 1 light + if ((face->surface_flags() & 1) == 1) { + material |= Material::Light; + } + + // calculate bounding box + for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { + + *(*it) *= SCALE; + + for (int i=0; i < 3; i++) { + if (class_maxbbox[i] < (*(*it))[i]) + class_maxbbox[i] = (*(*it))[i]; + + if (class_minbbox[i] > (*(*it))[i]) + class_minbbox[i] = (*(*it))[i]; + } + } + + // split face into triangles + while (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(); + ++vn1; + + Vector3f n(face->normal()*-1); + n.normalize(); + + if (material & Material::Primary) { + // evertices will be added to the VertexArray after normal vertices + Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, 0, face->detail()); + class_etris.push_back(triangle); + } else if (material & Material::Light) { + // lvertices + Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, color, face->detail()); + class_ltris.push_back(triangle); + } else { + Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, color, face->detail()); + class_tris.push_back(triangle); + } + + delete (*vn); + vl.pop_back(); + } + } else { + con_debug << "Unresolved face!\n"; + } + + // clean up the vertex list + for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) { + delete(*it); + } + + vl.clear(); +} + +bool Map::got_key_string(const char * keylabel, std::string & valuestring) { + if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + valuestring.assign(value_current); + return true; + } else { + return false; + } +} + +bool Map::got_key_vector3f(const char * keylabel, math::Vector3f & v) { + if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + std::istringstream is(value_current); + float x, y, z; + if ((is >> x) && (is >> y) && (is >> z)) { + v = math::Vector3f(x,y,z); + } else { + v= math::Vector3f(); + } + return true; + } else { + return false; + } +} + +bool Map::got_key_float(const char * keylabel, float & f) { + if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + std::istringstream is(value_current); + if (!(is >> f)) { + f = 0; + } + return true; + } else { + return false; + } +} + +bool Map::got_key_int(const char * keylabel, unsigned int & u) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + std::istringstream is(value_current); + if (!(is >> u)) { + u = 0; + } + return true; + } else { + return false; + } +} + +bool Map::got_key(const char * keylabel) { + return (last_read_was_key && (key_current.compare(keylabel) == 0 )); +} + +bool Map::got_key_angle(const char * keylabel, float & f) { + if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + std::istringstream is(value_current); + if ((is >> f)) { + f = math::degrees360f(f); + } else { + f = 0; + } + return true; + } else { + return false; + } +} + +bool Map::got_key_color(const char * keylabel, math::Color & color) { + if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + std::istringstream is(value_current); + float r, g, b; + if ((is >> r) && (is >> g) && (is >> b)) { + if ((r > 1) || (g > 1) || (b > 1)) { + r /= 255; g /= 255; b /= 255; + } + color = math::Color(r, g, b); + } else { + color = math::Color(); + } + return true; + } else { + return false; + } +} + +void Map::close() +{ + mapfile_ifs.close(); +} + +void Map::load_fragments(Model *model) +{ + if (!VertexArray::instance() || VertexArray::instance()->overflow()) + return; + // process the triangles calculated by the mapfile and add them to the vertex array - if (VertexArray::instance() && !VertexArray::instance()->overflow() && ((mapfile.class_tris.size() + mapfile.class_etris.size() + mapfile.class_ltris.size()) > 0)) { + if ((class_tris.size() + class_etris.size() + class_ltris.size()) > 0) { - math::Vector3f center = (mapfile.class_minbbox + mapfile.class_maxbbox) / 2; + math::Vector3f center = (class_minbbox + class_maxbbox) / 2; - model->model_minbbox = mapfile.class_minbbox - center; - model->model_maxbbox = mapfile.class_maxbbox - center; + model->model_minbbox = class_minbbox - center; + model->model_maxbbox = class_maxbbox - center; model->model_radius = model->model_maxbbox.length(); // structural triangles model->model_first_vertex = VertexArray::instance()->index()/3; - for (std::list<Triangle *>::iterator it = mapfile.class_tris.begin(); it != mapfile.class_tris.end() && !VertexArray::instance()->overflow(); it++) { + for (std::list<Triangle *>::iterator it = class_tris.begin(); it != class_tris.end(); it++) { Triangle *triangle = (*it); if (!triangle->detail()) { size_t count = 0; - count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v0()-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v1()-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v2()-center, triangle->normal(), triangle->color() ); if (count == 3) model->model_vertex_count += count; } } // detail triangles - for (std::list<Triangle *>::iterator it = mapfile.class_tris.begin(); it != mapfile.class_tris.end() && !VertexArray::instance()->overflow(); it++) { + for (std::list<Triangle *>::iterator it = class_tris.begin(); it != class_tris.end(); it++) { Triangle *triangle = (*it); if (triangle->detail()) { size_t count = 0; - count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v0()-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v1()-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v2()-center, triangle->normal(), triangle->color() ); if (count == 3) model->model_vertex_countdetail += count; } delete triangle; } - mapfile.class_tris.clear(); + class_tris.clear(); // structural etriangles model->model_first_evertex = VertexArray::instance()->index()/3; - for (std::list<Triangle *>::iterator it = mapfile.class_etris.begin(); it != mapfile.class_etris.end() && !VertexArray::instance()->overflow(); it++) { + for (std::list<Triangle *>::iterator it = class_etris.begin(); it != class_etris.end(); it++) { Triangle *triangle = (*it); if (!triangle->detail()) { size_t count = 0; - count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v0()-center, triangle->normal(), triangle->color()); + count += VertexArray::instance()->add_vertex(triangle->v1()-center, triangle->normal(), triangle->color()); + count += VertexArray::instance()->add_vertex(triangle->v2()-center, triangle->normal(), triangle->color()); if (count == 3) model->model_evertex_count += count; } } // detail etriangles - for (std::list<Triangle *>::iterator it = mapfile.class_etris.begin(); it != mapfile.class_etris.end() && !VertexArray::instance()->overflow(); it++) { + for (std::list<Triangle *>::iterator it = class_etris.begin(); it != class_etris.end(); it++) { Triangle *triangle = (*it); if (triangle->detail()) { size_t count = 0; - count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v0()-center, triangle->normal(), triangle->color()); + count += VertexArray::instance()->add_vertex(triangle->v1()-center, triangle->normal(), triangle->color()); + count += VertexArray::instance()->add_vertex(triangle->v2()-center, triangle->normal(), triangle->color()); if (count == 3) model->model_evertex_countdetail += count; } delete triangle; } - mapfile.class_etris.clear(); + class_etris.clear(); // structural ltriangles model->model_first_lvertex = VertexArray::instance()->index()/3; - for (std::list<Triangle *>::iterator it = mapfile.class_ltris.begin(); it != mapfile.class_ltris.end() && !VertexArray::instance()->overflow(); it++) { + for (std::list<Triangle *>::iterator it = class_ltris.begin(); it != class_ltris.end(); it++) { Triangle *triangle = (*it); if (!triangle->detail()) { size_t count = 0; - count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v0()-center, triangle->normal(), triangle->color()); + count += VertexArray::instance()->add_vertex(triangle->v1()-center, triangle->normal(), triangle->color()); + count += VertexArray::instance()->add_vertex(triangle->v2()-center, triangle->normal(), triangle->color()); if (count == 3) model->model_lvertex_count += count; } } // detail ltriangles - for (std::list<Triangle *>::iterator it = mapfile.class_ltris.begin(); it != mapfile.class_ltris.end() && !VertexArray::instance()->overflow(); it++) { + for (std::list<Triangle *>::iterator it = class_ltris.begin(); it != class_ltris.end(); it++) { Triangle *triangle = (*it); if (triangle->detail()) { size_t count = 0; - count += VertexArray::instance()->add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() ); - count += VertexArray::instance()->add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v0()-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v1()-center, triangle->normal(), triangle->color() ); + count += VertexArray::instance()->add_vertex(triangle->v2()-center, triangle->normal(), triangle->color() ); if (count == 3) model->model_lvertex_countdetail += count; } delete triangle; } - mapfile.class_ltris.clear(); + class_ltris.clear(); - // reposition light and engines - for (std::list<Engine *>::iterator eit = model->model_engine.begin(); eit != model->model_engine.end(); eit++) { - (*eit)->engine_location -= center; - } - + // reposition lights, flares and engines for (std::list<Light *>::iterator lit = model->model_light.begin(); lit != model->model_light.end(); lit++) { (*lit)->light_location -= center; } @@ -267,12 +846,13 @@ Model * Map::load(std::string const &name) (*flit)->light_location -= center; } + for (std::list<Engine *>::iterator eit = model->model_engine.begin(); eit != model->model_engine.end(); eit++) { + (*eit)->engine_location -= center; + } } - con_print << " maps/" << model->name() << ".map " << mapfile.brushes << " brushes " << model->tris() - << " tris (" << model->details() << " detail)" << std::endl; - - return model; + con_print << " maps/" << model->name() << ".map " << brushes << " brushes " << model->tris() << " tris (" << model->details() << " detail)" << std::endl; } } + |