@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
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) {
|