Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/model.cc')
-rw-r--r--src/core/model.cc126
1 files changed, 99 insertions, 27 deletions
diff --git a/src/core/model.cc b/src/core/model.cc
index 6a82989..a0aa489 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -117,7 +117,6 @@ void VertexArray::add_sphere()
}
- con_debug << "SPhere segment count " << count <<std::endl;
delete[] sintable;
delete[] costable;
}
@@ -206,10 +205,14 @@ Model::Model(std::string const & name) :
{
model_valid = false;
model_scale = 1.0f / 1024.0f;
+
model_first_vertex = 0;
model_first_evertex = 0;
+
model_vertex_count = 0;
+ model_vertex_countdetail = 0;
model_evertex_count = 0;
+ model_evertex_countdetail = 0;
std::string fn("maps/");
fn.append(name);
@@ -243,9 +246,8 @@ Model::Model(std::string const & name) :
float class_angle;
math::Color class_color;
unsigned int class_spawnflags;
+ bool brush_detail;
- model_first_vertex = VertexArray::vertex_index/3;
-
while (ifs) {
ifs.getline(data, 1023);
std::istringstream linestream(data);
@@ -262,6 +264,7 @@ Model::Model(std::string const & name) :
class_origin = math::Vector3f(0,0,0);
class_color = math::Color(1, 1, 1);
class_spawnflags = 0;
+ brush_detail = false;
}
level ++;
//cout << " LEVEL +" << level << std::endl;
@@ -273,7 +276,7 @@ Model::Model(std::string const & name) :
// for every face
std::vector<Vector3f *>points;
for (std::vector<Plane3f *>::iterator face = planes.begin(); face != planes.end(); face++) {
- make_face((*face), planes);
+ make_face((*face), planes, brush_detail);
}
}
@@ -282,6 +285,7 @@ Model::Model(std::string const & name) :
delete(*it);
}
planes.clear();
+ brush_detail = false;
} else if ((level == 1) && (class_name == "target_engine")) {
//con_debug << " engine at " << class_origin << "\n";
@@ -376,6 +380,13 @@ Model::Model(std::string const & name) :
linestream >> tmp; // )
linestream >> texture;
+ // 5 numbers (texture alignment?)
+ for (int i=0; i < 5; i++)
+ linestream >> tmp;
+
+ if (linestream >> tmp)
+ brush_detail = true;
+
//cout << data << std::endl;
//cout << "(" << p1 << ") (" << p2 << ") (" << p3 << ") " << texture << std::endl;
@@ -392,29 +403,76 @@ Model::Model(std::string const & name) :
ifs.close();
- model_first_evertex = VertexArray::vertex_index/3;
- if (model_etris.size()) {
+ if ((model_tris.size() + model_etris.size()) > 0) {
+
+ math::Vector3f center = (model_minbbox + model_maxbbox) / 2;
+
+ model_minbbox -= center;
+ model_maxbbox -= center;
+ model_radius = model_maxbbox.length();
+
+ // structural triangles
+ model_first_vertex = VertexArray::vertex_index/3;
+ for (std::list<Triangle *>::iterator it = model_tris.begin(); it != model_tris.end(); it++) {
+ Triangle *triangle = (*it);
+ if (!triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_vertex_count += 3;
+ }
+ }
+ // detail triangles
+ for (std::list<Triangle *>::iterator it = model_tris.begin(); it != model_tris.end(); it++) {
+ Triangle *triangle = (*it);
+ if (triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_vertex_countdetail += 3;
+ }
+ delete triangle;
+ }
+ model_tris.clear();
+
+ // structural etriangles
+ model_first_evertex = VertexArray::vertex_index/3;
+ for (std::list<Triangle *>::iterator it = model_etris.begin(); it != model_etris.end(); it++) {
+ Triangle *triangle = (*it);
+ if (!triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_evertex_count += 3;
+ }
+ }
+
+ // detail etriangles
for (std::list<Triangle *>::iterator it = model_etris.begin(); it != model_etris.end(); it++) {
Triangle *triangle = (*it);
- VertexArray::add_vertex(triangle->triangle_v0, triangle->normal(), triangle->color() );
- VertexArray::add_vertex(triangle->triangle_v1, triangle->normal(), triangle->color() );
- VertexArray::add_vertex(triangle->triangle_v2, triangle->normal(), triangle->color() );
- model_evertex_count += 3;
+ if (triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_evertex_countdetail += 3;
+ }
delete triangle;
}
model_etris.clear();
- }
- if ((model_vertex_count + model_evertex_count) > 0 ) {
- if (model_maxbbox.lengthsquared() > model_minbbox.lengthsquared()) {
- model_radius = model_maxbbox.length();
- } else {
- model_radius = model_minbbox.length();
+ // reposition light and engines
+ for (std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) {
+ (*eit)->engine_location -= center;
}
- model_valid = true;
+
+ for (std::list<Light *>::iterator lit = model_light.begin(); lit != model_light.end(); lit++) {
+ (*lit)->light_location -= center;
+ }
+
+ model_valid = true;
}
- //con_debug << " maps/" << name << ".map " << model_face.size() << " polygons\n";
- con_debug << " maps/" << name << ".map " << tris() << " triangles" << std::endl;
+
+ con_debug << " maps/" << name << ".map " << tris() << " triangles (" << details() << " detail)" << std::endl;
}
Model::~Model()
@@ -432,7 +490,18 @@ Model::~Model()
model_light.clear();
}
-void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes)
+size_t Model::tris() const
+{
+ return ((model_vertex_count + model_vertex_countdetail +
+ model_evertex_count + model_evertex_countdetail)/3);
+}
+
+size_t Model::details() const
+{
+ return ((model_vertex_countdetail + model_evertex_countdetail)/3);
+}
+
+void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes, bool detail)
{
using math::Vector3f;
using math::Plane3f;
@@ -681,17 +750,19 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
if (!color) {
// evertices will be added to the VertexArray after normal vertices
- Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, 0, false);
+ Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, 0, detail);
model_etris.push_back(triangle);
//VertexArray::add_evertex(*(*vn1), n);
//VertexArray::add_evertex(*(*vn), n);
//VertexArray::add_evertex(*(*v0), n);
//model_evertex_count += 3;
} else {
- VertexArray::add_vertex(*(*vn1), n, *color);
- VertexArray::add_vertex(*(*vn), n, *color);
- VertexArray::add_vertex(*(*v0), n, *color);
- model_vertex_count += 3;
+ Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, color, detail);
+ model_tris.push_back(triangle);
+ //VertexArray::add_vertex(*(*vn1), n, *color);
+ //VertexArray::add_vertex(*(*vn), n, *color);
+ //VertexArray::add_vertex(*(*v0), n, *color);
+ //model_vertex_count += 3;
}
delete (*vn);
@@ -756,12 +827,13 @@ void Model::list()
{
for (std::map<std::string, Model*>::iterator mit = registry.begin(); mit != registry.end(); mit++) {
con_print << " " << (*mit).second->name() << " "
- << ((*mit).second->vertex_count() + (*mit).second->evertex_count())/3 << " triangles "
+ << (*mit).second->tris() << " triangles ("
+ << (*mit).second->details() << " detail) "
<< (*mit).second->model_engine.size() << " engines "
<< (*mit).second->model_light.size() << " lights\n";
}
con_print << registry.size() << " registered models" << std::endl;
- con_print << "vertex array " << VertexArray::vertex_index << "/" << VERTEXARRAYSIZE << " used" << std::endl;
+ con_print << "vertex array " << VertexArray::vertex_index/3 << "/" << VERTEXARRAYSIZE/3 << " used" << std::endl;
}
}