@inweb/viewer-visualize 25.3.18 → 25.3.20

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.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Convert world coordinates to screen normalized (-1, 1)
3
+ *
4
+ * @param viewMatrix Camera world matrix
5
+ * @param projectionMatrix Camera projection matrix
6
+ * @param worldPoint World point
7
+ */
8
+ export declare function worldToScreenNormalized(viewMatrix: Array<number>, projectionMatrix: Array<number>, worldPoint: [x: number, y: number, z: number]): [x: number, y: number, z: number];
9
+ export declare function multiplyMatrices(a: Array<number>, b: Array<number>): Array<number>;
10
+ /**
11
+ * @param matrix
12
+ * @returns Matrix
13
+ */
14
+ export declare function invertMatrix(matrix: Array<number>): Array<number>;
15
+ /**
16
+ * Convert world coordinates to screen (screenWidth, screenHeight)
17
+ *
18
+ * @param viewMatrix Camera world matrix
19
+ * @param projectionMatrix Camera projection matrix
20
+ * @param worldPoint World point
21
+ * @param screenWidth Screen width
22
+ * @param screenHeight Screen height
23
+ */
24
+ export declare function worldToScreen(viewMatrix: Array<number>, projectionMatrix: Array<number>, worldPoint: [x: number, y: number, z: number], screenWidth: number, screenHeight: number): number[];
25
+ export declare function createOrthoProjectionMatrix(camera: any, width: any, height: any): number[];
26
+ export declare function createViewMatrix(camera: any): any[];
27
+ export declare function bcfWorldToScreenFromCamera(camera: any, canvas: HTMLCanvasElement, point: [x: number, y: number, z: number]): number[];
28
+ export declare function matrixLookAt(matrix: any, eye: any, target: any, up: any): any;
@@ -1,10 +1,10 @@
1
1
  import { Model } from "@inweb/client";
2
- import { OptionsData } from "@inweb/viewer-core";
2
+ import { IOptions } from "@inweb/viewer-core";
3
3
  import { Viewer } from "../Viewer";
4
4
  export declare class BaseLoader {
5
5
  protected viewer: Viewer;
6
6
  protected model: Model;
7
- protected options: OptionsData;
8
- constructor(viewer: Viewer, model: Model, options: OptionsData);
7
+ protected options: IOptions;
8
+ constructor(viewer: Viewer, model: Model, options: IOptions);
9
9
  load(): Promise<void>;
10
10
  }
@@ -1,10 +1,10 @@
1
1
  import { Model } from "@inweb/client";
2
- import { OptionsData } from "@inweb/viewer-core";
2
+ import { IOptions } from "@inweb/viewer-core";
3
3
  import { TCSLoader } from "./TCSLoader";
4
+ import { VsfXLoader } from "./VsfXLoader";
4
5
  import { VsfXStreamingLoader } from "./VsfXStreamingLoader";
5
6
  import { VsfXPartialLoader } from "./VsfXPartialLoader";
6
7
  import { Viewer } from "../Viewer";
7
- import { VsfXLoader } from "./VsfXLoader";
8
8
  export declare class LoaderFactory {
9
- create(viewer: Viewer, model: Model, options: OptionsData): TCSLoader | VsfXStreamingLoader | VsfXPartialLoader | VsfXLoader;
9
+ create(viewer: Viewer, model: Model, options: IOptions): TCSLoader | VsfXLoader | VsfXStreamingLoader | VsfXPartialLoader;
10
10
  }
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter2 } from "@inweb/eventemitter2";
2
2
  import { Assembly, Client, File, Model } from "@inweb/client";
3
- import { IViewpoint, IViewer, Options, OptionsData, OptionsEventMap, ViewerEventMap } from "@inweb/viewer-core";
3
+ import { IOptions, IViewpoint, IViewer, Options, OptionsEventMap, ViewerEventMap } from "@inweb/viewer-core";
4
4
  import { OdBaseDragger } from "./Draggers/Common/OdBaseDragger";
5
5
  import { IMarkup, MarkupType } from "./Markup/IMarkup";
6
6
  /**
@@ -28,7 +28,7 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & OptionsEventM
28
28
  visualizeJs: any;
29
29
  _abortController: AbortController | undefined;
30
30
  _abortControllerForRequestMap: Map<string, AbortController> | undefined;
31
- client: Client;
31
+ client: Client | undefined;
32
32
  /**
33
33
  * @param client - The `Client` instance that provides access to a server. Do not specify
34
34
  * `Client` if you need a standalone viewer instance without access to server models.
@@ -133,8 +133,8 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & OptionsEventM
133
133
  */
134
134
  visViewer(): any;
135
135
  syncOpenCloudVisualStyle(isInitializing: boolean): this;
136
- syncOptions(options?: OptionsData): this;
137
- syncHighlightingOptions(options?: OptionsData): this;
136
+ syncOptions(options?: IOptions): this;
137
+ syncHighlightingOptions(options?: IOptions): this;
138
138
  /**
139
139
  * List of names of available draggers:
140
140
  *
@@ -1,3 +1,2 @@
1
- export declare function loadScript(url: string): Promise<unknown>;
2
- export declare const memoize: (f: any) => (...args: any[]) => any;
3
- export declare const loadVisualizeJs: (url: string, onprogress: any) => Promise<unknown>;
1
+ export declare function loadScript(url: string): Promise<HTMLScriptElement>;
2
+ export declare const loadVisualizeJs: (url: string, onprogress: any) => Promise<any>;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./Viewer/Commands";
2
- export { commands, Options } from "@inweb/viewer-core";
2
+ export * from "@inweb/viewer-core";
3
3
  export { Viewer } from "./Viewer/Viewer";
4
4
  export { OdBaseDragger } from "./Viewer/Draggers/Common/OdBaseDragger";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "25.3.18",
3
+ "version": "25.3.20",
4
4
  "description": "3D CAD and BIM data Viewer powered by Visualize",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -28,9 +28,9 @@
28
28
  "test": "karma start karma.conf.js"
29
29
  },
30
30
  "dependencies": {
31
- "@inweb/client": "^25.3.13",
32
- "@inweb/eventemitter2": "^25.3.13",
33
- "@inweb/viewer-core": "^25.3.13"
31
+ "@inweb/client": "^25.3.19",
32
+ "@inweb/eventemitter2": "^25.3.19",
33
+ "@inweb/viewer-core": "^25.3.19"
34
34
  },
35
35
  "devDependencies": {
36
36
  "canvas": "^2.11.2",
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Convert world coordinates to screen normalized (-1, 1)
3
+ *
4
+ * @param viewMatrix Camera world matrix
5
+ * @param projectionMatrix Camera projection matrix
6
+ * @param worldPoint World point
7
+ */
8
+ export function worldToScreenNormalized(
9
+ viewMatrix: Array<number>,
10
+ projectionMatrix: Array<number>,
11
+ worldPoint: [x: number, y: number, z: number]
12
+ ): [x: number, y: number, z: number] {
13
+ function applyMatrixToPoint3(matrix, point: [x: number, y: number, z: number]): [x: number, y: number, z: number] {
14
+ const [x, y, z] = point;
15
+ const e = matrix;
16
+ const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
17
+
18
+ return [
19
+ (e[0] * x + e[4] * y + e[8] * z + e[12]) * w,
20
+ (e[1] * x + e[5] * y + e[9] * z + e[13]) * w,
21
+ (e[2] * x + e[6] * y + e[10] * z + e[14]) * w,
22
+ ];
23
+ }
24
+
25
+ const [x, y, z] = applyMatrixToPoint3(projectionMatrix, applyMatrixToPoint3(invertMatrix(viewMatrix), worldPoint));
26
+
27
+ return [x, y, z];
28
+ }
29
+
30
+ export function multiplyMatrices(a: Array<number>, b: Array<number>): Array<number> {
31
+ const ae = a;
32
+ const be = b;
33
+ const te = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
34
+
35
+ const a11 = ae[0],
36
+ a12 = ae[4],
37
+ a13 = ae[8],
38
+ a14 = ae[12];
39
+ const a21 = ae[1],
40
+ a22 = ae[5],
41
+ a23 = ae[9],
42
+ a24 = ae[13];
43
+ const a31 = ae[2],
44
+ a32 = ae[6],
45
+ a33 = ae[10],
46
+ a34 = ae[14];
47
+ const a41 = ae[3],
48
+ a42 = ae[7],
49
+ a43 = ae[11],
50
+ a44 = ae[15];
51
+
52
+ const b11 = be[0],
53
+ b12 = be[4],
54
+ b13 = be[8],
55
+ b14 = be[12];
56
+ const b21 = be[1],
57
+ b22 = be[5],
58
+ b23 = be[9],
59
+ b24 = be[13];
60
+ const b31 = be[2],
61
+ b32 = be[6],
62
+ b33 = be[10],
63
+ b34 = be[14];
64
+ const b41 = be[3],
65
+ b42 = be[7],
66
+ b43 = be[11],
67
+ b44 = be[15];
68
+
69
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
70
+ te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
71
+ te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
72
+ te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
73
+
74
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
75
+ te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
76
+ te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
77
+ te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
78
+
79
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
80
+ te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
81
+ te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
82
+ te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
83
+
84
+ te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
85
+ te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
86
+ te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
87
+ te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
88
+
89
+ return te;
90
+ }
91
+
92
+ /**
93
+ * @param matrix
94
+ * @returns Matrix
95
+ */
96
+ export function invertMatrix(matrix: Array<number>): Array<number> {
97
+ const te = matrix,
98
+ n11 = te[0],
99
+ n21 = te[1],
100
+ n31 = te[2],
101
+ n41 = te[3],
102
+ n12 = te[4],
103
+ n22 = te[5],
104
+ n32 = te[6],
105
+ n42 = te[7],
106
+ n13 = te[8],
107
+ n23 = te[9],
108
+ n33 = te[10],
109
+ n43 = te[11],
110
+ n14 = te[12],
111
+ n24 = te[13],
112
+ n34 = te[14],
113
+ n44 = te[15],
114
+ t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
115
+ t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
116
+ t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
117
+ t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
118
+
119
+ const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
120
+
121
+ if (det === 0) return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
122
+
123
+ const detInv = 1 / det;
124
+
125
+ return [
126
+ t11 * detInv,
127
+ (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) *
128
+ detInv,
129
+ (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) *
130
+ detInv,
131
+ (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) *
132
+ detInv,
133
+
134
+ t12 * detInv,
135
+ (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) *
136
+ detInv,
137
+ (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) *
138
+ detInv,
139
+ (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) *
140
+ detInv,
141
+
142
+ t13 * detInv,
143
+ (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) *
144
+ detInv,
145
+ (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) *
146
+ detInv,
147
+ (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) *
148
+ detInv,
149
+
150
+ t14 * detInv,
151
+ (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) *
152
+ detInv,
153
+ (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) *
154
+ detInv,
155
+ (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) *
156
+ detInv,
157
+ ];
158
+ }
159
+
160
+ /**
161
+ * Convert world coordinates to screen (screenWidth, screenHeight)
162
+ *
163
+ * @param viewMatrix Camera world matrix
164
+ * @param projectionMatrix Camera projection matrix
165
+ * @param worldPoint World point
166
+ * @param screenWidth Screen width
167
+ * @param screenHeight Screen height
168
+ */
169
+ export function worldToScreen(
170
+ viewMatrix: Array<number>,
171
+ projectionMatrix: Array<number>,
172
+ worldPoint: [x: number, y: number, z: number],
173
+ screenWidth: number,
174
+ screenHeight: number
175
+ ): number[] {
176
+ const widthHalf = screenWidth / 2;
177
+ const heightHalf = screenHeight / 2;
178
+
179
+ const [x, y] = worldToScreenNormalized(viewMatrix, projectionMatrix, worldPoint);
180
+ const p = [x * widthHalf + widthHalf, -(y * heightHalf) + heightHalf];
181
+ return p;
182
+ }
183
+
184
+ /**
185
+ * @param a
186
+ * @returns
187
+ */
188
+ function lengthVector(a: { x: number; y: number; z: number }): number {
189
+ return Math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
190
+ }
191
+
192
+ function normalizeVector(a: { x: number; y: number; z: number }): { x: number; y: number; z: number } {
193
+ const len = lengthVector(a);
194
+ if (len === 0) return a;
195
+ return {
196
+ x: a.x / len,
197
+ y: a.y / len,
198
+ z: a.z / len,
199
+ };
200
+ }
201
+
202
+ function crossVectors(a, b) {
203
+ const ax = a.x,
204
+ ay = a.y,
205
+ az = a.z;
206
+ const bx = b.x,
207
+ by = b.y,
208
+ bz = b.z;
209
+
210
+ return {
211
+ x: ay * bz - az * by,
212
+ y: az * bx - ax * bz,
213
+ z: ax * by - ay * bx,
214
+ };
215
+ }
216
+
217
+ function normalizedProjection(
218
+ width,
219
+ height,
220
+ nearClipPlaneDist,
221
+ farClipPlaneDist,
222
+ normalizedCenter,
223
+ normalizedWidth,
224
+ normalizedHeight,
225
+ normalizedDepth
226
+ ) {
227
+ const mtx = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
228
+
229
+ mtx[0] = -normalizedWidth / width;
230
+ mtx[1] = 0;
231
+ mtx[2] = 0.0;
232
+ mtx[3] = normalizedCenter.x;
233
+
234
+ mtx[4] = 0.0;
235
+ mtx[5] = -normalizedHeight / height;
236
+ mtx[6] = 0.0;
237
+ mtx[7] = normalizedCenter.y;
238
+
239
+ mtx[8] = 0;
240
+ mtx[9] = 0.0;
241
+ mtx[10] = normalizedDepth / (farClipPlaneDist - nearClipPlaneDist);
242
+ mtx[11] = -mtx[10] * nearClipPlaneDist;
243
+
244
+ mtx[12] = mtx[13] = mtx[14] = 0.0;
245
+ mtx[15] = 1.0;
246
+
247
+ return mtx;
248
+ }
249
+
250
+ export function createOrthoProjectionMatrix(camera, width, height) {
251
+ const nearClipPlaneDist = 0.1;
252
+ const farClipPlaneDist = 1000;
253
+ const fieldWidth = camera.field_width;
254
+ const fieldHeight = camera.field_height;
255
+ let viewportNormalizedWidth = 2;
256
+ let viewportNormalizedHeight = 2;
257
+
258
+ if (width > height) {
259
+ const aspect = height / width;
260
+ const aspectFiled = fieldHeight / fieldWidth;
261
+ viewportNormalizedWidth = (2 / aspectFiled) * aspect;
262
+ viewportNormalizedHeight = 2;
263
+ } else {
264
+ const aspect = width / height;
265
+ const aspectFiled = fieldWidth / fieldHeight;
266
+ viewportNormalizedWidth = 2;
267
+ viewportNormalizedHeight = (2 / aspectFiled) * aspect;
268
+ }
269
+
270
+ const viewportNormalizedCenter = {
271
+ x: 0,
272
+ y: 0,
273
+ };
274
+
275
+ const projectionMatrix = normalizedProjection(
276
+ fieldWidth,
277
+ fieldHeight,
278
+ nearClipPlaneDist,
279
+ farClipPlaneDist,
280
+ viewportNormalizedCenter,
281
+ viewportNormalizedWidth,
282
+ viewportNormalizedHeight,
283
+ 1.0
284
+ );
285
+
286
+ return projectionMatrix;
287
+ }
288
+
289
+ export function createViewMatrix(camera) {
290
+ const position = camera.view_point;
291
+
292
+ const viewMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, position.x, position.y, position.z, 1];
293
+
294
+ const target = addVectors(camera.direction, position);
295
+
296
+ matrixLookAt(viewMatrix, position, target, camera.up_vector);
297
+
298
+ return viewMatrix;
299
+ }
300
+
301
+ export function bcfWorldToScreenFromCamera(
302
+ camera,
303
+ canvas: HTMLCanvasElement,
304
+ point: [x: number, y: number, z: number]
305
+ ) {
306
+ const { width, height } = canvas;
307
+
308
+ if (lengthVector(camera.direction) >= 1.0001) {
309
+ camera = {
310
+ ...camera,
311
+ direction: normalizeVector(subVectors(camera.direction, camera.view_point)),
312
+ };
313
+ }
314
+
315
+ const projectionMatrix = createOrthoProjectionMatrix(camera, width, height);
316
+ const viewMatrix = createViewMatrix(camera);
317
+
318
+ return worldToScreen(viewMatrix, projectionMatrix, point, width, height);
319
+ }
320
+
321
+ function subVectors(
322
+ a: { x: number; y: number; z: number },
323
+ b: { x: number; y: number; z: number }
324
+ ): { x: number; y: number; z: number } {
325
+ return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
326
+ }
327
+
328
+ function addVectors(
329
+ a: { x: number; y: number; z: number },
330
+ b: { x: number; y: number; z: number }
331
+ ): { x: number; y: number; z: number } {
332
+ return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
333
+ }
334
+
335
+ export function matrixLookAt(matrix, eye, target, up) {
336
+ let z = subVectors(eye, target);
337
+
338
+ if (lengthVector(z) === 0) {
339
+ z.z = 1;
340
+ }
341
+ z = normalizeVector(z);
342
+
343
+ let x = crossVectors(z, up);
344
+ if (lengthVector(x) === 0) {
345
+ if (Math.abs(up.z) === 1) {
346
+ z.x += 0.0001;
347
+ } else {
348
+ z.z += 0.0001;
349
+ }
350
+
351
+ z = normalizeVector(z);
352
+
353
+ x = crossVectors(up, z);
354
+ }
355
+
356
+ x = normalizeVector(x);
357
+
358
+ const y = crossVectors(z, x);
359
+
360
+ const m = matrix;
361
+
362
+ m[0] = x.x;
363
+ m[4] = y.x;
364
+ m[8] = z.x;
365
+ m[1] = x.y;
366
+ m[5] = y.y;
367
+ m[9] = z.y;
368
+ m[2] = x.z;
369
+ m[6] = y.z;
370
+ m[10] = z.z;
371
+
372
+ return m;
373
+ }
@@ -22,15 +22,15 @@
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
24
  import { Model } from "@inweb/client";
25
- import { OptionsData } from "@inweb/viewer-core";
25
+ import { IOptions } from "@inweb/viewer-core";
26
26
  import { Viewer } from "../Viewer";
27
27
 
28
28
  export class BaseLoader {
29
29
  protected viewer: Viewer;
30
30
  protected model: Model;
31
- protected options: OptionsData;
31
+ protected options: IOptions;
32
32
 
33
- constructor(viewer: Viewer, model: Model, options: OptionsData) {
33
+ constructor(viewer: Viewer, model: Model, options: IOptions) {
34
34
  this.viewer = viewer;
35
35
  this.model = model;
36
36
  this.options = options;
@@ -22,16 +22,16 @@
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
24
  import { Model } from "@inweb/client";
25
- import { OptionsData } from "@inweb/viewer-core";
25
+ import { IOptions } from "@inweb/viewer-core";
26
26
 
27
27
  import { TCSLoader } from "./TCSLoader";
28
+ import { VsfXLoader } from "./VsfXLoader";
28
29
  import { VsfXStreamingLoader } from "./VsfXStreamingLoader";
29
30
  import { VsfXPartialLoader } from "./VsfXPartialLoader";
30
31
  import { Viewer } from "../Viewer";
31
- import { VsfXLoader } from "./VsfXLoader";
32
32
 
33
33
  export class LoaderFactory {
34
- create(viewer: Viewer, model: Model, options: OptionsData) {
34
+ create(viewer: Viewer, model: Model, options: IOptions) {
35
35
  const geometryType = model.database.split(".").pop();
36
36
 
37
37
  if (model.geometry.length === 0 && geometryType === "vsfx") {
@@ -43,6 +43,7 @@ export class LoaderFactory {
43
43
  if (geometryType === "data") {
44
44
  return new TCSLoader(viewer, model, options);
45
45
  }
46
+
46
47
  throw new Error(`Unknown geometry type: ${geometryType}`);
47
48
  }
48
49
  }
@@ -31,25 +31,23 @@ export class TCSLoader extends BaseLoader {
31
31
  const visViewer = visLib.getViewer();
32
32
  const abortController = new AbortController();
33
33
 
34
- const listFileForDownload = [this.model.database, ...this.model.geometry];
35
- const chunksProgress = listFileForDownload.map(() => 0);
36
-
37
- const calcProgress = (index, progress) => {
38
- chunksProgress[index] = progress;
39
- const fileProgress = chunksProgress.reduce((acc, progress) => (acc += progress)) / (chunksProgress.length || 1);
40
- this.viewer.emitEvent({ type: "geometryprogress", data: fileProgress, model: this.model });
41
- };
34
+ const filesToDownload = [this.model.database, ...this.model.geometry];
42
35
 
43
36
  this.viewer._abortController = abortController;
44
37
 
38
+ console.time("File load time");
45
39
  try {
46
40
  this.viewer.emitEvent({ type: "geometrystart", model: this.model });
47
41
 
48
- for (let i = 0; i < listFileForDownload.length; i++) {
49
- const chunk = listFileForDownload[i];
42
+ for (let i = 0; i < filesToDownload.length; i++) {
43
+ const dataId = filesToDownload[i];
44
+
45
+ const chunkLoadHandler = (progress: number) => {
46
+ const data = (i + progress) / filesToDownload.length;
47
+ this.viewer.emitEvent({ type: "geometryprogress", data, model: this.model });
48
+ };
50
49
 
51
- const progressCb = (progress) => calcProgress(i, progress);
52
- const arrayBuffer = await this.model.downloadResource(chunk, progressCb, abortController.signal);
50
+ const arrayBuffer = await this.model.downloadResource(dataId, chunkLoadHandler, abortController.signal);
53
51
 
54
52
  if (abortController.signal.aborted) {
55
53
  await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
@@ -73,6 +71,8 @@ export class TCSLoader extends BaseLoader {
73
71
  }
74
72
  }
75
73
 
74
+ console.timeEnd("File load time");
75
+
76
76
  this.viewer.emitEvent({ type: "geometryend", model: this.model });
77
77
  } catch (error) {
78
78
  this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
@@ -15,6 +15,7 @@ export class UpdaterController {
15
15
  public delayUpdateTime: number;
16
16
 
17
17
  constructor() {
18
+ this.lastUpdate = 0;
18
19
  this.delayUpdateTime = START_UPDATE_TIME;
19
20
  }
20
21
 
@@ -65,7 +65,7 @@ export class VsfXLoader extends BaseLoader {
65
65
 
66
66
  this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
67
67
  this.viewer.emitEvent({ type: "geometryend", model: this.model });
68
- } catch (error) {
68
+ } catch (error: any) {
69
69
  this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
70
70
  throw error;
71
71
  }