@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
27 lines (24 loc) • 913 B
JavaScript
import { resolveBufferUri } from './gltf-json-asset-Bm6pwOaU.esm.js';
import './index-By0tcgYN.esm.js';
async function loadMultiBuffer(json, baseUrl) {
const buffers = json.buffers ?? [];
const arrays = await Promise.all(buffers.map((b) => b?.uri ? fetch(resolveBufferUri(b.uri, baseUrl)).then((r) => r.arrayBuffer()) : Promise.resolve(new ArrayBuffer(0))));
const offsets = [];
let total = 0;
for (const a of arrays) {
offsets.push(total);
total += a.byteLength;
total = total + 3 & -4;
}
const out = new Uint8Array(total);
for (let i = 0; i < arrays.length; i++) {
out.set(new Uint8Array(arrays[i]), offsets[i]);
}
for (const bv of json.bufferViews ?? []) {
bv.byteOffset = (bv.byteOffset ?? 0) + offsets[bv.buffer ?? 0];
bv.buffer = 0;
}
return new DataView(out.buffer);
}
export { loadMultiBuffer };
//# sourceMappingURL=gltf-multi-buffer-5Wl9SblW.esm.js.map