X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fsceneload.cc;h=4c0d3241f096ac4c4ca0389678ec35419f03a5df;hp=11ce1e1b0208b7773e5fa1afa1f16d90a2191ea0;hb=e12a327cc0b4f1e59f4a66a80b170ec41ce97be6;hpb=84f1549d8146ac54574256ae0243747199e51151 diff --git a/src/sceneload.cc b/src/sceneload.cc index 11ce1e1..4c0d324 100644 --- a/src/sceneload.cc +++ b/src/sceneload.cc @@ -13,10 +13,12 @@ #include #include #include +#include "app.h" #include "scene.h" #include "objmesh.h" #include "datamap.h" #include "logger.h" +#include "metascene.h" static bool load_material(Scene *scn, Material *mat, const aiMaterial *aimat); static SceneNode *load_node(Scene *scn, const aiScene *aiscn, unsigned int flags, const aiNode *ainode); @@ -24,7 +26,7 @@ static Mesh *load_mesh(Scene *scn, const aiScene *aiscn, unsigned int flags, con /*static const char *mprop_semantic(int x); static int count_textures(const aiMaterial *aimat);*/ static int assimp_textype(aiTextureType type); -static const char *assimp_textypestr(aiTextureType type); +//static const char *assimp_textypestr(aiTextureType type); static Mat4 assimp_matrix(const aiMatrix4x4 &aim); @@ -66,6 +68,9 @@ bool Scene::load(const char *fname, unsigned int flags) } info_log("Loading scene file: %s\n", fname); + if(this->name.empty()) { + this->name = std::string(fname); + } const aiScene *aiscn = aiImportFile(fname, ppflags); if(!aiscn) { @@ -73,6 +78,27 @@ bool Scene::load(const char *fname, unsigned int flags) return false; } + LoaderData *ldata = new LoaderData; + ldata->aiscn = aiscn; + ldata->fname = std::string(fname); + loader_data = (void*)ldata; + } + + /* then, assuming we have successfully loaded everything, proceed to construct + * all the engine objects, which require access to the OpenGL context + */ + if(flags & SCNLOAD_STAGE_GL) { + if(!loader_data) { + error_log("second stage scene loader failed to find valid I/O data\n"); + return false; + } + + LoaderData *ldata = (LoaderData*)loader_data; + const aiScene *aiscn = ldata->aiscn; + fname = ldata->fname.c_str(); + + clear(); // clear any previous data (TODO: add flag for not clearing) + // assimp adds its own root node, which might have transformations Vec3 root_pos, root_scaling(1.0, 1.0, 1.0); Quat root_rot; @@ -93,25 +119,6 @@ bool Scene::load(const char *fname, unsigned int flags) nodes->set_scaling(root_scaling); } - LoaderData *ldata = new LoaderData; - ldata->aiscn = aiscn; - ldata->fname = std::string(fname); - loader_data = (void*)ldata; - } - - /* then, assuming we have successfully loaded everything, proceed to construct - * all the engine objects, which require access to the OpenGL context - */ - if(flags & SCNLOAD_STAGE_GL) { - if(!loader_data) { - error_log("second stage scene loader failed to find valid I/O data\n"); - return false; - } - - LoaderData *ldata = (LoaderData*)loader_data; - const aiScene *aiscn = ldata->aiscn; - fname = ldata->fname.c_str(); - // load all meshes for(unsigned int i=0; imNumMeshes; i++) { aiMesh *aimesh = aiscn->mMeshes[i]; @@ -198,10 +205,11 @@ 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); - info_log("loading %s texture: %s\n", assimp_textypestr(aitype), fname); - Texture *tex = scn->texset->get_texture(fname, TEX_2D); + Texture *tex = texman.get_texture(fname, TEX_2D, &scn->datamap); assert(tex); mat->textures.push_back(tex); @@ -334,7 +342,7 @@ static int assimp_textype(aiTextureType type) return MTL_TEX_UNKNOWN; } -static const char *assimp_textypestr(aiTextureType type) +/*static const char *assimp_textypestr(aiTextureType type) { switch(type) { case aiTextureType_DIFFUSE: @@ -352,7 +360,7 @@ static const char *assimp_textypestr(aiTextureType type) break; } return "unknown"; -} +}*/ static Mat4 assimp_matrix(const aiMatrix4x4 &aim) { @@ -381,7 +389,11 @@ bool SceneSet::load_scene(Scene *scn, const char *fname) bool SceneSet::done_scene(Scene *scn) { - return scn->load(0, SCNLOAD_STAGE_GL); + bool res = scn->load(0, SCNLOAD_STAGE_GL); + if(scn->metascn) { + scn->metascn->scene_loaded(scn); + } + return res; } void SceneSet::free_scene(Scene *scn)