@preference-sl/pref-viewer 2.11.0-beta.5 → 2.11.0-beta.7
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
CHANGED
|
@@ -12,6 +12,9 @@ import { OpeningAnimation } from "./babylonjs-animation-opening.js";
|
|
|
12
12
|
* - Displays and disposes the animation control menu (GUI) for animated nodes.
|
|
13
13
|
* - Provides API for interaction and animation control.
|
|
14
14
|
*
|
|
15
|
+
* Public Methods:
|
|
16
|
+
* - dispose(): Disposes all resources managed by the animation controller.
|
|
17
|
+
*
|
|
15
18
|
* @class
|
|
16
19
|
*/
|
|
17
20
|
export default class BabylonJSAnimationController {
|
|
@@ -50,6 +53,7 @@ export default class BabylonJSAnimationController {
|
|
|
50
53
|
*/
|
|
51
54
|
#getAnimatedNodes() {
|
|
52
55
|
this.#scene.animationGroups.forEach((animationGroup) => {
|
|
56
|
+
animationGroup.stop();
|
|
53
57
|
if (!animationGroup._targetedAnimations.length) {
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
@@ -150,21 +154,34 @@ export default class BabylonJSAnimationController {
|
|
|
150
154
|
* @private
|
|
151
155
|
*/
|
|
152
156
|
#setupPointerObservers() {
|
|
153
|
-
this.#
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
157
|
+
if (this.#openingAnimations.length === 0) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.#scene.onPointerObservable.add(this.#onAnimationPointerObservable.bind(this));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Handles pointer events in the Babylon.js scene for animation interaction.
|
|
165
|
+
* On pointer move, highlights meshes belonging to animated nodes under the cursor.
|
|
166
|
+
* On pointer up (click), disposes any existing GUI and displays the animation control menu for the selected node.
|
|
167
|
+
*
|
|
168
|
+
* @private
|
|
169
|
+
* @param {PointerInfo} pointerInfo - The pointer event information from Babylon.js.
|
|
170
|
+
*/
|
|
171
|
+
#onAnimationPointerObservable(pointerInfo) {
|
|
172
|
+
if (pointerInfo.type === PointerEventTypes.POINTERMOVE) {
|
|
173
|
+
const pickingInfo = this.#scene.pick(pointerInfo.event.clientX, pointerInfo.event.clientY);
|
|
174
|
+
this.#hightlightMeshesForAnimation(pickingInfo);
|
|
175
|
+
}
|
|
176
|
+
if (pointerInfo.type === PointerEventTypes.POINTERUP) {
|
|
177
|
+
// Remove any previously created Babylon GUI
|
|
178
|
+
if (this.#advancedDynamicTexture) {
|
|
179
|
+
this.#advancedDynamicTexture.dispose();
|
|
180
|
+
this.#advancedDynamicTexture = null;
|
|
166
181
|
}
|
|
167
|
-
|
|
182
|
+
const pickingInfo = this.#scene.pick(pointerInfo.event.clientX, pointerInfo.event.clientY);
|
|
183
|
+
this.#showMenu(pickingInfo);
|
|
184
|
+
}
|
|
168
185
|
}
|
|
169
186
|
|
|
170
187
|
/**
|
|
@@ -192,4 +209,27 @@ export default class BabylonJSAnimationController {
|
|
|
192
209
|
}
|
|
193
210
|
openingAnimation.showControls(this.#advancedDynamicTexture);
|
|
194
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Disposes all resources managed by the animation controller.
|
|
215
|
+
* Cleans up the highlight layer, GUI texture, and internal animation/node lists.
|
|
216
|
+
* Should be called when the controller is no longer needed to prevent memory leaks.
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
dispose() {
|
|
220
|
+
if (this.#highlightLayer) {
|
|
221
|
+
this.#highlightLayer.dispose();
|
|
222
|
+
this.#highlightLayer = null;
|
|
223
|
+
}
|
|
224
|
+
if (this.#advancedDynamicTexture) {
|
|
225
|
+
this.#advancedDynamicTexture.dispose();
|
|
226
|
+
this.#advancedDynamicTexture = null;
|
|
227
|
+
}
|
|
228
|
+
this.#animatedNodes = [];
|
|
229
|
+
this.#openingAnimations = [];
|
|
230
|
+
const observer = this.#scene.onPointerObservable._observers.find((observer) => observer.callback.name.includes("#onAnimationPointerObservable"));
|
|
231
|
+
if (observer) {
|
|
232
|
+
this.#scene.onPointerObservable.remove(observer);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
195
235
|
}
|
|
@@ -5,7 +5,7 @@ import "@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
|
|
|
5
5
|
import { USDZExportAsync, GLTF2Export } from "@babylonjs/serializers";
|
|
6
6
|
|
|
7
7
|
import GLTFResolver from "./gltf-resolver.js";
|
|
8
|
-
import {
|
|
8
|
+
import { MaterialData } from "./pref-viewer-3d-data.js";
|
|
9
9
|
import BabylonJSAnimationController from "./babylonjs-animation-controller.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -452,7 +452,7 @@ export default class BabylonJSController {
|
|
|
452
452
|
if (container.state.name === "materials") {
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
if (container.assetContainer && (container.isPending || materialContainer.isPending || optionMaterial.isPending)) {
|
|
455
|
+
if (container.assetContainer && (container.state.isPending || materialContainer.state.isPending || optionMaterial.isPending)) {
|
|
456
456
|
assetContainersToProcess.push(container.assetContainer);
|
|
457
457
|
}
|
|
458
458
|
});
|
|
@@ -504,7 +504,7 @@ export default class BabylonJSController {
|
|
|
504
504
|
const modelContainer = this.#containers.model;
|
|
505
505
|
const environmentContainer = this.#containers.environment;
|
|
506
506
|
|
|
507
|
-
if (!cameraState.isPending && !modelContainer.isPending && !environmentContainer.isPending) {
|
|
507
|
+
if (!cameraState.isPending && !modelContainer.state.isPending && !environmentContainer.state.isPending) {
|
|
508
508
|
return false;
|
|
509
509
|
}
|
|
510
510
|
|
|
@@ -559,7 +559,7 @@ export default class BabylonJSController {
|
|
|
559
559
|
* Finds and returns the asset container object by its name.
|
|
560
560
|
* @private
|
|
561
561
|
* @param {string} name - The name of the container to find.
|
|
562
|
-
* @returns {
|
|
562
|
+
* @returns {Object|null} The matching container object, or null if not found.
|
|
563
563
|
*/
|
|
564
564
|
#findContainerByName(name) {
|
|
565
565
|
return Object.values(this.#containers).find((container) => container.state.name === name) || null;
|
|
@@ -612,7 +612,7 @@ export default class BabylonJSController {
|
|
|
612
612
|
/**
|
|
613
613
|
* Adds the asset container to the Babylon.js scene if it should be shown and is not already visible.
|
|
614
614
|
* @private
|
|
615
|
-
* @param {
|
|
615
|
+
* @param {object} container - The container object containing asset state and metadata.
|
|
616
616
|
* @param {boolean} [updateVisibility=true] - If true, updates the visibility attribute in parent components.
|
|
617
617
|
* @returns {boolean} True if the container was added, false otherwise.
|
|
618
618
|
*/
|
|
@@ -631,7 +631,7 @@ export default class BabylonJSController {
|
|
|
631
631
|
/**
|
|
632
632
|
* Removes the asset container from the Babylon.js scene if it is currently visible.
|
|
633
633
|
* @private
|
|
634
|
-
* @param {
|
|
634
|
+
* @param {object} container - The container object containing asset state and metadata.
|
|
635
635
|
* @param {boolean} [updateVisibility=true] - If true, updates the visibility attribute in parent components.
|
|
636
636
|
* @returns {boolean} True if the container was removed, false otherwise.
|
|
637
637
|
*/
|
|
@@ -650,7 +650,7 @@ export default class BabylonJSController {
|
|
|
650
650
|
/**
|
|
651
651
|
* Replaces the asset container in the Babylon.js scene with a new one.
|
|
652
652
|
* @private
|
|
653
|
-
* @param {
|
|
653
|
+
* @param {object} container - The container object containing asset state and metadata.
|
|
654
654
|
* @param {AssetContainer} newAssetContainer - The new asset container to add to the scene.
|
|
655
655
|
* @returns {boolean} True if the container was replaced and added, false otherwise.
|
|
656
656
|
*/
|
|
@@ -703,8 +703,8 @@ export default class BabylonJSController {
|
|
|
703
703
|
/**
|
|
704
704
|
* Loads an asset container (model, environment, materials, etc.) using the provided container state.
|
|
705
705
|
* @private
|
|
706
|
-
* @param {
|
|
707
|
-
* @returns {Promise<[
|
|
706
|
+
* @param {object} container - The container object containing asset state and metadata.
|
|
707
|
+
* @returns {Promise<[object, AssetContainer|boolean]>} Resolves to an array with the container and the loaded asset container, or false if loading fails.
|
|
708
708
|
* @description
|
|
709
709
|
* Resolves the asset source using GLTFResolver, prepares plugin options, and loads the asset into the Babylon.js scene.
|
|
710
710
|
* Updates the container's cache data and returns the container along with the loaded asset container or false if loading fails.
|
|
@@ -768,6 +768,10 @@ export default class BabylonJSController {
|
|
|
768
768
|
|
|
769
769
|
await Promise.allSettled(promiseArray)
|
|
770
770
|
.then((values) => {
|
|
771
|
+
if (this.#babylonJSAnimationController) {
|
|
772
|
+
this.#babylonJSAnimationController.dispose();
|
|
773
|
+
this.#babylonJSAnimationController = null;
|
|
774
|
+
};
|
|
771
775
|
values.forEach((result) => {
|
|
772
776
|
const container = result.value ? result.value[0] : null;
|
|
773
777
|
const assetContainer = result.value ? result.value[1] : null;
|
|
@@ -775,10 +779,7 @@ export default class BabylonJSController {
|
|
|
775
779
|
if (container.state.name === "model") {
|
|
776
780
|
assetContainer.lights = [];
|
|
777
781
|
}
|
|
778
|
-
|
|
779
|
-
if (replaced && container.state.name === "model") {
|
|
780
|
-
this.#babylonJSAnimationController = new BabylonJSAnimationController(this.#scene);
|
|
781
|
-
}
|
|
782
|
+
this.#replaceContainer(container, assetContainer);
|
|
782
783
|
container.state.setSuccess(true);
|
|
783
784
|
} else {
|
|
784
785
|
if (container.assetContainer && container.state.mustBeShown !== container.state.isVisible && container.state.name === "materials") {
|
|
@@ -787,7 +788,7 @@ export default class BabylonJSController {
|
|
|
787
788
|
container.state.setSuccess(false);
|
|
788
789
|
}
|
|
789
790
|
});
|
|
790
|
-
|
|
791
|
+
|
|
791
792
|
this.#setOptions_Materials();
|
|
792
793
|
this.#setOptions_Camera();
|
|
793
794
|
this.#setVisibilityOfWallAndFloorInModel();
|
|
@@ -802,9 +803,9 @@ export default class BabylonJSController {
|
|
|
802
803
|
.finally(async () => {
|
|
803
804
|
this.#setMaxSimultaneousLights();
|
|
804
805
|
this.#initializeShadows();
|
|
806
|
+
this.#babylonJSAnimationController = new BabylonJSAnimationController(this.#scene);
|
|
805
807
|
this.#startRender();
|
|
806
808
|
});
|
|
807
|
-
|
|
808
809
|
return detail;
|
|
809
810
|
}
|
|
810
811
|
|