@spacexr/3d-tiles-runtime 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +93 -2
  3. package/dist/chunk-AI6NWGCA.js +316 -0
  4. package/dist/chunk-AI6NWGCA.js.map +1 -0
  5. package/dist/chunk-G7YVZYMR.js +24 -0
  6. package/dist/chunk-G7YVZYMR.js.map +1 -0
  7. package/dist/chunk-PJIVVIOF.js +205 -0
  8. package/dist/chunk-PJIVVIOF.js.map +1 -0
  9. package/dist/chunk-Q2AL6LWU.js +3 -0
  10. package/dist/chunk-Q2AL6LWU.js.map +1 -0
  11. package/dist/chunk-Q35HKP5V.js +249 -0
  12. package/dist/chunk-Q35HKP5V.js.map +1 -0
  13. package/dist/chunk-URZDM4BH.js +488 -0
  14. package/dist/chunk-URZDM4BH.js.map +1 -0
  15. package/dist/implicit/index.d.ts +64 -0
  16. package/dist/implicit/index.js +4 -0
  17. package/dist/implicit/index.js.map +1 -0
  18. package/dist/index-CNnPRQZc.d.ts +350 -0
  19. package/dist/index.d.ts +713 -0
  20. package/dist/index.js +3074 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/metadata/index.d.ts +12 -0
  23. package/dist/metadata/index.js +3 -0
  24. package/dist/metadata/index.js.map +1 -0
  25. package/dist/pipeline/index.d.ts +5 -0
  26. package/dist/pipeline/index.js +3 -0
  27. package/dist/pipeline/index.js.map +1 -0
  28. package/dist/ports/index.d.ts +62 -0
  29. package/dist/ports/index.js +4 -0
  30. package/dist/ports/index.js.map +1 -0
  31. package/dist/resource-DH72MRMN.d.ts +34 -0
  32. package/dist/spatial/index.d.ts +402 -0
  33. package/dist/spatial/index.js +3 -0
  34. package/dist/spatial/index.js.map +1 -0
  35. package/dist/spatial-3IDPbyv4.d.ts +28 -0
  36. package/dist/types-Dn5i8Uqg.d.ts +78 -0
  37. package/dist/types-ri64XfSE.d.ts +237 -0
  38. package/package.json +102 -5
  39. package/src/implicit/availability.ts +55 -0
  40. package/src/implicit/coordinates.ts +193 -0
  41. package/src/implicit/dense-subtree-loader.ts +23 -0
  42. package/src/implicit/index.ts +6 -0
  43. package/src/implicit/standard-subtree-loader.ts +71 -0
  44. package/src/implicit/tile-data-source.ts +120 -0
  45. package/src/implicit/types.ts +156 -0
  46. package/src/index.ts +6 -0
  47. package/src/metadata/index.ts +2 -0
  48. package/src/metadata/metadata-resolver.ts +308 -0
  49. package/src/metadata/types.ts +91 -0
  50. package/src/pipeline/index.ts +4 -0
  51. package/src/pipeline/metadata-store.ts +44 -0
  52. package/src/pipeline/ports.ts +62 -0
  53. package/src/pipeline/states.ts +56 -0
  54. package/src/pipeline/tile-3d.ts +165 -0
  55. package/src/ports/camera.ts +12 -0
  56. package/src/ports/content.ts +71 -0
  57. package/src/ports/glyph.ts +13 -0
  58. package/src/ports/index.ts +32 -0
  59. package/src/ports/resource.ts +54 -0
  60. package/src/ports/spatial.ts +28 -0
  61. package/src/ports/telemetry.ts +44 -0
  62. package/src/runtime/cache.ts +112 -0
  63. package/src/runtime/contracts.ts +77 -0
  64. package/src/runtime/events.ts +57 -0
  65. package/src/runtime/hooks.ts +99 -0
  66. package/src/runtime/index.ts +7 -0
  67. package/src/runtime/instrumentation.ts +163 -0
  68. package/src/runtime/priority-scheduler.ts +88 -0
  69. package/src/runtime/quadtree-balance.ts +215 -0
  70. package/src/runtime/tile-runtime.ts +3508 -0
  71. package/src/spatial/bounding-volumes.ts +159 -0
  72. package/src/spatial/ecef-types.ts +110 -0
  73. package/src/spatial/ecef.ts +196 -0
  74. package/src/spatial/index.ts +6 -0
  75. package/src/spatial/utm-bounds.ts +151 -0
  76. package/src/spatial/utm-types.ts +83 -0
  77. package/src/spatial/vertical-scale.ts +125 -0
  78. package/src/spatial/view-metrics.ts +132 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/metadata/metadata-resolver.ts"],"names":[],"mappings":";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,CAAA,CAAA;AAAA,YACtC;AAAA,WACH,CAAA;AAAA,QACL;AACA,QAAA,IAAI,gBAAgB,MAAA,IAAa,CAAC,aAAa,WAAA,EAAa,UAAA,EAAY,MAAM,CAAA,EAAG;AAC7E,UAAA,WAAA,CAAY,IAAA,CAAK;AAAA,YACb,IAAA,EAAM,wBAAA;AAAA,YACN,QAAA,EAAU,OAAA;AAAA,YACV,OAAA,EAAS,CAAA,UAAA,EAAa,UAAU,CAAA,0BAAA,EAA6B,WAAW,IAAI,CAAA,YAAA,CAAA;AAAA,YAC5E,IAAA,EAAM,CAAA,EAAG,IAAI,CAAA,YAAA,EAAe,UAAU,CAAA,CAAA;AAAA,YACtC;AAAA,WACH,CAAA;AAAA,QACL;AAAA,MACJ;AAEA,MAAA,UAAA,CAAW,UAAU,CAAA,GAAI;AAAA,QACrB,EAAA,EAAI,UAAA;AAAA,QACJ,GAAI,aAAa,EAAE,UAAA,EAAY,UAAU,UAAA,CAAW,QAAA,KAAa,EAAC;AAAA,QAClE,GAAI,QAAA,KAAa,MAAA,GAAY,EAAE,QAAA,KAAa,EAAC;AAAA,QAC7C,GAAI,KAAA,KAAU,MAAA,GAAY,EAAE,KAAA,KAAU,EAAC;AAAA,QACvC,WAAA;AAAA,QACA;AAAA,OACJ;AAAA,IACJ;AAEA,IAAA,OAAO;AAAA,MACH,KAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,GAAI,SAAA,KAAc,MAAA,GAAY,EAAE,SAAA,KAAc,EAAC;AAAA,MAC/C,MAAA;AAAA,MACA,SAAS,MAAA,CAAO,KAAA;AAAA,MAChB,GAAI,eAAA,GAAkB,EAAE,eAAA,KAAoB,EAAC;AAAA,MAC7C,UAAA;AAAA,MACA;AAAA,KACJ;AAAA,EACJ;AACJ","file":"chunk-Q35HKP5V.js","sourcesContent":["import type {\n IMetadataClassProperty,\n IMetadataEntity,\n IMetadataSchema,\n MetadataComponentType,\n MetadataValue,\n} from \"@spacexr/3d-tiles-core\";\n\nimport type {\n IMetadataDiagnostic,\n IMetadataResolutionInput,\n IMetadataSnapshot,\n IResolvedMetadataEntity,\n IResolvedMetadataProperty,\n MetadataScopeKind,\n MetadataScopeOrder,\n} from \"./types\";\n\nconst VECTOR_LENGTHS: Readonly<Record<string, number>> = { VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 };\n\nconst INTEGER_RANGES: Readonly<Record<MetadataComponentType, readonly [number, number] | undefined>> = {\n INT8: [-128, 127],\n UINT8: [0, 255],\n INT16: [-32768, 32767],\n UINT16: [0, 65535],\n INT32: [-2147483648, 2147483647],\n UINT32: [0, 4294967295],\n INT64: undefined,\n UINT64: undefined,\n FLOAT32: undefined,\n FLOAT64: undefined,\n};\n\nexport const DEFAULT_METADATA_SCOPE_ORDER: MetadataScopeOrder = [\n \"feature\",\n \"content\",\n \"tile\",\n \"ancestor-tile\",\n \"subtree\",\n \"group\",\n \"tileset\",\n];\n\nfunction valuesEqual(left: unknown, right: unknown): boolean {\n if (left === right) return true;\n if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;\n return left.every((value, index) => valuesEqual(value, right[index]));\n}\n\nfunction valueAt(value: MetadataValue | undefined, index: number): MetadataValue | undefined {\n if (!Array.isArray(value)) return value;\n return value[index];\n}\n\nfunction normalizeNumber(value: number, componentType: MetadataComponentType | undefined): number {\n if (!componentType) return value;\n const range = INTEGER_RANGES[componentType];\n if (!range) return value;\n if (range[0] < 0) return Math.max(value / range[1], -1);\n return value / range[1];\n}\n\nfunction transformValue(value: MetadataValue, definition: IMetadataClassProperty): MetadataValue {\n const transformNumber = (item: number, index: number): number => {\n const normalized = definition.normalized ? normalizeNumber(item, definition.componentType) : item;\n const scale = valueAt(definition.scale, index);\n const offset = valueAt(definition.offset, index);\n return normalized * (typeof scale === \"number\" ? scale : 1) + (typeof offset === \"number\" ? offset : 0);\n };\n\n if (typeof value === \"number\") return transformNumber(value, 0);\n if (Array.isArray(value)) {\n return value.map((item, index) => (typeof item === \"number\" ? transformNumber(item, index) : item)) as MetadataValue;\n }\n return value;\n}\n\nfunction validateComponentNumber(value: unknown, definition: IMetadataClassProperty): boolean {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return false;\n const component = definition.componentType;\n if (!component || component.startsWith(\"FLOAT\")) return true;\n if (!Number.isInteger(value)) return false;\n const range = INTEGER_RANGES[component];\n return !range || (value >= range[0] && value <= range[1]);\n}\n\nfunction isValueValid(value: unknown, definition: IMetadataClassProperty, schema: IMetadataSchema | undefined): boolean {\n if (definition.array) {\n if (!Array.isArray(value)) return false;\n if (definition.count !== undefined && value.length !== definition.count) return false;\n return value.every((item) => isSingleValueValid(item, { ...definition, array: false }, schema));\n }\n return isSingleValueValid(value, definition, schema);\n}\n\nfunction isSingleValueValid(value: unknown, definition: IMetadataClassProperty, schema: IMetadataSchema | undefined): boolean {\n if (definition.type === \"BOOLEAN\") return typeof value === \"boolean\";\n if (definition.type === \"STRING\") return typeof value === \"string\";\n if (definition.type === \"ENUM\") {\n if (typeof value !== \"string\" || !definition.enumType) return false;\n return schema?.enums?.[definition.enumType]?.values.some((candidate) => candidate.name === value) ?? false;\n }\n if (definition.type === \"SCALAR\") return validateComponentNumber(value, definition);\n\n const expectedLength = VECTOR_LENGTHS[definition.type];\n return (\n expectedLength !== undefined &&\n Array.isArray(value) &&\n value.length === expectedLength &&\n value.every((item) => validateComponentNumber(item, definition))\n );\n}\n\nexport class MetadataResolver {\n public resolve(input: IMetadataResolutionInput): IMetadataSnapshot {\n const scopes: IResolvedMetadataEntity[] = [];\n const diagnostics: IMetadataDiagnostic[] = [...input.document.diagnostics];\n const append = (\n scope: MetadataScopeKind,\n ownerId: string,\n entity: IMetadataEntity | undefined,\n path: string,\n featureId?: string | number,\n ): void => {\n if (!entity) return;\n const resolved = this.resolveEntity(input.document.uri, input.document.schema, scope, ownerId, entity, path, featureId);\n scopes.push(resolved);\n diagnostics.push(...resolved.diagnostics);\n };\n\n append(\"tileset\", input.document.uri, input.document.tileset.metadata, \"$.metadata\");\n if (input.subtree) {\n const resolved = this.resolveEntity(\n input.subtree.documentUri,\n input.document.schema,\n \"subtree\",\n input.subtree.id,\n input.subtree.entity,\n `${input.subtree.id}.subtreeMetadata`,\n );\n scopes.push(resolved);\n diagnostics.push(...resolved.diagnostics);\n }\n for (const ancestor of input.ancestors) {\n diagnostics.push(...ancestor.document.diagnostics);\n if (ancestor.tile.metadata) {\n const resolved = this.resolveEntity(\n ancestor.document.uri,\n ancestor.document.schema,\n \"ancestor-tile\",\n ancestor.id,\n ancestor.tile.metadata,\n `${ancestor.id}.metadata`,\n );\n scopes.push(resolved);\n diagnostics.push(...resolved.diagnostics);\n }\n }\n append(\"tile\", input.tileId, input.tile.metadata, `${input.tileId}.metadata`);\n\n if (input.content?.group !== undefined) {\n const group = input.document.tileset.groups?.[input.content.group];\n if (group) {\n append(\"group\", `${input.document.uri}#group/${input.content.group}`, group, `$.groups[${input.content.group}]`);\n } else {\n diagnostics.push({\n code: \"METADATA_GROUP_OUT_OF_RANGE\",\n severity: \"error\",\n message: `Content references missing group ${input.content.group}.`,\n path: `${input.tileId}.content.group`,\n documentUri: input.document.uri,\n });\n }\n }\n\n append(\"content\", `${input.tileId}.content`, input.content?.metadata, `${input.tileId}.content.metadata`);\n for (const feature of input.features ?? []) {\n const resolved = this.resolveEntity(\n feature.sourceUri ?? input.document.uri,\n feature.schema ?? input.document.schema,\n \"feature\",\n `${input.tileId}.feature/${feature.id ?? scopes.length}`,\n feature.entity,\n `${input.tileId}.features[${String(feature.id ?? scopes.length)}]`,\n feature.id,\n );\n scopes.push(resolved);\n diagnostics.push(...resolved.diagnostics);\n }\n\n return {\n document: input.document,\n tileId: input.tileId,\n tile: input.tile,\n ...(input.content ? { content: input.content } : {}),\n scopes,\n diagnostics,\n };\n }\n\n public findBySemantic(\n snapshot: IMetadataSnapshot,\n semantic: string,\n order: MetadataScopeOrder = DEFAULT_METADATA_SCOPE_ORDER,\n ): IResolvedMetadataProperty | undefined {\n for (const scopeKind of order) {\n for (let index = snapshot.scopes.length - 1; index >= 0; index--) {\n const scope = snapshot.scopes[index];\n if (scope?.scope !== scopeKind) continue;\n const property = Object.values(scope.properties).find((candidate) => candidate.semantic === semantic);\n if (property) return property;\n }\n }\n return undefined;\n }\n\n private resolveEntity(\n documentUri: string,\n schema: IMetadataSchema | undefined,\n scope: MetadataScopeKind,\n ownerId: string,\n entity: IMetadataEntity,\n path: string,\n featureId?: string | number,\n ): IResolvedMetadataEntity {\n const diagnostics: IMetadataDiagnostic[] = [];\n const classDefinition = schema?.classes?.[entity.class];\n if (!schema) {\n diagnostics.push({\n code: \"METADATA_SCHEMA_UNAVAILABLE\",\n severity: \"warning\",\n message: `Cannot validate class \"${entity.class}\" because its schema is unavailable.`,\n path,\n documentUri,\n });\n } else if (!classDefinition) {\n diagnostics.push({\n code: \"METADATA_CLASS_UNKNOWN\",\n severity: \"error\",\n message: `Class \"${entity.class}\" is not declared by schema \"${schema.id}\".`,\n path: `${path}.class`,\n documentUri,\n });\n }\n\n const propertyIds = new Set([...Object.keys(classDefinition?.properties ?? {}), ...Object.keys(entity.properties ?? {})]);\n const properties: Record<string, IResolvedMetadataProperty> = {};\n\n for (const propertyId of propertyIds) {\n const definition = classDefinition?.properties?.[propertyId];\n const rawValue = entity.properties?.[propertyId];\n const isNoData = definition?.noData !== undefined && rawValue !== undefined && valuesEqual(rawValue, definition.noData);\n const fromDefault = (rawValue === undefined || isNoData) && definition?.default !== undefined;\n const sourceValue = fromDefault ? definition?.default : isNoData ? undefined : rawValue;\n const value = sourceValue !== undefined && definition ? transformValue(sourceValue, definition) : sourceValue;\n\n if (!definition) {\n diagnostics.push({\n code: \"METADATA_PROPERTY_UNKNOWN\",\n severity: \"warning\",\n message: `Property \"${propertyId}\" is not declared by class \"${entity.class}\".`,\n path: `${path}.properties.${propertyId}`,\n documentUri,\n });\n } else {\n if (definition.required && sourceValue === undefined) {\n diagnostics.push({\n code: \"METADATA_PROPERTY_REQUIRED\",\n severity: \"error\",\n message: `Required property \"${propertyId}\" is missing.`,\n path: `${path}.properties.${propertyId}`,\n documentUri,\n });\n }\n if (sourceValue !== undefined && !isValueValid(sourceValue, definition, schema)) {\n diagnostics.push({\n code: \"METADATA_PROPERTY_TYPE\",\n severity: \"error\",\n message: `Property \"${propertyId}\" does not conform to its ${definition.type} definition.`,\n path: `${path}.properties.${propertyId}`,\n documentUri,\n });\n }\n }\n\n properties[propertyId] = {\n id: propertyId,\n ...(definition ? { definition, semantic: definition.semantic } : {}),\n ...(rawValue !== undefined ? { rawValue } : {}),\n ...(value !== undefined ? { value } : {}),\n fromDefault,\n isNoData,\n };\n }\n\n return {\n scope,\n ownerId,\n documentUri,\n ...(featureId !== undefined ? { featureId } : {}),\n entity,\n classId: entity.class,\n ...(classDefinition ? { classDefinition } : {}),\n properties,\n diagnostics,\n };\n }\n}\n"]}
@@ -0,0 +1,488 @@
1
+ import { resolveUtmProjection, getUtmBoundingVolume } from '@spacexr/3d-tiles-core';
2
+ import { cartesian3, matrix4 } from '@spacexr/geometry';
3
+ import { UtmProjection } from '@spacexr/geodesy';
4
+
5
+ // src/spatial/ecef.ts
6
+ function boundsFromBox(box, matrix) {
7
+ const center = matrix4.transformPoint(matrix, { x: box[0], y: box[1], z: box[2] });
8
+ const axes = [
9
+ matrix4.transformDirection(matrix, { x: box[3], y: box[4], z: box[5] }),
10
+ matrix4.transformDirection(matrix, { x: box[6], y: box[7], z: box[8] }),
11
+ matrix4.transformDirection(matrix, { x: box[9], y: box[10], z: box[11] })
12
+ ];
13
+ const extent = {
14
+ x: Math.abs(axes[0].x) + Math.abs(axes[1].x) + Math.abs(axes[2].x),
15
+ y: Math.abs(axes[0].y) + Math.abs(axes[1].y) + Math.abs(axes[2].y),
16
+ z: Math.abs(axes[0].z) + Math.abs(axes[1].z) + Math.abs(axes[2].z)
17
+ };
18
+ let radius = 0;
19
+ for (const xSign of [-1, 1]) {
20
+ for (const ySign of [-1, 1]) {
21
+ for (const zSign of [-1, 1]) {
22
+ radius = Math.max(
23
+ radius,
24
+ cartesian3.length({
25
+ x: xSign * axes[0].x + ySign * axes[1].x + zSign * axes[2].x,
26
+ y: xSign * axes[0].y + ySign * axes[1].y + zSign * axes[2].y,
27
+ z: xSign * axes[0].z + ySign * axes[1].z + zSign * axes[2].z
28
+ })
29
+ );
30
+ }
31
+ }
32
+ }
33
+ return {
34
+ boundingBox: {
35
+ min: { x: center.x - extent.x, y: center.y - extent.y, z: center.z - extent.z },
36
+ max: { x: center.x + extent.x, y: center.y + extent.y, z: center.z + extent.z }
37
+ },
38
+ boundingSphere: { center, radius }
39
+ };
40
+ }
41
+ function boundsFromSphere(sphere, matrix) {
42
+ const center = matrix4.transformPoint(matrix, { x: sphere[0], y: sphere[1], z: sphere[2] });
43
+ const radius = sphere[3] * matrix4.maximumScale(matrix);
44
+ return {
45
+ boundingSphere: { center, radius },
46
+ boundingBox: {
47
+ min: { x: center.x - radius, y: center.y - radius, z: center.z - radius },
48
+ max: { x: center.x + radius, y: center.y + radius, z: center.z + radius }
49
+ }
50
+ };
51
+ }
52
+ function angleWithin(angle, west, east) {
53
+ const fullTurn = Math.PI * 2;
54
+ const normalized2 = (angle % fullTurn + fullTurn) % fullTurn;
55
+ const normalizedWest = (west % fullTurn + fullTurn) % fullTurn;
56
+ let normalizedEast = (east % fullTurn + fullTurn) % fullTurn;
57
+ if (normalizedEast < normalizedWest) normalizedEast += fullTurn;
58
+ const candidate = normalized2 < normalizedWest ? normalized2 + fullTurn : normalized2;
59
+ return candidate >= normalizedWest && candidate <= normalizedEast;
60
+ }
61
+ function regionSamples(region) {
62
+ const [west, south, east, north, minimumHeight, maximumHeight] = region;
63
+ const longitudes = /* @__PURE__ */ new Set([west, east, (west + (east < west ? east + Math.PI * 2 : east)) / 2]);
64
+ for (const candidate of [-Math.PI, -Math.PI / 2, 0, Math.PI / 2, Math.PI]) {
65
+ if (angleWithin(candidate, west, east)) longitudes.add(candidate);
66
+ }
67
+ const latitudes = /* @__PURE__ */ new Set([south, north, (south + north) / 2]);
68
+ if (south <= 0 && north >= 0) latitudes.add(0);
69
+ const samples = [];
70
+ for (const longitude of longitudes) {
71
+ for (const latitude of latitudes) {
72
+ samples.push([longitude, latitude, minimumHeight], [longitude, latitude, maximumHeight]);
73
+ }
74
+ }
75
+ return samples;
76
+ }
77
+ function boundsFromRegion(region, system) {
78
+ return boundsFromPoints(
79
+ regionSamples(region).map(([longitude, latitude, height]) => system.geodeticRadiansToEcef(latitude, longitude, height))
80
+ );
81
+ }
82
+ function boundsFromPoints(points) {
83
+ const min = { x: Number.POSITIVE_INFINITY, y: Number.POSITIVE_INFINITY, z: Number.POSITIVE_INFINITY };
84
+ const max = { x: Number.NEGATIVE_INFINITY, y: Number.NEGATIVE_INFINITY, z: Number.NEGATIVE_INFINITY };
85
+ for (const point of points) {
86
+ min.x = Math.min(min.x, point.x);
87
+ min.y = Math.min(min.y, point.y);
88
+ min.z = Math.min(min.z, point.z);
89
+ max.x = Math.max(max.x, point.x);
90
+ max.y = Math.max(max.y, point.y);
91
+ max.z = Math.max(max.z, point.z);
92
+ }
93
+ const center = { x: (min.x + max.x) / 2, y: (min.y + max.y) / 2, z: (min.z + max.z) / 2 };
94
+ const radius = points.reduce((current, point) => Math.max(current, cartesian3.distance(point, center)), 0);
95
+ return { boundingBox: { min, max }, boundingSphere: { center, radius } };
96
+ }
97
+ function boxesIntersect(left, right) {
98
+ return !(left.max.x < right.min.x || left.min.x > right.max.x || left.max.y < right.min.y || left.min.y > right.max.y || left.max.z < right.min.z || left.min.z > right.max.z);
99
+ }
100
+ function sphereOutsidePlane(sphere, plane) {
101
+ return cartesian3.dot(plane, sphere.center) + plane.w < -sphere.radius;
102
+ }
103
+ function isSphereBeyondHorizon(sphere, cameraPosition, bodyRadius, lowestHeight, heightRange) {
104
+ const centreDistance = cartesian3.length(sphere.center);
105
+ if (sphere.radius >= centreDistance) return false;
106
+ const cameraDistance = cartesian3.length(cameraPosition);
107
+ const lowest = heightRange ? bodyRadius + heightRange[0] : centreDistance - sphere.radius;
108
+ const highest = heightRange ? bodyRadius + heightRange[1] : centreDistance + sphere.radius;
109
+ const occluder = Math.min(bodyRadius + Math.min(0, lowestHeight), lowest);
110
+ if (occluder <= 0 || cameraDistance <= occluder) return false;
111
+ const cosine = cartesian3.dot(sphere.center, cameraPosition) / (centreDistance * cameraDistance);
112
+ const angle = Math.acos(Math.max(-1, Math.min(1, cosine)));
113
+ const extent = Math.asin(sphere.radius / centreDistance);
114
+ return angle - extent > Math.acos(occluder / cameraDistance) + Math.acos(occluder / Math.max(occluder, highest));
115
+ }
116
+ function isSphereBelowConservativeHorizon(sphere, cameraPosition, occluderRadius) {
117
+ const cameraDistance = cartesian3.length(cameraPosition);
118
+ if (cameraDistance <= occluderRadius) return false;
119
+ const centreDotCamera = cartesian3.dot(sphere.center, cameraPosition);
120
+ return centreDotCamera + sphere.radius * cameraDistance < occluderRadius * occluderRadius;
121
+ }
122
+ var SAMPLES_PER_AXIS = 3;
123
+ function defaultHorizontalDatumResolver(_projection) {
124
+ return void 0;
125
+ }
126
+ function explicitGeoidMargin(options) {
127
+ const margin = options.geoidUndulationMargin;
128
+ if (margin === void 0 || !Number.isFinite(margin) || margin < 0)
129
+ throw new RangeError("An explicit nonnegative geoid margin or geoid model is required.");
130
+ return margin;
131
+ }
132
+ function upwardInterval(vertical) {
133
+ return vertical.direction === "DOWN" ? [-vertical.maximum, -vertical.minimum] : [vertical.minimum, vertical.maximum];
134
+ }
135
+ function verticalModel(vertical, options) {
136
+ const [lower, upper] = upwardInterval(vertical);
137
+ switch (vertical.reference) {
138
+ case "ELLIPSOID":
139
+ return { origin: "ellipsoid", range: [lower, upper], orthometric: false };
140
+ case "GEOID":
141
+ return { origin: "geoid", range: [lower, upper], orthometric: true };
142
+ case "GROUND":
143
+ if (vertical.groundElevation !== void 0) {
144
+ return {
145
+ origin: "ground-elevation",
146
+ range: [vertical.groundElevation + lower, vertical.groundElevation + upper],
147
+ orthometric: true
148
+ };
149
+ }
150
+ break;
151
+ }
152
+ return {
153
+ origin: "assumed-terrain",
154
+ range: (() => {
155
+ const range = options.unknownGroundHeightRange;
156
+ if (!range || !range.every(Number.isFinite) || range[0] > range[1])
157
+ throw new RangeError("An explicit valid terrain height envelope is required.");
158
+ return [range[0] + lower, range[1] + upper];
159
+ })(),
160
+ orthometric: false
161
+ };
162
+ }
163
+ function ellipsoidalHeightRange(vertical, options) {
164
+ const model = verticalModel(vertical, options);
165
+ return model.orthometric ? [model.range[0] - explicitGeoidMargin(options), model.range[1] + explicitGeoidMargin(options)] : model.range;
166
+ }
167
+ function widen(bounds, margin) {
168
+ if (margin <= 0 || !bounds.boundingBox || !bounds.boundingSphere) return bounds;
169
+ const { min, max } = bounds.boundingBox;
170
+ return {
171
+ boundingBox: {
172
+ min: { x: min.x - margin, y: min.y - margin, z: min.z - margin },
173
+ max: { x: max.x + margin, y: max.y + margin, z: max.z + margin }
174
+ },
175
+ boundingSphere: { center: bounds.boundingSphere.center, radius: bounds.boundingSphere.radius + margin }
176
+ };
177
+ }
178
+ function boundsFromUtm(extent, system, options = {}) {
179
+ const projection = resolveUtmProjection(extent);
180
+ if (!projection) return { placement: { status: "unresolved-projection", horizontalMargin: 0, verticalMargin: 0 } };
181
+ const datumTransformation = (options.datumResolver ?? defaultHorizontalDatumResolver)(projection);
182
+ if (!datumTransformation) return { placement: { status: "unresolved-datum", projection, horizontalMargin: 0, verticalMargin: 0 } };
183
+ const vertical = verticalModel(extent.vertical, options);
184
+ const geoid = vertical.orthometric ? options.geoidUndulation ? "model" : "margin" : void 0;
185
+ const verticalMargin = geoid === "margin" ? explicitGeoidMargin(options) : 0;
186
+ const minimumHeight = vertical.range[0] - verticalMargin;
187
+ const maximumHeight = vertical.range[1] + verticalMargin;
188
+ const ellipsoid = datumTransformation.sourceEllipsoid ?? system.ellipsoid;
189
+ const utm = new UtmProjection(projection.zone, projection.hemisphere, ellipsoid);
190
+ const points = [];
191
+ const geodetic = { latitude: 0, longitude: 0, height: 0 };
192
+ for (let i = 0; i < SAMPLES_PER_AXIS; i++) {
193
+ const easting = extent.minEasting + (extent.maxEasting - extent.minEasting) * i / (SAMPLES_PER_AXIS - 1);
194
+ for (let j = 0; j < SAMPLES_PER_AXIS; j++) {
195
+ const northing = extent.minNorthing + (extent.maxNorthing - extent.minNorthing) * j / (SAMPLES_PER_AXIS - 1);
196
+ utm.projectedToGeodeticRadians(easting, northing, 0, geodetic);
197
+ datumTransformation.transform?.(geodetic);
198
+ const undulation = geoid === "model" ? options.geoidUndulation(geodetic.latitude, geodetic.longitude) : 0;
199
+ points.push(system.geodeticRadiansToEcef(geodetic.latitude, geodetic.longitude, minimumHeight + undulation));
200
+ points.push(system.geodeticRadiansToEcef(geodetic.latitude, geodetic.longitude, maximumHeight + undulation));
201
+ }
202
+ }
203
+ const placement = {
204
+ status: "placed",
205
+ projection,
206
+ datumTransformation: { name: datumTransformation.name, accuracy: datumTransformation.accuracy },
207
+ horizontalMargin: datumTransformation.accuracy,
208
+ verticalOrigin: vertical.origin,
209
+ verticalMargin,
210
+ heightRange: [minimumHeight, maximumHeight]
211
+ };
212
+ if (geoid) placement.geoid = geoid;
213
+ return { ...widen(boundsFromPoints(points), datumTransformation.accuracy), placement };
214
+ }
215
+ var VerticalScale = class _VerticalScale {
216
+ current;
217
+ listeners = /* @__PURE__ */ new Set();
218
+ /** @throws RangeError When the value is negative or not finite. */
219
+ constructor(value = 1) {
220
+ this.current = _VerticalScale.checked(value);
221
+ }
222
+ get value() {
223
+ return this.current;
224
+ }
225
+ /** Changes the scale and notifies the listeners when it differs. @throws RangeError When the value is negative or not finite. */
226
+ set(value) {
227
+ const next = _VerticalScale.checked(value);
228
+ if (next === this.current) return;
229
+ this.current = next;
230
+ for (const listener of [...this.listeners]) listener(next);
231
+ }
232
+ /** @returns The function that stops the notifications. */
233
+ subscribe(listener) {
234
+ this.listeners.add(listener);
235
+ return () => this.listeners.delete(listener);
236
+ }
237
+ static checked(value) {
238
+ if (!Number.isFinite(value) || value < 0) throw new RangeError("The vertical scale must be non-negative and finite.");
239
+ return value;
240
+ }
241
+ };
242
+ function radialVerticalFrame(reference) {
243
+ return {
244
+ height: (point) => reference.height(point),
245
+ up: (point) => cartesian3.normalize(point)
246
+ };
247
+ }
248
+ function geodeticVerticalFrame(system) {
249
+ return {
250
+ height: (point) => system.ecefToGeodeticRadians(point).height,
251
+ up: (point) => {
252
+ const { latitude, longitude } = system.ecefToGeodeticRadians(point);
253
+ const cosine = Math.cos(latitude);
254
+ return { x: cosine * Math.cos(longitude), y: cosine * Math.sin(longitude), z: Math.sin(latitude) };
255
+ }
256
+ };
257
+ }
258
+ function verticalDisplacement(anchor, placement) {
259
+ const factor = placement.scale.value - 1;
260
+ if (factor === 0 || !anchor || anchor.x === 0 && anchor.y === 0 && anchor.z === 0) return { x: 0, y: 0, z: 0 };
261
+ const distance = placement.frame.height(anchor) * factor;
262
+ return cartesian3.scale(placement.frame.up(anchor), distance);
263
+ }
264
+ function placeVertically(state, placement, parent) {
265
+ const origin = matrix4.translation(state.worldTransform);
266
+ const object = parent?.verticalObject ?? (cartesian3.length(origin) > 0 ? origin : void 0);
267
+ const sphere = state.boundingSphere;
268
+ const anchor = object ?? (sphere && cartesian3.copy(sphere.center));
269
+ const placed = { ...state, ...object ? { verticalObject: object } : {}, ...anchor ? { verticalAnchor: anchor } : {} };
270
+ const factor = placement.scale.value - 1;
271
+ if (factor === 0 || !sphere) return placed;
272
+ const moved = verticalDisplacement(anchor, placement);
273
+ const margin = object ? 0 : sphere.radius * Math.abs(factor);
274
+ placed.boundingSphere = {
275
+ center: cartesian3.add(sphere.center, moved),
276
+ radius: sphere.radius + margin
277
+ };
278
+ if (state.boundingBox) {
279
+ const { min, max } = state.boundingBox;
280
+ placed.boundingBox = {
281
+ min: { x: min.x + moved.x - margin, y: min.y + moved.y - margin, z: min.z + moved.z - margin },
282
+ max: { x: max.x + moved.x + margin, y: max.y + moved.y + margin, z: max.z + moved.z + margin }
283
+ };
284
+ }
285
+ return placed;
286
+ }
287
+ function metresPerPixel(camera, distance, fallback) {
288
+ const viewportHeight = camera.viewportHeight > 0 ? camera.viewportHeight : fallback.viewportHeight;
289
+ const tanHalfVerticalFov = camera.tanHalfVerticalFov ?? Math.tan((camera.verticalFovRadians ?? fallback.verticalFovRadians) / 2);
290
+ if (!Number.isFinite(tanHalfVerticalFov) || tanHalfVerticalFov <= 0) return Number.NaN;
291
+ return 2 * tanHalfVerticalFov * distance / viewportHeight;
292
+ }
293
+ var DEGREES = 180 / Math.PI;
294
+ var { cross, dot } = cartesian3;
295
+ function normalized(vector) {
296
+ return cartesian3.length(vector) > 0 ? cartesian3.normalize(vector) : void 0;
297
+ }
298
+ function raySphereDistance(origin, direction, radius) {
299
+ const b = dot(origin, direction);
300
+ const c = dot(origin, origin) - radius * radius;
301
+ const discriminant = b * b - c;
302
+ if (discriminant < 0) return void 0;
303
+ const root = Math.sqrt(discriminant);
304
+ const near = -b - root;
305
+ if (near >= 0) return near;
306
+ const far = -b + root;
307
+ return far >= 0 ? far : void 0;
308
+ }
309
+ function describeView(camera, options) {
310
+ const position = camera.position;
311
+ const up = options.vertical.up(position);
312
+ const height = options.vertical.height(position);
313
+ const metrics = {
314
+ latitude: Math.asin(Math.max(-1, Math.min(1, up.z))) * DEGREES,
315
+ longitude: Math.atan2(up.y, up.x) * DEGREES,
316
+ height
317
+ };
318
+ const ground = options.groundHeight;
319
+ if (ground !== void 0 && Number.isFinite(ground)) metrics.altitude = height - ground;
320
+ const forward = camera.forward && normalized(camera.forward);
321
+ if (!forward) return metrics;
322
+ const vertical = dot(forward, up);
323
+ metrics.pitch = Math.asin(Math.max(-1, Math.min(1, vertical))) * DEGREES;
324
+ const north = normalized({ x: -up.z * up.x, y: -up.z * up.y, z: 1 - up.z * up.z }) ?? normalized({ x: -Math.sign(up.z), y: 0, z: 0 });
325
+ const level = normalized({ x: forward.x - vertical * up.x, y: forward.y - vertical * up.y, z: forward.z - vertical * up.z });
326
+ if (north && level) {
327
+ const east = cross(north, up);
328
+ const heading = Math.atan2(dot(level, east), dot(level, north)) * DEGREES;
329
+ metrics.heading = heading < 0 ? heading + 360 : heading;
330
+ }
331
+ const drop = metrics.altitude ?? height;
332
+ const below = { x: position.x - drop * up.x, y: position.y - drop * up.y, z: position.z - drop * up.z };
333
+ const distance = options.targetDistance ?? raySphereDistance(position, forward, cartesian3.length(below));
334
+ if (distance !== void 0 && Number.isFinite(distance) && distance > 0) {
335
+ metrics.targetDistance = distance;
336
+ const perPixel = metresPerPixel(camera, distance, options.fallback);
337
+ if (perPixel > 0) metrics.metresPerPixel = perPixel;
338
+ }
339
+ return metrics;
340
+ }
341
+
342
+ // src/spatial/ecef.ts
343
+ var DEFAULT_VIEWPORT_HEIGHT = 1080;
344
+ var DEFAULT_VERTICAL_FOV_RADIANS = Math.PI / 3;
345
+ var EcefSpatialMetric = class {
346
+ system;
347
+ horizonCulling;
348
+ horizon;
349
+ /** Lowest terrain measured on any tile so far, over the reference surface, in metres. */
350
+ /** Lowest terrain measured, without the vertical scale, which may change later. */
351
+ lowestUnscaledHeight = 0;
352
+ defaultViewportHeight;
353
+ defaultVerticalFovRadians;
354
+ /** Viewport height and field of view used when a camera frame does not give them. */
355
+ projectionFallback;
356
+ utmOptions;
357
+ vertical;
358
+ /**
359
+ * Creates an ECEF spatial metric.
360
+ *
361
+ * @param options - Geodetic system and camera fallbacks.
362
+ */
363
+ constructor(options) {
364
+ if (!options?.geodeticSystem) throw new TypeError("An explicit geodetic system is required.");
365
+ this.system = options.geodeticSystem;
366
+ this.horizonCulling = options.horizonCulling ?? true;
367
+ this.horizon = options.horizon ?? "plane";
368
+ this.defaultViewportHeight = options.defaultViewportHeight ?? DEFAULT_VIEWPORT_HEIGHT;
369
+ this.defaultVerticalFovRadians = options.defaultVerticalFovRadians ?? DEFAULT_VERTICAL_FOV_RADIANS;
370
+ this.utmOptions = options.utm ?? {};
371
+ this.vertical = options.vertical;
372
+ this.projectionFallback = { viewportHeight: this.defaultViewportHeight, verticalFovRadians: this.defaultVerticalFovRadians };
373
+ if (!Number.isFinite(this.defaultViewportHeight) || this.defaultViewportHeight <= 0) {
374
+ throw new RangeError("The default viewport height must be a positive finite number.");
375
+ }
376
+ if (!Number.isFinite(this.defaultVerticalFovRadians) || this.defaultVerticalFovRadians <= 0 || this.defaultVerticalFovRadians >= Math.PI) {
377
+ throw new RangeError("The default vertical field of view must be in the interval (0, PI).");
378
+ }
379
+ }
380
+ /** Geodetic reference system used for regions and horizon culling. */
381
+ get geodeticSystem() {
382
+ return this.system;
383
+ }
384
+ /**
385
+ * Derives world-space state for a tile.
386
+ *
387
+ * Box and sphere volumes receive the accumulated tile transform. A region
388
+ * is already expressed in the tileset geodetic reference system and is not
389
+ * transformed, as required by 3D Tiles. A `SPACEXR_bounding_volume_utm`
390
+ * extent is likewise absolute: it takes precedence over any standard
391
+ * fallback volume and ignores the tile transform. Its datum
392
+ * transformation, geoid handling and margins are reported in
393
+ * `utmPlacement`. When it cannot be placed, the standard volume is used
394
+ * if present; otherwise the state has no bounds and the tile is never culled.
395
+ *
396
+ * @param context - Source tile and optional parent spatial state.
397
+ * @returns Spatial state expressed in ECEF metres.
398
+ */
399
+ derive(context) {
400
+ const unscaled = this.deriveUnscaled(context);
401
+ const state = context.heightRange ? { ...unscaled, heightRange: context.heightRange } : unscaled;
402
+ if (context.heightRange) {
403
+ const scale = this.vertical?.scale.value ?? 1;
404
+ if (scale > 0) this.lowestUnscaledHeight = Math.min(this.lowestUnscaledHeight, context.heightRange[0] / scale);
405
+ }
406
+ return this.vertical ? placeVertically(state, this.vertical, context.parent) : state;
407
+ }
408
+ deriveUnscaled(context) {
409
+ const worldTransform = matrix4.create();
410
+ matrix4.from(context.tile.transform, worldTransform);
411
+ if (context.parent) matrix4.multiply(context.parent.worldTransform, worldTransform, worldTransform);
412
+ const scale = matrix4.maximumScale(worldTransform);
413
+ const volume = context.tile.boundingVolume;
414
+ const utm = getUtmBoundingVolume(volume);
415
+ const utmBounds = utm ? boundsFromUtm(utm, this.system, this.utmOptions) : void 0;
416
+ const standardBounds = volume.box ? boundsFromBox(volume.box, worldTransform) : volume.sphere ? boundsFromSphere(volume.sphere, worldTransform) : volume.region ? boundsFromRegion(volume.region, this.system) : {};
417
+ if (utmBounds) {
418
+ const { placement, ...placedBounds } = utmBounds;
419
+ const bounds = placement.status === "placed" ? placedBounds : standardBounds;
420
+ return { worldTransform, ...bounds, geometricError: context.tile.geometricError * scale, utmPlacement: placement };
421
+ }
422
+ return {
423
+ worldTransform,
424
+ ...standardBounds,
425
+ geometricError: context.tile.geometricError * scale
426
+ };
427
+ }
428
+ /**
429
+ * Evaluates coarse clip bounds, conservative horizon culling and frustum planes.
430
+ *
431
+ * @param spatial - Derived tile state.
432
+ * @param camera - Camera expressed in ECEF metres.
433
+ * @returns `true` when the tile may contribute to the current view.
434
+ */
435
+ isVisible(spatial, camera) {
436
+ return this.isInside(spatial, camera, camera.frustumPlanes);
437
+ }
438
+ /**
439
+ * Whether a tile is inside the wider planes around the view, with the same bounds and horizon as {@link isVisible}.
440
+ *
441
+ * @param spatial - Derived tile state.
442
+ * @param camera - Camera expressed in ECEF metres.
443
+ * @returns `true` when the camera has such planes and the tile may lie inside them.
444
+ */
445
+ isInPeriphery(spatial, camera) {
446
+ return camera.peripheryFrustumPlanes !== void 0 && this.isInside(spatial, camera, camera.peripheryFrustumPlanes);
447
+ }
448
+ isInside(spatial, camera, planes) {
449
+ if (camera.clipBounds && spatial.boundingBox && !boxesIntersect(spatial.boundingBox, camera.clipBounds)) return false;
450
+ if (!spatial.boundingSphere) return true;
451
+ if (this.horizonCulling) {
452
+ const radius = this.system.ellipsoid.minimumRadius;
453
+ const hidden = this.horizon === "tile-heights" ? isSphereBeyondHorizon(
454
+ spatial.boundingSphere,
455
+ camera.position,
456
+ radius,
457
+ this.lowestUnscaledHeight * (this.vertical?.scale.value ?? 1),
458
+ spatial.heightRange
459
+ ) : isSphereBelowConservativeHorizon(spatial.boundingSphere, camera.position, radius);
460
+ if (hidden) return false;
461
+ }
462
+ if (planes?.some((plane) => sphereOutsidePlane(spatial.boundingSphere, plane))) return false;
463
+ return true;
464
+ }
465
+ /**
466
+ * Computes projected geometric error in physical pixels.
467
+ *
468
+ * Distance is measured from the camera to the enclosing sphere surface,
469
+ * not merely to its centre. This prevents premature refinement changes
470
+ * near large tiles.
471
+ *
472
+ * @param context - Camera, tile and derived spatial state.
473
+ * @returns Screen-space error in physical pixels.
474
+ */
475
+ screenSpaceError(context) {
476
+ if (context.spatial.geometricError <= 0) return 0;
477
+ const camera = context.camera;
478
+ const sphere = context.spatial.boundingSphere;
479
+ const distance = sphere ? Math.max(cartesian3.distance(camera.position, sphere.center) - sphere.radius, Number.EPSILON) : Math.max(cartesian3.length(camera.position), Number.EPSILON);
480
+ const perPixel = metresPerPixel(camera, distance, this.projectionFallback);
481
+ if (!(perPixel > 0)) return Number.POSITIVE_INFINITY;
482
+ return context.spatial.geometricError / perPixel;
483
+ }
484
+ };
485
+
486
+ export { EcefSpatialMetric, VerticalScale, boundsFromUtm, defaultHorizontalDatumResolver, describeView, ellipsoidalHeightRange, geodeticVerticalFrame, metresPerPixel, placeVertically, radialVerticalFrame, verticalDisplacement };
487
+ //# sourceMappingURL=chunk-URZDM4BH.js.map
488
+ //# sourceMappingURL=chunk-URZDM4BH.js.map