working model cat backup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user