@inweb/viewer-visualize 26.10.6 → 26.11.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.
- package/README.md +6 -4
- package/dist/viewer-visualize.js +591 -475
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +583 -483
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Commands/GetSelected2.d.ts +2 -0
- package/lib/Viewer/Commands/SetSelected.d.ts +1 -1
- package/lib/Viewer/Commands/SetSelected2.d.ts +2 -0
- package/lib/Viewer/Components/index.d.ts +8 -7
- package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +5 -1
- package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +3 -2
- package/lib/Viewer/Loaders/VSFXCloudLoader.d.ts +1 -1
- package/lib/Viewer/Loaders/VSFXCloudPartialLoader.d.ts +1 -1
- package/lib/Viewer/Loaders/index.d.ts +14 -9
- package/lib/Viewer/Models/IModelImpl.d.ts +5 -0
- package/lib/Viewer/Models/ModelImpl.d.ts +5 -0
- package/lib/Viewer/Viewer.d.ts +129 -136
- package/package.json +5 -5
- package/src/Viewer/Commands/ClearSelected.ts +3 -1
- package/src/Viewer/Commands/GetSelected2.ts +33 -0
- package/src/Viewer/Commands/HideSelected.ts +3 -1
- package/src/Viewer/Commands/SelectModel.ts +2 -3
- package/src/Viewer/Commands/SetSelected.ts +5 -2
- package/src/Viewer/Commands/SetSelected2.ts +39 -0
- package/src/Viewer/Commands/index.ts +4 -0
- package/src/Viewer/Components/index.ts +8 -7
- package/src/Viewer/Draggers/Common/OdBaseDragger.ts +3 -2
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +44 -13
- package/src/Viewer/Draggers/MeasureLineDragger/index.ts +53 -18
- package/src/Viewer/Draggers/OdJoyStickDragger.ts +2 -2
- package/src/Viewer/Loaders/VSFCloudLoader.ts +6 -0
- package/src/Viewer/Loaders/VSFFileLoader.ts +7 -1
- package/src/Viewer/Loaders/VSFXCloudLoader.ts +7 -1
- package/src/Viewer/Loaders/VSFXCloudPartialLoader.ts +8 -2
- package/src/Viewer/Loaders/VSFXCloudStreamingLoader.ts +7 -1
- package/src/Viewer/Loaders/VSFXFileLoader.ts +7 -1
- package/src/Viewer/Loaders/index.ts +14 -9
- package/src/Viewer/Models/IModelImpl.ts +29 -0
- package/src/Viewer/Models/ModelImpl.ts +32 -0
- package/src/Viewer/Viewer.ts +780 -775
|
@@ -213,8 +213,8 @@ class OdBaseDragger extends OdaGeAction {
|
|
|
213
213
|
viewer.select(x, y, x, y);
|
|
214
214
|
this.subject.update();
|
|
215
215
|
const selectionSet = viewer.getSelected();
|
|
216
|
-
|
|
217
|
-
this.onmessage({ type: "
|
|
216
|
+
this.onmessage({ type: "select", data: selectionSet, handles: this.subject.getSelected() });
|
|
217
|
+
this.onmessage({ type: "select2", data: selectionSet, handles: this.subject.getSelected2() });
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
dblclick(ev) {
|
|
@@ -402,8 +402,9 @@ class MeasureLineItem {
|
|
|
402
402
|
this.htmlElemTitle = null;
|
|
403
403
|
this.startPoint = null;
|
|
404
404
|
this.endPoint = null;
|
|
405
|
-
this.unit = "";
|
|
406
405
|
this.scale = 1.0;
|
|
406
|
+
this.unit = "";
|
|
407
|
+
this.precision = 2;
|
|
407
408
|
this.size = 10.0;
|
|
408
409
|
this.lineThickness = 2;
|
|
409
410
|
this.style = {
|
|
@@ -488,10 +489,9 @@ class MeasureLineItem {
|
|
|
488
489
|
this.htmlElemLine.style.background = this.style.background;
|
|
489
490
|
this.htmlElemLine.style.zIndex = "1";
|
|
490
491
|
this.htmlElemLine.style.height = `${height}px`;
|
|
491
|
-
const distance =
|
|
492
|
+
const distance = this.getDistance();
|
|
492
493
|
const pX = p1.x + dx / 2;
|
|
493
494
|
const pY = p1.y + dy / 2;
|
|
494
|
-
const widthTitle = distance.length * 10;
|
|
495
495
|
this.htmlElemTitle = createHtmlElementIfNeed(this.htmlElemTitle, this.targetElement, "ruler-value");
|
|
496
496
|
this.htmlElemTitle.style.display = "block";
|
|
497
497
|
this.htmlElemTitle.style.cursor = "pointer";
|
|
@@ -499,9 +499,8 @@ class MeasureLineItem {
|
|
|
499
499
|
this.htmlElemTitle.style.color = "white";
|
|
500
500
|
this.htmlElemTitle.style.position = "Absolute";
|
|
501
501
|
this.htmlElemTitle.style.top = `${pY}px`;
|
|
502
|
-
this.htmlElemTitle.style.left = `${pX
|
|
503
|
-
this.htmlElemTitle.style.
|
|
504
|
-
this.htmlElemTitle.style.transformOrigin = "0px 0px";
|
|
502
|
+
this.htmlElemTitle.style.left = `${pX}px`;
|
|
503
|
+
this.htmlElemTitle.style.transform = "translate(-50%, -50%)";
|
|
505
504
|
this.htmlElemTitle.style.borderRadius = "5px";
|
|
506
505
|
this.htmlElemTitle.style.boxShadow = this.style.boxShadow;
|
|
507
506
|
this.htmlElemTitle.style.border = "none";
|
|
@@ -509,7 +508,7 @@ class MeasureLineItem {
|
|
|
509
508
|
this.htmlElemTitle.style.zIndex = "3";
|
|
510
509
|
this.htmlElemTitle.style.padding = "2px";
|
|
511
510
|
this.htmlElemTitle.style.textAlign = "center";
|
|
512
|
-
this.htmlElemTitle.innerHTML =
|
|
511
|
+
this.htmlElemTitle.innerHTML = this.formatDistance(distance);
|
|
513
512
|
}
|
|
514
513
|
else {
|
|
515
514
|
this.htmlElemLine.style.display = "none";
|
|
@@ -519,11 +518,43 @@ class MeasureLineItem {
|
|
|
519
518
|
}
|
|
520
519
|
getDistance() {
|
|
521
520
|
let distance = getDistance(this.startPoint, this.endPoint, this.moduleInstance);
|
|
522
|
-
if (Math.abs(this.scale
|
|
523
|
-
distance
|
|
524
|
-
}
|
|
521
|
+
if (Math.abs(this.scale) > 1e-10)
|
|
522
|
+
distance /= this.scale;
|
|
525
523
|
return distance;
|
|
526
524
|
}
|
|
525
|
+
calculatePrecision(value) {
|
|
526
|
+
const distance = Math.abs(value);
|
|
527
|
+
if (distance >= 1000)
|
|
528
|
+
return 0;
|
|
529
|
+
if (distance >= 10)
|
|
530
|
+
return 1;
|
|
531
|
+
if (distance >= 0.1)
|
|
532
|
+
return 2;
|
|
533
|
+
if (distance >= 0.001)
|
|
534
|
+
return 3;
|
|
535
|
+
return distance > 0 ? Math.floor(-Math.log10(distance)) + 1 : 2;
|
|
536
|
+
}
|
|
537
|
+
formatDistance(distance) {
|
|
538
|
+
let digits;
|
|
539
|
+
if (this.precision === "Auto")
|
|
540
|
+
digits = this.calculatePrecision(distance);
|
|
541
|
+
else if (Number.isFinite(this.precision))
|
|
542
|
+
digits = this.precision;
|
|
543
|
+
else
|
|
544
|
+
digits = parseFloat(this.precision);
|
|
545
|
+
if (!Number.isFinite(digits))
|
|
546
|
+
digits = 2;
|
|
547
|
+
else if (digits < 0)
|
|
548
|
+
digits = 0;
|
|
549
|
+
else if (digits > 10)
|
|
550
|
+
digits = 10;
|
|
551
|
+
let result = distance.toFixed(digits);
|
|
552
|
+
if (this.precision === "Auto")
|
|
553
|
+
result = result.replace(/\.0+$/, "").replace(/\.$/, "");
|
|
554
|
+
if (+result !== distance)
|
|
555
|
+
result = "~ " + result;
|
|
556
|
+
return `${result} ${this.unit}`;
|
|
557
|
+
}
|
|
527
558
|
setStartPoint(gePoint) {
|
|
528
559
|
this.startPoint = gePoint;
|
|
529
560
|
this.drawMeasureLine();
|
|
@@ -556,6 +587,10 @@ class MeasureLineItem {
|
|
|
556
587
|
this.scale = scale;
|
|
557
588
|
this.drawMeasureLine();
|
|
558
589
|
}
|
|
590
|
+
setPrecision(precision) {
|
|
591
|
+
this.precision = precision;
|
|
592
|
+
this.drawMeasureLine();
|
|
593
|
+
}
|
|
559
594
|
setStyle(style) {
|
|
560
595
|
this.style = style;
|
|
561
596
|
this.drawMeasureLine();
|
|
@@ -578,14 +613,14 @@ function renameUnit(table, unit) {
|
|
|
578
613
|
}
|
|
579
614
|
class MeasureLineDragger extends OdBaseDragger {
|
|
580
615
|
constructor(subject) {
|
|
581
|
-
var _a;
|
|
616
|
+
var _a, _b;
|
|
582
617
|
super(subject);
|
|
583
618
|
this.lineThickness = 2;
|
|
584
619
|
this.press = false;
|
|
585
620
|
this.gripingRadius = 5.0;
|
|
586
621
|
this.firstPoint = null;
|
|
587
622
|
this.secondPoint = null;
|
|
588
|
-
this.
|
|
623
|
+
this.rulerUnitTable = {
|
|
589
624
|
Millimeters: "mm",
|
|
590
625
|
Centimeters: "cm",
|
|
591
626
|
Meters: "m",
|
|
@@ -595,13 +630,14 @@ class MeasureLineDragger extends OdBaseDragger {
|
|
|
595
630
|
Kilometers: "km",
|
|
596
631
|
Miles: "mi",
|
|
597
632
|
Micrometers: "µm",
|
|
633
|
+
Mils: "mil",
|
|
598
634
|
MicroInches: "µin",
|
|
599
635
|
Default: "unit",
|
|
600
636
|
};
|
|
637
|
+
this.rulerUnit = (_a = subject.options.rulerUnit) !== null && _a !== void 0 ? _a : "Default";
|
|
638
|
+
this.rulerPrecision = (_b = subject.options.rulerPrecision) !== null && _b !== void 0 ? _b : "Default";
|
|
601
639
|
this.items = [];
|
|
602
|
-
this.canvasEvents.push("resize");
|
|
603
|
-
this.oldRulerUnit = (_a = subject.options.rulerUnit) !== null && _a !== void 0 ? _a : "Default";
|
|
604
|
-
this.optionsChange = this.optionsChange.bind(this);
|
|
640
|
+
this.canvasEvents.push("resize", "optionsChange");
|
|
605
641
|
}
|
|
606
642
|
initialize() {
|
|
607
643
|
super.initialize();
|
|
@@ -696,8 +732,9 @@ class MeasureLineDragger extends OdBaseDragger {
|
|
|
696
732
|
const viewer = this.m_module.getViewer();
|
|
697
733
|
const item = new MeasureLineItem(this.m_overlayElement, viewer, this.m_module);
|
|
698
734
|
item.lineThickness = this.lineThickness || item.lineThickness;
|
|
699
|
-
const isDefaultUnit =
|
|
700
|
-
|
|
735
|
+
const isDefaultUnit = this.rulerUnit === "Default";
|
|
736
|
+
const isDefaultPrecision = this.rulerPrecision === "Default";
|
|
737
|
+
item.setUnit(renameUnit(this.rulerUnitTable, isDefaultUnit ? viewer.getUnit() : this.rulerUnit));
|
|
701
738
|
if (!isDefaultUnit) {
|
|
702
739
|
const fromUnit = this.getKUnitByName(viewer.getUnit());
|
|
703
740
|
const toUnit = this.getKUnitByName(this.subject.options.rulerUnit);
|
|
@@ -708,29 +745,49 @@ class MeasureLineDragger extends OdBaseDragger {
|
|
|
708
745
|
else {
|
|
709
746
|
item.setConversionFactor(1.0);
|
|
710
747
|
}
|
|
748
|
+
if (!isDefaultPrecision) {
|
|
749
|
+
item.setPrecision(this.rulerPrecision);
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
item.setPrecision(2);
|
|
753
|
+
}
|
|
711
754
|
this.items.push(item);
|
|
712
755
|
return item;
|
|
713
756
|
}
|
|
714
757
|
optionsChange(event) {
|
|
715
|
-
var _a;
|
|
758
|
+
var _a, _b;
|
|
716
759
|
const options = event.data;
|
|
717
760
|
const toUnitName = (_a = options.rulerUnit) !== null && _a !== void 0 ? _a : "Default";
|
|
718
|
-
|
|
761
|
+
const toPrecision = (_b = options.rulerPrecision) !== null && _b !== void 0 ? _b : "Default";
|
|
762
|
+
const unitChanged = this.rulerUnit !== toUnitName;
|
|
763
|
+
const precisionChanged = this.rulerPrecision !== toPrecision;
|
|
764
|
+
if (!unitChanged && !precisionChanged)
|
|
719
765
|
return;
|
|
720
|
-
this.
|
|
766
|
+
this.rulerUnit = toUnitName;
|
|
767
|
+
this.rulerPrecision = toPrecision;
|
|
721
768
|
const drawingUnit = this.m_module.getViewer().getUnit();
|
|
722
769
|
const eToUnit = this.getKUnitByName(toUnitName);
|
|
723
770
|
const eFromUnit = this.getKUnitByName(drawingUnit);
|
|
724
771
|
this.items.forEach((item) => {
|
|
725
|
-
if (
|
|
726
|
-
|
|
727
|
-
|
|
772
|
+
if (unitChanged) {
|
|
773
|
+
if (toUnitName === "Default") {
|
|
774
|
+
item.setUnit(renameUnit(this.rulerUnitTable, drawingUnit));
|
|
775
|
+
item.setConversionFactor(1.0);
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
item.setUnit(renameUnit(this.rulerUnitTable, toUnitName));
|
|
779
|
+
const multiplier = this.m_module.getViewer().getUnitsConversionCoef(eFromUnit, eToUnit);
|
|
780
|
+
this.conversionFactor = 1 / multiplier;
|
|
781
|
+
item.setConversionFactor(this.conversionFactor);
|
|
782
|
+
}
|
|
728
783
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
784
|
+
if (precisionChanged) {
|
|
785
|
+
if (toPrecision === "Default") {
|
|
786
|
+
item.setPrecision(2);
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
item.setPrecision(toPrecision);
|
|
790
|
+
}
|
|
734
791
|
}
|
|
735
792
|
});
|
|
736
793
|
}
|
|
@@ -764,6 +821,9 @@ class MeasureLineDragger extends OdBaseDragger {
|
|
|
764
821
|
case "Micrometers":
|
|
765
822
|
eUnit = this.m_module.Units.kMicrometers;
|
|
766
823
|
break;
|
|
824
|
+
case "Mils":
|
|
825
|
+
eUnit = this.m_module.Units.kMils;
|
|
826
|
+
break;
|
|
767
827
|
case "MicroInches":
|
|
768
828
|
eUnit = this.m_module.Units.kMicroInches;
|
|
769
829
|
break;
|
|
@@ -819,7 +879,7 @@ class OdJoyStickDragger {
|
|
|
819
879
|
callback({
|
|
820
880
|
x: 100 * ((movedX - centerX) / maxMoveStick),
|
|
821
881
|
y: 100 * ((movedY - centerY) / maxMoveStick) * -1,
|
|
822
|
-
global
|
|
882
|
+
global,
|
|
823
883
|
});
|
|
824
884
|
}
|
|
825
885
|
};
|
|
@@ -834,7 +894,7 @@ class OdJoyStickDragger {
|
|
|
834
894
|
callback({
|
|
835
895
|
x: 100 * ((movedX - centerX) / maxMoveStick),
|
|
836
896
|
y: 100 * ((movedY - centerY) / maxMoveStick) * -1,
|
|
837
|
-
global
|
|
897
|
+
global,
|
|
838
898
|
});
|
|
839
899
|
};
|
|
840
900
|
this.drawExternal = () => {
|
|
@@ -2325,7 +2385,8 @@ function clearSelected(viewer) {
|
|
|
2325
2385
|
const visViewer = viewer.visViewer();
|
|
2326
2386
|
visViewer.unselect();
|
|
2327
2387
|
viewer.update();
|
|
2328
|
-
viewer.emitEvent({ type: "select",
|
|
2388
|
+
viewer.emitEvent({ type: "select", handles: [] });
|
|
2389
|
+
viewer.emitEvent({ type: "select2", handles: [] });
|
|
2329
2390
|
}
|
|
2330
2391
|
|
|
2331
2392
|
function clearSlices(viewer) {
|
|
@@ -2401,6 +2462,13 @@ function getSelected(viewer) {
|
|
|
2401
2462
|
return handles;
|
|
2402
2463
|
}
|
|
2403
2464
|
|
|
2465
|
+
function getSelected2(viewer) {
|
|
2466
|
+
const handles = viewer.executeCommand("getSelected");
|
|
2467
|
+
const model = viewer.models[0];
|
|
2468
|
+
const handles2 = handles.map((handle) => `${model.id}:${handle}`);
|
|
2469
|
+
return handles2;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2404
2472
|
function hideSelected(viewer) {
|
|
2405
2473
|
if (!viewer.visualizeJs)
|
|
2406
2474
|
return;
|
|
@@ -2408,7 +2476,8 @@ function hideSelected(viewer) {
|
|
|
2408
2476
|
visViewer.hideSelectedObjects(false);
|
|
2409
2477
|
viewer.update();
|
|
2410
2478
|
viewer.emitEvent({ type: "hide" });
|
|
2411
|
-
viewer.emitEvent({ type: "select",
|
|
2479
|
+
viewer.emitEvent({ type: "select", handles: [] });
|
|
2480
|
+
viewer.emitEvent({ type: "select2", handles: [] });
|
|
2412
2481
|
}
|
|
2413
2482
|
|
|
2414
2483
|
function isolateSelected(viewer) {
|
|
@@ -2456,9 +2525,9 @@ function selectModel(viewer, handle) {
|
|
|
2456
2525
|
if (modelPtr.getDatabaseHandle() === handle) {
|
|
2457
2526
|
const selectionSet = activeView.selectCrossing([0, 9999, 9999, 0], modelPtr);
|
|
2458
2527
|
visViewer.setSelected(selectionSet);
|
|
2459
|
-
const handles = viewer.getSelected();
|
|
2460
2528
|
viewer.update();
|
|
2461
|
-
viewer.emitEvent({ type: "select",
|
|
2529
|
+
viewer.emitEvent({ type: "select", handles: viewer.getSelected() });
|
|
2530
|
+
viewer.emitEvent({ type: "select2", handles: viewer.getSelected2() });
|
|
2462
2531
|
selectionSet.delete();
|
|
2463
2532
|
break;
|
|
2464
2533
|
}
|
|
@@ -2485,13 +2554,14 @@ function setMarkupColor(viewer, r = 255, g = 0, b = 0) {
|
|
|
2485
2554
|
viewer.markup.setMarkupColor(r, g, b);
|
|
2486
2555
|
}
|
|
2487
2556
|
|
|
2488
|
-
function setSelected(viewer,
|
|
2557
|
+
function setSelected(viewer, handles2 = []) {
|
|
2489
2558
|
if (!viewer.visualizeJs)
|
|
2490
2559
|
return;
|
|
2560
|
+
const handles = handles2.map((handle) => handle.slice(handle.indexOf(":") + 1));
|
|
2491
2561
|
const visLib = viewer.visLib();
|
|
2492
2562
|
const visViewer = viewer.visViewer();
|
|
2493
2563
|
const selectionSet = new visLib.OdTvSelectionSet();
|
|
2494
|
-
handles
|
|
2564
|
+
handles.forEach((handle) => {
|
|
2495
2565
|
const entityId = visViewer.getEntityByOriginalHandle(handle + "");
|
|
2496
2566
|
if (!entityId.isNull())
|
|
2497
2567
|
selectionSet.appendEntity(entityId);
|
|
@@ -2499,9 +2569,25 @@ function setSelected(viewer, handles = []) {
|
|
|
2499
2569
|
visViewer.setSelected(selectionSet);
|
|
2500
2570
|
viewer.update();
|
|
2501
2571
|
viewer.emitEvent({ type: "select", data: selectionSet, handles });
|
|
2572
|
+
viewer.emitEvent({ type: "select2", data: selectionSet, handles: handles2 });
|
|
2502
2573
|
selectionSet.delete();
|
|
2503
2574
|
}
|
|
2504
2575
|
|
|
2576
|
+
function setSelected2(viewer, handles2 = []) {
|
|
2577
|
+
const handles = [];
|
|
2578
|
+
handles2.forEach((handle) => {
|
|
2579
|
+
if (!handle.includes(":")) {
|
|
2580
|
+
handles.push(handle);
|
|
2581
|
+
}
|
|
2582
|
+
else
|
|
2583
|
+
viewer.models.forEach((model) => {
|
|
2584
|
+
if (handle.split(":", 1)[0] === model.id + "")
|
|
2585
|
+
handles.push(handle);
|
|
2586
|
+
});
|
|
2587
|
+
});
|
|
2588
|
+
return viewer.executeCommand("setSelected", handles);
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2505
2591
|
function showAll(viewer) {
|
|
2506
2592
|
if (!viewer.visualizeJs)
|
|
2507
2593
|
return;
|
|
@@ -2624,6 +2710,7 @@ commands.registerCommand("collect", collect);
|
|
|
2624
2710
|
commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
|
|
2625
2711
|
commands.registerCommand("getModels", getModels);
|
|
2626
2712
|
commands.registerCommand("getSelected", getSelected);
|
|
2713
|
+
commands.registerCommand("getSelected2", getSelected2);
|
|
2627
2714
|
commands.registerCommand("hideSelected", hideSelected);
|
|
2628
2715
|
commands.registerCommand("isolateSelected", isolateSelected);
|
|
2629
2716
|
commands.registerCommand("regenerateAll", regenerateAll);
|
|
@@ -2633,6 +2720,7 @@ commands.registerCommand("setActiveDragger", setActiveDragger);
|
|
|
2633
2720
|
commands.registerCommand("setDefaultViewPosition", setDefaultViewPosition);
|
|
2634
2721
|
commands.registerCommand("setMarkupColor", setMarkupColor);
|
|
2635
2722
|
commands.registerCommand("setSelected", setSelected);
|
|
2723
|
+
commands.registerCommand("setSelected2", setSelected2);
|
|
2636
2724
|
commands.registerCommand("showAll", showAll);
|
|
2637
2725
|
commands.registerCommand("zoomToExtents", zoomToExtents);
|
|
2638
2726
|
commands.registerCommand("zoomToObjects", zoomToObjects);
|
|
@@ -2981,6 +3069,10 @@ components.registerComponent("ZoomWheelComponent", (viewer) => new ZoomWheelComp
|
|
|
2981
3069
|
components.registerComponent("GestureManagerComponent", (viewer) => new GestureManagerComponent(viewer));
|
|
2982
3070
|
components.registerComponent("ResetComponent", (viewer) => new ResetComponent(viewer));
|
|
2983
3071
|
|
|
3072
|
+
class ModelImpl {
|
|
3073
|
+
dispose() { }
|
|
3074
|
+
}
|
|
3075
|
+
|
|
2984
3076
|
class FileLoader {
|
|
2985
3077
|
constructor() {
|
|
2986
3078
|
this.requestHeader = {};
|
|
@@ -3064,7 +3156,7 @@ class VSFFileLoader extends Loader {
|
|
|
3064
3156
|
return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
|
|
3065
3157
|
/vsf$/i.test(format));
|
|
3066
3158
|
}
|
|
3067
|
-
async load(file, format, params) {
|
|
3159
|
+
async load(file, format, params = {}) {
|
|
3068
3160
|
if (!this.viewer.visualizeJs)
|
|
3069
3161
|
return this;
|
|
3070
3162
|
const visViewer = this.viewer.visViewer();
|
|
@@ -3088,6 +3180,9 @@ class VSFFileLoader extends Loader {
|
|
|
3088
3180
|
console.error("VSF parse error.", error);
|
|
3089
3181
|
throw error;
|
|
3090
3182
|
}
|
|
3183
|
+
const modelImpl = new ModelImpl();
|
|
3184
|
+
modelImpl.id = params.modelId || this.extractFileName(file);
|
|
3185
|
+
this.viewer.models.push(modelImpl);
|
|
3091
3186
|
this.viewer.syncOptions();
|
|
3092
3187
|
this.viewer.syncOverlay();
|
|
3093
3188
|
this.viewer.update(true);
|
|
@@ -3131,6 +3226,9 @@ class VSFCloudLoader extends Loader {
|
|
|
3131
3226
|
throw error;
|
|
3132
3227
|
}
|
|
3133
3228
|
if (i === 0) {
|
|
3229
|
+
const modelImpl = new ModelImpl();
|
|
3230
|
+
modelImpl.id = model.file.id;
|
|
3231
|
+
this.viewer.models.push(modelImpl);
|
|
3134
3232
|
this.viewer.syncOptions();
|
|
3135
3233
|
this.viewer.syncOverlay();
|
|
3136
3234
|
this.viewer.update(true);
|
|
@@ -3155,7 +3253,7 @@ class VSFXFileLoader extends Loader {
|
|
|
3155
3253
|
return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
|
|
3156
3254
|
/vsfx$/i.test(format));
|
|
3157
3255
|
}
|
|
3158
|
-
async load(file, format, params) {
|
|
3256
|
+
async load(file, format, params = {}) {
|
|
3159
3257
|
if (!this.viewer.visualizeJs)
|
|
3160
3258
|
return this;
|
|
3161
3259
|
const visViewer = this.viewer.visViewer();
|
|
@@ -3179,6 +3277,9 @@ class VSFXFileLoader extends Loader {
|
|
|
3179
3277
|
console.error("VSFX parse error.", error);
|
|
3180
3278
|
throw error;
|
|
3181
3279
|
}
|
|
3280
|
+
const modelImpl = new ModelImpl();
|
|
3281
|
+
modelImpl.id = params.modelId || this.extractFileName(file);
|
|
3282
|
+
this.viewer.models.push(modelImpl);
|
|
3182
3283
|
this.viewer.syncOptions();
|
|
3183
3284
|
this.viewer.syncOverlay();
|
|
3184
3285
|
this.viewer.update(true);
|
|
@@ -3199,7 +3300,7 @@ class VSFXCloudLoader extends Loader {
|
|
|
3199
3300
|
/.vsfx$/i.test(file.database) &&
|
|
3200
3301
|
this.viewer.options.enableStreamingMode === false);
|
|
3201
3302
|
}
|
|
3202
|
-
async load(model
|
|
3303
|
+
async load(model) {
|
|
3203
3304
|
if (!this.viewer.visualizeJs)
|
|
3204
3305
|
return Promise.resolve(this);
|
|
3205
3306
|
const visViewer = this.viewer.visViewer();
|
|
@@ -3218,6 +3319,9 @@ class VSFXCloudLoader extends Loader {
|
|
|
3218
3319
|
console.error("VSFX parse error.", error);
|
|
3219
3320
|
throw error;
|
|
3220
3321
|
}
|
|
3322
|
+
const modelImpl = new ModelImpl();
|
|
3323
|
+
modelImpl.id = model.file.id;
|
|
3324
|
+
this.viewer.models.push(modelImpl);
|
|
3221
3325
|
this.viewer.syncOptions();
|
|
3222
3326
|
this.viewer.syncOverlay();
|
|
3223
3327
|
this.viewer.update(true);
|
|
@@ -3296,6 +3400,9 @@ class VSFXCloudStreamingLoader extends Loader {
|
|
|
3296
3400
|
isDatabaseChunk = true;
|
|
3297
3401
|
}
|
|
3298
3402
|
if (isDatabaseChunk) {
|
|
3403
|
+
const modelImpl = new ModelImpl();
|
|
3404
|
+
modelImpl.id = model.file.id;
|
|
3405
|
+
this.viewer.models.push(modelImpl);
|
|
3299
3406
|
this.viewer.syncOptions();
|
|
3300
3407
|
this.viewer.syncOverlay();
|
|
3301
3408
|
updateController.update(UpdateType.kForce);
|
|
@@ -3330,7 +3437,7 @@ class VSFXCloudPartialLoader extends Loader {
|
|
|
3330
3437
|
/.vsfx$/i.test(file.database) &&
|
|
3331
3438
|
(this.viewer.options.enablePartialMode === true || /.rcs$/i.test(file.name)));
|
|
3332
3439
|
}
|
|
3333
|
-
async load(model
|
|
3440
|
+
async load(model) {
|
|
3334
3441
|
if (!this.viewer.visualizeJs)
|
|
3335
3442
|
return this;
|
|
3336
3443
|
const visViewer = this.viewer.visViewer();
|
|
@@ -3356,6 +3463,9 @@ class VSFXCloudPartialLoader extends Loader {
|
|
|
3356
3463
|
}
|
|
3357
3464
|
this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
|
|
3358
3465
|
if (isDatabaseChunk) {
|
|
3466
|
+
const modelImpl = new ModelImpl();
|
|
3467
|
+
modelImpl.id = model.file.id;
|
|
3468
|
+
this.viewer.models.push(modelImpl);
|
|
3359
3469
|
this.viewer.syncOptions();
|
|
3360
3470
|
this.viewer.syncOverlay();
|
|
3361
3471
|
updateController.update(UpdateType.kForce);
|
|
@@ -3844,27 +3954,34 @@ class Viewer extends EventEmitter2 {
|
|
|
3844
3954
|
super();
|
|
3845
3955
|
this._visualizeJsUrl = "";
|
|
3846
3956
|
this.configure(params);
|
|
3847
|
-
this._options = new Options(this);
|
|
3848
3957
|
this.client = client;
|
|
3958
|
+
this.options = new Options(this);
|
|
3849
3959
|
this.loaders = [];
|
|
3960
|
+
this.models = [];
|
|
3961
|
+
this.canvasEvents = CANVAS_EVENTS.slice();
|
|
3962
|
+
this.canvaseventlistener = (event) => this.emit(event);
|
|
3850
3963
|
this._activeDragger = null;
|
|
3851
3964
|
this._components = [];
|
|
3965
|
+
this._renderNeeded = false;
|
|
3852
3966
|
this._renderTime = 0;
|
|
3853
|
-
this.canvasEvents = CANVAS_EVENTS.slice();
|
|
3854
|
-
this.canvaseventlistener = (event) => this.emit(event);
|
|
3855
3967
|
this._enableAutoUpdate = (_a = params.enableAutoUpdate) !== null && _a !== void 0 ? _a : true;
|
|
3856
|
-
this._renderNeeded = false;
|
|
3857
3968
|
this._isRunAsyncUpdate = false;
|
|
3858
3969
|
this.render = this.render.bind(this);
|
|
3859
3970
|
this.update = this.update.bind(this);
|
|
3860
3971
|
this._markup = MarkupFactory.createMarkup(params.markupType);
|
|
3861
3972
|
}
|
|
3862
|
-
get options() {
|
|
3863
|
-
return this._options;
|
|
3864
|
-
}
|
|
3865
3973
|
get visualizeJsUrl() {
|
|
3866
3974
|
return this._visualizeJsUrl;
|
|
3867
3975
|
}
|
|
3976
|
+
get visualizeJs() {
|
|
3977
|
+
return this._visualizeJs;
|
|
3978
|
+
}
|
|
3979
|
+
visLib() {
|
|
3980
|
+
return this._visualizeJs;
|
|
3981
|
+
}
|
|
3982
|
+
visViewer() {
|
|
3983
|
+
return this._viewer;
|
|
3984
|
+
}
|
|
3868
3985
|
get markup() {
|
|
3869
3986
|
return this._markup;
|
|
3870
3987
|
}
|
|
@@ -3873,13 +3990,20 @@ class Viewer extends EventEmitter2 {
|
|
|
3873
3990
|
this._crossOrigin = params.crossOrigin;
|
|
3874
3991
|
return this;
|
|
3875
3992
|
}
|
|
3993
|
+
get draggers() {
|
|
3994
|
+
return [...draggers.getDraggers().keys()];
|
|
3995
|
+
}
|
|
3996
|
+
get components() {
|
|
3997
|
+
return [...components.getComponents().keys()];
|
|
3998
|
+
}
|
|
3876
3999
|
async initialize(canvas, onProgress) {
|
|
3877
4000
|
this.addEventListener("optionschange", (event) => this.syncOptions(event.data));
|
|
4001
|
+
const pixelRatio = window.devicePixelRatio;
|
|
3878
4002
|
const rect = canvas.parentElement.getBoundingClientRect();
|
|
3879
4003
|
const width = rect.width || 1;
|
|
3880
4004
|
const height = rect.height || 1;
|
|
3881
|
-
canvas.width = Math.round(width *
|
|
3882
|
-
canvas.height = Math.round(height *
|
|
4005
|
+
canvas.width = Math.round(width * pixelRatio);
|
|
4006
|
+
canvas.height = Math.round(height * pixelRatio);
|
|
3883
4007
|
canvas.style.width = width + "px";
|
|
3884
4008
|
canvas.style.height = height + "px";
|
|
3885
4009
|
canvas.parentElement.style.touchAction = "none";
|
|
@@ -3947,6 +4071,26 @@ class Viewer extends EventEmitter2 {
|
|
|
3947
4071
|
this.update(true);
|
|
3948
4072
|
this.emitEvent({ type: "resize", width, height });
|
|
3949
4073
|
}
|
|
4074
|
+
resize() {
|
|
4075
|
+
console.warn("Viewer.resize() has been deprecated since 26.9 and will be removed in a future release, use Viewer.setSize() instead.");
|
|
4076
|
+
if (!this.visualizeJs)
|
|
4077
|
+
return this;
|
|
4078
|
+
if (!this.canvas.parentElement)
|
|
4079
|
+
return this;
|
|
4080
|
+
const { width, height } = this.canvas.parentElement.getBoundingClientRect();
|
|
4081
|
+
if (!width || !height)
|
|
4082
|
+
return this;
|
|
4083
|
+
this.setSize(width, height);
|
|
4084
|
+
return this;
|
|
4085
|
+
}
|
|
4086
|
+
update(force = false) {
|
|
4087
|
+
if (this._enableAutoUpdate) {
|
|
4088
|
+
this._renderNeeded = true;
|
|
4089
|
+
if (force)
|
|
4090
|
+
this.render();
|
|
4091
|
+
}
|
|
4092
|
+
this.emitEvent({ type: "update", data: force });
|
|
4093
|
+
}
|
|
3950
4094
|
render(time) {
|
|
3951
4095
|
var _a, _b;
|
|
3952
4096
|
if (!this.visualizeJs)
|
|
@@ -3965,133 +4109,222 @@ class Viewer extends EventEmitter2 {
|
|
|
3965
4109
|
(_b = (_a = this._activeDragger) === null || _a === void 0 ? void 0 : _a.updatePreview) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
3966
4110
|
this.emitEvent({ type: "render", time, deltaTime });
|
|
3967
4111
|
}
|
|
3968
|
-
|
|
3969
|
-
|
|
4112
|
+
async loadReferences(model) {
|
|
4113
|
+
var _a;
|
|
3970
4114
|
if (!this.visualizeJs)
|
|
3971
4115
|
return this;
|
|
3972
|
-
if (!this.
|
|
4116
|
+
if (!this.client)
|
|
3973
4117
|
return this;
|
|
3974
|
-
|
|
3975
|
-
if (!width || !height)
|
|
4118
|
+
if (!model.getReferences)
|
|
3976
4119
|
return this;
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
4120
|
+
const abortController = new AbortController();
|
|
4121
|
+
(_a = this._abortControllerForReferences) === null || _a === void 0 ? void 0 : _a.abort();
|
|
4122
|
+
this._abortControllerForReferences = abortController;
|
|
4123
|
+
let references = [];
|
|
4124
|
+
await model
|
|
4125
|
+
.getReferences(abortController.signal)
|
|
4126
|
+
.then((data) => (references = data.references))
|
|
4127
|
+
.catch((e) => console.error("Cannot load model references.", e));
|
|
4128
|
+
for (const file of references) {
|
|
4129
|
+
await this.client
|
|
4130
|
+
.downloadFile(file.id, undefined, abortController.signal)
|
|
4131
|
+
.then((arrayBuffer) => { var _a; return (_a = this.visualizeJs) === null || _a === void 0 ? void 0 : _a.getViewer().addEmbeddedFile(file.name, new Uint8Array(arrayBuffer)); })
|
|
4132
|
+
.catch((e) => console.error(`Cannot load reference file ${file.name}.`, e));
|
|
3985
4133
|
}
|
|
3986
|
-
this
|
|
4134
|
+
return this;
|
|
3987
4135
|
}
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
setTimeout(() => {
|
|
3991
|
-
var _a, _b, _c;
|
|
3992
|
-
try {
|
|
3993
|
-
if (this._enableAutoUpdate) {
|
|
3994
|
-
(_a = this.visViewer()) === null || _a === void 0 ? void 0 : _a.update(maxScheduleUpdateTimeInMs);
|
|
3995
|
-
(_c = (_b = this._activeDragger) === null || _b === void 0 ? void 0 : _b.updatePreview) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
3996
|
-
}
|
|
3997
|
-
this.emitEvent({ type: "update", data: false });
|
|
3998
|
-
resolve();
|
|
3999
|
-
}
|
|
4000
|
-
catch (e) {
|
|
4001
|
-
console.error(e);
|
|
4002
|
-
reject();
|
|
4003
|
-
}
|
|
4004
|
-
}, 0);
|
|
4005
|
-
});
|
|
4136
|
+
applyModelTransformMatrix(model) {
|
|
4137
|
+
this.executeCommand("applyModelTransform", model);
|
|
4006
4138
|
}
|
|
4007
|
-
|
|
4139
|
+
applySceneGraphSettings(options = this.options) {
|
|
4008
4140
|
if (!this.visualizeJs)
|
|
4009
4141
|
return;
|
|
4010
|
-
|
|
4142
|
+
const visLib = this.visLib();
|
|
4143
|
+
const visViewer = this.visViewer();
|
|
4144
|
+
const device = visViewer.getActiveDevice();
|
|
4145
|
+
if (isExist(options.sceneGraph)) {
|
|
4146
|
+
device.setOptionBool(visLib.DeviceOptions.kDelaySceneGraphProc, !options.sceneGraph);
|
|
4147
|
+
}
|
|
4148
|
+
device.delete();
|
|
4149
|
+
this.update();
|
|
4150
|
+
}
|
|
4151
|
+
async open(file, params = {}) {
|
|
4152
|
+
if (!this.visualizeJs)
|
|
4153
|
+
return this;
|
|
4154
|
+
this.cancel();
|
|
4155
|
+
this.clear();
|
|
4156
|
+
this.emitEvent({ type: "open", mode: "file", file });
|
|
4157
|
+
let model = file;
|
|
4158
|
+
if (model && typeof model.getModels === "function") {
|
|
4159
|
+
const models = await model.getModels();
|
|
4160
|
+
model = models.find((model) => model.default) || models[0] || file;
|
|
4161
|
+
}
|
|
4162
|
+
if (model && typeof model.database === "string") {
|
|
4163
|
+
file = model.file;
|
|
4164
|
+
}
|
|
4165
|
+
if (!model)
|
|
4166
|
+
throw new Error(`Format not supported`);
|
|
4167
|
+
let format = params.format;
|
|
4168
|
+
if (!format && typeof file["type"] === "string")
|
|
4169
|
+
format = file["type"].split(".").pop();
|
|
4170
|
+
if (!format && typeof file === "string")
|
|
4171
|
+
format = file.split(".").pop();
|
|
4172
|
+
if (!format && file instanceof globalThis.File)
|
|
4173
|
+
format = file.name.split(".").pop();
|
|
4174
|
+
const loader = loaders.createLoader(this, model, format);
|
|
4175
|
+
if (!loader)
|
|
4176
|
+
throw new Error(`Format not supported`);
|
|
4177
|
+
this.loaders.push(loader);
|
|
4178
|
+
this.emitEvent({ type: "geometrystart", file, model });
|
|
4011
4179
|
try {
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
await this.scheduleUpdateAsync(maxScheduleUpdateTimeInMs);
|
|
4015
|
-
}
|
|
4016
|
-
await this.scheduleUpdateAsync(maxScheduleUpdateTimeInMs);
|
|
4180
|
+
await this.loadReferences(model);
|
|
4181
|
+
await loader.load(model, format, params);
|
|
4017
4182
|
}
|
|
4018
|
-
catch (
|
|
4019
|
-
|
|
4183
|
+
catch (error) {
|
|
4184
|
+
this.emitEvent({ type: "geometryerror", data: error, file, model });
|
|
4185
|
+
throw error;
|
|
4020
4186
|
}
|
|
4021
|
-
|
|
4022
|
-
|
|
4187
|
+
this.emitEvent({ type: "geometryend", file, model });
|
|
4188
|
+
if (this.visualizeJs) {
|
|
4189
|
+
this.applyModelTransformMatrix(model);
|
|
4190
|
+
this.applySceneGraphSettings();
|
|
4023
4191
|
}
|
|
4192
|
+
return this;
|
|
4024
4193
|
}
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
}
|
|
4028
|
-
visLib() {
|
|
4029
|
-
return this._visualizeJs;
|
|
4030
|
-
}
|
|
4031
|
-
visViewer() {
|
|
4032
|
-
return this._viewer;
|
|
4033
|
-
}
|
|
4034
|
-
syncOpenCloudVisualStyle() {
|
|
4194
|
+
openVsfFile(buffer) {
|
|
4195
|
+
console.warn("Viewer.openVsfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
|
|
4035
4196
|
if (!this.visualizeJs)
|
|
4036
4197
|
return this;
|
|
4037
|
-
|
|
4198
|
+
this.cancel();
|
|
4199
|
+
this.clear();
|
|
4200
|
+
this.emitEvent({ type: "open", mode: "file", file: "", buffer });
|
|
4038
4201
|
const visViewer = this.visViewer();
|
|
4039
|
-
|
|
4040
|
-
if (device.isNull())
|
|
4041
|
-
return this;
|
|
4042
|
-
const view = device.getActiveView();
|
|
4043
|
-
view.enableDefaultLighting(true, visLib.DefaultLightingType.kTwoLights);
|
|
4044
|
-
view.setDefaultLightingIntensity(1.25);
|
|
4045
|
-
let visualStyleId;
|
|
4202
|
+
this.emitEvent({ type: "geometrystart", file: "", buffer });
|
|
4046
4203
|
try {
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4204
|
+
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
4205
|
+
visViewer.parseFile(data);
|
|
4206
|
+
this.syncOptions();
|
|
4207
|
+
this.syncOverlay();
|
|
4208
|
+
this.update(true);
|
|
4209
|
+
this.emitEvent({ type: "geometryprogress", data: 1, file: "", buffer });
|
|
4210
|
+
this.emitEvent({ type: "databasechunk", data, file: "", buffer });
|
|
4051
4211
|
}
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
const shadedVsId = visViewer.findVisualStyle("Realistic");
|
|
4056
|
-
const visualStylePtr = visualStyleId.openObject();
|
|
4057
|
-
visualStylePtr.copyFrom(shadedVsId);
|
|
4058
|
-
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kFaceModifiers, 0, visLib.VisualStyleOperations.kSet);
|
|
4059
|
-
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kEdgeModel, 2, visLib.VisualStyleOperations.kSet);
|
|
4060
|
-
visualStylePtr.setOptionDouble(visLib.VisualStyleOptions.kEdgeCreaseAngle, 60, visLib.VisualStyleOperations.kSet);
|
|
4061
|
-
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kEdgeStyles, 0, visLib.VisualStyleOperations.kSet);
|
|
4062
|
-
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kEdgeModifiers, 8, visLib.VisualStyleOperations.kSet);
|
|
4063
|
-
visualStylePtr.setOptionColor(visLib.VisualStyleOptions.kEdgeColorValue, colorDef, visLib.VisualStyleOperations.kSet);
|
|
4064
|
-
visualStylePtr.delete();
|
|
4212
|
+
catch (error) {
|
|
4213
|
+
this.emitEvent({ type: "geometryerror", data: error, file: "", buffer });
|
|
4214
|
+
throw error;
|
|
4065
4215
|
}
|
|
4066
|
-
|
|
4067
|
-
view.delete();
|
|
4068
|
-
device.delete();
|
|
4216
|
+
this.emitEvent({ type: "geometryend", file: "", buffer });
|
|
4069
4217
|
return this;
|
|
4070
4218
|
}
|
|
4071
|
-
|
|
4219
|
+
openVsfxFile(buffer) {
|
|
4220
|
+
console.warn("Viewer.openVsfxFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
|
|
4072
4221
|
if (!this.visualizeJs)
|
|
4073
4222
|
return this;
|
|
4074
|
-
this.
|
|
4075
|
-
|
|
4223
|
+
this.cancel();
|
|
4224
|
+
this.clear();
|
|
4225
|
+
this.emitEvent({ type: "open", mode: "file", file: "", buffer });
|
|
4076
4226
|
const visViewer = this.visViewer();
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4227
|
+
this.emitEvent({ type: "geometrystart", file: "", buffer });
|
|
4228
|
+
try {
|
|
4229
|
+
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
4230
|
+
visViewer.parseVsfx(data);
|
|
4231
|
+
this.syncOptions();
|
|
4232
|
+
this.syncOverlay();
|
|
4233
|
+
this.update(true);
|
|
4234
|
+
this.emitEvent({ type: "geometryprogress", data: 1, file: "", buffer });
|
|
4235
|
+
this.emitEvent({ type: "databasechunk", data, file: "", buffer });
|
|
4236
|
+
}
|
|
4237
|
+
catch (error) {
|
|
4238
|
+
this.emitEvent({ type: "geometryerror", data: error, file: "", buffer });
|
|
4239
|
+
throw error;
|
|
4240
|
+
}
|
|
4241
|
+
this.emitEvent({ type: "geometryend", file: "", buffer });
|
|
4242
|
+
return this;
|
|
4243
|
+
}
|
|
4244
|
+
cancel() {
|
|
4245
|
+
var _a;
|
|
4246
|
+
(_a = this._abortControllerForReferences) === null || _a === void 0 ? void 0 : _a.abort();
|
|
4247
|
+
this._abortControllerForReferences = undefined;
|
|
4248
|
+
this.loaders.forEach((loader) => loader.cancel());
|
|
4249
|
+
this.emitEvent({ type: "cancel" });
|
|
4250
|
+
return this;
|
|
4251
|
+
}
|
|
4252
|
+
clear() {
|
|
4253
|
+
if (!this.visualizeJs)
|
|
4254
|
+
return this;
|
|
4255
|
+
const visViewer = this.visViewer();
|
|
4256
|
+
this.setActiveDragger();
|
|
4257
|
+
this.clearSlices();
|
|
4258
|
+
this.clearOverlay();
|
|
4259
|
+
this.clearSelected();
|
|
4260
|
+
this.loaders.forEach((loader) => loader.dispose());
|
|
4261
|
+
this.loaders = [];
|
|
4262
|
+
this.models.forEach((model) => model.dispose());
|
|
4263
|
+
this.models = [];
|
|
4264
|
+
visViewer.clear();
|
|
4265
|
+
visViewer.createLocalDatabase();
|
|
4266
|
+
this.syncOptions();
|
|
4267
|
+
this.syncOverlay();
|
|
4268
|
+
this.update(true);
|
|
4269
|
+
this.emitEvent({ type: "clear" });
|
|
4270
|
+
return this;
|
|
4271
|
+
}
|
|
4272
|
+
is3D() {
|
|
4273
|
+
if (!this.visualizeJs)
|
|
4274
|
+
return false;
|
|
4275
|
+
const visViewer = this.visViewer();
|
|
4276
|
+
const ext = visViewer.getActiveExtents();
|
|
4277
|
+
const min = ext.min();
|
|
4278
|
+
const max = ext.max();
|
|
4279
|
+
const extHeight = max[2] - min[2];
|
|
4280
|
+
return extHeight !== 0;
|
|
4281
|
+
}
|
|
4282
|
+
syncOptions(options = this.options) {
|
|
4283
|
+
if (!this.visualizeJs)
|
|
4284
|
+
return this;
|
|
4285
|
+
const visLib = this.visLib();
|
|
4286
|
+
const visViewer = this.visViewer();
|
|
4287
|
+
const device = visViewer.getActiveDevice();
|
|
4288
|
+
if (device.isNull())
|
|
4289
|
+
return this;
|
|
4290
|
+
const view = device.getActiveView();
|
|
4291
|
+
view.enableDefaultLighting(true, visLib.DefaultLightingType.kTwoLights);
|
|
4292
|
+
view.setDefaultLightingIntensity(1.25);
|
|
4293
|
+
let visualStyleId;
|
|
4294
|
+
try {
|
|
4295
|
+
visualStyleId = visViewer.findVisualStyle("OpenCloud");
|
|
4296
|
+
}
|
|
4297
|
+
catch {
|
|
4298
|
+
visualStyleId = undefined;
|
|
4299
|
+
}
|
|
4300
|
+
if (!visualStyleId || visualStyleId.isNull()) {
|
|
4301
|
+
visualStyleId = visViewer.createVisualStyle("OpenCloud");
|
|
4302
|
+
const colorDef = new visLib.OdTvColorDef(66, 66, 66);
|
|
4303
|
+
const shadedVsId = visViewer.findVisualStyle("Realistic");
|
|
4304
|
+
const visualStylePtr = visualStyleId.openObject();
|
|
4305
|
+
visualStylePtr.copyFrom(shadedVsId);
|
|
4306
|
+
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kFaceModifiers, 0, visLib.VisualStyleOperations.kSet);
|
|
4307
|
+
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kEdgeModel, 2, visLib.VisualStyleOperations.kSet);
|
|
4308
|
+
visualStylePtr.setOptionDouble(visLib.VisualStyleOptions.kEdgeCreaseAngle, 60, visLib.VisualStyleOperations.kSet);
|
|
4309
|
+
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kEdgeStyles, 0, visLib.VisualStyleOperations.kSet);
|
|
4310
|
+
visualStylePtr.setOptionInt32(visLib.VisualStyleOptions.kEdgeModifiers, 8, visLib.VisualStyleOperations.kSet);
|
|
4311
|
+
visualStylePtr.setOptionColor(visLib.VisualStyleOptions.kEdgeColorValue, colorDef, visLib.VisualStyleOperations.kSet);
|
|
4312
|
+
visualStylePtr.delete();
|
|
4313
|
+
}
|
|
4314
|
+
view.visualStyle = visualStyleId;
|
|
4315
|
+
if (options.showWCS !== visViewer.getEnableWCS()) {
|
|
4316
|
+
visViewer.setEnableWCS(options.showWCS);
|
|
4317
|
+
}
|
|
4318
|
+
if (options.cameraAnimation !== visViewer.getEnableAnimation()) {
|
|
4319
|
+
visViewer.setEnableAnimation(options.cameraAnimation);
|
|
4320
|
+
}
|
|
4321
|
+
const antialiasing = options.antialiasing === true || options.antialiasing === "fxaa";
|
|
4322
|
+
if (antialiasing !== visViewer.fxaaAntiAliasing3d) {
|
|
4323
|
+
visViewer.fxaaAntiAliasing3d = antialiasing;
|
|
4089
4324
|
visViewer.fxaaQuality = 5;
|
|
4090
4325
|
}
|
|
4091
4326
|
if (options.shadows !== visViewer.shadows) {
|
|
4092
4327
|
visViewer.shadows = options.shadows;
|
|
4093
|
-
const canvas = visLib.canvas;
|
|
4094
|
-
device.invalidate([0, canvas.width, canvas.height, 0]);
|
|
4095
4328
|
}
|
|
4096
4329
|
if (options.groundShadow !== visViewer.groundShadow) {
|
|
4097
4330
|
visViewer.groundShadow = options.groundShadow;
|
|
@@ -4117,17 +4350,7 @@ class Viewer extends EventEmitter2 {
|
|
|
4117
4350
|
visualStyleId.delete();
|
|
4118
4351
|
activeView.delete();
|
|
4119
4352
|
}
|
|
4120
|
-
device.delete();
|
|
4121
|
-
this.syncHighlightingOptions(options);
|
|
4122
|
-
this.update();
|
|
4123
|
-
return this;
|
|
4124
|
-
}
|
|
4125
|
-
syncHighlightingOptions(options = this.options) {
|
|
4126
|
-
if (!this.visualizeJs)
|
|
4127
|
-
return this;
|
|
4128
4353
|
const params = options.enableCustomHighlight ? options : Options.defaults();
|
|
4129
|
-
const visLib = this.visLib();
|
|
4130
|
-
const visViewer = this.visViewer();
|
|
4131
4354
|
const { Entry, OdTvRGBColorDef } = visLib;
|
|
4132
4355
|
const highlightStyleId = visViewer.findHighlightStyle("Web_Default");
|
|
4133
4356
|
const highlightStylePtr = highlightStyleId.openObject();
|
|
@@ -4154,19 +4377,80 @@ class Viewer extends EventEmitter2 {
|
|
|
4154
4377
|
const visibility = !isExist(params.edgesVisibility) ? true : params.edgesVisibility;
|
|
4155
4378
|
highlightStylePtr.setEdgesVisibility(Entry.k2DTop.value | Entry.k3DTop.value, params.edgesOverlap && visibility);
|
|
4156
4379
|
}
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
device.invalidate([0, canvas.width, canvas.height, 0]);
|
|
4161
|
-
device.delete();
|
|
4162
|
-
}
|
|
4380
|
+
view.delete();
|
|
4381
|
+
device.delete();
|
|
4382
|
+
this.update();
|
|
4163
4383
|
return this;
|
|
4164
4384
|
}
|
|
4165
|
-
|
|
4166
|
-
|
|
4385
|
+
syncOverlay() {
|
|
4386
|
+
if (!this.visualizeJs)
|
|
4387
|
+
return;
|
|
4388
|
+
const visViewer = this.visViewer();
|
|
4389
|
+
const activeView = visViewer.activeView;
|
|
4390
|
+
let overlayView = visViewer.getViewByName(OVERLAY_VIEW_NAME);
|
|
4391
|
+
if (!overlayView) {
|
|
4392
|
+
const markupModel = visViewer.getMarkupModel();
|
|
4393
|
+
const pDevice = visViewer.getActiveDevice();
|
|
4394
|
+
overlayView = pDevice.createView(OVERLAY_VIEW_NAME, false);
|
|
4395
|
+
overlayView.addModel(markupModel);
|
|
4396
|
+
activeView.addSibling(overlayView);
|
|
4397
|
+
pDevice.addView(overlayView);
|
|
4398
|
+
}
|
|
4399
|
+
overlayView.viewPosition = activeView.viewPosition;
|
|
4400
|
+
overlayView.viewTarget = activeView.viewTarget;
|
|
4401
|
+
overlayView.upVector = activeView.upVector;
|
|
4402
|
+
overlayView.viewFieldWidth = activeView.viewFieldWidth;
|
|
4403
|
+
overlayView.viewFieldHeight = activeView.viewFieldHeight;
|
|
4404
|
+
const viewPort = overlayView.getViewport();
|
|
4405
|
+
overlayView.setViewport(viewPort.lowerLeft, viewPort.upperRight);
|
|
4406
|
+
overlayView.vportRect = activeView.vportRect;
|
|
4407
|
+
this._markup.syncOverlay();
|
|
4408
|
+
this.update();
|
|
4167
4409
|
}
|
|
4168
|
-
|
|
4169
|
-
|
|
4410
|
+
clearOverlay() {
|
|
4411
|
+
if (!this.visualizeJs)
|
|
4412
|
+
return;
|
|
4413
|
+
this._markup.clearOverlay();
|
|
4414
|
+
this.update();
|
|
4415
|
+
}
|
|
4416
|
+
clearSlices() {
|
|
4417
|
+
if (!this.visualizeJs)
|
|
4418
|
+
return;
|
|
4419
|
+
const visViewer = this.visViewer();
|
|
4420
|
+
const activeView = visViewer.activeView;
|
|
4421
|
+
activeView.removeCuttingPlanes();
|
|
4422
|
+
activeView.delete();
|
|
4423
|
+
this.update();
|
|
4424
|
+
}
|
|
4425
|
+
getSelected() {
|
|
4426
|
+
return this.executeCommand("getSelected");
|
|
4427
|
+
}
|
|
4428
|
+
setSelected(handles) {
|
|
4429
|
+
this.executeCommand("setSelected", handles);
|
|
4430
|
+
}
|
|
4431
|
+
getSelected2() {
|
|
4432
|
+
return this.executeCommand("getSelected2");
|
|
4433
|
+
}
|
|
4434
|
+
setSelected2(handles) {
|
|
4435
|
+
this.executeCommand("setSelected2", handles);
|
|
4436
|
+
}
|
|
4437
|
+
clearSelected() {
|
|
4438
|
+
this.executeCommand("clearSelected");
|
|
4439
|
+
}
|
|
4440
|
+
hideSelected() {
|
|
4441
|
+
this.executeCommand("hideSelected");
|
|
4442
|
+
}
|
|
4443
|
+
isolateSelected() {
|
|
4444
|
+
this.executeCommand("isolateSelected");
|
|
4445
|
+
}
|
|
4446
|
+
showAll() {
|
|
4447
|
+
this.executeCommand("showAll");
|
|
4448
|
+
}
|
|
4449
|
+
explode(index = 0) {
|
|
4450
|
+
this.executeCommand("explode", index);
|
|
4451
|
+
}
|
|
4452
|
+
collect() {
|
|
4453
|
+
this.executeCommand("collect");
|
|
4170
4454
|
}
|
|
4171
4455
|
registerDragger(name, dragger) {
|
|
4172
4456
|
console.warn("Viewer.registerDragger() has been deprecated since 25.12 and will be removed in a future release, use draggers('visualizejs').registerDragger() instead.");
|
|
@@ -4213,55 +4497,102 @@ class Viewer extends EventEmitter2 {
|
|
|
4213
4497
|
getComponent(name) {
|
|
4214
4498
|
return this._components.find((component) => component.name === name);
|
|
4215
4499
|
}
|
|
4216
|
-
|
|
4500
|
+
drawViewpoint(viewpoint) {
|
|
4501
|
+
var _a, _b;
|
|
4217
4502
|
if (!this.visualizeJs)
|
|
4218
4503
|
return;
|
|
4219
4504
|
const visViewer = this.visViewer();
|
|
4220
4505
|
const activeView = visViewer.activeView;
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4506
|
+
const getPoint3dAsArray = (point3d) => {
|
|
4507
|
+
return [point3d.x, point3d.y, point3d.z];
|
|
4508
|
+
};
|
|
4509
|
+
const setOrthogonalCamera = (orthogonal_camera) => {
|
|
4510
|
+
if (orthogonal_camera) {
|
|
4511
|
+
activeView.setView(getPoint3dAsArray(orthogonal_camera.view_point), getPoint3dAsArray(orthogonal_camera.direction), getPoint3dAsArray(orthogonal_camera.up_vector), orthogonal_camera.field_width, orthogonal_camera.field_height, true);
|
|
4512
|
+
this.syncOverlay();
|
|
4513
|
+
this.emitEvent({ type: "changecameramode", mode: "orthographic" });
|
|
4514
|
+
}
|
|
4515
|
+
};
|
|
4516
|
+
const setPerspectiveCamera = (perspective_camera) => { };
|
|
4517
|
+
const setClippingPlanes = (clipping_planes) => {
|
|
4518
|
+
if (clipping_planes) {
|
|
4519
|
+
for (const clipping_plane of clipping_planes) {
|
|
4520
|
+
const cuttingPlane = new (this.visLib().OdTvPlane)();
|
|
4521
|
+
cuttingPlane.set(getPoint3dAsArray(clipping_plane.location), getPoint3dAsArray(clipping_plane.direction));
|
|
4522
|
+
activeView.addCuttingPlane(cuttingPlane);
|
|
4523
|
+
activeView.setEnableCuttingPlaneFill(true, 0x66, 0x66, 0x66);
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
};
|
|
4527
|
+
const setSelection = (selection) => {
|
|
4528
|
+
if (selection)
|
|
4529
|
+
this.setSelected(selection.map((component) => component.handle));
|
|
4530
|
+
};
|
|
4531
|
+
const draggerName = (_a = this._activeDragger) === null || _a === void 0 ? void 0 : _a.name;
|
|
4532
|
+
this.setActiveDragger();
|
|
4533
|
+
this.clearSlices();
|
|
4534
|
+
this.clearOverlay();
|
|
4535
|
+
this.clearSelected();
|
|
4536
|
+
this.showAll();
|
|
4537
|
+
this.explode();
|
|
4538
|
+
setOrthogonalCamera(viewpoint.orthogonal_camera);
|
|
4539
|
+
setPerspectiveCamera(viewpoint.perspective_camera);
|
|
4540
|
+
setClippingPlanes(viewpoint.clipping_planes);
|
|
4541
|
+
setSelection(((_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.selection2) || viewpoint.selection);
|
|
4542
|
+
this._markup.setViewpoint(viewpoint);
|
|
4543
|
+
this.setActiveDragger(draggerName);
|
|
4544
|
+
this.emitEvent({ type: "drawviewpoint", data: viewpoint });
|
|
4229
4545
|
this.update();
|
|
4230
4546
|
}
|
|
4231
|
-
|
|
4547
|
+
createViewpoint() {
|
|
4232
4548
|
if (!this.visualizeJs)
|
|
4233
|
-
return;
|
|
4549
|
+
return {};
|
|
4234
4550
|
const visViewer = this.visViewer();
|
|
4235
4551
|
const activeView = visViewer.activeView;
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4552
|
+
const getPoint3dFromArray = (array) => {
|
|
4553
|
+
return { x: array[0], y: array[1], z: array[2] };
|
|
4554
|
+
};
|
|
4555
|
+
const getOrthogonalCamera = () => {
|
|
4556
|
+
return {
|
|
4557
|
+
view_point: getPoint3dFromArray(activeView.viewPosition),
|
|
4558
|
+
direction: getPoint3dFromArray(activeView.viewTarget),
|
|
4559
|
+
up_vector: getPoint3dFromArray(activeView.upVector),
|
|
4560
|
+
field_width: activeView.viewFieldWidth,
|
|
4561
|
+
field_height: activeView.viewFieldHeight,
|
|
4562
|
+
view_to_world_scale: 1,
|
|
4563
|
+
};
|
|
4564
|
+
};
|
|
4565
|
+
const getPerspectiveCamera = () => {
|
|
4566
|
+
return undefined;
|
|
4567
|
+
};
|
|
4568
|
+
const getClippingPlanes = () => {
|
|
4569
|
+
const clipping_planes = [];
|
|
4570
|
+
for (let i = 0; i < activeView.numCuttingPlanes(); i++) {
|
|
4571
|
+
const cuttingPlane = activeView.getCuttingPlane(i);
|
|
4572
|
+
const clipping_plane = {
|
|
4573
|
+
location: getPoint3dFromArray(cuttingPlane.getOrigin()),
|
|
4574
|
+
direction: getPoint3dFromArray(cuttingPlane.normal()),
|
|
4575
|
+
};
|
|
4576
|
+
clipping_planes.push(clipping_plane);
|
|
4577
|
+
}
|
|
4578
|
+
return clipping_planes;
|
|
4579
|
+
};
|
|
4580
|
+
const getSelection = () => {
|
|
4581
|
+
return this.getSelected().map((handle) => ({ handle }));
|
|
4582
|
+
};
|
|
4583
|
+
const getSelection2 = () => {
|
|
4584
|
+
return this.getSelected2().map((handle) => ({ handle }));
|
|
4585
|
+
};
|
|
4586
|
+
const viewpoint = { custom_fields: {} };
|
|
4587
|
+
viewpoint.orthogonal_camera = getOrthogonalCamera();
|
|
4588
|
+
viewpoint.perspective_camera = getPerspectiveCamera();
|
|
4589
|
+
viewpoint.clipping_planes = getClippingPlanes();
|
|
4590
|
+
viewpoint.selection = getSelection();
|
|
4591
|
+
viewpoint.description = new Date().toDateString();
|
|
4592
|
+
this._markup.getViewpoint(viewpoint);
|
|
4593
|
+
viewpoint.custom_fields.selection2 = getSelection2();
|
|
4594
|
+
this.emitEvent({ type: "createviewpoint", data: viewpoint });
|
|
4595
|
+
return viewpoint;
|
|
4265
4596
|
}
|
|
4266
4597
|
screenToWorld(position) {
|
|
4267
4598
|
if (!this.visualizeJs)
|
|
@@ -4296,184 +4627,23 @@ class Viewer extends EventEmitter2 {
|
|
|
4296
4627
|
result.z = 1 / z;
|
|
4297
4628
|
return result;
|
|
4298
4629
|
}
|
|
4299
|
-
|
|
4300
|
-
return
|
|
4301
|
-
}
|
|
4302
|
-
setSelected(handles) {
|
|
4303
|
-
this.executeCommand("setSelected", handles);
|
|
4304
|
-
}
|
|
4305
|
-
clearSelected() {
|
|
4306
|
-
this.executeCommand("clearSelected");
|
|
4307
|
-
}
|
|
4308
|
-
hideSelected() {
|
|
4309
|
-
this.executeCommand("hideSelected");
|
|
4310
|
-
}
|
|
4311
|
-
isolateSelected() {
|
|
4312
|
-
this.executeCommand("isolateSelected");
|
|
4313
|
-
}
|
|
4314
|
-
showAll() {
|
|
4315
|
-
this.executeCommand("showAll");
|
|
4316
|
-
}
|
|
4317
|
-
explode(index = 0) {
|
|
4318
|
-
this.executeCommand("explode", index);
|
|
4319
|
-
}
|
|
4320
|
-
collect() {
|
|
4321
|
-
this.executeCommand("collect");
|
|
4322
|
-
}
|
|
4323
|
-
async loadReferences(model) {
|
|
4324
|
-
var _a;
|
|
4325
|
-
if (!this.visualizeJs)
|
|
4326
|
-
return this;
|
|
4327
|
-
if (!this.client)
|
|
4328
|
-
return this;
|
|
4329
|
-
if (!model.getReferences)
|
|
4330
|
-
return this;
|
|
4331
|
-
const abortController = new AbortController();
|
|
4332
|
-
(_a = this._abortControllerForReferences) === null || _a === void 0 ? void 0 : _a.abort();
|
|
4333
|
-
this._abortControllerForReferences = abortController;
|
|
4334
|
-
let references = [];
|
|
4335
|
-
await model
|
|
4336
|
-
.getReferences(abortController.signal)
|
|
4337
|
-
.then((data) => (references = data.references))
|
|
4338
|
-
.catch((e) => console.error("Cannot load model references.", e));
|
|
4339
|
-
for (const file of references) {
|
|
4340
|
-
await this.client
|
|
4341
|
-
.downloadFile(file.id, undefined, abortController.signal)
|
|
4342
|
-
.then((arrayBuffer) => { var _a; return (_a = this.visualizeJs) === null || _a === void 0 ? void 0 : _a.getViewer().addEmbeddedFile(file.name, new Uint8Array(arrayBuffer)); })
|
|
4343
|
-
.catch((e) => console.error(`Cannot load reference file ${file.name}.`, e));
|
|
4344
|
-
}
|
|
4345
|
-
return this;
|
|
4346
|
-
}
|
|
4347
|
-
applyModelTransformMatrix(model) {
|
|
4348
|
-
this.executeCommand("applyModelTransform", model);
|
|
4630
|
+
executeCommand(id, ...args) {
|
|
4631
|
+
return commands.executeCommand(id, this, ...args);
|
|
4349
4632
|
}
|
|
4350
|
-
|
|
4633
|
+
addMarkupEntity(entityName) {
|
|
4351
4634
|
if (!this.visualizeJs)
|
|
4352
|
-
return;
|
|
4353
|
-
|
|
4635
|
+
return null;
|
|
4636
|
+
this.syncOverlay();
|
|
4354
4637
|
const visViewer = this.visViewer();
|
|
4355
|
-
const
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4638
|
+
const model = visViewer.getMarkupModel();
|
|
4639
|
+
const entityId = model.appendEntity(entityName);
|
|
4640
|
+
const entityPtr = entityId.openObject();
|
|
4641
|
+
const color = this.getMarkupColor();
|
|
4642
|
+
entityPtr.setColor(color.r, color.g, color.b);
|
|
4643
|
+
entityPtr.setLineWeight(2);
|
|
4644
|
+
entityPtr.delete();
|
|
4360
4645
|
this.update();
|
|
4361
|
-
|
|
4362
|
-
async open(file, params = {}) {
|
|
4363
|
-
if (!this.visualizeJs)
|
|
4364
|
-
return this;
|
|
4365
|
-
this.cancel();
|
|
4366
|
-
this.clear();
|
|
4367
|
-
this.emitEvent({ type: "open", file });
|
|
4368
|
-
let model = file;
|
|
4369
|
-
if (model && typeof model.getModels === "function") {
|
|
4370
|
-
const models = await model.getModels();
|
|
4371
|
-
model = models.find((model) => model.default) || models[0] || file;
|
|
4372
|
-
}
|
|
4373
|
-
if (!model)
|
|
4374
|
-
throw new Error(`Format not supported`);
|
|
4375
|
-
let format = params.format;
|
|
4376
|
-
if (!format && typeof model.type === "string")
|
|
4377
|
-
format = model.type.split(".").pop();
|
|
4378
|
-
if (!format && typeof file === "string")
|
|
4379
|
-
format = file.split(".").pop();
|
|
4380
|
-
if (!format && file instanceof globalThis.File)
|
|
4381
|
-
format = file.name.split(".").pop();
|
|
4382
|
-
const loader = loaders.createLoader(this, model, format);
|
|
4383
|
-
if (!loader)
|
|
4384
|
-
throw new Error(`Format not supported`);
|
|
4385
|
-
this.loaders.push(loader);
|
|
4386
|
-
this.emitEvent({ type: "geometrystart", file, model });
|
|
4387
|
-
try {
|
|
4388
|
-
await this.loadReferences(model);
|
|
4389
|
-
await loader.load(model, format, params);
|
|
4390
|
-
}
|
|
4391
|
-
catch (error) {
|
|
4392
|
-
this.emitEvent({ type: "geometryerror", data: error, file, model });
|
|
4393
|
-
throw error;
|
|
4394
|
-
}
|
|
4395
|
-
this.emitEvent({ type: "geometryend", file, model });
|
|
4396
|
-
if (this.visualizeJs) {
|
|
4397
|
-
this.applyModelTransformMatrix(model);
|
|
4398
|
-
this.applySceneGraphSettings();
|
|
4399
|
-
}
|
|
4400
|
-
return this;
|
|
4401
|
-
}
|
|
4402
|
-
openVsfFile(buffer) {
|
|
4403
|
-
console.warn("Viewer.openVsfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
|
|
4404
|
-
if (!this.visualizeJs)
|
|
4405
|
-
return this;
|
|
4406
|
-
this.cancel();
|
|
4407
|
-
this.clear();
|
|
4408
|
-
this.emitEvent({ type: "open", file: "", buffer });
|
|
4409
|
-
const visViewer = this.visViewer();
|
|
4410
|
-
this.emitEvent({ type: "geometrystart", file: "", buffer });
|
|
4411
|
-
try {
|
|
4412
|
-
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
4413
|
-
visViewer.parseFile(data);
|
|
4414
|
-
this.syncOptions();
|
|
4415
|
-
this.syncOverlay();
|
|
4416
|
-
this.update(true);
|
|
4417
|
-
this.emitEvent({ type: "geometryprogress", data: 1, file: "", buffer });
|
|
4418
|
-
this.emitEvent({ type: "databasechunk", data, file: "", buffer });
|
|
4419
|
-
}
|
|
4420
|
-
catch (error) {
|
|
4421
|
-
this.emitEvent({ type: "geometryerror", data: error, file: "", buffer });
|
|
4422
|
-
throw error;
|
|
4423
|
-
}
|
|
4424
|
-
this.emitEvent({ type: "geometryend", file: "", buffer });
|
|
4425
|
-
return this;
|
|
4426
|
-
}
|
|
4427
|
-
openVsfxFile(buffer) {
|
|
4428
|
-
console.warn("Viewer.openVsfxFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
|
|
4429
|
-
if (!this.visualizeJs)
|
|
4430
|
-
return this;
|
|
4431
|
-
this.cancel();
|
|
4432
|
-
this.clear();
|
|
4433
|
-
this.emitEvent({ type: "open", file: "", buffer });
|
|
4434
|
-
const visViewer = this.visViewer();
|
|
4435
|
-
this.emitEvent({ type: "geometrystart", file: "", buffer });
|
|
4436
|
-
try {
|
|
4437
|
-
const data = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
4438
|
-
visViewer.parseVsfx(data);
|
|
4439
|
-
this.syncOptions();
|
|
4440
|
-
this.syncOverlay();
|
|
4441
|
-
this.update(true);
|
|
4442
|
-
this.emitEvent({ type: "geometryprogress", data: 1, file: "", buffer });
|
|
4443
|
-
this.emitEvent({ type: "databasechunk", data, file: "", buffer });
|
|
4444
|
-
}
|
|
4445
|
-
catch (error) {
|
|
4446
|
-
this.emitEvent({ type: "geometryerror", data: error, file: "", buffer });
|
|
4447
|
-
throw error;
|
|
4448
|
-
}
|
|
4449
|
-
this.emitEvent({ type: "geometryend", file: "", buffer });
|
|
4450
|
-
return this;
|
|
4451
|
-
}
|
|
4452
|
-
cancel() {
|
|
4453
|
-
var _a;
|
|
4454
|
-
(_a = this._abortControllerForReferences) === null || _a === void 0 ? void 0 : _a.abort();
|
|
4455
|
-
this._abortControllerForReferences = undefined;
|
|
4456
|
-
this.loaders.forEach((loader) => loader.cancel());
|
|
4457
|
-
this.emitEvent({ type: "cancel" });
|
|
4458
|
-
return this;
|
|
4459
|
-
}
|
|
4460
|
-
clear() {
|
|
4461
|
-
if (!this.visualizeJs)
|
|
4462
|
-
return this;
|
|
4463
|
-
const visViewer = this.visViewer();
|
|
4464
|
-
this.setActiveDragger();
|
|
4465
|
-
this.clearSlices();
|
|
4466
|
-
this.clearOverlay();
|
|
4467
|
-
this.clearSelected();
|
|
4468
|
-
this.loaders.forEach((loader) => loader.dispose());
|
|
4469
|
-
this.loaders = [];
|
|
4470
|
-
visViewer.clear();
|
|
4471
|
-
visViewer.createLocalDatabase();
|
|
4472
|
-
this.syncOptions();
|
|
4473
|
-
this.syncOverlay();
|
|
4474
|
-
this.update(true);
|
|
4475
|
-
this.emitEvent({ type: "clear" });
|
|
4476
|
-
return this;
|
|
4646
|
+
return entityId;
|
|
4477
4647
|
}
|
|
4478
4648
|
getMarkupColor() {
|
|
4479
4649
|
console.warn("Viewer.getMarkupColor() has been deprecated since 25.11 and will be removed in a future release, use Viewer.markup.getMarkupColor() instead.");
|
|
@@ -4490,113 +4660,43 @@ class Viewer extends EventEmitter2 {
|
|
|
4490
4660
|
colorizeSelectedMarkups(r = 255, g = 0, b = 0) {
|
|
4491
4661
|
this._markup.colorizeSelectedMarkups(r, g, b);
|
|
4492
4662
|
}
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4663
|
+
scheduleUpdateAsync(maxScheduleUpdateTimeInMs = 50) {
|
|
4664
|
+
return new Promise((resolve, reject) => {
|
|
4665
|
+
setTimeout(() => {
|
|
4666
|
+
var _a, _b, _c;
|
|
4667
|
+
try {
|
|
4668
|
+
if (this._enableAutoUpdate) {
|
|
4669
|
+
(_a = this.visViewer()) === null || _a === void 0 ? void 0 : _a.update(maxScheduleUpdateTimeInMs);
|
|
4670
|
+
(_c = (_b = this._activeDragger) === null || _b === void 0 ? void 0 : _b.updatePreview) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
4671
|
+
}
|
|
4672
|
+
this.emitEvent({ type: "update", data: false });
|
|
4673
|
+
resolve();
|
|
4674
|
+
}
|
|
4675
|
+
catch (e) {
|
|
4676
|
+
console.error(e);
|
|
4677
|
+
reject();
|
|
4678
|
+
}
|
|
4679
|
+
}, 0);
|
|
4680
|
+
});
|
|
4507
4681
|
}
|
|
4508
|
-
|
|
4509
|
-
var _a;
|
|
4682
|
+
async updateAsync(maxScheduleUpdateTimeInMs = 50, maxScheduleUpdateCount = 50) {
|
|
4510
4683
|
if (!this.visualizeJs)
|
|
4511
4684
|
return;
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
this.setOrthogonalCameraSettings(viewpoint.orthogonal_camera);
|
|
4520
|
-
this.setClippingPlanes(viewpoint.clipping_planes);
|
|
4521
|
-
this.setSelection(viewpoint.selection);
|
|
4522
|
-
this._markup.setViewpoint(viewpoint);
|
|
4523
|
-
this.setActiveDragger(draggerName);
|
|
4524
|
-
this.emitEvent({ type: "drawviewpoint", data: viewpoint });
|
|
4525
|
-
this.update();
|
|
4526
|
-
}
|
|
4527
|
-
createViewpoint() {
|
|
4528
|
-
if (!this.visualizeJs)
|
|
4529
|
-
return {};
|
|
4530
|
-
const viewpoint = {};
|
|
4531
|
-
viewpoint.orthogonal_camera = this.getOrthogonalCameraSettings();
|
|
4532
|
-
viewpoint.clipping_planes = this.getClippingPlanes();
|
|
4533
|
-
viewpoint.selection = this.getSelection();
|
|
4534
|
-
viewpoint.description = new Date().toDateString();
|
|
4535
|
-
this._markup.getViewpoint(viewpoint);
|
|
4536
|
-
this.emitEvent({ type: "createviewpoint", data: viewpoint });
|
|
4537
|
-
return viewpoint;
|
|
4538
|
-
}
|
|
4539
|
-
getPoint3dFromArray(array) {
|
|
4540
|
-
return { x: array[0], y: array[1], z: array[2] };
|
|
4541
|
-
}
|
|
4542
|
-
getLogicalPoint3dAsArray(point3d) {
|
|
4543
|
-
return [point3d.x, point3d.y, point3d.z];
|
|
4544
|
-
}
|
|
4545
|
-
getOrthogonalCameraSettings() {
|
|
4546
|
-
const visViewer = this.visViewer();
|
|
4547
|
-
const activeView = visViewer.activeView;
|
|
4548
|
-
return {
|
|
4549
|
-
view_point: this.getPoint3dFromArray(activeView.viewPosition),
|
|
4550
|
-
direction: this.getPoint3dFromArray(activeView.viewTarget),
|
|
4551
|
-
up_vector: this.getPoint3dFromArray(activeView.upVector),
|
|
4552
|
-
field_width: activeView.viewFieldWidth,
|
|
4553
|
-
field_height: activeView.viewFieldHeight,
|
|
4554
|
-
view_to_world_scale: 1,
|
|
4555
|
-
};
|
|
4556
|
-
}
|
|
4557
|
-
setOrthogonalCameraSettings(settings) {
|
|
4558
|
-
const visViewer = this.visViewer();
|
|
4559
|
-
const activeView = visViewer.activeView;
|
|
4560
|
-
if (settings) {
|
|
4561
|
-
activeView.setView(this.getLogicalPoint3dAsArray(settings.view_point), this.getLogicalPoint3dAsArray(settings.direction), this.getLogicalPoint3dAsArray(settings.up_vector), settings.field_width, settings.field_height, true);
|
|
4562
|
-
this.syncOverlay();
|
|
4685
|
+
this._isRunAsyncUpdate = true;
|
|
4686
|
+
try {
|
|
4687
|
+
const device = this.visViewer().getActiveDevice();
|
|
4688
|
+
for (let iterationCount = 0; !device.isValid() && iterationCount < maxScheduleUpdateCount; iterationCount++) {
|
|
4689
|
+
await this.scheduleUpdateAsync(maxScheduleUpdateTimeInMs);
|
|
4690
|
+
}
|
|
4691
|
+
await this.scheduleUpdateAsync(maxScheduleUpdateTimeInMs);
|
|
4563
4692
|
}
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
const visViewer = this.visViewer();
|
|
4567
|
-
const activeView = visViewer.activeView;
|
|
4568
|
-
const clipping_planes = [];
|
|
4569
|
-
for (let i = 0; i < activeView.numCuttingPlanes(); i++) {
|
|
4570
|
-
const cuttingPlane = activeView.getCuttingPlane(i);
|
|
4571
|
-
const clipping_plane = {
|
|
4572
|
-
location: this.getPoint3dFromArray(cuttingPlane.getOrigin()),
|
|
4573
|
-
direction: this.getPoint3dFromArray(cuttingPlane.normal()),
|
|
4574
|
-
};
|
|
4575
|
-
clipping_planes.push(clipping_plane);
|
|
4693
|
+
catch (e) {
|
|
4694
|
+
console.error(e);
|
|
4576
4695
|
}
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
setClippingPlanes(clipping_planes) {
|
|
4580
|
-
if (clipping_planes) {
|
|
4581
|
-
const visViewer = this.visViewer();
|
|
4582
|
-
const activeView = visViewer.activeView;
|
|
4583
|
-
for (const clipping_plane of clipping_planes) {
|
|
4584
|
-
const cuttingPlane = new (this.visLib().OdTvPlane)();
|
|
4585
|
-
cuttingPlane.set(this.getLogicalPoint3dAsArray(clipping_plane.location), this.getLogicalPoint3dAsArray(clipping_plane.direction));
|
|
4586
|
-
activeView.addCuttingPlane(cuttingPlane);
|
|
4587
|
-
activeView.setEnableCuttingPlaneFill(true, 0x66, 0x66, 0x66);
|
|
4588
|
-
}
|
|
4696
|
+
finally {
|
|
4697
|
+
this._isRunAsyncUpdate = false;
|
|
4589
4698
|
}
|
|
4590
4699
|
}
|
|
4591
|
-
getSelection() {
|
|
4592
|
-
return this.getSelected().map((handle) => ({ handle }));
|
|
4593
|
-
}
|
|
4594
|
-
setSelection(selection) {
|
|
4595
|
-
this.setSelected(selection === null || selection === void 0 ? void 0 : selection.map((component) => component.handle));
|
|
4596
|
-
}
|
|
4597
|
-
executeCommand(id, ...args) {
|
|
4598
|
-
return commands.executeCommand(id, this, ...args);
|
|
4599
|
-
}
|
|
4600
4700
|
deviceAutoRegeneration() {
|
|
4601
4701
|
const visViewer = this.visViewer();
|
|
4602
4702
|
const device = visViewer.getActiveDevice();
|