working model cat backup

This commit is contained in:
2026-08-04 21:47:37 -05:00
parent 50a70bfe31
commit be8c1a9ea8
6 changed files with 156 additions and 47 deletions
+31
View File
@@ -3401,3 +3401,34 @@ a.deletelink {
.mods-badge.server { background: #e6e0ff; color: #3a2d8f; }
.mods-link { color: inherit; text-decoration: none; opacity: 0.6; }
.mods-link:hover { opacity: 1; }
/* Model category format badges */
.model-format-badge {
display: inline-block;
border-radius: 999px;
background: #eef2ff;
color: #3730a3;
padding: 0.1rem 0.5rem;
font-size: 0.7rem;
font-weight: 600;
margin-right: 0.35rem;
}
.model-tex-badge.embedded {
display: inline-block;
border-radius: 999px;
background: #d1fae5;
color: #065f46;
padding: 0.1rem 0.5rem;
font-size: 0.7rem;
font-weight: 600;
margin-right: 0.35rem;
}
.model-incompatible {
display: inline-block;
border-radius: 999px;
background: #fee2e2;
color: #991b1b;
padding: 0.15rem 0.6rem;
font-size: 0.72rem;
font-weight: 600;
}
+32 -13
View File
@@ -83,6 +83,17 @@
return r.json();
}
async function fetchModelText(member, baseUrl) {
const r = await fetch(assetUrl(baseUrl, member), { headers: { 'Accept': 'application/json' } });
if (!r.ok) throw new Error('Could not load the model file');
return r.text();
}
// Formats whose textures are baked into the file (nothing to resolve).
// glTF/GLB are NOT here — import needs the desktop-only glTF Importer
// plugin, so those models are marked "Incompatible" instead.
const EMBEDDED_FORMATS = ['.bbmodel'];
async function fetchVanillaIndex(vanillaBaseUrl) {
try {
const r = await fetch(assetUrl(vanillaBaseUrl, 'entity_index.json'));
@@ -165,6 +176,7 @@
async function open(btn) {
const member = btn.dataset.member;
const name = btn.dataset.name || member;
const modelFormat = btn.dataset.modelFormat || '.geo.json';
const opts = { baseUrl: btn.dataset.baseUrl, vanillaBaseUrl: btn.dataset.vanillaBaseUrl, defaultTexture: btn.dataset.defaultTexture || null };
if (!member || !opts.baseUrl || busy) return;
busy = true;
@@ -205,19 +217,26 @@
setStatus('Loading model…');
try {
const [geo, index] = await Promise.all([
fetchGeo(member, opts.baseUrl),
fetchVanillaIndex(opts.vanillaBaseUrl),
]);
const entity = entityNameFromMember(member);
const textures = await resolveTextures(geo, entity, opts, index);
iframe.contentWindow.postMessage({
type: 'packs-open-model',
geo: geo,
name: name,
textures: textures,
}, window.location.origin);
setStatus('Applying textures…');
const msg = { type: 'packs-open-model', name: name };
if (modelFormat === '.gltf' || modelFormat === '.glb') {
setStatus('Incompatible — glTF/GLB preview needs the desktop glTF Importer plugin.');
busy = false;
return;
}
if (EMBEDDED_FORMATS.indexOf(modelFormat) !== -1) {
// Textures baked into the file — hand it to Blockbench as-is.
msg.modelFile = { format: modelFormat, content: await fetchModelText(member, opts.baseUrl) };
} else {
const [geo, index] = await Promise.all([
fetchGeo(member, opts.baseUrl),
fetchVanillaIndex(opts.vanillaBaseUrl),
]);
const entity = entityNameFromMember(member);
msg.geo = geo;
msg.textures = await resolveTextures(geo, entity, opts, index);
}
iframe.contentWindow.postMessage(msg, window.location.origin);
setStatus('Applying…');
} catch (e) {
setStatus('Could not load model: ' + e.message);
}
@@ -62,6 +62,19 @@
async function openModel(msg) {
await waitFor(() => typeof loadModelFile === 'function', 15000);
const name = msg.name || 'model';
if (msg.modelFile) {
// Standalone Blockbench model (bbmodel) with baked textures.
// glTF/GLB is not sent here — those are marked "Incompatible" by the
// parent page (import needs the desktop-only glTF Importer plugin).
if (msg.modelFile.content) {
await loadModelFile({ content: msg.modelFile.content, name: name, path: name });
}
await new Promise((r) => setTimeout(r, 400));
notify('model-open', { name: name });
return;
}
await loadModelFile({ content: JSON.stringify(msg.geo), name: name, path: name });
// Give the format importer a beat, then set the feature-bone overrides
// (before adding textures, so the plugin's add_texture listener applies