- match mtledit blocks with material name not object name
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 11 Dec 2016 22:10:56 +0000 (00:10 +0200)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 11 Dec 2016 22:10:56 +0000 (00:10 +0200)
- bind texutres based on the stdmap order
- clear the scene before reloading

src/app.cc
src/material.cc
src/metascene.cc
src/scene.cc
src/scene.h
src/sceneload.cc

index ef8db06..49f8469 100644 (file)
@@ -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");
index 6b10534..6288ef4 100644 (file)
@@ -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<ntex; i++) {
                bind_texture(textures[i], i);
        }
+       */
+       for(int i=0; i<NUM_MTL_TEXTURES; i++) {
+               if(stdtex[i]) {
+                       bind_texture(stdtex[i], i);
+               }
+       }
 
        if(stdtex[MTL_TEX_LIGHTMAP]) {
                bind_program(stdtex[MTL_TEX_DIFFUSE] ? sdr_ltmap : sdr_ltmap_notex);
index e0b2b20..53474f7 100644 (file)
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <string>
 #include <regex>
 #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; i<nobj; i++) {
                Object *obj = scn->objects[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);
                }
        }
index 683c9ec..35b562d 100644 (file)
@@ -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;
 
index 1cf8dcc..f295bbc 100644 (file)
@@ -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);
 
index e33e457..58d1865 100644 (file)
@@ -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);
 }