This commit is contained in:
2026-10-03 16:28:09 -03:00
parent 24fe7cdede
commit 91655c28c5
53 changed files with 1752 additions and 114 deletions
+7 -16
View File
@@ -25,13 +25,12 @@ import {
type ToChunkWorker,
UNALIGNED_GROUP,
} from "./chunk_messages.ts";
import { get_state_value } from "$/common/utils.ts";
import {
bake_model,
block_variant,
bake_block,
FACE_CORNERS,
find_model,
is_full_cube,
is_tinted,
looks_by_state,
type ModelJson,
} from "$/common/block_models.ts";
import {
@@ -88,7 +87,7 @@ let blocks_registry: BlockRegistry[] = [];
const TABLE_SIZE = ID_MASK + 1;
const block_layers = new Uint8Array(TABLE_SIZE);
const block_cull_same = new Uint8Array(TABLE_SIZE);
// darkens the corners it touches (minecraft's ambient occlusion), blocks with a full collision box do
// darkens the corners it touches (minecraft's ambient occlusion), full cubes with collision do
const block_occludes = new Uint8Array(TABLE_SIZE);
// light can come around a corner past it
const block_lets_light_by = new Uint8Array(TABLE_SIZE);
@@ -259,7 +258,7 @@ function build_block_tables() {
const opacity = block_light_opacity(block);
block_layers[nid] = layer;
block_cull_same[nid] = (block.cull_same ?? layer === TRANSLUCENT) ? 1 : 0;
block_occludes[nid] = block.has_collision && layer !== TRANSLUCENT ? 1 : 0;
block_occludes[nid] = block.has_collision && layer !== TRANSLUCENT && is_full_cube(block) ? 1 : 0;
block_lets_light_by[nid] = layer !== SOLID || opacity === 0 ? 1 : 0;
light_tables.opacity[nid] = opacity;
light_tables.emission[nid] = block_light_emission(block);
@@ -429,19 +428,11 @@ function atlas_v(sprite: SpriteRegion, v: number) {
function block_quads(value: number): MeshQuad[] {
const nid = value & ID_MASK;
const block = blocks_registry[nid];
const key = block.variants ? value : nid;
const key = looks_by_state(block) ? value : nid;
let quads = baked.get(key);
if (quads) return quads;
let states: Record<string, number> | undefined;
if (block.variants && block.states) {
states = {};
for (const state of block.states) states[state.name] = get_state_value(value, block, state.name)!;
}
const variant = block_variant(block, states);
const model = find_model(variant.model, models) ?? find_model("engine:cube", models)!;
quads = bake_model(model, variant.textures, variant.y).map((quad) => ({
quads = bake_block(block, value, models).map((quad) => ({
positions: quad.positions,
uvs: quad.uvs,
face: quad.face,