Refactor handling of imported assets a bit
parent
be9c54a94a
commit
c9189c7807
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef ASSIMP_TYPES_H_
|
||||||
|
#define ASSIMP_TYPES_H_
|
||||||
|
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
|
typedef struct aiScene AiScene;
|
||||||
|
typedef struct aiNode AiNode;
|
||||||
|
typedef struct aiMesh AiMesh;
|
||||||
|
typedef struct aiFace AiFace;
|
||||||
|
|
||||||
|
#endif
|
23
level.c
23
level.c
|
@ -1,30 +1,29 @@
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <assimp/cimport.h>
|
#include <assimp/cimport.h>
|
||||||
#include <assimp/scene.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h> // TODO remove
|
#include <stdio.h> // TODO remove
|
||||||
|
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
#include "tga.h"
|
|
||||||
|
|
||||||
const Block BLOCK_EMPTY = 0;
|
const AiScene* levelScene = NULL;
|
||||||
const Block BLOCK_WALL01 = 1;
|
|
||||||
|
|
||||||
TgaImage* levelImage = NULL;
|
static const Block BLOCK_EMPTY = 0;
|
||||||
|
static const Block BLOCK_WALL01 = 0xFF0000FF; // red
|
||||||
|
|
||||||
Block getBlock(GLushort x, GLushort y) {
|
static const AiScene* blockWall01 = NULL;
|
||||||
if (levelImage == NULL) {
|
|
||||||
return BLOCK_EMPTY;
|
static TgaImage* levelImage = NULL;
|
||||||
}
|
|
||||||
return ((Block*) (*levelImage).bytes)[x * (*levelImage).header.imageWidth + y];
|
void initLevel() {
|
||||||
|
blockWall01 = importScene("out/assets/wall01.3ds");
|
||||||
|
levelScene = blockWall01;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setImage(TgaImage* image) {
|
void setImage(TgaImage* image) {
|
||||||
levelImage = image;
|
levelImage = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct aiScene* importModel(const char* path) {
|
const AiScene* importScene(const char* path) {
|
||||||
const struct aiScene* scene = aiImportFile(path, 0u);
|
const struct aiScene* scene = aiImportFile(path, 0u);
|
||||||
if (scene == NULL) {
|
if (scene == NULL) {
|
||||||
fprintf(stderr, "Asset import failed at file %s\n", path); // TODO factor logging the heck outta here
|
fprintf(stderr, "Asset import failed at file %s\n", path); // TODO factor logging the heck outta here
|
||||||
|
|
13
level.h
13
level.h
|
@ -1,17 +1,18 @@
|
||||||
#ifndef LEVEL_H_
|
#ifndef LEVEL_H_
|
||||||
#define LEVEL_H_
|
#define LEVEL_H_
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "assimp_types.h"
|
||||||
|
|
||||||
#include "tga.h"
|
#include "tga.h"
|
||||||
|
|
||||||
typedef GLuint Block;
|
typedef uint32_t Block;
|
||||||
|
|
||||||
const Block BLOCK_EMPTY;
|
const AiScene* levelScene;
|
||||||
const Block BLOCK_WALL01;
|
|
||||||
|
|
||||||
Block getBlock(GLushort x, GLushort y);
|
void initLevel();
|
||||||
void setImage(TgaImage* image);
|
void setImage(TgaImage* image);
|
||||||
const struct aiScene* importModel(const char* path);
|
const AiScene* importScene(const char* path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
2
main.c
2
main.c
|
@ -24,8 +24,8 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
initRender();
|
initRender();
|
||||||
initPerformanceMetering();
|
initPerformanceMetering();
|
||||||
|
initLevel();
|
||||||
|
|
||||||
model = importModel("out/assets/wall01.3ds");
|
|
||||||
/*
|
/*
|
||||||
fprintf(stderr, "*model = ");
|
fprintf(stderr, "*model = ");
|
||||||
print_struct_aiScene(stderr, model);
|
print_struct_aiScene(stderr, model);
|
||||||
|
|
12
render.c
12
render.c
|
@ -1,6 +1,8 @@
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#include <assimp/scene.h>
|
|
||||||
|
|
||||||
|
#include "assimp_types.h"
|
||||||
|
|
||||||
|
#include "level.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include "performance.h"
|
#include "performance.h"
|
||||||
|
@ -19,7 +21,7 @@ void renderScene() {
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
drawModelRecursive(model, (*model).mRootNode);
|
drawModelRecursive(levelScene, levelScene->mRootNode);
|
||||||
glDisable(GL_LIGHT0);
|
glDisable(GL_LIGHT0);
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
|
@ -55,15 +57,15 @@ void drawAxes() {
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawModelRecursive(const struct aiScene* model, const struct aiNode* node) {
|
void drawModelRecursive(const AiScene* model, const AiNode* node) {
|
||||||
if (((*model).mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
|
if (((*model).mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < (*node).mNumMeshes; ++i) {
|
for (int i = 0; i < (*node).mNumMeshes; ++i) {
|
||||||
const struct aiMesh* mesh = (*model).mMeshes[(*node).mMeshes[i]];
|
const AiMesh* mesh = (*model).mMeshes[(*node).mMeshes[i]];
|
||||||
for (int k = 0; k < (*mesh).mNumFaces; ++k) {
|
for (int k = 0; k < (*mesh).mNumFaces; ++k) {
|
||||||
const struct aiFace face = (*mesh).mFaces[k];
|
const AiFace face = (*mesh).mFaces[k];
|
||||||
|
|
||||||
GLenum faceMode;
|
GLenum faceMode;
|
||||||
switch (face.mNumIndices) {
|
switch (face.mNumIndices) {
|
||||||
|
|
Loading…
Reference in New Issue