This commit is contained in:
2025-11-11 15:50:57 -06:00
parent 5adf8a0773
commit 9953d7d388
11 changed files with 135 additions and 86 deletions

View File

@@ -10,32 +10,43 @@ CHUNK_WIDTH = 16
CHUNK_HEIGHT = 16
CHUNK_DEPTH = 32
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):
# Only append vertices if z == 0
if z != 0:
return
vertices = []
indices = []
# Tile 0, nothing
if tileIndex == 0:
return {
'vertices': vertices,
'indices': indices
}
# Determine color for checkerboard pattern
color = (255,255,255) if (x + y) % 2 == 0 else (0,0,0)
# Use TILE_SIZE for positions
px = x * TILE_SIZE
py = y * TILE_SIZE
pz = z * TILE_SIZE
quad_vertices = [
if tileIndex == 2:
color = (255,0,0)
# Use TILE_WIDTH for positions
px = x * TILE_WIDTH
py = y * TILE_HEIGHT
pz = z * TILE_DEPTH
vertices = [
{'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_SIZE, py + TILE_SIZE, pz), 'color': color, 'uv': (1,1)}, # 1,1
{'position': (px + TILE_WIDTH, py, pz), 'color': color, 'uv': (1,0)}, # 1,0
{'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 + TILE_SIZE, py + TILE_SIZE, pz), 'color': color, 'uv': (1,1)}, # 1,1 (repeat)
{'position': (px, py + TILE_SIZE, pz), 'color': color, 'uv': (0,1)} # 0,1
{'position': (px + TILE_WIDTH, py + TILE_HEIGHT, pz), 'color': color, 'uv': (1,1)}, # 1,1 (repeat)
{'position': (px, py + TILE_HEIGHT, pz), 'color': color, 'uv': (0,1)} # 0,1
]
base = len(model['vertices'])
quad_indices = [base, base+1, base+2, base+3, base+4, base+5]
model['vertices'].extend(quad_vertices)
model['indices'].extend(quad_indices)
model['vertexCount'] = len(model['vertices'])
model['indexCount'] = len(model['indices'])
indices = [0, 1, 2, 3, 4, 5]
return {
'vertices': vertices,
'indices': indices
}
def processMap(asset):
cache = assetGetCache(asset['path'])
@@ -45,8 +56,6 @@ def processMap(asset):
# Read input file as JSON
with open(asset['path'], 'r') as f:
inData = json.load(f)
tileIndexes = inData['tiles']
# Create output object 'map' with default tile indexes and models array
map = {
@@ -65,12 +74,24 @@ def processMap(asset):
# Append the model to map.models
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
x = i % CHUNK_WIDTH
y = (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
buffer = bytearray()