@file-viewer/renderer-3d 3.1.1 → 3.2.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 (73) hide show
  1. package/GEO3D.md +505 -0
  2. package/GEO3D_THIRD_PARTY_NOTICES.md +63 -0
  3. package/IFC.md +14 -1
  4. package/README.en.md +3 -35
  5. package/README.md +3 -35
  6. package/bin/copy-geo3d-assets.mjs +143 -0
  7. package/bin/copy-ifc-assets.mjs +52 -16
  8. package/dist/geo3d-workers/geotiff-worker.js +9 -0
  9. package/dist/geo3d-workers/las-worker.js +3858 -0
  10. package/dist/geo3d-workers/licenses/_giro3d_giro3d-LICENSE +10 -0
  11. package/dist/geo3d-workers/licenses/copc-license +21 -0
  12. package/dist/geo3d-workers/licenses/cross-fetch-LICENSE +21 -0
  13. package/dist/geo3d-workers/licenses/laz-perf-COPYING.txt +202 -0
  14. package/dist/geo3d-workers/licenses/mgrs-license.md +19 -0
  15. package/dist/geo3d-workers/licenses/ol-LICENSE.md +25 -0
  16. package/dist/geo3d-workers/licenses/proj4-LICENSE.md +29 -0
  17. package/dist/geo3d-workers/licenses/three-LICENSE +21 -0
  18. package/dist/geo3d-workers/licenses/wkt-parser-LICENSE.md +29 -0
  19. package/dist/geo3d-workers/manifest.json +203 -0
  20. package/dist/geo3d-workers/raster-licenses/_giro3d_giro3d-LICENSE +10 -0
  21. package/dist/geo3d-workers/raster-licenses/_petamoriken_float16-LICENSE +21 -0
  22. package/dist/geo3d-workers/raster-licenses/geotiff-LICENSE +22 -0
  23. package/dist/geo3d-workers/raster-licenses/lerc-LICENSE +101 -0
  24. package/dist/geo3d-workers/raster-licenses/lerc-NOTICE +23 -0
  25. package/dist/geo3d-workers/raster-licenses/pako-LICENSE +21 -0
  26. package/dist/geo3d-workers/raster-licenses/quick-lru-license +9 -0
  27. package/dist/geo3d-workers/raster-licenses/web-worker-LICENSE +201 -0
  28. package/dist/geo3d-workers/raster-licenses/xml-utils-LICENSE +121 -0
  29. package/dist/geo3d-workers/raster-licenses/zstddec-LICENSE +54 -0
  30. package/dist/geo3d-workers/texture-worker.js +1 -0
  31. package/dist/geo3d.d.ts +10 -0
  32. package/dist/geo3d.js +38 -0
  33. package/dist/geo3dArchive.d.ts +25 -0
  34. package/dist/geo3dArchive.js +393 -0
  35. package/dist/geo3dCityJson.d.ts +65 -0
  36. package/dist/geo3dCityJson.js +354 -0
  37. package/dist/geo3dCrs.d.ts +8 -0
  38. package/dist/geo3dCrs.js +18 -0
  39. package/dist/geo3dHooks.d.ts +4 -0
  40. package/dist/geo3dHooks.js +91 -0
  41. package/dist/geo3dInspect.d.ts +32 -0
  42. package/dist/geo3dInspect.js +410 -0
  43. package/dist/geo3dLasWorkers.d.ts +6 -0
  44. package/dist/geo3dLasWorkers.js +59 -0
  45. package/dist/geo3dOwnedWorkerPool.d.ts +31 -0
  46. package/dist/geo3dOwnedWorkerPool.js +209 -0
  47. package/dist/geo3dPointFactories.js +3835 -0
  48. package/dist/geo3dPointMaterial.d.ts +2 -0
  49. package/dist/geo3dPointMaterial.js +54 -0
  50. package/dist/geo3dRange.d.ts +11 -0
  51. package/dist/geo3dRange.js +151 -0
  52. package/dist/geo3dRasterFactories.js +32 -0
  53. package/dist/geo3dRasterWorkers.d.ts +14 -0
  54. package/dist/geo3dRasterWorkers.js +48 -0
  55. package/dist/geo3dRuntime.d.ts +144 -0
  56. package/dist/geo3dRuntime.js +378 -0
  57. package/dist/geo3dUrl.d.ts +1 -0
  58. package/dist/geo3dUrl.js +5 -0
  59. package/dist/ifc-import.worker.js +0 -2
  60. package/dist/ifc.d.ts +0 -9
  61. package/dist/ifc.js +0 -1
  62. package/dist/ifcRuntime.js +4 -9
  63. package/dist/ifcSettings.d.ts +0 -3
  64. package/dist/ifcSettings.js +0 -3
  65. package/dist/model.js +0 -4
  66. package/dist/occtModel.js +0 -2
  67. package/licenses/laz-perf-COPYING.txt +202 -0
  68. package/licenses/laz-perf-PROVENANCE.md +22 -0
  69. package/licenses/lerc-LICENSE +101 -0
  70. package/licenses/lerc-NOTICE +23 -0
  71. package/licenses/lerc-PROVENANCE.md +37 -0
  72. package/licenses/thatopen-components-MIT.txt +18 -0
  73. package/package.json +115 -29
@@ -0,0 +1,354 @@
1
+ import { BufferGeometry, ClampToEdgeWrapping, DoubleSide, Float32BufferAttribute, Group, Mesh, MeshBasicMaterial, MirroredRepeatWrapping, RepeatWrapping, ShapeUtils, SRGBColorSpace, Texture, Vector2, Vector3 } from 'three';
2
+ import { checkAbort, readBoundedResponse } from './geo3dRange.js';
3
+ const MAX_TEXTURES = 64;
4
+ const MAX_TEXTURE_BYTES = 16 * 1024 * 1024;
5
+ const MAX_TOTAL_TEXTURE_BYTES = 64 * 1024 * 1024;
6
+ const MAX_TEXTURE_PIXELS = 16 * 1024 * 1024;
7
+ const MAX_TOTAL_TEXTURE_PIXELS = 32 * 1024 * 1024;
8
+ const textureDisposers = new WeakMap();
9
+ const disposedGroups = new WeakSet();
10
+ const isRing = (value) => Array.isArray(value) && value.length >= 3 && value.every(Number.isInteger);
11
+ const isSurface = (value) => Array.isArray(value) && value.length > 0 && value.every(isRing);
12
+ function collectSurfaces(boundaries, textures, output, depth = 0) {
13
+ if (depth > 16)
14
+ throw new Error('CityJSON geometry nesting exceeds its limit.');
15
+ if (isSurface(boundaries)) {
16
+ if (output.length >= 100000)
17
+ throw new Error('CityJSON surface limit exceeded.');
18
+ output.push({ rings: boundaries, texture: textures });
19
+ }
20
+ else if (Array.isArray(boundaries)) {
21
+ boundaries.forEach((child, index) => collectSurfaces(child, Array.isArray(textures) ? textures[index] : undefined, output, depth + 1));
22
+ }
23
+ }
24
+ function projection(ring) {
25
+ let x = 0, y = 0, z = 0;
26
+ ring.forEach((p, i) => {
27
+ const q = ring[(i + 1) % ring.length];
28
+ x += (p.y - q.y) * (p.z + q.z);
29
+ y += (p.z - q.z) * (p.x + q.x);
30
+ z += (p.x - q.x) * (p.y + q.y);
31
+ });
32
+ if (Math.abs(x) >= Math.abs(y) && Math.abs(x) >= Math.abs(z))
33
+ return 'x';
34
+ return Math.abs(y) >= Math.abs(z) ? 'y' : 'z';
35
+ }
36
+ const project = (v, axis) => axis === 'x'
37
+ ? new Vector2(v.y, v.z)
38
+ : axis === 'y'
39
+ ? new Vector2(v.x, v.z)
40
+ : new Vector2(v.x, v.y);
41
+ const parseEpsg = (value) => {
42
+ if (!value)
43
+ return undefined;
44
+ const standard = /EPSG(?::|::|\/0\/|\/)(\d+)/i.exec(value);
45
+ if (standard)
46
+ return `EPSG:${standard[1]}`;
47
+ const marker = /epsg/i.exec(value);
48
+ const code = marker && /\d+/.exec(value.slice(marker.index + marker[0].length));
49
+ return code ? `EPSG:${code[0]}` : undefined;
50
+ };
51
+ export function parseCityJson(text) {
52
+ const value = JSON.parse(text);
53
+ if (!value ||
54
+ value.type !== 'CityJSON' ||
55
+ !value.CityObjects ||
56
+ typeof value.CityObjects !== 'object' ||
57
+ Array.isArray(value.CityObjects) ||
58
+ !Array.isArray(value.vertices)) {
59
+ throw new Error('Invalid CityJSON document.');
60
+ }
61
+ return value;
62
+ }
63
+ export function renderCityJsonDocument(document, resolveRelativeUrl = (value) => value, options = {}) {
64
+ const scale = document.transform?.scale || [1, 1, 1];
65
+ const translate = document.transform?.translate || [0, 0, 0];
66
+ if (scale.length !== 3 ||
67
+ translate.length !== 3 ||
68
+ ![...scale, ...translate].every(Number.isFinite)) {
69
+ throw new Error('Invalid CityJSON transform.');
70
+ }
71
+ if (document.vertices.length > 2000000)
72
+ throw new Error('CityJSON vertex limit exceeded.');
73
+ const vertices = document.vertices.map((v) => {
74
+ if (!Array.isArray(v) || v.length < 3 || !v.slice(0, 3).every(Number.isFinite))
75
+ throw new Error('Invalid CityJSON vertex.');
76
+ return new Vector3(v[0] * scale[0] + translate[0], v[1] * scale[1] + translate[1], v[2] * scale[2] + translate[2]);
77
+ });
78
+ const origin = vertices[0]?.clone() || new Vector3();
79
+ const buckets = new Map();
80
+ let triangleCount = 0, objectCount = 0;
81
+ for (const city of Object.values(document.CityObjects)) {
82
+ let contributed = false;
83
+ for (const geometry of city.geometry || []) {
84
+ const themes = geometry.texture || {};
85
+ const theme = options.textureTheme ||
86
+ document.appearance?.['default-theme-texture'] ||
87
+ Object.keys(themes)[0] ||
88
+ '';
89
+ if (options.textureTheme && Object.keys(themes).length && !themes[theme])
90
+ throw new Error(`CityJSON texture theme not found: ${theme}`);
91
+ const surfaces = [];
92
+ collectSurfaces(geometry.boundaries, themes[theme]?.values, surfaces);
93
+ for (const surface of surfaces) {
94
+ const mapping = Array.isArray(surface.texture) ? surface.texture : [];
95
+ const first = Array.isArray(mapping[0]) ? mapping[0][0] : null;
96
+ const textureId = first === null || first === undefined ? -1 : first;
97
+ if (!Number.isInteger(textureId) ||
98
+ textureId < -1 ||
99
+ (textureId >= 0 && !document.appearance?.textures?.[textureId]))
100
+ throw new Error('Invalid CityJSON texture index.');
101
+ const vectors = [], texcoords = [];
102
+ surface.rings.forEach((indices, ringIndex) => {
103
+ const mapped = mapping[ringIndex];
104
+ if (textureId >= 0 &&
105
+ (!Array.isArray(mapped) ||
106
+ mapped[0] !== textureId ||
107
+ mapped.length !== indices.length + 1)) {
108
+ throw new Error('CityJSON texture ring does not match its geometry.');
109
+ }
110
+ const ring = indices.map((index) => {
111
+ if (index < 0 || !vertices[index])
112
+ throw new Error('Invalid CityJSON vertex index.');
113
+ return vertices[index];
114
+ });
115
+ const uv = textureId < 0
116
+ ? []
117
+ : indices.map((_, i) => {
118
+ const index = mapped[i + 1];
119
+ const value = document.appearance?.['vertices-texture']?.[index];
120
+ if (!Number.isInteger(index) ||
121
+ index < 0 ||
122
+ !value ||
123
+ value.length !== 2 ||
124
+ !value.every(Number.isFinite)) {
125
+ throw new Error('Invalid CityJSON texture coordinate.');
126
+ }
127
+ return new Vector2(value[0], value[1]);
128
+ });
129
+ if (ring.length > 3 && ring[0].equals(ring[ring.length - 1])) {
130
+ ring.pop();
131
+ uv.pop();
132
+ }
133
+ vectors.push(ring);
134
+ texcoords.push(uv);
135
+ });
136
+ const axis = projection(vectors[0]), flat = vectors.flat(), flatUv = texcoords.flat();
137
+ const triangles = ShapeUtils.triangulateShape(vectors[0].map((v) => project(v, axis)), vectors.slice(1).map((ring) => ring.map((v) => project(v, axis))));
138
+ let bucket = buckets.get(textureId);
139
+ if (!bucket) {
140
+ bucket = { positions: [], uv: [] };
141
+ buckets.set(textureId, bucket);
142
+ }
143
+ for (const triangle of triangles) {
144
+ if (++triangleCount > 2000000)
145
+ throw new Error('CityJSON triangle limit exceeded.');
146
+ for (const index of triangle) {
147
+ const v = flat[index];
148
+ bucket.positions.push(v.x - origin.x, v.y - origin.y, v.z - origin.z);
149
+ if (textureId >= 0)
150
+ bucket.uv.push(flatUv[index].x, flatUv[index].y);
151
+ }
152
+ contributed = true;
153
+ }
154
+ }
155
+ }
156
+ if (contributed)
157
+ objectCount++;
158
+ }
159
+ if (!triangleCount)
160
+ throw new Error('CityJSON contains no renderable surface geometry.');
161
+ if (buckets.size > MAX_TEXTURES + 1)
162
+ throw new Error('CityJSON texture count exceeds its limit.');
163
+ const group = new Group(), textureBindings = [];
164
+ group.name = 'file-viewer-cityjson-root';
165
+ group.position.copy(origin);
166
+ try {
167
+ for (const [index, bucket] of buckets) {
168
+ if (!bucket.positions.length)
169
+ continue;
170
+ const geometry = new BufferGeometry();
171
+ geometry.setAttribute('position', new Float32BufferAttribute(bucket.positions, 3));
172
+ if (index >= 0)
173
+ geometry.setAttribute('uv', new Float32BufferAttribute(bucket.uv, 2));
174
+ geometry.computeVertexNormals();
175
+ geometry.computeBoundingBox();
176
+ geometry.computeBoundingSphere();
177
+ const material = new MeshBasicMaterial({
178
+ color: index < 0 ? (options.materialColor ?? 0xb8c4d2) : 0xffffff,
179
+ side: DoubleSide
180
+ });
181
+ const mesh = new Mesh(geometry, material);
182
+ mesh.name = 'file-viewer-cityjson';
183
+ group.add(mesh);
184
+ if (index >= 0) {
185
+ const definition = document.appearance.textures[index];
186
+ if (typeof definition.image !== 'string' || !definition.image)
187
+ throw new Error('CityJSON texture image is missing.');
188
+ const wrapMode = definition.wrapMode || 'none';
189
+ if (!['none', 'wrap', 'mirror', 'clamp'].includes(wrapMode))
190
+ throw new Error(`Unsupported CityJSON texture wrap mode: ${wrapMode}`);
191
+ textureBindings.push({
192
+ material,
193
+ resource: { source: definition.image, url: resolveRelativeUrl(definition.image) },
194
+ wrapMode
195
+ });
196
+ }
197
+ }
198
+ }
199
+ catch (error) {
200
+ disposeCityJsonGroup(group);
201
+ throw error;
202
+ }
203
+ const externalResources = (document.appearance?.textures || [])
204
+ .map((t) => t.image)
205
+ .filter((value) => typeof value === 'string' && value.length > 0)
206
+ .map((source) => ({ source, url: resolveRelativeUrl(source) }));
207
+ return {
208
+ group,
209
+ crs: parseEpsg(document.metadata?.referenceSystem),
210
+ triangleCount,
211
+ objectCount,
212
+ externalResources,
213
+ textureBindings
214
+ };
215
+ }
216
+ export function cityJsonTextureSize(data) {
217
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
218
+ if (data.length >= 33 &&
219
+ [137, 80, 78, 71, 13, 10, 26, 10].every((v, i) => data[i] === v) &&
220
+ view.getUint32(8) === 13 &&
221
+ view.getUint32(12) === 0x49484452) {
222
+ return { width: view.getUint32(16), height: view.getUint32(20), mime: 'image/png' };
223
+ }
224
+ if (data.length >= 4 && data[0] === 255 && data[1] === 216) {
225
+ let p = 2;
226
+ while (p < data.length) {
227
+ if (data[p++] !== 255)
228
+ break;
229
+ while (data[p] === 255)
230
+ p++;
231
+ const marker = data[p++];
232
+ if (marker === 0xda || marker === 0xd9)
233
+ break;
234
+ if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7))
235
+ continue;
236
+ if (p + 2 > data.length)
237
+ break;
238
+ const length = view.getUint16(p);
239
+ if (length < 2 || p + length > data.length)
240
+ break;
241
+ if ([0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf].includes(marker) &&
242
+ length >= 8) {
243
+ return { width: view.getUint16(p + 5), height: view.getUint16(p + 3), mime: 'image/jpeg' };
244
+ }
245
+ p += length;
246
+ }
247
+ }
248
+ throw new Error('CityJSON textures must contain a valid PNG or JPEG header.');
249
+ }
250
+ export async function renderCityJsonWithTextures(document, resolveRelativeUrl, options = {}, datasetUrl, signal) {
251
+ checkAbort(signal);
252
+ const result = renderCityJsonDocument(document, resolveRelativeUrl, options);
253
+ const owned = [];
254
+ textureDisposers.set(result.group, () => {
255
+ for (const { texture, bitmap } of owned.splice(0)) {
256
+ try {
257
+ texture.dispose();
258
+ }
259
+ catch {
260
+ }
261
+ try {
262
+ bitmap.close();
263
+ }
264
+ catch {
265
+ }
266
+ }
267
+ });
268
+ let totalBytes = 0, totalPixels = 0;
269
+ try {
270
+ for (const binding of result.textureBindings) {
271
+ checkAbort(signal);
272
+ if (!datasetUrl)
273
+ throw new Error('CityJSON textures require a dataset URL for relative resource resolution.');
274
+ const url = new URL(binding.resource.url, datasetUrl), base = new URL(datasetUrl);
275
+ if (!['http:', 'https:'].includes(url.protocol) ||
276
+ url.username ||
277
+ url.password ||
278
+ url.origin !== base.origin) {
279
+ throw new Error('CityJSON texture must be an HTTP(S) resource on the dataset origin.');
280
+ }
281
+ const response = await fetch(url.href, { signal, credentials: 'omit', redirect: 'error' });
282
+ if (!response.ok) {
283
+ await response.body?.cancel();
284
+ throw new Error(`CityJSON texture failed: HTTP ${response.status}.`);
285
+ }
286
+ const data = await readBoundedResponse(response, Math.min(MAX_TEXTURE_BYTES, MAX_TOTAL_TEXTURE_BYTES - totalBytes), signal);
287
+ totalBytes += data.length;
288
+ const { width, height, mime } = cityJsonTextureSize(data);
289
+ totalPixels += width * height;
290
+ if (!width ||
291
+ !height ||
292
+ width > 8192 ||
293
+ height > 8192 ||
294
+ width * height > MAX_TEXTURE_PIXELS ||
295
+ totalPixels > MAX_TOTAL_TEXTURE_PIXELS) {
296
+ throw new Error('CityJSON texture dimensions exceed the decoded pixel limit.');
297
+ }
298
+ const bitmap = await createImageBitmap(new Blob([data.slice().buffer], { type: mime }), {
299
+ imageOrientation: 'flipY',
300
+ premultiplyAlpha: 'none'
301
+ });
302
+ if (signal?.aborted) {
303
+ bitmap.close();
304
+ checkAbort(signal);
305
+ }
306
+ if (bitmap.width !== width || bitmap.height !== height) {
307
+ bitmap.close();
308
+ throw new Error('CityJSON texture dimensions changed during decoding.');
309
+ }
310
+ const texture = new Texture(bitmap);
311
+ owned.push({ texture, bitmap });
312
+ texture.colorSpace = SRGBColorSpace;
313
+ texture.flipY = false;
314
+ texture.wrapS = texture.wrapT =
315
+ binding.wrapMode === 'wrap'
316
+ ? RepeatWrapping
317
+ : binding.wrapMode === 'mirror'
318
+ ? MirroredRepeatWrapping
319
+ : ClampToEdgeWrapping;
320
+ texture.needsUpdate = true;
321
+ binding.material.map = texture;
322
+ binding.material.needsUpdate = true;
323
+ }
324
+ checkAbort(signal);
325
+ return result;
326
+ }
327
+ catch (error) {
328
+ disposeCityJsonGroup(result.group);
329
+ throw error;
330
+ }
331
+ }
332
+ export function disposeCityJsonGroup(group) {
333
+ if (disposedGroups.has(group))
334
+ return;
335
+ disposedGroups.add(group);
336
+ textureDisposers.get(group)?.();
337
+ textureDisposers.delete(group);
338
+ group.traverse((object) => {
339
+ if (!(object instanceof Mesh))
340
+ return;
341
+ try {
342
+ object.geometry.dispose();
343
+ }
344
+ catch {
345
+ }
346
+ for (const material of Array.isArray(object.material) ? object.material : [object.material]) {
347
+ try {
348
+ material.dispose();
349
+ }
350
+ catch {
351
+ }
352
+ }
353
+ });
354
+ }
@@ -0,0 +1,8 @@
1
+ import type * as CoordinateSystemModule from '@giro3d/giro3d/core/geographic/CoordinateSystem.js';
2
+ type CoordinateSystem = CoordinateSystemModule.default;
3
+ export type Geo3dCrsInput = `EPSG:${number}` | {
4
+ id: string;
5
+ definition: string;
6
+ };
7
+ export declare function resolveGeo3dCrs(input?: Geo3dCrsInput | string, fallback?: CoordinateSystem): Promise<CoordinateSystem>;
8
+ export {};
@@ -0,0 +1,18 @@
1
+ export async function resolveGeo3dCrs(input, fallback) {
2
+ const { default: CRS } = await import('@giro3d/giro3d/core/geographic/CoordinateSystem.js');
3
+ if (!input)
4
+ return fallback || CRS.unknown;
5
+ if (typeof input === 'object')
6
+ return CRS.register(input.id, input.definition, { throwIfFailedToRegisterWithProj: true });
7
+ try {
8
+ const known = CRS.get(input);
9
+ if (known)
10
+ return known;
11
+ }
12
+ catch { }
13
+ const match = /^EPSG:(326|327)(\d{2})$/.exec(input);
14
+ if (match && Number(match[2]) >= 1 && Number(match[2]) <= 60) {
15
+ return CRS.register(input, `+proj=utm +zone=${Number(match[2])}${match[1] === '327' ? ' +south' : ''} +datum=WGS84 +units=m +no_defs`, { throwIfFailedToRegisterWithProj: true });
16
+ }
17
+ throw new Error(`Unknown Geo3D CRS ${input}. Register its offline definition with crsDefinitions; coordinates are not silently relabelled.`);
18
+ }
@@ -0,0 +1,4 @@
1
+ export type Geo3dHookCleanup = () => void | Promise<void>;
2
+ export type Geo3dHookResult = void | Geo3dHookCleanup;
3
+ export declare function reportGeo3dExtensionError(error: unknown, observer?: (error: unknown) => void): void;
4
+ export declare function runGeo3dHook(hook: () => Geo3dHookResult | Promise<Geo3dHookResult>, signal: AbortSignal, retain: (cleanup: Geo3dHookCleanup) => void, onExtensionError?: (error: unknown) => void): Promise<void>;
@@ -0,0 +1,91 @@
1
+ export function reportGeo3dExtensionError(error, observer) {
2
+ const report = (value) => {
3
+ if (typeof globalThis.reportError === 'function')
4
+ globalThis.reportError(value);
5
+ else
6
+ console.error('Geo3D extension failed after cancellation:', value);
7
+ };
8
+ if (!observer) {
9
+ report(error);
10
+ return;
11
+ }
12
+ try {
13
+ observer(error);
14
+ }
15
+ catch (observerError) {
16
+ report(new AggregateError([error, observerError], 'Geo3D extension error observer failed'));
17
+ }
18
+ }
19
+ export function runGeo3dHook(hook, signal, retain, onExtensionError) {
20
+ if (signal.aborted)
21
+ return Promise.reject(signal.reason);
22
+ let cleanup;
23
+ let released = false;
24
+ const report = (error) => reportGeo3dExtensionError(error, onExtensionError);
25
+ const runCleanup = () => {
26
+ const current = cleanup;
27
+ cleanup = undefined;
28
+ if (!current)
29
+ return;
30
+ try {
31
+ return Promise.resolve(current()).catch(report);
32
+ }
33
+ catch (error) {
34
+ report(error);
35
+ }
36
+ };
37
+ retain(() => {
38
+ if (released)
39
+ return;
40
+ released = true;
41
+ return runCleanup();
42
+ });
43
+ return new Promise((resolve, reject) => {
44
+ let settled = false;
45
+ const remove = () => signal.removeEventListener('abort', abort);
46
+ const abort = () => {
47
+ if (settled)
48
+ return;
49
+ settled = true;
50
+ remove();
51
+ reject(signal.reason);
52
+ };
53
+ const fail = (error) => {
54
+ if (settled) {
55
+ if (error !== signal.reason)
56
+ report(error);
57
+ return;
58
+ }
59
+ settled = true;
60
+ remove();
61
+ reject(error);
62
+ };
63
+ const accept = (value) => {
64
+ if (value !== undefined && typeof value !== 'function') {
65
+ fail(new TypeError('Geo3D extension hook must return a cleanup function or undefined'));
66
+ return;
67
+ }
68
+ cleanup = value || undefined;
69
+ if (released)
70
+ void runCleanup();
71
+ if (!settled) {
72
+ settled = true;
73
+ remove();
74
+ resolve();
75
+ }
76
+ };
77
+ signal.addEventListener('abort', abort, { once: true });
78
+ if (signal.aborted)
79
+ abort();
80
+ queueMicrotask(() => {
81
+ if (signal.aborted)
82
+ return;
83
+ try {
84
+ void Promise.resolve(hook()).then(accept, fail);
85
+ }
86
+ catch (error) {
87
+ fail(error);
88
+ }
89
+ });
90
+ });
91
+ }
@@ -0,0 +1,32 @@
1
+ import type { RendererSourceTypeProbeInput } from '@file-viewer/core';
2
+ export type Geo3dDatasetFormat = 'copc' | 'las' | 'laz' | 'geotiff' | 'cog' | 'cityjson' | '3d-tiles' | '3tz';
3
+ export interface Geo3dDatasetInspection {
4
+ format: Geo3dDatasetFormat;
5
+ confidence: 'high' | 'medium';
6
+ reason: string;
7
+ }
8
+ export interface GeoTiffInspection {
9
+ type: 'geotiff';
10
+ isCog: boolean | 'unknown';
11
+ crs?: string;
12
+ bbox?: [number, number, number, number];
13
+ width?: number;
14
+ height?: number;
15
+ bands?: number;
16
+ tiled: boolean;
17
+ overviewCount: number;
18
+ geoTags: readonly number[];
19
+ }
20
+ export type Geo3dRangeGetter = (begin: number, end: number) => Promise<Uint8Array>;
21
+ export declare const createGeo3dProbeRangeGetter: (input: Pick<RendererSourceTypeProbeInput, "url" | "file" | "buffer" | "signal">) => Geo3dRangeGetter;
22
+ export declare function isCopcLasBuffer(buffer: ArrayBuffer): boolean;
23
+ export declare function isCopcRangeSource(getter: Geo3dRangeGetter): Promise<boolean>;
24
+ export declare function inspectGeoTiffRangeSource(getter: Geo3dRangeGetter): Promise<GeoTiffInspection | null>;
25
+ export declare const inspectGeoTiffBuffer: (buffer: ArrayBuffer) => Promise<GeoTiffInspection | null>;
26
+ export declare function isCityJsonBuffer(buffer: ArrayBuffer): boolean;
27
+ export declare function is3dTilesJsonBuffer(buffer: ArrayBuffer): boolean;
28
+ export declare function resolveGeo3dSourceType(input: RendererSourceTypeProbeInput): Promise<string | false>;
29
+ export declare function inspectGeo3dDataset(input: {
30
+ filename?: string;
31
+ buffer?: ArrayBuffer;
32
+ }): Geo3dDatasetInspection | null;