@inweb/viewer-visualize 25.8.15 → 25.8.19
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/README.md +41 -19
- package/dist/viewer-visualize.js +102 -92
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +40 -29
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Markup/MarkupFactory.d.ts +2 -6
- package/lib/Viewer/Viewer.d.ts +66 -63
- package/package.json +6 -6
- package/src/Viewer/Draggers/OdZoomDragger.ts +1 -1
- package/src/Viewer/Markup/MarkupFactory.ts +5 -9
- package/src/Viewer/Viewer.ts +82 -78
package/src/Viewer/Viewer.ts
CHANGED
|
@@ -62,7 +62,7 @@ const OVERLAY_VIEW_NAME = "$OVERLAY_VIEW_NAME";
|
|
|
62
62
|
const isExist = (value) => value !== undefined && value !== null;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* 3D viewer powered by
|
|
66
66
|
* {@link https://cloud.opendesign.com/docs/index.html#/visualizejs | VisualizeJS} library.
|
|
67
67
|
*/
|
|
68
68
|
|
|
@@ -98,19 +98,17 @@ export class Viewer
|
|
|
98
98
|
public client: Client | undefined;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
* @param client - The `Client` instance that provides access to a
|
|
102
|
-
* `Client` if you need a standalone viewer instance
|
|
101
|
+
* @param client - The `Client` instance that provides access to a Open Cloud Server. Do not
|
|
102
|
+
* specify `Client` if you need a standalone viewer instance to view `VSFX` files from the
|
|
103
|
+
* web or from local computer.
|
|
103
104
|
* @param params - An object containing viewer configuration parameters.
|
|
104
105
|
* @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own
|
|
105
|
-
* library instance, or
|
|
106
|
-
* `
|
|
107
|
-
*
|
|
108
|
-
* _Note: Your own `VisualizeJS` library version must match the version of the `Client.js`
|
|
109
|
-
* you are using._
|
|
106
|
+
* library instance, or specify `undefined` or blank to use the default URL defined by
|
|
107
|
+
* `Viewer.visualize` library you are using.
|
|
110
108
|
* @param params.enableAutoUpdate - Enable auto-update of the viewer after any changes. If
|
|
111
|
-
* the auto-update is disabled, you need to register
|
|
112
|
-
* the viewer and
|
|
113
|
-
* @param params.markupType -
|
|
109
|
+
* the auto-update is disabled, you need to register an `update` event handler and update
|
|
110
|
+
* the `VisualizeJS` viewer and active dragger manually. Default is `true`.
|
|
111
|
+
* @param params.markupType - The type of the markup core: `Visualize` (deprecated) or
|
|
114
112
|
* `Konva`. Default is `Konva`.
|
|
115
113
|
*/
|
|
116
114
|
constructor(
|
|
@@ -157,7 +155,7 @@ export class Viewer
|
|
|
157
155
|
/**
|
|
158
156
|
* Viewer options.
|
|
159
157
|
*/
|
|
160
|
-
get options():
|
|
158
|
+
get options(): IOptions {
|
|
161
159
|
return this._options;
|
|
162
160
|
}
|
|
163
161
|
|
|
@@ -171,7 +169,7 @@ export class Viewer
|
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
/**
|
|
174
|
-
* 2D markup core.
|
|
172
|
+
* 2D markup core instance used to create markups.
|
|
175
173
|
*
|
|
176
174
|
* @readonly
|
|
177
175
|
*/
|
|
@@ -180,11 +178,12 @@ export class Viewer
|
|
|
180
178
|
}
|
|
181
179
|
|
|
182
180
|
/**
|
|
183
|
-
*
|
|
181
|
+
* Changes the viewer parameters.
|
|
184
182
|
*
|
|
185
|
-
* @param params - An object containing new
|
|
183
|
+
* @param params - An object containing new parameters.
|
|
186
184
|
* @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own
|
|
187
|
-
* library instance or
|
|
185
|
+
* library instance or specify `undefined` or blank to use the default URL defined by
|
|
186
|
+
* `Viewer.visualize` library you are using.
|
|
188
187
|
*/
|
|
189
188
|
configure(params: { visualizeJsUrl?: string }): this {
|
|
190
189
|
this._visualizeJsUrl = params.visualizeJsUrl || "VISUALIZE_JS_URL";
|
|
@@ -192,7 +191,7 @@ export class Viewer
|
|
|
192
191
|
}
|
|
193
192
|
|
|
194
193
|
/**
|
|
195
|
-
*
|
|
194
|
+
* Loads the `VisualizeJS` module and initialize it with the specified canvas. Call
|
|
196
195
|
* {@link dispose | dispose()} to release allocated resources.
|
|
197
196
|
*
|
|
198
197
|
* Fires:
|
|
@@ -264,8 +263,8 @@ export class Viewer
|
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
/**
|
|
267
|
-
* Releases all resources allocated by this
|
|
268
|
-
*
|
|
266
|
+
* Releases all resources allocated by this viewer instance. Call this method before release
|
|
267
|
+
* the `Viewer` instance.
|
|
269
268
|
*/
|
|
270
269
|
dispose(): this {
|
|
271
270
|
this.cancel();
|
|
@@ -301,7 +300,7 @@ export class Viewer
|
|
|
301
300
|
}
|
|
302
301
|
|
|
303
302
|
/**
|
|
304
|
-
* Returns `true` if `VisualizeJS` module has been loaded
|
|
303
|
+
* Returns `true` if `VisualizeJS` module has been loaded and initialized.
|
|
305
304
|
*/
|
|
306
305
|
isInitialized(): boolean {
|
|
307
306
|
return !!this.visualizeJs;
|
|
@@ -345,8 +344,10 @@ export class Viewer
|
|
|
345
344
|
}
|
|
346
345
|
|
|
347
346
|
/**
|
|
348
|
-
* Updates the viewer.
|
|
349
|
-
*
|
|
347
|
+
* Updates the viewer.
|
|
348
|
+
*
|
|
349
|
+
* Do nothing if the auto-update mode is disabled in the constructor. In this case, register
|
|
350
|
+
* an `update` event handler and update the `Visualize` viewer and active dragger manually.
|
|
350
351
|
*
|
|
351
352
|
* Fires:
|
|
352
353
|
*
|
|
@@ -367,21 +368,15 @@ export class Viewer
|
|
|
367
368
|
this.emitEvent({ type: "update", data: force });
|
|
368
369
|
}
|
|
369
370
|
|
|
370
|
-
/**
|
|
371
|
-
* Update with internal schedule, need after change operation when have long update for
|
|
372
|
-
* update without lock UI
|
|
373
|
-
*
|
|
374
|
-
* @param maxScheduleUpdateTimeInMs - Maximum time for one update, by default 30 ms
|
|
375
|
-
* @param maxScheduleUpdateCount - Maximum count of schedule update
|
|
376
|
-
* @returns return void Promise
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
371
|
private scheduleUpdateAsync(maxScheduleUpdateTimeInMs = 50): Promise<void> {
|
|
380
372
|
return new Promise<void>((resolve, reject) => {
|
|
381
373
|
setTimeout(() => {
|
|
382
374
|
try {
|
|
383
|
-
this.
|
|
384
|
-
|
|
375
|
+
if (this._enableAutoUpdate) {
|
|
376
|
+
this.visViewer()?.update(maxScheduleUpdateTimeInMs);
|
|
377
|
+
this.activeDragger()?.updatePreview();
|
|
378
|
+
}
|
|
379
|
+
this.emitEvent({ type: "update", data: false });
|
|
385
380
|
resolve();
|
|
386
381
|
} catch (e) {
|
|
387
382
|
console.error(e);
|
|
@@ -391,6 +386,20 @@ export class Viewer
|
|
|
391
386
|
});
|
|
392
387
|
}
|
|
393
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Updates the viewer asynchronously without locking the user interface. Used to update the
|
|
391
|
+
* viewer after changes that require a long rendering time.
|
|
392
|
+
*
|
|
393
|
+
* Do nothing if the auto-update mode is disabled in the constructor. In this case, register
|
|
394
|
+
* an `update` event handler and update the `VisualizeJS` viewer and active dragger manually.
|
|
395
|
+
*
|
|
396
|
+
* Fires:
|
|
397
|
+
*
|
|
398
|
+
* - {@link UpdateEvent | update}
|
|
399
|
+
*
|
|
400
|
+
* @param maxScheduleUpdateTimeInMs - Maximum time for one update, default 30 ms.
|
|
401
|
+
* @param maxScheduleUpdateCount - Maximum count of scheduled updates.
|
|
402
|
+
*/
|
|
394
403
|
async updateAsync(maxScheduleUpdateTimeInMs = 50, maxScheduleUpdateCount = 50): Promise<void> {
|
|
395
404
|
this._isRunAsyncUpdate = true;
|
|
396
405
|
const device = this.visViewer().getActiveDevice();
|
|
@@ -611,7 +620,7 @@ export class Viewer
|
|
|
611
620
|
}
|
|
612
621
|
|
|
613
622
|
/**
|
|
614
|
-
* List of names of
|
|
623
|
+
* List of names of registered draggers. By default, the following draggers are registered:
|
|
615
624
|
*
|
|
616
625
|
* - `Line`
|
|
617
626
|
* - `Text`
|
|
@@ -633,7 +642,8 @@ export class Viewer
|
|
|
633
642
|
}
|
|
634
643
|
|
|
635
644
|
/**
|
|
636
|
-
*
|
|
645
|
+
* Registers a dragger for the viewer. Dragger is an object that received mouse/keyboard
|
|
646
|
+
* events and does something to the viewer.
|
|
637
647
|
*
|
|
638
648
|
* @param name - Dragger name.
|
|
639
649
|
* @param dragger - Dragger class.
|
|
@@ -650,7 +660,7 @@ export class Viewer
|
|
|
650
660
|
}
|
|
651
661
|
|
|
652
662
|
/**
|
|
653
|
-
*
|
|
663
|
+
* Changes the active dragger. Viewer must be initialized before enable dragger or exception is thrown.
|
|
654
664
|
*
|
|
655
665
|
* Fires:
|
|
656
666
|
*
|
|
@@ -688,7 +698,7 @@ export class Viewer
|
|
|
688
698
|
}
|
|
689
699
|
|
|
690
700
|
/**
|
|
691
|
-
*
|
|
701
|
+
* Resets the state of the active dragger.
|
|
692
702
|
*/
|
|
693
703
|
resetActiveDragger(): void {
|
|
694
704
|
const dragger = this._activeDragger;
|
|
@@ -699,7 +709,7 @@ export class Viewer
|
|
|
699
709
|
}
|
|
700
710
|
|
|
701
711
|
/**
|
|
702
|
-
*
|
|
712
|
+
* Removes all cutting planes.
|
|
703
713
|
*/
|
|
704
714
|
clearSlices(): void {
|
|
705
715
|
if (!this.visualizeJs) return;
|
|
@@ -713,7 +723,7 @@ export class Viewer
|
|
|
713
723
|
}
|
|
714
724
|
|
|
715
725
|
/**
|
|
716
|
-
*
|
|
726
|
+
* Clears the overlay view.
|
|
717
727
|
*/
|
|
718
728
|
clearOverlay(): void {
|
|
719
729
|
if (!this.visualizeJs) return;
|
|
@@ -723,7 +733,7 @@ export class Viewer
|
|
|
723
733
|
}
|
|
724
734
|
|
|
725
735
|
/**
|
|
726
|
-
*
|
|
736
|
+
* Creates an overlay view. Overlay view is used to draw cutting planes and `Visualize` markups.
|
|
727
737
|
*/
|
|
728
738
|
syncOverlay(): any {
|
|
729
739
|
if (!this.visualizeJs) return;
|
|
@@ -758,7 +768,7 @@ export class Viewer
|
|
|
758
768
|
}
|
|
759
769
|
|
|
760
770
|
/**
|
|
761
|
-
* Returns `true` if current
|
|
771
|
+
* Returns `true` if current model is 3D model.
|
|
762
772
|
*/
|
|
763
773
|
is3D(): boolean {
|
|
764
774
|
if (!this.visualizeJs) return false;
|
|
@@ -776,12 +786,16 @@ export class Viewer
|
|
|
776
786
|
screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number } {
|
|
777
787
|
if (!this.visualizeJs) return { x: position.x, y: position.y, z: 0 };
|
|
778
788
|
|
|
779
|
-
const
|
|
789
|
+
const activeView = this.visViewer().activeView;
|
|
790
|
+
const worldPoint = activeView.transformScreenToWorld(
|
|
780
791
|
position.x * window.devicePixelRatio,
|
|
781
792
|
position.y * window.devicePixelRatio
|
|
782
793
|
);
|
|
794
|
+
|
|
783
795
|
const result = { x: worldPoint[0], y: worldPoint[1], z: worldPoint[2] };
|
|
784
796
|
|
|
797
|
+
activeView.delete();
|
|
798
|
+
|
|
785
799
|
return result;
|
|
786
800
|
}
|
|
787
801
|
|
|
@@ -789,15 +803,10 @@ export class Viewer
|
|
|
789
803
|
if (!this.visualizeJs) return { x: position.x, y: position.y };
|
|
790
804
|
|
|
791
805
|
const activeView = this.visViewer().activeView;
|
|
792
|
-
const
|
|
793
|
-
const worldPoint = this.visLib().Point3d.createFromArray([position.x, position.y, position.z]);
|
|
806
|
+
const devicePoint = activeView.transformWorldToScreen(position.x, position.y, position.z);
|
|
794
807
|
|
|
795
|
-
const
|
|
796
|
-
const result = { x: devicePoint.x / window.devicePixelRatio, y: devicePoint.y / window.devicePixelRatio };
|
|
808
|
+
const result = { x: devicePoint[0] / window.devicePixelRatio, y: devicePoint[1] / window.devicePixelRatio };
|
|
797
809
|
|
|
798
|
-
devicePoint.delete();
|
|
799
|
-
worldPoint.delete();
|
|
800
|
-
worldMatrix.delete();
|
|
801
810
|
activeView.delete();
|
|
802
811
|
|
|
803
812
|
return result;
|
|
@@ -822,16 +831,14 @@ export class Viewer
|
|
|
822
831
|
}
|
|
823
832
|
|
|
824
833
|
/**
|
|
825
|
-
* Returns a list of original handles for the selected
|
|
834
|
+
* Returns a list of original handles for the selected objects.
|
|
826
835
|
*/
|
|
827
836
|
getSelected(): string[] {
|
|
828
837
|
return this.executeCommand("getSelected");
|
|
829
838
|
}
|
|
830
839
|
|
|
831
840
|
/**
|
|
832
|
-
*
|
|
833
|
-
* {@link File.getProperties | File.getProperties()} or
|
|
834
|
-
* {@link File.searchProperties | File.searchProperties()} methods.
|
|
841
|
+
* Selects the model objects by original handles that are obtained using `File.searchProperties()`.
|
|
835
842
|
*
|
|
836
843
|
* Fires:
|
|
837
844
|
*
|
|
@@ -843,13 +850,8 @@ export class Viewer
|
|
|
843
850
|
this.executeCommand("setSelected", handles);
|
|
844
851
|
}
|
|
845
852
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
* correct rendering of the model.
|
|
849
|
-
*
|
|
850
|
-
* @param model - Instance of model with references. If a `File` instance is specified
|
|
851
|
-
* instead of a model, the file references will be loaded.
|
|
852
|
-
*/
|
|
853
|
+
// Internal loading routines
|
|
854
|
+
|
|
853
855
|
async loadReferences(model: Model | File | Assembly): Promise<this> {
|
|
854
856
|
if (!this.visualizeJs) return this;
|
|
855
857
|
if (!this.client) return this;
|
|
@@ -874,8 +876,6 @@ export class Viewer
|
|
|
874
876
|
return this;
|
|
875
877
|
}
|
|
876
878
|
|
|
877
|
-
// Internal loading routines
|
|
878
|
-
|
|
879
879
|
applyModelTransformMatrix(model: Model | Assembly) {
|
|
880
880
|
this.executeCommand("applyModelTransform", model);
|
|
881
881
|
}
|
|
@@ -899,7 +899,7 @@ export class Viewer
|
|
|
899
899
|
}
|
|
900
900
|
|
|
901
901
|
/**
|
|
902
|
-
* Loads a model
|
|
902
|
+
* Loads a model/file/assembly into the viewer.
|
|
903
903
|
*
|
|
904
904
|
* This method requires a {@link Client} instance to work. For standalone viewer instance use
|
|
905
905
|
* {@link openVsfFile | openVsfFile()} or {@link openVsfxFile | openVsfxFile()}.
|
|
@@ -934,7 +934,7 @@ export class Viewer
|
|
|
934
934
|
if (!model) throw new Error("No default model found");
|
|
935
935
|
|
|
936
936
|
const overrideOptions = new Options();
|
|
937
|
-
overrideOptions.data = this.
|
|
937
|
+
overrideOptions.data = this._options.data;
|
|
938
938
|
if (file.type === ".rcs" && !overrideOptions.enablePartialMode) {
|
|
939
939
|
console.log("Partial load mode is forced for RCS file");
|
|
940
940
|
overrideOptions.enablePartialMode = true;
|
|
@@ -955,7 +955,7 @@ export class Viewer
|
|
|
955
955
|
}
|
|
956
956
|
|
|
957
957
|
/**
|
|
958
|
-
* Loads a VSF file into the viewer.
|
|
958
|
+
* Loads a `VSF` file into the viewer.
|
|
959
959
|
*
|
|
960
960
|
* Fires:
|
|
961
961
|
*
|
|
@@ -1001,7 +1001,7 @@ export class Viewer
|
|
|
1001
1001
|
}
|
|
1002
1002
|
|
|
1003
1003
|
/**
|
|
1004
|
-
* Loads a VSFX file into the viewer.
|
|
1004
|
+
* Loads a `VSFX` file into the viewer.
|
|
1005
1005
|
*
|
|
1006
1006
|
* Fires:
|
|
1007
1007
|
*
|
|
@@ -1065,7 +1065,7 @@ export class Viewer
|
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
1067
1067
|
/**
|
|
1068
|
-
* Unloads the model and clears the viewer.
|
|
1068
|
+
* Unloads the model and clears the viewer and markups.
|
|
1069
1069
|
*/
|
|
1070
1070
|
clear(): this {
|
|
1071
1071
|
if (!this.visualizeJs) return this;
|
|
@@ -1088,16 +1088,18 @@ export class Viewer
|
|
|
1088
1088
|
}
|
|
1089
1089
|
|
|
1090
1090
|
/**
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1093
|
-
* @returns Color with `RGB` values.
|
|
1091
|
+
* Returns the color of new markup objects.
|
|
1094
1092
|
*/
|
|
1095
1093
|
getMarkupColor(): { r: number; g: number; b: number } {
|
|
1096
1094
|
return this._markup.getMarkupColor();
|
|
1097
1095
|
}
|
|
1098
1096
|
|
|
1099
1097
|
/**
|
|
1100
|
-
*
|
|
1098
|
+
* Sets the color of new markup objects.
|
|
1099
|
+
*
|
|
1100
|
+
* Fires:
|
|
1101
|
+
*
|
|
1102
|
+
* - {@link ChangeMarkupColorEvent | changemarkupcolor}
|
|
1101
1103
|
*
|
|
1102
1104
|
* @param r - `Red` part of color.
|
|
1103
1105
|
* @param g - `Green` part of color.
|
|
@@ -1110,7 +1112,7 @@ export class Viewer
|
|
|
1110
1112
|
}
|
|
1111
1113
|
|
|
1112
1114
|
/**
|
|
1113
|
-
*
|
|
1115
|
+
* Colors all markup objects with the specified color.
|
|
1114
1116
|
*
|
|
1115
1117
|
* @param r - `Red` part of color.
|
|
1116
1118
|
* @param g - `Green` part of color.
|
|
@@ -1121,7 +1123,7 @@ export class Viewer
|
|
|
1121
1123
|
}
|
|
1122
1124
|
|
|
1123
1125
|
/**
|
|
1124
|
-
*
|
|
1126
|
+
* Colors selected markup objects with the specified color.
|
|
1125
1127
|
*
|
|
1126
1128
|
* @param r - `Red` part of color.
|
|
1127
1129
|
* @param g - `Green` part of color.
|
|
@@ -1132,7 +1134,7 @@ export class Viewer
|
|
|
1132
1134
|
}
|
|
1133
1135
|
|
|
1134
1136
|
/**
|
|
1135
|
-
*
|
|
1137
|
+
* Adds an empty `Visualize` markup entity to the overlay.
|
|
1136
1138
|
*/
|
|
1137
1139
|
addMarkupEntity(entityName: string) {
|
|
1138
1140
|
if (!this.visualizeJs) return null;
|
|
@@ -1155,8 +1157,9 @@ export class Viewer
|
|
|
1155
1157
|
}
|
|
1156
1158
|
|
|
1157
1159
|
/**
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1160
|
+
* Sets the viewer state to the specified viewpoint.
|
|
1161
|
+
*
|
|
1162
|
+
* To get a list of available model viewpoints, use the `File.getViewpoints()`.
|
|
1160
1163
|
*
|
|
1161
1164
|
* @param viewpoint - Viewpoint data.
|
|
1162
1165
|
*/
|
|
@@ -1167,8 +1170,9 @@ export class Viewer
|
|
|
1167
1170
|
}
|
|
1168
1171
|
|
|
1169
1172
|
/**
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1173
|
+
* Saves the viewer state at the viewpoint.
|
|
1174
|
+
*
|
|
1175
|
+
* To save a viewpoint to a model on the server, use the `File.saveViewpoint()`.
|
|
1172
1176
|
*/
|
|
1173
1177
|
createViewpoint(): IViewpoint {
|
|
1174
1178
|
const vp = this._markup.getViewpoint();
|