5 changed files with 200 additions and 14 deletions
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* mesh.h |
||||
* - wrapper for assimp http://www.assimp.org
|
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <cassert> |
||||
|
||||
#include <glm/glm.hpp> // vec3 |
||||
|
||||
#include <assimp/cimport.h> |
||||
#include <assimp/scene.h> |
||||
#include <assimp/postprocess.h> |
||||
|
||||
#include "aixlog.hpp" |
||||
|
||||
#include "hexgame.h" |
||||
|
||||
|
||||
/* the global Assimp scene object */ |
||||
const aiScene* g_scene = NULL; |
||||
|
||||
bool |
||||
initAssimp() |
||||
{ |
||||
/* get a handle to the predefined STDOUT log stream and attach
|
||||
* it to the logging system. It remains active for all further |
||||
* calls to aiImportFile(Ex) and aiApplyPostProcessing. */ |
||||
aiLogStream stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL); |
||||
aiAttachLogStream(&stream); |
||||
|
||||
g_scene = aiImportFile("../data/animated.block.dae", aiProcessPreset_TargetRealtime_MaxQuality); |
||||
|
||||
if (g_scene->mNumMeshes != 1) { |
||||
LOG(ERROR) << "We Can only handle 1 mesh per entity atm\n"; |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
uint |
||||
getVertexCount() |
||||
{ |
||||
assert(g_scene); |
||||
return g_scene->mMeshes[0]->mNumVertices; |
||||
} |
||||
|
||||
// copy data from assimp for use in our renderer
|
||||
Entity* |
||||
convertMesh(Entity* e) |
||||
{ |
||||
assert(g_scene); |
||||
uint numVertices = getVertexCount(); |
||||
assert(e && e->num_vertices == numVertices); |
||||
|
||||
// copy vertices
|
||||
for (uint i = 0; i < numVertices; i++) { |
||||
aiVector3D v_in = g_scene->mMeshes[0]->mVertices[i]; |
||||
glm::vec3 &v_out = e->vertices[i]; |
||||
v_out.x = v_in.x; |
||||
v_out.y = v_in.y; |
||||
v_out.z = v_in.z; |
||||
} |
||||
|
||||
return e; |
||||
} |
||||
|
||||
void |
||||
shutdownAssimp() |
||||
{ |
||||
|
||||
/* cleanup - calling 'aiReleaseImport' is important, as the library
|
||||
keeps internal resources until the scene is freed again. Not |
||||
doing so can cause severe resource leaking. */ |
||||
aiReleaseImport(g_scene); |
||||
aiDetachAllLogStreams(); |
||||
} |
||||
|
||||
Loading…
Reference in new issue