@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
package/dist/viewer-visualize.js
CHANGED
|
@@ -379,11 +379,15 @@
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
///////////////////////////////////////////////////////////////////////////////
|
|
382
|
-
const composeMatrixFromTransform = (
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
382
|
+
const composeMatrixFromTransform = (transform, modelCenter, visLib) => {
|
|
383
|
+
const { translate, scale, rotation } = transform;
|
|
384
|
+
const translateMatrix = new visLib.Matrix3d();
|
|
385
|
+
translateMatrix.setTranslation([translate.x, translate.y, translate.z]);
|
|
386
|
+
const rotateMatrix = new visLib.Matrix3d();
|
|
387
|
+
rotateMatrix.setToRotation(rotation.angle, [rotation.x, rotation.y, rotation.z], modelCenter);
|
|
388
|
+
const scaleMatrix = new visLib.Matrix3d();
|
|
389
|
+
scaleMatrix.setToScaling(scale, modelCenter);
|
|
390
|
+
return rotateMatrix.postMultBy(translateMatrix).postMultBy(scaleMatrix);
|
|
387
391
|
};
|
|
388
392
|
function applyModelTransform(viewer, model) {
|
|
389
393
|
var _a;
|
|
@@ -399,7 +403,8 @@
|
|
|
399
403
|
const transform = model.getModelTransformMatrix(modelPtr.getDatabaseHandle());
|
|
400
404
|
if (transform) {
|
|
401
405
|
const extents = modelPtr.getExtents();
|
|
402
|
-
|
|
406
|
+
extents.transformBy(modelPtr.getUnitsMatrix());
|
|
407
|
+
const matrix = composeMatrixFromTransform(transform, extents.center(), visLib);
|
|
403
408
|
modelPtr.setModelingMatrix(matrix, true);
|
|
404
409
|
}
|
|
405
410
|
}
|
|
@@ -692,6 +697,65 @@
|
|
|
692
697
|
}
|
|
693
698
|
commands("VisualizeJS").registerCommand("zoomToSelected", zoomToSelected);
|
|
694
699
|
|
|
700
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
701
|
+
function isTemplateModel(modelPtr) {
|
|
702
|
+
return modelPtr.getName()[0] === "$";
|
|
703
|
+
}
|
|
704
|
+
async function autoTransformAllModelsToCentralPoint(viewer, model) {
|
|
705
|
+
var _a;
|
|
706
|
+
if (!viewer.visualizeJs)
|
|
707
|
+
return;
|
|
708
|
+
if (!model.getModelTransformMatrix)
|
|
709
|
+
return; // Model.getModelTransformMatrix() since 24.3.14
|
|
710
|
+
const visLib = viewer.visLib();
|
|
711
|
+
const visViewer = visLib.getViewer();
|
|
712
|
+
const viewExt = visViewer.getActiveExtents();
|
|
713
|
+
const centralPoint = viewExt.center();
|
|
714
|
+
const modelItr = visViewer.getModelIterator();
|
|
715
|
+
for (; !modelItr.done(); modelItr.step()) {
|
|
716
|
+
const modelPtr = modelItr.getModel();
|
|
717
|
+
if (!isTemplateModel(modelPtr)) {
|
|
718
|
+
let ext = modelPtr.getExtents();
|
|
719
|
+
const unitsMatrix = modelPtr.getUnitsMatrix();
|
|
720
|
+
ext.transformBy(modelPtr.getUnitsMatrix()); // ext in wcs
|
|
721
|
+
const unitsMatrixInvert = modelPtr.getUnitsMatrix().invert();
|
|
722
|
+
const center = ext.center();
|
|
723
|
+
const scale = 1.0;
|
|
724
|
+
const scaleMatrix = new visLib.Matrix3d();
|
|
725
|
+
const translateMatrix = new visLib.Matrix3d();
|
|
726
|
+
translateMatrix.setTranslation([
|
|
727
|
+
centralPoint[0] - center[0],
|
|
728
|
+
centralPoint[1] - center[1],
|
|
729
|
+
centralPoint[2] - center[2],
|
|
730
|
+
]);
|
|
731
|
+
scaleMatrix.setToScaling(scale, centralPoint);
|
|
732
|
+
const resMatrixWithUnits = unitsMatrixInvert
|
|
733
|
+
.postMultBy(scaleMatrix)
|
|
734
|
+
.postMultBy(translateMatrix)
|
|
735
|
+
.postMultBy(unitsMatrix);
|
|
736
|
+
const resScale = resMatrixWithUnits.scale();
|
|
737
|
+
const transform = {
|
|
738
|
+
translate: {
|
|
739
|
+
x: resMatrixWithUnits.get(0, 3) - (1 - resScale) * center[0],
|
|
740
|
+
y: resMatrixWithUnits.get(1, 3) - (1 - resScale) * center[1],
|
|
741
|
+
z: resMatrixWithUnits.get(2, 3) - (1 - resScale) * center[2],
|
|
742
|
+
},
|
|
743
|
+
rotation: { x: 0, y: 0, z: 1, angle: 0.0 },
|
|
744
|
+
scale: resScale,
|
|
745
|
+
};
|
|
746
|
+
const matrix = composeMatrixFromTransform(transform, center, visLib);
|
|
747
|
+
modelPtr.setModelingMatrix(matrix, true);
|
|
748
|
+
centralPoint[0] += Math.abs(ext.max()[0] - ext.min()[0]) * resScale;
|
|
749
|
+
await model.setModelTransformMatrix(modelPtr.getDatabaseHandle(), transform);
|
|
750
|
+
}
|
|
751
|
+
modelPtr.delete();
|
|
752
|
+
}
|
|
753
|
+
modelItr.delete();
|
|
754
|
+
(_a = visViewer.clearViewExtentsCache) === null || _a === void 0 ? void 0 : _a.call(visViewer);
|
|
755
|
+
viewer.update();
|
|
756
|
+
}
|
|
757
|
+
commands("VisualizeJS").registerCommand("autoTransformAllModelsToCentralPoint", autoTransformAllModelsToCentralPoint);
|
|
758
|
+
|
|
695
759
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
696
760
|
|
|
697
761
|
function getDefaultExportFromCjs (x) {
|
|
@@ -12204,7 +12268,7 @@
|
|
|
12204
12268
|
this._ref = ref;
|
|
12205
12269
|
return;
|
|
12206
12270
|
}
|
|
12207
|
-
if (!params.points) return;
|
|
12271
|
+
if (!params || !params.points) return;
|
|
12208
12272
|
const konvaPoints = [];
|
|
12209
12273
|
params.points.forEach((point => konvaPoints.push(point.x, point.y)));
|
|
12210
12274
|
this._ref = new Konva.Line({
|
|
@@ -12306,7 +12370,7 @@
|
|
|
12306
12370
|
this._ref = ref;
|
|
12307
12371
|
return;
|
|
12308
12372
|
}
|
|
12309
|
-
if (!params || !params.text) return;
|
|
12373
|
+
if (!params || !params.position || !params.text) return;
|
|
12310
12374
|
this._ref = new Konva.Text({
|
|
12311
12375
|
x: params.position.x,
|
|
12312
12376
|
y: params.position.y,
|
|
@@ -12408,7 +12472,7 @@
|
|
|
12408
12472
|
this._ref = ref;
|
|
12409
12473
|
return;
|
|
12410
12474
|
}
|
|
12411
|
-
if (!params.position) return;
|
|
12475
|
+
if (!params || !params.position) return;
|
|
12412
12476
|
this._ref = new Konva.Rect({
|
|
12413
12477
|
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
12414
12478
|
strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
|
|
@@ -12518,7 +12582,7 @@
|
|
|
12518
12582
|
this._ref = ref;
|
|
12519
12583
|
return;
|
|
12520
12584
|
}
|
|
12521
|
-
if (!params.position) return;
|
|
12585
|
+
if (!params || !params.position || !params.radius) return;
|
|
12522
12586
|
this._ref = new Konva.Ellipse({
|
|
12523
12587
|
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
12524
12588
|
strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
|
|
@@ -12640,7 +12704,7 @@
|
|
|
12640
12704
|
this._ref = ref;
|
|
12641
12705
|
return;
|
|
12642
12706
|
}
|
|
12643
|
-
if (!params.start || !params.end) return;
|
|
12707
|
+
if (!params || !params.start || !params.end) return;
|
|
12644
12708
|
this._ref = new Konva.Arrow({
|
|
12645
12709
|
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
12646
12710
|
fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
|
|
@@ -12734,6 +12798,7 @@
|
|
|
12734
12798
|
|
|
12735
12799
|
class KonvaImage {
|
|
12736
12800
|
constructor(params, ref = null) {
|
|
12801
|
+
var _a, _b;
|
|
12737
12802
|
this._ratio = 1;
|
|
12738
12803
|
if (ref) {
|
|
12739
12804
|
if (ref.height() === 0 || ref.width() === 0) return;
|
|
@@ -12742,14 +12807,14 @@
|
|
|
12742
12807
|
this._ratio = this._ref.height() / this._ref.width();
|
|
12743
12808
|
return;
|
|
12744
12809
|
}
|
|
12745
|
-
if (!params.position || !params.src) return;
|
|
12810
|
+
if (!params || !params.position || !params.src) return;
|
|
12746
12811
|
this._canvasImage = new Image;
|
|
12747
12812
|
this._ref = new Konva.Image({
|
|
12748
12813
|
x: params.position.x,
|
|
12749
12814
|
y: params.position.y,
|
|
12750
12815
|
image: this._canvasImage,
|
|
12751
|
-
width: params.width,
|
|
12752
|
-
height: params.height,
|
|
12816
|
+
width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
|
|
12817
|
+
height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
|
|
12753
12818
|
draggable: true
|
|
12754
12819
|
});
|
|
12755
12820
|
this._canvasImage.onload = () => {
|
|
@@ -12857,7 +12922,7 @@
|
|
|
12857
12922
|
this._ref = ref;
|
|
12858
12923
|
return;
|
|
12859
12924
|
}
|
|
12860
|
-
if (!params
|
|
12925
|
+
if (!params || !params.position) return;
|
|
12861
12926
|
const arcRadius = 16;
|
|
12862
12927
|
this._ref = new Konva.Shape({
|
|
12863
12928
|
x: params.position.x,
|
|
@@ -13061,7 +13126,7 @@
|
|
|
13061
13126
|
},
|
|
13062
13127
|
Cloud: {
|
|
13063
13128
|
name: "Cloud",
|
|
13064
|
-
initializer: ref => new KonvaCloud(
|
|
13129
|
+
initializer: (ref, params = null) => new KonvaCloud(params, ref),
|
|
13065
13130
|
zIndex: 1
|
|
13066
13131
|
}
|
|
13067
13132
|
};
|
|
@@ -14496,6 +14561,14 @@
|
|
|
14496
14561
|
pt2[1] -= pt1[1];
|
|
14497
14562
|
return Math.min(pt2[0], pt2[1]) / 120;
|
|
14498
14563
|
}
|
|
14564
|
+
start(x, y) {
|
|
14565
|
+
this.createNewMeasureIfNeed();
|
|
14566
|
+
const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
|
|
14567
|
+
if (point) {
|
|
14568
|
+
this.firstPoint = point;
|
|
14569
|
+
this.previewMeasureLine.setStartPoint(this.firstPoint);
|
|
14570
|
+
}
|
|
14571
|
+
}
|
|
14499
14572
|
drag(x, y) {
|
|
14500
14573
|
this.createNewMeasureIfNeed();
|
|
14501
14574
|
const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
|
|
@@ -17097,11 +17170,15 @@
|
|
|
17097
17170
|
//return visViewer.activeView.upVector[1] >= 0.95;
|
|
17098
17171
|
}
|
|
17099
17172
|
screenToWorld(position) {
|
|
17100
|
-
|
|
17173
|
+
if (!this.visualizeJs)
|
|
17174
|
+
return { x: position.x, y: position.y, z: 0 };
|
|
17175
|
+
const worldPoint = this.visViewer().screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
17176
|
+
const result = { x: worldPoint[0], y: worldPoint[1], z: worldPoint[2] };
|
|
17177
|
+
return result;
|
|
17101
17178
|
}
|
|
17102
17179
|
worldToScreen(position) {
|
|
17103
17180
|
if (!this.visualizeJs)
|
|
17104
|
-
return position;
|
|
17181
|
+
return { x: position.x, y: position.y };
|
|
17105
17182
|
const activeView = this.visViewer().activeView;
|
|
17106
17183
|
const worldMatrix = activeView.worldToDeviceMatrix;
|
|
17107
17184
|
const worldPoint = this.visLib().Point3d.createFromArray([position.x, position.y, position.z]);
|
|
@@ -17117,15 +17194,15 @@
|
|
|
17117
17194
|
const result = { x: 1.0, y: 1.0, z: 1.0 };
|
|
17118
17195
|
const projMatrix = this.visViewer().activeView.projectionMatrix;
|
|
17119
17196
|
const tolerance = 1.0e-6;
|
|
17120
|
-
const x = projMatrix.get(
|
|
17197
|
+
const x = projMatrix.get(0, 0);
|
|
17121
17198
|
if (x > tolerance || x < -tolerance)
|
|
17122
|
-
result.x = 1 /
|
|
17199
|
+
result.x = 1 / x;
|
|
17123
17200
|
const y = projMatrix.get(1, 1);
|
|
17124
17201
|
if (y > tolerance || y < -tolerance)
|
|
17125
|
-
result.y = 1 /
|
|
17202
|
+
result.y = 1 / y;
|
|
17126
17203
|
const z = projMatrix.get(2, 2);
|
|
17127
17204
|
if (z > tolerance || z < -tolerance)
|
|
17128
|
-
result.z = 1 /
|
|
17205
|
+
result.z = 1 / z;
|
|
17129
17206
|
return result;
|
|
17130
17207
|
}
|
|
17131
17208
|
/**
|