@inweb/viewer-visualize 26.5.0 → 26.5.2

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 (34) hide show
  1. package/dist/viewer-visualize.js +18183 -18012
  2. package/dist/viewer-visualize.js.map +1 -1
  3. package/dist/viewer-visualize.min.js +1 -1
  4. package/dist/viewer-visualize.module.js +335 -297
  5. package/dist/viewer-visualize.module.js.map +1 -1
  6. package/lib/Viewer/Loaders/{UpdaterController.d.ts → UpdateController.d.ts} +1 -1
  7. package/lib/Viewer/Loaders/VSFBufferLoader.d.ts +8 -0
  8. package/lib/Viewer/Loaders/VSFModelLoader.d.ts +8 -0
  9. package/lib/Viewer/Loaders/VSFXBufferLoader.d.ts +8 -0
  10. package/lib/Viewer/Loaders/VSFXModelLoader.d.ts +8 -0
  11. package/lib/Viewer/Loaders/VSFXPartialLoader.d.ts +10 -0
  12. package/lib/Viewer/Loaders/VSFXStreamingLoader.d.ts +8 -0
  13. package/lib/Viewer/Loaders/index.d.ts +67 -0
  14. package/lib/Viewer/Viewer.d.ts +7 -59
  15. package/lib/index.d.ts +3 -2
  16. package/package.json +5 -5
  17. package/src/Viewer/Loaders/{BaseLoader.ts → UpdateController.ts} +30 -10
  18. package/src/Viewer/Loaders/{LoaderFactory.ts → VSFBufferLoader.ts} +28 -19
  19. package/src/Viewer/Loaders/VSFModelLoader.ts +87 -0
  20. package/src/Viewer/Loaders/VSFXBufferLoader.ts +58 -0
  21. package/src/Viewer/Loaders/{VsfXLoader.ts → VSFXModelLoader.ts} +35 -35
  22. package/src/Viewer/Loaders/{VsfXPartialLoader.ts → VSFXPartialLoader.ts} +55 -45
  23. package/src/Viewer/Loaders/{VsfXStreamingLoader.ts → VSFXStreamingLoader.ts} +35 -25
  24. package/src/Viewer/Loaders/index.ts +108 -0
  25. package/src/Viewer/Viewer.ts +53 -103
  26. package/src/index.ts +6 -3
  27. package/lib/Viewer/Loaders/BaseLoader.d.ts +0 -10
  28. package/lib/Viewer/Loaders/LoaderFactory.d.ts +0 -10
  29. package/lib/Viewer/Loaders/TCSLoader.d.ts +0 -4
  30. package/lib/Viewer/Loaders/VsfXLoader.d.ts +0 -4
  31. package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +0 -4
  32. package/lib/Viewer/Loaders/VsfXStreamingLoader.d.ts +0 -4
  33. package/src/Viewer/Loaders/TCSLoader.ts +0 -83
  34. package/src/Viewer/Loaders/UpdaterController.ts +0 -37
@@ -4,7 +4,7 @@ export declare enum UpdateType {
4
4
  kNormal = 1,
5
5
  kForce = 2
6
6
  }
7
- export declare class UpdaterController {
7
+ export declare class UpdateController {
8
8
  private lastUpdate;
9
9
  private viewer;
10
10
  delayUpdateTime: number;
@@ -0,0 +1,8 @@
1
+ import { Loader } from "@inweb/viewer-core";
2
+ import { Viewer } from "../Viewer";
3
+ export declare class VSFBufferLoader extends Loader {
4
+ viewer: Viewer;
5
+ constructor(viewer: Viewer);
6
+ isSupport(file: any, format?: string): boolean;
7
+ load(buffer: any, format?: string): Promise<this>;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Loader } from "@inweb/viewer-core";
2
+ import { Viewer } from "../Viewer";
3
+ export declare class VSFModelLoader extends Loader {
4
+ viewer: Viewer;
5
+ constructor(viewer: Viewer);
6
+ isSupport(file: any, format?: string): boolean;
7
+ load(model: any, format?: string): Promise<this>;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Loader } from "@inweb/viewer-core";
2
+ import { Viewer } from "../Viewer";
3
+ export declare class VSFXBufferLoader extends Loader {
4
+ viewer: Viewer;
5
+ constructor(viewer: Viewer);
6
+ isSupport(file: any, format?: string): boolean;
7
+ load(buffer: any, format?: string): Promise<this>;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Loader } from "@inweb/viewer-core";
2
+ import { Viewer } from "../Viewer";
3
+ export declare class VSFXModelLoader extends Loader {
4
+ viewer: Viewer;
5
+ constructor(viewer: Viewer);
6
+ isSupport(file: any): boolean;
7
+ load(model: any, format?: string, params?: any): Promise<this>;
8
+ }
@@ -0,0 +1,10 @@
1
+ import { Loader } from "@inweb/viewer-core";
2
+ import { Viewer } from "../Viewer";
3
+ export declare class VSFXPartialLoader extends Loader {
4
+ viewer: Viewer;
5
+ abortControllerForRequestMap: Map<number, AbortController>;
6
+ constructor(viewer: Viewer);
7
+ isSupport(file: any): boolean;
8
+ load(model: any, format?: string): Promise<this>;
9
+ cancel(): void;
10
+ }
@@ -0,0 +1,8 @@
1
+ import { Loader } from "@inweb/viewer-core";
2
+ import { Viewer } from "../Viewer";
3
+ export declare class VSFXStreamingLoader extends Loader {
4
+ viewer: Viewer;
5
+ constructor(viewer: Viewer);
6
+ isSupport(file: any): boolean;
7
+ load(model: any): Promise<this>;
8
+ }
@@ -0,0 +1,67 @@
1
+ import { ILoadersRegistry } from "@inweb/viewer-core";
2
+ /**
3
+ * Viewer loaders registry. Use this registry to register custom loaders.
4
+ *
5
+ * To implement custom loader:
6
+ *
7
+ * 1. Define a loader class implements {@link ILoader}.
8
+ * 2. Define a constructor with a `viewer` parameter.
9
+ * 3. Override {@link ILoader.isSupport} and сheck if the loader can load the specified file.
10
+ * 4. Override {@link ILoader.load} and define the logic for loading the model from the file.
11
+ *
12
+ * The loader should do:
13
+ *
14
+ * - Load model data from file. The model data must be a `VSFX` data buffer of `VSFX` data chunk.
15
+ * - Parse model data with the `VisualizeJS` viewer instance.
16
+ * - Synchronize viewer styles, options and overlay.
17
+ * - Update the viewer.
18
+ *
19
+ * The loader must emit events:
20
+ *
21
+ * - `geometryprogress` - during loading. If progress is not supported, emit it once with a value of 100%
22
+ * after the load is complete.
23
+ * - `databasechunk` - when model is loaded and ready to render.
24
+ * 5. Override {@link ILoader.dispose} and release loader resources, if required.
25
+ * 6. Register loader provider in the loaders registry by calling the {@link loaders.registerLoader}.
26
+ *
27
+ * @example Implementing a custom loader.
28
+ *
29
+ * ```javascript
30
+ * import { Loader } from "@inweb/viewer-core";
31
+ * import { loaders, Viewer } from "@inweb/viewer-visualize";
32
+ *
33
+ * class MyLoader extends Loader {
34
+ * public viewer: Viewer;
35
+ *
36
+ * constructor(viewer: Viewer) {
37
+ * super();
38
+ * this.viewer = viewer;
39
+ * }
40
+ *
41
+ * override isSupport(file, format): Boolean {
42
+ * // place custom logic here
43
+ * return ...;
44
+ * }
45
+ *
46
+ * override load(file, format, params): Promise<this> {
47
+ *
48
+ * // place custom loading logic here
49
+ * const data = ...
50
+ *
51
+ * this.viewer.visualizeJs.getViewer().parseVsfx(data);
52
+ *
53
+ * this.viewer.syncOpenCloudVisualStyle(false);
54
+ * this.viewer.syncOptions();
55
+ * this.viewer.syncOverlay();
56
+ * this.viewer.resize();
57
+ *
58
+ * this.viewer.emitEvent({ type: "databasechunk", data: model, file });
59
+ *
60
+ * return Promise.resove(this);
61
+ * };
62
+ * }
63
+ *
64
+ * loaders.registerLoader("MyLoader", (viewer) => new MyLoader(viewer));
65
+ * ```
66
+ */
67
+ export declare const loaders: ILoadersRegistry;
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter2 } from "@inweb/eventemitter2";
2
2
  import { Assembly, Client, File, Model } from "@inweb/client";
3
- import { CanvasEventMap, Dragger, IComponent, IDragger, IOptions, IViewer, IViewpoint, Options, OptionsEventMap, ViewerEventMap } from "@inweb/viewer-core";
3
+ import { CanvasEventMap, Dragger, FileSource, IComponent, IDragger, ILoader, IOptions, IViewer, IViewpoint, Options, OptionsEventMap, ViewerEventMap } from "@inweb/viewer-core";
4
4
  import { IMarkup, IWorldTransform } from "@inweb/markup";
5
5
  import { MarkupType } from "./Markup/MarkupFactory";
6
6
  /**
@@ -23,10 +23,9 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
23
23
  canvasEvents: string[];
24
24
  private _markup;
25
25
  canvas: HTMLCanvasElement | undefined;
26
- _abortController: AbortController | undefined;
27
- _abortControllerForRequestMap: Map<string, AbortController> | undefined;
28
26
  _abortControllerForReferences: AbortController | undefined;
29
27
  client: Client | undefined;
28
+ loaders: Array<ILoader>;
30
29
  /**
31
30
  * @param client - The `Client` instance that is used to load model reference files from the Open Cloud
32
31
  * Server. Do not specify `Client` if you need a standalone viewer instance to view `VSFX` files from
@@ -200,63 +199,12 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
200
199
  loadReferences(model: Model | File | Assembly): Promise<this>;
201
200
  applyModelTransformMatrix(model: Model | Assembly): void;
202
201
  applySceneGraphSettings(options?: IOptions): void;
202
+ open(file: FileSource, params?: {
203
+ format?: string;
204
+ mode?: string;
205
+ }): Promise<this>;
203
206
  /**
204
- * Loads a file from Open Cloud Server into the viewer.
205
- *
206
- * The file geometry data on the server must be converted to `VSFX` format.
207
- *
208
- * To open a large file, enable {@link IOptions.enablePartialMode | partial streaming} mode before
209
- * opening (see example below).
210
- *
211
- * This method requires a `Client` instance to be specified when creating the viewer to load model
212
- * reference files from the Open Cloud Server. For a standalone viewer instance use
213
- * {@link openVsfFile | openVsfFile()} or {@link openVsfxFile | openVsfxFile()}.
214
- *
215
- * If there was an active dragger before opening the file, it will be deactivated. After opening the
216
- * file, you must manually activate the required dragger.
217
- *
218
- * Fires:
219
- *
220
- * - {@link OpenEvent | open}
221
- * - {@link GeometryStartEvent | geometrystart}
222
- * - {@link GeometryProgressEvent | geometryprogress}
223
- * - {@link DatabaseChunkEvent | databasechunk}
224
- * - {@link GeometryChunkEvent | geometrychunk}
225
- * - {@link GeometryEndEvent | geometryend}
226
- * - {@link GeometryErrorEvent | geometryerror}
227
- *
228
- * @example Using partial streaming mode to open a large file from a server.
229
- *
230
- * ```javascript
231
- * viewer.options.enableStreamingMode = true;
232
- * viewer.options.enablePartialMode = true;
233
- * await viewer.open(file);
234
- * ```
235
- *
236
- * @param file - File, assembly or specific model to load. If a `File` instance with multiple models is
237
- * specified, the default model will be loaded. If there is no default model, first availiable model
238
- * will be loaded.
239
- */
240
- open(file: File | Assembly | Model): Promise<this>;
241
- /**
242
- * Loads a `VSF` file into the viewer.
243
- *
244
- * This method does not support {@link IOptions.enableStreamingMode | streaming} or
245
- * {@link IOptions.enablePartialMode | partial streaming} mode.
246
- *
247
- * If there was an active dragger before opening the file, it will be deactivated. After opening the
248
- * file, you must manually activate the required dragger.
249
- *
250
- * Fires:
251
- *
252
- * - {@link OpenEvent | open}
253
- * - {@link GeometryStartEvent | geometrystart}
254
- * - {@link GeometryProgressEvent | geometryprogress}
255
- * - {@link DatabaseChunkEvent | databasechunk}
256
- * - {@link GeometryEndEvent | geometryend}
257
- * - {@link GeometryErrorEvent | geometryerror}
258
- *
259
- * @param buffer - Binary data buffer to load.
207
+ * Deprecated since `26.4`. Use {@link open | open()} instead.
260
208
  */
261
209
  openVsfFile(buffer: Uint8Array | ArrayBuffer): this;
262
210
  /**
package/lib/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * from "@inweb/viewer-core";
2
- export * from "@inweb/markup";
3
1
  export { draggers } from "./Viewer/Draggers";
4
2
  export { commands } from "./Viewer/Commands";
5
3
  export { components } from "./Viewer/Components";
4
+ export { loaders } from "./Viewer/Loaders";
6
5
  export { Viewer } from "./Viewer/Viewer";
7
6
  export { OdBaseDragger } from "./Viewer/Draggers/Common/OdBaseDragger";
8
7
  export { MarkupType } from "./Viewer/Markup/MarkupFactory";
8
+ export * from "@inweb/viewer-core";
9
+ export * from "@inweb/markup";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "26.5.0",
3
+ "version": "26.5.2",
4
4
  "description": "JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -29,10 +29,10 @@
29
29
  "docs": "typedoc"
30
30
  },
31
31
  "dependencies": {
32
- "@inweb/client": "~26.5.0",
33
- "@inweb/eventemitter2": "~26.5.0",
34
- "@inweb/markup": "~26.5.0",
35
- "@inweb/viewer-core": "~26.5.0"
32
+ "@inweb/client": "~26.5.2",
33
+ "@inweb/eventemitter2": "~26.5.2",
34
+ "@inweb/markup": "~26.5.2",
35
+ "@inweb/viewer-core": "~26.5.2"
36
36
  },
37
37
  "visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
38
38
  }
@@ -21,20 +21,40 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Model } from "@inweb/client";
25
- import { IOptions } from "@inweb/viewer-core";
26
24
  import { Viewer } from "../Viewer";
27
25
 
28
- export class BaseLoader {
29
- protected viewer: Viewer;
30
- protected model: Model;
31
- protected options: IOptions;
26
+ const DELAY_TIME_MULTIPLEXER = 2.0;
27
+ const START_UPDATE_TIME = 1000;
32
28
 
33
- constructor(viewer: Viewer, model: Model, options: IOptions) {
29
+ export enum UpdateType {
30
+ kDelay,
31
+ kNormal,
32
+ kForce,
33
+ }
34
+
35
+ export class UpdateController {
36
+ private lastUpdate: number;
37
+ private viewer: Viewer;
38
+ public delayUpdateTime: number;
39
+
40
+ constructor() {
41
+ this.lastUpdate = 0;
42
+ this.delayUpdateTime = START_UPDATE_TIME;
43
+ }
44
+
45
+ initialize(viewer: Viewer) {
34
46
  this.viewer = viewer;
35
- this.model = model;
36
- this.options = options;
47
+ this.lastUpdate = performance.now();
37
48
  }
38
49
 
39
- async load(): Promise<void> {}
50
+ update(type: UpdateType) {
51
+ const isNeedUpdate = type !== UpdateType.kDelay || performance.now() - this.lastUpdate >= this.delayUpdateTime;
52
+ const isForce = type === UpdateType.kForce;
53
+
54
+ if (isNeedUpdate) {
55
+ this.viewer.update(isForce);
56
+ this.lastUpdate = performance.now();
57
+ this.delayUpdateTime *= DELAY_TIME_MULTIPLEXER;
58
+ }
59
+ }
40
60
  }
@@ -21,29 +21,38 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { Model } from "@inweb/client";
25
- import { IOptions } from "@inweb/viewer-core";
26
-
27
- import { TCSLoader } from "./TCSLoader";
28
- import { VsfXLoader } from "./VsfXLoader";
29
- import { VsfXStreamingLoader } from "./VsfXStreamingLoader";
30
- import { VsfXPartialLoader } from "./VsfXPartialLoader";
24
+ import { Loader } from "@inweb/viewer-core";
31
25
  import { Viewer } from "../Viewer";
32
26
 
33
- export class LoaderFactory {
34
- create(viewer: Viewer, model: Model, options: IOptions) {
35
- const geometryType = model.database.split(".").pop();
27
+ export class VSFBufferLoader extends Loader {
28
+ public viewer: Viewer;
29
+
30
+ constructor(viewer: Viewer) {
31
+ super();
32
+ this.viewer = viewer;
33
+ }
34
+
35
+ override isSupport(file: any, format?: string): boolean {
36
+ return file instanceof ArrayBuffer && /vsf$/i.test(format);
37
+ }
38
+
39
+ override load(buffer: any, format?: string): Promise<this> {
40
+ if (!this.viewer.visualizeJs) return Promise.resolve(this);
41
+
42
+ const visLib = this.viewer.visLib();
43
+ const visViewer = visLib.getViewer();
44
+
45
+ const data = new Uint8Array(buffer);
46
+ visViewer.parseFile(data);
36
47
 
37
- if (model.geometry.length === 0 && geometryType === "vsfx") {
38
- if (!options.enableStreamingMode) return new VsfXLoader(viewer, model, options);
39
- else if (options.enablePartialMode) return new VsfXPartialLoader(viewer, model, options);
40
- else return new VsfXStreamingLoader(viewer, model, options);
41
- }
48
+ this.viewer.syncOpenCloudVisualStyle(false);
49
+ this.viewer.syncOptions();
50
+ this.viewer.syncOverlay();
51
+ this.viewer.resize();
42
52
 
43
- if (geometryType === "data") {
44
- return new TCSLoader(viewer, model, options);
45
- }
53
+ this.viewer.emitEvent({ type: "geometryprogress", data: 1, file: buffer });
54
+ this.viewer.emitEvent({ type: "databasechunk", data, file: buffer });
46
55
 
47
- throw new Error(`Unknown geometry type: ${geometryType}`);
56
+ return Promise.resolve(this);
48
57
  }
49
58
  }
@@ -0,0 +1,87 @@
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
+ import { Loader } from "@inweb/viewer-core";
25
+ import { Viewer } from "../Viewer";
26
+
27
+ export class VSFModelLoader extends Loader {
28
+ public viewer: Viewer;
29
+
30
+ constructor(viewer: Viewer) {
31
+ super();
32
+ this.viewer = viewer;
33
+ }
34
+
35
+ override isSupport(file: any, format?: string): boolean {
36
+ return (
37
+ typeof file === "object" &&
38
+ typeof file.database === "string" &&
39
+ typeof file.downloadResource === "function" &&
40
+ /.data$/i.test(file.database)
41
+ );
42
+ }
43
+
44
+ override async load(model: any, format?: string): Promise<this> {
45
+ if (!this.viewer.visualizeJs) return this;
46
+
47
+ const visLib = this.viewer.visLib();
48
+ const visViewer = visLib.getViewer();
49
+
50
+ const filesToDownload = [model.database, ...model.geometry];
51
+
52
+ console.time("File load time");
53
+
54
+ for (let i = 0; i < filesToDownload.length; i++) {
55
+ const dataId = filesToDownload[i];
56
+
57
+ const progress = (progress: number) => {
58
+ const data = (i + progress) / filesToDownload.length;
59
+ this.viewer.emitEvent({ type: "geometryprogress", data, file: model.file, model });
60
+ };
61
+
62
+ const arrayBuffer = await model.downloadResource(dataId, progress, this.abortController.signal);
63
+ if (!this.viewer.visualizeJs) return this;
64
+
65
+ const data = new Uint8Array(arrayBuffer);
66
+ visViewer.parseStream(data);
67
+
68
+ if (i === 0) {
69
+ this.viewer.update(true);
70
+
71
+ this.viewer.syncOpenCloudVisualStyle(false);
72
+ this.viewer.syncOptions();
73
+ this.viewer.syncOverlay();
74
+ this.viewer.resize();
75
+
76
+ this.viewer.emitEvent({ type: "databasechunk", data, file: model.file, model });
77
+ } else {
78
+ this.viewer.update();
79
+ this.viewer.emitEvent({ type: "geometrychunk", data, file: model.file, model });
80
+ }
81
+ }
82
+
83
+ console.timeEnd("File load time");
84
+
85
+ return this;
86
+ }
87
+ }
@@ -0,0 +1,58 @@
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
+ import { Loader } from "@inweb/viewer-core";
25
+ import { Viewer } from "../Viewer";
26
+
27
+ export class VSFXBufferLoader extends Loader {
28
+ public viewer: Viewer;
29
+
30
+ constructor(viewer: Viewer) {
31
+ super();
32
+ this.viewer = viewer;
33
+ }
34
+
35
+ override isSupport(file: any, format?: string): boolean {
36
+ return file instanceof ArrayBuffer && /vsfx$/i.test(format);
37
+ }
38
+
39
+ override load(buffer: any, format?: string): Promise<this> {
40
+ if (!this.viewer.visualizeJs) return Promise.resolve(this);
41
+
42
+ const visLib = this.viewer.visLib();
43
+ const visViewer = visLib.getViewer();
44
+
45
+ const data = new Uint8Array(buffer);
46
+ visViewer.parseVsfx(data);
47
+
48
+ this.viewer.syncOpenCloudVisualStyle(false);
49
+ this.viewer.syncOptions();
50
+ this.viewer.syncOverlay();
51
+ this.viewer.resize();
52
+
53
+ this.viewer.emitEvent({ type: "geometryprogress", data: 1, file: buffer });
54
+ this.viewer.emitEvent({ type: "databasechunk", data, file: buffer });
55
+
56
+ return Promise.resolve(this);
57
+ }
58
+ }
@@ -21,54 +21,54 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { BaseLoader } from "./BaseLoader";
24
+ import { Loader } from "@inweb/viewer-core";
25
+ import { Viewer } from "../Viewer";
25
26
 
26
- export class VsfXLoader extends BaseLoader {
27
- override async load(): Promise<void> {
28
- if (!this.viewer.visualizeJs) return;
27
+ export class VSFXModelLoader extends Loader {
28
+ public viewer: Viewer;
29
+
30
+ constructor(viewer: Viewer) {
31
+ super();
32
+ this.viewer = viewer;
33
+ }
34
+
35
+ override isSupport(file: any): boolean {
36
+ return (
37
+ typeof file === "object" &&
38
+ typeof file.database === "string" &&
39
+ typeof file.downloadResource === "function" &&
40
+ /.vsfx$/i.test(file.database) &&
41
+ this.viewer.options.enableStreamingMode === false
42
+ );
43
+ }
44
+
45
+ override async load(model: any, format?: string, params: any = {}): Promise<this> {
46
+ if (!this.viewer.visualizeJs) return Promise.resolve(this);
29
47
 
30
48
  const visLib = this.viewer.visLib();
31
49
  const visViewer = visLib.getViewer();
32
- const abortController = new AbortController();
33
-
34
- this.viewer._abortController = abortController;
35
50
 
36
- const chunkLoadHandler = (progress: number) => {
37
- this.viewer.emitEvent({ type: "geometryprogress", data: progress, model: this.model });
51
+ const progress = (progress: number) => {
52
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
38
53
  };
39
54
 
40
55
  console.time("File load time");
41
- try {
42
- this.viewer.emitEvent({ type: "geometrystart", model: this.model });
43
-
44
- const arrayBuffer = await this.model.downloadResource(
45
- this.model.database,
46
- chunkLoadHandler,
47
- abortController.signal
48
- );
49
56
 
50
- if (abortController.signal.aborted) {
51
- await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
52
- }
57
+ const arrayBuffer = await model.downloadResource(model.database, progress, this.abortController.signal);
58
+ if (!this.viewer.visualizeJs) return this;
53
59
 
54
- const data = new Uint8Array(arrayBuffer);
60
+ const data = new Uint8Array(arrayBuffer);
61
+ visViewer.parseVsfx(data);
55
62
 
56
- if (this.viewer.visualizeJs) {
57
- visViewer.parseVsfx(data);
63
+ this.viewer.syncOpenCloudVisualStyle(false);
64
+ this.viewer.syncOptions();
65
+ this.viewer.syncOverlay();
66
+ this.viewer.resize();
58
67
 
59
- this.viewer.syncOpenCloudVisualStyle(false);
60
- this.viewer.syncOptions();
61
- this.viewer.syncOverlay();
62
- this.viewer.resize();
63
- }
68
+ this.viewer.emitEvent({ type: "databasechunk", data, file: model.file, model });
64
69
 
65
- console.timeEnd("File load time");
70
+ console.timeEnd("File load time");
66
71
 
67
- this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
68
- this.viewer.emitEvent({ type: "geometryend", model: this.model });
69
- } catch (error: any) {
70
- this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
71
- throw error;
72
- }
72
+ return this;
73
73
  }
74
74
  }