@inweb/viewer-core 26.10.6 → 26.12.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.
@@ -4,8 +4,10 @@ import { ICommandService } from "../commands/ICommands";
4
4
  import { IOptions } from "../options/IOptions";
5
5
  import { IDragger } from "../draggers/IDraggers";
6
6
  import { IComponent } from "../components/IComponents";
7
- import { FileSource } from "../loaders/ILoader";
7
+ import { FileSource, ILoader } from "../loaders/ILoader";
8
+ import { IModel } from "../models/IModel";
8
9
  import { IViewpoint } from "./IViewpoint";
10
+ import { IInfo } from "./IInfo";
9
11
  /**
10
12
  * Viewer core interface.
11
13
  */
@@ -50,6 +52,14 @@ export interface IViewer extends IEventEmitter, ICommandService {
50
52
  * - wheel
51
53
  */
52
54
  canvasEvents: string[];
55
+ /**
56
+ * List of active loaders used to load models into the viewer.
57
+ */
58
+ loaders: ILoader[];
59
+ /**
60
+ * List of models loaded into the viewer.
61
+ */
62
+ models: IModel[];
53
63
  /**
54
64
  * List of names of available draggers.
55
65
  *
@@ -71,6 +81,10 @@ export interface IViewer extends IEventEmitter, ICommandService {
71
81
  * List of names of available components.
72
82
  */
73
83
  components: string[];
84
+ /**
85
+ * Statistical information about the GPU memory and the rendering process.
86
+ */
87
+ info: IInfo;
74
88
  /**
75
89
  * Initializes the viewer it with the specified canvas. Call {@link dispose | dispose()} to release
76
90
  * allocated resources.
@@ -134,14 +148,16 @@ export interface IViewer extends IEventEmitter, ICommandService {
134
148
  * thrown.
135
149
  *
136
150
  * For URLs, the file extension is used to determine the file format. For a `ArrayBuffer` and `Data
137
- * URL`, a file format must be specified using `params.format` parameter (see below). If no appropriate
138
- * loader is found for the specified format, an exception will be thrown.
151
+ * URL`, a file format must be specified using `params.format` parameter. If no appropriate loader is
152
+ * found for the specified format, an exception will be thrown.
139
153
  *
140
154
  * If there was an active dragger before opening the file, it will be deactivated. After opening the
141
155
  * file, you must manually activate the required dragger.
142
156
  *
143
157
  * Fires:
144
158
  *
159
+ * - {@link CancelEvent | cancel}
160
+ * - {@link ClearEvent | clear}
145
161
  * - {@link OpenEvent | open}
146
162
  * - {@link GeometryStartEvent | geometrystart}
147
163
  * - {@link GeometryProgressEvent | geometryprogress}
@@ -150,23 +166,26 @@ export interface IViewer extends IEventEmitter, ICommandService {
150
166
  * - {@link GeometryEndEvent | geometryend}
151
167
  * - {@link GeometryErrorEvent | geometryerror}
152
168
  *
153
- * @param file - File to load. Can be one of:
169
+ * @param file - File to load. Can be:
154
170
  *
155
171
  * - `File`, `Assembly` or `Model` instance from the Open Cloud Server
156
- * - File `URL` string
172
+ * - `URL` string
157
173
  * - {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL} string
158
174
  * - {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object
159
175
  * - {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer}
160
176
  * object
161
177
  *
162
178
  * @param params - Loading parameters.
163
- * @param params.format - File format string. Required when loading a file as `ArrayBuffer` or `Data *
164
- * URL`.
165
- * @param params.mode - File opening mode. Viewer specific. Can be one of:
179
+ * @param params.format - File format. Required when loading a file as `ArrayBuffer` or `Data URL`.
180
+ * @param params.mode - File opening mode. Can be one of:
166
181
  *
167
- * - `open` - Unloads an open file and opens a new one. This is default mode.
168
- * - `append` - Appends a file to an already open file. This mode is not supported for all formats.
182
+ * - `file` - Single file mode. Unloads an open file and opens a new one. This is default mode.
183
+ * - `assembly` - Assembly mode. Appends a file to an already open file (). This mode is not supported
184
+ * for all viewers.
169
185
  *
186
+ * @param params.modelId - Unique model ID in the assembly (multi-model scene). Used as a model prefix
187
+ * when selecting objects (see {@link getSelected2}). Must not contain the ":" (colon). Required when
188
+ * loading a file as `ArrayBuffer` or `Data URL`.
170
189
  * @param params.requestHeader - The
171
190
  * {@link https://developer.mozilla.org/docs/Glossary/Request_header | request header} used in HTTP
172
191
  * request.
@@ -178,6 +197,7 @@ export interface IViewer extends IEventEmitter, ICommandService {
178
197
  open(file: FileSource, params: {
179
198
  format?: string;
180
199
  mode?: string;
200
+ modelId?: string;
181
201
  requestHeader?: HeadersInit;
182
202
  withCredentials?: boolean;
183
203
  }): Promise<this>;
@@ -214,19 +234,41 @@ export interface IViewer extends IEventEmitter, ICommandService {
214
234
  */
215
235
  clearSlices(): void;
216
236
  /**
217
- * Returns a list of original handles for the selected objects.
237
+ * Returns a list of original handles for the selected objects. To avoid handle collisions in
238
+ * assemblies (multi-model scenes), use {@link getSelected2} instead.
239
+ *
240
+ * @returns The list of original object handles.
218
241
  */
219
242
  getSelected(): string[];
220
243
  /**
221
- * Selects the objects by original handles.
244
+ * Returns a list of original handles for the selected objects in assemblies (multi-model scenes).
245
+ *
246
+ * @returns The list of original object handles with model prefix in format "model:handle".
247
+ */
248
+ getSelected2(): string[];
249
+ /**
250
+ * Selects the objects by original handles. To avoid handle collisions in assemblies (multi-model
251
+ * scenes), use {@link setSelected2} instead.
222
252
  *
223
253
  * Fires:
224
254
  *
225
255
  * - {@link SelectEvent | select}
256
+ * - {@link Select2Event | select2}
226
257
  *
227
258
  * @param handles - The list of original handles.
228
259
  */
229
260
  setSelected(handles?: string[]): void;
261
+ /**
262
+ * Selects the objects by original handles in assemblies (multi-model scenes).
263
+ *
264
+ * Fires:
265
+ *
266
+ * - {@link SelectEvent | select}
267
+ * - {@link Select2Event | select2}
268
+ *
269
+ * @param handles - The list of original handles with model prefix in format "model:handle".
270
+ */
271
+ setSelected2(handles?: string[]): void;
230
272
  /**
231
273
  * Unselects all objects.
232
274
  *
@@ -302,6 +344,8 @@ export interface IViewer extends IEventEmitter, ICommandService {
302
344
  resetActiveDragger(): void;
303
345
  /**
304
346
  * Returns the component reference, or `null` if there is no component with the specified name.
347
+ *
348
+ * @param name - Component name. Can be one of the {@link components} list.
305
349
  */
306
350
  getComponent(name: string): IComponent | null;
307
351
  /**
@@ -0,0 +1,10 @@
1
+ import { IInfo, IMemoryInfo, IPerformanceInfo, IRenderInfo, ISceneInfo, ISystemInfo } from "./IInfo";
2
+ export declare class Info implements IInfo {
3
+ performance: IPerformanceInfo;
4
+ render: IRenderInfo;
5
+ scene: ISceneInfo;
6
+ optimizedScene: ISceneInfo;
7
+ memory: IMemoryInfo;
8
+ system: ISystemInfo;
9
+ constructor();
10
+ }
@@ -19,7 +19,7 @@ export interface AnimateEvent {
19
19
  time: DOMHighResTimeStamp;
20
20
  }
21
21
  /**
22
- * Event that fires when model loading has been canceled.
22
+ * Event that fires when file loading has been canceled.
23
23
  *
24
24
  * @event
25
25
  */
@@ -207,7 +207,7 @@ export interface GeometryChunkEvent {
207
207
  buffer?: Uint8Array | ArrayBuffer;
208
208
  }
209
209
  /**
210
- * Event that fires after model has been successfully loaded.
210
+ * Event that fires after file has been successfully loaded.
211
211
  *
212
212
  * @event
213
213
  */
@@ -261,7 +261,7 @@ export interface GeometryErrorEvent {
261
261
  buffer?: Uint8Array | ArrayBuffer;
262
262
  }
263
263
  /**
264
- * Event that measures the progress of the model loading.
264
+ * Event that measures the progress of the file loading.
265
265
  *
266
266
  * @event
267
267
  */
@@ -290,7 +290,7 @@ export interface GeometryProgressEvent {
290
290
  buffer?: Uint8Array | ArrayBuffer;
291
291
  }
292
292
  /**
293
- * Event that fires before the model loads.
293
+ * Event that fires before the file loads.
294
294
  *
295
295
  * @event
296
296
  */
@@ -373,7 +373,7 @@ export interface IsolateEvent {
373
373
  type: "isolate";
374
374
  }
375
375
  /**
376
- * Event that fires before model open.
376
+ * Event that fires before file open.
377
377
  *
378
378
  * @event
379
379
  */
@@ -383,13 +383,13 @@ export interface OpenEvent {
383
383
  */
384
384
  type: "open";
385
385
  /**
386
- * File to load.
386
+ * File opening mode.
387
387
  */
388
- file: File | Assembly | Model | string | globalThis.File | ArrayBuffer;
388
+ mode: string;
389
389
  /**
390
- * Model from file to load. Only defined when loading a file from the Open Cloud Server.
390
+ * File to load.
391
391
  */
392
- model?: Model;
392
+ file: File | Assembly | Model | string | globalThis.File | ArrayBuffer;
393
393
  /**
394
394
  * Deprecated since `26.4`. Use {@link file} instead.
395
395
  *
@@ -487,9 +487,29 @@ export interface SelectEvent {
487
487
  /**
488
488
  * Selection set (viewer dependent).
489
489
  */
490
- data: any;
490
+ data?: any;
491
491
  /**
492
- * Handles of selected entities.
492
+ * Handles of selected objects.
493
+ */
494
+ handles: string[];
495
+ }
496
+ /**
497
+ * Event that fires after viewer selection changes. Uses model prefix to avoid handle collisions in
498
+ * assemblies (multi-model scenes).
499
+ *
500
+ * @event
501
+ */
502
+ export interface Select2Event {
503
+ /**
504
+ * Event type.
505
+ */
506
+ type: "select2";
507
+ /**
508
+ * Selection set (viewer dependent).
509
+ */
510
+ data?: any;
511
+ /**
512
+ * Handles of selected objects with model prefix in format "model:handle".
493
513
  */
494
514
  handles: string[];
495
515
  }
@@ -683,7 +703,7 @@ export interface ViewerEventMap {
683
703
  */
684
704
  animate: AnimateEvent;
685
705
  /**
686
- * Event that fires when model loading has been canceled.
706
+ * Event that fires when file loading has been canceled.
687
707
  */
688
708
  cancel: CancelEvent;
689
709
  /**
@@ -735,7 +755,7 @@ export interface ViewerEventMap {
735
755
  */
736
756
  geometrychunk: GeometryChunkEvent;
737
757
  /**
738
- * Event that fires after model has been successfully loaded.
758
+ * Event that fires after file has been successfully loaded.
739
759
  */
740
760
  geometryend: GeometryEndEvent;
741
761
  /**
@@ -743,11 +763,11 @@ export interface ViewerEventMap {
743
763
  */
744
764
  geometryerror: GeometryErrorEvent;
745
765
  /**
746
- * Event that measures the progress of the model loading.
766
+ * Event that measures the progress of the file loading.
747
767
  */
748
768
  geometryprogress: GeometryProgressEvent;
749
769
  /**
750
- * Event that fires before the model opens.
770
+ * Event that fires before the file opens.
751
771
  */
752
772
  geometrystart: GeometryStartEvent;
753
773
  /**
@@ -767,7 +787,7 @@ export interface ViewerEventMap {
767
787
  */
768
788
  isolate: IsolateEvent;
769
789
  /**
770
- * Event that fires before model opens.
790
+ * Event that fires before file opens.
771
791
  */
772
792
  open: OpenEvent;
773
793
  /**
@@ -790,6 +810,10 @@ export interface ViewerEventMap {
790
810
  * Event that fires when the selection changes.
791
811
  */
792
812
  select: SelectEvent;
813
+ /**
814
+ * Event that fires when the selection changes.
815
+ */
816
+ select2: Select2Event;
793
817
  /**
794
818
  * Event that fires after selected objects becomes visible.
795
819
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-core",
3
- "version": "26.10.6",
3
+ "version": "26.12.0",
4
4
  "description": "3D CAD and BIM data Viewer core",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,7 +26,7 @@
26
26
  "test": "karma start karma.conf.js"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/client": "~26.10.6",
30
- "@inweb/eventemitter2": "~26.10.6"
29
+ "@inweb/client": "~26.12.0",
30
+ "@inweb/eventemitter2": "~26.12.0"
31
31
  }
32
32
  }
@@ -28,12 +28,13 @@ import { IViewer } from "../viewer/IViewer";
28
28
  */
29
29
  export interface ICommandService {
30
30
  /**
31
- * Executes the command denoted by the given command ID.
31
+ * Executes the command denoted by the given command ID. If the command is not found, tries to set
32
+ * active dragger with the specified name.
32
33
  *
33
- * @param id - ID of the command to execute.
34
+ * @param id - Command ID or dragger name.
34
35
  * @param args - Parameters passed to the command handler function.
35
- * @returns Returns the result of the command handler function. Returns `undefined` when the command
36
- * doesn't exists.
36
+ * @returns Returns the result of the command handler function or new active dragger instance. Returns
37
+ * `undefined` if neither the command nor the dragger exists.
37
38
  */
38
39
  executeCommand(id: string, ...args: any[]): any;
39
40
  }
package/src/index.ts CHANGED
@@ -32,10 +32,13 @@ export * from "./components/IComponents";
32
32
  export * from "./loaders/ILoader";
33
33
  export * from "./loaders/Loader";
34
34
  export * from "./loaders/Loaders";
35
+ export * from "./models/IModel";
35
36
  export * from "./options/IOptions";
36
37
  export * from "./options/Options";
37
38
  export * from "./options/OptionsEvents";
38
39
  export * from "./viewer/CanvasEvents";
40
+ export * from "./viewer/IInfo";
41
+ export * from "./viewer/Info";
39
42
  export * from "./viewer/IViewer";
40
43
  export * from "./viewer/IViewpoint";
41
44
  export * from "./viewer/ViewerEvents";
@@ -28,7 +28,7 @@ import type { IViewer } from "../viewer/IViewer";
28
28
  * Defines the file source to load into the viewer:
29
29
  *
30
30
  * - `File`, `Assembly` or `Model` instance from the Open Cloud Server
31
- * - File `URL` string
31
+ * - `URL` string
32
32
  * - {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL} string
33
33
  * - {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object
34
34
  * - {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer}
@@ -43,4 +43,13 @@ export class Loader implements ILoader {
43
43
  cancel(): void {
44
44
  this.abortController.abort();
45
45
  }
46
+
47
+ extractFileName(file: FileSource): string {
48
+ const regex = /[^/\\?#:]+(?=\?|#|$)/;
49
+
50
+ if (typeof file === "string") return (file.match(regex) || [])[0];
51
+ else if (file instanceof globalThis.File) return (file.name.match(regex) || [])[0];
52
+
53
+ return undefined;
54
+ }
46
55
  }
@@ -0,0 +1,44 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ /**
25
+ * Model interface.
26
+ */
27
+ export interface IModel {
28
+ /**
29
+ * Unique model ID, used as a model prefix when selecting objects in assemblies (multi-model scenes).
30
+ * Can be:
31
+ *
32
+ * - `file ID` - when loading a file from Open Cloud Server.
33
+ * - `assembly ID` - when loading an assembly from Open Cloud Server.
34
+ * - `model ID` - when loading a model of the file/assembly from Open Cloud Server.
35
+ * - `file name` - when loading from local File or URL.
36
+ * - `user defined` - when loading from ArrayBuffer or Data URL.
37
+ */
38
+ id: string;
39
+
40
+ /**
41
+ * Disposes the model and releases allocated resources.
42
+ */
43
+ dispose(): void;
44
+ }
@@ -212,14 +212,45 @@ export interface IOptions {
212
212
  geometryType?: string;
213
213
 
214
214
  /**
215
- * Ruler unit.
215
+ * Unit of measurement for the ruler tool (distance measurements).
216
216
  *
217
- * Available values: Default, Millimeters, Centimeters, Meters, Feet, Inches, Yards, Kilometers, Miles,
218
- * Micrometers, MicroInches
217
+ * When set to `Default`, the ruler uses the file's native units. Otherwise, distances are
218
+ * automatically converted to the specified unit.
219
+ *
220
+ * Available values:
221
+ *
222
+ * - `Default` - Use file's native units (recommended)
223
+ * - `Millimeters` - Metric: 0.001 m
224
+ * - `Centimeters` - Metric: 0.01 m
225
+ * - `Meters` - Metric: 1 m (base unit)
226
+ * - `Kilometers` - Metric: 1000 m
227
+ * - `Micrometers` - Metric: 0.000001 m
228
+ * - `Inches` - Imperial: 0.0254 m
229
+ * - `Feet` - Imperial: 0.3048 m
230
+ * - `Yards` - Imperial: 0.9144 m
231
+ * - `Miles` - Imperial: 1609.344 m
232
+ * - `Mils` - Imperial: 0.0000254 m
233
+ * - `MicroInches` - Imperial: 0.0000000254 m
219
234
  *
220
235
  * @defaultValue "Default"
221
236
  */
222
- rulerUnit: string;
237
+ rulerUnit?: string;
238
+
239
+ /**
240
+ * Number of decimal places to display in ruler measurements.
241
+ *
242
+ * Controls the precision of distance values shown by the ruler tool. Higher values provide more
243
+ * precision but may clutter the display with unnecessary digits.
244
+ *
245
+ * Available values:
246
+ *
247
+ * - `Default` - Use file's native units precision, if supported, otherwise use 2 digits.
248
+ * - `Auto` - Automatically choose precision based on distance value.
249
+ * - `0`...`10` - Use specified number of decimal places (range 0-10, inclusive).
250
+ *
251
+ * @defaultValue 2
252
+ */
253
+ rulerPrecision?: any;
223
254
 
224
255
  /**
225
256
  * Camera projection mode:
@@ -267,6 +298,7 @@ export function defaultOptions(): IOptions {
267
298
  enableGestures: true,
268
299
  geometryType: "vsfx",
269
300
  rulerUnit: "Default",
301
+ rulerPrecision: 2,
270
302
  cameraMode: "perspective",
271
303
  };
272
304
  }
@@ -343,6 +343,15 @@ export class Options implements IOptions {
343
343
  this.change();
344
344
  }
345
345
 
346
+ get rulerPrecision(): any {
347
+ return this._data.rulerPrecision;
348
+ }
349
+
350
+ set rulerPrecision(value: any) {
351
+ this._data.rulerPrecision = value;
352
+ this.change();
353
+ }
354
+
346
355
  get cameraMode(): CameraMode {
347
356
  return this._data.cameraMode || "perspective";
348
357
  }