backup befor new branch to test Blockbenh instead of regex renderer

This commit is contained in:
2026-08-04 16:04:30 -05:00
parent f59e9a165c
commit 8c17c273fe
11 changed files with 376 additions and 19 deletions
+61 -2
View File
@@ -80,8 +80,12 @@ for (const { c } of centers) {
}
assert(allInRange, 'all UVs within [0,1]');
// Unmapped bones default to the pack's main texture.
assert(headCube.texture === 'needsofnature:textures/entity/zombie/zombie.png', 'head uses default texture');
// Unmapped bones default to the pack's main texture (resource location
// converted to the zip member path).
assert(headCube.texture === 'assets/needsofnature/textures/entity/zombie/zombie.png', 'head uses default texture');
assert(GeoBuilder.resourceToMember('needsofnature:textures/entity/zombie/zombie.png') === 'assets/needsofnature/textures/entity/zombie/zombie.png', 'resource location converted to member');
assert(GeoBuilder.resourceToMember('assets/needsofnature/textures/x.png') === 'assets/needsofnature/textures/x.png', 'already-member unchanged');
assert(GeoBuilder.resourceToMember('textures/plain.png') === 'assets/textures/plain.png', 'bare path prefixed');
// ---------- 2. Synthetic rotated bone: Rz(-90°) around pivot (0,10,0) ----------
// Rotations are negated to match the Bedrock/GeckoLib direction.
@@ -166,6 +170,61 @@ if (pFront) {
assert(approx(pRear.center[1], pFront.center[1], 1.5), 'rear + front torso at similar height');
}
// ---------- 6. Per-face UV (Blockbench) cubes produce finite, in-range UVs ----------
// Real per-face cube from the default pack phantom model (down face is flipped
// via negative uv_size).
const perFace = {
'minecraft:geometry': [{
description: { identifier: 'geometry.pf', texture_width: 64, texture_height: 64 },
bones: [{
name: 'd2',
cubes: [{
origin: [0, 0, 0], size: [4, 8, 4],
uv: {
north: { uv: [8, 40], uv_size: [4, 8] },
east: { uv: [0, 40], uv_size: [4, 8] },
south: { uv: [12, 40], uv_size: [4, 8] },
west: { uv: [4, 40], uv_size: [4, 8] },
up: { uv: [4, 36], uv_size: [4, 4] },
down: { uv: [8, 40], uv_size: [4, -4] },
},
}],
}],
}],
};
const pfBuilt = GeoBuilder.build(perFace);
const pfCube = pfBuilt.cubes[0];
assert(pfCube && typeof pfCube.uv === 'object', 'per-face cube passed through build()');
if (pfCube) {
const g = GeoBuilder.cubeGeometry(pfCube.size, pfCube.uv, 64, 64);
assert(g.uvs.length === 48, 'per-face geometry emits 24 UVs (48 floats)');
let allFinite = true, allIn01 = true;
for (const u of g.uvs) {
if (!Number.isFinite(u)) allFinite = false;
if (u < 0 || u > 1) allIn01 = false;
}
assert(allFinite, 'per-face UVs are finite (no NaN)');
assert(allIn01, 'per-face UVs within [0,1]');
// south face = index 4 in face order [east,west,top,bottom,south,north]:
// rect [12,40,4,8] -> U 12/64..16/64, V flipped: 1-(40+8)/64 .. 1-40/64.
const southStart = 4 * 8;
let minU = 2, maxU = -1, minV = 2, maxV = -1;
for (let i = 0; i < 8; i += 2) {
minU = Math.min(minU, g.uvs[southStart + i]);
maxU = Math.max(maxU, g.uvs[southStart + i]);
minV = Math.min(minV, g.uvs[southStart + i + 1]);
maxV = Math.max(maxV, g.uvs[southStart + i + 1]);
}
assert(approx(minU, 12 / 64) && approx(maxU, 16 / 64), `per-face south U in (12..16)/64 (got ${minU.toFixed(3)}..${maxU.toFixed(3)})`);
assert(approx(minV, 1 - 48 / 64) && approx(maxV, 1 - 40 / 64), `per-face south V in [0.25,0.375] (got ${minV.toFixed(3)}..${maxV.toFixed(3)})`);
}
// ---------- 7. Per-face rects: negative uv_size mirrors (down face) ----------
const rects = GeoBuilder.perFaceRects(perFace['minecraft:geometry'][0].bones[0].cubes[0].uv);
assert(rects.bottom[3] === -4, 'negative uv_size preserved for down face');
assert(rects.top[3] === 4 && rects.south[2] === 4, 'positive faces keep size');
assert(Array.isArray(GeoBuilder.boxUVRects([0, 0], [4, 8, 4]).south), 'boxUVRects still array-based');
// ---------- summary ----------
if (failures === 0) {
console.log(`geo_builder tests OK (${checks} checks)`);