@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.
@@ -1 +1 @@
1
- export declare const composeMatrixFromTransform: (translate: any, rotate: any, scale: any, modelCenter: any, matrix: any) => any;
1
+ export declare const composeMatrixFromTransform: (transform: any, modelCenter: any, visLib: any) => any;
@@ -20,3 +20,4 @@ import "./Unselect";
20
20
  import "./ZoomToExtents";
21
21
  import "./ZoomToObjects";
22
22
  import "./ZoomToSelected";
23
+ import "./AutoTransformAllModelsToCentralPoint";
@@ -16,6 +16,7 @@ export declare class MeasureLineDragger extends OdBaseDragger {
16
16
  updatePreview(): void;
17
17
  resize(): void;
18
18
  getSnapPointRadius(): number;
19
+ start(x: number, y: number): void;
19
20
  drag(x: number, y: number): void;
20
21
  end(): void;
21
22
  createNewMeasureIfNeed(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "25.8.7",
3
+ "version": "25.8.9",
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.7",
33
- "@inweb/eventemitter2": "~25.8.7",
34
- "@inweb/markup": "~25.8.7",
35
- "@inweb/viewer-core": "~25.8.7"
32
+ "@inweb/client": "~25.8.9",
33
+ "@inweb/eventemitter2": "~25.8.9",
34
+ "@inweb/markup": "~25.8.9",
35
+ "@inweb/viewer-core": "~25.8.9"
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 = (translate, rotate, scale, modelCenter, matrix) => {
29
- const translateMatrix = matrix.setTranslation([translate.x, translate.y, translate.z]);
30
- const rotateMatrix = matrix.setToRotation(rotate.angle, [rotate.x, rotate.y, rotate.z], modelCenter);
31
- const scaleMatrix = matrix.setToScaling(scale, modelCenter);
32
- return translateMatrix.postMultBy(rotateMatrix).postMultBy(scaleMatrix);
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
- const matrix = composeMatrixFromTransform(
50
- transform.translate,
51
- transform.rotation,
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);
@@ -43,3 +43,4 @@ import "./Unselect";
43
43
  import "./ZoomToExtents";
44
44
  import "./ZoomToObjects";
45
45
  import "./ZoomToSelected";
46
+ import "./AutoTransformAllModelsToCentralPoint";
@@ -109,6 +109,16 @@ export class MeasureLineDragger extends OdBaseDragger {
109
109
  return Math.min(pt2[0], pt2[1]) / 120;
110
110
  }
111
111
 
112
+ override start(x: number, y: number): void {
113
+ this.createNewMeasureIfNeed();
114
+ const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
115
+
116
+ if (point) {
117
+ this.firstPoint = point;
118
+ this.previewMeasureLine.setStartPoint(this.firstPoint);
119
+ }
120
+ }
121
+
112
122
  override drag(x: number, y: number): void {
113
123
  this.createNewMeasureIfNeed();
114
124
  const point = this.getViewer().getSnapPoint(x, y, this.gripingRadius);
@@ -741,11 +741,19 @@ export class Viewer
741
741
  }
742
742
 
743
743
  screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number } {
744
- return this.visViewer().screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
744
+ if (!this.visualizeJs) return { x: position.x, y: position.y, z: 0 };
745
+
746
+ const worldPoint = this.visViewer().screenToWorld(
747
+ position.x * window.devicePixelRatio,
748
+ position.y * window.devicePixelRatio
749
+ );
750
+ const result = { x: worldPoint[0], y: worldPoint[1], z: worldPoint[2] };
751
+
752
+ return result;
745
753
  }
746
754
 
747
755
  worldToScreen(position: { x: number; y: number; z: number }): { x: number; y: number } {
748
- if (!this.visualizeJs) return position;
756
+ if (!this.visualizeJs) return { x: position.x, y: position.y };
749
757
 
750
758
  const activeView = this.visViewer().activeView;
751
759
  const worldMatrix = activeView.worldToDeviceMatrix;
@@ -768,14 +776,14 @@ export class Viewer
768
776
  const projMatrix = this.visViewer().activeView.projectionMatrix;
769
777
  const tolerance = 1.0e-6;
770
778
 
771
- const x = projMatrix.get(1, 1);
772
- if (x > tolerance || x < -tolerance) result.x = 1 / result.x;
779
+ const x = projMatrix.get(0, 0);
780
+ if (x > tolerance || x < -tolerance) result.x = 1 / x;
773
781
 
774
782
  const y = projMatrix.get(1, 1);
775
- if (y > tolerance || y < -tolerance) result.y = 1 / result.y;
783
+ if (y > tolerance || y < -tolerance) result.y = 1 / y;
776
784
 
777
785
  const z = projMatrix.get(2, 2);
778
- if (z > tolerance || z < -tolerance) result.z = 1 / result.z;
786
+ if (z > tolerance || z < -tolerance) result.z = 1 / z;
779
787
 
780
788
  return result;
781
789
  }