UNPKG

@loaders.gl/i3s

Version:
98 lines (97 loc) 3.67 kB
import { OrientedBoundingBox } from '@math.gl/culling'; import { Ellipsoid } from '@math.gl/geospatial'; import { load } from '@loaders.gl/core'; import { TILE_TYPE, TILE_REFINEMENT, TILESET_TYPE } from '@loaders.gl/tiles'; import I3SNodePagesTiles from "../helpers/i3s-nodepages-tiles.js"; import { generateTileAttributeUrls, getUrlWithToken, getUrlWithoutParams } from "../utils/url-utils.js"; import { I3SLoader } from "../../i3s-loader.js"; export function normalizeTileData(tile, context) { const url = context.url || ''; let contentUrl; if (tile.geometryData) { contentUrl = `${url}/${tile.geometryData[0].href}`; } let textureUrl; if (tile.textureData) { textureUrl = `${url}/${tile.textureData[0].href}`; } let attributeUrls; if (tile.attributeData) { attributeUrls = generateTileAttributeUrls(url, tile); } const children = tile.children || []; return normalizeTileNonUrlData({ ...tile, children, url, contentUrl, textureUrl, textureFormat: 'jpg', // `jpg` format will cause `ImageLoader` usage that will be able to handle `png` as well attributeUrls, isDracoGeometry: false }); } export function normalizeTileNonUrlData(tile) { const boundingVolume = {}; let mbs = [0, 0, 0, 1]; if (tile.mbs) { mbs = tile.mbs; boundingVolume.sphere = [ ...Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)), // cartesian center of sphere tile.mbs[3] // radius of sphere ]; } else if (tile.obb) { boundingVolume.box = [ ...Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center), // cartesian center of box ...tile.obb.halfSize, // halfSize ...tile.obb.quaternion // quaternion ]; const obb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(boundingVolume.box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion); const boundingSphere = obb.getBoundingSphere(); boundingVolume.sphere = [...boundingSphere.center, boundingSphere.radius]; mbs = [...tile.obb.center, boundingSphere.radius]; } const lodMetricType = tile.lodSelection?.[0].metricType; const lodMetricValue = tile.lodSelection?.[0].maxError; const type = TILE_TYPE.MESH; /** * I3S specification supports only REPLACE */ const refine = TILE_REFINEMENT.REPLACE; return { ...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, type, refine }; } export async function normalizeTilesetData(tileset, options, context) { const url = getUrlWithoutParams(context.url || ''); let nodePagesTile; let root; if (tileset.nodePages) { nodePagesTile = new I3SNodePagesTiles(tileset, url, options); root = await nodePagesTile.formTileFromNodePages(0); } else { const parseOptions = options.i3s; const rootNodeUrl = getUrlWithToken(`${url}/nodes/root`, parseOptions.token); // eslint-disable-next-line no-use-before-define root = await load(rootNodeUrl, I3SLoader, { ...options, i3s: { // @ts-expect-error options is not properly typed ...options.i3s, loadContent: false, isTileHeader: true, isTileset: false } }); } return { ...tileset, loader: I3SLoader, url, basePath: url, type: TILESET_TYPE.I3S, nodePagesTile, // @ts-expect-error root, lodMetricType: root.lodMetricType, lodMetricValue: root.lodMetricValue }; }