21 lines
1.0 KiB
JavaScript
21 lines
1.0 KiB
JavaScript
"use strict";
|
|
|
|
const { resolveAsset, resolveRuntime, placement } = require("./asset-package-resolver");
|
|
|
|
async function loadPackage(viewer, manifestUrl, assetId = "main") {
|
|
const manifest = await fetch(manifestUrl).then((response) => {
|
|
if (!response.ok) throw new Error(`Could not load manifest: ${response.status}`);
|
|
return response.json();
|
|
});
|
|
const p = placement(manifest);
|
|
const origin = Cesium.Cartesian3.fromDegrees(p.longitude, p.latitude, p.height);
|
|
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
|
|
const rotation = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(p.headingCorrectionDegrees));
|
|
const modelMatrix = Cesium.Matrix4.multiplyByMatrix3(enu, rotation, new Cesium.Matrix4());
|
|
const model = await Cesium.Model.fromGltfAsync({ url: resolveAsset(manifestUrl, manifest, assetId), modelMatrix });
|
|
viewer.scene.primitives.add(model);
|
|
return { manifest, model, placement: p, runtime: (id) => resolveRuntime(manifestUrl, manifest, id) };
|
|
}
|
|
|
|
module.exports = { loadPackage };
|