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