@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,14 @@
1
+ import { Geo3dOwnedWorkerPool } from './geo3dOwnedWorkerPool.js';
2
+ export interface Geo3dRasterDecoder {
3
+ bindParameters(compression: number, decoderParameters: unknown): {
4
+ decode(buffer: ArrayBuffer): Promise<ArrayBuffer>;
5
+ };
6
+ }
7
+ export interface Geo3dRasterWorkers {
8
+ readonly signal: AbortSignal;
9
+ readonly decoder: Geo3dRasterDecoder;
10
+ readonly texture: Geo3dOwnedWorkerPool;
11
+ combineSignal(signal?: AbortSignal): AbortSignal;
12
+ dispose(): void;
13
+ }
14
+ export declare function createGeo3dRasterWorkers(assetBaseUrl: string, signal: AbortSignal): Geo3dRasterWorkers;
@@ -0,0 +1,48 @@
1
+ import { Geo3dOwnedWorkerPool } from './geo3dOwnedWorkerPool.js';
2
+ export function createGeo3dRasterWorkers(assetBaseUrl, signal) {
3
+ const controller = new AbortController();
4
+ const base = new URL(assetBaseUrl, document.baseURI);
5
+ const makePool = (name) => new Geo3dOwnedWorkerPool({
6
+ signal: controller.signal,
7
+ concurrency: 2,
8
+ maxQueued: 128,
9
+ createWorker: () => ({
10
+ worker: new Worker(new URL(`workers/${name}-worker.js`, base), {
11
+ type: 'module', name: `file-viewer-${name}`,
12
+ }),
13
+ }),
14
+ });
15
+ const decoder = makePool('geotiff');
16
+ const texture = makePool('texture');
17
+ let disposed = false;
18
+ const onAbort = () => dispose();
19
+ function dispose() {
20
+ if (disposed)
21
+ return;
22
+ disposed = true;
23
+ signal.removeEventListener('abort', onAbort);
24
+ controller.abort(signal.reason ?? new DOMException('Geo3D raster source disposed.', 'AbortError'));
25
+ decoder.dispose(controller.signal.reason);
26
+ texture.dispose(controller.signal.reason);
27
+ }
28
+ signal.addEventListener('abort', onAbort, { once: true });
29
+ if (signal.aborted)
30
+ dispose();
31
+ return {
32
+ signal: controller.signal,
33
+ decoder: {
34
+ bindParameters(compression, decoderParameters) {
35
+ return {
36
+ decode(buffer) {
37
+ return decoder.queue('DecodeRaster', { compression, decoderParameters, buffer }, [buffer]);
38
+ },
39
+ };
40
+ },
41
+ },
42
+ texture,
43
+ combineSignal(requestSignal) {
44
+ return requestSignal ? AbortSignal.any([controller.signal, requestSignal]) : controller.signal;
45
+ },
46
+ dispose,
47
+ };
48
+ }
@@ -0,0 +1,144 @@
1
+ import type { FileRenderContext } from '@file-viewer/core';
2
+ import type * as InstanceModule from '@giro3d/giro3d/core/Instance.js';
3
+ import type * as PointCloudModule from '@giro3d/giro3d/entities/PointCloud.js';
4
+ import type * as MapModule from '@giro3d/giro3d/entities/Map.js';
5
+ import type * as Tiles3DModule from '@giro3d/giro3d/entities/Tiles3D.js';
6
+ import type * as CoordinateSystemModule from '@giro3d/giro3d/core/geographic/CoordinateSystem.js';
7
+ import type * as LASSourceModule from '@giro3d/giro3d/sources/LASSource.js';
8
+ import type * as COPCSourceModule from '@giro3d/giro3d/sources/COPCSource.js';
9
+ import type * as GeoTIFFSourceModule from '@giro3d/giro3d/sources/GeoTIFFSource.js';
10
+ import type * as ColorLayerModule from '@giro3d/giro3d/core/layer/ColorLayer.js';
11
+ import type { PointCloudBatchTableAttributeMapping } from '@giro3d/giro3d/entities/Tiles3D.js';
12
+ import { type Geo3dDatasetFormat, type GeoTiffInspection } from './geo3dInspect.js';
13
+ import { renderCityJsonDocument } from './geo3dCityJson.js';
14
+ import { type Geo3d3tzLimits } from './geo3dArchive.js';
15
+ import { type Geo3dCrsInput } from './geo3dCrs.js';
16
+ import { type Geo3dHookResult } from './geo3dHooks.js';
17
+ type Instance = InstanceModule.default;
18
+ type PointCloud = PointCloudModule.default;
19
+ type GiroMap = MapModule.default;
20
+ type Tiles3D = Tiles3DModule.default;
21
+ type CoordinateSystem = CoordinateSystemModule.default;
22
+ type LASSource = LASSourceModule.default;
23
+ type COPCSource = COPCSourceModule.default;
24
+ type GeoTIFFSource = GeoTIFFSourceModule.default;
25
+ type ColorLayer = ColorLayerModule.default;
26
+ export type { Geo3dCrsInput } from './geo3dCrs.js';
27
+ export interface Geo3dCopcOptions {
28
+ enableWorkers?: boolean;
29
+ decimate?: number;
30
+ compressColorsTo8Bit?: boolean;
31
+ pointSize?: number;
32
+ subdivisionThreshold?: number;
33
+ }
34
+ export interface Geo3dLasOptions extends Geo3dCopcOptions {
35
+ }
36
+ export interface Geo3dTilesOptions {
37
+ errorTarget?: number;
38
+ pointCloudAttributeMapping?: PointCloudBatchTableAttributeMapping;
39
+ pointSize?: number;
40
+ enableFetchPlugin?: boolean;
41
+ }
42
+ export interface Geo3dGeoTiffOptions {
43
+ channels?: [number] | [number, number, number] | [number, number, number, number];
44
+ enableWorkers?: boolean;
45
+ flipY?: boolean;
46
+ httpTimeout?: number;
47
+ is8bit?: boolean;
48
+ transparent?: boolean;
49
+ }
50
+ export interface Geo3dCityJsonOptions {
51
+ materialColor?: number | string;
52
+ textureTheme?: string;
53
+ }
54
+ export interface Geo3dGiroOptions {
55
+ instance?: {
56
+ crs?: Geo3dCrsInput;
57
+ backgroundColor?: string | number | null;
58
+ logarithmicDepthBuffer?: boolean;
59
+ };
60
+ view?: {
61
+ fitToDataset?: boolean;
62
+ controls?: boolean;
63
+ };
64
+ sources?: {
65
+ copc?: Geo3dCopcOptions;
66
+ las?: Geo3dLasOptions;
67
+ geotiff?: Geo3dGeoTiffOptions;
68
+ cog?: Geo3dGeoTiffOptions;
69
+ cityjson?: Geo3dCityJsonOptions;
70
+ '3d-tiles'?: Geo3dTilesOptions;
71
+ };
72
+ }
73
+ export interface Geo3dDatasetSource {
74
+ format: Geo3dDatasetFormat;
75
+ filename: string;
76
+ url?: string;
77
+ file?: File | Blob;
78
+ buffer?: ArrayBuffer;
79
+ resolveRelativeUrl(reference: string): string;
80
+ }
81
+ interface Geo3dMetadataLike {
82
+ crs?: CoordinateSystem | string;
83
+ triangleCount?: number;
84
+ objectCount?: number;
85
+ externalResources?: Array<{
86
+ source: string;
87
+ url: string;
88
+ }>;
89
+ }
90
+ type Geo3dEntityBinding = {
91
+ format: 'copc';
92
+ entity: PointCloud;
93
+ readonly nativeSource: COPCSource;
94
+ readonly colorLayer: null;
95
+ } | {
96
+ format: 'las' | 'laz';
97
+ entity: PointCloud;
98
+ readonly nativeSource: LASSource;
99
+ readonly colorLayer: null;
100
+ } | {
101
+ format: 'geotiff' | 'cog';
102
+ entity: GiroMap;
103
+ readonly nativeSource: GeoTIFFSource;
104
+ readonly colorLayer: ColorLayer;
105
+ } | {
106
+ format: '3d-tiles' | '3tz';
107
+ entity: Tiles3D;
108
+ readonly nativeSource: null;
109
+ readonly colorLayer: null;
110
+ } | {
111
+ format: 'cityjson';
112
+ entity: ReturnType<typeof renderCityJsonDocument>['group'];
113
+ readonly nativeSource: null;
114
+ readonly colorLayer: null;
115
+ };
116
+ export interface Geo3dRuntimeContext {
117
+ instance: Instance;
118
+ source: Geo3dDatasetSource;
119
+ metadata: Geo3dMetadataLike | GeoTiffInspection | null;
120
+ format: Geo3dDatasetFormat;
121
+ signal: AbortSignal;
122
+ }
123
+ export type Geo3dExtensionContext = Geo3dRuntimeContext & Geo3dEntityBinding & {
124
+ fitToDataset(): void;
125
+ };
126
+ export interface Geo3dViewerOptions {
127
+ assetBaseUrl?: string | URL;
128
+ maxLasBytes?: number;
129
+ maxCityJsonBytes?: number;
130
+ max3tzBytes?: number;
131
+ crsDefinitions?: Record<string, string>;
132
+ archive?: Geo3d3tzLimits;
133
+ giro3d?: Geo3dGiroOptions;
134
+ configureInstance?: (context: Geo3dRuntimeContext) => Geo3dHookResult | Promise<Geo3dHookResult>;
135
+ configure?: (context: Geo3dExtensionContext) => Geo3dHookResult | Promise<Geo3dHookResult>;
136
+ onExtensionError?: (error: unknown) => void;
137
+ }
138
+ export type Geo3dViewerInstance = {
139
+ $el: HTMLElement;
140
+ instance: Instance;
141
+ fitToDataset(): void;
142
+ unmount(): Promise<void>;
143
+ } & Geo3dEntityBinding;
144
+ export declare function renderGeo3d(buffer: ArrayBuffer, target: HTMLDivElement, type?: string, context?: FileRenderContext, options?: Geo3dViewerOptions): Promise<Geo3dViewerInstance>;
@@ -0,0 +1,378 @@
1
+ import { createGeo3dProbeRangeGetter, inspectGeo3dDataset, inspectGeoTiffRangeSource, isCopcRangeSource } from './geo3dInspect.js';
2
+ import { disposeCityJsonGroup, parseCityJson, renderCityJsonDocument, renderCityJsonWithTextures } from './geo3dCityJson.js';
3
+ import { prepare3tzDataset } from './geo3dArchive.js';
4
+ import { byteLimit, checkAbort, createRangeGetter, readBoundedResponse } from './geo3dRange.js';
5
+ import { resolveGeo3dCrs } from './geo3dCrs.js';
6
+ import { createGeo3dLasWorkers } from './geo3dLasWorkers.js';
7
+ import { createGeo3dRasterWorkers } from './geo3dRasterWorkers.js';
8
+ import { runGeo3dHook } from './geo3dHooks.js';
9
+ import { repairGeo3dPointMaterial } from './geo3dPointMaterial.js';
10
+ import { resolveGeo3dDatasetUrl } from './geo3dUrl.js';
11
+ const DEFAULT_MAX_LAS_BYTES = 512 * 1024 * 1024, DEFAULT_MAX_CITYJSON_BYTES = 64 * 1024 * 1024, DEFAULT_MAX_3TZ_BYTES = 512 * 1024 * 1024;
12
+ const resolveAssetBaseUrl = (value) => {
13
+ const raw = value?.toString() || '/file-viewer/vendor/geo3d/';
14
+ return raw.endsWith('/') ? raw : `${raw}/`;
15
+ };
16
+ async function whole(source, max, signal) {
17
+ byteLimit(max);
18
+ checkAbort(signal);
19
+ if (source.buffer) {
20
+ if (source.buffer.byteLength > max)
21
+ throw new Error('Geo3D whole-file input exceeds its byte limit.');
22
+ return new Uint8Array(source.buffer);
23
+ }
24
+ if (source.file) {
25
+ if (source.file.size > max)
26
+ throw new Error('Geo3D whole-file input exceeds its byte limit.');
27
+ const bytes = new Uint8Array(await source.file.arrayBuffer());
28
+ checkAbort(signal);
29
+ return bytes;
30
+ }
31
+ if (!source.url)
32
+ throw new Error('Geo3D source has no readable input.');
33
+ const response = await fetch(source.url, { signal });
34
+ if (!response.ok) {
35
+ await response.body?.cancel();
36
+ throw new Error(`Geo3D source download failed: HTTP ${response.status}.`);
37
+ }
38
+ return readBoundedResponse(response, max, signal);
39
+ }
40
+ function normalizeType(type) {
41
+ if (type === '3dtiles' || type === '3d-tiles')
42
+ return '3d-tiles';
43
+ return ['copc', 'las', 'laz', 'geotiff', 'cog', 'cityjson', '3tz'].includes(type || '')
44
+ ? type
45
+ : undefined;
46
+ }
47
+ async function createInstance(target, crs, options) {
48
+ const { default: Instance } = await import('@giro3d/giro3d/core/Instance.js');
49
+ return new Instance({
50
+ target,
51
+ crs,
52
+ backgroundColor: options.giro3d?.instance?.backgroundColor ?? null,
53
+ renderer: options.giro3d?.instance?.logarithmicDepthBuffer === undefined
54
+ ? undefined
55
+ : { logarithmicDepthBuffer: options.giro3d.instance.logarithmicDepthBuffer }
56
+ });
57
+ }
58
+ async function createControls(instance, enabled) {
59
+ if (!enabled)
60
+ return null;
61
+ const { default: FirstPersonControls } = await import('@giro3d/giro3d/controls/FirstPersonControls.js');
62
+ const controls = new FirstPersonControls(instance, {
63
+ focusOnMouseOver: true
64
+ });
65
+ controls.reset?.();
66
+ return controls;
67
+ }
68
+ export async function renderGeo3d(buffer, target, type, context, options = {}) {
69
+ const hint = normalizeType(type?.toLowerCase()), inspection = hint
70
+ ? { format: hint }
71
+ : inspectGeo3dDataset({
72
+ filename: context?.filename,
73
+ buffer: buffer.byteLength ? buffer : undefined
74
+ });
75
+ if (!inspection)
76
+ throw new Error('Unsupported Geo3D dataset.');
77
+ const controller = new AbortController(), signal = controller.signal;
78
+ let cleanupPromise, loaded = false, destroyed = false;
79
+ let instance = null, entity = null, controls = null, sourceObject = null;
80
+ let colorLayer = null;
81
+ let stopPointRequests;
82
+ let cityObject = null;
83
+ const owned = [], hooks = [];
84
+ let archiveDataset;
85
+ let metadata = null;
86
+ let format = inspection.format;
87
+ const originalUrl = resolveGeo3dDatasetUrl(context?.streamUrl || context?.url, target.ownerDocument.baseURI);
88
+ let source = {
89
+ format,
90
+ filename: context?.filename || 'dataset',
91
+ url: originalUrl,
92
+ file: context?.sourceFile,
93
+ buffer: buffer.byteLength ? buffer : undefined,
94
+ resolveRelativeUrl(reference) {
95
+ return originalUrl ? new URL(reference, originalUrl).href : reference;
96
+ }
97
+ };
98
+ const cleanup = () => {
99
+ if (cleanupPromise)
100
+ return cleanupPromise;
101
+ destroyed = true;
102
+ cleanupPromise = Promise.resolve().then(async () => {
103
+ const tasks = [
104
+ ...hooks.reverse(),
105
+ () => instance?.view.setControls(null),
106
+ () => controls?.dispose?.(),
107
+ () => {
108
+ if (cityObject)
109
+ disposeCityJsonGroup(cityObject);
110
+ },
111
+ () => instance?.dispose(),
112
+ () => sourceObject?.dispose?.(),
113
+ ...owned.reverse()
114
+ ];
115
+ for (const dispose of tasks) {
116
+ try {
117
+ await dispose();
118
+ }
119
+ catch {
120
+ }
121
+ }
122
+ target.replaceChildren();
123
+ });
124
+ context?.signal?.removeEventListener('abort', abort);
125
+ try {
126
+ stopPointRequests?.();
127
+ }
128
+ catch {
129
+ }
130
+ controller.abort(new DOMException('Geo3D viewer disposed.', 'AbortError'));
131
+ return cleanupPromise;
132
+ };
133
+ const abort = () => {
134
+ try {
135
+ stopPointRequests?.();
136
+ }
137
+ catch {
138
+ }
139
+ controller.abort(context?.signal?.reason);
140
+ if (loaded)
141
+ void cleanup();
142
+ };
143
+ context?.signal?.addEventListener('abort', abort, { once: true });
144
+ if (context?.signal?.aborted)
145
+ abort();
146
+ const before = async (crs) => {
147
+ checkAbort(signal);
148
+ instance = await createInstance(target, crs, options);
149
+ checkAbort(signal);
150
+ controls = await createControls(instance, options.giro3d?.view?.controls !== false);
151
+ checkAbort(signal);
152
+ const runtimeContext = { instance, source, metadata, format, signal };
153
+ if (options.configureInstance)
154
+ await runGeo3dHook(() => options.configureInstance(runtimeContext), signal, (dispose) => hooks.push(dispose), options.onExtensionError);
155
+ checkAbort(signal);
156
+ return instance;
157
+ };
158
+ try {
159
+ checkAbort(signal);
160
+ const maxLasBytes = byteLimit(options.maxLasBytes ?? DEFAULT_MAX_LAS_BYTES, 'maxLasBytes');
161
+ const maxCityJsonBytes = byteLimit(options.maxCityJsonBytes ?? DEFAULT_MAX_CITYJSON_BYTES, 'maxCityJsonBytes');
162
+ const max3tzBytes = byteLimit(options.max3tzBytes ?? DEFAULT_MAX_3TZ_BYTES, 'max3tzBytes');
163
+ for (const [id, definition] of Object.entries(options.crsDefinitions || {}))
164
+ await resolveGeo3dCrs({ id, definition });
165
+ const instanceCrs = options.giro3d?.instance?.crs;
166
+ if (typeof instanceCrs === 'object')
167
+ await resolveGeo3dCrs(instanceCrs);
168
+ if (format === 'las' || format === 'laz') {
169
+ if (await isCopcRangeSource(createGeo3dProbeRangeGetter({ ...source, signal })))
170
+ format = 'copc';
171
+ source = { ...source, format };
172
+ }
173
+ if (format === '3tz') {
174
+ const archive = await prepare3tzDataset(await whole(source, max3tzBytes, signal), options.archive, signal);
175
+ archiveDataset = archive;
176
+ owned.push(archive.dispose);
177
+ source = { ...source, url: archive.rootUrl };
178
+ }
179
+ if (format === 'copc' || format === 'las' || format === 'laz') {
180
+ const pointOptions = format === 'copc' ? options.giro3d?.sources?.copc : options.giro3d?.sources?.las;
181
+ const workers = createGeo3dLasWorkers(resolveAssetBaseUrl(options.assetBaseUrl), signal);
182
+ owned.push(() => workers.dispose());
183
+ if (pointOptions?.enableWorkers === false) {
184
+ const { setLazPerfPath } = await import('@giro3d/giro3d/sources/las/config.js');
185
+ setLazPerfPath(`${resolveAssetBaseUrl(options.assetBaseUrl)}laz-perf/`);
186
+ }
187
+ const factories = await import('./geo3dPointFactories.js');
188
+ checkAbort(signal);
189
+ let pointSource;
190
+ if (format === 'copc') {
191
+ const input = {
192
+ url: createRangeGetter({ ...source, signal }),
193
+ enableWorkers: pointOptions?.enableWorkers,
194
+ decimate: pointOptions?.decimate,
195
+ compressColorsTo8Bit: pointOptions?.compressColorsTo8Bit
196
+ };
197
+ pointSource = factories.createCOPCSource(workers, input);
198
+ }
199
+ else {
200
+ const input = {
201
+ url: () => whole(source, maxLasBytes, signal),
202
+ enableWorkers: pointOptions?.enableWorkers,
203
+ decimate: pointOptions?.decimate,
204
+ compressColorsTo8Bit: pointOptions?.compressColorsTo8Bit
205
+ };
206
+ pointSource = factories.createLASSource(workers, input);
207
+ }
208
+ sourceObject = pointSource;
209
+ await pointSource.initialize();
210
+ checkAbort(signal);
211
+ metadata = (await pointSource.getMetadata());
212
+ const native = typeof metadata?.crs === 'string' ? await resolveGeo3dCrs(metadata.crs) : metadata?.crs;
213
+ const scene = await resolveGeo3dCrs(instanceCrs, native);
214
+ if (native && !native.isUnknown() && !scene.equals(native))
215
+ throw new Error('Point-cloud instance CRS must match its dataset CRS; reproject the dataset before loading.');
216
+ const current = await before(scene);
217
+ const point = factories.createOwnedPointCloud({ source: pointSource });
218
+ const pointEntity = point.entity;
219
+ entity = pointEntity;
220
+ stopPointRequests = point.stop;
221
+ owned.push(() => pointEntity.dispose());
222
+ if (pointOptions?.pointSize !== undefined) {
223
+ if (!Number.isFinite(pointOptions.pointSize) || pointOptions.pointSize < 0)
224
+ throw new Error('Invalid Geo3D pointSize.');
225
+ pointEntity.pointSize = pointOptions.pointSize;
226
+ }
227
+ if (pointOptions?.subdivisionThreshold !== undefined) {
228
+ if (!Number.isFinite(pointOptions.subdivisionThreshold) ||
229
+ pointOptions.subdivisionThreshold <= 0)
230
+ throw new Error('Invalid Geo3D subdivisionThreshold.');
231
+ pointEntity.subdivisionThreshold = pointOptions.subdivisionThreshold;
232
+ }
233
+ await current.add(pointEntity);
234
+ }
235
+ else if (format === 'geotiff' || format === 'cog') {
236
+ const tiff = await inspectGeoTiffRangeSource(createGeo3dProbeRangeGetter({ ...source, signal }));
237
+ if (!tiff?.bbox)
238
+ throw new Error('GeoTIFF requires readable georeferencing and raster bounds.');
239
+ if (!tiff.crs && !instanceCrs)
240
+ throw new Error('GeoTIFF CRS is missing; supply an explicit offline CRS definition.');
241
+ metadata = tiff;
242
+ const native = await resolveGeo3dCrs(tiff.crs || instanceCrs), scene = await resolveGeo3dCrs(instanceCrs, native);
243
+ const current = await before(scene);
244
+ let url = source.url;
245
+ if (!url) {
246
+ const blob = source.file || (source.buffer ? new Blob([source.buffer], { type: 'image/tiff' }) : null);
247
+ if (!blob)
248
+ throw new Error('Missing GeoTIFF source.');
249
+ url = URL.createObjectURL(blob);
250
+ const ownedUrl = url;
251
+ owned.push(() => URL.revokeObjectURL(ownedUrl));
252
+ }
253
+ const { default: Extent } = await import('@giro3d/giro3d/core/geographic/Extent.js');
254
+ const { createGeoTIFFSource } = await import('./geo3dRasterFactories.js');
255
+ const { default: Map } = await import('@giro3d/giro3d/entities/Map.js');
256
+ const { default: ColorLayer } = await import('@giro3d/giro3d/core/layer/ColorLayer.js');
257
+ const [minX, minY, maxX, maxY] = tiff.bbox, extent = new Extent(native, minX, maxX, minY, maxY);
258
+ const raster = format === 'cog'
259
+ ? options.giro3d?.sources?.cog || options.giro3d?.sources?.geotiff
260
+ : options.giro3d?.sources?.geotiff;
261
+ const workers = createGeo3dRasterWorkers(resolveAssetBaseUrl(options.assetBaseUrl), signal);
262
+ owned.push(() => workers.dispose());
263
+ const image = createGeoTIFFSource(workers, {
264
+ url,
265
+ crs: native,
266
+ channels: raster?.channels,
267
+ enableWorkers: raster?.enableWorkers,
268
+ flipY: raster?.flipY,
269
+ httpTimeout: raster?.httpTimeout,
270
+ is8bit: raster?.is8bit,
271
+ transparent: raster?.transparent
272
+ });
273
+ sourceObject = image;
274
+ const map = new Map({ extent: extent.as(scene).withRelativeMargin(0.02) });
275
+ entity = map;
276
+ await current.add(map);
277
+ checkAbort(signal);
278
+ colorLayer = new ColorLayer({ name: 'file-viewer-geotiff', source: image, extent });
279
+ await map.addLayer(colorLayer);
280
+ }
281
+ else if (format === 'cityjson') {
282
+ const document = parseCityJson(new TextDecoder().decode(await whole(source, maxCityJsonBytes, signal)));
283
+ const rendered = await renderCityJsonWithTextures(document, source.resolveRelativeUrl, options.giro3d?.sources?.cityjson, source.url, signal);
284
+ cityObject = rendered.group;
285
+ entity = rendered.group;
286
+ metadata = {
287
+ crs: rendered.crs,
288
+ triangleCount: rendered.triangleCount,
289
+ objectCount: rendered.objectCount,
290
+ externalResources: rendered.externalResources
291
+ };
292
+ const native = await resolveGeo3dCrs(rendered.crs || instanceCrs), scene = await resolveGeo3dCrs(instanceCrs, native);
293
+ if (rendered.crs && !scene.equals(native))
294
+ throw new Error('CityJSON instance CRS must match its dataset CRS; implicit coordinate relabelling is not supported.');
295
+ const current = await before(scene);
296
+ checkAbort(signal);
297
+ await current.add(rendered.group);
298
+ }
299
+ else {
300
+ if (!source.url)
301
+ throw new Error('3D Tiles requires a URL or 3TZ so relative tile and texture references remain resolvable.');
302
+ const current = await before(await resolveGeo3dCrs(instanceCrs || 'EPSG:4978'));
303
+ const { default: Tiles3D } = await import('@giro3d/giro3d/entities/Tiles3D.js');
304
+ const tiles = options.giro3d?.sources?.['3d-tiles'], assetBase = resolveAssetBaseUrl(options.assetBaseUrl);
305
+ const tilesEntity = new Tiles3D({
306
+ url: source.url,
307
+ errorTarget: tiles?.errorTarget,
308
+ pointCloudAttributeMapping: tiles?.pointCloudAttributeMapping,
309
+ pointSize: tiles?.pointSize,
310
+ enableFetchPlugin: archiveDataset ? false : tiles?.enableFetchPlugin,
311
+ dracoDecoderPath: `${assetBase}three/draco/`,
312
+ ktx2DecoderPath: `${assetBase}three/basis/`
313
+ });
314
+ entity = tilesEntity;
315
+ const native = tilesEntity.tiles;
316
+ if (archiveDataset)
317
+ native.registerPlugin({
318
+ name: 'FILE_VIEWER_LOCAL_3TZ',
319
+ fetchData: archiveDataset.fetchData
320
+ });
321
+ const preparePointMaterials = ({ scene }) => {
322
+ if (signal.aborted)
323
+ return;
324
+ scene.traverse((object) => {
325
+ const materials = Array.isArray(object.material) ? object.material : [object.material];
326
+ for (const material of materials)
327
+ repairGeo3dPointMaterial(material);
328
+ });
329
+ };
330
+ native.addEventListener('load-model', preparePointMaterials);
331
+ hooks.push(() => native.removeEventListener('load-model', preparePointMaterials));
332
+ const events = ['load-tileset', 'load-tile-set', 'load-model', 'needs-update'];
333
+ const notify = () => {
334
+ if (!signal.aborted)
335
+ current.notifyChange(tilesEntity);
336
+ };
337
+ for (const event of events)
338
+ native.addEventListener(event, notify);
339
+ hooks.push(() => {
340
+ for (const event of events)
341
+ native.removeEventListener(event, notify);
342
+ });
343
+ await current.add(tilesEntity);
344
+ }
345
+ checkAbort(signal);
346
+ if (!instance || !entity)
347
+ throw new Error('Geo3D runtime did not create an entity.');
348
+ const ready = instance, readyEntity = entity;
349
+ const fitToDataset = () => {
350
+ if (destroyed)
351
+ return;
352
+ const pov = ready.view.goTo(readyEntity);
353
+ if (pov) {
354
+ controls?.reset?.();
355
+ ready.notifyChange(readyEntity);
356
+ }
357
+ };
358
+ if (options.giro3d?.view?.fitToDataset !== false)
359
+ fitToDataset();
360
+ const binding = {
361
+ format,
362
+ entity: readyEntity,
363
+ nativeSource: sourceObject,
364
+ colorLayer
365
+ };
366
+ const extensionContext = { instance: ready, ...binding, source, metadata, signal, fitToDataset };
367
+ if (options.configure)
368
+ await runGeo3dHook(() => options.configure(extensionContext), signal, (dispose) => hooks.push(dispose), options.onExtensionError);
369
+ checkAbort(signal);
370
+ loaded = true;
371
+ context?.onProgressiveRender?.();
372
+ return { $el: target, instance: ready, ...binding, fitToDataset, unmount: cleanup };
373
+ }
374
+ catch (error) {
375
+ await cleanup();
376
+ throw error;
377
+ }
378
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveGeo3dDatasetUrl(value: string | undefined, documentBaseUrl: string): string | undefined;
@@ -0,0 +1,5 @@
1
+ export function resolveGeo3dDatasetUrl(value, documentBaseUrl) {
2
+ if (!value)
3
+ return undefined;
4
+ return new URL(value, documentBaseUrl).href;
5
+ }
@@ -1,6 +1,5 @@
1
1
  import { applyIfcSettings, copyIfcImporterSettings } from "./ifcSettings.js";
2
2
  import { IfcImporter } from "@thatopen/fragments";
3
- // Compiled into a self-hosted module Worker by the optional asset installer.
4
3
  const scope = globalThis;
5
4
  let active = false;
6
5
  scope.onmessage = async ({ data }) => {
@@ -18,7 +17,6 @@ scope.onmessage = async ({ data }) => {
18
17
  bytes: new Uint8Array(data.bytes),
19
18
  progressCallback: (progress) => scope.postMessage({ kind: "progress", progress }),
20
19
  });
21
- // slice owns the exact byte range even when the importer returns a view.
22
20
  const bytes = Uint8Array.from(result).buffer;
23
21
  scope.postMessage({ kind: "ready", bytes }, [bytes]);
24
22
  }
package/dist/ifc.d.ts CHANGED
@@ -16,32 +16,23 @@ export interface IfcExtensionContext {
16
16
  signal: AbortSignal;
17
17
  select: (localId: number | null) => Promise<IfcSelection | null>;
18
18
  }
19
- /** Advanced runtime objects are adapter-owned; return cleanup only for host resources. */
20
19
  export type IfcRuntimeContext = Pick<IfcExtensionContext, "components" | "fragments" | "world" | "signal">;
21
20
  export interface IfcThatOpenOptions {
22
- /** Public IfcImporter data fields; no executable methods, WASM or Worker overrides. */
23
21
  importer?: Readonly<Record<string, unknown>>;
24
- /** Public FragmentsModels.settings fields, not constructor/Worker ownership. */
25
22
  fragments?: {
26
23
  settings?: Readonly<Record<string, unknown>>;
27
24
  };
28
25
  }
29
26
  export interface IfcViewerOptions {
30
- /** Optional pre-import data settings; defaults are unchanged when omitted. */
31
27
  thatOpen?: IfcThatOpenOptions;
32
- /** Runs after runtime creation, before model loading. Return host-resource cleanup. */
33
28
  configureRuntime?: (context: IfcRuntimeContext) => void | (() => void) | Promise<void | (() => void)>;
34
- /** Directory installed by file-viewer-ifc-assets. Defaults to /file-viewer/vendor/ifc/. */
35
29
  assetBaseUrl?: string | URL;
36
30
  fitToModel?: boolean;
37
31
  enableSelection?: boolean;
38
32
  showProperties?: boolean;
39
- /** Whole-input limit, before a transferable copy is made. Default: 512 MiB. */
40
33
  maxFileBytes?: number;
41
- /** Bound stalled import/worker setup. Default: 120 seconds. */
42
34
  loadTimeoutMs?: number;
43
35
  onSelectionChange?: (selection: IfcSelection | null) => void;
44
- /** Advanced, opt-in access. Return cleanup for resources created by the hook. */
45
36
  configure?: (context: IfcExtensionContext) => void | (() => void) | Promise<void | (() => void)>;
46
37
  }
47
38
  export interface IfcViewerInstance {
package/dist/ifc.js CHANGED
@@ -23,7 +23,6 @@ export function createIfcRenderer(options = {}) {
23
23
  };
24
24
  }
25
25
  export async function renderFileViewerIfc(buffer, target, context, options = {}) {
26
- // Optional engines never enter the normal model/Office entry or initial bundle.
27
26
  const { renderIfc } = await import("./ifcRuntime.js");
28
27
  return renderIfc(buffer, target, context, options);
29
28
  }