@combeenation/3d-viewer 6.5.0 → 7.0.0-beta2

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.
Files changed (118) hide show
  1. package/README.md +111 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
  6. package/dist/lib-cjs/api/classes/element.d.ts +153 -149
  7. package/dist/lib-cjs/api/classes/element.js +670 -669
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/event.d.ts +396 -342
  10. package/dist/lib-cjs/api/classes/event.js +419 -365
  11. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  13. package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
  14. package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -0
  15. package/dist/lib-cjs/api/classes/fuzzyMap.js +22 -0
  16. package/dist/lib-cjs/api/classes/fuzzyMap.js.map +1 -0
  17. package/dist/lib-cjs/api/classes/parameter.d.ts +351 -339
  18. package/dist/lib-cjs/api/classes/parameter.js +517 -464
  19. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  20. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  21. package/dist/lib-cjs/api/classes/parameterObservable.js +72 -97
  22. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  23. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  24. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  25. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  26. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  27. package/dist/lib-cjs/api/classes/variant.d.ts +253 -234
  28. package/dist/lib-cjs/api/classes/variant.js +843 -818
  29. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -44
  31. package/dist/lib-cjs/api/classes/variantInstance.js +125 -105
  32. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  34. package/dist/lib-cjs/api/classes/variantParameterizable.js +88 -88
  35. package/dist/lib-cjs/api/classes/viewer.d.ts +199 -185
  36. package/dist/lib-cjs/api/classes/viewer.js +670 -619
  37. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  38. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  39. package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
  40. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  41. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  42. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  43. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
  44. package/dist/lib-cjs/api/internal/sceneSetup.js +226 -226
  45. package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
  46. package/dist/lib-cjs/api/manager/animationManager.js +126 -126
  47. package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +78 -78
  49. package/dist/lib-cjs/api/manager/gltfExportManager.js +241 -241
  50. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
  51. package/dist/lib-cjs/api/manager/sceneManager.js +130 -130
  52. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  53. package/dist/lib-cjs/api/manager/tagManager.d.ts +108 -0
  54. package/dist/lib-cjs/api/manager/tagManager.js +420 -0
  55. package/dist/lib-cjs/api/manager/tagManager.js.map +1 -0
  56. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
  57. package/dist/lib-cjs/api/manager/textureLoadManager.js +97 -97
  58. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +102 -92
  59. package/dist/lib-cjs/api/manager/variantInstanceManager.js +284 -260
  60. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
  61. package/dist/lib-cjs/api/store/specStorage.d.ts +32 -24
  62. package/dist/lib-cjs/api/store/specStorage.js +65 -50
  63. package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
  64. package/dist/lib-cjs/api/util/babylonHelper.d.ts +235 -206
  65. package/dist/lib-cjs/api/util/babylonHelper.js +745 -668
  66. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  67. package/dist/lib-cjs/api/util/globalTypes.d.ts +432 -387
  68. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  69. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  70. package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
  71. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +44 -43
  72. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +173 -155
  73. package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +1 -1
  74. package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
  75. package/dist/lib-cjs/api/util/stringHelper.js +32 -32
  76. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  77. package/dist/lib-cjs/api/util/structureHelper.js +48 -48
  78. package/dist/lib-cjs/buildinfo.json +3 -3
  79. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  80. package/dist/lib-cjs/index.d.ts +53 -52
  81. package/dist/lib-cjs/index.js +114 -112
  82. package/dist/lib-cjs/index.js.map +1 -1
  83. package/package.json +81 -81
  84. package/src/api/classes/animationInterface.ts +10 -10
  85. package/src/api/classes/dottedPath.ts +181 -181
  86. package/src/api/classes/element.ts +731 -717
  87. package/src/api/classes/event.ts +452 -385
  88. package/src/api/classes/eventBroadcaster.ts +52 -52
  89. package/src/api/classes/fuzzyMap.ts +21 -0
  90. package/src/api/classes/parameter.ts +554 -497
  91. package/src/api/classes/parameterObservable.ts +73 -100
  92. package/src/api/classes/parameterizable.ts +87 -87
  93. package/src/api/classes/placementAnimation.ts +162 -162
  94. package/src/api/classes/variant.ts +933 -884
  95. package/src/api/classes/variantInstance.ts +123 -97
  96. package/src/api/classes/variantParameterizable.ts +85 -85
  97. package/src/api/classes/viewer.ts +743 -691
  98. package/src/api/classes/viewerLight.ts +339 -339
  99. package/src/api/internal/debugViewer.ts +90 -90
  100. package/src/api/internal/lensRendering.ts +9 -9
  101. package/src/api/internal/sceneSetup.ts +205 -205
  102. package/src/api/manager/animationManager.ts +143 -143
  103. package/src/api/manager/gltfExportManager.ts +236 -236
  104. package/src/api/manager/sceneManager.ts +136 -132
  105. package/src/api/manager/tagManager.ts +451 -0
  106. package/src/api/manager/textureLoadManager.ts +95 -95
  107. package/src/api/manager/variantInstanceManager.ts +297 -265
  108. package/src/api/store/specStorage.ts +68 -51
  109. package/src/api/util/babylonHelper.ts +817 -739
  110. package/src/api/util/globalTypes.ts +499 -437
  111. package/src/api/util/resourceHelper.ts +191 -191
  112. package/src/api/util/sceneLoaderHelper.ts +170 -151
  113. package/src/api/util/stringHelper.ts +30 -30
  114. package/src/api/util/structureHelper.ts +49 -49
  115. package/src/buildinfo.json +3 -3
  116. package/src/dev.ts +62 -60
  117. package/src/index.ts +100 -98
  118. package/src/types.d.ts +35 -28
@@ -1,669 +1,746 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.envHelperMetadataName = exports.backgroundDomeName = exports.changeEnvironment = exports.getClientRectFromMesh = exports.removeFromShadowGenerator = exports.addToShadowGenerator = exports.setReceiveShadows = exports.removeFromHighlightLayer = exports.addToHighlightLayer = exports.setMaterialRoughness = exports.setMaterialMetallness = exports.setMaterialTexture = exports.setMaterialColor = exports.setSourceNodeMaterial = exports.setMaterial = exports.transformTransformNode = exports.disableNodeWithParents = exports.enableNodeWithParents = exports.deactivateTransformNode = exports.activateTransformNode = exports.assertTransformNode = exports.injectNodeMetadata = exports.applyMaterialAfterTexturesLoaded = exports.getOrCreateMaterial = exports.cloneTransformNodeMaterial = exports.cloneNodeWithParents = exports.cloneTransformNode = exports.getDottedPathForNode = exports.mapToDottedNodes = exports.isTextureWithOnLoadObservable = exports.getRootNode = void 0;
13
- const dottedPath_1 = require("../classes/dottedPath");
14
- const sceneSetup_1 = require("../internal/sceneSetup");
15
- const sceneLoaderHelper_1 = require("./sceneLoaderHelper");
16
- const photoDome_1 = require("@babylonjs/core/Helpers/photoDome");
17
- const light_1 = require("@babylonjs/core/Lights/light");
18
- const baseTexture_1 = require("@babylonjs/core/Materials/Textures/baseTexture");
19
- const cubeTexture_1 = require("@babylonjs/core/Materials/Textures/cubeTexture");
20
- const math_axis_1 = require("@babylonjs/core/Maths/math.axis");
21
- const math_color_1 = require("@babylonjs/core/Maths/math.color");
22
- const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
23
- const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
24
- const instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
25
- const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
26
- const tools_1 = require("@babylonjs/core/Misc/tools");
27
- const lodash_es_1 = require("lodash-es");
28
- const backgroundDomeName = 'BackgroundDome_ViewerGenerated';
29
- exports.backgroundDomeName = backgroundDomeName;
30
- const envHelperMetadataName = 'viewerEnvHelper';
31
- exports.envHelperMetadataName = envHelperMetadataName;
32
- const materialWaitingToBeSetMetadataName = 'materialWaitingToBeSet';
33
- /**
34
- * @param node
35
- * @return Node
36
- */
37
- const getRootNode = function (node) {
38
- let _node = node;
39
- while (_node.parent) {
40
- _node = _node.parent;
41
- }
42
- return _node;
43
- };
44
- exports.getRootNode = getRootNode;
45
- /**
46
- * @param nodes
47
- * @param predicate
48
- * @return Map<DottedPath, T>
49
- */
50
- const mapToDottedNodes = function (nodes, predicate) {
51
- const map = new Map();
52
- const addNodes = function (_node) {
53
- if (predicate && predicate(_node)) {
54
- map.set(_node.metadata.dottedPath, _node);
55
- }
56
- _node.getChildren().forEach(child => {
57
- addNodes(child);
58
- });
59
- };
60
- nodes.forEach(node => {
61
- addNodes(node);
62
- });
63
- return map;
64
- };
65
- exports.mapToDottedNodes = mapToDottedNodes;
66
- /**
67
- * @param node
68
- * @return DottedPath
69
- */
70
- const getDottedPathForNode = function (node) {
71
- const dottedPath = dottedPath_1.DottedPath.create(node.name);
72
- let _parent = node;
73
- while (_parent.parent) {
74
- _parent = _parent.parent;
75
- dottedPath.unshiftPart(_parent.name);
76
- }
77
- return dottedPath;
78
- };
79
- exports.getDottedPathForNode = getDottedPathForNode;
80
- /**
81
- * @param node
82
- * @param predicate
83
- * @param deep
84
- * @return TransformNode | null
85
- */
86
- const cloneTransformNode = function (node, predicate, deep = true) {
87
- if (predicate && !predicate(node)) {
88
- return null;
89
- }
90
- const clone = node.clone(node.name, node.parent, true);
91
- if (clone) {
92
- clone.metadata = (0, lodash_es_1.cloneDeep)(node.metadata);
93
- // if the cloned node is of type InstancedMesh, due to a bug(?),
94
- // the InstancedMesh.isEnabled state may have changed after cloning.
95
- // in that case, set the clone's enabled state to the original's state
96
- if (node.constructor.name === 'InstancedMesh') {
97
- clone.setEnabled(node.isEnabled(false));
98
- }
99
- }
100
- if (deep) {
101
- const children = node.getChildTransformNodes(true);
102
- children.forEach(child => {
103
- const clonedChild = cloneTransformNode(child, predicate, deep);
104
- if (clonedChild) {
105
- clonedChild.parent = clone;
106
- }
107
- });
108
- }
109
- return clone;
110
- };
111
- exports.cloneTransformNode = cloneTransformNode;
112
- /**
113
- * @param node
114
- */
115
- const cloneNodeWithParents = function (node) {
116
- let clone = null;
117
- if (node instanceof transformNode_1.TransformNode) {
118
- clone = node.clone(node.name, cloneNodeWithParents(node.parent), true);
119
- }
120
- else if (node instanceof light_1.Light) {
121
- clone = node.clone(node.name, cloneNodeWithParents(node.parent));
122
- }
123
- else if (node) {
124
- throw new Error(`Cloning of "${node === null || node === void 0 ? void 0 : node.constructor.name}" is not implemented (yet).`);
125
- }
126
- return clone;
127
- };
128
- exports.cloneNodeWithParents = cloneNodeWithParents;
129
- /**
130
- * @param node
131
- * @param deep
132
- * @param prefix
133
- * @return TransformNode
134
- */
135
- const cloneTransformNodeMaterial = function (node, prefix = '', deep = true) {
136
- if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
137
- const newMatName = dottedPath_1.DottedPath.create(prefix).addParts([node.material.name, 'clone', node.uniqueId.toString()]);
138
- node.material = node.material.clone(newMatName.path);
139
- }
140
- if (deep) {
141
- const children = node.getChildTransformNodes(true);
142
- children.forEach(child => cloneTransformNodeMaterial(child, prefix, deep));
143
- }
144
- return node;
145
- };
146
- exports.cloneTransformNodeMaterial = cloneTransformNodeMaterial;
147
- /**
148
- * @param node
149
- * @param deep
150
- * @param metadata
151
- */
152
- const injectNodeMetadata = function (node, metadata, deep = true) {
153
- node.metadata = (0, lodash_es_1.merge)({}, node.metadata, metadata);
154
- if (deep && node instanceof transformNode_1.TransformNode) {
155
- const children = node.getChildTransformNodes(true);
156
- children.forEach(child => injectNodeMetadata(child, metadata, deep));
157
- }
158
- };
159
- exports.injectNodeMetadata = injectNodeMetadata;
160
- /**
161
- * @param node
162
- * @param assertCallable
163
- * @param callableParameters
164
- * @param deep
165
- */
166
- const assertTransformNode = function (node, assertCallable, callableParameters = [], deep = true) {
167
- assertCallable(node, ...callableParameters);
168
- if (deep) {
169
- const children = node.getChildTransformNodes(true);
170
- children.forEach(child => assertTransformNode(child, assertCallable, callableParameters, deep));
171
- }
172
- };
173
- exports.assertTransformNode = assertTransformNode;
174
- /**
175
- * @param node
176
- * @param deep
177
- */
178
- const activateTransformNode = function (node, deep = true) {
179
- node.setEnabled(true);
180
- /*
181
- if( node instanceof AbstractMesh ) {
182
- node.visibility = 1;
183
- node.isPickable = true;
184
- }
185
- */
186
- if (deep) {
187
- node.getChildTransformNodes(true).forEach(child => activateTransformNode(child, deep));
188
- }
189
- };
190
- exports.activateTransformNode = activateTransformNode;
191
- /**
192
- * @param node
193
- * @param deep
194
- */
195
- const deactivateTransformNode = function (node, deep = true) {
196
- node.setEnabled(false);
197
- /*
198
- if( node instanceof AbstractMesh ) {
199
- node.visibility = 0;
200
- node.isPickable = false;
201
- }
202
- */
203
- if (deep) {
204
- node.getChildTransformNodes(true).forEach(child => deactivateTransformNode(child, deep));
205
- }
206
- };
207
- exports.deactivateTransformNode = deactivateTransformNode;
208
- /**
209
- * @param node
210
- */
211
- const enableNodeWithParents = function (node) {
212
- node.setEnabled(true);
213
- if (node.parent) {
214
- enableNodeWithParents(node.parent);
215
- }
216
- };
217
- exports.enableNodeWithParents = enableNodeWithParents;
218
- /**
219
- * @param node
220
- */
221
- const disableNodeWithParents = function (node) {
222
- node.setEnabled(false);
223
- if (node.parent) {
224
- disableNodeWithParents(node.parent);
225
- }
226
- };
227
- exports.disableNodeWithParents = disableNodeWithParents;
228
- /**
229
- * Applies a {@link TransformationDefinition} consecutively to ensure dependencies in positioning etc.
230
- * @param node
231
- * @param transformation
232
- */
233
- const transformTransformNode = function (node, transformation) {
234
- // scaling
235
- if (!(0, lodash_es_1.has)(node.metadata, 'scaling.initial')) {
236
- injectNodeMetadata(node, { 'scaling.initial': node.scaling }, false);
237
- }
238
- const initialScaling = (0, lodash_es_1.get)(node.metadata, 'scaling.initial');
239
- node.scaling = initialScaling.multiply(transformation.scaling);
240
- // position
241
- if (!(0, lodash_es_1.has)(node.metadata, 'position.initial')) {
242
- injectNodeMetadata(node, { 'position.initial': node.absolutePosition.clone() }, false);
243
- }
244
- const initialPosition = (0, lodash_es_1.get)(node.metadata, 'position.initial');
245
- node.setAbsolutePosition(initialPosition.add(transformation.position).multiply(transformation.scaling));
246
- // rotation
247
- if (!(0, lodash_es_1.has)(node.metadata, 'rotation.initial')) {
248
- let rotationQuaternion = node.rotationQuaternion;
249
- if (!rotationQuaternion) {
250
- rotationQuaternion = math_vector_1.Quaternion.RotationYawPitchRoll(node.rotation.x, node.rotation.y, node.rotation.z);
251
- }
252
- injectNodeMetadata(node, { 'rotation.initial': rotationQuaternion.asArray() }, false);
253
- }
254
- const initialRotationQuaternion = math_vector_1.Quaternion.FromArray((0, lodash_es_1.get)(node.metadata, 'rotation.initial'));
255
- node.rotationQuaternion = initialRotationQuaternion;
256
- node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.X, transformation.rotation.x);
257
- node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.Y, transformation.rotation.y);
258
- node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.Z, transformation.rotation.z);
259
- node.computeWorldMatrix(true);
260
- };
261
- exports.transformTransformNode = transformTransformNode;
262
- /**
263
- * Apply changes of environment (background texture, etc.) consecutively in order to avoid dependency related issues.
264
- * @param scene
265
- * @param envDef
266
- */
267
- const changeEnvironment = function (scene, envDef) {
268
- var _a;
269
- // issue warning if both background texture and usedefault are set
270
- if (envDef.environmentUseDefault && envDef.environmentBackground) {
271
- console.warn(`!!! Warning !!! Spec parameter 'environment.usedefault' is being overruled by 'environment.background'.`);
272
- }
273
- const useDefaultEnv = envDef.environmentUseDefault && !envDef.environmentBackground;
274
- // 1) set ENVIRONMENT_COLOR
275
- const clearColorBefore = scene.clearColor.toString();
276
- scene.clearColor = envDef.environmentColor
277
- ? math_color_1.Color4.FromColor3(envDef.environmentColor)
278
- : useDefaultEnv
279
- ? sceneSetup_1.defaultEnvHelperColor
280
- : sceneSetup_1.defaultSceneClearColor;
281
- const clearColorChanged = clearColorBefore !== scene.clearColor.toString();
282
- // 2) dispose existing & set new ENVIRONMENT (==texture)
283
- const curEnvTexture = scene.environmentTexture;
284
- const envTextureChanged = envDef.environment !== (curEnvTexture === null || curEnvTexture === void 0 ? void 0 : curEnvTexture.url);
285
- if (curEnvTexture && (!envDef.environment || envTextureChanged)) {
286
- curEnvTexture.dispose();
287
- }
288
- const rotation = envDef.environmentRotation !== undefined ? tools_1.Tools.ToRadians(envDef.environmentRotation) : 0;
289
- if (envDef.environment && envTextureChanged) {
290
- const envTexture = cubeTexture_1.CubeTexture.CreateFromPrefilteredData(envDef.environment, scene);
291
- envTexture.rotationY = rotation;
292
- scene.environmentTexture = envTexture;
293
- }
294
- else if (curEnvTexture && curEnvTexture.rotationY !== rotation) {
295
- curEnvTexture.rotationY = rotation;
296
- }
297
- // 3) dispose existing & set new ENVIRONMENT_BACKGROUND
298
- const curDome = scene.getNodeByName(backgroundDomeName);
299
- const backgroundUrlChanged = envDef.environmentBackground !== (curDome === null || curDome === void 0 ? void 0 : curDome.texture.url);
300
- if (curDome && (!envDef.environmentBackground || backgroundUrlChanged)) {
301
- curDome.dispose();
302
- }
303
- const rotationPhotoDome = -1 * rotation;
304
- if (envDef.environmentBackground && backgroundUrlChanged) {
305
- const textureUrl = envDef.environmentBackground;
306
- const dome = new photoDome_1.PhotoDome(backgroundDomeName, textureUrl, { resolution: 32, size: 450 }, scene);
307
- // Rotate submesh to get them in line with environment texture
308
- dome.getChildMeshes(true)[0].rotation.y = tools_1.Tools.ToRadians(90);
309
- dome.rotation.y = rotationPhotoDome;
310
- }
311
- else if (curDome && curDome.rotation.y !== rotationPhotoDome) {
312
- curDome.rotation.y = rotationPhotoDome;
313
- }
314
- // 4) dispose existing & set new ENVIRONMENT_USEDEFAULT (only if no background is set)
315
- const curEnvHelper = (_a = scene.metadata) === null || _a === void 0 ? void 0 : _a[envHelperMetadataName];
316
- if (curEnvHelper && !useDefaultEnv) {
317
- curEnvHelper.dispose();
318
- delete scene.metadata[envHelperMetadataName];
319
- }
320
- const envHelperMainColor = math_color_1.Color3.FromArray(scene.clearColor.asArray());
321
- if (useDefaultEnv && !curEnvHelper) {
322
- const envHelper = scene.createDefaultEnvironment({ sizeAuto: true });
323
- envHelper === null || envHelper === void 0 ? void 0 : envHelper.setMainColor(envHelperMainColor);
324
- if (envHelper) {
325
- scene.metadata = (0, lodash_es_1.merge)({}, scene.metadata, { [envHelperMetadataName]: envHelper });
326
- }
327
- }
328
- else if (curEnvHelper && useDefaultEnv && clearColorChanged) {
329
- curEnvHelper.setMainColor(envHelperMainColor);
330
- }
331
- // 5) set ENVIRONMENT_INTENSITY
332
- if (envDef.environmentIntensity !== undefined) {
333
- scene.environmentIntensity = envDef.environmentIntensity;
334
- }
335
- };
336
- exports.changeEnvironment = changeEnvironment;
337
- /**
338
- * Sets a material by a given material id as material property on the given node.
339
- *
340
- * If the material is not already available in the scene, the viewer tries to create a material based on a Combeenation
341
- * [material asset](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset).
342
- * This of course only works if the viewer is used inside a Combeenation configurator.
343
- *
344
- * Furthermore this function also defers the material creation if the node is not visible yet to improve network &
345
- * viewer bootstrap performance as textures are automatically being lazy loaded only when they are actually visible in
346
- * the scene.
347
- *
348
- * Finally the material will not be applied before all its textures have been loaded. In this way "flickering" effects
349
- * will be avoided, since the material would be incomplete without its loaded textures.
350
- */
351
- const setMaterial = function (scene, node, materialId, deep = true, variant) {
352
- if (node instanceof abstractMesh_1.AbstractMesh) {
353
- const materialExists = scene.getMaterialById(materialId);
354
- const hasMissingMaterial = (0, lodash_es_1.has)(node.metadata, sceneLoaderHelper_1.missingMaterialMetadataName);
355
- const deferMaterialCreation = !materialExists && !node.isEnabled();
356
- if (deferMaterialCreation) {
357
- // do not set the material
358
- injectNodeMetadata(node, { [sceneLoaderHelper_1.missingMaterialMetadataName]: materialId }, false);
359
- // if it already had the missing material flag before, there already exists an observer...
360
- if (!hasMissingMaterial) {
361
- (0, sceneLoaderHelper_1.addMissingMaterialObserver)(node);
362
- }
363
- }
364
- else {
365
- // create material an apply it when textures have been loaded
366
- const material = getOrCreateMaterial(scene, materialId, variant);
367
- applyMaterialAfterTexturesLoaded(material, node);
368
- if (hasMissingMaterial) {
369
- delete node.metadata[sceneLoaderHelper_1.missingMaterialMetadataName];
370
- }
371
- }
372
- }
373
- // recursively set materials on children (if desired)
374
- if (deep) {
375
- for (const child of node.getChildTransformNodes(true)) {
376
- setMaterial(scene, child, materialId, deep, variant);
377
- }
378
- }
379
- };
380
- exports.setMaterial = setMaterial;
381
- /**
382
- * Gets the Material either from the given {@link Variant}, the given scene or tries to create it from an Combeenation
383
- * material asset when inside a Combeenation configurator.
384
- */
385
- const getOrCreateMaterial = function (scene, materialId, variant) {
386
- let chosenMaterial;
387
- chosenMaterial = variant === null || variant === void 0 ? void 0 : variant.inheritedMaterials.find(mat => mat.id === materialId);
388
- chosenMaterial = chosenMaterial || scene.materials.find(mat => mat.id === materialId);
389
- chosenMaterial = chosenMaterial || (0, sceneLoaderHelper_1.createMaterialFromCbnAssets)(materialId, scene);
390
- if (chosenMaterial) {
391
- return chosenMaterial;
392
- }
393
- // reject when material was not found
394
- let rejectMessage = `Material with id "${materialId}" does not exist on scene.`;
395
- if (variant) {
396
- rejectMessage = `Material with id "${materialId}" does not exist for variant "${variant.id}".`;
397
- }
398
- throw new Error(rejectMessage);
399
- };
400
- exports.getOrCreateMaterial = getOrCreateMaterial;
401
- /**
402
- * Waits until the materials textures are loaded and sets the material on the node if there is no newer "set material"
403
- * request
404
- */
405
- const applyMaterialAfterTexturesLoaded = function (material, node) {
406
- return __awaiter(this, void 0, void 0, function* () {
407
- // set current material id as last valid id, in this case all previously set materials on the node will be invalidated
408
- injectNodeMetadata(node, { [materialWaitingToBeSetMetadataName]: material.id }, false);
409
- const promTexturesReady = new Promise(resolve => baseTexture_1.BaseTexture.WhenAllReady(material.getActiveTextures(), resolve));
410
- // this promise should only take some time on the first call of the corresponding shader (eg: PBRMaterial shader)
411
- // on each other call of the same material/shader type there should be not be a waiting time, or at maximum one frame
412
- // https://forum.babylonjs.com/t/mesh-flickering-when-setting-material-initially/37312
413
- const promMaterialCompiled = material.forceCompilationAsync(node);
414
- // material needs to fulfill 2 criterias before it's ready to use
415
- // - textures need to be "ready" => downloaded
416
- // - dedicated shader needs to be compiled
417
- // if this would not be the case you can see some "flickering" when setting the material
418
- yield Promise.all([promTexturesReady, promMaterialCompiled]);
419
- // textures ready, now check if the material is still up-to-date
420
- if (material.id === node.metadata[materialWaitingToBeSetMetadataName]) {
421
- node.material = material;
422
- delete node.metadata[materialWaitingToBeSetMetadataName];
423
- }
424
- });
425
- };
426
- exports.applyMaterialAfterTexturesLoaded = applyMaterialAfterTexturesLoaded;
427
- /**
428
- * !!! Warning !!!
429
- * This function is not public API. Whilst it can help solving certain problems, it only works reliably in well defined
430
- * situations and can cause unwanted side effects under some conditions. Use carefully at your own risk!
431
- *
432
- * See https://combeenation.myjetbrains.com/youtrack/issue/CB-5906 for further details regarding this warning.
433
- *
434
- * Set material of an instanced meshes source mesh.
435
- * Changes the material of all instanced meshes which have the same source mesh.
436
- *
437
- * @param node
438
- * @param material
439
- * @param deep
440
- *
441
- * @ignore
442
- */
443
- const setSourceNodeMaterial = function (node, material, deep = true) {
444
- const warn = ` You're using "setSourceNodeMaterial" which is not public API.
445
- Whilst it can help solving certain problems, it only works reliably in well defined situations and can cause unwanted side effects under some conditions.
446
- Use carefully at your own risk!`;
447
- console.warn(`!!! Warning !!!\n${warn}`);
448
- if (node instanceof instancedMesh_1.InstancedMesh) {
449
- node.sourceMesh.material = material;
450
- }
451
- if (deep) {
452
- node.getChildTransformNodes(true).forEach(child => setSourceNodeMaterial(child, material, deep));
453
- }
454
- };
455
- exports.setSourceNodeMaterial = setSourceNodeMaterial;
456
- /**
457
- * @param node
458
- * @param color
459
- * @param deep
460
- */
461
- const setMaterialColor = function (node, color, deep = true) {
462
- if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
463
- const materialCls = node.material.getClassName();
464
- switch (materialCls) {
465
- case 'PBRMaterial':
466
- node.material.albedoColor = color.toLinearSpace();
467
- break;
468
- case 'StandardMaterial':
469
- node.material.diffuseColor = color;
470
- break;
471
- default:
472
- throw new Error(`Setting color for material of instance "${materialCls}" not implemented (yet).`);
473
- }
474
- }
475
- if (deep) {
476
- node.getChildTransformNodes(true).forEach(child => setMaterialColor(child, color, deep));
477
- }
478
- };
479
- exports.setMaterialColor = setMaterialColor;
480
- /**
481
- * @param node
482
- * @param texture
483
- * @param deep
484
- */
485
- const setMaterialTexture = function (node, texture, deep = true) {
486
- if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
487
- const materialCls = node.material.getClassName();
488
- switch (materialCls) {
489
- case 'PBRMaterial':
490
- node.material.albedoTexture = texture;
491
- break;
492
- case 'StandardMaterial':
493
- node.material.diffuseTexture = texture;
494
- break;
495
- default:
496
- throw new Error(`Setting texture for material of instance "${materialCls}" not implemented (yet).`);
497
- }
498
- }
499
- if (deep) {
500
- node.getChildTransformNodes(true).forEach(child => setMaterialTexture(child, texture, deep));
501
- }
502
- };
503
- exports.setMaterialTexture = setMaterialTexture;
504
- /**
505
- * @param node
506
- * @param metallness
507
- * @param deep
508
- */
509
- const setMaterialMetallness = function (node, metallness, deep = true) {
510
- if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
511
- const materialCls = node.material.getClassName();
512
- switch (materialCls) {
513
- case 'PBRMaterial':
514
- node.material.metallic = metallness;
515
- break;
516
- default:
517
- throw new Error(`Setting metallness for material of instance "${materialCls}" not implemented (yet).`);
518
- }
519
- }
520
- if (deep) {
521
- node.getChildTransformNodes(true).forEach(child => setMaterialMetallness(child, metallness, deep));
522
- }
523
- };
524
- exports.setMaterialMetallness = setMaterialMetallness;
525
- /**
526
- * @param node
527
- * @param roughness
528
- * @param deep
529
- */
530
- const setMaterialRoughness = function (node, roughness, deep = true) {
531
- if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
532
- const materialCls = node.material.getClassName();
533
- switch (materialCls) {
534
- case 'PBRMaterial':
535
- node.material.roughness = roughness;
536
- break;
537
- case 'StandardMaterial':
538
- node.material.roughness = roughness;
539
- break;
540
- default:
541
- throw new Error(`Setting roughness for material of instance "${materialCls}" not implemented (yet).`);
542
- }
543
- }
544
- if (deep) {
545
- node.getChildTransformNodes(true).forEach(child => setMaterialRoughness(child, roughness, deep));
546
- }
547
- };
548
- exports.setMaterialRoughness = setMaterialRoughness;
549
- /**
550
- * @param node
551
- * @param layer
552
- * @param color
553
- * @param deep
554
- */
555
- const addToHighlightLayer = function (layer, color, node, deep = true) {
556
- if (node instanceof abstractMesh_1.AbstractMesh) {
557
- layer.addMesh(node, color);
558
- }
559
- if (deep) {
560
- node.getChildTransformNodes(true).forEach(child => addToHighlightLayer(layer, color, child, deep));
561
- }
562
- };
563
- exports.addToHighlightLayer = addToHighlightLayer;
564
- /**
565
- * @param node
566
- * @param layer
567
- * @param deep
568
- */
569
- const removeFromHighlightLayer = function (layer, node, deep = true) {
570
- if (node instanceof abstractMesh_1.AbstractMesh) {
571
- layer.removeMesh(node);
572
- }
573
- if (deep) {
574
- node.getChildTransformNodes(true).forEach(child => removeFromHighlightLayer(layer, child, deep));
575
- }
576
- };
577
- exports.removeFromHighlightLayer = removeFromHighlightLayer;
578
- /**
579
- * @param node
580
- * @param receiveShadows
581
- * @param deep
582
- */
583
- const setReceiveShadows = function (node, receiveShadows, deep = true) {
584
- if (node instanceof abstractMesh_1.AbstractMesh) {
585
- node.receiveShadows = receiveShadows;
586
- }
587
- if (deep) {
588
- node.getChildTransformNodes(true).forEach(child => setReceiveShadows(child, receiveShadows, deep));
589
- }
590
- };
591
- exports.setReceiveShadows = setReceiveShadows;
592
- /**
593
- * @param node
594
- * @param generator
595
- * @param deep
596
- */
597
- const addToShadowGenerator = function (generator, node, deep = true) {
598
- if (node instanceof abstractMesh_1.AbstractMesh) {
599
- // We have to remove the node because there's no duplicate check in babylon
600
- generator.removeShadowCaster(node, false);
601
- generator.addShadowCaster(node, false);
602
- }
603
- if (deep) {
604
- node.getChildTransformNodes(true).forEach(child => addToShadowGenerator(generator, child, deep));
605
- }
606
- };
607
- exports.addToShadowGenerator = addToShadowGenerator;
608
- /**
609
- * @param node
610
- * @param generator
611
- * @param deep
612
- */
613
- const removeFromShadowGenerator = function (generator, node, deep = true) {
614
- if (node instanceof abstractMesh_1.AbstractMesh) {
615
- generator.removeShadowCaster(node, false);
616
- }
617
- if (deep) {
618
- node.getChildTransformNodes(true).forEach(child => removeFromShadowGenerator(generator, child, deep));
619
- }
620
- };
621
- exports.removeFromShadowGenerator = removeFromShadowGenerator;
622
- /**
623
- * https://forum.babylonjs.com/t/get-mesh-bounding-box-position-and-size-in-2d-screen-coordinates/1058/3
624
- * @param mesh
625
- * @param scene
626
- * @param canvas
627
- */
628
- const getClientRectFromMesh = function (mesh, scene, canvas) {
629
- // get bounding box of the mesh
630
- const meshVectors = mesh.getBoundingInfo().boundingBox.vectors;
631
- // get the matrix and viewport needed to project the vectors onto the screen
632
- const worldMatrix = mesh.getWorldMatrix();
633
- const transformMatrix = scene.getTransformMatrix();
634
- const viewport = scene.activeCamera.viewport;
635
- // loop though all the vectors and project them against the current camera viewport to get a set of coordinates
636
- const coordinates = meshVectors.map(vector => {
637
- const projection = math_vector_1.Vector3.Project(vector, worldMatrix, transformMatrix, viewport);
638
- projection.x = projection.x * canvas.clientWidth;
639
- projection.y = projection.y * canvas.clientHeight;
640
- return projection;
641
- });
642
- // get the min and max for all the coordinates so we can calculate the largest possible screen size
643
- const maxX = Math.max(...coordinates.map(o => o.x));
644
- const minX = Math.min(...coordinates.map(o => o.x));
645
- const maxY = Math.max(...coordinates.map(o => o.y));
646
- const minY = Math.min(...coordinates.map(o => o.y));
647
- // return a ClientRect from this
648
- return {
649
- width: maxX - minX,
650
- height: maxY - minY,
651
- left: minX,
652
- top: minY,
653
- right: maxX,
654
- bottom: maxY,
655
- };
656
- };
657
- exports.getClientRectFromMesh = getClientRectFromMesh;
658
- /**
659
- * This type guard checks whether the given `BaseTextures` is any of its subtypes which comes with an
660
- * `onLoadObservable`.
661
- *
662
- * !!! Timing of when this function is called is important !!!
663
- * See the following for more details: https://forum.babylonjs.com/t/basetexture-whenallready-returns-too-early/34501/6
664
- */
665
- const isTextureWithOnLoadObservable = function (texture) {
666
- return !!texture.onLoadObservable;
667
- };
668
- exports.isTextureWithOnLoadObservable = isTextureWithOnLoadObservable;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.reportDuplicateNodeNames = exports.duplicateNodeNames = exports.intersectingNodeNames = exports.mapTags = exports.envHelperMetadataName = exports.backgroundDomeName = exports.changeEnvironment = exports.getClientRectFromMesh = exports.removeFromShadowGenerator = exports.addToShadowGenerator = exports.setReceiveShadows = exports.removeFromHighlightLayer = exports.addToHighlightLayer = exports.setMaterialRoughness = exports.setMaterialMetallness = exports.setMaterialTexture = exports.setMaterialColor = exports.setSourceNodeMaterial = exports.setMaterial = exports.transformTransformNode = exports.disableNodeWithParents = exports.enableNodeWithParents = exports.deactivateTransformNode = exports.activateTransformNode = exports.assertMeshCapability = exports.assertTransformNode = exports.injectNodeMetadata = exports.applyMaterial = exports.getOrCreateMaterial = exports.cloneTransformNodeMaterial = exports.cloneNodeWithParents = exports.cloneTransformNode = exports.getDottedPathForNode = exports.mapToDottedNodes = exports.isTextureWithOnLoadObservable = exports.getRootNode = void 0;
13
+ const dottedPath_1 = require("../classes/dottedPath");
14
+ const event_1 = require("../classes/event");
15
+ const sceneSetup_1 = require("../internal/sceneSetup");
16
+ const sceneLoaderHelper_1 = require("./sceneLoaderHelper");
17
+ const photoDome_1 = require("@babylonjs/core/Helpers/photoDome");
18
+ const light_1 = require("@babylonjs/core/Lights/light");
19
+ const baseTexture_1 = require("@babylonjs/core/Materials/Textures/baseTexture");
20
+ const cubeTexture_1 = require("@babylonjs/core/Materials/Textures/cubeTexture");
21
+ const math_axis_1 = require("@babylonjs/core/Maths/math.axis");
22
+ const math_color_1 = require("@babylonjs/core/Maths/math.color");
23
+ const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
24
+ const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
25
+ const instancedMesh_1 = require("@babylonjs/core/Meshes/instancedMesh");
26
+ const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
27
+ const tags_1 = require("@babylonjs/core/Misc/tags");
28
+ const tools_1 = require("@babylonjs/core/Misc/tools");
29
+ const lodash_es_1 = require("lodash-es");
30
+ const backgroundDomeName = 'BackgroundDome_ViewerGenerated';
31
+ exports.backgroundDomeName = backgroundDomeName;
32
+ const envHelperMetadataName = 'viewerEnvHelper';
33
+ exports.envHelperMetadataName = envHelperMetadataName;
34
+ const materialWaitingToBeSetMetadataName = 'materialWaitingToBeSet';
35
+ /**
36
+ * @param node
37
+ * @return Node
38
+ */
39
+ const getRootNode = function (node) {
40
+ let _node = node;
41
+ while (_node.parent) {
42
+ _node = _node.parent;
43
+ }
44
+ return _node;
45
+ };
46
+ exports.getRootNode = getRootNode;
47
+ /**
48
+ * @param nodes
49
+ * @param predicate
50
+ * @return Map<DottedPath, T>
51
+ */
52
+ const mapToDottedNodes = function (nodes, predicate) {
53
+ const map = new Map();
54
+ const addNodes = function (_node) {
55
+ if (predicate && predicate(_node)) {
56
+ map.set(_node.metadata.dottedPath, _node);
57
+ }
58
+ _node.getChildren().forEach(child => {
59
+ addNodes(child);
60
+ });
61
+ };
62
+ nodes.forEach(node => {
63
+ addNodes(node);
64
+ });
65
+ return map;
66
+ };
67
+ exports.mapToDottedNodes = mapToDottedNodes;
68
+ /**
69
+ * @param node
70
+ * @return DottedPath
71
+ */
72
+ const getDottedPathForNode = function (node) {
73
+ const dottedPath = dottedPath_1.DottedPath.create(node.name);
74
+ let _parent = node;
75
+ while (_parent.parent) {
76
+ _parent = _parent.parent;
77
+ dottedPath.unshiftPart(_parent.name);
78
+ }
79
+ return dottedPath;
80
+ };
81
+ exports.getDottedPathForNode = getDottedPathForNode;
82
+ /**
83
+ * @param node
84
+ * @param nodeNamingStrategy
85
+ * @param predicate
86
+ * @param deep
87
+ * @return TransformNode | null
88
+ */
89
+ const cloneTransformNode = function (node, nodeNamingStrategy, predicate, deep = true) {
90
+ if (predicate && !predicate(node)) {
91
+ return null;
92
+ }
93
+ const newName = nodeNamingStrategy.handler(node, nodeNamingStrategy.payload);
94
+ const clone = node.clone(newName, node.parent, true);
95
+ if (clone) {
96
+ clone.id = newName;
97
+ clone.metadata = (0, lodash_es_1.cloneDeep)(node.metadata);
98
+ injectNodeMetadata(clone, { cloneSource: node }, false);
99
+ // if the cloned node is of type InstancedMesh, due to a bug(?),
100
+ // the InstancedMesh.isEnabled state may have changed after cloning.
101
+ // in that case, set the clone's enabled state to the original's state
102
+ if (node.constructor.name === 'InstancedMesh') {
103
+ clone.setEnabled(node.isEnabled(false));
104
+ }
105
+ }
106
+ if (deep) {
107
+ const children = node.getChildTransformNodes(true);
108
+ children.forEach(child => {
109
+ const clonedChild = cloneTransformNode(child, nodeNamingStrategy, predicate, deep);
110
+ if (clonedChild) {
111
+ clonedChild.parent = clone;
112
+ }
113
+ });
114
+ }
115
+ return clone;
116
+ };
117
+ exports.cloneTransformNode = cloneTransformNode;
118
+ /**
119
+ * @param node
120
+ */
121
+ const cloneNodeWithParents = function (node) {
122
+ let clone = null;
123
+ if (node instanceof transformNode_1.TransformNode) {
124
+ clone = node.clone(node.name, cloneNodeWithParents(node.parent), true);
125
+ }
126
+ else if (node instanceof light_1.Light) {
127
+ clone = node.clone(node.name, cloneNodeWithParents(node.parent));
128
+ }
129
+ else if (node) {
130
+ throw new Error(`Cloning of "${node === null || node === void 0 ? void 0 : node.constructor.name}" is not implemented (yet).`);
131
+ }
132
+ return clone;
133
+ };
134
+ exports.cloneNodeWithParents = cloneNodeWithParents;
135
+ /**
136
+ * @param node
137
+ * @param deep
138
+ * @param prefix
139
+ * @return TransformNode
140
+ */
141
+ const cloneTransformNodeMaterial = function (node, prefix = '', deep = true) {
142
+ if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
143
+ const newMatName = dottedPath_1.DottedPath.create(prefix).addParts([node.material.name, 'clone', node.uniqueId.toString()]);
144
+ node.material = node.material.clone(newMatName.path);
145
+ }
146
+ if (deep) {
147
+ const children = node.getChildTransformNodes(true);
148
+ children.forEach(child => cloneTransformNodeMaterial(child, prefix, deep));
149
+ }
150
+ return node;
151
+ };
152
+ exports.cloneTransformNodeMaterial = cloneTransformNodeMaterial;
153
+ /**
154
+ * @param node
155
+ * @param deep
156
+ * @param metadata
157
+ */
158
+ const injectNodeMetadata = function (node, metadata, deep = true) {
159
+ node.metadata = (0, lodash_es_1.merge)({}, node.metadata, metadata);
160
+ if (deep && node instanceof transformNode_1.TransformNode) {
161
+ const children = node.getChildTransformNodes(true);
162
+ children.forEach(child => injectNodeMetadata(child, metadata, deep));
163
+ }
164
+ };
165
+ exports.injectNodeMetadata = injectNodeMetadata;
166
+ /**
167
+ * @param node
168
+ * @param assertCallable
169
+ * @param callableParameters
170
+ * @param deep
171
+ */
172
+ const assertTransformNode = function (node, assertCallable, callableParameters = [], deep = true) {
173
+ assertCallable(node, ...callableParameters);
174
+ if (deep) {
175
+ const children = node.getChildTransformNodes(true);
176
+ children.forEach(child => assertTransformNode(child, assertCallable, callableParameters, deep));
177
+ }
178
+ };
179
+ exports.assertTransformNode = assertTransformNode;
180
+ /**
181
+ * @param node
182
+ * @param parameter
183
+ */
184
+ const assertMeshCapability = function (node, parameter) {
185
+ if (!(node instanceof abstractMesh_1.AbstractMesh)) {
186
+ const cls = node.getClassName();
187
+ throw new Error(`Changing parameter "${parameter}" of a(n) ${cls} is not supported. Tried to change node "${node.id}".`);
188
+ }
189
+ if (node instanceof instancedMesh_1.InstancedMesh) {
190
+ throw new Error(`Changing parameter "${parameter}" of an InstancedMesh is not supported. Tried to change node "${node.id}".`);
191
+ }
192
+ };
193
+ exports.assertMeshCapability = assertMeshCapability;
194
+ /**
195
+ * @param node
196
+ * @param deep
197
+ */
198
+ const activateTransformNode = function (node, deep = true) {
199
+ node.setEnabled(true);
200
+ /*
201
+ if( node instanceof AbstractMesh ) {
202
+ node.visibility = 1;
203
+ node.isPickable = true;
204
+ }
205
+ */
206
+ if (deep) {
207
+ node.getChildTransformNodes(true).forEach(child => activateTransformNode(child, deep));
208
+ }
209
+ };
210
+ exports.activateTransformNode = activateTransformNode;
211
+ /**
212
+ * @param node
213
+ * @param deep
214
+ */
215
+ const deactivateTransformNode = function (node, deep = true) {
216
+ node.setEnabled(false);
217
+ /*
218
+ if( node instanceof AbstractMesh ) {
219
+ node.visibility = 0;
220
+ node.isPickable = false;
221
+ }
222
+ */
223
+ if (deep) {
224
+ node.getChildTransformNodes(true).forEach(child => deactivateTransformNode(child, deep));
225
+ }
226
+ };
227
+ exports.deactivateTransformNode = deactivateTransformNode;
228
+ /**
229
+ * @param node
230
+ */
231
+ const enableNodeWithParents = function (node) {
232
+ node.setEnabled(true);
233
+ if (node.parent) {
234
+ enableNodeWithParents(node.parent);
235
+ }
236
+ };
237
+ exports.enableNodeWithParents = enableNodeWithParents;
238
+ /**
239
+ * @param node
240
+ */
241
+ const disableNodeWithParents = function (node) {
242
+ node.setEnabled(false);
243
+ if (node.parent) {
244
+ disableNodeWithParents(node.parent);
245
+ }
246
+ };
247
+ exports.disableNodeWithParents = disableNodeWithParents;
248
+ /**
249
+ * Applies a {@link TransformationDefinition} consecutively to ensure dependencies in positioning etc.
250
+ * @param node
251
+ * @param transformation
252
+ */
253
+ const transformTransformNode = function (node, transformation) {
254
+ // scaling
255
+ if (!(0, lodash_es_1.has)(node.metadata, 'scaling.initial')) {
256
+ injectNodeMetadata(node, { 'scaling.initial': node.scaling }, false);
257
+ }
258
+ const initialScaling = (0, lodash_es_1.get)(node.metadata, 'scaling.initial');
259
+ node.scaling = initialScaling.multiply(transformation.scaling);
260
+ // position
261
+ if (!(0, lodash_es_1.has)(node.metadata, 'position.initial')) {
262
+ injectNodeMetadata(node, { 'position.initial': node.absolutePosition.clone() }, false);
263
+ }
264
+ const initialPosition = (0, lodash_es_1.get)(node.metadata, 'position.initial');
265
+ node.setAbsolutePosition(initialPosition.add(transformation.position).multiply(transformation.scaling));
266
+ // rotation
267
+ if (!(0, lodash_es_1.has)(node.metadata, 'rotation.initial')) {
268
+ let rotationQuaternion = node.rotationQuaternion;
269
+ if (!rotationQuaternion) {
270
+ rotationQuaternion = math_vector_1.Quaternion.RotationYawPitchRoll(node.rotation.x, node.rotation.y, node.rotation.z);
271
+ }
272
+ injectNodeMetadata(node, { 'rotation.initial': rotationQuaternion.asArray() }, false);
273
+ }
274
+ const initialRotationQuaternion = math_vector_1.Quaternion.FromArray((0, lodash_es_1.get)(node.metadata, 'rotation.initial'));
275
+ node.rotationQuaternion = initialRotationQuaternion;
276
+ node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.X, transformation.rotation.x);
277
+ node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.Y, transformation.rotation.y);
278
+ node.rotateAround(math_vector_1.Vector3.Zero(), math_axis_1.Axis.Z, transformation.rotation.z);
279
+ node.computeWorldMatrix(true);
280
+ };
281
+ exports.transformTransformNode = transformTransformNode;
282
+ /**
283
+ * Apply changes of environment (background texture, etc.) consecutively in order to avoid dependency related issues.
284
+ * @param scene
285
+ * @param envDef
286
+ */
287
+ const changeEnvironment = function (scene, envDef) {
288
+ var _a;
289
+ // issue warning if both background texture and usedefault are set
290
+ if (envDef.environmentUseDefault && envDef.environmentBackground) {
291
+ console.warn(`!!! Warning !!! Spec parameter 'environment.usedefault' is being overruled by 'environment.background'.`);
292
+ }
293
+ const useDefaultEnv = envDef.environmentUseDefault && !envDef.environmentBackground;
294
+ // 1) set ENVIRONMENT_COLOR
295
+ const clearColorBefore = scene.clearColor.toString();
296
+ scene.clearColor = envDef.environmentColor
297
+ ? math_color_1.Color4.FromColor3(envDef.environmentColor)
298
+ : useDefaultEnv
299
+ ? sceneSetup_1.defaultEnvHelperColor
300
+ : sceneSetup_1.defaultSceneClearColor;
301
+ const clearColorChanged = clearColorBefore !== scene.clearColor.toString();
302
+ // 2) dispose existing & set new ENVIRONMENT (==texture)
303
+ const curEnvTexture = scene.environmentTexture;
304
+ const envTextureChanged = envDef.environment !== (curEnvTexture === null || curEnvTexture === void 0 ? void 0 : curEnvTexture.url);
305
+ if (curEnvTexture && (!envDef.environment || envTextureChanged)) {
306
+ curEnvTexture.dispose();
307
+ }
308
+ const rotation = envDef.environmentRotation !== undefined ? tools_1.Tools.ToRadians(envDef.environmentRotation) : 0;
309
+ if (envDef.environment && envTextureChanged) {
310
+ const envTexture = cubeTexture_1.CubeTexture.CreateFromPrefilteredData(envDef.environment, scene);
311
+ envTexture.rotationY = rotation;
312
+ scene.environmentTexture = envTexture;
313
+ }
314
+ else if (curEnvTexture && curEnvTexture.rotationY !== rotation) {
315
+ curEnvTexture.rotationY = rotation;
316
+ }
317
+ // 3) dispose existing & set new ENVIRONMENT_BACKGROUND
318
+ const curDome = scene.getNodeByName(backgroundDomeName);
319
+ const backgroundUrlChanged = envDef.environmentBackground !== (curDome === null || curDome === void 0 ? void 0 : curDome.texture.url);
320
+ if (curDome && (!envDef.environmentBackground || backgroundUrlChanged)) {
321
+ curDome.dispose();
322
+ }
323
+ const rotationPhotoDome = -1 * rotation;
324
+ if (envDef.environmentBackground && backgroundUrlChanged) {
325
+ const textureUrl = envDef.environmentBackground;
326
+ const dome = new photoDome_1.PhotoDome(backgroundDomeName, textureUrl, { resolution: 32, size: 450 }, scene);
327
+ // Rotate submesh to get them in line with environment texture
328
+ dome.getChildMeshes(true)[0].rotation.y = tools_1.Tools.ToRadians(90);
329
+ dome.rotation.y = rotationPhotoDome;
330
+ }
331
+ else if (curDome && curDome.rotation.y !== rotationPhotoDome) {
332
+ curDome.rotation.y = rotationPhotoDome;
333
+ }
334
+ // 4) dispose existing & set new ENVIRONMENT_USEDEFAULT (only if no background is set)
335
+ const curEnvHelper = (_a = scene.metadata) === null || _a === void 0 ? void 0 : _a[envHelperMetadataName];
336
+ if (curEnvHelper && !useDefaultEnv) {
337
+ curEnvHelper.dispose();
338
+ delete scene.metadata[envHelperMetadataName];
339
+ }
340
+ const envHelperMainColor = math_color_1.Color3.FromArray(scene.clearColor.asArray());
341
+ if (useDefaultEnv && !curEnvHelper) {
342
+ const envHelper = scene.createDefaultEnvironment({ sizeAuto: true });
343
+ envHelper === null || envHelper === void 0 ? void 0 : envHelper.setMainColor(envHelperMainColor);
344
+ if (envHelper) {
345
+ scene.metadata = (0, lodash_es_1.merge)({}, scene.metadata, { [envHelperMetadataName]: envHelper });
346
+ }
347
+ }
348
+ else if (curEnvHelper && useDefaultEnv && clearColorChanged) {
349
+ curEnvHelper.setMainColor(envHelperMainColor);
350
+ }
351
+ // 5) set ENVIRONMENT_INTENSITY
352
+ if (envDef.environmentIntensity !== undefined) {
353
+ scene.environmentIntensity = envDef.environmentIntensity;
354
+ }
355
+ };
356
+ exports.changeEnvironment = changeEnvironment;
357
+ /**
358
+ * Sets a material by a given material id as material property on the given node.
359
+ *
360
+ * If the material is not already available in the scene, the viewer tries to create a material based on a Combeenation
361
+ * [material asset](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset).
362
+ * This of course only works if the viewer is used inside a Combeenation configurator.
363
+ *
364
+ * Furthermore this function also defers the material creation if the node is not visible yet to improve network &
365
+ * viewer bootstrap performance as textures are automatically being lazy loaded only when they are actually visible in
366
+ * the scene.
367
+ *
368
+ * Finally the material will not be applied before all its textures have been loaded. In this way "flickering" effects
369
+ * will be avoided, since the material would be incomplete without its loaded textures.
370
+ */
371
+ const setMaterial = function (node, materialId, deep = true, variant) {
372
+ if (node instanceof abstractMesh_1.AbstractMesh) {
373
+ const materialExists = node.getScene().getMaterialById(materialId);
374
+ const hasMissingMaterial = (0, lodash_es_1.has)(node.metadata, sceneLoaderHelper_1.missingMaterialMetadataName);
375
+ const deferMaterialCreation = !materialExists && !node.isEnabled();
376
+ if (deferMaterialCreation) {
377
+ // do not set the material
378
+ injectNodeMetadata(node, { [sceneLoaderHelper_1.missingMaterialMetadataName]: materialId }, false);
379
+ // if it already had the missing material flag before, there already exists an observer...
380
+ if (!hasMissingMaterial) {
381
+ (0, sceneLoaderHelper_1.addMissingMaterialObserver)(node);
382
+ }
383
+ }
384
+ else {
385
+ // create material and apply it when textures have been loaded
386
+ const material = getOrCreateMaterial(node.getScene(), materialId, variant);
387
+ applyMaterial(material, node).then(() => event_1.emitter.emit(event_1.Event.MESH_MATERIAL_APPLIED, node, material));
388
+ if (hasMissingMaterial) {
389
+ delete node.metadata[sceneLoaderHelper_1.missingMaterialMetadataName];
390
+ }
391
+ }
392
+ }
393
+ // recursively set materials on children (if desired)
394
+ if (deep) {
395
+ for (const child of node.getChildTransformNodes(true)) {
396
+ setMaterial(child, materialId, deep, variant);
397
+ }
398
+ }
399
+ };
400
+ exports.setMaterial = setMaterial;
401
+ /**
402
+ * Gets the Material either from the given {@link Variant}, the given scene or tries to create it from an Combeenation
403
+ * material asset when inside a Combeenation configurator.
404
+ */
405
+ const getOrCreateMaterial = function (scene, materialId, variant) {
406
+ let chosenMaterial;
407
+ chosenMaterial = variant === null || variant === void 0 ? void 0 : variant.inheritedMaterials.find(mat => mat.id === materialId);
408
+ chosenMaterial = chosenMaterial || scene.materials.find(mat => mat.id === materialId);
409
+ chosenMaterial = chosenMaterial || (0, sceneLoaderHelper_1.createMaterialFromCbnAssets)(materialId, scene);
410
+ if (chosenMaterial) {
411
+ return chosenMaterial;
412
+ }
413
+ // reject when material was not found
414
+ let rejectMessage = `Material with id "${materialId}" does not exist on scene.`;
415
+ if (variant) {
416
+ rejectMessage = `Material with id "${materialId}" does not exist for variant "${variant.id}".`;
417
+ }
418
+ throw new Error(rejectMessage);
419
+ };
420
+ exports.getOrCreateMaterial = getOrCreateMaterial;
421
+ /**
422
+ * Waits until the materials textures are loaded and shaders are compiled.
423
+ * Then sets the material on the node if there is no newer "set material" request
424
+ */
425
+ const applyMaterial = function (material, node) {
426
+ var _a;
427
+ return __awaiter(this, void 0, void 0, function* () {
428
+ // set current material id as last valid id, in this case all previously set materials on the node will be invalidated
429
+ injectNodeMetadata(node, { [materialWaitingToBeSetMetadataName]: material.id }, false);
430
+ const promTexturesReady = new Promise(resolve => baseTexture_1.BaseTexture.WhenAllReady(material.getActiveTextures(), resolve));
431
+ // this promise should only take some time on the first call of the corresponding shader (eg: PBRMaterial shader)
432
+ // on each other call of the same material/shader type there should be not be a waiting time, or at maximum one frame
433
+ // https://forum.babylonjs.com/t/mesh-flickering-when-setting-material-initially/37312
434
+ const promMaterialCompiled = material.forceCompilationAsync(node);
435
+ // material needs to fulfill 2 criterias before it's ready to use
436
+ // - textures need to be "ready" => downloaded
437
+ // - dedicated shader needs to be compiled
438
+ // if this would not be the case you can see some "flickering" when setting the material
439
+ yield Promise.all([promTexturesReady, promMaterialCompiled]);
440
+ // textures ready, now check if the material is still up-to-date
441
+ if (material.id === ((_a = node.metadata) === null || _a === void 0 ? void 0 : _a[materialWaitingToBeSetMetadataName])) {
442
+ node.material = material;
443
+ delete node.metadata[materialWaitingToBeSetMetadataName];
444
+ }
445
+ });
446
+ };
447
+ exports.applyMaterial = applyMaterial;
448
+ /**
449
+ * !!! Warning !!!
450
+ * This function is not public API. Whilst it can help solving certain problems, it only works reliably in well defined
451
+ * situations and can cause unwanted side effects under some conditions. Use carefully at your own risk!
452
+ *
453
+ * See https://combeenation.myjetbrains.com/youtrack/issue/CB-5906 for further details regarding this warning.
454
+ *
455
+ * Set material of an instanced meshes source mesh.
456
+ * Changes the material of all instanced meshes which have the same source mesh.
457
+ *
458
+ * @param node
459
+ * @param material
460
+ * @param deep
461
+ *
462
+ * @ignore
463
+ */
464
+ const setSourceNodeMaterial = function (node, material, deep = true) {
465
+ const warn = ` You're using "setSourceNodeMaterial" which is not public API.
466
+ Whilst it can help solving certain problems, it only works reliably in well defined situations and can cause unwanted side effects under some conditions.
467
+ Use carefully at your own risk!`;
468
+ console.warn(`!!! Warning !!!\n${warn}`);
469
+ if (node instanceof instancedMesh_1.InstancedMesh) {
470
+ node.sourceMesh.material = material;
471
+ }
472
+ if (deep) {
473
+ node.getChildTransformNodes(true).forEach(child => setSourceNodeMaterial(child, material, deep));
474
+ }
475
+ };
476
+ exports.setSourceNodeMaterial = setSourceNodeMaterial;
477
+ /**
478
+ * @param node
479
+ * @param color
480
+ * @param deep
481
+ */
482
+ const setMaterialColor = function (node, color, deep = true) {
483
+ if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
484
+ const materialCls = node.material.getClassName();
485
+ switch (materialCls) {
486
+ case 'PBRMaterial':
487
+ node.material.albedoColor = color.toLinearSpace();
488
+ break;
489
+ case 'StandardMaterial':
490
+ node.material.diffuseColor = color;
491
+ break;
492
+ default:
493
+ throw new Error(`Setting color for material of instance "${materialCls}" not implemented (yet).`);
494
+ }
495
+ setMaterial(node, node.material.id, false);
496
+ }
497
+ if (deep) {
498
+ node.getChildTransformNodes(true).forEach(child => setMaterialColor(child, color, deep));
499
+ }
500
+ };
501
+ exports.setMaterialColor = setMaterialColor;
502
+ /**
503
+ * @param node
504
+ * @param texture
505
+ * @param deep
506
+ */
507
+ const setMaterialTexture = function (node, texture, deep = true) {
508
+ if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
509
+ const materialCls = node.material.getClassName();
510
+ switch (materialCls) {
511
+ case 'PBRMaterial':
512
+ node.material.albedoTexture = texture;
513
+ break;
514
+ case 'StandardMaterial':
515
+ node.material.diffuseTexture = texture;
516
+ break;
517
+ default:
518
+ throw new Error(`Setting texture for material of instance "${materialCls}" not implemented (yet).`);
519
+ }
520
+ setMaterial(node, node.material.id, false);
521
+ }
522
+ if (deep) {
523
+ node.getChildTransformNodes(true).forEach(child => setMaterialTexture(child, texture, deep));
524
+ }
525
+ };
526
+ exports.setMaterialTexture = setMaterialTexture;
527
+ /**
528
+ * @param node
529
+ * @param metallness
530
+ * @param deep
531
+ */
532
+ const setMaterialMetallness = function (node, metallness, deep = true) {
533
+ if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
534
+ const materialCls = node.material.getClassName();
535
+ switch (materialCls) {
536
+ case 'PBRMaterial':
537
+ node.material.metallic = metallness;
538
+ break;
539
+ default:
540
+ throw new Error(`Setting metallness for material of instance "${materialCls}" not implemented (yet).`);
541
+ }
542
+ setMaterial(node, node.material.id, false);
543
+ }
544
+ if (deep) {
545
+ node.getChildTransformNodes(true).forEach(child => setMaterialMetallness(child, metallness, deep));
546
+ }
547
+ };
548
+ exports.setMaterialMetallness = setMaterialMetallness;
549
+ /**
550
+ * @param node
551
+ * @param roughness
552
+ * @param deep
553
+ */
554
+ const setMaterialRoughness = function (node, roughness, deep = true) {
555
+ if (node instanceof abstractMesh_1.AbstractMesh && node.material) {
556
+ const materialCls = node.material.getClassName();
557
+ switch (materialCls) {
558
+ case 'PBRMaterial':
559
+ node.material.roughness = roughness;
560
+ break;
561
+ case 'StandardMaterial':
562
+ node.material.roughness = roughness;
563
+ break;
564
+ default:
565
+ throw new Error(`Setting roughness for material of instance "${materialCls}" not implemented (yet).`);
566
+ }
567
+ setMaterial(node, node.material.id, false);
568
+ }
569
+ if (deep) {
570
+ node.getChildTransformNodes(true).forEach(child => setMaterialRoughness(child, roughness, deep));
571
+ }
572
+ };
573
+ exports.setMaterialRoughness = setMaterialRoughness;
574
+ /**
575
+ * @param node
576
+ * @param layer
577
+ * @param color
578
+ * @param deep
579
+ */
580
+ const addToHighlightLayer = function (layer, color, node, deep = true) {
581
+ if (node instanceof abstractMesh_1.AbstractMesh) {
582
+ layer.addMesh(node, color);
583
+ }
584
+ if (deep) {
585
+ node.getChildTransformNodes(true).forEach(child => addToHighlightLayer(layer, color, child, deep));
586
+ }
587
+ };
588
+ exports.addToHighlightLayer = addToHighlightLayer;
589
+ /**
590
+ * @param node
591
+ * @param layer
592
+ * @param deep
593
+ */
594
+ const removeFromHighlightLayer = function (layer, node, deep = true) {
595
+ if (node instanceof abstractMesh_1.AbstractMesh) {
596
+ layer.removeMesh(node);
597
+ }
598
+ if (deep) {
599
+ node.getChildTransformNodes(true).forEach(child => removeFromHighlightLayer(layer, child, deep));
600
+ }
601
+ };
602
+ exports.removeFromHighlightLayer = removeFromHighlightLayer;
603
+ /**
604
+ * @param node
605
+ * @param receiveShadows
606
+ * @param deep
607
+ */
608
+ const setReceiveShadows = function (node, receiveShadows, deep = true) {
609
+ if (node instanceof abstractMesh_1.AbstractMesh) {
610
+ node.receiveShadows = receiveShadows;
611
+ }
612
+ if (deep) {
613
+ node.getChildTransformNodes(true).forEach(child => setReceiveShadows(child, receiveShadows, deep));
614
+ }
615
+ };
616
+ exports.setReceiveShadows = setReceiveShadows;
617
+ /**
618
+ * @param node
619
+ * @param generator
620
+ * @param deep
621
+ */
622
+ const addToShadowGenerator = function (generator, node, deep = true) {
623
+ if (node instanceof abstractMesh_1.AbstractMesh) {
624
+ // We have to remove the node because there's no duplicate check in babylon
625
+ generator.removeShadowCaster(node, false);
626
+ generator.addShadowCaster(node, false);
627
+ }
628
+ if (deep) {
629
+ node.getChildTransformNodes(true).forEach(child => addToShadowGenerator(generator, child, deep));
630
+ }
631
+ };
632
+ exports.addToShadowGenerator = addToShadowGenerator;
633
+ /**
634
+ * @param node
635
+ * @param generator
636
+ * @param deep
637
+ */
638
+ const removeFromShadowGenerator = function (generator, node, deep = true) {
639
+ if (node instanceof abstractMesh_1.AbstractMesh) {
640
+ generator.removeShadowCaster(node, false);
641
+ }
642
+ if (deep) {
643
+ node.getChildTransformNodes(true).forEach(child => removeFromShadowGenerator(generator, child, deep));
644
+ }
645
+ };
646
+ exports.removeFromShadowGenerator = removeFromShadowGenerator;
647
+ /**
648
+ * https://forum.babylonjs.com/t/get-mesh-bounding-box-position-and-size-in-2d-screen-coordinates/1058/3
649
+ * @param mesh
650
+ * @param scene
651
+ * @param canvas
652
+ */
653
+ const getClientRectFromMesh = function (mesh, scene, canvas) {
654
+ // get bounding box of the mesh
655
+ const meshVectors = mesh.getBoundingInfo().boundingBox.vectors;
656
+ // get the matrix and viewport needed to project the vectors onto the screen
657
+ const worldMatrix = mesh.getWorldMatrix();
658
+ const transformMatrix = scene.getTransformMatrix();
659
+ const viewport = scene.activeCamera.viewport;
660
+ // loop though all the vectors and project them against the current camera viewport to get a set of coordinates
661
+ const coordinates = meshVectors.map(vector => {
662
+ const projection = math_vector_1.Vector3.Project(vector, worldMatrix, transformMatrix, viewport);
663
+ projection.x = projection.x * canvas.clientWidth;
664
+ projection.y = projection.y * canvas.clientHeight;
665
+ return projection;
666
+ });
667
+ // get the min and max for all the coordinates so we can calculate the largest possible screen size
668
+ const maxX = Math.max(...coordinates.map(o => o.x));
669
+ const minX = Math.min(...coordinates.map(o => o.x));
670
+ const maxY = Math.max(...coordinates.map(o => o.y));
671
+ const minY = Math.min(...coordinates.map(o => o.y));
672
+ // return a ClientRect from this
673
+ return {
674
+ width: maxX - minX,
675
+ height: maxY - minY,
676
+ left: minX,
677
+ top: minY,
678
+ right: maxX,
679
+ bottom: maxY,
680
+ };
681
+ };
682
+ exports.getClientRectFromMesh = getClientRectFromMesh;
683
+ /**
684
+ * This type guard checks whether the given `BaseTextures` is any of its subtypes which comes with an
685
+ * `onLoadObservable`.
686
+ *
687
+ * !!! Timing of when this function is called is important !!!
688
+ * See the following for more details: https://forum.babylonjs.com/t/basetexture-whenallready-returns-too-early/34501/6
689
+ */
690
+ const isTextureWithOnLoadObservable = function (texture) {
691
+ return !!texture.onLoadObservable;
692
+ };
693
+ exports.isTextureWithOnLoadObservable = isTextureWithOnLoadObservable;
694
+ /**
695
+ * @param objects
696
+ * @param tagMapping
697
+ */
698
+ const mapTags = function (objects, tagMapping) {
699
+ var _a;
700
+ let affectedTags = [];
701
+ for (const object of objects) {
702
+ const oldTags = Object.keys((_a = tags_1.Tags.GetTags(object, false)) !== null && _a !== void 0 ? _a : {});
703
+ const mappedTags = oldTags.map(t => tagMapping[t] || t);
704
+ tags_1.Tags.RemoveTagsFrom(object, oldTags.join(' '));
705
+ tags_1.Tags.AddTagsTo(object, mappedTags.join(' '));
706
+ affectedTags = [...affectedTags, ...mappedTags];
707
+ }
708
+ return (0, lodash_es_1.uniq)(affectedTags);
709
+ };
710
+ exports.mapTags = mapTags;
711
+ /**
712
+ * Gets an array of ids for nodeIds that exist in both TransformNode arrays.
713
+ * @param nodes1
714
+ * @param nodes2
715
+ * @param predicate
716
+ */
717
+ const intersectingNodeNames = function (nodes1, nodes2, predicate) {
718
+ const nodeNames1 = nodes1.filter(n => !predicate || predicate(n)).map(n => n.name);
719
+ const nodesNames2 = nodes2.filter(n => !predicate || predicate(n)).map(n => n.name);
720
+ return nodeNames1.filter(n1 => nodesNames2.includes(n1));
721
+ };
722
+ exports.intersectingNodeNames = intersectingNodeNames;
723
+ /**
724
+ * Gets an array of ids for duplicate nodeIds in given node array.
725
+ * @param nodes
726
+ * @param predicate
727
+ */
728
+ const duplicateNodeNames = function (nodes, predicate) {
729
+ const nodeNames = nodes.filter(n => !predicate || predicate(n)).map(n => n.name);
730
+ return nodeNames.filter((v, i, self) => self.indexOf(v) !== i);
731
+ };
732
+ exports.duplicateNodeNames = duplicateNodeNames;
733
+ /**
734
+ * Reports duplicate nodeIds.
735
+ * @param nodeNames
736
+ */
737
+ const reportDuplicateNodeNames = function (nodeNames) {
738
+ var _a;
739
+ if (nodeNames.length > 0) {
740
+ const warn = `There are duplicate nodeNames: ${nodeNames.join(', ')}`;
741
+ console.warn(`!!! Warning !!!\n${warn}`);
742
+ (_a = window.Cbn) === null || _a === void 0 ? void 0 : _a.Assets.reportDuplicateNodeName(nodeNames);
743
+ }
744
+ };
745
+ exports.reportDuplicateNodeNames = reportDuplicateNodeNames;
669
746
  //# sourceMappingURL=babylonHelper.js.map