|
|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
#include <cassert> |
|
|
|
|
|
|
|
|
|
#include <assimp/cimport.h> |
|
|
|
|
#include <assimp/scene.h> |
|
|
|
|
#include <assimp/postprocess.h> |
|
|
|
|
|
|
|
|
|
#include <glm/glm.hpp> // vec3 |
|
|
|
|
|
|
|
|
|
#include "aixlog.hpp" |
|
|
|
|
@ -7,11 +11,24 @@
|
|
|
|
|
#include "mesh.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//typedef struct meMatInfo meMatInfo;
|
|
|
|
|
struct meMatInfo |
|
|
|
|
{ |
|
|
|
|
aiString name; |
|
|
|
|
aiColor3D diffuse_color; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct meMeshInfo |
|
|
|
|
{ |
|
|
|
|
aiString name; |
|
|
|
|
meMatInfo* mat; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/* the global Assimp scene object */ |
|
|
|
|
const aiScene* g_scene = NULL; |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
initAssimp() |
|
|
|
|
meInitAssimp() |
|
|
|
|
{ |
|
|
|
|
/* get a handle to the predefined STDOUT log stream and attach
|
|
|
|
|
* it to the logging system. It remains active for all further |
|
|
|
|
@ -21,6 +38,16 @@ initAssimp()
|
|
|
|
|
|
|
|
|
|
g_scene = aiImportFile("../data/animated.block.dae", aiProcessPreset_TargetRealtime_MaxQuality); |
|
|
|
|
|
|
|
|
|
// testing
|
|
|
|
|
|
|
|
|
|
aiMaterial* mat = g_scene->mMaterials[0]; |
|
|
|
|
aiColor3D color(0.f, 0.f, 0.f); |
|
|
|
|
if (AI_SUCCESS != mat->Get(AI_MATKEY_COLOR_DIFFUSE, color)) { |
|
|
|
|
LOG(ERROR) << "Some Assimp-type-error\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//////////
|
|
|
|
|
|
|
|
|
|
if (g_scene->mNumMeshes != 1) { |
|
|
|
|
LOG(ERROR) << "We Can only handle 1 mesh per entity atm\n"; |
|
|
|
|
return false; |
|
|
|
|
@ -29,15 +56,21 @@ initAssimp()
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
meLoadFromFile(const char* filename, meMeshInfo* mesh) |
|
|
|
|
{ |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint |
|
|
|
|
getVertexCount() |
|
|
|
|
meGetVertexCount(meMeshInfo* mesh) |
|
|
|
|
{ |
|
|
|
|
assert(g_scene); |
|
|
|
|
return g_scene->mMeshes[0]->mNumVertices; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint |
|
|
|
|
getIndexCount() |
|
|
|
|
meGetIndexCount(meMeshInfo* mesh) |
|
|
|
|
{ |
|
|
|
|
assert(g_scene); |
|
|
|
|
return g_scene->mMeshes[0]->mNumFaces * 3; // NOTE: assume 3 vertices per face
|
|
|
|
|
@ -49,12 +82,12 @@ getIndexCount()
|
|
|
|
|
|
|
|
|
|
// copy data from assimp for use in our renderer
|
|
|
|
|
Entity* |
|
|
|
|
convertMesh(Entity* e) |
|
|
|
|
meConvertMesh(Entity* e, meMeshInfo* mesh) |
|
|
|
|
{ |
|
|
|
|
assert(g_scene); |
|
|
|
|
uint numVertices = getVertexCount(); |
|
|
|
|
uint numVertices = meGetVertexCount(mesh); |
|
|
|
|
assert(e && e->num_vertices == numVertices); |
|
|
|
|
aiMesh* mesh = g_scene->mMeshes[0]; |
|
|
|
|
//aiMesh* mesh = g_scene->mMeshes[0];
|
|
|
|
|
|
|
|
|
|
// copy vertices
|
|
|
|
|
for (uint i = 0; i < numVertices; i++) { |
|
|
|
|
@ -77,7 +110,7 @@ convertMesh(Entity* e)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
shutdownAssimp() |
|
|
|
|
meShutdownAssimp() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
/* cleanup - calling 'aiReleaseImport' is important, as the library
|
|
|
|
|
|