X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fsceneload.cc;h=6fb17d452d442e68b45bab2b808f1e19ec08a18b;hb=31e1ffedb543e048673b7ba969607fbb8214ac9a;hp=1ae167bcda6e81303313a3b217107035848c357c;hpb=873255c40ab793b8c569eca3728d918339686000;p=laserbrain_demo diff --git a/src/sceneload.cc b/src/sceneload.cc index 1ae167b..6fb17d4 100644 --- a/src/sceneload.cc +++ b/src/sceneload.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -18,10 +19,10 @@ 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); static Mesh *load_mesh(Scene *scn, const aiScene *aiscn, unsigned int flags, const aiMesh *aimesh); -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 +43,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); @@ -63,11 +67,6 @@ bool Scene::load(const char *fname, unsigned int flags) root_pos = root_matrix.get_translation(); root_rot = root_matrix.get_rotation(); root_scaling = root_matrix.get_scaling(); - - printf("assimp root node: %s\n", aiscn->mRootNode->mName.data); - printf(" pos: %f %f %f\n", root_pos.x, root_pos.y, root_pos.z); - printf(" rot: %f %+f %+f %+f\n", root_rot.w, root_rot.x, root_rot.y, root_rot.z); - printf(" scaling: %f %f %f\n", root_scaling.x, root_scaling.y, root_scaling.z); } // load all meshes @@ -91,6 +90,7 @@ bool Scene::load(const char *fname, unsigned int flags) if(!nodes) { nodes = new SceneNode; + nodes->scene = this; nodes->set_name("root"); nodes->set_position(root_pos); nodes->set_rotation(root_rot); @@ -111,7 +111,6 @@ bool Scene::load(const char *fname, unsigned int flags) aiReleaseImport(aiscn); printf("loaded scene file: %s, %d meshes\n", fname, (int)meshes.size()); nodes->update(0); - print_nodes(nodes); return true; } @@ -171,17 +170,13 @@ 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); if(textype != MTL_TEX_UNKNOWN && !mat->stdtex[textype]) { mat->stdtex[textype] = tex; } @@ -214,6 +209,7 @@ static SceneNode *load_node(Scene *scn, const aiScene *aiscn, unsigned int flags Mesh *mesh = mesh_by_aimesh[aimesh]; if(mesh) { ObjMesh *obj = new ObjMesh; + obj->set_name(mesh->get_name()); obj->mesh = mesh; // also grab the material of this mesh load_material(scn, &obj->mtl, aiscn->mMaterials[aimesh->mMaterialIndex]); @@ -238,6 +234,7 @@ static SceneNode *load_node(Scene *scn, const aiScene *aiscn, unsigned int flags static Mesh *load_mesh(Scene *scn, const aiScene *aiscn, unsigned int flags, const aiMesh *aimesh) { Mesh *mesh = new Mesh; + mesh->set_name(aimesh->mName.data); int num_verts = aimesh->mNumVertices; int num_faces = aimesh->mNumFaces; @@ -284,35 +281,9 @@ static Mesh *load_mesh(Scene *scn, const aiScene *aiscn, unsigned int flags, con iptr[2] = aimesh->mFaces[i].mIndices[flags & SCNLOAD_FLIPYZ ? 1 : 2]; iptr += 3; } - return mesh; } -static void print_nodes(SceneNode *node, int lvl) -{ - Vec3 pos = node->get_node_position(); - Quat rot = node->get_node_rotation(); - Vec3 scale = node->get_node_scaling(); - - const char *type = node->get_num_objects() > 0 ? "mesh node" : "null node"; - - for(int i=0; iget_name(), - pos.x, pos.y, pos.z, rot.w, rot.x, rot.y, rot.z, scale.x, scale.y, scale.z); - - if(node->get_num_objects()) { - Mat4 xform = node->get_matrix(); - xform.print(stdout); - } - - int nchld = node->get_num_children(); - for(int i=0; iget_child(i), lvl + 1); - } -} - static int assimp_textype(aiTextureType type) { switch(type) { @@ -323,6 +294,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 +304,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;