Handle stairs better
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
1, 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,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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,
|
||||||
|
|||||||
37
assets/map/map/1_0_0.json
Normal file
37
assets/map/map/1_0_0.json
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"tiles": [
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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||||
|
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
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -51,12 +51,19 @@ void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
|
|||||||
outPosition[0] = pos.x * TILE_WIDTH;
|
outPosition[0] = pos.x * TILE_WIDTH;
|
||||||
outPosition[1] = pos.y * TILE_HEIGHT;
|
outPosition[1] = pos.y * TILE_HEIGHT;
|
||||||
outPosition[2] = pos.z * TILE_DEPTH;
|
outPosition[2] = pos.z * TILE_DEPTH;
|
||||||
|
|
||||||
|
// Handle stair tiles.
|
||||||
|
tile_t tile = mapGetTile(pos);
|
||||||
|
if(tileIsStairs(tile)) {
|
||||||
|
outPosition[2] += TILE_DEPTH / 2.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
||||||
assertNotNull(entity, "Entity cannot be NULL");
|
assertNotNull(entity, "Entity cannot be NULL");
|
||||||
assertNotNull(outPosition, "Output position cannot be NULL");
|
assertNotNull(outPosition, "Output position cannot be NULL");
|
||||||
|
|
||||||
|
// Get position
|
||||||
sceneMapGetWorldPosition(entity->position, outPosition);
|
sceneMapGetWorldPosition(entity->position, outPosition);
|
||||||
|
|
||||||
// Add animation offset(s)
|
// Add animation offset(s)
|
||||||
@@ -64,20 +71,12 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
|||||||
case ENTITY_ANIM_WALK:
|
case ENTITY_ANIM_WALK:
|
||||||
float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION;
|
float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION;
|
||||||
|
|
||||||
// Get facing rel, we know we moved from the inverse direction.
|
vec3 lastPosition;
|
||||||
|
sceneMapGetWorldPosition(entity->lastPosition, lastPosition);
|
||||||
|
|
||||||
// Add tile size times percentage to posMin/max
|
vec3 offset;
|
||||||
vec3 offset = {
|
glm_vec3_sub(outPosition, lastPosition, offset);
|
||||||
(
|
glm_vec3_scale(offset, -animPercentage, offset);
|
||||||
(float_t)entity->position.x - (float_t)entity->lastPosition.x
|
|
||||||
) * TILE_WIDTH * -animPercentage,
|
|
||||||
(
|
|
||||||
(float_t)entity->position.y - (float_t)entity->lastPosition.y
|
|
||||||
) * TILE_HEIGHT * -animPercentage,
|
|
||||||
(
|
|
||||||
(float_t)entity->position.z - (float_t)entity->lastPosition.z
|
|
||||||
) * TILE_DEPTH * -animPercentage
|
|
||||||
};
|
|
||||||
glm_vec3_add(outPosition, offset, outPosition);
|
glm_vec3_add(outPosition, offset, outPosition);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -14,21 +14,21 @@ TILE_WIDTH = 16.0
|
|||||||
TILE_HEIGHT = 16.0
|
TILE_HEIGHT = 16.0
|
||||||
TILE_DEPTH = 11.36
|
TILE_DEPTH = 11.36
|
||||||
|
|
||||||
def processTile(tileIndex, x=0, y=0, z=0):
|
def processTile(tileIndex, x=0, y=0, z=0, chunkX=0, chunkY=0, chunkZ=0):
|
||||||
vertices = []
|
vertices = []
|
||||||
indices = []
|
indices = []
|
||||||
tileType = tileIndex
|
tileType = tileIndex
|
||||||
|
|
||||||
# Placement X, Y, Z
|
# Placement X, Y, Z
|
||||||
px = x * TILE_WIDTH
|
px = (x * TILE_WIDTH) + (chunkX * CHUNK_WIDTH * TILE_WIDTH)
|
||||||
py = y * TILE_HEIGHT
|
py = (y * TILE_HEIGHT) + (chunkY * CHUNK_HEIGHT * TILE_HEIGHT)
|
||||||
pz = z * TILE_DEPTH
|
pz = (z * TILE_DEPTH) + (chunkZ * CHUNK_DEPTH * TILE_DEPTH)
|
||||||
|
|
||||||
if tileIndex == 0:
|
if tileIndex == 0:
|
||||||
# Tile 0, nothing
|
# Tile 0, nothing
|
||||||
return None
|
return None
|
||||||
|
|
||||||
elif tileIndex == 2:
|
elif tileIndex == 5:
|
||||||
# Tile 2, ramp up
|
# Tile 2, ramp up
|
||||||
color = (255,0,0)
|
color = (255,0,0)
|
||||||
vertices = [
|
vertices = [
|
||||||
@@ -44,7 +44,7 @@ def processTile(tileIndex, x=0, y=0, z=0):
|
|||||||
else:
|
else:
|
||||||
# Determine color for checkerboard pattern
|
# Determine color for checkerboard pattern
|
||||||
if tileIndex == 1:
|
if tileIndex == 1:
|
||||||
color = (0, 255, 0)
|
color = (255, 255, 255)
|
||||||
else:
|
else:
|
||||||
color = (0, 0, 255)
|
color = (0, 0, 255)
|
||||||
|
|
||||||
@@ -73,7 +73,17 @@ def processChunk(path):
|
|||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
inData = json.load(f)
|
inData = json.load(f)
|
||||||
|
|
||||||
|
# Filename must contain chunk coordinates as X_Y_Z
|
||||||
|
fileName = os.path.basename(path)
|
||||||
|
nameParts = os.path.splitext(fileName)[0].split('_')
|
||||||
|
if len(nameParts) != 3:
|
||||||
|
print(f"Error: Chunk filename {fileName} does not contain valid chunk coordinates.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
chunk = {
|
chunk = {
|
||||||
|
'chunkX': int(nameParts[0]),
|
||||||
|
'chunkY': int(nameParts[1]),
|
||||||
|
'chunkZ': int(nameParts[2]),
|
||||||
'tiles': [0] * CHUNK_TILE_COUNT,
|
'tiles': [0] * CHUNK_TILE_COUNT,
|
||||||
'models': []
|
'models': []
|
||||||
}
|
}
|
||||||
@@ -97,7 +107,7 @@ def processChunk(path):
|
|||||||
z = i // (CHUNK_WIDTH * CHUNK_HEIGHT)
|
z = i // (CHUNK_WIDTH * CHUNK_HEIGHT)
|
||||||
|
|
||||||
# Add tile 3D model
|
# Add tile 3D model
|
||||||
result = processTile(tile, x, y, z)
|
result = processTile(tile, x, y, z, chunk['chunkX'], chunk['chunkY'], chunk['chunkZ'])
|
||||||
if result is not None and len(result['vertices']) > 0:
|
if result is not None and len(result['vertices']) > 0:
|
||||||
base = len(baseModel['vertices'])
|
base = len(baseModel['vertices'])
|
||||||
quad_indices = [base + idx for idx in result['indices']]
|
quad_indices = [base + idx for idx in result['indices']]
|
||||||
|
|||||||
Reference in New Issue
Block a user