@preference-sl/pref-viewer 2.12.0-beta.1 → 2.12.0-beta.2
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
|
@@ -24,6 +24,7 @@ import BabylonJSAnimationController from "./babylonjs-animation-controller.js";
|
|
|
24
24
|
* - Provides methods for downloading models and scenes in GLB, glTF (ZIP), and USDZ formats.
|
|
25
25
|
* - Manages camera and material options, container visibility, and user interactions.
|
|
26
26
|
* - Observes canvas resize events and updates the engine accordingly.
|
|
27
|
+
* - Applies metadata-driven scene adjustments (e.g., inner floor translation) after asset reloads.
|
|
27
28
|
* - Designed for integration with PrefViewer and GLTFResolver.
|
|
28
29
|
* - All resource management and rendering operations are performed asynchronously for performance.
|
|
29
30
|
*
|
|
@@ -84,6 +85,9 @@ import BabylonJSAnimationController from "./babylonjs-animation-controller.js";
|
|
|
84
85
|
* - #startRender(): Starts the Babylon.js render loop.
|
|
85
86
|
* - #loadAssetContainer(container): Loads an asset container asynchronously.
|
|
86
87
|
* - #loadContainers(): Loads all asset containers and adds them to the scene.
|
|
88
|
+
* - #checkModelMetadata(oldMetadata, newMetadata): Processes metadata changes after loading.
|
|
89
|
+
* - #checkInnerFloorTranslation(oldMetadata, newMetadata): Applies inner floor Y translations from metadata.
|
|
90
|
+
* - #translateNodeY(name, deltaY): Adjusts the Y position of a scene node.
|
|
87
91
|
* - #addDateToName(name): Appends the current date/time to a name string.
|
|
88
92
|
* - #downloadZip(files, name, comment, addDateInName): Generates and downloads a ZIP file.
|
|
89
93
|
* - #openDownloadDialog(): Opens the modal download dialog.
|
|
@@ -319,9 +323,9 @@ export default class BabylonJSController {
|
|
|
319
323
|
* @returns {boolean}
|
|
320
324
|
*/
|
|
321
325
|
#initializeEnvironmentTexture() {
|
|
322
|
-
return false;
|
|
326
|
+
return false; // Environment texture disabled by the moment
|
|
323
327
|
if (this.#scene.environmentTexture) {
|
|
324
|
-
return;
|
|
328
|
+
return false;
|
|
325
329
|
}
|
|
326
330
|
const hdrTextureURI = "../src/environments/noon_grass.hdr";
|
|
327
331
|
const hdrTexture = new HDRCubeTexture(hdrTextureURI, this.#scene, 128);
|
|
@@ -329,6 +333,7 @@ export default class BabylonJSController {
|
|
|
329
333
|
hdrTexture._noMipmap = false;
|
|
330
334
|
hdrTexture.level = 2.0;
|
|
331
335
|
this.#scene.environmentTexture = hdrTexture;
|
|
336
|
+
return true;
|
|
332
337
|
}
|
|
333
338
|
|
|
334
339
|
/**
|
|
@@ -340,7 +345,7 @@ export default class BabylonJSController {
|
|
|
340
345
|
* @returns {void|false} Returns false if no environment texture is set; otherwise void.
|
|
341
346
|
*/
|
|
342
347
|
#initializeIBLShadows() {
|
|
343
|
-
if (!this.#scene.environmentTexture) {
|
|
348
|
+
if (!this.#scene.environmentTexture || !this.#scene.environmentTexture.isReady()) {
|
|
344
349
|
return false;
|
|
345
350
|
}
|
|
346
351
|
|
|
@@ -407,7 +412,7 @@ export default class BabylonJSController {
|
|
|
407
412
|
* Otherwise, sets up shadow casting and receiving for all relevant meshes using the shadow generator.
|
|
408
413
|
*/
|
|
409
414
|
#initializeShadows() {
|
|
410
|
-
if (
|
|
415
|
+
if (this.#scene.environmentTexture) {
|
|
411
416
|
this.#initializeIBLShadows();
|
|
412
417
|
return true;
|
|
413
418
|
}
|
|
@@ -417,7 +422,7 @@ export default class BabylonJSController {
|
|
|
417
422
|
return false;
|
|
418
423
|
}
|
|
419
424
|
mesh.receiveShadows = true;
|
|
420
|
-
if (
|
|
425
|
+
if (mesh.name !== "hdri") {
|
|
421
426
|
this.#shadowGen.addShadowCaster(mesh, true);
|
|
422
427
|
}
|
|
423
428
|
});
|
|
@@ -848,6 +853,8 @@ export default class BabylonJSController {
|
|
|
848
853
|
container.assetContainer = null;
|
|
849
854
|
}
|
|
850
855
|
this.#scene.getEngine().releaseEffects();
|
|
856
|
+
this.#scene.getEngine().releaseComputeEffects();
|
|
857
|
+
|
|
851
858
|
container.assetContainer = newAssetContainer;
|
|
852
859
|
return this.#addContainer(container, false);
|
|
853
860
|
}
|
|
@@ -914,7 +921,7 @@ export default class BabylonJSController {
|
|
|
914
921
|
return [container, false];
|
|
915
922
|
}
|
|
916
923
|
|
|
917
|
-
container.state.setPendingCacheData(sourceData.size, sourceData.timeStamp);
|
|
924
|
+
container.state.setPendingCacheData(sourceData.size, sourceData.timeStamp, sourceData.metadata);
|
|
918
925
|
|
|
919
926
|
// https://doc.babylonjs.com/typedoc/interfaces/BABYLON.LoadAssetContainerOptions
|
|
920
927
|
let options = {
|
|
@@ -943,6 +950,9 @@ export default class BabylonJSController {
|
|
|
943
950
|
async #loadContainers() {
|
|
944
951
|
this.#stopRender();
|
|
945
952
|
|
|
953
|
+
let oldModelMetadata = { ...(this.#containers.model?.state?.metadata ?? {}) };
|
|
954
|
+
let newModelMetadata = {};
|
|
955
|
+
|
|
946
956
|
const promiseArray = [];
|
|
947
957
|
Object.values(this.#containers).forEach((container) => {
|
|
948
958
|
promiseArray.push(this.#loadAssetContainer(container));
|
|
@@ -962,6 +972,7 @@ export default class BabylonJSController {
|
|
|
962
972
|
if (result.status === "fulfilled" && assetContainer) {
|
|
963
973
|
if (container.state.name === "model") {
|
|
964
974
|
assetContainer.lights = [];
|
|
975
|
+
newModelMetadata = { ...(container.state.update.metadata ?? {}) };
|
|
965
976
|
}
|
|
966
977
|
this.#replaceContainer(container, assetContainer);
|
|
967
978
|
container.state.setSuccess(true);
|
|
@@ -985,6 +996,7 @@ export default class BabylonJSController {
|
|
|
985
996
|
detail.error = error;
|
|
986
997
|
})
|
|
987
998
|
.finally(async () => {
|
|
999
|
+
this.#checkModelMetadata(oldModelMetadata, newModelMetadata);
|
|
988
1000
|
this.#setMaxSimultaneousLights();
|
|
989
1001
|
this.#initializeShadows();
|
|
990
1002
|
this.#babylonJSAnimationController = new BabylonJSAnimationController(this.#scene);
|
|
@@ -993,6 +1005,101 @@ export default class BabylonJSController {
|
|
|
993
1005
|
return detail;
|
|
994
1006
|
}
|
|
995
1007
|
|
|
1008
|
+
/**
|
|
1009
|
+
* Checks and applies model metadata changes after asset loading.
|
|
1010
|
+
* @private
|
|
1011
|
+
* @param {object} oldMetadata - The previous metadata object for the model.
|
|
1012
|
+
* @param {object} newMetadata - The new metadata object for the model.
|
|
1013
|
+
* @returns {void}
|
|
1014
|
+
* @description
|
|
1015
|
+
* Currently, it only checks for changes related to the inner floor translation by delegating to #checkInnerFloorTranslation.
|
|
1016
|
+
*/
|
|
1017
|
+
#checkModelMetadata(oldMetadata, newMetadata) {
|
|
1018
|
+
// For the moment only check inner floor translation
|
|
1019
|
+
this.#checkInnerFloorTranslation(oldMetadata, newMetadata);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Checks and applies Y-axis translation for the inner floor node based on metadata changes.
|
|
1024
|
+
* @private
|
|
1025
|
+
* @param {object} oldMetadata - The previous metadata object for the model.
|
|
1026
|
+
* @param {object} newMetadata - The new metadata object for the model.
|
|
1027
|
+
* @returns {void}
|
|
1028
|
+
*/
|
|
1029
|
+
#checkInnerFloorTranslation(oldMetadata, newMetadata) {
|
|
1030
|
+
let newDeltaY = newMetadata?.customProperties?.innerFloorValue ? parseFloat(newMetadata.customProperties.innerFloorValue) : 0;
|
|
1031
|
+
let oldDeltaY = oldMetadata?.customProperties?.innerFloorValue ? parseFloat(oldMetadata.customProperties.innerFloorValue) : 0;
|
|
1032
|
+
|
|
1033
|
+
if (newDeltaY === 0 && oldDeltaY === 0) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
if (!this.#containers.environment.assetContainer) {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
const getNodeName = (data) => {
|
|
1042
|
+
if (data && typeof data === "string" && data.includes("/")) {
|
|
1043
|
+
data = data.slice(data.lastIndexOf("/") + 1);
|
|
1044
|
+
return data;
|
|
1045
|
+
}
|
|
1046
|
+
return false;
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
let applyNewTranslation = false;
|
|
1050
|
+
let applyOldTranslation = false;
|
|
1051
|
+
let undoOldTranslation = false;
|
|
1052
|
+
const newTranslationNodeName = getNodeName(newMetadata?.customProperties?.innerFloorPath);
|
|
1053
|
+
const oldTranslationNodeName = getNodeName(oldMetadata?.customProperties?.innerFloorPath);
|
|
1054
|
+
|
|
1055
|
+
if (this.#containers.environment.state.isSuccess) {
|
|
1056
|
+
// If environment is being reloaded:
|
|
1057
|
+
if (this.#containers.model.state.isSuccess) {
|
|
1058
|
+
// If model is also being reloaded, apply only new translation
|
|
1059
|
+
applyNewTranslation = newDeltaY !== 0 && newTranslationNodeName;
|
|
1060
|
+
} else {
|
|
1061
|
+
// If model is not being reloaded, apply old translation
|
|
1062
|
+
applyOldTranslation = oldDeltaY !== 0 && oldTranslationNodeName;
|
|
1063
|
+
}
|
|
1064
|
+
} else {
|
|
1065
|
+
// If environment is not being reloaded:
|
|
1066
|
+
if (this.#containers.model.state.isSuccess) {
|
|
1067
|
+
// If environment is not being reload but model is being reloaded, undo old trasnslation and apply new translation
|
|
1068
|
+
undoOldTranslation = oldDeltaY !== 0 && oldTranslationNodeName;
|
|
1069
|
+
applyNewTranslation = newDeltaY !== 0 && newTranslationNodeName;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
if (undoOldTranslation) {
|
|
1074
|
+
this.#translateNodeY(oldTranslationNodeName, -oldDeltaY);
|
|
1075
|
+
}
|
|
1076
|
+
if (applyOldTranslation) {
|
|
1077
|
+
this.#translateNodeY(oldTranslationNodeName, oldDeltaY);
|
|
1078
|
+
}
|
|
1079
|
+
if (applyNewTranslation) {
|
|
1080
|
+
this.#translateNodeY(newTranslationNodeName, newDeltaY);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* Translates a node along the scene's vertical (Y) axis by the provided value.
|
|
1086
|
+
* @private
|
|
1087
|
+
* @param {string} name - The node name to find in the scene.
|
|
1088
|
+
* @param {number} deltaY - The Y-axis translation amount (positive or negative).
|
|
1089
|
+
* @returns {boolean} True if the node was found and translated, false otherwise.
|
|
1090
|
+
*/
|
|
1091
|
+
#translateNodeY(name, deltaY) {
|
|
1092
|
+
if (!this.#scene) {
|
|
1093
|
+
return false;
|
|
1094
|
+
}
|
|
1095
|
+
const node = this.#scene.getNodeByName(name);
|
|
1096
|
+
if (!node || !node.position) {
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
node.position.y += deltaY;
|
|
1100
|
+
return true;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
996
1103
|
/**
|
|
997
1104
|
* Appends the current date and time to the provided name string in the format: name_YYYY-MM-DD_HH.mm.ss
|
|
998
1105
|
* @private
|
package/src/gltf-resolver.js
CHANGED
|
@@ -220,6 +220,7 @@ export default class GLTFResolver {
|
|
|
220
220
|
let source = storage.url || null;
|
|
221
221
|
let newSize, newTimeStamp;
|
|
222
222
|
let pending = false;
|
|
223
|
+
let metadata = {};
|
|
223
224
|
|
|
224
225
|
if (storage.db && storage.table && storage.id) {
|
|
225
226
|
await this.#initializeStorage(storage.db, storage.table);
|
|
@@ -228,6 +229,7 @@ export default class GLTFResolver {
|
|
|
228
229
|
return false;
|
|
229
230
|
}
|
|
230
231
|
source = object.data;
|
|
232
|
+
metadata = { ...(object.metadata ?? {}) };
|
|
231
233
|
if (object.timeStamp === currentTimeStamp) {
|
|
232
234
|
return false;
|
|
233
235
|
} else {
|
|
@@ -283,6 +285,6 @@ export default class GLTFResolver {
|
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
|
-
return { source: file || source, size: newSize, timeStamp: newTimeStamp, extension: extension };
|
|
288
|
+
return { source: file || source, size: newSize, timeStamp: newTimeStamp, extension: extension, metadata: metadata, };
|
|
287
289
|
}
|
|
288
290
|
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export class ContainerData {
|
|
15
15
|
constructor(name = "") {
|
|
16
|
+
this.metadata = {};
|
|
16
17
|
this.name = name;
|
|
17
18
|
this.show = true;
|
|
18
19
|
this.size = 0;
|
|
@@ -23,6 +24,7 @@ export class ContainerData {
|
|
|
23
24
|
}
|
|
24
25
|
reset() {
|
|
25
26
|
this.update = {
|
|
27
|
+
metadata: {},
|
|
26
28
|
pending: false,
|
|
27
29
|
storage: null,
|
|
28
30
|
success: false,
|
|
@@ -37,6 +39,7 @@ export class ContainerData {
|
|
|
37
39
|
this.show = this.update.show !== null ? this.update.show : this.show;
|
|
38
40
|
this.size = this.update.size;
|
|
39
41
|
this.timeStamp = this.update.timeStamp;
|
|
42
|
+
this.metadata = { ...(this.update.metadata ?? {}) };
|
|
40
43
|
} else {
|
|
41
44
|
this.update.success = false;
|
|
42
45
|
}
|
|
@@ -48,9 +51,10 @@ export class ContainerData {
|
|
|
48
51
|
this.update.success = false;
|
|
49
52
|
this.update.show = show !== undefined ? show : this.update.show !== null ? this.update.show : this.show;
|
|
50
53
|
}
|
|
51
|
-
setPendingCacheData(size = 0, timeStamp = null) {
|
|
54
|
+
setPendingCacheData(size = 0, timeStamp = null, metadata = {}) {
|
|
52
55
|
this.update.size = size;
|
|
53
56
|
this.update.timeStamp = timeStamp;
|
|
57
|
+
this.update.metadata = { ...(metadata ?? {}) };
|
|
54
58
|
}
|
|
55
59
|
get isPending() {
|
|
56
60
|
return this.update.pending === true;
|