Better block models !
This commit is contained in:
+17
-4
@@ -48,6 +48,9 @@ export interface BlockVariant {
|
||||
textures?: BlockTextures;
|
||||
// turns the model around the vertical axis, clockwise seen from above: 0, 90, 180 or 270
|
||||
y?: number;
|
||||
// what the player points at and bumps into, as boxes in pixels: [x1, y1, z1, x2, y2, z2]. the model's boxes when
|
||||
// not set, see common/block_shapes.ts
|
||||
shape?: number[][];
|
||||
}
|
||||
|
||||
export const DEFAULT_MODEL = "engine:cube";
|
||||
@@ -142,21 +145,31 @@ export function texture_variables(reference: string, textures: BlockTextures | u
|
||||
return variables;
|
||||
}
|
||||
|
||||
// the block's model, textures and turn for a value with state bits. each comes from the first variant whose conditions
|
||||
// the block's model, textures, turn and shape for a value with state bits. each comes from the first variant whose conditions
|
||||
// match that sets it, so "lit=1" can change the textures and "facing=1" the turn of the same block
|
||||
export function block_variant(block: BlockRegistry, states?: Record<string, number>): Required<BlockVariant> {
|
||||
export function block_variant(
|
||||
block: BlockRegistry,
|
||||
states?: Record<string, number>,
|
||||
): Required<Omit<BlockVariant, "shape">> & Pick<BlockVariant, "shape"> {
|
||||
let model: string | undefined;
|
||||
let textures: BlockTextures | undefined;
|
||||
let y: number | undefined;
|
||||
let shape: number[][] | undefined;
|
||||
if (block.variants && states) {
|
||||
for (const [condition, override] of Object.entries(block.variants)) {
|
||||
if (!variant_matches(condition, states)) continue;
|
||||
model ??= override.model;
|
||||
textures ??= override.textures;
|
||||
y ??= override.y;
|
||||
shape ??= override.shape;
|
||||
}
|
||||
}
|
||||
return { model: model ?? block.model ?? DEFAULT_MODEL, textures: textures ?? block.textures, y: y ?? 0 };
|
||||
return {
|
||||
model: model ?? block.model ?? DEFAULT_MODEL,
|
||||
textures: textures ?? block.textures,
|
||||
y: y ?? 0,
|
||||
shape: shape ?? block.shape,
|
||||
};
|
||||
}
|
||||
|
||||
// "age=7" or "age=7,facing=2", "" matches everything
|
||||
@@ -300,7 +313,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
|
||||
}
|
||||
|
||||
// turns a point (in block space) by the element's rotation
|
||||
function element_rotation(element: ModelElementJson): (point: number[]) => number[] {
|
||||
export function element_rotation(element: ModelElementJson): (point: number[]) => number[] {
|
||||
const rotation = element.rotation;
|
||||
if (!rotation || rotation.angle === 0) return (point) => point;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user