X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fsceneload.cc;h=d173538407188325231d11f922ae0141801346b4;hp=1ae167bcda6e81303313a3b217107035848c357c;hb=572bf1ef8d54ef5a7cba7cdf38515cb16c4c312c;hpb=3bfa17f584d9b6ad0bcb468c85b815c5046d7250 diff --git a/src/sceneload.cc b/src/sceneload.cc index 1ae167b..d173538 100644 --- a/src/sceneload.cc +++ b/src/sceneload.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -22,6 +23,7 @@ static void print_nodes(SceneNode *node, int lvl = 0); /*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 Mat4 assimp_matrix(const aiMatrix4x4 &aim); @@ -42,12 +44,15 @@ bool Scene::load(const char *fname, unsigned int flags) aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_GenUVCoords | + //aiProcess_PreTransformVertices | aiProcess_TransformUVCoords; if(flags & SCNLOAD_FLIPTEX) { ppflags |= aiProcess_FlipUVs; } + printf("Loading scene file: %s\n", fname); + const aiScene *aiscn = aiImportFile(fname, ppflags); if(!aiscn) { fprintf(stderr, "failed to load scene file: %s\n", fname); @@ -126,7 +131,7 @@ static bool load_material(Scene *scn, Material *mat, const aiMaterial *aimat) } else { mat->name = "unknown"; } - //printf("load_material: %s\n", mat->name.c_str()); + printf("load_material: %s\n", mat->name.c_str()); if(aiGetMaterialColor(aimat, AI_MATKEY_COLOR_DIFFUSE, &aicol) == 0) { mat->diffuse = Vec3(aicol[0], aicol[1], aicol[2]); @@ -171,17 +176,15 @@ static bool load_material(Scene *scn, Material *mat, const aiMaterial *aimat) } while(*sptr++); } - Texture *tex = scn->texset->get(fname); - if(!tex) { - fprintf(stderr, "failed to load texture: %s\n", fname); - delete [] fname; - continue; - } - delete [] fname; + int textype = assimp_textype(aitype); + printf("loading %s texture: %s\n", assimp_textypestr(aitype), fname); + Texture *tex = scn->texset->get_texture(fname, TEX_2D); + assert(tex); mat->textures.push_back(tex); - int textype = assimp_textype(aitype); + printf(" DBG(%p)\n", (void*)tex); + if(textype != MTL_TEX_UNKNOWN && !mat->stdtex[textype]) { mat->stdtex[textype] = tex; } @@ -285,6 +288,10 @@ static Mesh *load_mesh(Scene *scn, const aiScene *aiscn, unsigned int flags, con iptr += 3; } + AABox bbox = mesh->get_aabbox(); + printf("mesh bounding box: %f %f %f -> %f %f %f\n", bbox.min.x, bbox.min.y, bbox.min.z, + bbox.max.x, bbox.max.y, bbox.max.z); + return mesh; } @@ -323,6 +330,7 @@ static int assimp_textype(aiTextureType type) case aiTextureType_NORMALS: return MTL_TEX_NORMALMAP; case aiTextureType_LIGHTMAP: + case aiTextureType_EMISSIVE: return MTL_TEX_LIGHTMAP; case aiTextureType_REFLECTION: return MTL_TEX_ENVMAP; @@ -332,6 +340,26 @@ static int assimp_textype(aiTextureType type) return MTL_TEX_UNKNOWN; } +static const char *assimp_textypestr(aiTextureType type) +{ + switch(type) { + case aiTextureType_DIFFUSE: + return "diffuse"; + case aiTextureType_SPECULAR: + return "specular"; + case aiTextureType_NORMALS: + return "normalmap"; + case aiTextureType_LIGHTMAP: + case aiTextureType_EMISSIVE: + return "lightmap"; + case aiTextureType_REFLECTION: + return "envmap"; + default: + break; + } + return "unknown"; +} + static Mat4 assimp_matrix(const aiMatrix4x4 &aim) { Mat4 m;