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
+37 -2
View File
@@ -83,11 +83,29 @@
};
}
// Blockbench per-face UV: {north:{uv:[u,v], uv_size:[w,h]}, ...} with
// up/down for top/bottom. Negative uv_size mirrors that face (180° flip).
function perFaceRects(uv) {
var map = { top: 'up', bottom: 'down', north: 'north', south: 'south', east: 'east', west: 'west' };
var rects = {};
for (var face in map) {
var p = uv[map[face]];
if (!p || !Array.isArray(p.uv)) {
rects[face] = [0, 0, 0, 0];
continue;
}
var w = (p.uv_size && p.uv_size[0]) || 0;
var h = (p.uv_size && p.uv_size[1]) || 0;
rects[face] = [p.uv[0], p.uv[1], w, h];
}
return rects;
}
// Build one cube as a BufferGeometry-compatible mesh:
// 24 positions (6 faces x 4 corners), 24 UVs, 36 indices, outward winding.
function cubeGeometry(size, uv, tw, th) {
var hx = size[0] / 2, hy = size[1] / 2, hz = size[2] / 2;
var rects = boxUVRects(uv, size);
var rects = Array.isArray(uv) ? boxUVRects(uv, size) : perFaceRects(uv);
var order = ['east', 'west', 'top', 'bottom', 'south', 'north'];
var outward = {
east: [1, 0, 0], west: [-1, 0, 0],
@@ -167,13 +185,28 @@
}
// ---------- model build ----------
// Resource locations like "needsofnature:textures/entity/x.png" resolve to
// the zip member "assets/needsofnature/textures/entity/x.png".
function resourceToMember(resource) {
resource = String(resource);
if (resource.indexOf(':') !== -1) {
var p = resource.split(':');
return 'assets/' + p.shift() + '/' + p.join(':');
}
if (resource.indexOf('assets/') === 0) return resource;
return 'assets/' + resource;
}
// Returns { cubes: [{matrix, size, uv, texture}], texture_width, texture_height }
function build(geo) {
var geometry = ((geo['minecraft:geometry'] || [])[0]) || null;
if (!geometry) return { cubes: [], texture_width: 64, texture_height: 64 };
var tw = (geometry.description && geometry.description.texture_width) || 64;
var th = (geometry.description && geometry.description.texture_height) || 64;
var textures = geo['afw_bone_textures'] || {};
var textures = {};
for (var k in (geo['afw_bone_textures'] || {})) {
textures[k] = resourceToMember(geo['afw_bone_textures'][k]);
}
var defaultTex = null;
for (var k in textures) { defaultTex = textures[k]; break; }
@@ -247,6 +280,8 @@
build: build,
cubeGeometry: cubeGeometry,
boxUVRects: boxUVRects,
perFaceRects: perFaceRects,
resourceToMember: resourceToMember,
transformPoint: transformPoint,
identity: identity,
translation: translation,