@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
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const composeMatrixFromTransform: (
|
|
1
|
+
export declare const composeMatrixFromTransform: (transform: any, modelCenter: any, visLib: any) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/viewer-visualize",
|
|
3
|
-
"version": "25.8.
|
|
3
|
+
"version": "25.8.8",
|
|
4
4
|
"description": "3D CAD and BIM data Viewer powered by Visualize",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"docs": "typedoc"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@inweb/client": "~25.8.
|
|
33
|
-
"@inweb/eventemitter2": "~25.8.
|
|
34
|
-
"@inweb/markup": "~25.8.
|
|
35
|
-
"@inweb/viewer-core": "~25.8.
|
|
32
|
+
"@inweb/client": "~25.8.8",
|
|
33
|
+
"@inweb/eventemitter2": "~25.8.8",
|
|
34
|
+
"@inweb/markup": "~25.8.8",
|
|
35
|
+
"@inweb/viewer-core": "~25.8.8"
|
|
36
36
|
},
|
|
37
37
|
"visualizeJS": "https://opencloud.azureedge.net/libs/visualizejs/master/Visualize.js"
|
|
38
38
|
}
|
|
@@ -25,11 +25,19 @@ import { Model, File, Assembly } from "@inweb/client";
|
|
|
25
25
|
import { commands } from "@inweb/viewer-core";
|
|
26
26
|
import { Viewer } from "../Viewer";
|
|
27
27
|
|
|
28
|
-
export const composeMatrixFromTransform = (
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
28
|
+
export const composeMatrixFromTransform = (transform, modelCenter, visLib) => {
|
|
29
|
+
const { translate, scale, rotation } = transform;
|
|
30
|
+
|
|
31
|
+
const translateMatrix = new visLib.Matrix3d();
|
|
32
|
+
translateMatrix.setTranslation([translate.x, translate.y, translate.z]);
|
|
33
|
+
|
|
34
|
+
const rotateMatrix = new visLib.Matrix3d();
|
|
35
|
+
rotateMatrix.setToRotation(rotation.angle, [rotation.x, rotation.y, rotation.z], modelCenter);
|
|
36
|
+
|
|
37
|
+
const scaleMatrix = new visLib.Matrix3d();
|
|
38
|
+
scaleMatrix.setToScaling(scale, modelCenter);
|
|
39
|
+
|
|
40
|
+
return rotateMatrix.postMultBy(translateMatrix).postMultBy(scaleMatrix);
|
|
33
41
|
};
|
|
34
42
|
|
|
35
43
|
function applyModelTransform(viewer: Viewer, model: Model | File | Assembly) {
|
|
@@ -46,13 +54,9 @@ function applyModelTransform(viewer: Viewer, model: Model | File | Assembly) {
|
|
|
46
54
|
const transform = model.getModelTransformMatrix(modelPtr.getDatabaseHandle());
|
|
47
55
|
if (transform) {
|
|
48
56
|
const extents = modelPtr.getExtents();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
transform.scale,
|
|
53
|
-
extents.center(),
|
|
54
|
-
new visLib.Matrix3d()
|
|
55
|
-
);
|
|
57
|
+
extents.transformBy(modelPtr.getUnitsMatrix());
|
|
58
|
+
|
|
59
|
+
const matrix = composeMatrixFromTransform(transform, extents.center(), visLib);
|
|
56
60
|
|
|
57
61
|
modelPtr.setModelingMatrix(matrix, true);
|
|
58
62
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { Model, File, Assembly, version } from "@inweb/client";
|
|
25
|
+
import { commands } from "@inweb/viewer-core";
|
|
26
|
+
import { Viewer } from "../Viewer";
|
|
27
|
+
|
|
28
|
+
import { composeMatrixFromTransform } from "./ApplyModelTransform";
|
|
29
|
+
|
|
30
|
+
function isTemplateModel(modelPtr) {
|
|
31
|
+
return modelPtr.getName()[0] === "$";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function autoTransformAllModelsToCentralPoint(viewer: Viewer, model: Model | File | Assembly): Promise<void> {
|
|
35
|
+
if (!viewer.visualizeJs) return;
|
|
36
|
+
if (!model.getModelTransformMatrix) return; // Model.getModelTransformMatrix() since 24.3.14
|
|
37
|
+
|
|
38
|
+
const visLib = viewer.visLib();
|
|
39
|
+
const visViewer = visLib.getViewer();
|
|
40
|
+
|
|
41
|
+
const viewExt = visViewer.getActiveExtents();
|
|
42
|
+
const centralPoint = viewExt.center();
|
|
43
|
+
|
|
44
|
+
const modelItr = visViewer.getModelIterator();
|
|
45
|
+
for (; !modelItr.done(); modelItr.step()) {
|
|
46
|
+
const modelPtr = modelItr.getModel();
|
|
47
|
+
|
|
48
|
+
if (!isTemplateModel(modelPtr)) {
|
|
49
|
+
let ext = modelPtr.getExtents();
|
|
50
|
+
|
|
51
|
+
const unitsMatrix = modelPtr.getUnitsMatrix();
|
|
52
|
+
ext.transformBy(modelPtr.getUnitsMatrix()); // ext in wcs
|
|
53
|
+
|
|
54
|
+
const unitsMatrixInvert = modelPtr.getUnitsMatrix().invert();
|
|
55
|
+
|
|
56
|
+
const center = ext.center();
|
|
57
|
+
const scale = 1.0;
|
|
58
|
+
|
|
59
|
+
const scaleMatrix = new visLib.Matrix3d();
|
|
60
|
+
const translateMatrix = new visLib.Matrix3d();
|
|
61
|
+
|
|
62
|
+
translateMatrix.setTranslation([
|
|
63
|
+
centralPoint[0] - center[0],
|
|
64
|
+
centralPoint[1] - center[1],
|
|
65
|
+
centralPoint[2] - center[2],
|
|
66
|
+
]);
|
|
67
|
+
scaleMatrix.setToScaling(scale, centralPoint);
|
|
68
|
+
|
|
69
|
+
const resMatrixWithUnits = unitsMatrixInvert
|
|
70
|
+
.postMultBy(scaleMatrix)
|
|
71
|
+
.postMultBy(translateMatrix)
|
|
72
|
+
.postMultBy(unitsMatrix);
|
|
73
|
+
|
|
74
|
+
const resScale = resMatrixWithUnits.scale();
|
|
75
|
+
const transform = {
|
|
76
|
+
translate: {
|
|
77
|
+
x: resMatrixWithUnits.get(0, 3) - (1 - resScale) * center[0],
|
|
78
|
+
y: resMatrixWithUnits.get(1, 3) - (1 - resScale) * center[1],
|
|
79
|
+
z: resMatrixWithUnits.get(2, 3) - (1 - resScale) * center[2],
|
|
80
|
+
},
|
|
81
|
+
rotation: { x: 0, y: 0, z: 1, angle: 0.0 },
|
|
82
|
+
scale: resScale,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const matrix = composeMatrixFromTransform(transform, center, visLib);
|
|
86
|
+
modelPtr.setModelingMatrix(matrix, true);
|
|
87
|
+
|
|
88
|
+
centralPoint[0] += Math.abs(ext.max()[0] - ext.min()[0]) * resScale;
|
|
89
|
+
|
|
90
|
+
await model.setModelTransformMatrix(modelPtr.getDatabaseHandle(), transform);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
modelPtr.delete();
|
|
94
|
+
}
|
|
95
|
+
modelItr.delete();
|
|
96
|
+
|
|
97
|
+
visViewer.clearViewExtentsCache?.();
|
|
98
|
+
|
|
99
|
+
viewer.update();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
commands("VisualizeJS").registerCommand("autoTransformAllModelsToCentralPoint", autoTransformAllModelsToCentralPoint);
|