Files
osmWorkflow/examples/three-asset-package.js

18 lines
831 B
JavaScript

"use strict";
const { resolveAsset, resolveRuntime, placement } = require("./asset-package-resolver");
async function loadPackage(loader, manifestUrl, assetId = "main", handoffEnuPlacement) {
const manifest = await fetch(manifestUrl).then((response) => {
if (!response.ok) throw new Error(`Could not load manifest: ${response.status}`);
return response.json();
});
const scene = await loader.loadAsync(resolveAsset(manifestUrl, manifest, assetId));
// Three.js does not georeference local ENU itself; the embedding host owns it.
const enuPlacement = placement(manifest);
if (handoffEnuPlacement) handoffEnuPlacement(enuPlacement, scene.scene);
return { manifest, scene: scene.scene, placement: enuPlacement, runtime: (id) => resolveRuntime(manifestUrl, manifest, id) };
}
module.exports = { loadPackage };