#include <stdio.h>
#include <assert.h>
+#include <string>
#include <vector>
#include <map>
#include <gmath/gmath.h>
#include <assimp/vector3.h>
#include <assimp/matrix4x4.h>
#include <assimp/quaternion.h>
+#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);
/*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);
struct LoaderData {
const aiScene *aiscn;
+ std::string fname;
std::map<std::string, SceneNode*> node_by_name;
std::map<aiMesh*, Mesh*> mesh_by_aimesh;
};
}
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) {
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;
nodes->set_scaling(root_scaling);
}
- LoaderData *ldata = new LoaderData;
- ldata->aiscn = aiscn;
- 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;
-
// load all meshes
for(unsigned int i=0; i<aiscn->mNumMeshes; i++) {
aiMesh *aimesh = aiscn->mMeshes[i];
}
}
+ info_log("loaded scene file: %s, %d meshes\n", fname, (int)meshes.size());
+
aiReleaseImport(aiscn);
delete ldata;
loader_data = 0;
- info_log("loaded scene file: %s, %d meshes\n", fname, (int)meshes.size());
nodes->update(0);
}
return true;
*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);
return MTL_TEX_UNKNOWN;
}
-static const char *assimp_textypestr(aiTextureType type)
+/*static const char *assimp_textypestr(aiTextureType type)
{
switch(type) {
case aiTextureType_DIFFUSE:
break;
}
return "unknown";
-}
+}*/
static Mat4 assimp_matrix(const aiMatrix4x4 &aim)
{
memcpy(m[0], &aim, 16 * sizeof(float));
return transpose(m);
}
+
+
+// --- SceneSet ---
+
+SceneSet::SceneSet()
+ : DataSet<Scene*>(create_scene, load_scene, done_scene, free_scene)
+{
+}
+
+Scene *SceneSet::create_scene()
+{
+ return new Scene;
+}
+
+bool SceneSet::load_scene(Scene *scn, const char *fname)
+{
+ return scn->load(fname, SCNLOAD_FLIPTEX | SCNLOAD_STAGE_IO);
+}
+
+bool SceneSet::done_scene(Scene *scn)
+{
+ bool res = scn->load(0, SCNLOAD_STAGE_GL);
+ if(scn->metascn) {
+ scn->metascn->scene_loaded(scn);
+ }
+ return res;
+}
+
+void SceneSet::free_scene(Scene *scn)
+{
+ delete scn;
+}