working renderer
This commit is contained in:
@@ -35,14 +35,48 @@
|
|||||||
return inst;
|
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) {
|
async function openModel(msg) {
|
||||||
await waitFor(() => typeof loadModelFile === 'function', 15000);
|
await waitFor(() => typeof loadModelFile === 'function', 15000);
|
||||||
const name = msg.name || 'model';
|
const name = msg.name || 'model';
|
||||||
await loadModelFile({ content: JSON.stringify(msg.geo), name: name, path: name });
|
await loadModelFile({ content: JSON.stringify(msg.geo), name: name, path: name });
|
||||||
// Give the format importer a beat, then load the textures and let
|
// Give the format importer a beat, then set the feature-bone overrides
|
||||||
// Blockbench's own default-texture logic apply them.
|
// (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));
|
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 {
|
try {
|
||||||
const tex = new Texture({ name: t.name || 'texture', folder: 'entity' });
|
const tex = new Texture({ name: t.name || 'texture', folder: 'entity' });
|
||||||
if (t.dataUrl) {
|
if (t.dataUrl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user