@combeenation/3d-viewer 13.0.1 → 14.0.1-rc1

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 (72) hide show
  1. package/README.md +9 -9
  2. package/dist/lib-cjs/buildinfo.json +3 -3
  3. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  4. package/dist/lib-cjs/index.d.ts +62 -63
  5. package/dist/lib-cjs/index.js +94 -95
  6. package/dist/lib-cjs/index.js.map +1 -1
  7. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
  8. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
  9. package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
  10. package/dist/lib-cjs/internal/cloning-helper.js +163 -163
  11. package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
  12. package/dist/lib-cjs/internal/device-helper.js +24 -24
  13. package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
  14. package/dist/lib-cjs/internal/geometry-helper.js +145 -145
  15. package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
  16. package/dist/lib-cjs/internal/metadata-helper.js +50 -50
  17. package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
  18. package/dist/lib-cjs/internal/paintable-helper.js +286 -286
  19. package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
  20. package/dist/lib-cjs/internal/tags-helper.js +37 -37
  21. package/dist/lib-cjs/manager/camera-manager.d.ts +110 -51
  22. package/dist/lib-cjs/manager/camera-manager.js +206 -153
  23. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  24. package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
  25. package/dist/lib-cjs/manager/debug-manager.js +217 -217
  26. package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
  27. package/dist/lib-cjs/manager/event-manager.js +71 -71
  28. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +84 -75
  29. package/dist/lib-cjs/manager/gltf-export-manager.js +290 -278
  30. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  31. package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
  32. package/dist/lib-cjs/manager/material-manager.js +125 -125
  33. package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
  34. package/dist/lib-cjs/manager/model-manager.js +382 -382
  35. package/dist/lib-cjs/manager/parameter-manager.d.ts +210 -210
  36. package/dist/lib-cjs/manager/parameter-manager.js +514 -514
  37. package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
  38. package/dist/lib-cjs/manager/scene-manager.js +64 -64
  39. package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
  40. package/dist/lib-cjs/manager/texture-manager.js +43 -43
  41. package/dist/lib-cjs/viewer-error.d.ts +48 -48
  42. package/dist/lib-cjs/viewer-error.js +60 -60
  43. package/dist/lib-cjs/viewer.d.ts +115 -117
  44. package/dist/lib-cjs/viewer.js +217 -221
  45. package/dist/lib-cjs/viewer.js.map +1 -1
  46. package/package.json +91 -91
  47. package/src/buildinfo.json +3 -3
  48. package/src/dev.ts +47 -47
  49. package/src/global-types.d.ts +39 -39
  50. package/src/index.ts +81 -82
  51. package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
  52. package/src/internal/cloning-helper.ts +225 -225
  53. package/src/internal/device-helper.ts +25 -25
  54. package/src/internal/geometry-helper.ts +181 -181
  55. package/src/internal/metadata-helper.ts +63 -63
  56. package/src/internal/paintable-helper.ts +310 -310
  57. package/src/internal/tags-helper.ts +41 -41
  58. package/src/manager/camera-manager.ts +365 -236
  59. package/src/manager/debug-manager.ts +245 -245
  60. package/src/manager/event-manager.ts +72 -72
  61. package/src/manager/gltf-export-manager.ts +357 -341
  62. package/src/manager/material-manager.ts +135 -135
  63. package/src/manager/model-manager.ts +458 -458
  64. package/src/manager/parameter-manager.ts +652 -652
  65. package/src/manager/scene-manager.ts +101 -101
  66. package/src/manager/texture-manager.ts +32 -32
  67. package/src/viewer-error.ts +68 -68
  68. package/src/viewer.ts +290 -296
  69. package/dist/lib-cjs/manager/screenshot-manager.d.ts +0 -36
  70. package/dist/lib-cjs/manager/screenshot-manager.js +0 -40
  71. package/dist/lib-cjs/manager/screenshot-manager.js.map +0 -1
  72. package/src/manager/screenshot-manager.ts +0 -59
@@ -1,181 +1,181 @@
1
- import {
2
- ExcludedGeometry,
3
- ExcludedGeometryList,
4
- FloatArray,
5
- Geometry,
6
- InstancedMesh,
7
- Mesh,
8
- MorphTarget,
9
- MorphTargetManager,
10
- ParameterSubject,
11
- TransformNode,
12
- Vector3,
13
- VertexBuffer,
14
- } from '../index';
15
- import { cloneInternalMetadata } from './metadata-helper';
16
- import { hasTag } from './tags-helper';
17
-
18
- /**
19
- * Find out if a node is part of a list of excluded geometry
20
- * @param node BJS node
21
- * @param list list of excluded geometry
22
- * @returns boolean based on whether node (or one of its parents) was found in list
23
- */
24
- export function isNodeExcluded(nodeToCheck: TransformNode, list: ExcludedGeometryList): boolean {
25
- // CAUTION: node has to be the same instance
26
- const checkNode = (excludedNode: TransformNode): boolean => excludedNode === nodeToCheck;
27
- const checkTagManagerSubject = (excludedSubject: ParameterSubject): boolean => {
28
- const nameMatches = !!excludedSubject.nodeName && excludedSubject.nodeName === nodeToCheck.name;
29
- const tagMatches = !!excludedSubject.tagName && hasTag(nodeToCheck, excludedSubject.tagName);
30
- return nameMatches || tagMatches;
31
- };
32
- const check = (geometryToExclude: ExcludedGeometry): boolean => {
33
- if (geometryToExclude instanceof TransformNode) {
34
- return checkNode(geometryToExclude);
35
- }
36
- if ((geometryToExclude as ParameterSubject).tagName || (geometryToExclude as ParameterSubject).nodeName) {
37
- return checkTagManagerSubject(geometryToExclude as ParameterSubject);
38
- }
39
- return false;
40
- };
41
-
42
- let isExcluded = list.some(geometryToExclude => check(geometryToExclude));
43
- // consider parent as well
44
- if (!isExcluded && nodeToCheck.parent instanceof TransformNode) {
45
- isExcluded = isNodeExcluded(nodeToCheck.parent, list);
46
- }
47
-
48
- return isExcluded;
49
- }
50
-
51
- /**
52
- * Creates a "standard" mesh from an instanced mesh, by cloning the source mesh and applying transformation data
53
- */
54
- export function createMeshFromInstancedMesh(
55
- instancedMesh: InstancedMesh,
56
- newName: string,
57
- clonedParent: TransformNode
58
- ): Mesh {
59
- // first create a clone of the source mesh
60
- const newMesh = instancedMesh.sourceMesh.clone(newName, clonedParent, true);
61
- cloneInternalMetadata(instancedMesh.sourceMesh, newMesh);
62
- // apply the transformation data, it's important to create clones of the transformations to not touch the original
63
- // transformation when applying changes (eg: geometry baking)
64
- newMesh.position = instancedMesh.position.clone();
65
- newMesh.rotation = instancedMesh.rotation.clone();
66
- newMesh.scaling = instancedMesh.scaling.clone();
67
-
68
- // rotation quaternion is optional
69
- if (instancedMesh.rotationQuaternion) {
70
- newMesh.rotationQuaternion = instancedMesh.rotationQuaternion.clone();
71
- }
72
-
73
- // also sync the enabled state from the original instanced mesh
74
- newMesh.setEnabled(instancedMesh.isEnabled(false));
75
-
76
- return newMesh;
77
- }
78
-
79
- /**
80
- * Removes transformation data from the mesh and stores it in the geometry, which is called "baking".
81
- * Also considers the geometry change from morph targets.
82
- */
83
- export function bakeGeometryOfMesh(mesh: Mesh): void {
84
- if (!mesh.geometry) {
85
- // no geometry available, nothing to do
86
- return;
87
- }
88
-
89
- // geometries can be shared across multiple meshes, first make them unique to avoid side-effects
90
- mesh.makeGeometryUnique();
91
-
92
- // Babylon.js already provides a function for baking the current skeleton changes into the geometry
93
- if (mesh.skeleton) {
94
- mesh.applySkeleton(mesh.skeleton);
95
- mesh.skeleton = null;
96
- }
97
-
98
- // NOTE: in difference to skeletons and transformations there is no baking function for morph targets (yet)
99
- // however another approach could be to re-apply the position and normals data, as there are nice functions for it
100
- // - `getPositionData(applySkeleton: boolean = false, applyMorph: boolean = false)`
101
- // - `getNormalsData(applySkeleton: boolean = false, applyMorph: boolean = false)`
102
- // you can decide if skeletons and morph targets can be added, which is exactly what we want
103
- // I'm still hesitant to use it because "tangent" and "UV" kinds are not supported, whereas I'm not sure if it's
104
- // required
105
- // => try it out when there is enough time for detailed regression tests!
106
- const morphTargetManager = mesh.morphTargetManager;
107
- const geometry = mesh.geometry;
108
-
109
- if (morphTargetManager?.numTargets) {
110
- // apply morph target vertices data to mesh geometry
111
- // mostly only the "PositionKind" is implemented
112
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.PositionKind, morphTargetManager, geometry);
113
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.NormalKind, morphTargetManager, geometry);
114
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.TangentKind, morphTargetManager, geometry);
115
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.UVKind, morphTargetManager, geometry);
116
-
117
- // remove morph target manager with all it's morph targets
118
- mesh.morphTargetManager = null;
119
- }
120
-
121
- // bake the transformation data in the mesh geometry, fortunately there is already a help function from Babylon.js
122
- mesh.bakeCurrentTransformIntoVertices();
123
- }
124
-
125
- /**
126
- * Resets transformation to initial state
127
- */
128
- export function resetTransformation(node: TransformNode): void {
129
- node.position = new Vector3(0, 0, 0);
130
- node.rotation = new Vector3(0, 0, 0);
131
- node.rotationQuaternion = null;
132
- node.scaling = new Vector3(1, 1, 1);
133
- }
134
-
135
- /**
136
- * @param kind morph targets can affect various vertices kinds, whereas "position" is the most common one
137
- * still other kinds (like normals or tangents) can be affected as well and can be provided on this input
138
- */
139
- function _bakeMorphTargetManagerIntoVertices(
140
- kind: string,
141
- morphTargetManager: MorphTargetManager,
142
- geometry: Geometry
143
- ): void {
144
- const origVerticesData = geometry.getVerticesData(kind);
145
- if (!origVerticesData) {
146
- // no vertices data for this kind availabe on the mesh geometry
147
- return;
148
- }
149
-
150
- let verticesData = [...origVerticesData];
151
- for (let i = 0; i < morphTargetManager.numTargets; i++) {
152
- const target = morphTargetManager.getTarget(i);
153
- const targetVerticesData = _getVerticesDataFromMorphTarget(kind, target);
154
- if (targetVerticesData) {
155
- // vertices data of this kind are implemented on the morph target
156
- // add the influence of this morph target to the vertices data
157
- // formula is taken from: https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets#basics
158
- verticesData = verticesData.map(
159
- (oldVal, idx) => oldVal + (targetVerticesData[idx] - origVerticesData[idx]) * target.influence
160
- );
161
- }
162
- }
163
-
164
- // apply the updated vertices data
165
- geometry.setVerticesData(kind, verticesData);
166
- }
167
-
168
- function _getVerticesDataFromMorphTarget(kind: string, morphTarget: MorphTarget): FloatArray | null {
169
- switch (kind) {
170
- case VertexBuffer.PositionKind:
171
- return morphTarget.getPositions();
172
- case VertexBuffer.NormalKind:
173
- return morphTarget.getNormals();
174
- case VertexBuffer.TangentKind:
175
- return morphTarget.getTangents();
176
- case VertexBuffer.UVKind:
177
- return morphTarget.getUVs();
178
- }
179
-
180
- return null;
181
- }
1
+ import {
2
+ ExcludedGeometry,
3
+ ExcludedGeometryList,
4
+ FloatArray,
5
+ Geometry,
6
+ InstancedMesh,
7
+ Mesh,
8
+ MorphTarget,
9
+ MorphTargetManager,
10
+ ParameterSubject,
11
+ TransformNode,
12
+ Vector3,
13
+ VertexBuffer,
14
+ } from '../index';
15
+ import { cloneInternalMetadata } from './metadata-helper';
16
+ import { hasTag } from './tags-helper';
17
+
18
+ /**
19
+ * Find out if a node is part of a list of excluded geometry
20
+ * @param node BJS node
21
+ * @param list list of excluded geometry
22
+ * @returns boolean based on whether node (or one of its parents) was found in list
23
+ */
24
+ export function isNodeExcluded(nodeToCheck: TransformNode, list: ExcludedGeometryList): boolean {
25
+ // CAUTION: node has to be the same instance
26
+ const checkNode = (excludedNode: TransformNode): boolean => excludedNode === nodeToCheck;
27
+ const checkTagManagerSubject = (excludedSubject: ParameterSubject): boolean => {
28
+ const nameMatches = !!excludedSubject.nodeName && excludedSubject.nodeName === nodeToCheck.name;
29
+ const tagMatches = !!excludedSubject.tagName && hasTag(nodeToCheck, excludedSubject.tagName);
30
+ return nameMatches || tagMatches;
31
+ };
32
+ const check = (geometryToExclude: ExcludedGeometry): boolean => {
33
+ if (geometryToExclude instanceof TransformNode) {
34
+ return checkNode(geometryToExclude);
35
+ }
36
+ if ((geometryToExclude as ParameterSubject).tagName || (geometryToExclude as ParameterSubject).nodeName) {
37
+ return checkTagManagerSubject(geometryToExclude as ParameterSubject);
38
+ }
39
+ return false;
40
+ };
41
+
42
+ let isExcluded = list.some(geometryToExclude => check(geometryToExclude));
43
+ // consider parent as well
44
+ if (!isExcluded && nodeToCheck.parent instanceof TransformNode) {
45
+ isExcluded = isNodeExcluded(nodeToCheck.parent, list);
46
+ }
47
+
48
+ return isExcluded;
49
+ }
50
+
51
+ /**
52
+ * Creates a "standard" mesh from an instanced mesh, by cloning the source mesh and applying transformation data
53
+ */
54
+ export function createMeshFromInstancedMesh(
55
+ instancedMesh: InstancedMesh,
56
+ newName: string,
57
+ clonedParent: TransformNode
58
+ ): Mesh {
59
+ // first create a clone of the source mesh
60
+ const newMesh = instancedMesh.sourceMesh.clone(newName, clonedParent, true);
61
+ cloneInternalMetadata(instancedMesh.sourceMesh, newMesh);
62
+ // apply the transformation data, it's important to create clones of the transformations to not touch the original
63
+ // transformation when applying changes (eg: geometry baking)
64
+ newMesh.position = instancedMesh.position.clone();
65
+ newMesh.rotation = instancedMesh.rotation.clone();
66
+ newMesh.scaling = instancedMesh.scaling.clone();
67
+
68
+ // rotation quaternion is optional
69
+ if (instancedMesh.rotationQuaternion) {
70
+ newMesh.rotationQuaternion = instancedMesh.rotationQuaternion.clone();
71
+ }
72
+
73
+ // also sync the enabled state from the original instanced mesh
74
+ newMesh.setEnabled(instancedMesh.isEnabled(false));
75
+
76
+ return newMesh;
77
+ }
78
+
79
+ /**
80
+ * Removes transformation data from the mesh and stores it in the geometry, which is called "baking".
81
+ * Also considers the geometry change from morph targets.
82
+ */
83
+ export function bakeGeometryOfMesh(mesh: Mesh): void {
84
+ if (!mesh.geometry) {
85
+ // no geometry available, nothing to do
86
+ return;
87
+ }
88
+
89
+ // geometries can be shared across multiple meshes, first make them unique to avoid side-effects
90
+ mesh.makeGeometryUnique();
91
+
92
+ // Babylon.js already provides a function for baking the current skeleton changes into the geometry
93
+ if (mesh.skeleton) {
94
+ mesh.applySkeleton(mesh.skeleton);
95
+ mesh.skeleton = null;
96
+ }
97
+
98
+ // NOTE: in difference to skeletons and transformations there is no baking function for morph targets (yet)
99
+ // however another approach could be to re-apply the position and normals data, as there are nice functions for it
100
+ // - `getPositionData(applySkeleton: boolean = false, applyMorph: boolean = false)`
101
+ // - `getNormalsData(applySkeleton: boolean = false, applyMorph: boolean = false)`
102
+ // you can decide if skeletons and morph targets can be added, which is exactly what we want
103
+ // I'm still hesitant to use it because "tangent" and "UV" kinds are not supported, whereas I'm not sure if it's
104
+ // required
105
+ // => try it out when there is enough time for detailed regression tests!
106
+ const morphTargetManager = mesh.morphTargetManager;
107
+ const geometry = mesh.geometry;
108
+
109
+ if (morphTargetManager?.numTargets) {
110
+ // apply morph target vertices data to mesh geometry
111
+ // mostly only the "PositionKind" is implemented
112
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.PositionKind, morphTargetManager, geometry);
113
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.NormalKind, morphTargetManager, geometry);
114
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.TangentKind, morphTargetManager, geometry);
115
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.UVKind, morphTargetManager, geometry);
116
+
117
+ // remove morph target manager with all it's morph targets
118
+ mesh.morphTargetManager = null;
119
+ }
120
+
121
+ // bake the transformation data in the mesh geometry, fortunately there is already a help function from Babylon.js
122
+ mesh.bakeCurrentTransformIntoVertices();
123
+ }
124
+
125
+ /**
126
+ * Resets transformation to initial state
127
+ */
128
+ export function resetTransformation(node: TransformNode): void {
129
+ node.position = new Vector3(0, 0, 0);
130
+ node.rotation = new Vector3(0, 0, 0);
131
+ node.rotationQuaternion = null;
132
+ node.scaling = new Vector3(1, 1, 1);
133
+ }
134
+
135
+ /**
136
+ * @param kind morph targets can affect various vertices kinds, whereas "position" is the most common one
137
+ * still other kinds (like normals or tangents) can be affected as well and can be provided on this input
138
+ */
139
+ function _bakeMorphTargetManagerIntoVertices(
140
+ kind: string,
141
+ morphTargetManager: MorphTargetManager,
142
+ geometry: Geometry
143
+ ): void {
144
+ const origVerticesData = geometry.getVerticesData(kind);
145
+ if (!origVerticesData) {
146
+ // no vertices data for this kind availabe on the mesh geometry
147
+ return;
148
+ }
149
+
150
+ let verticesData = [...origVerticesData];
151
+ for (let i = 0; i < morphTargetManager.numTargets; i++) {
152
+ const target = morphTargetManager.getTarget(i);
153
+ const targetVerticesData = _getVerticesDataFromMorphTarget(kind, target);
154
+ if (targetVerticesData) {
155
+ // vertices data of this kind are implemented on the morph target
156
+ // add the influence of this morph target to the vertices data
157
+ // formula is taken from: https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets#basics
158
+ verticesData = verticesData.map(
159
+ (oldVal, idx) => oldVal + (targetVerticesData[idx] - origVerticesData[idx]) * target.influence
160
+ );
161
+ }
162
+ }
163
+
164
+ // apply the updated vertices data
165
+ geometry.setVerticesData(kind, verticesData);
166
+ }
167
+
168
+ function _getVerticesDataFromMorphTarget(kind: string, morphTarget: MorphTarget): FloatArray | null {
169
+ switch (kind) {
170
+ case VertexBuffer.PositionKind:
171
+ return morphTarget.getPositions();
172
+ case VertexBuffer.NormalKind:
173
+ return morphTarget.getNormals();
174
+ case VertexBuffer.TangentKind:
175
+ return morphTarget.getTangents();
176
+ case VertexBuffer.UVKind:
177
+ return morphTarget.getUVs();
178
+ }
179
+
180
+ return null;
181
+ }
@@ -1,63 +1,63 @@
1
- import { BaseTexture, Material, Node } from '../index';
2
- import { cloneDeep } from 'lodash-es';
3
-
4
- type MetadataValue = string | number | boolean | undefined;
5
- type MetadataTarget = Node | Material | BaseTexture;
6
- type MetadataKeys =
7
- // CBN babylon loader
8
- | 'deferredMaterial'
9
- // material manager
10
- | 'materialToBeSet'
11
- // GLTF export
12
- | 'exportNode'
13
- | 'deleteAfterExport'
14
- | 'exchangeMaterialWith'
15
- // cloning
16
- | 'cloneSource'
17
- | 'cloneTarget';
18
-
19
- // TODO WTT: use generics or some kind of logic that is able to type the metadata according to their key
20
- /**
21
- * Sets certain metadata on the objects INTERNAL metadata storage.
22
- * "object._internalMetadata.cbn" is reserved for CBN specific metadata information.
23
- * The objects public metadata ("object.metadata") is not affected and should therefore not interfere with metadata
24
- * that is used in consumer projects.
25
- */
26
- export function setInternalMetadataValue(object: MetadataTarget, key: MetadataKeys, value: MetadataValue): void {
27
- if (!object._internalMetadata) {
28
- object._internalMetadata = {};
29
- }
30
- if (!object._internalMetadata.cbn) {
31
- object._internalMetadata.cbn = {};
32
- }
33
-
34
- object._internalMetadata.cbn[key] = value;
35
- }
36
-
37
- export function clearInternalMetadataValue(object: MetadataTarget, key: MetadataKeys): void {
38
- delete object._internalMetadata?.cbn?.[key];
39
- }
40
-
41
- export function getInternalMetadataValue(object: MetadataTarget, key: MetadataKeys): MetadataValue {
42
- return object._internalMetadata?.cbn?.[key];
43
- }
44
-
45
- /**
46
- * Creates a deep clone from the source objects internal metadata and assigns it to the target objects metadata.
47
- * This is required as Babylon.js only creates shallow clones of the internal metadata, which would be problematic for
48
- * our needs.
49
- */
50
- export function cloneInternalMetadata(sourceObject: MetadataTarget, targetObject: MetadataTarget): void {
51
- targetObject._internalMetadata = cloneDeep(sourceObject._internalMetadata);
52
- }
53
-
54
- /**
55
- * Clones the metadata from one object to another.
56
- * CAUTION: this is now the public available "object.metadata" object.
57
- * We need this function internally when cloning instanced meshes.
58
- */
59
- export function cloneMetadata(sourceObject: MetadataTarget, targetObject: MetadataTarget): void {
60
- const clonedMetadata = cloneDeep(sourceObject.metadata);
61
-
62
- targetObject.metadata = clonedMetadata;
63
- }
1
+ import { BaseTexture, Material, Node } from '../index';
2
+ import { cloneDeep } from 'lodash-es';
3
+
4
+ type MetadataValue = string | number | boolean | undefined;
5
+ type MetadataTarget = Node | Material | BaseTexture;
6
+ type MetadataKeys =
7
+ // CBN babylon loader
8
+ | 'deferredMaterial'
9
+ // material manager
10
+ | 'materialToBeSet'
11
+ // GLTF export
12
+ | 'exportNode'
13
+ | 'deleteAfterExport'
14
+ | 'exchangeMaterialWith'
15
+ // cloning
16
+ | 'cloneSource'
17
+ | 'cloneTarget';
18
+
19
+ // TODO WTT: use generics or some kind of logic that is able to type the metadata according to their key
20
+ /**
21
+ * Sets certain metadata on the objects INTERNAL metadata storage.
22
+ * "object._internalMetadata.cbn" is reserved for CBN specific metadata information.
23
+ * The objects public metadata ("object.metadata") is not affected and should therefore not interfere with metadata
24
+ * that is used in consumer projects.
25
+ */
26
+ export function setInternalMetadataValue(object: MetadataTarget, key: MetadataKeys, value: MetadataValue): void {
27
+ if (!object._internalMetadata) {
28
+ object._internalMetadata = {};
29
+ }
30
+ if (!object._internalMetadata.cbn) {
31
+ object._internalMetadata.cbn = {};
32
+ }
33
+
34
+ object._internalMetadata.cbn[key] = value;
35
+ }
36
+
37
+ export function clearInternalMetadataValue(object: MetadataTarget, key: MetadataKeys): void {
38
+ delete object._internalMetadata?.cbn?.[key];
39
+ }
40
+
41
+ export function getInternalMetadataValue(object: MetadataTarget, key: MetadataKeys): MetadataValue {
42
+ return object._internalMetadata?.cbn?.[key];
43
+ }
44
+
45
+ /**
46
+ * Creates a deep clone from the source objects internal metadata and assigns it to the target objects metadata.
47
+ * This is required as Babylon.js only creates shallow clones of the internal metadata, which would be problematic for
48
+ * our needs.
49
+ */
50
+ export function cloneInternalMetadata(sourceObject: MetadataTarget, targetObject: MetadataTarget): void {
51
+ targetObject._internalMetadata = cloneDeep(sourceObject._internalMetadata);
52
+ }
53
+
54
+ /**
55
+ * Clones the metadata from one object to another.
56
+ * CAUTION: this is now the public available "object.metadata" object.
57
+ * We need this function internally when cloning instanced meshes.
58
+ */
59
+ export function cloneMetadata(sourceObject: MetadataTarget, targetObject: MetadataTarget): void {
60
+ const clonedMetadata = cloneDeep(sourceObject.metadata);
61
+
62
+ targetObject.metadata = clonedMetadata;
63
+ }