@combeenation/3d-viewer 7.1.1 → 7.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) 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 -153
  7. package/dist/lib-cjs/api/classes/element.js +672 -670
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/event.d.ts +401 -396
  10. package/dist/lib-cjs/api/classes/event.js +424 -419
  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 -7
  15. package/dist/lib-cjs/api/classes/fuzzyMap.js +21 -21
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +351 -351
  17. package/dist/lib-cjs/api/classes/parameter.js +524 -517
  18. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  20. package/dist/lib-cjs/api/classes/parameterObservable.js +72 -72
  21. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  22. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  23. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  24. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  25. package/dist/lib-cjs/api/classes/variant.d.ts +253 -253
  26. package/dist/lib-cjs/api/classes/variant.js +858 -843
  27. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  28. package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -53
  29. package/dist/lib-cjs/api/classes/variantInstance.js +125 -125
  30. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  31. package/dist/lib-cjs/api/classes/variantParameterizable.js +86 -88
  32. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/viewer.d.ts +204 -200
  34. package/dist/lib-cjs/api/classes/viewer.js +682 -670
  35. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  36. package/dist/lib-cjs/api/classes/viewerError.d.ts +43 -0
  37. package/dist/lib-cjs/api/classes/viewerError.js +56 -0
  38. package/dist/lib-cjs/api/classes/viewerError.js.map +1 -0
  39. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  40. package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
  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/gltfExportManager.d.ts +79 -79
  48. package/dist/lib-cjs/api/manager/gltfExportManager.js +242 -242
  49. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
  50. package/dist/lib-cjs/api/manager/sceneManager.js +128 -130
  51. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  52. package/dist/lib-cjs/api/manager/tagManager.d.ts +116 -109
  53. package/dist/lib-cjs/api/manager/tagManager.js +444 -425
  54. package/dist/lib-cjs/api/manager/tagManager.js.map +1 -1
  55. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
  56. package/dist/lib-cjs/api/manager/textureLoadManager.js +97 -97
  57. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +106 -106
  58. package/dist/lib-cjs/api/manager/variantInstanceManager.js +292 -292
  59. package/dist/lib-cjs/api/store/specStorage.d.ts +32 -32
  60. package/dist/lib-cjs/api/store/specStorage.js +65 -65
  61. package/dist/lib-cjs/api/util/babylonHelper.d.ts +235 -235
  62. package/dist/lib-cjs/api/util/babylonHelper.js +753 -753
  63. package/dist/lib-cjs/api/util/globalTypes.d.ts +441 -437
  64. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  65. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  66. package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
  67. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +44 -44
  68. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +175 -175
  69. package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
  70. package/dist/lib-cjs/api/util/stringHelper.js +32 -32
  71. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  72. package/dist/lib-cjs/api/util/structureHelper.js +57 -48
  73. package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
  74. package/dist/lib-cjs/buildinfo.json +3 -3
  75. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  76. package/dist/lib-cjs/index.d.ts +54 -53
  77. package/dist/lib-cjs/index.js +117 -114
  78. package/dist/lib-cjs/index.js.map +1 -1
  79. package/package.json +81 -81
  80. package/src/api/classes/animationInterface.ts +10 -10
  81. package/src/api/classes/dottedPath.ts +181 -181
  82. package/src/api/classes/element.ts +733 -731
  83. package/src/api/classes/event.ts +457 -452
  84. package/src/api/classes/eventBroadcaster.ts +52 -52
  85. package/src/api/classes/fuzzyMap.ts +21 -21
  86. package/src/api/classes/parameter.ts +561 -554
  87. package/src/api/classes/parameterObservable.ts +73 -73
  88. package/src/api/classes/parameterizable.ts +87 -87
  89. package/src/api/classes/placementAnimation.ts +162 -162
  90. package/src/api/classes/variant.ts +949 -933
  91. package/src/api/classes/variantInstance.ts +123 -123
  92. package/src/api/classes/variantParameterizable.ts +83 -85
  93. package/src/api/classes/viewer.ts +760 -744
  94. package/src/api/classes/viewerError.ts +63 -0
  95. package/src/api/classes/viewerLight.ts +339 -339
  96. package/src/api/internal/debugViewer.ts +90 -90
  97. package/src/api/internal/lensRendering.ts +9 -9
  98. package/src/api/internal/sceneSetup.ts +205 -205
  99. package/src/api/manager/animationManager.ts +143 -143
  100. package/src/api/manager/gltfExportManager.ts +237 -237
  101. package/src/api/manager/sceneManager.ts +134 -136
  102. package/src/api/manager/tagManager.ts +477 -457
  103. package/src/api/manager/textureLoadManager.ts +95 -95
  104. package/src/api/manager/variantInstanceManager.ts +309 -309
  105. package/src/api/store/specStorage.ts +68 -68
  106. package/src/api/util/babylonHelper.ts +823 -823
  107. package/src/api/util/globalTypes.ts +508 -504
  108. package/src/api/util/resourceHelper.ts +191 -191
  109. package/src/api/util/sceneLoaderHelper.ts +170 -170
  110. package/src/api/util/stringHelper.ts +30 -30
  111. package/src/api/util/structureHelper.ts +58 -49
  112. package/src/buildinfo.json +3 -3
  113. package/src/dev.ts +62 -62
  114. package/src/index.ts +103 -100
  115. package/src/types.d.ts +38 -38
@@ -1,243 +1,243 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.GltfExportManager = void 0;
24
- const viewer_1 = require("../classes/viewer");
25
- const babylonHelper_1 = require("../util/babylonHelper");
26
- const structureHelper_1 = require("../util/structureHelper");
27
- const pbrMaterial_1 = require("@babylonjs/core/Materials/PBR/pbrMaterial");
28
- const math_color_1 = require("@babylonjs/core/Maths/math.color");
29
- const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
30
- const mesh_1 = require("@babylonjs/core/Meshes/mesh");
31
- const _2_0_1 = require("@babylonjs/serializers/glTF/2.0");
32
- const lodash_es_1 = require("lodash-es");
33
- class GltfExportManager {
34
- /**
35
- * Constructor.
36
- */
37
- constructor(viewer) {
38
- this.viewer = viewer;
39
- }
40
- /**
41
- * Creates an {@link GltfExportManager}.
42
- */
43
- static create(viewer) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return new GltfExportManager(viewer);
46
- });
47
- }
48
- /**
49
- * Exports selected nodes to a file.
50
- * @param filename optional name of the exported .GLB file.
51
- * @param exportOptions export options to be merged with default options.\
52
- * `exportOptions.createUniqueMeshNames` defaults to `true` if not given.
53
- * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
54
- */
55
- exportGlb(filename = 'glb-export.glb', _a = {}, excluded) {
56
- var { createUniqueMeshNames = true } = _a, exportOptionsRest = __rest(_a, ["createUniqueMeshNames"]);
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const exportOptions = Object.assign({ createUniqueMeshNames }, exportOptionsRest);
59
- this.exportPreProcess(exportOptions);
60
- const glbData = yield _2_0_1.GLTF2Export.GLBAsync(this.viewer.scene, 'dummy', this.gltfExportOptions(exportOptions, excluded));
61
- this.exportPostProcess();
62
- const resBlob = glbData.glTFFiles['dummy.glb']; // should be only one file for glb
63
- // check if result is valid, according to the typings this could also be a string
64
- if (resBlob instanceof Blob) {
65
- if (!filename.endsWith('.glb')) {
66
- filename += '.glb';
67
- }
68
- return new File([resBlob], filename);
69
- }
70
- else {
71
- // result was not a valid blob
72
- return undefined;
73
- }
74
- });
75
- }
76
- /**
77
- * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
78
- * @param filename name of the main (text-based) .GLTF file referring to separate texture files.
79
- * @param exportOptions export options to be merged with default options.\
80
- * `exportOptions.createUniqueMeshNames` defaults to `true` if not given.
81
- * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
82
- */
83
- exportGltfToFile(filename, _a = {}, excluded) {
84
- var { createUniqueMeshNames = true } = _a, exportOptionsRest = __rest(_a, ["createUniqueMeshNames"]);
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const exportOptions = Object.assign({ createUniqueMeshNames }, exportOptionsRest);
87
- this.exportPreProcess(exportOptions);
88
- yield _2_0_1.GLTF2Export.GLTFAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(glb => {
89
- glb.downloadFiles();
90
- });
91
- this.exportPostProcess();
92
- });
93
- }
94
- /**
95
- * Exports selected nodes to GLB. This results in one binary file.
96
- * @param filename name of the .GLB file.
97
- * @param exportOptions export options to be merged with default options.\
98
- * `exportOptions.createUniqueMeshNames` defaults to `true` if not given.
99
- * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
100
- */
101
- exportGlbToFile(filename, _a = {}, excluded) {
102
- var { createUniqueMeshNames = true } = _a, exportOptionsRest = __rest(_a, ["createUniqueMeshNames"]);
103
- return __awaiter(this, void 0, void 0, function* () {
104
- const exportOptions = Object.assign({ createUniqueMeshNames }, exportOptionsRest);
105
- this.exportPreProcess(exportOptions);
106
- yield _2_0_1.GLTF2Export.GLBAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(glb => {
107
- glb.downloadFiles();
108
- });
109
- this.exportPostProcess();
110
- });
111
- }
112
- /**
113
- * Gets predefined {@link IExportOptionsExtended } merged with given ones.
114
- */
115
- gltfExportOptions(mergeWithOptions = {}, excluded) {
116
- const defaultOptions = {
117
- // includeCoordinateSystemConversionNodes: true,
118
- shouldExportNode: function (node) {
119
- if (!node.isEnabled()) {
120
- return false;
121
- }
122
- if (node.name.startsWith(viewer_1.Viewer.BOUNDING_BOX_NAME)) {
123
- return false;
124
- }
125
- if (excluded && node instanceof mesh_1.Mesh && (0, structureHelper_1.isMeshIncludedInExclusionList)(node, excluded)) {
126
- return false;
127
- }
128
- return true;
129
- },
130
- };
131
- return (0, lodash_es_1.merge)({}, defaultOptions, mergeWithOptions);
132
- }
133
- /**
134
- * Stuff to be done before exporting to GLTF
135
- */
136
- exportPreProcess({ createUniqueMeshNames = true }) {
137
- this.viewer.pauseRendering();
138
- if (createUniqueMeshNames !== null && createUniqueMeshNames !== void 0 ? createUniqueMeshNames : true) {
139
- this.setUniqueMeshNames();
140
- }
141
- this.exchangeRefractionMaterials();
142
- }
143
- /**
144
- * Stuff to be done after the GLTF export
145
- */
146
- exportPostProcess() {
147
- this.restoreRefractionMaterials();
148
- this.restoreOriginalMeshNames();
149
- this.viewer.resumeRendering();
150
- }
151
- /**
152
- * Materials with refraction set are not exported properly.
153
- * Exchange all such (relevant) materials with a more export-friendly version
154
- */
155
- exchangeRefractionMaterials() {
156
- for (const n of this.viewer.scene.getNodes()) {
157
- if (!(n instanceof abstractMesh_1.AbstractMesh))
158
- continue;
159
- if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
160
- continue;
161
- if (!n.material.subSurface.isRefractionEnabled)
162
- continue;
163
- if (n.material.transparencyMode !== pbrMaterial_1.PBRMaterial.PBRMATERIAL_OPAQUE)
164
- continue;
165
- // if we're here, we have a node holding a material with set refraction whose transparencyMode is set to
166
- // PBRMATERIAL_OPAQUE
167
- n.material = this.createRefractionMaterialReplacement(n.material);
168
- }
169
- }
170
- /**
171
- * Restore original materials with set refraction.
172
- */
173
- restoreRefractionMaterials() {
174
- for (const n of this.viewer.scene.getNodes()) {
175
- if (!(n instanceof abstractMesh_1.AbstractMesh))
176
- continue;
177
- if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
178
- continue;
179
- if (!this.isMaterialClonedForExport(n.material))
180
- continue;
181
- // at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
182
- // restore and dispose
183
- const currMaterial = n.material;
184
- const prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
185
- if (prevMaterial) {
186
- n.material = prevMaterial; // restore previous material
187
- currMaterial.dispose(false, true); // dispose of clone
188
- }
189
- }
190
- }
191
- /**
192
- * Create an export-friendly replacement material for a material using refraction.
193
- * @param mat Material to be replaced
194
- */
195
- createRefractionMaterialReplacement(mat) {
196
- // if we're dealing with a clone already, return it instead of cloning
197
- if (this.isMaterialClonedForExport(mat))
198
- return mat;
199
- // change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
200
- const clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
201
- clonedMaterial.metadata = Object.assign(Object.assign({}, mat.metadata), { clonedFrom: mat.uniqueId }); // create shallow copy of metadata on clone. see https://forum.babylonjs.com/t/the-metadata-of-the-mesh-cloned-by-the-instantiatemodelstoscene-method-is-a-shallow-copy/21563
202
- clonedMaterial.refractionTexture = null;
203
- clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
204
- clonedMaterial.alpha = 0.7;
205
- clonedMaterial.albedoColor = new math_color_1.Color3(0.3, 0.3, 0.3);
206
- clonedMaterial.transparencyMode = pbrMaterial_1.PBRMaterial.PBRMATERIAL_ALPHABLEND;
207
- clonedMaterial.metallic = 0.65;
208
- clonedMaterial.roughness = 0.15;
209
- return clonedMaterial;
210
- }
211
- /**
212
- * Inspect if a material was temporarily cloned for GLB export
213
- * @param mat Material to be inspected
214
- */
215
- isMaterialClonedForExport(mat) {
216
- var _a;
217
- return !!((_a = mat.metadata) === null || _a === void 0 ? void 0 : _a.clonedFrom);
218
- }
219
- /**
220
- * Set unique mesh names for GLB export
221
- */
222
- setUniqueMeshNames() {
223
- this.viewer.scene.meshes.forEach(currMesh => {
224
- (0, babylonHelper_1.injectNodeMetadata)(currMesh, { [GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY]: currMesh.name }, false);
225
- currMesh.name = `${currMesh.name}_${currMesh.uniqueId}`;
226
- });
227
- }
228
- /**
229
- * Restore original mesh names for meshes that were
230
- * renamed with {@link setUniqueMeshNames()}
231
- */
232
- restoreOriginalMeshNames() {
233
- this.viewer.scene.meshes.forEach(currMesh => {
234
- if ((0, lodash_es_1.has)(currMesh.metadata, GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY)) {
235
- currMesh.name = currMesh.metadata[GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY];
236
- delete currMesh.metadata[GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY];
237
- }
238
- });
239
- }
240
- }
241
- exports.GltfExportManager = GltfExportManager;
242
- GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY = 'originalName';
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.GltfExportManager = void 0;
24
+ const viewer_1 = require("../classes/viewer");
25
+ const babylonHelper_1 = require("../util/babylonHelper");
26
+ const structureHelper_1 = require("../util/structureHelper");
27
+ const pbrMaterial_1 = require("@babylonjs/core/Materials/PBR/pbrMaterial");
28
+ const math_color_1 = require("@babylonjs/core/Maths/math.color");
29
+ const abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
30
+ const mesh_1 = require("@babylonjs/core/Meshes/mesh");
31
+ const _2_0_1 = require("@babylonjs/serializers/glTF/2.0");
32
+ const lodash_es_1 = require("lodash-es");
33
+ class GltfExportManager {
34
+ /**
35
+ * Constructor.
36
+ */
37
+ constructor(viewer) {
38
+ this.viewer = viewer;
39
+ }
40
+ /**
41
+ * Creates an {@link GltfExportManager}.
42
+ */
43
+ static create(viewer) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return new GltfExportManager(viewer);
46
+ });
47
+ }
48
+ /**
49
+ * Exports selected nodes to a file.
50
+ * @param filename optional name of the exported .GLB file.
51
+ * @param exportOptions export options to be merged with default options.\
52
+ * `exportOptions.createUniqueMeshNames` defaults to `true` if not given.
53
+ * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
54
+ */
55
+ exportGlb(filename = 'glb-export.glb', _a = {}, excluded) {
56
+ var { createUniqueMeshNames = true } = _a, exportOptionsRest = __rest(_a, ["createUniqueMeshNames"]);
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const exportOptions = Object.assign({ createUniqueMeshNames }, exportOptionsRest);
59
+ this.exportPreProcess(exportOptions);
60
+ const glbData = yield _2_0_1.GLTF2Export.GLBAsync(this.viewer.scene, 'dummy', this.gltfExportOptions(exportOptions, excluded));
61
+ this.exportPostProcess();
62
+ const resBlob = glbData.glTFFiles['dummy.glb']; // should be only one file for glb
63
+ // check if result is valid, according to the typings this could also be a string
64
+ if (resBlob instanceof Blob) {
65
+ if (!filename.endsWith('.glb')) {
66
+ filename += '.glb';
67
+ }
68
+ return new File([resBlob], filename);
69
+ }
70
+ else {
71
+ // result was not a valid blob
72
+ return undefined;
73
+ }
74
+ });
75
+ }
76
+ /**
77
+ * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
78
+ * @param filename name of the main (text-based) .GLTF file referring to separate texture files.
79
+ * @param exportOptions export options to be merged with default options.\
80
+ * `exportOptions.createUniqueMeshNames` defaults to `true` if not given.
81
+ * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
82
+ */
83
+ exportGltfToFile(filename, _a = {}, excluded) {
84
+ var { createUniqueMeshNames = true } = _a, exportOptionsRest = __rest(_a, ["createUniqueMeshNames"]);
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const exportOptions = Object.assign({ createUniqueMeshNames }, exportOptionsRest);
87
+ this.exportPreProcess(exportOptions);
88
+ yield _2_0_1.GLTF2Export.GLTFAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(glb => {
89
+ glb.downloadFiles();
90
+ });
91
+ this.exportPostProcess();
92
+ });
93
+ }
94
+ /**
95
+ * Exports selected nodes to GLB. This results in one binary file.
96
+ * @param filename name of the .GLB file.
97
+ * @param exportOptions export options to be merged with default options.\
98
+ * `exportOptions.createUniqueMeshNames` defaults to `true` if not given.
99
+ * @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
100
+ */
101
+ exportGlbToFile(filename, _a = {}, excluded) {
102
+ var { createUniqueMeshNames = true } = _a, exportOptionsRest = __rest(_a, ["createUniqueMeshNames"]);
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const exportOptions = Object.assign({ createUniqueMeshNames }, exportOptionsRest);
105
+ this.exportPreProcess(exportOptions);
106
+ yield _2_0_1.GLTF2Export.GLBAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(glb => {
107
+ glb.downloadFiles();
108
+ });
109
+ this.exportPostProcess();
110
+ });
111
+ }
112
+ /**
113
+ * Gets predefined {@link IExportOptionsExtended } merged with given ones.
114
+ */
115
+ gltfExportOptions(mergeWithOptions = {}, excluded) {
116
+ const defaultOptions = {
117
+ // includeCoordinateSystemConversionNodes: true,
118
+ shouldExportNode: function (node) {
119
+ if (!node.isEnabled()) {
120
+ return false;
121
+ }
122
+ if (node.name.startsWith(viewer_1.Viewer.BOUNDING_BOX_NAME)) {
123
+ return false;
124
+ }
125
+ if (excluded && node instanceof mesh_1.Mesh && (0, structureHelper_1.isMeshIncludedInExclusionList)(node, excluded)) {
126
+ return false;
127
+ }
128
+ return true;
129
+ },
130
+ };
131
+ return (0, lodash_es_1.merge)({}, defaultOptions, mergeWithOptions);
132
+ }
133
+ /**
134
+ * Stuff to be done before exporting to GLTF
135
+ */
136
+ exportPreProcess({ createUniqueMeshNames = true }) {
137
+ this.viewer.pauseRendering();
138
+ if (createUniqueMeshNames !== null && createUniqueMeshNames !== void 0 ? createUniqueMeshNames : true) {
139
+ this.setUniqueMeshNames();
140
+ }
141
+ this.exchangeRefractionMaterials();
142
+ }
143
+ /**
144
+ * Stuff to be done after the GLTF export
145
+ */
146
+ exportPostProcess() {
147
+ this.restoreRefractionMaterials();
148
+ this.restoreOriginalMeshNames();
149
+ this.viewer.resumeRendering();
150
+ }
151
+ /**
152
+ * Materials with refraction set are not exported properly.
153
+ * Exchange all such (relevant) materials with a more export-friendly version
154
+ */
155
+ exchangeRefractionMaterials() {
156
+ for (const n of this.viewer.scene.getNodes()) {
157
+ if (!(n instanceof abstractMesh_1.AbstractMesh))
158
+ continue;
159
+ if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
160
+ continue;
161
+ if (!n.material.subSurface.isRefractionEnabled)
162
+ continue;
163
+ if (n.material.transparencyMode !== pbrMaterial_1.PBRMaterial.PBRMATERIAL_OPAQUE)
164
+ continue;
165
+ // if we're here, we have a node holding a material with set refraction whose transparencyMode is set to
166
+ // PBRMATERIAL_OPAQUE
167
+ n.material = this.createRefractionMaterialReplacement(n.material);
168
+ }
169
+ }
170
+ /**
171
+ * Restore original materials with set refraction.
172
+ */
173
+ restoreRefractionMaterials() {
174
+ for (const n of this.viewer.scene.getNodes()) {
175
+ if (!(n instanceof abstractMesh_1.AbstractMesh))
176
+ continue;
177
+ if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
178
+ continue;
179
+ if (!this.isMaterialClonedForExport(n.material))
180
+ continue;
181
+ // at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
182
+ // restore and dispose
183
+ const currMaterial = n.material;
184
+ const prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
185
+ if (prevMaterial) {
186
+ n.material = prevMaterial; // restore previous material
187
+ currMaterial.dispose(false, true); // dispose of clone
188
+ }
189
+ }
190
+ }
191
+ /**
192
+ * Create an export-friendly replacement material for a material using refraction.
193
+ * @param mat Material to be replaced
194
+ */
195
+ createRefractionMaterialReplacement(mat) {
196
+ // if we're dealing with a clone already, return it instead of cloning
197
+ if (this.isMaterialClonedForExport(mat))
198
+ return mat;
199
+ // change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
200
+ const clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
201
+ clonedMaterial.metadata = Object.assign(Object.assign({}, mat.metadata), { clonedFrom: mat.uniqueId }); // create shallow copy of metadata on clone. see https://forum.babylonjs.com/t/the-metadata-of-the-mesh-cloned-by-the-instantiatemodelstoscene-method-is-a-shallow-copy/21563
202
+ clonedMaterial.refractionTexture = null;
203
+ clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
204
+ clonedMaterial.alpha = 0.7;
205
+ clonedMaterial.albedoColor = new math_color_1.Color3(0.3, 0.3, 0.3);
206
+ clonedMaterial.transparencyMode = pbrMaterial_1.PBRMaterial.PBRMATERIAL_ALPHABLEND;
207
+ clonedMaterial.metallic = 0.65;
208
+ clonedMaterial.roughness = 0.15;
209
+ return clonedMaterial;
210
+ }
211
+ /**
212
+ * Inspect if a material was temporarily cloned for GLB export
213
+ * @param mat Material to be inspected
214
+ */
215
+ isMaterialClonedForExport(mat) {
216
+ var _a;
217
+ return !!((_a = mat.metadata) === null || _a === void 0 ? void 0 : _a.clonedFrom);
218
+ }
219
+ /**
220
+ * Set unique mesh names for GLB export
221
+ */
222
+ setUniqueMeshNames() {
223
+ this.viewer.scene.meshes.forEach(currMesh => {
224
+ (0, babylonHelper_1.injectNodeMetadata)(currMesh, { [GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY]: currMesh.name }, false);
225
+ currMesh.name = `${currMesh.name}_${currMesh.uniqueId}`;
226
+ });
227
+ }
228
+ /**
229
+ * Restore original mesh names for meshes that were
230
+ * renamed with {@link setUniqueMeshNames()}
231
+ */
232
+ restoreOriginalMeshNames() {
233
+ this.viewer.scene.meshes.forEach(currMesh => {
234
+ if ((0, lodash_es_1.has)(currMesh.metadata, GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY)) {
235
+ currMesh.name = currMesh.metadata[GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY];
236
+ delete currMesh.metadata[GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY];
237
+ }
238
+ });
239
+ }
240
+ }
241
+ exports.GltfExportManager = GltfExportManager;
242
+ GltfExportManager.UNIQUE_MESH_METADATA_PROPERTY = 'originalName';
243
243
  //# sourceMappingURL=gltfExportManager.js.map
@@ -1,33 +1,33 @@
1
- import { ParameterObservable } from '../classes/parameterObservable';
2
- import { TextureLoadManager } from './textureLoadManager';
3
- import { Camera } from '@babylonjs/core/Cameras/camera';
4
- import { Scene as BabylonScene } from '@babylonjs/core/scene';
5
- export declare class SceneManager extends ParameterObservable {
6
- scene: BabylonScene;
7
- protected readonly _parameterObservers: Map<string, ParameterObserver[]>;
8
- protected _textureLoadManager: TextureLoadManager | null;
9
- /**
10
- * Constructor.
11
- */
12
- protected constructor(scene: BabylonScene);
13
- /**
14
- * Creates a {@link SceneManager} based on given Babylon.js scene.
15
- */
16
- static create(scene: BabylonScene): Promise<SceneManager>;
17
- /**
18
- * The active `Camera`.
19
- */
20
- get activeCamera(): Camera;
21
- /**
22
- * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
23
- * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
24
- *
25
- * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
26
- */
27
- commitParameters(parameters?: ParameterBag): Promise<SceneManager>;
28
- protected addParameterObservers(): SceneManager;
29
- /**
30
- * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
31
- */
32
- protected bootstrapParameters(parameters?: ParameterBag): Promise<SceneManager>;
33
- }
1
+ import { ParameterObservable } from '../classes/parameterObservable';
2
+ import { TextureLoadManager } from './textureLoadManager';
3
+ import { Camera } from '@babylonjs/core/Cameras/camera';
4
+ import { Scene as BabylonScene } from '@babylonjs/core/scene';
5
+ export declare class SceneManager extends ParameterObservable {
6
+ scene: BabylonScene;
7
+ protected readonly _parameterObservers: Map<string, ParameterObserver[]>;
8
+ protected _textureLoadManager: TextureLoadManager | null;
9
+ /**
10
+ * Constructor.
11
+ */
12
+ protected constructor(scene: BabylonScene);
13
+ /**
14
+ * Creates a {@link SceneManager} based on given Babylon.js scene.
15
+ */
16
+ static create(scene: BabylonScene): Promise<SceneManager>;
17
+ /**
18
+ * The active `Camera`.
19
+ */
20
+ get activeCamera(): Camera;
21
+ /**
22
+ * Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
23
+ * {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
24
+ *
25
+ * @emit {@link Event.SCENE_PARAMETER_COMMITTED}
26
+ */
27
+ commitParameters(parameters?: ParameterBag): Promise<SceneManager>;
28
+ protected addParameterObservers(): SceneManager;
29
+ /**
30
+ * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
31
+ */
32
+ protected bootstrapParameters(parameters?: ParameterBag): Promise<SceneManager>;
33
+ }