Prog
This commit is contained in:
@@ -1,6 +1,38 @@
|
|||||||
{
|
{
|
||||||
"tiles": [
|
"tiles": [
|
||||||
1, 1, 1,
|
1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1
|
1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
|
||||||
|
|
||||||
|
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -14,20 +14,18 @@ errorret_t assetMapLoad(void *data, void *output) {
|
|||||||
assertNotNull(output, "Output cannot be NULL");
|
assertNotNull(output, "Output cannot be NULL");
|
||||||
|
|
||||||
assetmap_t *mapData = (assetmap_t *)data;
|
assetmap_t *mapData = (assetmap_t *)data;
|
||||||
assetmapmodel_t *mesh = (assetmapmodel_t *)output;
|
assetmap_t *out = (assetmap_t *)output;
|
||||||
|
|
||||||
memoryCopy(
|
memoryCopy(out, mapData, sizeof(assetmap_t));
|
||||||
mesh,
|
|
||||||
&mapData->models[0],
|
|
||||||
sizeof(assetmapmodel_t)
|
|
||||||
);
|
|
||||||
|
|
||||||
meshInit(
|
meshInit(
|
||||||
&mesh->mesh,
|
&out->models[0].mesh,
|
||||||
MESH_PRIMITIVE_TRIANGLES,
|
MESH_PRIMITIVE_TRIANGLES,
|
||||||
mesh->vertexCount,
|
out->models[0].vertexCount,
|
||||||
mesh->vertices
|
out->models[0].vertices
|
||||||
);
|
);
|
||||||
|
|
||||||
|
printf("Load asset\n");
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t vertexCount;
|
uint32_t vertexCount;
|
||||||
meshvertex_t vertices[36];
|
meshvertex_t vertices[6 * CHUNK_TILE_COUNT];
|
||||||
mesh_t mesh;
|
mesh_t mesh;
|
||||||
} assetmapmodel_t;
|
} assetmapmodel_t;
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ void meshDraw(
|
|||||||
const GLsizei stride = sizeof(meshvertex_t);
|
const GLsizei stride = sizeof(meshvertex_t);
|
||||||
|
|
||||||
glColorPointer(
|
glColorPointer(
|
||||||
MESH_VERTEX_COLOR_SIZE,
|
sizeof(color4b_t),
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
stride,
|
stride,
|
||||||
(const GLvoid*)&mesh->vertices[offset].color[0]
|
(const GLvoid*)&mesh->vertices[offset].color
|
||||||
);
|
);
|
||||||
glTexCoordPointer(
|
glTexCoordPointer(
|
||||||
MESH_VERTEX_UV_SIZE,
|
MESH_VERTEX_UV_SIZE,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "display/display.h"
|
#include "display/display.h"
|
||||||
|
#include "display/color.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
@@ -14,13 +15,12 @@ typedef enum {
|
|||||||
#endif
|
#endif
|
||||||
} meshprimitivetype_t;
|
} meshprimitivetype_t;
|
||||||
|
|
||||||
#define MESH_VERTEX_COLOR_SIZE 4
|
|
||||||
#define MESH_VERTEX_UV_SIZE 2
|
#define MESH_VERTEX_UV_SIZE 2
|
||||||
#define MESH_VERTEX_POS_SIZE 3
|
#define MESH_VERTEX_POS_SIZE 3
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
GLubyte color[MESH_VERTEX_COLOR_SIZE];
|
color4b_t color;
|
||||||
GLfloat uv[MESH_VERTEX_UV_SIZE];
|
GLfloat uv[MESH_VERTEX_UV_SIZE];
|
||||||
GLfloat pos[MESH_VERTEX_POS_SIZE];
|
GLfloat pos[MESH_VERTEX_POS_SIZE];
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
mesh_t QUAD_MESH_SIMPLE;
|
mesh_t QUAD_MESH_SIMPLE;
|
||||||
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {
|
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {
|
||||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
{ COLOR_WHITE_4B, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
||||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
{ COLOR_WHITE_4B, { 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
||||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
{ COLOR_WHITE_4B, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
||||||
|
|
||||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
{ COLOR_WHITE_4B, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
||||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
{ COLOR_WHITE_4B, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
||||||
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }
|
{ COLOR_WHITE_4B, { 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }
|
||||||
};
|
};
|
||||||
|
|
||||||
void quadInit() {
|
void quadInit() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
#include "scene/scene/scenemap.h"
|
||||||
|
|
||||||
map_t MAP;
|
map_t MAP;
|
||||||
|
|
||||||
@@ -111,6 +112,7 @@ void mapPositionSet(const chunkpos_t newPos) {
|
|||||||
void mapUpdate() {
|
void mapUpdate() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapChunkUnload(chunk_t* chunk) {
|
void mapChunkUnload(chunk_t* chunk) {
|
||||||
printf("Unloading chunk at (%d, %d, %d)\n",
|
printf("Unloading chunk at (%d, %d, %d)\n",
|
||||||
chunk->position.x,
|
chunk->position.x,
|
||||||
@@ -120,33 +122,20 @@ void mapChunkUnload(chunk_t* chunk) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mapChunkLoad(chunk_t* chunk) {
|
void mapChunkLoad(chunk_t* chunk) {
|
||||||
printf("Loading chunk at (%d, %d, %d)\n",
|
// printf("Loading chunk at (%d, %d, %d)\n",
|
||||||
chunk->position.x,
|
// chunk->position.x,
|
||||||
chunk->position.y,
|
// chunk->position.y,
|
||||||
chunk->position.z
|
// chunk->position.z
|
||||||
);
|
// );
|
||||||
|
|
||||||
memoryZero(chunk->tiles, sizeof(tile_t) * CHUNK_TILE_COUNT);
|
memoryZero(chunk->tiles, sizeof(tile_t) * CHUNK_TILE_COUNT);
|
||||||
|
|
||||||
// 3x3 test walkable area
|
if(chunk->position.x == 0 && chunk->position.y == 0 && chunk->position.z == 0) {
|
||||||
chunktileindex_t x, y, z;
|
if(TEST_MAP_READY) {
|
||||||
|
|
||||||
z = 0;
|
|
||||||
for(y = 0; y <= 3; y++) {
|
|
||||||
for(x = 0; x <= 3; x++) {
|
|
||||||
chunktileindex_t tileIndex = (y * CHUNK_WIDTH) + x;
|
|
||||||
chunk->tiles[tileIndex] = TILE_WALKABLE;
|
|
||||||
}
|
}
|
||||||
|
printf("LOAD CHUNK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
x = 3, y = 3;
|
|
||||||
chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_STAIRS_UP;
|
|
||||||
|
|
||||||
// x = 3, y = 2, z = 1;
|
|
||||||
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
|
|
||||||
// x = 2, y = 2, z = 1;
|
|
||||||
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
|
|
||||||
// x = 4, y = 2, z = 1;
|
|
||||||
// chunk->tiles[(z * CHUNK_WIDTH * CHUNK_HEIGHT) + (y * CHUNK_WIDTH) + x] = TILE_WALKABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
chunkindex_t mapGetChunkIndexAt(const chunkpos_t position) {
|
||||||
|
|||||||
@@ -16,8 +16,11 @@
|
|||||||
#include "rpg/rpgcamera.h"
|
#include "rpg/rpgcamera.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
#define TILE_SIZE 16
|
#define TILE_WIDTH 16.0f
|
||||||
assetmapmodel_t mesh;
|
#define TILE_HEIGHT 16.0f
|
||||||
|
#define TILE_DEPTH 11.36f
|
||||||
|
assetmap_t TEST_MAP;
|
||||||
|
bool_t TEST_MAP_READY = false;
|
||||||
|
|
||||||
errorret_t sceneMapInit(scenedata_t *data) {
|
errorret_t sceneMapInit(scenedata_t *data) {
|
||||||
// Init the camera.
|
// Init the camera.
|
||||||
@@ -37,7 +40,8 @@ errorret_t sceneMapInit(scenedata_t *data) {
|
|||||||
data->sceneMap.camera.lookatPixelPerfect.pixelsPerUnit = 1.0f;
|
data->sceneMap.camera.lookatPixelPerfect.pixelsPerUnit = 1.0f;
|
||||||
|
|
||||||
|
|
||||||
errorChain(assetLoad("map/map.dmf", &mesh));
|
errorChain(assetLoad("map/map.dmf", &TEST_MAP));
|
||||||
|
TEST_MAP_READY = true;
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,9 +52,9 @@ void sceneMapUpdate(scenedata_t *data) {
|
|||||||
void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
|
void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
|
||||||
assertNotNull(outPosition, "Output position cannot be NULL");
|
assertNotNull(outPosition, "Output position cannot be NULL");
|
||||||
|
|
||||||
outPosition[0] = pos.x * TILE_SIZE;
|
outPosition[0] = pos.x * TILE_WIDTH;
|
||||||
outPosition[1] = pos.y * TILE_SIZE;
|
outPosition[1] = pos.y * TILE_HEIGHT;
|
||||||
outPosition[2] = pos.z * TILE_SIZE;
|
outPosition[2] = pos.z * TILE_DEPTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
||||||
@@ -70,13 +74,13 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
|||||||
vec3 offset = {
|
vec3 offset = {
|
||||||
(
|
(
|
||||||
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
||||||
) * TILE_SIZE * -animPercentage,
|
) * TILE_WIDTH * -animPercentage,
|
||||||
(
|
(
|
||||||
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
||||||
) * TILE_SIZE * -animPercentage,
|
) * TILE_HEIGHT * -animPercentage,
|
||||||
(
|
(
|
||||||
(float_t)entity->position.z - (float_t)entity->lastPosition.z
|
(float_t)entity->position.z - (float_t)entity->lastPosition.z
|
||||||
) * TILE_SIZE * -animPercentage
|
) * TILE_DEPTH * -animPercentage
|
||||||
};
|
};
|
||||||
glm_vec3_add(outPosition, offset, outPosition);
|
glm_vec3_add(outPosition, offset, outPosition);
|
||||||
break;
|
break;
|
||||||
@@ -117,7 +121,7 @@ void sceneMapRender(scenedata_t *data) {
|
|||||||
// sceneMapRenderMap();
|
// sceneMapRenderMap();
|
||||||
|
|
||||||
textureBind(NULL);
|
textureBind(NULL);
|
||||||
meshDraw(&mesh.mesh, -1, -1);
|
meshDraw(&TEST_MAP.models[0].mesh, -1, -1);
|
||||||
|
|
||||||
// Render ents
|
// Render ents
|
||||||
entity_t *ent = ENTITIES;
|
entity_t *ent = ENTITIES;
|
||||||
@@ -136,7 +140,7 @@ void sceneMapRenderEntity(entity_t *entity) {
|
|||||||
if(entity->type == ENTITY_TYPE_NULL) return;
|
if(entity->type == ENTITY_TYPE_NULL) return;
|
||||||
|
|
||||||
vec3 posMin, posMax;
|
vec3 posMin, posMax;
|
||||||
vec3 size = { TILE_SIZE, TILE_SIZE, TILE_SIZE };
|
vec3 size = { TILE_WIDTH, TILE_HEIGHT, TILE_DEPTH };
|
||||||
sceneMapEntityGetPosition(entity, posMin);
|
sceneMapEntityGetPosition(entity, posMin);
|
||||||
glm_vec3_add(posMin, size, posMax);
|
glm_vec3_add(posMin, size, posMax);
|
||||||
|
|
||||||
@@ -172,12 +176,12 @@ void sceneMapRenderMap() {
|
|||||||
chunk_t *chunk = MAP.chunkOrder[i];
|
chunk_t *chunk = MAP.chunkOrder[i];
|
||||||
|
|
||||||
vec3 min, max;
|
vec3 min, max;
|
||||||
min[0] = chunk->position.x * CHUNK_WIDTH * TILE_SIZE;
|
min[0] = chunk->position.x * CHUNK_WIDTH * TILE_WIDTH;
|
||||||
min[1] = chunk->position.y * CHUNK_HEIGHT * TILE_SIZE;
|
min[1] = chunk->position.y * CHUNK_HEIGHT * TILE_HEIGHT;
|
||||||
min[2] = chunk->position.z * CHUNK_DEPTH * TILE_SIZE;
|
min[2] = chunk->position.z * CHUNK_DEPTH * TILE_DEPTH;
|
||||||
|
|
||||||
max[0] = min[0] + (CHUNK_WIDTH * TILE_SIZE);
|
max[0] = min[0] + (CHUNK_WIDTH * TILE_WIDTH);
|
||||||
max[1] = min[1] + (CHUNK_HEIGHT * TILE_SIZE);
|
max[1] = min[1] + (CHUNK_HEIGHT * TILE_HEIGHT);
|
||||||
max[2] = min[2];
|
max[2] = min[2];
|
||||||
|
|
||||||
color_t color = COLOR_WHITE;
|
color_t color = COLOR_WHITE;
|
||||||
@@ -199,5 +203,5 @@ void sceneMapRenderMap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sceneMapDispose(scenedata_t *data) {
|
void sceneMapDispose(scenedata_t *data) {
|
||||||
meshDispose(&mesh.mesh);
|
meshDispose(&TEST_MAP.models[0].mesh);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,15 @@
|
|||||||
#include "scene/scene.h"
|
#include "scene/scene.h"
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
#include "display/camera.h"
|
#include "display/camera.h"
|
||||||
|
#include "asset/asset.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
camera_t camera;
|
camera_t camera;
|
||||||
} scenemap_t;
|
} scenemap_t;
|
||||||
|
|
||||||
|
extern assetmap_t TEST_MAP;
|
||||||
|
extern bool_t TEST_MAP_READY;
|
||||||
|
|
||||||
errorret_t sceneMapInit(scenedata_t *data);
|
errorret_t sceneMapInit(scenedata_t *data);
|
||||||
void sceneMapUpdate(scenedata_t *data);
|
void sceneMapUpdate(scenedata_t *data);
|
||||||
void sceneMapRender(scenedata_t *data);
|
void sceneMapRender(scenedata_t *data);
|
||||||
|
|||||||
@@ -29,9 +29,10 @@ void uiDebugRender(const tileset_t *tileset, texture_t *texture) {
|
|||||||
snprintf(
|
snprintf(
|
||||||
buffer,
|
buffer,
|
||||||
sizeof(buffer),
|
sizeof(buffer),
|
||||||
"%.2f/%.2f/%d",
|
"%.2f/%.2f/%d/%d",
|
||||||
TIME.dynamicDelta * 1000.0f,
|
TIME.dynamicDelta * 1000.0f,
|
||||||
TIME.delta * 1000.0f,
|
TIME.delta * 1000.0f,
|
||||||
|
TIME.dynamicUpdate,
|
||||||
(int32_t)fpsDynamic
|
(int32_t)fpsDynamic
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -10,32 +10,43 @@ CHUNK_WIDTH = 16
|
|||||||
CHUNK_HEIGHT = 16
|
CHUNK_HEIGHT = 16
|
||||||
CHUNK_DEPTH = 32
|
CHUNK_DEPTH = 32
|
||||||
CHUNK_TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH
|
CHUNK_TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH
|
||||||
TILE_SIZE = 16.0
|
TILE_WIDTH = 16.0
|
||||||
|
TILE_HEIGHT = 16.0
|
||||||
|
TILE_DEPTH = 11.36
|
||||||
|
|
||||||
def createQuadForTile(model, tileIndex, x=0, y=0, z=0):
|
def createQuadForTile(model, tileIndex, x=0, y=0, z=0):
|
||||||
# Only append vertices if z == 0
|
vertices = []
|
||||||
if z != 0:
|
indices = []
|
||||||
return
|
|
||||||
|
# Tile 0, nothing
|
||||||
|
if tileIndex == 0:
|
||||||
|
return {
|
||||||
|
'vertices': vertices,
|
||||||
|
'indices': indices
|
||||||
|
}
|
||||||
|
|
||||||
# Determine color for checkerboard pattern
|
# Determine color for checkerboard pattern
|
||||||
color = (255,255,255) if (x + y) % 2 == 0 else (0,0,0)
|
color = (255,255,255) if (x + y) % 2 == 0 else (0,0,0)
|
||||||
# Use TILE_SIZE for positions
|
if tileIndex == 2:
|
||||||
px = x * TILE_SIZE
|
color = (255,0,0)
|
||||||
py = y * TILE_SIZE
|
# Use TILE_WIDTH for positions
|
||||||
pz = z * TILE_SIZE
|
px = x * TILE_WIDTH
|
||||||
quad_vertices = [
|
py = y * TILE_HEIGHT
|
||||||
|
pz = z * TILE_DEPTH
|
||||||
|
vertices = [
|
||||||
{'position': (px, py, pz), 'color': color, 'uv': (0,0)}, # 0,0
|
{'position': (px, py, pz), 'color': color, 'uv': (0,0)}, # 0,0
|
||||||
{'position': (px + TILE_SIZE, py, pz), 'color': color, 'uv': (1,0)}, # 1,0
|
{'position': (px + TILE_WIDTH, py, pz), 'color': color, 'uv': (1,0)}, # 1,0
|
||||||
{'position': (px + TILE_SIZE, py + TILE_SIZE, pz), 'color': color, 'uv': (1,1)}, # 1,1
|
{'position': (px + TILE_WIDTH, py + TILE_HEIGHT, pz), 'color': color, 'uv': (1,1)}, # 1,1
|
||||||
{'position': (px, py, pz), 'color': color, 'uv': (0,0)}, # 0,0 (repeat)
|
{'position': (px, py, pz), 'color': color, 'uv': (0,0)}, # 0,0 (repeat)
|
||||||
{'position': (px + TILE_SIZE, py + TILE_SIZE, pz), 'color': color, 'uv': (1,1)}, # 1,1 (repeat)
|
{'position': (px + TILE_WIDTH, py + TILE_HEIGHT, pz), 'color': color, 'uv': (1,1)}, # 1,1 (repeat)
|
||||||
{'position': (px, py + TILE_SIZE, pz), 'color': color, 'uv': (0,1)} # 0,1
|
{'position': (px, py + TILE_HEIGHT, pz), 'color': color, 'uv': (0,1)} # 0,1
|
||||||
]
|
]
|
||||||
base = len(model['vertices'])
|
indices = [0, 1, 2, 3, 4, 5]
|
||||||
quad_indices = [base, base+1, base+2, base+3, base+4, base+5]
|
|
||||||
model['vertices'].extend(quad_vertices)
|
return {
|
||||||
model['indices'].extend(quad_indices)
|
'vertices': vertices,
|
||||||
model['vertexCount'] = len(model['vertices'])
|
'indices': indices
|
||||||
model['indexCount'] = len(model['indices'])
|
}
|
||||||
|
|
||||||
def processMap(asset):
|
def processMap(asset):
|
||||||
cache = assetGetCache(asset['path'])
|
cache = assetGetCache(asset['path'])
|
||||||
@@ -45,8 +56,6 @@ def processMap(asset):
|
|||||||
# Read input file as JSON
|
# Read input file as JSON
|
||||||
with open(asset['path'], 'r') as f:
|
with open(asset['path'], 'r') as f:
|
||||||
inData = json.load(f)
|
inData = json.load(f)
|
||||||
|
|
||||||
tileIndexes = inData['tiles']
|
|
||||||
|
|
||||||
# Create output object 'map' with default tile indexes and models array
|
# Create output object 'map' with default tile indexes and models array
|
||||||
map = {
|
map = {
|
||||||
@@ -65,12 +74,24 @@ def processMap(asset):
|
|||||||
# Append the model to map.models
|
# Append the model to map.models
|
||||||
map['models'].append(model)
|
map['models'].append(model)
|
||||||
|
|
||||||
for i, tile in enumerate(tileIndexes):
|
for i, tile in enumerate(inData['tiles']):
|
||||||
|
# Set to map
|
||||||
|
map['tiles'][i] = tile
|
||||||
|
|
||||||
# Calculate x, y, z from i
|
# Calculate x, y, z from i
|
||||||
x = i % CHUNK_WIDTH
|
x = i % CHUNK_WIDTH
|
||||||
y = (i // CHUNK_WIDTH) % CHUNK_HEIGHT
|
y = (i // CHUNK_WIDTH) % CHUNK_HEIGHT
|
||||||
z = i // (CHUNK_WIDTH * CHUNK_HEIGHT)
|
z = i // (CHUNK_WIDTH * CHUNK_HEIGHT)
|
||||||
createQuadForTile(model, tile, x, y, z)
|
|
||||||
|
# Add tile 3D model
|
||||||
|
result = createQuadForTile(model, tile, x, y, z)
|
||||||
|
if len(result['vertices']) > 0:
|
||||||
|
base = len(model['vertices'])
|
||||||
|
quad_indices = [base + idx for idx in result['indices']]
|
||||||
|
model['vertices'].extend(result['vertices'])
|
||||||
|
model['indices'].extend(quad_indices)
|
||||||
|
model['vertexCount'] = len(model['vertices'])
|
||||||
|
model['indexCount'] = len(model['indices'])
|
||||||
|
|
||||||
# Generate binary buffer for efficient output
|
# Generate binary buffer for efficient output
|
||||||
buffer = bytearray()
|
buffer = bytearray()
|
||||||
|
|||||||
Reference in New Issue
Block a user