@inweb/viewer-visualize 26.10.2 → 26.10.4

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,11 @@
1
+ import { CameraMode, IComponent } from "@inweb/viewer-core";
2
+ import type { Viewer } from "../Viewer";
3
+ export declare class CameraComponent implements IComponent {
4
+ protected viewer: Viewer;
5
+ constructor(viewer: Viewer);
6
+ dispose(): void;
7
+ getCameraMode(view: any): CameraMode;
8
+ switchCameraMode(mode: CameraMode): void;
9
+ optionsChange: () => void;
10
+ geometryEnd: () => void;
11
+ }
@@ -0,0 +1,19 @@
1
+ interface JoyStickStatus {
2
+ x: number;
3
+ y: number;
4
+ global: any;
5
+ }
6
+ export declare class OdJoyStickDragger {
7
+ private onMouseDown;
8
+ private onMouseMove;
9
+ private onMouseUp;
10
+ private drawExternal;
11
+ private drawInternal;
12
+ private canvas;
13
+ private onResize;
14
+ private hasEventListeners;
15
+ private container;
16
+ constructor(global: any, container: HTMLElement, callback: (status: JoyStickStatus) => void, canvasElement?: HTMLCanvasElement);
17
+ cleanup(): void;
18
+ }
19
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { Viewer } from "../Viewer";
2
2
  import { Point2d } from "./Common/Geometry";
3
3
  import { OdBaseDragger } from "./Common/OdBaseDragger";
4
+ import { OdJoyStickDragger } from "./OdJoyStickDragger";
4
5
  export declare class OdaFlyDragger extends OdBaseDragger {
5
6
  protected lastCoord: Point2d;
6
7
  protected speed: number;
@@ -17,6 +18,11 @@ export declare class OdaFlyDragger extends OdBaseDragger {
17
18
  protected deltaAngle: number;
18
19
  protected enableZoomWheelPreviousValue: boolean;
19
20
  protected dragPosition: Point2d;
21
+ protected lastJoyStickCoord: Point2d;
22
+ protected lastFrameJoyStickTS: number;
23
+ protected moving: boolean;
24
+ protected joyStickOverlayElement: HTMLDivElement;
25
+ protected joyStickDragger: OdJoyStickDragger;
20
26
  constructor(subject: Viewer);
21
27
  initialize(): void;
22
28
  dispose(): void;
@@ -28,4 +34,6 @@ export declare class OdaFlyDragger extends OdBaseDragger {
28
34
  turnLeft(angle: any): void;
29
35
  setupCamera(view: any): void;
30
36
  getMaxDimension(view: any): number;
37
+ processJoyMovement(timestamp: number): void;
38
+ moveTotal(currentDelta: number, forward: number, right: number): void;
31
39
  }
@@ -1,9 +1,9 @@
1
1
  import { Viewer } from "../Viewer";
2
2
  import { Point2d } from "./Common/Geometry";
3
3
  import { OdBaseDragger } from "./Common/OdBaseDragger";
4
+ import { OdJoyStickDragger } from "./OdJoyStickDragger";
4
5
  export declare class OdaWalkDragger extends OdBaseDragger {
5
- protected lastCoord: Point2d;
6
- protected speed: number;
6
+ protected baseSpeed: number;
7
7
  protected delta: number;
8
8
  protected keyPressMap: Set<string>;
9
9
  protected oldWCSEnableValue: boolean;
@@ -13,21 +13,30 @@ export declare class OdaWalkDragger extends OdBaseDragger {
13
13
  protected viewer: any;
14
14
  protected multiplier: number;
15
15
  protected lastFrameTS: number;
16
+ protected lastFrameJoyStickTS: number;
16
17
  protected animationId: any;
17
18
  protected deltaAngle: number;
18
19
  protected enableZoomWheelPreviousValue: boolean;
19
20
  protected dragPosition: Point2d;
21
+ protected joyStickOverlayElement: HTMLDivElement;
22
+ protected joyStickDragger: OdJoyStickDragger;
23
+ protected isJoyStickMoving: boolean;
24
+ protected lastJoyStickCoord: Point2d;
20
25
  constructor(subject: Viewer);
21
26
  initialize(): void;
22
27
  dispose(): void;
23
- keydown(ev: any): void;
24
- keyup(ev: any): void;
25
- processMovement(timestamp: any): void;
28
+ keydown(ev: KeyboardEvent): void;
29
+ keyup(ev: KeyboardEvent): void;
30
+ processMovement(timestamp: number): void;
26
31
  start(x: number, y: number): void;
27
32
  drag(x: number, y: number): void;
28
- moveForward(currentDelta: any): void;
29
- moveBackward(currentDelta: any): void;
30
- turnLeft(angle: any): void;
33
+ moveForward(currentDelta: number): void;
34
+ moveBackward(currentDelta: number): void;
35
+ turnLeft(angle: number): void;
31
36
  setupCamera(view: any): void;
32
37
  getMaxDimension(view: any): number;
38
+ private addJoyStickDragger;
39
+ processJoyStickMovement(timestamp: number): void;
40
+ moveTotal(currentDelta: number, forward: number, right: number): void;
41
+ proceedChangeCamera(): void;
33
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "26.10.2",
3
+ "version": "26.10.4",
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.10.2",
33
- "@inweb/eventemitter2": "~26.10.2",
34
- "@inweb/markup": "~26.10.2",
35
- "@inweb/viewer-core": "~26.10.2"
32
+ "@inweb/client": "~26.10.4",
33
+ "@inweb/eventemitter2": "~26.10.4",
34
+ "@inweb/markup": "~26.10.4",
35
+ "@inweb/viewer-core": "~26.10.4"
36
36
  },
37
37
  "visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
38
38
  }
@@ -0,0 +1,78 @@
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
+
24
+ import { CameraMode, IComponent } from "@inweb/viewer-core";
25
+ import type { Viewer } from "../Viewer";
26
+
27
+ export class CameraComponent implements IComponent {
28
+ protected viewer: Viewer;
29
+
30
+ constructor(viewer: Viewer) {
31
+ this.viewer = viewer;
32
+ this.viewer.addEventListener("databasechunk", this.geometryEnd);
33
+ this.viewer.addEventListener("clear", this.geometryEnd);
34
+ this.viewer.addEventListener("optionschange", this.optionsChange);
35
+ this.viewer.addEventListener("initialize", this.optionsChange);
36
+ }
37
+
38
+ dispose() {
39
+ this.viewer.removeEventListener("databasechunk", this.geometryEnd);
40
+ this.viewer.removeEventListener("clear", this.geometryEnd);
41
+ this.viewer.removeEventListener("optionschange", this.optionsChange);
42
+ this.viewer.removeEventListener("initialize", this.optionsChange);
43
+ }
44
+
45
+ getCameraMode(view: any): CameraMode {
46
+ return view.perspective ? "perspective" : "orthographic";
47
+ }
48
+
49
+ switchCameraMode(mode: CameraMode) {
50
+ if (!mode) return;
51
+
52
+ const activeView = this.viewer.visViewer().activeView;
53
+
54
+ if (mode !== this.getCameraMode(activeView)) {
55
+ activeView.perspective = !activeView.perspective;
56
+
57
+ this.viewer.update();
58
+ this.viewer.emitEvent({ type: "changecameramode", mode });
59
+ }
60
+
61
+ activeView.delete();
62
+ }
63
+
64
+ optionsChange = () => {
65
+ this.switchCameraMode(this.viewer.options.cameraMode);
66
+ };
67
+
68
+ geometryEnd = () => {
69
+ const activeView = this.viewer.visViewer().activeView;
70
+
71
+ const mode = this.getCameraMode(activeView);
72
+
73
+ this.viewer.options.cameraMode = mode;
74
+ this.viewer.emitEvent({ type: "changecameramode", mode });
75
+
76
+ activeView.delete();
77
+ };
78
+ }
@@ -23,6 +23,7 @@
23
23
 
24
24
  import { IComponentsRegistry, componentsRegistry } from "@inweb/viewer-core";
25
25
 
26
+ import { CameraComponent } from "./CameraComponent";
26
27
  import { RenderLoopComponent } from "./RenderLoopComponent";
27
28
  import { ResizeCanvasComponent } from "./ResizeCanvasComponent";
28
29
  import { ZoomWheelComponent } from "./ZoomWheelComponent";
@@ -71,6 +72,7 @@ export const components: IComponentsRegistry = componentsRegistry("visualizejs")
71
72
 
72
73
  // build-in components
73
74
 
75
+ components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
74
76
  components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
75
77
  components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
76
78
  components.registerComponent("ZoomWheelComponent", (viewer) => new ZoomWheelComponent(viewer));
@@ -0,0 +1,222 @@
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
+
24
+ // ===================== AI-CODE-FILE ======================
25
+ // Source: Claude Sonnet 4.5
26
+ // Date: 2025-10-07
27
+ // Reviewer: vitaly.ivanov@opendesign.com
28
+ // Issue: CLOUD-5851
29
+ // Notes: Originally AI-generated, modified manually
30
+ // =========================================================
31
+
32
+ interface JoyStickStatus {
33
+ x: number;
34
+ y: number;
35
+ global: any;
36
+ }
37
+
38
+ export class OdJoyStickDragger {
39
+ private onMouseDown: (event?: any) => void;
40
+ private onMouseMove: (event: any) => void;
41
+ private onMouseUp: (event?: any) => void;
42
+ private drawExternal: () => void;
43
+ private drawInternal: () => void;
44
+ private canvas: HTMLCanvasElement;
45
+ private onResize: () => void;
46
+ private hasEventListeners: boolean = false;
47
+ private container: HTMLElement;
48
+
49
+ constructor(
50
+ global: any,
51
+ container: HTMLElement,
52
+ callback: (status: JoyStickStatus) => void,
53
+ canvasElement?: HTMLCanvasElement
54
+ ) {
55
+ const internalLineWidth = 2;
56
+ const internalStrokeColor = "#003300";
57
+ const externalLineWidth = 2;
58
+ const externalStrokeColor = "#35436E";
59
+
60
+ this.container = container;
61
+ this.container.style.touchAction = "none";
62
+
63
+ this.canvas = document.createElement("canvas");
64
+ this.canvas.id = "odJoyStickCanvas";
65
+ this.canvas.width = 200;
66
+ this.canvas.height = 200;
67
+ this.container.appendChild(this.canvas);
68
+ const context = this.canvas.getContext("2d")!;
69
+
70
+ let pressed = 0;
71
+ const circumference = 2 * Math.PI;
72
+ const internalRadius = (this.canvas.width - (this.canvas.width / 2 + 10)) / 2;
73
+ const maxMoveStick = internalRadius + 5;
74
+ const externalRadius = internalRadius + 30;
75
+ const centerX = this.canvas.width / 2;
76
+ const centerY = this.canvas.height / 2;
77
+ let movedX = centerX;
78
+ let movedY = centerY;
79
+
80
+ this.onMouseDown = () => {
81
+ event.preventDefault();
82
+ pressed = 1;
83
+ };
84
+
85
+ this.onMouseMove = (event) => {
86
+ event.preventDefault();
87
+ if (pressed === 1) {
88
+ movedX = event.pageX;
89
+ movedY = event.pageY;
90
+ if (this.canvas.offsetParent && (this.canvas.offsetParent as HTMLElement).tagName.toUpperCase() === "BODY") {
91
+ movedX -= this.canvas.offsetLeft;
92
+ movedY -= this.canvas.offsetTop;
93
+ } else if (this.canvas.offsetParent) {
94
+ movedX -= (this.canvas.offsetParent as HTMLElement).offsetLeft;
95
+ movedY -= (this.canvas.offsetParent as HTMLElement).offsetTop;
96
+ }
97
+ context.clearRect(0, 0, this.canvas.width, this.canvas.height);
98
+ this.drawExternal();
99
+ this.drawInternal();
100
+ callback({
101
+ x: 100 * ((movedX - centerX) / maxMoveStick),
102
+ y: 100 * ((movedY - centerY) / maxMoveStick) * -1,
103
+ global: global,
104
+ });
105
+ }
106
+ };
107
+
108
+ this.onMouseUp = () => {
109
+ event.preventDefault();
110
+ pressed = 0;
111
+ movedX = centerX;
112
+ movedY = centerY;
113
+ context.clearRect(0, 0, this.canvas.width, this.canvas.height);
114
+ this.drawExternal();
115
+ this.drawInternal();
116
+ callback({
117
+ x: 100 * ((movedX - centerX) / maxMoveStick),
118
+ y: 100 * ((movedY - centerY) / maxMoveStick) * -1,
119
+ global: global,
120
+ });
121
+ };
122
+
123
+ this.drawExternal = () => {
124
+ context.beginPath();
125
+ context.arc(centerX, centerY, externalRadius, 0, circumference, false);
126
+ context.lineWidth = externalLineWidth;
127
+ context.strokeStyle = externalStrokeColor;
128
+ context.globalAlpha = 0.5;
129
+ context.stroke();
130
+ };
131
+
132
+ this.drawInternal = () => {
133
+ context.beginPath();
134
+ if (movedX < internalRadius) {
135
+ movedX = maxMoveStick;
136
+ }
137
+ if (movedX + internalRadius > this.canvas.width) {
138
+ movedX = this.canvas.width - maxMoveStick;
139
+ }
140
+ if (movedY < internalRadius) {
141
+ movedY = maxMoveStick;
142
+ }
143
+ if (movedY + internalRadius > this.canvas.height) {
144
+ movedY = this.canvas.height - maxMoveStick;
145
+ }
146
+ context.arc(movedX, movedY, internalRadius, 0, circumference, false);
147
+ context.fillStyle = externalStrokeColor;
148
+ context.lineWidth = internalLineWidth;
149
+ context.strokeStyle = internalStrokeColor;
150
+ context.globalAlpha = 0.5;
151
+ context.fill();
152
+ context.stroke();
153
+ };
154
+
155
+ const addEventListeners = () => {
156
+ if (!this.hasEventListeners) {
157
+ this.canvas.addEventListener("pointerdown", this.onMouseDown, false);
158
+ document.addEventListener("pointermove", this.onMouseMove, false);
159
+ document.addEventListener("pointerup", this.onMouseUp, false);
160
+ this.hasEventListeners = true;
161
+ }
162
+ };
163
+
164
+ const removeEventListeners = () => {
165
+ if (this.hasEventListeners) {
166
+ this.canvas.removeEventListener("pointerdown", this.onMouseDown, false);
167
+ document.removeEventListener("pointermove", this.onMouseMove, false);
168
+ document.removeEventListener("pointerup", this.onMouseUp, false);
169
+ this.hasEventListeners = false;
170
+ }
171
+ };
172
+
173
+ const updateContainerPosition = () => {
174
+ if (canvasElement) {
175
+ const rect = canvasElement.getBoundingClientRect();
176
+ this.container.style.top = `${rect.height - 200}px`;
177
+ this.container.style.left = `${rect.left}px`;
178
+ this.container.style.width = `200px`;
179
+ this.container.style.height = `200px`;
180
+ }
181
+ };
182
+
183
+ const updateVisibility = () => {
184
+ const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
185
+ const isNarrowScreen = window.innerWidth < 1024;
186
+ const shouldShow = isMobile || isNarrowScreen;
187
+
188
+ if (shouldShow) {
189
+ this.container.style.display = "block";
190
+ addEventListeners();
191
+ } else {
192
+ this.container.style.display = "none";
193
+ removeEventListeners();
194
+ }
195
+ };
196
+
197
+ this.onResize = () => {
198
+ updateVisibility();
199
+ setTimeout(updateContainerPosition, 500);
200
+ };
201
+
202
+ updateVisibility();
203
+ updateContainerPosition();
204
+ window.addEventListener("resize", this.onResize, false);
205
+
206
+ this.drawExternal();
207
+ this.drawInternal();
208
+ }
209
+
210
+ cleanup(): void {
211
+ window.removeEventListener("resize", this.onResize, false);
212
+
213
+ if (this.hasEventListeners) {
214
+ this.canvas.removeEventListener("pointerdown", this.onMouseDown, false);
215
+ document.removeEventListener("pointermove", this.onMouseMove, false);
216
+ document.removeEventListener("pointerup", this.onMouseUp, false);
217
+ this.hasEventListeners = false;
218
+ }
219
+
220
+ this.canvas.remove();
221
+ }
222
+ }
@@ -23,6 +23,7 @@
23
23
  import { Viewer } from "../Viewer";
24
24
  import { Point2d, Vector3 } from "./Common/Geometry";
25
25
  import { OdBaseDragger } from "./Common/OdBaseDragger";
26
+ import { OdJoyStickDragger } from "./OdJoyStickDragger";
26
27
 
27
28
  const FocalLengthConst = 42.0;
28
29
 
@@ -46,6 +47,11 @@ export class OdaFlyDragger extends OdBaseDragger {
46
47
  protected deltaAngle: number;
47
48
  protected enableZoomWheelPreviousValue: boolean;
48
49
  protected dragPosition: Point2d;
50
+ protected lastJoyStickCoord: Point2d;
51
+ protected lastFrameJoyStickTS: number;
52
+ protected moving: boolean;
53
+ protected joyStickOverlayElement: HTMLDivElement;
54
+ protected joyStickDragger: OdJoyStickDragger;
49
55
 
50
56
  constructor(subject: Viewer) {
51
57
  super(subject);
@@ -59,11 +65,42 @@ export class OdaFlyDragger extends OdBaseDragger {
59
65
  this.keyup = this.keyup.bind(this);
60
66
 
61
67
  this.lastFrameTS = 0;
68
+ this.lastFrameJoyStickTS = 0;
62
69
  this.animationId = undefined;
63
70
  this.processMovement = this.processMovement.bind(this);
71
+ this.processJoyMovement = this.processJoyMovement.bind(this);
64
72
 
65
73
  this.deltaAngle = Math.PI / 3600;
66
74
  this.autoSelect = true;
75
+
76
+ this.moving = false;
77
+
78
+ this.joyStickOverlayElement = document.createElement("div");
79
+ this.joyStickOverlayElement.id = "joyStickDiv";
80
+ this.joyStickOverlayElement.style.background = "rgba(0,0,0,0)";
81
+ this.joyStickOverlayElement.style.position = "fixed";
82
+ this.joyStickOverlayElement.style.zIndex = "0";
83
+ document.body.appendChild(this.joyStickOverlayElement);
84
+
85
+ this.joyStickDragger = new OdJoyStickDragger(
86
+ this,
87
+ this.joyStickOverlayElement,
88
+ (stickData) => {
89
+ if (Math.sqrt(stickData.x * stickData.x + stickData.y * stickData.y) > 20) {
90
+ this.lastJoyStickCoord = { x: stickData.x, y: stickData.y };
91
+ if (!this.animationId && !this.moving) {
92
+ this.moving = true;
93
+ this.processJoyMovement(0);
94
+ }
95
+ } else {
96
+ this.moving = false;
97
+ window.cancelAnimationFrame(this.animationId);
98
+ this.animationId = undefined;
99
+ this.lastFrameJoyStickTS = 0;
100
+ }
101
+ },
102
+ this.m_module.canvas
103
+ );
67
104
  }
68
105
 
69
106
  override initialize() {
@@ -137,6 +174,9 @@ export class OdaFlyDragger extends OdBaseDragger {
137
174
  // CLOUD-5359 Demo Viewer crashes after the Fly Mode
138
175
  this.subject.update(true);
139
176
  this.subject.options.enableZoomWheel = this.enableZoomWheelPreviousValue;
177
+
178
+ this.joyStickOverlayElement.remove();
179
+ this.joyStickDragger.cleanup();
140
180
  }
141
181
 
142
182
  keydown(ev) {
@@ -289,4 +329,38 @@ export class OdaFlyDragger extends OdBaseDragger {
289
329
  const volume = [xmax - xmin, ymax - ymin, zmax - zmin];
290
330
  return Math.max(...volume);
291
331
  }
332
+
333
+ processJoyMovement(timestamp: number) {
334
+ if (!this.moving) return;
335
+ this.animationId = requestAnimationFrame(this.processJoyMovement);
336
+
337
+ if (this.lastFrameJoyStickTS !== 0) {
338
+ const deltaTS = timestamp - this.lastFrameJoyStickTS;
339
+ if (deltaTS > 0) {
340
+ const maxJoystickDistance = 100;
341
+ const forward = this.lastJoyStickCoord.y / maxJoystickDistance;
342
+ const right = this.lastJoyStickCoord.x / maxJoystickDistance;
343
+
344
+ const currentDelta = this.multiplier * deltaTS * this.speed;
345
+ this.moveTotal(currentDelta, forward, right);
346
+ }
347
+ }
348
+
349
+ this.lastFrameJoyStickTS = timestamp;
350
+ }
351
+
352
+ moveTotal(currentDelta: number, forward: number, right: number): void {
353
+ if (forward !== 0) {
354
+ if (forward > 0) {
355
+ this.cameraFlyer.moveForward(currentDelta * forward);
356
+ } else {
357
+ this.cameraFlyer.moveBackward(currentDelta * Math.abs(forward));
358
+ }
359
+ }
360
+ if (right !== 0) {
361
+ this.cameraFlyer.moveRight(currentDelta * right);
362
+ }
363
+ this.subject.update();
364
+ this.subject.emitEvent({ type: "changecamera" });
365
+ }
292
366
  }