From 68e71418a70dab4174981d5a579e96a9089f8682 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 12 Dec 2016 00:10:56 +0200 Subject: [PATCH] - match mtledit blocks with material name not object name - bind texutres based on the stdmap order - clear the scene before reloading --- src/app.cc | 6 ++++-- src/material.cc | 7 +++++++ src/metascene.cc | 3 ++- src/scene.cc | 14 ++++++++++++++ src/scene.h | 3 ++- src/sceneload.cc | 3 +++ 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/app.cc b/src/app.cc index ef8db06..49f8469 100644 --- a/src/app.cc +++ b/src/app.cc @@ -126,12 +126,14 @@ bool app_init(int argc, char **argv) if(!(sdr_ltmap_notex = create_program_load("sdr/lightmap.v.glsl", "sdr/lightmap-notex.p.glsl"))) { return false; } + set_uniform_int(sdr_ltmap_notex, "texmap", MTL_TEX_DIFFUSE); + set_uniform_int(sdr_ltmap_notex, "lightmap", MTL_TEX_LIGHTMAP); if(!(sdr_ltmap = create_program_load("sdr/lightmap.v.glsl", "sdr/lightmap-tex.p.glsl"))) { return false; } - set_uniform_int(sdr_ltmap, "texmap", 0); - set_uniform_int(sdr_ltmap, "lightmap", 1); + set_uniform_int(sdr_ltmap, "texmap", MTL_TEX_DIFFUSE); + set_uniform_int(sdr_ltmap, "lightmap", MTL_TEX_LIGHTMAP); if(!fb_srgb) { sdr_post_gamma = create_program_load("sdr/post_gamma.v.glsl", "sdr/post_gamma.p.glsl"); diff --git a/src/material.cc b/src/material.cc index 6b10534..6288ef4 100644 --- a/src/material.cc +++ b/src/material.cc @@ -22,10 +22,17 @@ void Material::setup() const glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ks); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); + /* int ntex = std::min((int)textures.size(), 8); // TODO: use max texture units for(int i=0; i #include #include #include "metascene.h" @@ -303,7 +304,7 @@ static void apply_mtledit(Scene *scn, const MaterialEdit &med) int nobj = scn->objects.size(); for(int i=0; iobjects[i]; - if(std::regex_match(obj->get_name(), med.name_re)) { + if(std::regex_match(obj->mtl.name, med.name_re)) { apply_mtledit(&obj->mtl, med); } } diff --git a/src/scene.cc b/src/scene.cc index 683c9ec..35b562d 100644 --- a/src/scene.cc +++ b/src/scene.cc @@ -11,6 +11,9 @@ Scene::Scene() nodes = 0; walk_mesh = 0; + + texset = 0; + loader_data = 0; } Scene::~Scene() @@ -20,6 +23,17 @@ Scene::~Scene() void Scene::destroy() { + clear(); + + metascn = 0; + texset = 0; + loader_data = 0; + + datamap.clear(); +} + +void Scene::clear() +{ destroy_node_tree(nodes); nodes = 0; diff --git a/src/scene.h b/src/scene.h index 1cf8dcc..f295bbc 100644 --- a/src/scene.h +++ b/src/scene.h @@ -31,7 +31,7 @@ public: Mesh *walk_mesh; - TextureSet *texset; // only owned by Scene if own_texset is true + TextureSet *texset; void *loader_data; explicit Scene(); @@ -41,6 +41,7 @@ public: Scene &operator =(const Scene &rhs) = delete; void destroy(); + void clear(); // clear all contents (meshes, objects, and nodes) bool load(const char *fname, unsigned int flags = 0); diff --git a/src/sceneload.cc b/src/sceneload.cc index e33e457..58d1865 100644 --- a/src/sceneload.cc +++ b/src/sceneload.cc @@ -200,6 +200,8 @@ static bool load_material(Scene *scn, Material *mat, const aiMaterial *aimat) *dptr++ = *sptr == '\\' ? '/' : *sptr; } while(*sptr++); + if(!fname || !*fname) continue; + int textype = assimp_textype(aitype); Texture *tex = texman.get_texture(fname, TEX_2D, &scn->datamap); @@ -377,6 +379,7 @@ Scene *SceneSet::create_scene() bool SceneSet::load_scene(Scene *scn, const char *fname) { + scn->clear(); return scn->load(fname, SCNLOAD_FLIPTEX | SCNLOAD_STAGE_IO); } -- 1.7.10.4