From bd142a328328cdf0cbfbb59e4e0aa99dd51184b8 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 10 Aug 2009 22:32:36 +0000 Subject: initial texture support for ase models --- src/model/material.cc | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/model/material.cc') diff --git a/src/model/material.cc b/src/model/material.cc index 81adfae..7d278f9 100644 --- a/src/model/material.cc +++ b/src/model/material.cc @@ -19,6 +19,7 @@ Material::Material(const std::string &name) : material_name(name), material_colo { aux::to_lowercase(material_name); material_flags = 0; + material_texture_id = 0; } Material::~Material() @@ -31,6 +32,16 @@ void Material::set_color(const math::Color &color) material_color.a = 1.0f; } +void Material::set_texture(const std::string &texture) +{ + material_texture.assign(texture); +} + +void Material::set_texture_id(const size_t texture_id) +{ + material_texture_id = texture_id; +} + Material::Registry Material::material_registry; void Material::init() @@ -113,17 +124,14 @@ void Material::load_shader(const std::string &shadername) } else if ((firstword.size()) && (parselevel == 0) ) { - if (firstword.compare(0, 9, "textures/") == 0) { - firstword.erase(0, 9); - material = find(firstword); - if (material) { - con_warn << "Duplicate material '" << firstword << "'" << std::endl; - } else { - material = new Material(firstword); - add(material); - //con_debug << " " << firstword << std::endl; - } + material = find(firstword); + if (material) { + con_warn << "Duplicate material '" << firstword << "'" << std::endl; + } else { + material = new Material(firstword); + add(material); count++; + //con_debug << " " << firstword << std::endl; } } else if ((parselevel == 1) && (material)) { @@ -151,6 +159,16 @@ void Material::load_shader(const std::string &shadername) continue; } else if (firstword.compare("qer_trans") == 0) { continue; + } else if (firstword.compare("texture") == 0) { + + // texture name should not contain spaces + if (linestream >> firstword) { + material->set_texture(firstword); + material->set_flags(Material::Texture); + } else { + con_warn << shaderfile.name() << " texture key without filename at line " << linenumber << std::endl; + } + } else { con_warn << shaderfile.name() << " unknown key '" << firstword << "' at line " << linenumber << std::endl; -- cgit v1.2.3