#include <stdio.h>
+#include <assert.h>
#include <vector>
#include <map>
#include <gmath/gmath.h>
/*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);
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);
} 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]);
} 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;
}
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;
}
case aiTextureType_NORMALS:
return MTL_TEX_NORMALMAP;
case aiTextureType_LIGHTMAP:
+ case aiTextureType_EMISSIVE:
return MTL_TEX_LIGHTMAP;
case aiTextureType_REFLECTION:
return MTL_TEX_ENVMAP;
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;