feat(assets): publish reusable area packages
This commit is contained in:
20
examples/cesium-asset-package.js
Normal file
20
examples/cesium-asset-package.js
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
const { resolveAsset, 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 };
|
||||
}
|
||||
|
||||
module.exports = { loadPackage };
|
||||
Reference in New Issue
Block a user