@inweb/viewer-visualize 25.8.7 → 25.8.8
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 +70 -6
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +67 -6
- 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/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
|
@@ -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;
|