Add all textures and models from create

This commit is contained in:
2026-10-12 18:47:41 -03:00
parent d4eff11f3e
commit 99bdcaeffc
3775 changed files with 66614 additions and 58 deletions
+27 -3
View File
@@ -117,6 +117,9 @@ export interface BlockVariant {
textures?: BlockTextures;
// turns the model around the vertical axis, clockwise seen from above: 0, 90, 180 or 270
y?: number;
// turns the model around the east-west axis first, like minecraft's: 0, 90, 180 or 270. 90 tips its top to the north,
// so a model pointing up points north, then y turns it to face the rest of the ways
x?: 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[][];
@@ -133,6 +136,7 @@ export interface BlockPart {
// the block's textures when not set
textures?: BlockTextures;
y?: number;
x?: number;
shape?: number[][];
collision_shape?: number[][];
}
@@ -142,6 +146,7 @@ export interface PlacedModel {
model: string;
textures: BlockTextures;
y: number;
x: number;
shape?: number[][];
collision_shape?: number[][];
}
@@ -244,6 +249,7 @@ export function block_variant(block: BlockRegistry, states?: Record<string, numb
let model: string | undefined;
let textures: BlockTextures | undefined;
let y: number | undefined;
let x: number | undefined;
let shape: number[][] | undefined;
let collision_shape: number[][] | undefined;
if (block.variants && states) {
@@ -252,6 +258,7 @@ export function block_variant(block: BlockRegistry, states?: Record<string, numb
model ??= override.model;
textures ??= override.textures;
y ??= override.y;
x ??= override.x;
shape ??= override.shape;
collision_shape ??= override.collision_shape;
}
@@ -260,6 +267,7 @@ export function block_variant(block: BlockRegistry, states?: Record<string, numb
model: model ?? block.model ?? DEFAULT_MODEL,
textures: textures ?? cube_textures(block),
y: y ?? 0,
x: x ?? 0,
shape: shape ?? block.shape,
collision_shape: collision_shape ?? block.collision_shape,
};
@@ -276,6 +284,7 @@ export function block_parts(block: BlockRegistry, states?: Record<string, number
model: part.model,
textures: part.textures ?? variant.textures,
y: part.y ?? 0,
x: part.x ?? 0,
shape: part.shape,
collision_shape: part.collision_shape,
}));
@@ -306,7 +315,7 @@ export function bake_block(block: BlockRegistry, value: number, models: Record<s
const states = looks_by_state(block) ? states_of(block, value) : undefined;
return block_parts(block, states).flatMap((part) => {
const model = find_model(part.model, models) ?? BUILTIN_MODELS[DEFAULT_MODEL];
return bake_model(model, part.textures, part.y);
return bake_model(model, part.textures, part.y, part.x);
});
}
@@ -410,6 +419,12 @@ export const FACE_CORNERS = [
export const CORNER_UVS = [[0, 1], [1, 1], [1, 0], [0, 0]] as const;
// the face a face becomes after turning the model 90 degrees clockwise seen from above
const TURN_Y = [0, 1, 4, 5, 3, 2];
// the face a face becomes after a quarter turn around the east-west axis, the top tipping north: top to north, north to
// bottom, bottom to south and south to top
const TURN_X = [3, 2, 0, 1, 4, 5];
// a quarter turn's count for a turn of 0, 90, 180 or 270 degrees
const quarters = (degrees: number) => ((Math.round(degrees / 90) % 4) + 4) % 4;
// minecraft's default uvs: the part of the texture the face would cover if the texture was wrapped around the block
function default_uv(face: ModelFace, from: number[], to: number[]): [number, number, number, number] {
@@ -431,9 +446,16 @@ function default_uv(face: ModelFace, from: number[], to: number[]): [number, num
const EPSILON = 1e-4;
export function bake_model(model: ModelJson, textures: BlockTextures | undefined, y_rotation = 0): BakedQuad[] {
// a model's quads with its textures, turned by x and then y like a block variant's turns
export function bake_model(
model: ModelJson,
textures: BlockTextures | undefined,
y_rotation = 0,
x_rotation = 0,
): BakedQuad[] {
const quads: BakedQuad[] = [];
const turns = ((Math.round(y_rotation / 90) % 4) + 4) % 4;
const turns = quarters(y_rotation);
const x_turns = quarters(x_rotation);
for (const element of model.elements) {
const rotate = element_rotation(element);
@@ -450,6 +472,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
FACE_CORNERS[index].forEach((corner, k) => {
let point = corner.map((end, axis) => (end ? element.to[axis] : element.from[axis]) / 16);
point = rotate(point);
for (let t = 0; t < x_turns; t++) point = [point[0], point[2], 1 - point[1]];
for (let t = 0; t < turns; t++) point = [1 - point[2], point[1], point[0]];
positions.push(...point);
const [cu, cv] = CORNER_UVS[(k + uv_turns) % 4];
@@ -457,6 +480,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
});
let cull = face_json.cullface ? FACE_INDEX[face_json.cullface] : -1;
for (let t = 0; t < x_turns && cull >= 0; t++) cull = TURN_X[cull];
for (let t = 0; t < turns && cull >= 0; t++) cull = TURN_Y[cull];
const { face: facing, flush, aligned } = classify(positions);
quads.push({