@preference-sl/pref-viewer 2.11.0-beta.12 → 2.11.0-beta.13
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/package.json +62 -50
- package/src/babylonjs-animation-controller.js +54 -65
- package/src/babylonjs-animation-opening.js +12 -4
- package/src/babylonjs-controller.js +110 -37
- package/src/index.js +15 -911
- package/src/pref-viewer.js +911 -0
package/package.json
CHANGED
|
@@ -1,53 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
"name": "@preference-sl/pref-viewer",
|
|
3
|
+
"version": "2.11.0-beta.13",
|
|
4
|
+
"description": "Web Component to preview GLTF models with Babylon.js",
|
|
5
|
+
"author": "Alex Moreno Palacio <amoreno@preference.es>",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build:prefweb": "webpack --config webpack.config.cjs --mode production",
|
|
8
|
+
"build:prefweb:dev": "webpack --config webpack.config.cjs --mode development",
|
|
9
|
+
"release": "standard-version --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\"",
|
|
10
|
+
"release:beta": "standard-version --prerelease beta --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\"",
|
|
11
|
+
"build": "esbuild src/index.js --bundle --platform=node --format=esm --outfile=dist/bundle.js --sourcemap",
|
|
12
|
+
"start": "npm run build && http-server -c-1 . -p 8080",
|
|
13
|
+
"test": "vitest"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://bitbucket.org/preferencesl/pref-viewer.git"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "src/index.js",
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./src/index.js",
|
|
29
|
+
"require": "./src/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"files": [
|
|
34
|
+
"src",
|
|
35
|
+
"index.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@babylonjs/core": "^8.39.0",
|
|
39
|
+
"@babylonjs/gui": "^8.39.0",
|
|
40
|
+
"@babylonjs/loaders": "^8.39.0",
|
|
41
|
+
"@babylonjs/serializers": "^8.39.0",
|
|
42
|
+
"@panzoom/panzoom": "^4.6.0",
|
|
43
|
+
"babylonjs-gltf2interface": "^8.39.0",
|
|
44
|
+
"buffer": "^6.0.3",
|
|
45
|
+
"idb": "^8.0.3",
|
|
46
|
+
"is-svg": "^6.1.0",
|
|
47
|
+
"jszip": "^3.10.1",
|
|
48
|
+
"stream": "^0.0.3",
|
|
49
|
+
"string_decoder": "^1.3.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@babel/core": "^7.22.0",
|
|
53
|
+
"@babel/preset-env": "^7.22.0",
|
|
54
|
+
"babel-loader": "^9.2.1",
|
|
55
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
56
|
+
"esbuild": "^0.25.10",
|
|
57
|
+
"http-server": "^14.1.1",
|
|
58
|
+
"jsdom": "^26.1.0",
|
|
59
|
+
"standard-version": "^9.5.0",
|
|
60
|
+
"terser-webpack-plugin": "^5.3.6",
|
|
61
|
+
"vitest": "^3.2.3",
|
|
62
|
+
"webpack": "^5.88.2",
|
|
63
|
+
"webpack-cli": "^5.1.4"
|
|
28
64
|
}
|
|
29
|
-
},
|
|
30
|
-
"sideEffects": false,
|
|
31
|
-
"files": [
|
|
32
|
-
"src",
|
|
33
|
-
"index.d.ts"
|
|
34
|
-
],
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@babylonjs/core": "^8.36.1",
|
|
37
|
-
"@babylonjs/gui": "^8.36.1",
|
|
38
|
-
"@babylonjs/loaders": "^8.36.1",
|
|
39
|
-
"@babylonjs/serializers": "^8.36.1",
|
|
40
|
-
"@panzoom/panzoom": "^4.6.0",
|
|
41
|
-
"babylonjs-gltf2interface": "^8.36.1",
|
|
42
|
-
"idb": "^8.0.3",
|
|
43
|
-
"is-svg": "^6.1.0",
|
|
44
|
-
"jszip": "^3.10.1"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"esbuild": "^0.25.10",
|
|
48
|
-
"http-server": "^14.1.1",
|
|
49
|
-
"jsdom": "^26.1.0",
|
|
50
|
-
"standard-version": "^9.5.0",
|
|
51
|
-
"vitest": "^3.2.3"
|
|
52
|
-
}
|
|
53
65
|
}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import { Color3, HighlightLayer, Mesh, PickingInfo,
|
|
1
|
+
import { Color3, HighlightLayer, Mesh, PickingInfo, Scene } from "@babylonjs/core";
|
|
2
2
|
import { AdvancedDynamicTexture } from "@babylonjs/gui";
|
|
3
3
|
import { PrefViewerColors } from "./styles.js";
|
|
4
4
|
import OpeningAnimation from "./babylonjs-animation-opening.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* BabylonJSAnimationController - Manages animation playback and interactive
|
|
7
|
+
* BabylonJSAnimationController - Manages animation playback, highlighting, and interactive controls for animated nodes in Babylon.js scenes.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* Summary:
|
|
10
|
+
* This class detects, groups, and manages opening/closing animations for scene nodes, provides interactive highlighting of animated nodes and their meshes, and displays a GUI menu for animation control. It is designed for integration with product configurators and interactive 3D applications using Babylon.js.
|
|
11
|
+
*
|
|
12
|
+
* Key features:
|
|
10
13
|
* - Detects and groups opening/closing animations in the scene.
|
|
11
14
|
* - Tracks animated transformation nodes and their relationships to meshes.
|
|
12
|
-
* - Highlights animated nodes and their child meshes
|
|
13
|
-
* - Displays and disposes the animation control menu (GUI) for animated nodes.
|
|
14
|
-
* - Provides API for
|
|
15
|
+
* - Highlights animated nodes and their child meshes on pointer hover.
|
|
16
|
+
* - Displays and disposes the animation control menu (Babylon.js GUI) for animated nodes.
|
|
17
|
+
* - Provides public API for highlighting, showing the animation menu, and disposing resources.
|
|
18
|
+
* - Cleans up all resources and observers to prevent memory leaks.
|
|
15
19
|
*
|
|
16
20
|
* Public Methods:
|
|
17
21
|
* - dispose(): Disposes all resources managed by the animation controller.
|
|
22
|
+
* - hightlightMeshes(pickingInfo): Highlights meshes that are children of an animated node when hovered.
|
|
23
|
+
* - hideMenu(): Hides and disposes the animation control menu (Babylon.js GUI) if it exists.
|
|
24
|
+
* - showMenu(pickingInfo): Displays the animation control menu for the animated node under the pointer.
|
|
18
25
|
*
|
|
19
26
|
* @class
|
|
20
27
|
*/
|
|
@@ -33,7 +40,6 @@ export default class BabylonJSAnimationController {
|
|
|
33
40
|
constructor(scene) {
|
|
34
41
|
this.#scene = scene;
|
|
35
42
|
this.#initializeAnimations();
|
|
36
|
-
this.#setupPointerObservers();
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -123,12 +129,38 @@ export default class BabylonJSAnimationController {
|
|
|
123
129
|
return nodeId;
|
|
124
130
|
};
|
|
125
131
|
|
|
132
|
+
/**
|
|
133
|
+
* ---------------------------
|
|
134
|
+
* Public methods
|
|
135
|
+
* ---------------------------
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Disposes all resources managed by the animation controller.
|
|
140
|
+
* Cleans up the highlight layer, GUI texture, and internal animation/node lists.
|
|
141
|
+
* Should be called when the controller is no longer needed to prevent memory leaks.
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
dispose() {
|
|
145
|
+
if (this.#highlightLayer) {
|
|
146
|
+
this.#highlightLayer.dispose();
|
|
147
|
+
this.#highlightLayer = null;
|
|
148
|
+
}
|
|
149
|
+
this.hideMenu();
|
|
150
|
+
this.#animatedNodes = [];
|
|
151
|
+
this.#openingAnimations = [];
|
|
152
|
+
const observer = this.#scene.onPointerObservable._observers.find((observer) => observer.callback.name.includes("#onAnimationPointerObservable"));
|
|
153
|
+
if (observer) {
|
|
154
|
+
this.#scene.onPointerObservable.remove(observer);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
126
158
|
/**
|
|
127
159
|
* Highlights meshes that are children of an animated node when hovered.
|
|
128
|
-
* @
|
|
160
|
+
* @public
|
|
129
161
|
* @param {PickingInfo} pickingInfo - Raycast info from pointer position.
|
|
130
162
|
*/
|
|
131
|
-
|
|
163
|
+
hightlightMeshes(pickingInfo) {
|
|
132
164
|
if (!this.#highlightLayer) {
|
|
133
165
|
this.#highlightLayer = new HighlightLayer("hl_animations", this.#scene);
|
|
134
166
|
}
|
|
@@ -151,52 +183,32 @@ export default class BabylonJSAnimationController {
|
|
|
151
183
|
}
|
|
152
184
|
|
|
153
185
|
/**
|
|
154
|
-
*
|
|
155
|
-
* @
|
|
156
|
-
|
|
157
|
-
#setupPointerObservers() {
|
|
158
|
-
if (this.#openingAnimations.length === 0) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
this.#scene.onPointerObservable.add(this.#onAnimationPointerObservable.bind(this));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Handles pointer events in the Babylon.js scene for animation interaction.
|
|
166
|
-
* On pointer move, highlights meshes belonging to animated nodes under the cursor.
|
|
167
|
-
* On pointer up (click), disposes any existing GUI and displays the animation control menu for the selected node.
|
|
168
|
-
*
|
|
169
|
-
* @private
|
|
170
|
-
* @param {PointerInfo} pointerInfo - The pointer event information from Babylon.js.
|
|
186
|
+
* Hides and disposes the animation control menu (Babylon.js GUI) if it exists.
|
|
187
|
+
* @public
|
|
188
|
+
* @returns {void}
|
|
171
189
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.#
|
|
176
|
-
|
|
177
|
-
if (pointerInfo.type === PointerEventTypes.POINTERUP) {
|
|
178
|
-
// Remove any previously created Babylon GUI
|
|
179
|
-
if (this.#advancedDynamicTexture) {
|
|
180
|
-
this.#advancedDynamicTexture.dispose();
|
|
181
|
-
this.#advancedDynamicTexture = null;
|
|
182
|
-
}
|
|
183
|
-
const pickingInfo = this.#scene.pick(pointerInfo.event.clientX, pointerInfo.event.clientY);
|
|
184
|
-
this.#showMenu(pickingInfo);
|
|
190
|
+
hideMenu() {
|
|
191
|
+
// Remove any previously created Babylon GUI
|
|
192
|
+
if (this.#advancedDynamicTexture) {
|
|
193
|
+
this.#advancedDynamicTexture.dispose();
|
|
194
|
+
this.#advancedDynamicTexture = null;
|
|
185
195
|
}
|
|
186
196
|
}
|
|
187
197
|
|
|
188
198
|
/**
|
|
189
199
|
* Displays the animation control menu for the animated node under the pointer.
|
|
190
|
-
* @
|
|
200
|
+
* @public
|
|
191
201
|
* @param {PickingInfo} pickingInfo - Raycast info from pointer position.
|
|
192
202
|
* @description
|
|
193
203
|
* Creates the GUI if needed and invokes OpeningAnimation.showControls.
|
|
194
204
|
*/
|
|
195
|
-
|
|
205
|
+
showMenu(pickingInfo) {
|
|
196
206
|
if (!pickingInfo?.hit && !pickingInfo?.pickedMesh) {
|
|
197
207
|
return;
|
|
198
208
|
}
|
|
199
209
|
|
|
210
|
+
this.hideMenu();
|
|
211
|
+
|
|
200
212
|
const nodeId = this.#getNodeAnimatedByMesh(pickingInfo.pickedMesh);
|
|
201
213
|
if (!nodeId) {
|
|
202
214
|
return;
|
|
@@ -206,31 +218,8 @@ export default class BabylonJSAnimationController {
|
|
|
206
218
|
return;
|
|
207
219
|
}
|
|
208
220
|
if (!this.#advancedDynamicTexture) {
|
|
209
|
-
this.#advancedDynamicTexture = AdvancedDynamicTexture.CreateFullscreenUI("UI_Animation");
|
|
221
|
+
this.#advancedDynamicTexture = AdvancedDynamicTexture.CreateFullscreenUI("UI_Animation", true, this.#scene);
|
|
210
222
|
}
|
|
211
223
|
openingAnimation.showControls(this.#advancedDynamicTexture);
|
|
212
224
|
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Disposes all resources managed by the animation controller.
|
|
216
|
-
* Cleans up the highlight layer, GUI texture, and internal animation/node lists.
|
|
217
|
-
* Should be called when the controller is no longer needed to prevent memory leaks.
|
|
218
|
-
* @public
|
|
219
|
-
*/
|
|
220
|
-
dispose() {
|
|
221
|
-
if (this.#highlightLayer) {
|
|
222
|
-
this.#highlightLayer.dispose();
|
|
223
|
-
this.#highlightLayer = null;
|
|
224
|
-
}
|
|
225
|
-
if (this.#advancedDynamicTexture) {
|
|
226
|
-
this.#advancedDynamicTexture.dispose();
|
|
227
|
-
this.#advancedDynamicTexture = null;
|
|
228
|
-
}
|
|
229
|
-
this.#animatedNodes = [];
|
|
230
|
-
this.#openingAnimations = [];
|
|
231
|
-
const observer = this.#scene.onPointerObservable._observers.find((observer) => observer.callback.name.includes("#onAnimationPointerObservable"));
|
|
232
|
-
if (observer) {
|
|
233
|
-
this.#scene.onPointerObservable.remove(observer);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
225
|
}
|
|
@@ -138,11 +138,15 @@ export default class OpeningAnimation {
|
|
|
138
138
|
#goToOpened(useLoop = false) {
|
|
139
139
|
this.#lastPausedFrame = this.#endFrame;
|
|
140
140
|
|
|
141
|
-
if (this.#openAnimation._isStarted
|
|
142
|
-
this.#openAnimation.
|
|
141
|
+
if (!this.#openAnimation._isStarted) {
|
|
142
|
+
this.#openAnimation.start();
|
|
143
143
|
}
|
|
144
|
+
this.#openAnimation.pause();
|
|
144
145
|
this.#openAnimation.goToFrame(this.#endFrame);
|
|
145
146
|
|
|
147
|
+
if (!this.#closeAnimation._isStarted) {
|
|
148
|
+
this.#closeAnimation.start();
|
|
149
|
+
}
|
|
146
150
|
this.#closeAnimation.pause();
|
|
147
151
|
this.#closeAnimation.goToFrame(this.#startFrame);
|
|
148
152
|
|
|
@@ -162,11 +166,15 @@ export default class OpeningAnimation {
|
|
|
162
166
|
#goToClosed(useLoop = false) {
|
|
163
167
|
this.#lastPausedFrame = this.#startFrame;
|
|
164
168
|
|
|
165
|
-
if (this.#closeAnimation._isStarted
|
|
166
|
-
this.#closeAnimation.
|
|
169
|
+
if (!this.#closeAnimation._isStarted) {
|
|
170
|
+
this.#closeAnimation.start();
|
|
167
171
|
}
|
|
172
|
+
this.#closeAnimation.pause();
|
|
168
173
|
this.#closeAnimation.goToFrame(this.#endFrame - this.#startFrame);
|
|
169
174
|
|
|
175
|
+
if (!this.#openAnimation._isStarted) {
|
|
176
|
+
this.#openAnimation.start();
|
|
177
|
+
}
|
|
170
178
|
this.#openAnimation.pause();
|
|
171
179
|
this.#openAnimation.goToFrame(this.#startFrame);
|
|
172
180
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ArcRotateCamera, AssetContainer, Camera, Color4, DirectionalLight, Engine, HDRCubeTexture, HemisphericLight, IblShadowsRenderPipeline, LoadAssetContainerAsync, MeshBuilder, PointLight, Scene, ShadowGenerator, Tools, Vector3, WebXRDefaultExperience, WebXRFeatureName, WebXRSessionManager } from "@babylonjs/core";
|
|
2
|
-
import { DracoCompression } from "@babylonjs/core/Meshes/Compression/dracoCompression";
|
|
1
|
+
import { ArcRotateCamera, AssetContainer, Camera, Color4, DirectionalLight, Engine, HDRCubeTexture, HemisphericLight, IblShadowsRenderPipeline, LoadAssetContainerAsync, MeshBuilder, PointerEventTypes, PointLight, Scene, ShadowGenerator, Tools, Vector3, WebXRDefaultExperience, WebXRFeatureName, WebXRSessionManager } from "@babylonjs/core";
|
|
2
|
+
import { DracoCompression } from "@babylonjs/core/Meshes/Compression/dracoCompression.js";
|
|
3
3
|
import "@babylonjs/loaders";
|
|
4
|
-
import "@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
|
|
4
|
+
import "@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression.js";
|
|
5
5
|
import { USDZExportAsync, GLTF2Export } from "@babylonjs/serializers";
|
|
6
6
|
|
|
7
7
|
import GLTFResolver from "./gltf-resolver.js";
|
|
@@ -45,19 +45,37 @@ import BabylonJSAnimationController from "./babylonjs-animation-controller.js";
|
|
|
45
45
|
* - #renderLoop(): Babylon.js render loop callback.
|
|
46
46
|
* - #addStylesToARButton(): Styles AR button.
|
|
47
47
|
* - #createXRExperience(): Initializes WebXR AR experience.
|
|
48
|
-
* - #createCamera()
|
|
49
|
-
* - #
|
|
50
|
-
* - #
|
|
51
|
-
* - #
|
|
52
|
-
* - #
|
|
53
|
-
* - #
|
|
54
|
-
* - #
|
|
55
|
-
* - #
|
|
56
|
-
* - #
|
|
57
|
-
* - #
|
|
58
|
-
* - #
|
|
59
|
-
* - #
|
|
60
|
-
* - #
|
|
48
|
+
* - #createCamera(): Creates and configures the main camera.
|
|
49
|
+
* - #createLights(): Creates and configures scene lights and shadows.
|
|
50
|
+
* - #initializeEnvironmentTexture(): Loads and sets the HDR environment texture.
|
|
51
|
+
* - #initializeIBLShadows(): Sets up IBL shadow pipeline and assigns meshes/materials.
|
|
52
|
+
* - #initializeShadows(): Sets up standard or IBL shadows for meshes.
|
|
53
|
+
* - #setMaxSimultaneousLights(): Updates max simultaneous lights for all materials.
|
|
54
|
+
* - #onPointerObservable(info): Handles pointer events and dispatches to pointer/mouse handlers.
|
|
55
|
+
* - #onPointerUp(event, pickInfo): Handles pointer up events (e.g., right-click for animation menu).
|
|
56
|
+
* - #onPointerMove(event, pickInfo): Handles pointer move events (e.g., mesh highlighting).
|
|
57
|
+
* - #onMouseWheel(event, pickInfo): Handles mouse wheel events for camera zoom.
|
|
58
|
+
* - #onKeyUp(event): Handles keyup events for download dialog and shortcuts.
|
|
59
|
+
* - #enableInteraction(): Adds canvas and scene interaction event listeners.
|
|
60
|
+
* - #disableInteraction(): Removes canvas and scene interaction event listeners.
|
|
61
|
+
* - #disposeEngine(): Disposes engine and releases all resources.
|
|
62
|
+
* - #setOptionsMaterial(optionMaterial): Applies a material option to relevant meshes.
|
|
63
|
+
* - #setOptions_Materials(): Applies all material options from configuration.
|
|
64
|
+
* - #setOptions_Camera(): Applies camera options from configuration.
|
|
65
|
+
* - #findContainerByName(name): Finds a container by its name.
|
|
66
|
+
* - #addContainer(container, updateVisibility): Adds a container to the scene and updates visibility.
|
|
67
|
+
* - #removeContainer(container, updateVisibility): Removes a container from the scene and updates visibility.
|
|
68
|
+
* - #replaceContainer(container, newAssetContainer): Replaces a container in the scene.
|
|
69
|
+
* - #getPrefViewer3DComponent(): Caches and retrieves the parent PREF-VIEWER-3D element.
|
|
70
|
+
* - #getPrefViewerComponent(): Caches and retrieves the parent PREF-VIEWER element.
|
|
71
|
+
* - #updateVisibilityAttributeInComponents(name, isVisible): Updates parent visibility attributes.
|
|
72
|
+
* - #setVisibilityOfWallAndFloorInModel(show): Controls wall/floor mesh visibility.
|
|
73
|
+
* - #stopRender(): Stops the Babylon.js render loop.
|
|
74
|
+
* - #startRender(): Starts the Babylon.js render loop.
|
|
75
|
+
* - #loadAssetContainer(container): Loads an asset container asynchronously.
|
|
76
|
+
* - #loadContainers(): Loads all asset containers and adds them to the scene.
|
|
77
|
+
* - #addDateToName(name): Appends the current date/time to a name string.
|
|
78
|
+
* - #downloadZip(files, name, comment, addDateInName): Generates and downloads a ZIP file.
|
|
61
79
|
* - #openDownloadDialog(): Opens the modal download dialog.
|
|
62
80
|
*
|
|
63
81
|
* Notes:
|
|
@@ -401,13 +419,34 @@ export default class BabylonJSController {
|
|
|
401
419
|
}
|
|
402
420
|
|
|
403
421
|
/**
|
|
404
|
-
*
|
|
422
|
+
* Handles pointer events observed on the Babylon.js scene.
|
|
423
|
+
* @private
|
|
424
|
+
* @param {PointerInfo} info - The pointer event information from Babylon.js.
|
|
425
|
+
* @returns {void}
|
|
426
|
+
*/
|
|
427
|
+
#onPointerObservable(info) {
|
|
428
|
+
const pickInfo = this.#scene.pick(this.#scene.pointerX, this.#scene.pointerY);
|
|
429
|
+
if (info.type === PointerEventTypes.POINTERUP) {
|
|
430
|
+
this.#onPointerUp(info.event, pickInfo);
|
|
431
|
+
} else if (info.type === PointerEventTypes.POINTERMOVE) {
|
|
432
|
+
this.#onPointerMove(info.event, pickInfo);
|
|
433
|
+
} else if (info.type === PointerEventTypes.POINTERWHEEL) {
|
|
434
|
+
this.#onMouseWheel(info.event, pickInfo);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Sets up interaction handlers for the Babylon.js canvas and scene.
|
|
405
440
|
* @private
|
|
406
441
|
* @returns {void}
|
|
407
442
|
*/
|
|
408
443
|
#enableInteraction() {
|
|
409
|
-
this.#canvas
|
|
410
|
-
|
|
444
|
+
if (this.#canvas) {
|
|
445
|
+
this.#canvas.addEventListener("keyup", this.#onKeyUp.bind(this));
|
|
446
|
+
}
|
|
447
|
+
if (this.#scene) {
|
|
448
|
+
this.#scene.onPointerObservable.add(this.#onPointerObservable.bind(this));
|
|
449
|
+
}
|
|
411
450
|
}
|
|
412
451
|
|
|
413
452
|
/**
|
|
@@ -416,8 +455,12 @@ export default class BabylonJSController {
|
|
|
416
455
|
* @returns {void}
|
|
417
456
|
*/
|
|
418
457
|
#disableInteraction() {
|
|
419
|
-
this.#canvas
|
|
420
|
-
|
|
458
|
+
if (this.#canvas) {
|
|
459
|
+
this.#canvas.removeEventListener("keyup", this.#onKeyUp.bind(this));
|
|
460
|
+
}
|
|
461
|
+
if (this.#scene !== null) {
|
|
462
|
+
this.#scene.onPointerObservable.removeCallback(this.#onPointerObservable.bind(this));
|
|
463
|
+
}
|
|
421
464
|
}
|
|
422
465
|
|
|
423
466
|
/**
|
|
@@ -436,18 +479,37 @@ export default class BabylonJSController {
|
|
|
436
479
|
this.#XRExperience = null;
|
|
437
480
|
}
|
|
438
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Handles keyup events on the Babylon.js canvas for triggering model and scene downloads.
|
|
484
|
+
* @private
|
|
485
|
+
* @param {KeyboardEvent} event - The keyup event.
|
|
486
|
+
* @returns {void}
|
|
487
|
+
*/
|
|
488
|
+
#onKeyUp(event) {
|
|
489
|
+
// CTRL + ALT + letter
|
|
490
|
+
if (event.ctrlKey && event.altKey && event.key !== undefined) {
|
|
491
|
+
switch (event.key.toLowerCase()) {
|
|
492
|
+
case "d":
|
|
493
|
+
this.#openDownloadDialog();
|
|
494
|
+
break;
|
|
495
|
+
default:
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
439
501
|
/**
|
|
440
502
|
* Handles mouse wheel events on the Babylon.js canvas for zooming the camera.
|
|
441
503
|
* @private
|
|
442
504
|
* @param {WheelEvent} event - The mouse wheel event.
|
|
443
|
-
* @
|
|
505
|
+
* @param {Object} pickInfo - The result of the scene pick operation (not used in this method).
|
|
506
|
+
* @returns {void|false} Returns false if there is no active camera; otherwise, void.
|
|
444
507
|
*/
|
|
445
|
-
#onMouseWheel(event) {
|
|
446
|
-
if (!this.#scene
|
|
508
|
+
#onMouseWheel(event, pickInfo) {
|
|
509
|
+
if (!this.#scene?.activeCamera) {
|
|
447
510
|
return false;
|
|
448
511
|
}
|
|
449
|
-
//
|
|
450
|
-
//this.#camera.target = pick.hit ? pick.pickedPoint.clone() : this.#camera.target;
|
|
512
|
+
//this.#scene.activeCamera.target = pickInfo.hit ? pickInfo.pickedPoint.clone() : this.#scene.activeCamera.target;
|
|
451
513
|
if (!this.#scene.activeCamera.metadata?.locked) {
|
|
452
514
|
this.#scene.activeCamera.inertialRadiusOffset -= event.deltaY * this.#scene.activeCamera.wheelPrecision * 0.001;
|
|
453
515
|
}
|
|
@@ -455,24 +517,35 @@ export default class BabylonJSController {
|
|
|
455
517
|
}
|
|
456
518
|
|
|
457
519
|
/**
|
|
458
|
-
* Handles
|
|
520
|
+
* Handles pointer up events on the Babylon.js scene.
|
|
459
521
|
* @private
|
|
460
|
-
* @param {
|
|
522
|
+
* @param {PointerEvent} event - The pointer up event.
|
|
523
|
+
* @param {PickInfo} pickInfo - The result of the scene pick operation.
|
|
461
524
|
* @returns {void}
|
|
462
525
|
*/
|
|
463
|
-
#
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
break;
|
|
470
|
-
default:
|
|
471
|
-
break;
|
|
526
|
+
#onPointerUp(event, pickInfo) {
|
|
527
|
+
if (this.#babylonJSAnimationController) {
|
|
528
|
+
this.#babylonJSAnimationController.hideMenu();
|
|
529
|
+
// Right click for showing animation menu
|
|
530
|
+
if (event.button === 2) {
|
|
531
|
+
this.#babylonJSAnimationController.showMenu(pickInfo);
|
|
472
532
|
}
|
|
473
533
|
}
|
|
474
534
|
}
|
|
475
535
|
|
|
536
|
+
/**
|
|
537
|
+
* Handles pointer move events on the Babylon.js scene.
|
|
538
|
+
* @private
|
|
539
|
+
* @param {PointerEvent} event - The pointer move event.
|
|
540
|
+
* @param {PickInfo} pickInfo - The result of the scene pick operation.
|
|
541
|
+
* @returns {void}
|
|
542
|
+
*/
|
|
543
|
+
#onPointerMove(event, pickInfo) {
|
|
544
|
+
if (this.#babylonJSAnimationController) {
|
|
545
|
+
this.#babylonJSAnimationController.hightlightMeshes(pickInfo);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
476
549
|
/**
|
|
477
550
|
* Applies material options from the configuration to the relevant meshes.
|
|
478
551
|
* @private
|