@inweb/viewer-visualize 25.8.7 → 25.8.9
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 +99 -22
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +106 -22
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Commands/ApplyModelTransform.d.ts +1 -1
- package/lib/Viewer/Commands/AutoTransformAllModelsToCentralPoint.d.ts +1 -0
- package/lib/Viewer/Commands/index.d.ts +1 -0
- package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +1 -0
- package/package.json +5 -5
- package/src/Viewer/Commands/ApplyModelTransform.ts +16 -12
- package/src/Viewer/Commands/AutoTransformAllModelsToCentralPoint.ts +102 -0
- package/src/Viewer/Commands/index.ts +1 -0
- package/src/Viewer/Draggers/MeasureLineDragger/index.ts +10 -0
- package/src/Viewer/Viewer.ts +14 -6
|
@@ -374,11 +374,15 @@ class Dragger {
|
|
|
374
374
|
updatePreview() {}
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
const composeMatrixFromTransform = (
|
|
378
|
-
const
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
377
|
+
const composeMatrixFromTransform = (transform, modelCenter, visLib) => {
|
|
378
|
+
const {translate: translate, scale: scale, rotation: rotation} = transform;
|
|
379
|
+
const translateMatrix = new visLib.Matrix3d;
|
|
380
|
+
translateMatrix.setTranslation([ translate.x, translate.y, translate.z ]);
|
|
381
|
+
const rotateMatrix = new visLib.Matrix3d;
|
|
382
|
+
rotateMatrix.setToRotation(rotation.angle, [ rotation.x, rotation.y, rotation.z ], modelCenter);
|
|
383
|
+
const scaleMatrix = new visLib.Matrix3d;
|
|
384
|
+
scaleMatrix.setToScaling(scale, modelCenter);
|
|
385
|
+
return rotateMatrix.postMultBy(translateMatrix).postMultBy(scaleMatrix);
|
|
382
386
|
};
|
|
383
387
|
|
|
384
388
|
function applyModelTransform(viewer, model) {
|
|
@@ -393,7 +397,8 @@ function applyModelTransform(viewer, model) {
|
|
|
393
397
|
const transform = model.getModelTransformMatrix(modelPtr.getDatabaseHandle());
|
|
394
398
|
if (transform) {
|
|
395
399
|
const extents = modelPtr.getExtents();
|
|
396
|
-
|
|
400
|
+
extents.transformBy(modelPtr.getUnitsMatrix());
|
|
401
|
+
const matrix = composeMatrixFromTransform(transform, extents.center(), visLib);
|
|
397
402
|
modelPtr.setModelingMatrix(matrix, true);
|
|
398
403
|
}
|
|
399
404
|
}
|
|
@@ -705,6 +710,62 @@ function zoomToSelected(viewer) {
|
|
|
705
710
|
|
|
706
711
|
commands("VisualizeJS").registerCommand("zoomToSelected", zoomToSelected);
|
|
707
712
|
|
|
713
|
+
function isTemplateModel(modelPtr) {
|
|
714
|
+
return modelPtr.getName()[0] === "$";
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
async function autoTransformAllModelsToCentralPoint(viewer, model) {
|
|
718
|
+
var _a;
|
|
719
|
+
if (!viewer.visualizeJs) return;
|
|
720
|
+
if (!model.getModelTransformMatrix) return;
|
|
721
|
+
const visLib = viewer.visLib();
|
|
722
|
+
const visViewer = visLib.getViewer();
|
|
723
|
+
const viewExt = visViewer.getActiveExtents();
|
|
724
|
+
const centralPoint = viewExt.center();
|
|
725
|
+
const modelItr = visViewer.getModelIterator();
|
|
726
|
+
for (;!modelItr.done(); modelItr.step()) {
|
|
727
|
+
const modelPtr = modelItr.getModel();
|
|
728
|
+
if (!isTemplateModel(modelPtr)) {
|
|
729
|
+
let ext = modelPtr.getExtents();
|
|
730
|
+
const unitsMatrix = modelPtr.getUnitsMatrix();
|
|
731
|
+
ext.transformBy(modelPtr.getUnitsMatrix());
|
|
732
|
+
const unitsMatrixInvert = modelPtr.getUnitsMatrix().invert();
|
|
733
|
+
const center = ext.center();
|
|
734
|
+
const scale = 1;
|
|
735
|
+
const scaleMatrix = new visLib.Matrix3d;
|
|
736
|
+
const translateMatrix = new visLib.Matrix3d;
|
|
737
|
+
translateMatrix.setTranslation([ centralPoint[0] - center[0], centralPoint[1] - center[1], centralPoint[2] - center[2] ]);
|
|
738
|
+
scaleMatrix.setToScaling(scale, centralPoint);
|
|
739
|
+
const resMatrixWithUnits = unitsMatrixInvert.postMultBy(scaleMatrix).postMultBy(translateMatrix).postMultBy(unitsMatrix);
|
|
740
|
+
const resScale = resMatrixWithUnits.scale();
|
|
741
|
+
const transform = {
|
|
742
|
+
translate: {
|
|
743
|
+
x: resMatrixWithUnits.get(0, 3) - (1 - resScale) * center[0],
|
|
744
|
+
y: resMatrixWithUnits.get(1, 3) - (1 - resScale) * center[1],
|
|
745
|
+
z: resMatrixWithUnits.get(2, 3) - (1 - resScale) * center[2]
|
|
746
|
+
},
|
|
747
|
+
rotation: {
|
|
748
|
+
x: 0,
|
|
749
|
+
y: 0,
|
|
750
|
+
z: 1,
|
|
751
|
+
angle: 0
|
|
752
|
+
},
|
|
753
|
+
scale: resScale
|
|
754
|
+
};
|
|
755
|
+
const matrix = composeMatrixFromTransform(transform, center, visLib);
|
|
756
|
+
modelPtr.setModelingMatrix(matrix, true);
|
|
757
|
+
centralPoint[0] += Math.abs(ext.max()[0] - ext.min()[0]) * resScale;
|
|
758
|
+
await model.setModelTransformMatrix(modelPtr.getDatabaseHandle(), transform);
|
|
759
|
+
}
|
|
760
|
+
modelPtr.delete();
|
|
761
|
+
}
|
|
762
|
+
modelItr.delete();
|
|
763
|
+
(_a = visViewer.clearViewExtentsCache) === null || _a === void 0 ? void 0 : _a.call(visViewer);
|
|
764
|
+
viewer.update();
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
commands("VisualizeJS").registerCommand("autoTransformAllModelsToCentralPoint", autoTransformAllModelsToCentralPoint);
|
|
768
|
+
|
|
708
769
|
class MarkupColor {
|
|
709
770
|
get HexColor() {
|
|
710
771
|
return "#" + this._hex;
|
|
@@ -766,7 +827,7 @@ class KonvaLine {
|
|
|
766
827
|
this._ref = ref;
|
|
767
828
|
return;
|
|
768
829
|
}
|
|
769
|
-
if (!params.points) return;
|
|
830
|
+
if (!params || !params.points) return;
|
|
770
831
|
const konvaPoints = [];
|
|
771
832
|
params.points.forEach((point => konvaPoints.push(point.x, point.y)));
|
|
772
833
|
this._ref = new Konva.Line({
|
|
@@ -868,7 +929,7 @@ class KonvaText {
|
|
|
868
929
|
this._ref = ref;
|
|
869
930
|
return;
|
|
870
931
|
}
|
|
871
|
-
if (!params || !params.text) return;
|
|
932
|
+
if (!params || !params.position || !params.text) return;
|
|
872
933
|
this._ref = new Konva.Text({
|
|
873
934
|
x: params.position.x,
|
|
874
935
|
y: params.position.y,
|
|
@@ -970,7 +1031,7 @@ class KonvaRectangle {
|
|
|
970
1031
|
this._ref = ref;
|
|
971
1032
|
return;
|
|
972
1033
|
}
|
|
973
|
-
if (!params.position) return;
|
|
1034
|
+
if (!params || !params.position) return;
|
|
974
1035
|
this._ref = new Konva.Rect({
|
|
975
1036
|
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
976
1037
|
strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
|
|
@@ -1080,7 +1141,7 @@ class KonvaEllipse {
|
|
|
1080
1141
|
this._ref = ref;
|
|
1081
1142
|
return;
|
|
1082
1143
|
}
|
|
1083
|
-
if (!params.position) return;
|
|
1144
|
+
if (!params || !params.position || !params.radius) return;
|
|
1084
1145
|
this._ref = new Konva.Ellipse({
|
|
1085
1146
|
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
1086
1147
|
strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
|
|
@@ -1202,7 +1263,7 @@ class KonvaArrow {
|
|
|
1202
1263
|
this._ref = ref;
|
|
1203
1264
|
return;
|
|
1204
1265
|
}
|
|
1205
|
-
if (!params.start || !params.end) return;
|
|
1266
|
+
if (!params || !params.start || !params.end) return;
|
|
1206
1267
|
this._ref = new Konva.Arrow({
|
|
1207
1268
|
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
1208
1269
|
fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
|
|
@@ -1296,6 +1357,7 @@ class KonvaArrow {
|
|
|
1296
1357
|
|
|
1297
1358
|
class KonvaImage {
|
|
1298
1359
|
constructor(params, ref = null) {
|
|
1360
|
+
var _a, _b;
|
|
1299
1361
|
this._ratio = 1;
|
|
1300
1362
|
if (ref) {
|
|
1301
1363
|
if (ref.height() === 0 || ref.width() === 0) return;
|
|
@@ -1304,14 +1366,14 @@ class KonvaImage {
|
|
|
1304
1366
|
this._ratio = this._ref.height() / this._ref.width();
|
|
1305
1367
|
return;
|
|
1306
1368
|
}
|
|
1307
|
-
if (!params.position || !params.src) return;
|
|
1369
|
+
if (!params || !params.position || !params.src) return;
|
|
1308
1370
|
this._canvasImage = new Image;
|
|
1309
1371
|
this._ref = new Konva.Image({
|
|
1310
1372
|
x: params.position.x,
|
|
1311
1373
|
y: params.position.y,
|
|
1312
1374
|
image: this._canvasImage,
|
|
1313
|
-
width: params.width,
|
|
1314
|
-
height: params.height,
|
|
1375
|
+
width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
|
|
1376
|
+
height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
|
|
1315
1377
|
draggable: true
|
|
1316
1378
|
});
|
|
1317
1379
|
this._canvasImage.onload = () => {
|
|
@@ -1419,7 +1481,7 @@ class KonvaCloud {
|
|
|
1419
1481
|
this._ref = ref;
|
|
1420
1482
|
return;
|
|
1421
1483
|
}
|
|
1422
|
-
if (!params
|
|
1484
|
+
if (!params || !params.position) return;
|
|
1423
1485
|
const arcRadius = 16;
|
|
1424
1486
|
this._ref = new Konva.Shape({
|
|
1425
1487
|
x: params.position.x,
|
|
@@ -1623,7 +1685,7 @@ const MarkupMode2Konva = {
|
|
|
1623
1685
|
},
|
|
1624
1686
|
Cloud: {
|
|
1625
1687
|
name: "Cloud",
|
|
1626
|
-
initializer: ref => new KonvaCloud(
|
|
1688
|
+
initializer: (ref, params = null) => new KonvaCloud(params, ref),
|
|
1627
1689
|
zIndex: 1
|
|
1628
1690
|
}
|
|
1629
1691
|
};
|
|
@@ -3091,6 +3153,14 @@ class MeasureLineDragger extends OdBaseDragger {
|
|
|
3091
3153
|
pt2[1] -= pt1[1];
|
|
3092
3154
|
return Math.min(pt2[0], pt2[1]) / 120;
|
|
3093
3155
|
}
|
|
3156
|
+
start(x, y) {
|
|
3157
|
+
this.createNewMeasureIfNeed();
|
|
3158
|
+
const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
|
|
3159
|
+
if (point) {
|
|
3160
|
+
this.firstPoint = point;
|
|
3161
|
+
this.previewMeasureLine.setStartPoint(this.firstPoint);
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3094
3164
|
drag(x, y) {
|
|
3095
3165
|
this.createNewMeasureIfNeed();
|
|
3096
3166
|
const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
|
|
@@ -5471,10 +5541,24 @@ class Viewer extends EventEmitter2 {
|
|
|
5471
5541
|
return extHeight !== 0;
|
|
5472
5542
|
}
|
|
5473
5543
|
screenToWorld(position) {
|
|
5474
|
-
|
|
5544
|
+
if (!this.visualizeJs) return {
|
|
5545
|
+
x: position.x,
|
|
5546
|
+
y: position.y,
|
|
5547
|
+
z: 0
|
|
5548
|
+
};
|
|
5549
|
+
const worldPoint = this.visViewer().screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
5550
|
+
const result = {
|
|
5551
|
+
x: worldPoint[0],
|
|
5552
|
+
y: worldPoint[1],
|
|
5553
|
+
z: worldPoint[2]
|
|
5554
|
+
};
|
|
5555
|
+
return result;
|
|
5475
5556
|
}
|
|
5476
5557
|
worldToScreen(position) {
|
|
5477
|
-
if (!this.visualizeJs) return
|
|
5558
|
+
if (!this.visualizeJs) return {
|
|
5559
|
+
x: position.x,
|
|
5560
|
+
y: position.y
|
|
5561
|
+
};
|
|
5478
5562
|
const activeView = this.visViewer().activeView;
|
|
5479
5563
|
const worldMatrix = activeView.worldToDeviceMatrix;
|
|
5480
5564
|
const worldPoint = this.visLib().Point3d.createFromArray([ position.x, position.y, position.z ]);
|
|
@@ -5497,12 +5581,12 @@ class Viewer extends EventEmitter2 {
|
|
|
5497
5581
|
};
|
|
5498
5582
|
const projMatrix = this.visViewer().activeView.projectionMatrix;
|
|
5499
5583
|
const tolerance = 1e-6;
|
|
5500
|
-
const x = projMatrix.get(
|
|
5501
|
-
if (x > tolerance || x < -tolerance) result.x = 1 /
|
|
5584
|
+
const x = projMatrix.get(0, 0);
|
|
5585
|
+
if (x > tolerance || x < -tolerance) result.x = 1 / x;
|
|
5502
5586
|
const y = projMatrix.get(1, 1);
|
|
5503
|
-
if (y > tolerance || y < -tolerance) result.y = 1 /
|
|
5587
|
+
if (y > tolerance || y < -tolerance) result.y = 1 / y;
|
|
5504
5588
|
const z = projMatrix.get(2, 2);
|
|
5505
|
-
if (z > tolerance || z < -tolerance) result.z = 1 /
|
|
5589
|
+
if (z > tolerance || z < -tolerance) result.z = 1 / z;
|
|
5506
5590
|
return result;
|
|
5507
5591
|
}
|
|
5508
5592
|
getSelected() {
|