feat(assets): publish reusable area packages
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
async function main() {
|
||||
setLoadingMessage("Loading scene", config.areaId || "");
|
||||
const metadata = await fetchJson(config.metadataName);
|
||||
const descriptor = config.previewDescriptorName ? await fetchOptionalJson(config.previewDescriptorName) : null;
|
||||
adaptPackageManifest(metadata, descriptor);
|
||||
const routeData = await fetchOptionalJson(config.routeName);
|
||||
const signalData = await fetchOptionalJson(config.trafficSignalsName);
|
||||
const placement = scenePlacement(metadata);
|
||||
@@ -145,11 +147,11 @@
|
||||
}
|
||||
|
||||
function scenePlacement(metadata) {
|
||||
const anchor = metadata.anchor || {};
|
||||
const anchor = metadata.anchor || metadata.placement || {};
|
||||
const longitude = Number(anchor.longitude || 0);
|
||||
const latitude = Number(anchor.latitude || 0);
|
||||
const height = Number(anchor.height || 0);
|
||||
const heading = Number(metadata.heading_correction_degrees || 0);
|
||||
const heading = Number(metadata.heading_correction_degrees ?? metadata.placement?.headingCorrectionDegrees ?? 0);
|
||||
const position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
|
||||
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(position);
|
||||
const correction = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(heading));
|
||||
@@ -164,6 +166,10 @@
|
||||
}
|
||||
|
||||
function normalizedAssets(metadata) {
|
||||
if (metadata.schema === "osm-asset-package/v1") {
|
||||
const staticAssets = metadata.assets.map((asset) => ({ id: asset.id, label: asset.id, type: "model", url: asset.uri, enabled: asset.defaultLoad, category: asset.category, semantic: asset.role === "layer" }));
|
||||
return staticAssets.concat(metadata.previewAssets || []);
|
||||
}
|
||||
const assets = Array.isArray(metadata.assets) && metadata.assets.length
|
||||
? metadata.assets
|
||||
: [{
|
||||
@@ -176,6 +182,15 @@
|
||||
return assets.filter((asset) => (asset.type || "model") === "model" && asset.url);
|
||||
}
|
||||
|
||||
function adaptPackageManifest(metadata, descriptor) {
|
||||
if (metadata.schema !== "osm-asset-package/v1") return;
|
||||
metadata.anchor = metadata.placement;
|
||||
metadata.heading_correction_degrees = metadata.placement.headingCorrectionDegrees;
|
||||
metadata.scene_stats = metadata.sceneStats || {};
|
||||
metadata.bounds = { min_lon: metadata.bounds.minLon, min_lat: metadata.bounds.minLat, max_lon: metadata.bounds.maxLon, max_lat: metadata.bounds.maxLat };
|
||||
if (descriptor?.assets) metadata.previewAssets = descriptor.assets;
|
||||
}
|
||||
|
||||
// One broken entry in metadata.assets should not blank the whole preview, so
|
||||
// failures are collected and surfaced in the diagnostics panel instead.
|
||||
async function loadSceneAssets(viewer, metadata, placement) {
|
||||
@@ -187,7 +202,7 @@
|
||||
loaded.push(entry);
|
||||
// Semantic assets are inspection aids. Defer their network and GPU cost
|
||||
// until the user explicitly switches out of the normal scene view.
|
||||
if (entry.category === "semantic") continue;
|
||||
if (entry.semantic || entry.enabled === false) continue;
|
||||
await loadAsset(viewer, entry, placement);
|
||||
}
|
||||
if (!loaded.some((asset) => asset.model && asset.category !== "semantic")) {
|
||||
|
||||
Reference in New Issue
Block a user