Meshing and lighting per section
This commit is contained in:
+4
-24
@@ -8,8 +8,8 @@ import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
|
||||
import { DEFAULT_SHAPE } from "@/common/world_shape.ts";
|
||||
import { generate_raw_chunk } from "@/common/generation.ts";
|
||||
import { get_biome } from "@/common/worldgen/biomes.ts";
|
||||
import { type LayerMesh, TERRAIN_VERTEX_BYTES } from "@/client/workers/chunk_messages.ts";
|
||||
import { section_data, test_game } from "./helpers.ts";
|
||||
import { TERRAIN_VERTEX_BYTES } from "@/client/workers/chunk_messages.ts";
|
||||
import { chunk_worker, mesh_column, test_game } from "./helpers.ts";
|
||||
|
||||
type Colors = { grass: number; foliage: number; water?: number };
|
||||
|
||||
@@ -20,16 +20,7 @@ async function mesh_block(id: string, x: number, middle: Colors, west: Colors |
|
||||
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
|
||||
const block_ids: Record<string, number> = {};
|
||||
blocks.forEach((b, nid) => block_ids[b.id] = nid);
|
||||
const worker = new Worker(new URL("../client/workers/chunk_worker.ts", import.meta.url).href, { type: "module" });
|
||||
worker.postMessage({
|
||||
type: "init",
|
||||
shape: DEFAULT_SHAPE,
|
||||
blocks_registry: JSON.parse(JSON.stringify(blocks)),
|
||||
models: {},
|
||||
textures_info: { "cubi:missing": { x: 0, y: 0, width: 16, height: 16 } },
|
||||
image: { width: 1024, height: 1024 },
|
||||
visuals: [],
|
||||
});
|
||||
const worker = chunk_worker(DEFAULT_SHAPE);
|
||||
|
||||
const chunk = new Uint32Array(DEFAULT_SHAPE.volume);
|
||||
chunk[10 * CHUNK_AREA + 8 * CHUNK_SIZE + x] = block_ids[id];
|
||||
@@ -46,18 +37,7 @@ async function mesh_block(id: string, x: number, middle: Colors, west: Colors |
|
||||
colors[4] = biome_colors(middle);
|
||||
if (west) colors[3] = biome_colors(west);
|
||||
|
||||
const meshed = await new Promise<{ solid: LayerMesh; cutout: LayerMesh; translucent: LayerMesh }>((resolve) => {
|
||||
worker.onmessage = (e) => resolve(e.data);
|
||||
worker.postMessage({
|
||||
type: "mesh",
|
||||
chunk_x: 0,
|
||||
chunk_z: 0,
|
||||
version: 1,
|
||||
chunks: chunks.map(section_data),
|
||||
biome_colors: colors,
|
||||
camera: [0, 0, 0],
|
||||
});
|
||||
});
|
||||
const meshed = await mesh_column(worker, DEFAULT_SHAPE, chunks, { biome_colors: colors });
|
||||
worker.terminate();
|
||||
|
||||
const top: number[][] = [];
|
||||
|
||||
Reference in New Issue
Block a user