Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/asefile.cc2
-rw-r--r--src/model/mapfile.cc80
-rw-r--r--src/model/mapfile.h4
-rw-r--r--src/model/triangle.cc24
-rw-r--r--src/model/triangle.h172
5 files changed, 169 insertions, 113 deletions
diff --git a/src/model/asefile.cc b/src/model/asefile.cc
index a9e57d4..664a3f7 100644
--- a/src/model/asefile.cc
+++ b/src/model/asefile.cc
@@ -467,7 +467,7 @@ Model * ASEFile::load(const std::string &name)
model->add_group(group);
con_debug << " " << asefile.name() << " " << asefile.ase_vertexlist.size() << " vertices " <<
- model->model_tris_count << "/" << model->model_tris_detail_count << " faces/detail" << std::endl;
+ model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail" << std::endl;
return model;
}
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index c4f0b7b..54f6d78 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -142,13 +142,14 @@ inline bool spawnflag_isset(unsigned int spawnflags, unsigned int flag)
return ((spawnflags & flag) == flag);
}
-MapFile::MapFile() : map_center(0,0,0)
+MapFile::MapFile() : map_center(0.0f, 0.0f, 0.0f)
{
mapfile_name.clear();
map_brushes = 0;
map_faces = 0;
map_faces_detail = 0;
+ in_patchdef = false;
warning_q2brush = false;
}
@@ -205,6 +206,49 @@ bool MapFile::got_classend(const char * classnamelabel) const
return (last_read_was_classend && (classname_current.compare(classnamelabel) == 0));
}
+bool MapFile::read_patchdef()
+{
+ char data[1024];
+ memset(data, 0, sizeof(data));
+ size_t count = 0;
+
+ // first line: texture name
+ if (!mapfile_ifs.getline(data, 1023))
+ return false;
+ else
+ line_number++;
+
+ // second line: "( a b c d e )"
+ if (!mapfile_ifs.getline(data, 1023))
+ return false;
+ else
+ line_number++;
+
+ // third line: "("
+ if (!mapfile_ifs.getline(data, 1023))
+ return false;
+ else
+ line_number++;
+
+ while (mapfile_ifs.getline(data, 1023)) {
+ line_number++;
+
+ std::istringstream linestream(data);
+ std::string firstword;
+
+ if (linestream >> firstword) {
+ if (firstword.compare(")") == 0) {
+ //con_debug << " patchDef2 with " << count << " lines" << std::endl;
+ return true;
+ } else {
+ count ++;
+ }
+ }
+ }
+
+ return false;
+}
+
bool MapFile::getline()
{
using math::Vector3f;
@@ -236,9 +280,20 @@ bool MapFile::getline()
} else if (firstword == "{") {
parse_level++;
+
+ if ((parse_level == 3) && (in_patchdef)) {
+ if (!read_patchdef()) {
+ con_warn << name() << " error reading patchDef2 at line " << line_number << std::endl;
+ }
+ }
} else if (firstword == "}") {
- if ((parse_level == 2) && (planes.size())) {
+
+ if ((parse_level == 3) && (in_patchdef)) {
+ // end-of-patchdef
+ in_patchdef = false;
+
+ } else if ((parse_level == 2) && (planes.size())) {
// end-of-brush
// for every face
@@ -265,7 +320,7 @@ bool MapFile::getline()
} else if (parse_level == 1) {
- if (firstword == "\"classname\"") {
+ if (firstword.compare("\"classname\"") == 0) {
classname_current.clear();
if (linestream >> classname_current) {
@@ -295,7 +350,7 @@ bool MapFile::getline()
} else if (parse_level == 2) {
- if (firstword == "(") {
+ if (firstword.compare("(") == 0) {
// brush plane
Vector3f p1, p2, p3;
@@ -352,6 +407,9 @@ bool MapFile::getline()
planes.push_back(face);
value_current.clear();
+
+ } else if (firstword.compare("patchDef2") == 0) {
+ in_patchdef = true;
}
}
}
@@ -635,7 +693,7 @@ void MapFile::make_brushface(Face *face)
vl.pop_back();
}
} else {
- con_debug << "Unresolved face!\n";
+ con_warn << name() << " unresolved face at line " << line() << std::endl;
}
// clean up the vertex list
@@ -845,7 +903,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
if (primitives->quads().size()) {
Fragment *fragment = new Fragment(Fragment::Quads, primitives->material());
- // add structural triangles to the fragment
+ // add structural quads 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()) {
@@ -859,7 +917,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
}
}
- // add detail triangles to the fragment
+ // add detail quads 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()) {
@@ -943,7 +1001,8 @@ Model * MapFile::load(std::string const &name)
// worldspawn attributes
if (mapfile.got_key("name")) {
- con_debug << " model name '" << name << "'" << std::endl;
+ //con_debug << " model name '" << name << "'" << std::endl;
+ continue;
} else if (mapfile.got_key_int("enginesound", u)) {
model->model_enginesound = u;
@@ -1403,7 +1462,10 @@ Model * MapFile::load(std::string const &name)
}
con_debug << " " << mapfile.name() << " " << mapfile.map_brushes << " brushes " <<
- mapfile.map_faces << "/" << mapfile.map_faces_detail << " faces/detail " << std::endl;
+ model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail " <<
+ model->model_quad_count << "/" << model->model_quad_detail_count << " quads/detail" <<
+ std::endl;
+
if (mapfile.warning_q2brush)
con_warn << " quake2 style brushes detected" << std::endl;
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index fd6bf48..0cf66a5 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -45,6 +45,8 @@ private:
/// parse one line, returns false on end-of-file
bool getline();
+
+ bool read_patchdef();
/// current classname
inline std::string classname() const
@@ -182,6 +184,8 @@ private:
Materials map_materials;
bool warning_q2brush;
+
+ bool in_patchdef;
};
}
diff --git a/src/model/triangle.cc b/src/model/triangle.cc
index 90d52b7..40c34a3 100644
--- a/src/model/triangle.cc
+++ b/src/model/triangle.cc
@@ -10,23 +10,23 @@ namespace model
{
Triangle::Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2) :
- triangle_v0(v0),
- triangle_v1(v1),
- triangle_v2(v2)
+ triangle_v0(v0),
+ triangle_v1(v1),
+ triangle_v2(v2)
{
- triangle_detail = false;
+ triangle_detail = false;
}
Triangle::Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail) :
- triangle_v0(v0),
- triangle_n0(normal),
- triangle_v1(v1),
- triangle_n1(normal),
- triangle_v2(v2),
- triangle_n2(normal),
- triangle_normal(normal)
+ triangle_v0(v0),
+ triangle_n0(normal),
+ triangle_v1(v1),
+ triangle_n1(normal),
+ triangle_v2(v2),
+ triangle_n2(normal),
+ triangle_normal(normal)
{
- triangle_detail = detail;
+ triangle_detail = detail;
}
Triangle::~Triangle()
diff --git a/src/model/triangle.h b/src/model/triangle.h
index f2a741a..8e8d1e2 100644
--- a/src/model/triangle.h
+++ b/src/model/triangle.h
@@ -17,102 +17,92 @@ namespace model
class Triangle
{
public:
- /**
- * @brief a new triangle with 3 vertices
- * this constructor is used by the ASE reader sets the detail flag to false
- */
- Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
-
- /**
- * @brief a new triangle with 3 vertices
- * this constructor is used by the MAP reader and assigns the face normal to every vertex normal
- */
- Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false);
-
- /// delete triangle
- ~Triangle();
-
- /// triangle vertex 0
- inline math::Vector3f & v0()
- {
- return triangle_v0;
- }
-
- /// triangle vertex 0 normal
- inline math::Vector3f & n0()
- {
- return triangle_n0;
- }
-
- /// triangle vertex 0 texture coordinates
- inline math::Vector2f & t0()
- {
- return triangle_t0;
- }
-
- /// triangle vertex 1
- inline math::Vector3f & v1()
- {
- return triangle_v1;
- }
-
- /// triangle vertex 1 normal
- inline math::Vector3f & n1()
- {
- return triangle_n1;
- }
-
- /// triangle vertex 1 texture coordinates
- inline math::Vector2f & t1()
- {
- return triangle_t1;
- }
-
- /// triangle vertex 2
- inline math::Vector3f & v2()
- {
- return triangle_v2;
- }
-
- /// triangle vertex 2 normal
- inline math::Vector3f & n2()
- {
- return triangle_n2;
- }
-
- /// triangle vertex 2 texture coordinates
- inline math::Vector2f & t2()
- {
- return triangle_t2;
- }
-
- /// indidcates if this triangle was generated from a detail brush
- inline bool detail() const
- {
- return triangle_detail;
- }
-
- /// face normal
- inline math::Vector3f &normal() {
- return triangle_normal;
- }
+ /**
+ * @brief a new triangle with 3 vertices
+ * this constructor is used by the ASE reader sets the detail flag to false
+ */
+ Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
+
+ /**
+ * @brief a new triangle with 3 vertices
+ * this constructor is used by the MAP reader and assigns the face normal to every vertex normal
+ */
+ Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false);
+
+ /// delete triangle
+ ~Triangle();
+
+ /// triangle vertex 0
+ inline math::Vector3f & v0() {
+ return triangle_v0;
+ }
+
+ /// triangle vertex 0 normal
+ inline math::Vector3f & n0() {
+ return triangle_n0;
+ }
+
+ /// triangle vertex 0 texture coordinates
+ inline math::Vector2f & t0() {
+ return triangle_t0;
+ }
+
+ /// triangle vertex 1
+ inline math::Vector3f & v1() {
+ return triangle_v1;
+ }
+
+ /// triangle vertex 1 normal
+ inline math::Vector3f & n1() {
+ return triangle_n1;
+ }
+
+ /// triangle vertex 1 texture coordinates
+ inline math::Vector2f & t1() {
+ return triangle_t1;
+ }
+
+ /// triangle vertex 2
+ inline math::Vector3f & v2() {
+ return triangle_v2;
+ }
+
+ /// triangle vertex 2 normal
+ inline math::Vector3f & n2() {
+ return triangle_n2;
+ }
+
+ /// triangle vertex 2 texture coordinates
+ inline math::Vector2f & t2() {
+ return triangle_t2;
+ }
+
+ /// indidcates if this triangle was generated from a detail brush
+ inline bool detail() const {
+ return triangle_detail;
+ }
+
+ /// face normal
+ inline math::Vector3f &normal() {
+ return triangle_normal;
+ }
private:
- math::Vector3f triangle_v0;
- math::Vector3f triangle_n0;
- math::Vector2f triangle_t0;
+ math::Vector3f triangle_v0;
+ math::Vector3f triangle_n0;
+ math::Vector2f triangle_t0;
- math::Vector3f triangle_v1;
- math::Vector3f triangle_n1;
- math::Vector2f triangle_t1;
+ math::Vector3f triangle_v1;
+ math::Vector3f triangle_n1;
+ math::Vector2f triangle_t1;
- math::Vector3f triangle_v2;
- math::Vector3f triangle_n2;
- math::Vector2f triangle_t2;
-
- math::Vector3f triangle_normal;
- bool triangle_detail;
+ math::Vector3f triangle_v2;
+ math::Vector3f triangle_n2;
+ math::Vector2f triangle_t2;
+
+ math::Vector3f triangle_normal;
+ bool triangle_detail;
};
}