Meshing and lighting per section
This commit is contained in:
+3
-25
@@ -17,7 +17,7 @@ import { DEFAULT_SHAPE } from "@/common/world_shape.ts";
|
||||
import { get_state_value, set_state_value } from "@/common/utils.ts";
|
||||
import { cell_index, corner_height, fluid_quads, type FluidCell } from "@/client/workers/fluid_mesh.ts";
|
||||
import { TERRAIN_VERTEX_BYTES } from "@/client/workers/chunk_messages.ts";
|
||||
import { section_data, test_game } from "./helpers.ts";
|
||||
import { chunk_worker, mesh_column, test_game } from "./helpers.ts";
|
||||
|
||||
const OIL: BlockJson = {
|
||||
id: "oily:oil",
|
||||
@@ -170,35 +170,13 @@ async function mesh(blocks: [number, number, number, string, number?][]) {
|
||||
const registry = EverythingRegistry.get_registry<BlockRegistry>("blocks");
|
||||
const ids: Record<string, number> = {};
|
||||
registry.forEach((b, nid) => 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,
|
||||
// with the registry's gaps, like the client sends it
|
||||
blocks_registry: registry.map((block) => JSON.parse(JSON.stringify(block))),
|
||||
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 chunks = Array.from({ length: 9 }, () => new Uint32Array(DEFAULT_SHAPE.volume));
|
||||
for (const [x, y, z, id, level] of blocks) {
|
||||
const chunk = x < 0 ? chunks[3] : chunks[4];
|
||||
chunk[y * CHUNK_AREA + z * CHUNK_SIZE + ((x + CHUNK_SIZE) % CHUNK_SIZE)] = ids[id] | ((level ?? 0) << 16);
|
||||
}
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const meshed = await new Promise<any>((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: chunks.map(() => null),
|
||||
camera: [0, 0, 0],
|
||||
});
|
||||
});
|
||||
const meshed = await mesh_column(worker, DEFAULT_SHAPE, chunks);
|
||||
worker.terminate();
|
||||
const f32 = new Float32Array(meshed.translucent.vertices.buffer);
|
||||
const quads: number[][][] = [];
|
||||
|
||||
Reference in New Issue
Block a user