@inweb/viewer-visualize 26.9.4 → 26.9.6

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.
@@ -0,0 +1,31 @@
1
+ import { Viewer } from "../Viewer";
2
+ import { Point2d } from "./Common/Geometry";
3
+ import { OdBaseDragger } from "./Common/OdBaseDragger";
4
+ export declare class OdaFlyDragger extends OdBaseDragger {
5
+ protected lastCoord: Point2d;
6
+ protected speed: number;
7
+ protected delta: number;
8
+ protected keyPressMap: Set<string>;
9
+ protected oldWCSEnableValue: boolean;
10
+ protected viewParams: any;
11
+ protected cameraId: any;
12
+ protected cameraFlyer: any;
13
+ protected viewer: any;
14
+ protected multiplier: number;
15
+ protected lastFrameTS: number;
16
+ protected animationId: any;
17
+ protected deltaAngle: number;
18
+ protected enableZoomWheelPreviousValue: boolean;
19
+ protected dragPosition: Point2d;
20
+ constructor(subject: Viewer);
21
+ initialize(): void;
22
+ dispose(): void;
23
+ keydown(ev: any): void;
24
+ keyup(ev: any): void;
25
+ processMovement(timestamp: any): void;
26
+ start(x: number, y: number): void;
27
+ drag(x: number, y: number): void;
28
+ turnLeft(angle: any): void;
29
+ setupCamera(view: any): void;
30
+ getMaxDimension(view: any): number;
31
+ }
@@ -25,6 +25,8 @@ export declare class OdaWalkDragger extends OdBaseDragger {
25
25
  processMovement(timestamp: any): void;
26
26
  start(x: number, y: number): void;
27
27
  drag(x: number, y: number): void;
28
+ moveForward(currentDelta: any): void;
29
+ moveBackward(currentDelta: any): void;
28
30
  turnLeft(angle: any): void;
29
31
  setupCamera(view: any): void;
30
32
  getMaxDimension(view: any): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "26.9.4",
3
+ "version": "26.9.6",
4
4
  "description": "JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS",
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": "~26.9.4",
33
- "@inweb/eventemitter2": "~26.9.4",
34
- "@inweb/markup": "~26.9.4",
35
- "@inweb/viewer-core": "~26.9.4"
32
+ "@inweb/client": "~26.9.6",
33
+ "@inweb/eventemitter2": "~26.9.6",
34
+ "@inweb/markup": "~26.9.6",
35
+ "@inweb/viewer-core": "~26.9.6"
36
36
  },
37
37
  "visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
38
38
  }
@@ -0,0 +1,292 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2025, 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-2025 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
+ import { Viewer } from "../Viewer";
24
+ import { Point2d, Vector3 } from "./Common/Geometry";
25
+ import { OdBaseDragger } from "./Common/OdBaseDragger";
26
+
27
+ const FocalLengthConst = 42.0;
28
+
29
+ const calcFocalLength = (lensLength: number, fieldWidth: number, fieldHeight: number): number => {
30
+ return (lensLength / FocalLengthConst) * Math.sqrt(fieldWidth * fieldWidth + fieldHeight * fieldHeight);
31
+ };
32
+
33
+ export class OdaFlyDragger extends OdBaseDragger {
34
+ protected lastCoord: Point2d;
35
+ protected speed: number;
36
+ protected delta: number;
37
+ protected keyPressMap: Set<string>;
38
+ protected oldWCSEnableValue: boolean;
39
+ protected viewParams: any;
40
+ protected cameraId: any;
41
+ protected cameraFlyer: any;
42
+ protected viewer: any;
43
+ protected multiplier: number;
44
+ protected lastFrameTS: number;
45
+ protected animationId: any;
46
+ protected deltaAngle: number;
47
+ protected enableZoomWheelPreviousValue: boolean;
48
+ protected dragPosition: Point2d;
49
+
50
+ constructor(subject: Viewer) {
51
+ super(subject);
52
+ this.viewer = undefined;
53
+
54
+ this.multiplier = 5;
55
+ this.speed = 1;
56
+
57
+ this.keyPressMap = new Set();
58
+ this.keydown = this.keydown.bind(this);
59
+ this.keyup = this.keyup.bind(this);
60
+
61
+ this.lastFrameTS = 0;
62
+ this.animationId = undefined;
63
+ this.processMovement = this.processMovement.bind(this);
64
+
65
+ this.deltaAngle = Math.PI / 3600;
66
+ this.autoSelect = true;
67
+ }
68
+
69
+ override initialize() {
70
+ super.initialize();
71
+ this.viewer = this.getViewer();
72
+
73
+ window.addEventListener("keydown", this.keydown, false);
74
+ window.addEventListener("keyup", this.keyup, false);
75
+
76
+ this.oldWCSEnableValue = this.viewer.getEnableWCS();
77
+ this.viewer.setEnableWCS(false);
78
+
79
+ const view = this.viewer.activeView;
80
+ const maxDimension = this.getMaxDimension(view);
81
+ this.speed = maxDimension / 30000;
82
+
83
+ this.subject.emitEvent({ type: "flystart" });
84
+
85
+ this.viewParams = this.getViewParams();
86
+ //this.viewParams.lensLength = view.lensLength;
87
+
88
+ this.setViewParams(this.viewParams);
89
+ //view.lensLength = (view.lensLength * 42) / 120;
90
+
91
+ const model = this.viewer.getActiveModel();
92
+ this.cameraId = model.appendCamera("Camera0");
93
+ this.setupCamera(view);
94
+ model.delete();
95
+
96
+ //pCamera.setAdjustLensLength(true);
97
+ this.cameraFlyer = new this.m_module.OdTvCameraWalker();
98
+ this.cameraFlyer.setCamera(this.cameraId);
99
+
100
+ this.subject.update();
101
+ this.enableZoomWheelPreviousValue = this.subject.options.enableZoomWheel;
102
+ this.subject.options.enableZoomWheel = false;
103
+ }
104
+
105
+ override dispose() {
106
+ this.oldWCSEnableValue =
107
+ this.oldWCSEnableValue !== undefined ? this.oldWCSEnableValue : this.subject.options.showWCS;
108
+ this.viewer.setEnableWCS(this.oldWCSEnableValue);
109
+
110
+ super.dispose();
111
+
112
+ this.keyPressMap.clear();
113
+
114
+ window.removeEventListener("keydown", this.keydown);
115
+ window.removeEventListener("keyup", this.keyup);
116
+
117
+ if (this.animationId) {
118
+ window.cancelAnimationFrame(this.animationId);
119
+ this.animationId = undefined;
120
+ }
121
+
122
+ if (this.cameraId) {
123
+ const model = this.viewer.getActiveModel();
124
+ model.removeEntity(this.cameraId);
125
+ model.delete();
126
+ this.cameraFlyer?.delete();
127
+ }
128
+
129
+ if (this.viewParams) {
130
+ this.setViewParams(this.viewParams);
131
+
132
+ const avp = this.viewer.activeView;
133
+ //avp.lensLength = this.viewParams.lensLength;
134
+ avp.delete();
135
+ }
136
+
137
+ // CLOUD-5359 Demo Viewer crashes after the Fly Mode
138
+ this.subject.update(true);
139
+ this.subject.options.enableZoomWheel = this.enableZoomWheelPreviousValue;
140
+ }
141
+
142
+ keydown(ev) {
143
+ switch (ev.code) {
144
+ case "NumpadSubtract":
145
+ case "Minus":
146
+ if (this.multiplier > 1) {
147
+ this.multiplier = this.multiplier - 1;
148
+ this.subject.emitEvent({ type: "flyspeedchange", data: this.multiplier });
149
+ }
150
+ break;
151
+ case "NumpadAdd":
152
+ case "Equal":
153
+ if (this.multiplier < 10) {
154
+ this.multiplier = this.multiplier + 1;
155
+ this.subject.emitEvent({ type: "flyspeedchange", data: this.multiplier });
156
+ }
157
+ break;
158
+ case "KeyW":
159
+ case "KeyA":
160
+ case "KeyS":
161
+ case "KeyD":
162
+ case "KeyQ":
163
+ case "KeyE":
164
+ this.keyPressMap.add(ev.code);
165
+ if (!this.animationId) this.processMovement(0);
166
+ break;
167
+ }
168
+ }
169
+
170
+ keyup(ev) {
171
+ this.keyPressMap.delete(ev.code);
172
+ if (this.keyPressMap.size < 1 && this.animationId) {
173
+ window.cancelAnimationFrame(this.animationId);
174
+ this.animationId = undefined;
175
+ this.lastFrameTS = 0;
176
+ }
177
+ }
178
+
179
+ processMovement(timestamp) {
180
+ this.animationId = requestAnimationFrame(this.processMovement);
181
+
182
+ if (this.lastFrameTS !== 0) {
183
+ const deltaTS = timestamp - this.lastFrameTS;
184
+ const currentDelta = this.multiplier * deltaTS * this.speed;
185
+
186
+ for (const keyCode of this.keyPressMap) {
187
+ switch (keyCode) {
188
+ case "KeyW":
189
+ this.cameraFlyer.moveForward(currentDelta);
190
+ break;
191
+ case "KeyS":
192
+ this.cameraFlyer.moveBackward(currentDelta);
193
+ break;
194
+ case "KeyA":
195
+ this.cameraFlyer.moveLeft(currentDelta);
196
+ break;
197
+ case "KeyD":
198
+ this.cameraFlyer.moveRight(currentDelta);
199
+ break;
200
+ case "KeyQ":
201
+ this.cameraFlyer.moveUp(currentDelta);
202
+ break;
203
+ case "KeyE":
204
+ this.cameraFlyer.moveDown(currentDelta);
205
+ break;
206
+ }
207
+ }
208
+
209
+ this.subject.update();
210
+ this.subject.emitEvent({ type: "changecamera" });
211
+ }
212
+
213
+ this.lastFrameTS = timestamp;
214
+ }
215
+
216
+ override start(x: number, y: number): void {
217
+ this.dragPosition = { x, y };
218
+ }
219
+
220
+ override drag(x: number, y: number) {
221
+ if (this.cameraId && this.isDragging) {
222
+ const dltX = x - this.dragPosition.x;
223
+ const dltY = y - this.dragPosition.y;
224
+ this.dragPosition = { x, y };
225
+
226
+ if (dltX !== 0.0) this.turnLeft(-dltX * this.deltaAngle);
227
+ if (dltY !== 0.0) this.cameraFlyer.turnDown(dltY * this.deltaAngle);
228
+
229
+ this.subject.update();
230
+ this.subject.emitEvent({ type: "changecamera" });
231
+ }
232
+ }
233
+
234
+ turnLeft(angle) {
235
+ //TODO: migrate to VisualizeJS
236
+ const pCamera = this.cameraFlyer.camera().openObjectAsCamera();
237
+ const dir = this.toVector(pCamera.direction());
238
+ const up = this.toVector(pCamera.upVector());
239
+
240
+ const pos = pCamera.position();
241
+
242
+ const rotMatrix = this.createMatrix3d();
243
+ const zAxisVector: Vector3 = [0, 0, 1];
244
+ rotMatrix.setToRotation(angle, zAxisVector, pos);
245
+ dir.transformBy(rotMatrix);
246
+ up.transformBy(rotMatrix);
247
+ pCamera.setupCameraByDirection(pos, dir.toArray(), up.toArray());
248
+ pCamera.delete();
249
+ }
250
+
251
+ setupCamera(view) {
252
+ const pCamera = this.cameraId.openObjectAsCamera();
253
+ const target = view.viewTarget;
254
+
255
+ pCamera.setDisplayGlyph(false);
256
+ pCamera.setDisplayTarget(false);
257
+ pCamera.setAutoAdjust(true);
258
+ pCamera.setupCamera(view.viewPosition, target, view.upVector);
259
+ pCamera.setNearClip(false, 1.0);
260
+ pCamera.setFarClip(false, 0);
261
+ pCamera.setViewParameters(view.viewFieldWidth, view.viewFieldHeight, true);
262
+
263
+ const focalL = calcFocalLength(view.lensLength, view.viewFieldWidth, view.viewFieldHeight);
264
+
265
+ const pTarget = this.toPoint(view.viewTarget);
266
+ const viewDir = this.toPoint(view.viewPosition);
267
+ const viewDirSub = viewDir.sub(pTarget);
268
+ const viewDirVec = viewDirSub.asVector();
269
+ const viewDirVecNormal = viewDirVec.normalize();
270
+
271
+ const geViewDir = this.toGeVector(viewDirVecNormal);
272
+ const newGeViewDir = [geViewDir[0] * focalL, geViewDir[1] * focalL, geViewDir[2] * focalL];
273
+
274
+ const pTarget2 = this.toPoint(view.viewTarget);
275
+ const newGeViewDirPt = this.toPoint(newGeViewDir);
276
+
277
+ const newPos = pTarget2.add(newGeViewDirPt);
278
+ pCamera.setupCamera(this.toGePoint(newPos), view.viewTarget, view.upVector);
279
+
280
+ this.deleteAll([pTarget, viewDir, viewDirSub, viewDirVec, viewDirVecNormal, pTarget2, newGeViewDirPt, newPos]);
281
+
282
+ pCamera.assignView(view);
283
+ pCamera.delete();
284
+ }
285
+
286
+ getMaxDimension(view) {
287
+ const [xmax, ymax, zmax] = view.sceneExtents.max();
288
+ const [xmin, ymin, zmin] = view.sceneExtents.min();
289
+ const volume = [xmax - xmin, ymax - ymin, zmax - zmin];
290
+ return Math.max(...volume);
291
+ }
292
+ }
@@ -186,10 +186,10 @@ export class OdaWalkDragger extends OdBaseDragger {
186
186
  for (const keyCode of this.keyPressMap) {
187
187
  switch (keyCode) {
188
188
  case "KeyW":
189
- this.cameraWalker.moveForward(currentDelta);
189
+ this.moveForward(currentDelta);
190
190
  break;
191
191
  case "KeyS":
192
- this.cameraWalker.moveBackward(currentDelta);
192
+ this.moveBackward(currentDelta);
193
193
  break;
194
194
  case "KeyA":
195
195
  this.cameraWalker.moveLeft(currentDelta);
@@ -231,6 +231,31 @@ export class OdaWalkDragger extends OdBaseDragger {
231
231
  }
232
232
  }
233
233
 
234
+ moveForward(currentDelta) {
235
+ const { Vector3d } = this.m_module;
236
+
237
+ const camera = this.cameraWalker.camera().openObjectAsCamera();
238
+ const target = Vector3d.createFromArray(camera.target());
239
+ const dir = Vector3d.createFromArray(camera.direction());
240
+ const up = Vector3d.createFromArray(camera.upVector());
241
+ const pos = Vector3d.createFromArray(camera.position());
242
+ let move = Vector3d.createFromArray([dir.x, dir.y, 0]);
243
+ if (Math.abs(dir.x) > 0.001 && Math.abs(dir.y) > 0.001) {
244
+ move.setToProduct(move.normalize(), currentDelta);
245
+ } else {
246
+ move = Vector3d.createFromArray([0, currentDelta, 0]);
247
+ }
248
+
249
+ let newPos = pos.add(move);
250
+ let newTarget = target.add(move);
251
+
252
+ camera.setupCamera(newPos.toArray(), newTarget.toArray(), up.toArray());
253
+ }
254
+
255
+ moveBackward(currentDelta) {
256
+ this.moveForward(-currentDelta);
257
+ }
258
+
234
259
  turnLeft(angle) {
235
260
  //TODO: migrate to VisualizeJS
236
261
  const pCamera = this.cameraWalker.camera().openObjectAsCamera();
@@ -25,6 +25,7 @@ import { IDraggersRegistry, draggersRegistry } from "@inweb/viewer-core";
25
25
 
26
26
  import { MeasureLineDragger } from "./MeasureLineDragger";
27
27
  import { OdaWalkDragger } from "./OdaWalkDragger";
28
+ import { OdaFlyDragger } from "./OdaFlyDragger";
28
29
  import { OdCuttingPlaneXAxisDragger } from "./OdCuttingPlaneXAxisDragger";
29
30
  import { OdCuttingPlaneYAxisDragger } from "./OdCuttingPlaneYAxisDragger";
30
31
  import { OdCuttingPlaneZAxisDragger } from "./OdCuttingPlaneZAxisDragger";
@@ -93,3 +94,4 @@ draggers.registerDragger("CuttingPlaneXAxis", (viewer) => new OdCuttingPlaneXAxi
93
94
  draggers.registerDragger("CuttingPlaneYAxis", (viewer) => new OdCuttingPlaneYAxisDragger(viewer));
94
95
  draggers.registerDragger("CuttingPlaneZAxis", (viewer) => new OdCuttingPlaneZAxisDragger(viewer));
95
96
  draggers.registerDragger("Walk", (viewer) => new OdaWalkDragger(viewer));
97
+ draggers.registerDragger("Fly", (viewer) => new OdaFlyDragger(viewer));