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