Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/model/fragment.cc2
-rw-r--r--src/model/fragment.h7
-rw-r--r--src/model/map.cc69
-rw-r--r--src/model/map.h3
-rw-r--r--src/model/material.cc57
-rw-r--r--src/model/material.h27
-rw-r--r--src/model/primitives.cc2
-rw-r--r--src/model/primitives.h7
8 files changed, 99 insertions, 75 deletions
diff --git a/src/model/fragment.cc b/src/model/fragment.cc
index 044e232..d8479eb 100644
--- a/src/model/fragment.cc
+++ b/src/model/fragment.cc
@@ -16,7 +16,7 @@ namespace model
Quads: the number of Quads is size/4
*/
-Fragment::Fragment(Type type, unsigned int material)
+Fragment::Fragment(Type type, const Material *material)
{
fragment_type = type;
fragment_index = VertexArray::instance()->index() / 3;
diff --git a/src/model/fragment.h b/src/model/fragment.h
index 1978baa..d9c200d 100644
--- a/src/model/fragment.h
+++ b/src/model/fragment.h
@@ -12,6 +12,7 @@
#include "math/axis.h"
#include "math/color.h"
#include "math/vector3f.h"
+#include "model/material.h"
namespace model
{
@@ -24,7 +25,7 @@ public:
enum Type {Triangles, Quads};
/// create a new fragment
- Fragment(Type type, unsigned int material);
+ Fragment(Type type, const Material *material);
/// add a vertex to the fragment
size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, math::Color const & color, bool detail);
@@ -54,7 +55,7 @@ public:
}
/// material flags
- inline unsigned int material()
+ inline const Material * material() const
{
return fragment_material;
}
@@ -64,7 +65,7 @@ private:
size_t fragment_index;
size_t fragment_structural_size;
size_t fragment_detail_size;
- unsigned int fragment_material;
+ const Material * fragment_material;
};
/// a collection of fragments
diff --git a/src/model/map.cc b/src/model/map.cc
index 45ae3fd..8217f1b 100644
--- a/src/model/map.cc
+++ b/src/model/map.cc
@@ -209,6 +209,7 @@ bool Map::getline()
n = 0;
Plane *plane = new Plane(p1, p2, p3);
+ aux::to_lowercase(texture);
plane->texture() = texture;
if (n > 0)
plane->detail() = true;
@@ -432,65 +433,17 @@ void Map::make_brushface(Plane *face)
if (vl.size() > 2) {
- // default material is none
- unsigned int material = 0;
-
- // default color makes 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().compare("colors/white") == 0) {
- color.assign(1.0f);
- } else if (face->texture().compare("colors/grey90") == 0) {
- color.assign(0.9f);
- } else if (face->texture().compare("colors/grey75") == 0) {
- color.assign(0.75f);
- } else if (face->texture().compare("colors/grey50") == 0) {
- color.assign(0.5f);
- } else if (face->texture().compare("colors/grey25") == 0) {
- color.assign(0.25f);
- } else if (face->texture().compare("colors/black") == 0) {
- color.assign(0.0f);
- } else if (face->texture().compare("colors/red") == 0) {
- color.assign(1, 0, 0);
- } else if (face->texture().compare("colors/green") == 0) {
- color.assign(0, 1, 0);
- } else if (face->texture().compare("colors/blue") == 0) {
- color.assign(0, 0, 1);
-
- } else if (face->texture().compare("common/entity") == 0) {
- material |= Material::Primary;
- } else if (face->texture().compare("common/entity_dark") == 0) {
- material |= Material::Primary;
- material |= Material::Dark;
-
- } else if (face->texture().compare("common/entity_second") == 0) {
- material |= Material::Secondary;
- } else if (face->texture().compare("common/entity_second_dark") == 0) {
- material |= Material::Secondary;
- material |= Material::Dark;
-
- } else if (face->texture().compare("common/entity_third") == 0) {
- material |= Material::Tertiary;
- } else if (face->texture().compare("common/entity_thirdy_dark") == 0) {
- material |= Material::Tertiary;
- material |= Material::Dark;
-
- } else if (face->texture().compare("common/engine") == 0) {
- color.assign(1, 0, 0);
- material |= Material::Engine;
- }
-
- // translate surface flags to materials
-
- // surface flag 1 light
- if ((face->surface_flags() & 1) == 1) {
- material |= Material::Light;
- }
+ Material *material = Material::find(face->texture());
+ math::Color color(1.0, 0.0f, 1.0f);
+ if (material) {
+ color.assign(material->color());
+ } else {
+ material = new Material(face->texture());
+ Material::add(material);
+ material->set_color(color);
+ material->set_flags(Material::Bright);
- // surface flag 2 engine
- if ((face->surface_flags() & 2) == 2) {
- material |= Material::Engine;
+ con_warn << "Unkown material '" << face->texture() << "'" << std::endl;
}
// find the list if primitives for the current material, allocate a new one if necessary
diff --git a/src/model/map.h b/src/model/map.h
index e38b9ec..d7b01d7 100644
--- a/src/model/map.h
+++ b/src/model/map.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "model/material.h"
#include "model/model.h"
#include "model/plane.h"
#include "model/primitives.h"
@@ -33,7 +34,7 @@ private:
~Map();
/// tpye definition for a per-material list of Primitives
- typedef std::map<unsigned int, Primitives *> Materials;
+ typedef std::map<Material *, Primitives *> Materials;
/// open the file for reading
/** the filename will get the "maps/" prefix and ".map" suffix
diff --git a/src/model/material.cc b/src/model/material.cc
index 0167f7b..68e80a8 100644
--- a/src/model/material.cc
+++ b/src/model/material.cc
@@ -8,20 +8,29 @@
#include "auxiliary/functions.h"
#include "filesystem/filestream.h"
+#include "math/functions.h"
#include "model/material.h"
#include "sys/sys.h"
namespace model
{
-Material::Material(const std::string &name) : material_name(name)
+Material::Material(const std::string &name) : material_name(name), material_color(1.0f)
{
+ aux::to_lowercase(material_name);
+ material_flags = 0;
}
Material::~Material()
{
}
+void Material::set_color(const math::Color &color)
+{
+ material_color.assign(color);
+ material_color.a = 1.0f;
+}
+
Material::Registry Material::material_registry;
void Material::init()
@@ -70,10 +79,15 @@ void Material::load_shader(const std::string &shadername)
}
int parselevel = 0;
+ unsigned int linenumber = 0;
char line[1024];
unsigned int count = 0;
+ float r,g,b;
+ Material *material = 0;
while (shaderfile.getline(line, 1023)) {
+ linenumber++;
+
// read materials
std::string s(line);
aux::trim(s);
@@ -101,13 +115,46 @@ void Material::load_shader(const std::string &shadername)
if (firstword.compare(0, 9, "textures/") == 0) {
firstword.erase(0, 9);
- Material *material = new Material(firstword);
- add(material);
+ material = find(firstword);
+ if (material) {
+ con_warn << "Duplicate material '" << firstword << "'" << std::endl;
+ } else {
+ material = new Material(firstword);
+ add(material);
+ con_debug << " " << firstword << std::endl;
+ }
count++;
}
- } else if (parselevel == 1) {
-
+ } else if ((parselevel == 1) && (material)) {
+ aux::to_lowercase(firstword);
+ if (firstword.compare("color") == 0) {
+ if (linestream >> r >> g >> b) {
+ if (math::max(r, math::max(g, b)) > 1.0f) {
+ r /= 255.0f; g /= 255.0f; b /= 255.0f;
+ }
+ material->set_color(math::Color(r, g, b, 1.0f));
+ }
+ } else if (firstword.compare("engine") == 0) {
+ material->set_flags(Engine);
+ } else if (firstword.compare("bright") == 0) {
+ material->set_flags(Bright);
+ } else if (firstword.compare("environment") == 0) {
+ material->set_flags(Environment);
+ } else if (firstword.compare("entity") == 0) {
+ material->set_flags(Primary);
+ } else if (firstword.compare("entitysecond") == 0) {
+ material->set_flags(Secondary);
+ } else if (firstword.compare("entitythird") == 0) {
+ material->set_flags(Tertiary);
+ } else if (firstword.compare("qer_editorimage") == 0) {
+ continue;
+ } else if (firstword.compare("qer_trans") == 0) {
+ continue;
+ } else {
+ con_warn << shaderfile.name() << " unknown key '" << firstword
+ << "' at line " << linenumber << std::endl;
+ }
}
}
}
diff --git a/src/model/material.h b/src/model/material.h
index 8081792..a2ba0d6 100644
--- a/src/model/material.h
+++ b/src/model/material.h
@@ -10,6 +10,8 @@
#include <string>
#include <map>
+#include "math/color.h"
+
namespace model
{
@@ -18,7 +20,7 @@ class Material
{
public:
/// surface flags
- enum SurfaceFlags { None=0, Primary=1, Secondary=2, Tertiary=3, Dark=4, Light=8, Engine=16};
+ enum SurfaceFlags { None=0, Primary=1, Secondary=2, Tertiary=3, Bright=4, Engine=8, Environment=16};
/// type definition for the material registry
typedef std::map<std::string, Material *> Registry;
@@ -26,7 +28,24 @@ public:
Material(const std::string &name);
~Material();
- inline const std::string &name() { return material_name; }
+ inline const std::string &name() const { return material_name; }
+
+ inline const math::Color &color() const { return material_color; }
+
+ inline const unsigned int flags() const { return material_flags; }
+
+ inline void set_flags(SurfaceFlags flags)
+ {
+ material_flags |= flags;
+ }
+
+ inline void unset_flags(SurfaceFlags flags)
+ {
+ material_flags &= ~flags;
+ }
+
+
+ void set_color(const math::Color &color);
/* ---- static ----------------------------------------------------- */
@@ -54,7 +73,9 @@ public:
private:
std::string material_name;
-
+ math::Color material_color;
+ unsigned int material_flags;
+
/// the material registry
static Registry material_registry;
diff --git a/src/model/primitives.cc b/src/model/primitives.cc
index 1b9d216..a53ebcd 100644
--- a/src/model/primitives.cc
+++ b/src/model/primitives.cc
@@ -9,7 +9,7 @@
namespace model
{
-Primitives::Primitives(unsigned int material)
+Primitives::Primitives(Material *material)
{
primitives_material = material;
}
diff --git a/src/model/primitives.h b/src/model/primitives.h
index d11ac61..2b53b5a 100644
--- a/src/model/primitives.h
+++ b/src/model/primitives.h
@@ -11,6 +11,7 @@
#include "math/vector3f.h"
#include "math/color.h"
+#include "model/material.h"
#include "model/triangle.h"
#include "model/quad.h"
@@ -27,11 +28,11 @@ public:
/// type definition for a list of quads
typedef std::list<Quad *> Quads;
- Primitives(unsigned int material);
+ Primitives(Material *material);
~Primitives();
/// the material to be used for these primitives
- inline unsigned int material() const
+ inline const Material *material() const
{
return primitives_material;
}
@@ -60,7 +61,7 @@ private:
Triangles primitives_triangles;
Quads primitives_quads;
- unsigned int primitives_material;
+ Material * primitives_material;
};
}