Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/material.cc')
-rw-r--r--src/model/material.cc57
1 files changed, 52 insertions, 5 deletions
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;
+ }
}
}
}