working renderer

This commit is contained in:
2026-08-04 18:02:38 -05:00
parent ec74c092b7
commit 9b437c5046
@@ -35,14 +35,48 @@
return inst;
}
function filenameOf(resource) {
const s = String(resource || '').trim();
const parts = s.split('/');
return parts[parts.length - 1];
}
// Set the Multi Actor Animator per-bone texture overrides from the geo's
// afw_bone_textures. Only the feature bones get special treatment; the
// vanilla skin stays the model's base (just loaded, Blockbench default).
function applyAfwTextureOverrides(geo) {
const afw = (geo && geo['afw_bone_textures']) || {};
const overrides = {};
for (const bone in afw) {
const texName = filenameOf(afw[bone]);
if (texName) overrides[bone] = { name: bone, texture: texName };
}
if (!Object.keys(overrides).length || !Project) return;
try {
Project['multiactor_bone_texture_overrides'] = JSON.stringify(overrides);
} catch (e) {
console.error('packs override set failed', e);
}
}
async function openModel(msg) {
await waitFor(() => typeof loadModelFile === 'function', 15000);
const name = msg.name || 'model';
await loadModelFile({ content: JSON.stringify(msg.geo), name: name, path: name });
// Give the format importer a beat, then load the textures and let
// Blockbench's own default-texture logic apply them.
// Give the format importer a beat, then set the feature-bone overrides
// (before adding textures, so the plugin's add_texture listener applies
// them) and load the base texture first, then the feature overlays.
await new Promise((r) => setTimeout(r, 800));
for (const t of (msg.textures || [])) {
applyAfwTextureOverrides(msg.geo);
const afwFiles = new Set();
for (const k in ((msg.geo && msg.geo['afw_bone_textures']) || {})) {
afwFiles.add(filenameOf(msg.geo['afw_bone_textures'][k]));
}
const baseTextures = (msg.textures || []).filter((t) => !afwFiles.has(t.name));
const featureTextures = (msg.textures || []).filter((t) => afwFiles.has(t.name));
for (const t of baseTextures.concat(featureTextures)) {
try {
const tex = new Texture({ name: t.name || 'texture', folder: 'entity' });
if (t.dataUrl) {