@inweb/viewer-visualize 26.9.1 → 26.9.3
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.
- package/dist/viewer-visualize.js +1439 -1367
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +274 -239
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Components/ResizeCanvasComponent.d.ts +1 -1
- package/lib/Viewer/Loaders/index.d.ts +1 -2
- package/lib/Viewer/Viewer.d.ts +6 -4
- package/package.json +5 -5
- package/src/Viewer/Commands/ApplyModelTransform.ts +1 -1
- package/src/Viewer/Commands/AutoTransformAllModelsToCentralPoint.ts +1 -1
- package/src/Viewer/Commands/SetSelected.ts +1 -1
- package/src/Viewer/Components/ResizeCanvasComponent.ts +6 -2
- package/src/Viewer/Draggers/Actions/OrbitAction.ts +6 -0
- package/src/Viewer/Draggers/Actions/PanAction.ts +3 -0
- package/src/Viewer/Draggers/Actions/ZoomAction.ts +4 -0
- package/src/Viewer/Draggers/OdaWalkDragger.ts +4 -0
- package/src/Viewer/Loaders/VSFCloudLoader.ts +10 -9
- package/src/Viewer/Loaders/VSFFileLoader.ts +12 -7
- package/src/Viewer/Loaders/VSFXCloudLoader.ts +4 -6
- package/src/Viewer/Loaders/VSFXCloudPartialLoader.ts +6 -11
- package/src/Viewer/Loaders/VSFXCloudStreamingLoader.ts +7 -11
- package/src/Viewer/Loaders/VSFXFileLoader.ts +12 -7
- package/src/Viewer/Loaders/index.ts +1 -2
- package/src/Viewer/Markup/Visualize/VisualizeMarkup.ts +2 -2
- package/src/Viewer/Viewer.ts +95 -79
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -67,14 +67,15 @@ export class Viewer
|
|
|
67
67
|
private _activeDragger: IDragger | null;
|
|
68
68
|
private _components: Array<IComponent>;
|
|
69
69
|
private _enableAutoUpdate: boolean;
|
|
70
|
-
private
|
|
71
|
-
private _isRunAsyncUpdate: boolean;
|
|
70
|
+
private _renderNeeded: boolean;
|
|
72
71
|
private _renderTime: DOMHighResTimeStamp;
|
|
72
|
+
private _isRunAsyncUpdate: boolean;
|
|
73
73
|
|
|
74
74
|
protected _options: Options;
|
|
75
75
|
protected _visualizeJsUrl = "";
|
|
76
76
|
protected _visualizeJs: any;
|
|
77
77
|
protected _visualizeTimestamp: number;
|
|
78
|
+
protected _viewer: any;
|
|
78
79
|
protected _crossOrigin;
|
|
79
80
|
|
|
80
81
|
private canvaseventlistener: (event: Event) => void;
|
|
@@ -126,7 +127,7 @@ export class Viewer
|
|
|
126
127
|
this.canvaseventlistener = (event: Event) => this.emit(event);
|
|
127
128
|
|
|
128
129
|
this._enableAutoUpdate = params.enableAutoUpdate ?? true;
|
|
129
|
-
this.
|
|
130
|
+
this._renderNeeded = false;
|
|
130
131
|
this._isRunAsyncUpdate = false;
|
|
131
132
|
|
|
132
133
|
this.render = this.render.bind(this);
|
|
@@ -196,16 +197,19 @@ export class Viewer
|
|
|
196
197
|
async initialize(canvas: HTMLCanvasElement, onProgress?: (event: ProgressEvent) => void): Promise<this> {
|
|
197
198
|
this.addEventListener("optionschange", (event) => this.syncOptions(event.data));
|
|
198
199
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
const rect = canvas.parentElement.getBoundingClientRect();
|
|
201
|
+
const width = rect.width || 1;
|
|
202
|
+
const height = rect.height || 1;
|
|
203
|
+
|
|
204
|
+
canvas.width = Math.round(width * window.devicePixelRatio);
|
|
205
|
+
canvas.height = Math.round(height * window.devicePixelRatio);
|
|
206
|
+
|
|
207
|
+
canvas.style.width = width + "px";
|
|
208
|
+
canvas.style.height = height + "px";
|
|
209
|
+
|
|
203
210
|
canvas.parentElement.style.touchAction = "none";
|
|
204
211
|
canvas.style.touchAction = "none";
|
|
205
212
|
|
|
206
|
-
canvas.width = canvas.clientWidth * window.devicePixelRatio;
|
|
207
|
-
canvas.height = canvas.clientHeight * window.devicePixelRatio;
|
|
208
|
-
|
|
209
213
|
this._visualizeTimestamp = Date.now();
|
|
210
214
|
const visualizeTimestamp = this._visualizeTimestamp;
|
|
211
215
|
|
|
@@ -225,9 +229,10 @@ export class Viewer
|
|
|
225
229
|
);
|
|
226
230
|
|
|
227
231
|
this._visualizeJs = visualizeJs;
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
this.visualizeJs.
|
|
232
|
+
this._visualizeJs.canvas = canvas;
|
|
233
|
+
|
|
234
|
+
this._viewer = visualizeJs.Viewer.create();
|
|
235
|
+
this._viewer.resize(0, canvas.width, canvas.height, 0);
|
|
231
236
|
|
|
232
237
|
this.canvas = canvas;
|
|
233
238
|
this.canvasEvents.forEach((x) => canvas.addEventListener(x, this.canvaseventlistener));
|
|
@@ -238,7 +243,6 @@ export class Viewer
|
|
|
238
243
|
this._components.push(components.createComponent(name, this));
|
|
239
244
|
}
|
|
240
245
|
|
|
241
|
-
this.syncOpenCloudVisualStyle(true);
|
|
242
246
|
this.syncOptions();
|
|
243
247
|
this.syncOverlay();
|
|
244
248
|
|
|
@@ -269,10 +273,11 @@ export class Viewer
|
|
|
269
273
|
this.canvas = undefined;
|
|
270
274
|
}
|
|
271
275
|
|
|
272
|
-
if (this.
|
|
276
|
+
if (this._viewer) this._viewer.clear();
|
|
273
277
|
|
|
274
278
|
this._visualizeJs = undefined;
|
|
275
279
|
this._visualizeTimestamp = undefined;
|
|
280
|
+
this._viewer = undefined;
|
|
276
281
|
|
|
277
282
|
return this;
|
|
278
283
|
}
|
|
@@ -284,40 +289,57 @@ export class Viewer
|
|
|
284
289
|
return !!this.visualizeJs;
|
|
285
290
|
}
|
|
286
291
|
|
|
292
|
+
setSize(width: number, height: number, updateStyle = true): void {
|
|
293
|
+
if (!this.visualizeJs) return;
|
|
294
|
+
|
|
295
|
+
this.canvas.width = Math.round(width * window.devicePixelRatio);
|
|
296
|
+
this.canvas.height = Math.round(height * window.devicePixelRatio);
|
|
297
|
+
|
|
298
|
+
if (updateStyle) {
|
|
299
|
+
this.canvas.style.width = width + "px";
|
|
300
|
+
this.canvas.style.height = height + "px";
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
this._viewer.resize(0, this.canvas.width, this.canvas.height, 0);
|
|
304
|
+
|
|
305
|
+
this.update(true);
|
|
306
|
+
this.emitEvent({ type: "resize", width, height });
|
|
307
|
+
}
|
|
308
|
+
|
|
287
309
|
// internal render/resize routines
|
|
288
310
|
|
|
289
|
-
public render(time
|
|
311
|
+
public render(time?: DOMHighResTimeStamp) {
|
|
290
312
|
if (!this.visualizeJs) return;
|
|
291
|
-
|
|
292
313
|
if (this._isRunAsyncUpdate) return;
|
|
293
314
|
|
|
294
|
-
const
|
|
295
|
-
if (
|
|
296
|
-
visViewer.update();
|
|
297
|
-
this._activeDragger?.updatePreview?.();
|
|
298
|
-
this._isNeedRender = !visViewer.getActiveDevice().isValid();
|
|
315
|
+
const renderNeeded = this.visViewer().isRunningAnimation() || this._renderNeeded;
|
|
316
|
+
if (!renderNeeded) return;
|
|
299
317
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
318
|
+
if (!time) time = performance.now();
|
|
319
|
+
const deltaTime = (time - this._renderTime) / 1000;
|
|
320
|
+
|
|
321
|
+
this._renderTime = time;
|
|
322
|
+
this._renderNeeded = !this.visViewer().getActiveDevice().isValid();
|
|
323
|
+
|
|
324
|
+
this.visViewer().update();
|
|
325
|
+
this._activeDragger?.updatePreview?.();
|
|
326
|
+
|
|
327
|
+
this.emitEvent({ type: "render", time, deltaTime });
|
|
304
328
|
}
|
|
305
329
|
|
|
306
330
|
public resize(): this {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
331
|
+
console.warn(
|
|
332
|
+
"Viewer.resize() has been deprecated since 26.9 and will be removed in a future release, use Viewer.setSize() instead."
|
|
333
|
+
);
|
|
310
334
|
|
|
311
|
-
if (!
|
|
335
|
+
if (!this.visualizeJs) return this;
|
|
336
|
+
if (!this.canvas.parentElement) return this;
|
|
312
337
|
|
|
313
|
-
|
|
314
|
-
this.canvas.height = clientHeight * window.devicePixelRatio;
|
|
338
|
+
const { width, height } = this.canvas.parentElement.getBoundingClientRect();
|
|
315
339
|
|
|
316
|
-
|
|
317
|
-
visViewer.resize(0, this.canvas.width, this.canvas.height, 0);
|
|
340
|
+
if (!width || !height) return this; // <- invisible viewer, or viewer with parent removed
|
|
318
341
|
|
|
319
|
-
this.
|
|
320
|
-
this.emitEvent({ type: "resize", width: clientWidth, height: clientHeight });
|
|
342
|
+
this.setSize(width, height);
|
|
321
343
|
|
|
322
344
|
return this;
|
|
323
345
|
}
|
|
@@ -337,12 +359,8 @@ export class Viewer
|
|
|
337
359
|
*/
|
|
338
360
|
update(force = false) {
|
|
339
361
|
if (this._enableAutoUpdate) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
this._activeDragger?.updatePreview?.();
|
|
343
|
-
} else {
|
|
344
|
-
this._isNeedRender = true;
|
|
345
|
-
}
|
|
362
|
+
this._renderNeeded = true;
|
|
363
|
+
if (force) this.render();
|
|
346
364
|
}
|
|
347
365
|
this.emitEvent({ type: "update", data: force });
|
|
348
366
|
}
|
|
@@ -380,9 +398,11 @@ export class Viewer
|
|
|
380
398
|
* @param maxScheduleUpdateCount - Maximum count of scheduled updates.
|
|
381
399
|
*/
|
|
382
400
|
async updateAsync(maxScheduleUpdateTimeInMs = 50, maxScheduleUpdateCount = 50): Promise<void> {
|
|
401
|
+
if (!this.visualizeJs) return;
|
|
402
|
+
|
|
383
403
|
this._isRunAsyncUpdate = true;
|
|
384
|
-
const device = this.visViewer().getActiveDevice();
|
|
385
404
|
try {
|
|
405
|
+
const device = this.visViewer().getActiveDevice();
|
|
386
406
|
for (let iterationCount = 0; !device.isValid() && iterationCount < maxScheduleUpdateCount; iterationCount++) {
|
|
387
407
|
await this.scheduleUpdateAsync(maxScheduleUpdateTimeInMs);
|
|
388
408
|
}
|
|
@@ -407,7 +427,7 @@ export class Viewer
|
|
|
407
427
|
* instance.
|
|
408
428
|
*/
|
|
409
429
|
visLib(): any {
|
|
410
|
-
return this.
|
|
430
|
+
return this._visualizeJs;
|
|
411
431
|
}
|
|
412
432
|
|
|
413
433
|
/**
|
|
@@ -415,16 +435,16 @@ export class Viewer
|
|
|
415
435
|
* instance.
|
|
416
436
|
*/
|
|
417
437
|
visViewer(): any {
|
|
418
|
-
return this.
|
|
438
|
+
return this._viewer;
|
|
419
439
|
}
|
|
420
440
|
|
|
421
441
|
// update the VisualizeJS options
|
|
422
442
|
|
|
423
|
-
syncOpenCloudVisualStyle(
|
|
443
|
+
syncOpenCloudVisualStyle(): this {
|
|
424
444
|
if (!this.visualizeJs) return this;
|
|
425
445
|
|
|
426
446
|
const visLib = this.visLib();
|
|
427
|
-
const visViewer =
|
|
447
|
+
const visViewer = this.visViewer();
|
|
428
448
|
|
|
429
449
|
const device = visViewer.getActiveDevice();
|
|
430
450
|
if (device.isNull()) return this;
|
|
@@ -474,8 +494,10 @@ export class Viewer
|
|
|
474
494
|
syncOptions(options: IOptions = this.options): this {
|
|
475
495
|
if (!this.visualizeJs) return this;
|
|
476
496
|
|
|
497
|
+
this.syncOpenCloudVisualStyle();
|
|
498
|
+
|
|
477
499
|
const visLib = this.visLib();
|
|
478
|
-
const visViewer =
|
|
500
|
+
const visViewer = this.visViewer();
|
|
479
501
|
|
|
480
502
|
const device = visViewer.getActiveDevice();
|
|
481
503
|
if (device.isNull()) return this;
|
|
@@ -497,7 +519,7 @@ export class Viewer
|
|
|
497
519
|
visViewer.shadows = options.shadows;
|
|
498
520
|
|
|
499
521
|
const canvas = visLib.canvas;
|
|
500
|
-
device.invalidate([0, canvas.
|
|
522
|
+
device.invalidate([0, canvas.width, canvas.height, 0]);
|
|
501
523
|
}
|
|
502
524
|
|
|
503
525
|
if (options.groundShadow !== visViewer.groundShadow) {
|
|
@@ -550,7 +572,7 @@ export class Viewer
|
|
|
550
572
|
const params = options.enableCustomHighlight ? options : Options.defaults();
|
|
551
573
|
|
|
552
574
|
const visLib = this.visLib();
|
|
553
|
-
const visViewer =
|
|
575
|
+
const visViewer = this.visViewer();
|
|
554
576
|
const { Entry, OdTvRGBColorDef } = visLib;
|
|
555
577
|
|
|
556
578
|
const highlightStyleId = visViewer.findHighlightStyle("Web_Default");
|
|
@@ -593,7 +615,7 @@ export class Viewer
|
|
|
593
615
|
if (!device.isNull()) {
|
|
594
616
|
const canvas = visLib.canvas;
|
|
595
617
|
|
|
596
|
-
device.invalidate([0, canvas.
|
|
618
|
+
device.invalidate([0, canvas.width, canvas.height, 0]);
|
|
597
619
|
device.delete();
|
|
598
620
|
}
|
|
599
621
|
|
|
@@ -839,7 +861,7 @@ export class Viewer
|
|
|
839
861
|
if (!this.visualizeJs) return;
|
|
840
862
|
|
|
841
863
|
const visLib = this.visLib();
|
|
842
|
-
const visViewer =
|
|
864
|
+
const visViewer = this.visViewer();
|
|
843
865
|
|
|
844
866
|
const device = visViewer.getActiveDevice();
|
|
845
867
|
if (isExist(options.sceneGraph)) {
|
|
@@ -980,28 +1002,26 @@ export class Viewer
|
|
|
980
1002
|
this.cancel();
|
|
981
1003
|
this.clear();
|
|
982
1004
|
|
|
983
|
-
this.emitEvent({ type: "open", file: buffer });
|
|
1005
|
+
this.emitEvent({ type: "open", file: "", buffer });
|
|
984
1006
|
|
|
985
|
-
const
|
|
986
|
-
const visViewer = visLib.getViewer();
|
|
1007
|
+
const visViewer = this.visViewer();
|
|
987
1008
|
|
|
988
|
-
this.emitEvent({ type: "geometrystart", file: buffer });
|
|
1009
|
+
this.emitEvent({ type: "geometrystart", file: "", buffer });
|
|
989
1010
|
try {
|
|
990
1011
|
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
991
1012
|
visViewer.parseFile(data);
|
|
992
1013
|
|
|
993
|
-
this.syncOpenCloudVisualStyle(false);
|
|
994
1014
|
this.syncOptions();
|
|
995
1015
|
this.syncOverlay();
|
|
996
|
-
this.
|
|
1016
|
+
this.update(true);
|
|
997
1017
|
|
|
998
|
-
this.emitEvent({ type: "geometryprogress", data: 1, file: buffer });
|
|
999
|
-
this.emitEvent({ type: "databasechunk", data, file: buffer });
|
|
1018
|
+
this.emitEvent({ type: "geometryprogress", data: 1, file: "", buffer });
|
|
1019
|
+
this.emitEvent({ type: "databasechunk", data, file: "", buffer });
|
|
1000
1020
|
} catch (error: any) {
|
|
1001
|
-
this.emitEvent({ type: "geometryerror", data: error, file: buffer });
|
|
1021
|
+
this.emitEvent({ type: "geometryerror", data: error, file: "", buffer });
|
|
1002
1022
|
throw error;
|
|
1003
1023
|
}
|
|
1004
|
-
this.emitEvent({ type: "geometryend", file: buffer });
|
|
1024
|
+
this.emitEvent({ type: "geometryend", file: "", buffer });
|
|
1005
1025
|
|
|
1006
1026
|
return this;
|
|
1007
1027
|
}
|
|
@@ -1021,28 +1041,26 @@ export class Viewer
|
|
|
1021
1041
|
this.cancel();
|
|
1022
1042
|
this.clear();
|
|
1023
1043
|
|
|
1024
|
-
this.emitEvent({ type: "open", file: buffer });
|
|
1044
|
+
this.emitEvent({ type: "open", file: "", buffer });
|
|
1025
1045
|
|
|
1026
|
-
const
|
|
1027
|
-
const visViewer = visLib.getViewer();
|
|
1046
|
+
const visViewer = this.visViewer();
|
|
1028
1047
|
|
|
1029
|
-
this.emitEvent({ type: "geometrystart", file: buffer });
|
|
1048
|
+
this.emitEvent({ type: "geometrystart", file: "", buffer });
|
|
1030
1049
|
try {
|
|
1031
1050
|
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
1032
1051
|
visViewer.parseVsfx(data);
|
|
1033
1052
|
|
|
1034
|
-
this.syncOpenCloudVisualStyle(false);
|
|
1035
1053
|
this.syncOptions();
|
|
1036
1054
|
this.syncOverlay();
|
|
1037
|
-
this.
|
|
1055
|
+
this.update(true);
|
|
1038
1056
|
|
|
1039
|
-
this.emitEvent({ type: "geometryprogress", data: 1, file: buffer });
|
|
1040
|
-
this.emitEvent({ type: "databasechunk", data, file: buffer });
|
|
1057
|
+
this.emitEvent({ type: "geometryprogress", data: 1, file: "", buffer });
|
|
1058
|
+
this.emitEvent({ type: "databasechunk", data, file: "", buffer });
|
|
1041
1059
|
} catch (error: any) {
|
|
1042
|
-
this.emitEvent({ type: "geometryerror", data: error, file: buffer });
|
|
1060
|
+
this.emitEvent({ type: "geometryerror", data: error, file: "", buffer });
|
|
1043
1061
|
throw error;
|
|
1044
1062
|
}
|
|
1045
|
-
this.emitEvent({ type: "geometryend", file: buffer });
|
|
1063
|
+
this.emitEvent({ type: "geometryend", file: "", buffer });
|
|
1046
1064
|
|
|
1047
1065
|
return this;
|
|
1048
1066
|
}
|
|
@@ -1060,24 +1078,22 @@ export class Viewer
|
|
|
1060
1078
|
clear(): this {
|
|
1061
1079
|
if (!this.visualizeJs) return this;
|
|
1062
1080
|
|
|
1063
|
-
const
|
|
1064
|
-
const visViewer = visLib.getViewer();
|
|
1081
|
+
const visViewer = this.visViewer();
|
|
1065
1082
|
|
|
1066
1083
|
this.setActiveDragger();
|
|
1067
1084
|
this.clearSlices();
|
|
1068
1085
|
this.clearOverlay();
|
|
1069
1086
|
this.clearSelected();
|
|
1070
1087
|
|
|
1071
|
-
visViewer.clear();
|
|
1072
|
-
visViewer.createLocalDatabase();
|
|
1073
|
-
|
|
1074
1088
|
this.loaders.forEach((loader) => loader.dispose());
|
|
1075
1089
|
this.loaders = [];
|
|
1076
1090
|
|
|
1077
|
-
|
|
1091
|
+
visViewer.clear();
|
|
1092
|
+
visViewer.createLocalDatabase();
|
|
1093
|
+
|
|
1078
1094
|
this.syncOptions();
|
|
1079
1095
|
this.syncOverlay();
|
|
1080
|
-
this.
|
|
1096
|
+
this.update(true);
|
|
1081
1097
|
|
|
1082
1098
|
this.emitEvent({ type: "clear" });
|
|
1083
1099
|
|