Browse Source

breaking assimp

master
cinnaboot 8 years ago
parent
commit
1c9bfa1b3b
  1. 2
      src/hexgame.cpp
  2. 47
      src/mesh.cpp
  3. 18
      src/mesh.h
  4. 2
      src/render_group.cpp
  5. 1
      src/render_group.h

2
src/hexgame.cpp

@ -540,7 +540,7 @@ int main(int argc, char* argv[])
e->num_vertices = getVertexCount(); e->num_vertices = getVertexCount();
e->num_indices = getIndexCount(); e->num_indices = getIndexCount();
e->vertices = (glm::vec3 *) std::calloc(e->num_vertices, sizeof(glm::vec3)); e->vertices = (glm::vec3 *) std::calloc(e->num_vertices, sizeof(glm::vec3));
e->indices = (uint *) std::calloc (e->num_indices, sizeof(uint)); e->indices = (uint *) std::calloc(e->num_indices, sizeof(uint));
convertMesh(e); convertMesh(e);
g_render_state->entities = e; g_render_state->entities = e;
g_render_state->entity_count++; g_render_state->entity_count++;

47
src/mesh.cpp

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

18
src/mesh.h

@ -5,21 +5,21 @@
#pragma once #pragma once
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "hexgame.h" #include "hexgame.h"
bool initAssimp(); typedef struct meMeshInfo meMeshInfo;
bool meInitAssimp();
bool meLoadFromFile(const char* filename, meMeshInfo* mesh);
uint getVertexCount(); uint meGetVertexCount(meMeshInfo* mesh);
uint getIndexCount(); uint meGetIndexCount(meMeshInfo* mesh);
// copy data from assimp for use in our renderer // copy data from assimp for use in our renderer
Entity* convertMesh(Entity* e); Entity* meConvertMesh(Entity* e);
void shutdownAssimp(); void meShutdownAssimp();

2
src/render_group.cpp

@ -134,7 +134,7 @@ rgInitEntity(gl_render_group* rg, Entity* e)
uint vertex_index = 0; uint vertex_index = 0;
uint vertex_prop_index = 0; uint vertex_prop_index = 0;
GLfloat entity_test_color[3]; GLfloat entity_test_color[3];
convertColor(entity_test_color, 0xF46000FF); convertColor(entity_test_color, 0xCCCCCCFF /*0xF46000FF*/);
for (uint j = 0; j < entity_buf_len; j++) { for (uint j = 0; j < entity_buf_len; j++) {
const glm::vec3& vertex = e->vertices[vertex_index]; const glm::vec3& vertex = e->vertices[vertex_index];

1
src/render_group.h

@ -4,6 +4,7 @@
#include "hexgame.h" #include "hexgame.h"
// TODO: can these structs be used as opaque pointers?
struct gl_buffer struct gl_buffer
{ {
GLuint buffer_id = 0; GLuint buffer_id = 0;

Loading…
Cancel
Save