@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,279 +1,291 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GltfExportManager = void 0;
13
- const index_1 = require("../index");
14
- const device_helper_1 = require("../internal/device-helper");
15
- const geometry_helper_1 = require("../internal/geometry-helper");
16
- const geometry_helper_2 = require("../internal/geometry-helper");
17
- const metadata_helper_1 = require("../internal/metadata-helper");
18
- /**
19
- * Manager for gltf export and augmented reality features
20
- */
21
- class GltfExportManager {
22
- /** @internal */
23
- constructor(viewer) {
24
- this.viewer = viewer;
25
- // store initial max texture size, so that we can restore it in the post processing
26
- this._maxTextureSize = viewer.engine.getCaps().maxTextureSize;
27
- }
28
- /**
29
- * Defines options for the export.
30
- * We don't allow the user to overwrite certain settings, since we rely on properties like `removeNoopRootNodes` to
31
- * stay `true` in order to make the AR export work.
32
- * We could theoretically allow it if AR optimization is not desired, but this may confuse the user.
33
- */
34
- static _gltfExportOptions(optimizeForAR, excluded) {
35
- return {
36
- shouldExportNode: function (node) {
37
- if (optimizeForAR) {
38
- // we explicitely marked nodes, that should be exported in AR mode
39
- return (0, metadata_helper_1.getInternalMetadataValue)(node, 'exportNode');
40
- }
41
- else {
42
- // use the default export node check (enabled state, exclusion list, etc...)
43
- return GltfExportManager._shouldExportNode(node, excluded);
44
- }
45
- },
46
- };
47
- }
48
- /**
49
- * Checks if a node should be available in the export
50
- */
51
- static _shouldExportNode(node, excluded) {
52
- if (!(node instanceof index_1.TransformNode)) {
53
- return false;
54
- }
55
- // TODO WTT: think of adding "BackgroundHelper" and nodes with "infiniteDistance" here as well, at least in AR mode
56
- if (!node.isEnabled()) {
57
- return false;
58
- }
59
- if (excluded && (0, geometry_helper_2.isNodeExcluded)(node, excluded)) {
60
- return false;
61
- }
62
- return true;
63
- }
64
- /**
65
- * Creates a clone of the material which should be used for the export.
66
- * This is mostly required for recreating textures with lower sizes.
67
- * CAUTION: Material exchanging is not supported for materials that contain certain texture types:
68
- * - Dynamic textures (Paintables): Cloning dynamic textures doesn't clone the canvas context
69
- * => so the clone is just empty
70
- * - Render target textures: Disposing the clone will leave the scene in a "not ready" state
71
- * => this scenario is not fully analyzed yet, but it's not really worth the effort right now, since this kind of
72
- * of texture is not really used ATM
73
- */
74
- static _exchangeMaterial(material) {
75
- const baseTextures = material.getActiveTextures();
76
- const hasDynamicTextures = baseTextures.some(texture => texture instanceof index_1.DynamicTexture);
77
- const hasRenderTargetTextures = baseTextures.some(texture => texture instanceof index_1.RenderTargetTexture);
78
- if (hasDynamicTextures || hasRenderTargetTextures) {
79
- const textureTypesString = [
80
- hasDynamicTextures ? 'Dynamic Textures' : '',
81
- hasRenderTargetTextures ? 'Render Target Textures' : '',
82
- ]
83
- .filter(Boolean)
84
- .join();
85
- console.warn(`Couldn't exchange material "${material.name}" in GLB export, as it contains unsupported texture type(s) (${textureTypesString}). The export will still work, but the textures of this material will keep their original size.`);
86
- return;
87
- }
88
- const newName = `${material.name}_clone`;
89
- const clonedMaterial = material.clone(newName);
90
- (0, metadata_helper_1.cloneInternalMetadata)(material, clonedMaterial);
91
- const clonedTextures = clonedMaterial.getActiveTextures();
92
- // mark all exported textures, so that they will be deleted after the export
93
- clonedTextures.forEach(texture => (0, metadata_helper_1.setInternalMetadataValue)(texture, 'deleteAfterExport', true));
94
- (0, metadata_helper_1.setInternalMetadataValue)(material, 'exchangeMaterialWith', clonedMaterial.uniqueId);
95
- (0, metadata_helper_1.setInternalMetadataValue)(clonedMaterial, 'deleteAfterExport', true);
96
- }
97
- /**
98
- * Exports selected nodes to a file.
99
- * @param filename Optional name of the exported .GLB file.
100
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
101
- * is mostly targeting Apples .usdz format.
102
- * @param excluded Optional list of geometry (meshes, elements, variants,...) to be excluded from the export.
103
- */
104
- exportGlb(filename = 'glb-export.glb', optimizeForAR = false, excluded) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- yield this._exportPreProcess(optimizeForAR, excluded);
107
- const glbData = yield index_1.GLTF2Export.GLBAsync(this.viewer.scene, 'dummy', GltfExportManager._gltfExportOptions(optimizeForAR, excluded));
108
- yield this._exportPostProcess(optimizeForAR);
109
- const resBlob = glbData.glTFFiles['dummy.glb'];
110
- // check if result is valid, according to the typings this could also be a string
111
- if (resBlob instanceof Blob) {
112
- if (!filename.endsWith('.glb')) {
113
- filename += '.glb';
114
- }
115
- return new File([resBlob], filename);
116
- }
117
- else {
118
- // result was not a valid blob
119
- return undefined;
120
- }
121
- });
122
- }
123
- /**
124
- * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported seperately.
125
- * @param filename Name of the main (text-based) .GLTF file referring to separate texture files.
126
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
127
- * is mostly targeting Apples .usdz format.
128
- * @param excluded Optional list of geometry (meshes, elements, variants,...) to be excluded from the export.
129
- */
130
- exportGltfToFile(filename, optimizeForAR = false, excluded) {
131
- return __awaiter(this, void 0, void 0, function* () {
132
- yield this._exportPreProcess(optimizeForAR, excluded);
133
- const gltf = yield index_1.GLTF2Export.GLTFAsync(this.viewer.scene, filename, GltfExportManager._gltfExportOptions(optimizeForAR, excluded));
134
- gltf.downloadFiles();
135
- this._exportPostProcess(optimizeForAR);
136
- });
137
- }
138
- /**
139
- * Exports selected nodes to GLB. This results in one binary file.
140
- * @param filename Name of the main (text-based) .GLTF file referring to seperate texture files.
141
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
142
- * is mostly targeting Apples .usdz format.
143
- * @param excluded Optional list of geometry (meshes, elements, variants,...) to be excluded from the export.
144
- */
145
- exportGlbToFile(filename, optimizeForAR = false, excluded) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- yield this._exportPreProcess(optimizeForAR, excluded);
148
- const glb = yield index_1.GLTF2Export.GLBAsync(this.viewer.scene, filename, GltfExportManager._gltfExportOptions(optimizeForAR, excluded));
149
- glb.downloadFiles();
150
- yield this._exportPostProcess(optimizeForAR);
151
- });
152
- }
153
- /**
154
- * Prepares scene for GLB export.
155
- * This is very important for AR exports, since we have to do a lot of conversions to satisfy Apples .usdz format.
156
- */
157
- _exportPreProcess(optimizeForAR, excluded) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- if (!optimizeForAR) {
160
- // actually nothing to do if AR optimization is not required
161
- return;
162
- }
163
- // pause rendering, since we are altering the active scene, which should not be visible to the user
164
- this.viewer.pauseRendering();
165
- // exchange materials if required
166
- // the AR export should never contain textures larger than 1024 px:
167
- // - iOS devices will crash most likely when trying to access AR endpoints with such files
168
- // - file size will be reduced, which leads to faster loading times
169
- // - textures > 1024 px shouldn't make a difference on mobiles anyway
170
- // we don't have to rescale anything if are already on a downscaled device, since the textures are already <= 1024
171
- // also we have to be very cautios with copying textures on these devices, since we are potentially very limited
172
- // with the available memory
173
- const isScaledDownDevice = (0, device_helper_1.getIsScaledDownDevice)(this.viewer.viewerSettings.limitTextureSize);
174
- if (!isScaledDownDevice) {
175
- // the idea is to re-create all textures with a smaller texture size
176
- // we have to exchange all materials for this to work
177
- this.viewer.engine.clearInternalTexturesCache();
178
- this.viewer.engine.getCaps().maxTextureSize = 1024;
179
- this.viewer.scene.materials
180
- .filter(material => material instanceof index_1.PBRMaterial)
181
- .forEach(material => GltfExportManager._exchangeMaterial(material));
182
- }
183
- // since Babylon.js v6 the conversion to right handed GLB coordinate system is done differently
184
- // previously the geometry itself has been altered, now they negate the scaling of all root nodes
185
- // this is an issue for us, since we will receive this negated scalings in the exported GLB, which leads to issues
186
- // on iOS devices
187
- // we fix that by adding a top level root node with a negative scaling as well
188
- // the exporter just removes this node as he detects a "noop root node" (implementation details of Babylon.js)
189
- // everything beneath this node remains untouched
190
- // TODO BJS Update: Test AR export on iPhones as well and double check if we still need this special logic
191
- const exportRootNode = new index_1.TransformNode(GltfExportManager._EXPORT_ROOT_NAME, this.viewer.scene);
192
- exportRootNode.scaling = new index_1.Vector3(-1, 1, 1);
193
- (0, metadata_helper_1.setInternalMetadataValue)(exportRootNode, 'exportNode', true);
194
- (0, metadata_helper_1.setInternalMetadataValue)(exportRootNode, 'deleteAfterExport', true);
195
- // create clones of each node (recursively), optionally exchange with cloned materials and mark these nodes for the
196
- // export
197
- this.viewer.scene.rootNodes
198
- .filter(rootNode => rootNode.name !== GltfExportManager._EXPORT_ROOT_NAME)
199
- .forEach(rootNode => this._prepareNodeForExport(rootNode, exportRootNode, excluded));
200
- // bake transformation of all meshes, so that no negative scalings are left
201
- // it's important that this is done AFTER instanced meshes have been converted (_prepareNodeForExport)
202
- this._getNodesMarkedForExport(true).forEach(mesh => (0, geometry_helper_1.bakeGeometryOfMesh)(mesh));
203
- // reset transformation of all "TransformNodes", which couldn't be handled by the geometry baking algorithm
204
- // it's important that this is done AFTER all geometries have been baked
205
- this._getNodesMarkedForExport().forEach(node => (0, geometry_helper_1.resetTransformation)(node));
206
- });
207
- }
208
- /**
209
- * Cleans up scene after export
210
- */
211
- _exportPostProcess(optimizeForAR) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- if (!optimizeForAR) {
214
- // nothing to do, since no changes have been made without AR optimizations
215
- return;
216
- }
217
- // dispose all nodes, materials and textures that have only been created for the export
218
- this.viewer.scene.rootNodes
219
- .filter(rootNode => (0, metadata_helper_1.getInternalMetadataValue)(rootNode, 'deleteAfterExport'))
220
- .forEach(rootNode => rootNode.dispose());
221
- this.viewer.scene.materials
222
- .filter(mat => (0, metadata_helper_1.getInternalMetadataValue)(mat, 'deleteAfterExport'))
223
- .forEach(material => material.dispose(false, false));
224
- this.viewer.scene.textures
225
- .filter(texture => (0, metadata_helper_1.getInternalMetadataValue)(texture, 'deleteAfterExport'))
226
- .forEach(texture => texture.dispose());
227
- // reset engines max texture size and resume rendering
228
- this.viewer.engine.getCaps().maxTextureSize = this._maxTextureSize;
229
- this.viewer.resumeRendering();
230
- });
231
- }
232
- /**
233
- * Creates a clone of the node which should be used for the export.
234
- * Also switches to the cloned material if required.
235
- */
236
- _prepareNodeForExport(node, clonedParent, excluded) {
237
- if (!GltfExportManager._shouldExportNode(node, excluded)) {
238
- return;
239
- }
240
- // from here on we only have TransformNodes
241
- const transformNode = node;
242
- // clone original node and create unique name (via uniqueId) for the export
243
- const clonedNodeName = `${transformNode.name}_${transformNode.uniqueId}`;
244
- const clonedNode = transformNode instanceof index_1.InstancedMesh
245
- ? (0, geometry_helper_1.createMeshFromInstancedMesh)(transformNode, clonedNodeName, clonedParent)
246
- : transformNode.clone(clonedNodeName, clonedParent, true);
247
- (0, metadata_helper_1.cloneInternalMetadata)(transformNode, clonedNode);
248
- // exchange material
249
- if (clonedNode instanceof index_1.Mesh) {
250
- const exchangeWithMaterial = clonedNode.material && (0, metadata_helper_1.getInternalMetadataValue)(clonedNode.material, 'exchangeMaterialWith');
251
- if (exchangeWithMaterial) {
252
- clonedNode.material = this.viewer.scene.getMaterialByUniqueID(exchangeWithMaterial);
253
- }
254
- }
255
- // signalize that this is a cloned node
256
- (0, metadata_helper_1.setInternalMetadataValue)(clonedNode, 'exportNode', true);
257
- (0, metadata_helper_1.setInternalMetadataValue)(clonedNode, 'deleteAfterExport', true);
258
- // handle children
259
- const childs = transformNode.getChildTransformNodes(true);
260
- childs.forEach(child => this._prepareNodeForExport(child, clonedNode, excluded));
261
- }
262
- /**
263
- * Help function for receiving all nodes that are marked for the export
264
- */
265
- _getNodesMarkedForExport(meshesOnly) {
266
- const nodes = [...this.viewer.scene.meshes];
267
- if (!meshesOnly) {
268
- nodes.push(...this.viewer.scene.transformNodes);
269
- }
270
- const filteredNodes = nodes.filter(node => (0, metadata_helper_1.getInternalMetadataValue)(node, 'exportNode') &&
271
- // in the desired use cases we want to exclude the export root node
272
- // maybe add a parameter if we have to include it in certain scenarios in the future
273
- node.name !== GltfExportManager._EXPORT_ROOT_NAME);
274
- return filteredNodes;
275
- }
276
- }
277
- exports.GltfExportManager = GltfExportManager;
278
- GltfExportManager._EXPORT_ROOT_NAME = '__export_root__';
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GltfExportManager = void 0;
13
+ const index_1 = require("../index");
14
+ const device_helper_1 = require("../internal/device-helper");
15
+ const geometry_helper_1 = require("../internal/geometry-helper");
16
+ const geometry_helper_2 = require("../internal/geometry-helper");
17
+ const metadata_helper_1 = require("../internal/metadata-helper");
18
+ /**
19
+ * Manager for gltf export and augmented reality features
20
+ */
21
+ class GltfExportManager {
22
+ /** @internal */
23
+ constructor(viewer) {
24
+ this.viewer = viewer;
25
+ /**
26
+ * Animation groups which have been removed from the scene before export for AR and which need to be re-added
27
+ * afterwards.
28
+ *
29
+ * AR does not work on Android (i.e. the modelviewer) when animation groups are present in the scene.
30
+ * See CB-10055 for more details.
31
+ */
32
+ this._animationGroupsToRestore = [];
33
+ // store initial max texture size, so that we can restore it in the post processing
34
+ this._maxTextureSize = viewer.engine.getCaps().maxTextureSize;
35
+ }
36
+ /**
37
+ * Defines options for the export.
38
+ * We don't allow the user to overwrite certain settings, since we rely on properties like `removeNoopRootNodes` to
39
+ * stay `true` in order to make the AR export work.
40
+ * We could theoretically allow it if AR optimization is not desired, but this may confuse the user.
41
+ */
42
+ static _gltfExportOptions(optimizeForAR, excluded) {
43
+ return {
44
+ shouldExportNode: function (node) {
45
+ if (optimizeForAR) {
46
+ // we explicitely marked nodes, that should be exported in AR mode
47
+ return (0, metadata_helper_1.getInternalMetadataValue)(node, 'exportNode');
48
+ }
49
+ else {
50
+ // use the default export node check (enabled state, exclusion list, etc...)
51
+ return GltfExportManager._shouldExportNode(node, excluded);
52
+ }
53
+ },
54
+ };
55
+ }
56
+ /**
57
+ * Checks if a node should be available in the export
58
+ */
59
+ static _shouldExportNode(node, excluded) {
60
+ if (!(node instanceof index_1.TransformNode)) {
61
+ return false;
62
+ }
63
+ // TODO WTT: think of adding "BackgroundHelper" and nodes with "infiniteDistance" here as well, at least in AR mode
64
+ if (!node.isEnabled()) {
65
+ return false;
66
+ }
67
+ if (excluded && (0, geometry_helper_2.isNodeExcluded)(node, excluded)) {
68
+ return false;
69
+ }
70
+ return true;
71
+ }
72
+ /**
73
+ * Creates a clone of the material which should be used for the export.
74
+ * This is mostly required for recreating textures with lower sizes.
75
+ * CAUTION: Material exchanging is not supported for materials that contain certain texture types:
76
+ * - Dynamic textures (Paintables): Cloning dynamic textures doesn't clone the canvas context
77
+ * => so the clone is just empty
78
+ * - Render target textures: Disposing the clone will leave the scene in a "not ready" state
79
+ * => this scenario is not fully analyzed yet, but it's not really worth the effort right now, since this kind of
80
+ * of texture is not really used ATM
81
+ */
82
+ static _exchangeMaterial(material) {
83
+ const baseTextures = material.getActiveTextures();
84
+ const hasDynamicTextures = baseTextures.some(texture => texture instanceof index_1.DynamicTexture);
85
+ const hasRenderTargetTextures = baseTextures.some(texture => texture instanceof index_1.RenderTargetTexture);
86
+ if (hasDynamicTextures || hasRenderTargetTextures) {
87
+ const textureTypesString = [
88
+ hasDynamicTextures ? 'Dynamic Textures' : '',
89
+ hasRenderTargetTextures ? 'Render Target Textures' : '',
90
+ ]
91
+ .filter(Boolean)
92
+ .join();
93
+ console.warn(`Couldn't exchange material "${material.name}" in GLB export, as it contains unsupported texture type(s) (${textureTypesString}). The export will still work, but the textures of this material will keep their original size.`);
94
+ return;
95
+ }
96
+ const newName = `${material.name}_clone`;
97
+ const clonedMaterial = material.clone(newName);
98
+ (0, metadata_helper_1.cloneInternalMetadata)(material, clonedMaterial);
99
+ const clonedTextures = clonedMaterial.getActiveTextures();
100
+ // mark all exported textures, so that they will be deleted after the export
101
+ clonedTextures.forEach(texture => (0, metadata_helper_1.setInternalMetadataValue)(texture, 'deleteAfterExport', true));
102
+ (0, metadata_helper_1.setInternalMetadataValue)(material, 'exchangeMaterialWith', clonedMaterial.uniqueId);
103
+ (0, metadata_helper_1.setInternalMetadataValue)(clonedMaterial, 'deleteAfterExport', true);
104
+ }
105
+ /**
106
+ * Exports selected nodes to a file.
107
+ * @param filename Optional name of the exported .GLB file.
108
+ * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
109
+ * is mostly targeting Apples .usdz format.
110
+ * @param excluded Optional list of geometry (meshes, elements, variants,...) to be excluded from the export.
111
+ */
112
+ exportGlb(filename = 'glb-export.glb', optimizeForAR = false, excluded) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ yield this._exportPreProcess(optimizeForAR, excluded);
115
+ const glbData = yield index_1.GLTF2Export.GLBAsync(this.viewer.scene, 'dummy', GltfExportManager._gltfExportOptions(optimizeForAR, excluded));
116
+ yield this._exportPostProcess(optimizeForAR);
117
+ const resBlob = glbData.glTFFiles['dummy.glb'];
118
+ // check if result is valid, according to the typings this could also be a string
119
+ if (resBlob instanceof Blob) {
120
+ if (!filename.endsWith('.glb')) {
121
+ filename += '.glb';
122
+ }
123
+ return new File([resBlob], filename);
124
+ }
125
+ else {
126
+ // result was not a valid blob
127
+ return undefined;
128
+ }
129
+ });
130
+ }
131
+ /**
132
+ * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported seperately.
133
+ * @param filename Name of the main (text-based) .GLTF file referring to separate texture files.
134
+ * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
135
+ * is mostly targeting Apples .usdz format.
136
+ * @param excluded Optional list of geometry (meshes, elements, variants,...) to be excluded from the export.
137
+ */
138
+ exportGltfToFile(filename, optimizeForAR = false, excluded) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ yield this._exportPreProcess(optimizeForAR, excluded);
141
+ const gltf = yield index_1.GLTF2Export.GLTFAsync(this.viewer.scene, filename, GltfExportManager._gltfExportOptions(optimizeForAR, excluded));
142
+ gltf.downloadFiles();
143
+ this._exportPostProcess(optimizeForAR);
144
+ });
145
+ }
146
+ /**
147
+ * Exports selected nodes to GLB. This results in one binary file.
148
+ * @param filename Name of the main (text-based) .GLTF file referring to seperate texture files.
149
+ * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
150
+ * is mostly targeting Apples .usdz format.
151
+ * @param excluded Optional list of geometry (meshes, elements, variants,...) to be excluded from the export.
152
+ */
153
+ exportGlbToFile(filename, optimizeForAR = false, excluded) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ yield this._exportPreProcess(optimizeForAR, excluded);
156
+ const glb = yield index_1.GLTF2Export.GLBAsync(this.viewer.scene, filename, GltfExportManager._gltfExportOptions(optimizeForAR, excluded));
157
+ glb.downloadFiles();
158
+ yield this._exportPostProcess(optimizeForAR);
159
+ });
160
+ }
161
+ /**
162
+ * Prepares scene for GLB export.
163
+ * This is very important for AR exports, since we have to do a lot of conversions to satisfy Apples .usdz format.
164
+ */
165
+ _exportPreProcess(optimizeForAR, excluded) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ if (!optimizeForAR) {
168
+ // actually nothing to do if AR optimization is not required
169
+ return;
170
+ }
171
+ // pause rendering, since we are altering the active scene, which should not be visible to the user
172
+ this.viewer.pauseRendering();
173
+ this._animationGroupsToRestore = [...this.viewer.scene.animationGroups];
174
+ this._animationGroupsToRestore.forEach(x => this.viewer.scene.removeAnimationGroup(x));
175
+ // exchange materials if required
176
+ // the AR export should never contain textures larger than 1024 px:
177
+ // - iOS devices will crash most likely when trying to access AR endpoints with such files
178
+ // - file size will be reduced, which leads to faster loading times
179
+ // - textures > 1024 px shouldn't make a difference on mobiles anyway
180
+ // we don't have to rescale anything if are already on a downscaled device, since the textures are already <= 1024
181
+ // also we have to be very cautios with copying textures on these devices, since we are potentially very limited
182
+ // with the available memory
183
+ const isScaledDownDevice = (0, device_helper_1.getIsScaledDownDevice)(this.viewer.viewerSettings.limitTextureSize);
184
+ if (!isScaledDownDevice) {
185
+ // the idea is to re-create all textures with a smaller texture size
186
+ // we have to exchange all materials for this to work
187
+ this.viewer.engine.clearInternalTexturesCache();
188
+ this.viewer.engine.getCaps().maxTextureSize = 1024;
189
+ this.viewer.scene.materials
190
+ .filter(material => material instanceof index_1.PBRMaterial)
191
+ .forEach(material => GltfExportManager._exchangeMaterial(material));
192
+ }
193
+ // since Babylon.js v6 the conversion to right handed GLB coordinate system is done differently
194
+ // previously the geometry itself has been altered, now they negate the scaling of all root nodes
195
+ // this is an issue for us, since we will receive this negated scalings in the exported GLB, which leads to issues
196
+ // on iOS devices
197
+ // we fix that by adding a top level root node with a negative scaling as well
198
+ // the exporter just removes this node as he detects a "noop root node" (implementation details of Babylon.js)
199
+ // everything beneath this node remains untouched
200
+ // TODO BJS Update: Test AR export on iPhones as well and double check if we still need this special logic
201
+ const exportRootNode = new index_1.TransformNode(GltfExportManager._EXPORT_ROOT_NAME, this.viewer.scene);
202
+ exportRootNode.scaling = new index_1.Vector3(-1, 1, 1);
203
+ (0, metadata_helper_1.setInternalMetadataValue)(exportRootNode, 'exportNode', true);
204
+ (0, metadata_helper_1.setInternalMetadataValue)(exportRootNode, 'deleteAfterExport', true);
205
+ // create clones of each node (recursively), optionally exchange with cloned materials and mark these nodes for the
206
+ // export
207
+ this.viewer.scene.rootNodes
208
+ .filter(rootNode => rootNode.name !== GltfExportManager._EXPORT_ROOT_NAME)
209
+ .forEach(rootNode => this._prepareNodeForExport(rootNode, exportRootNode, excluded));
210
+ // bake transformation of all meshes, so that no negative scalings are left
211
+ // it's important that this is done AFTER instanced meshes have been converted (_prepareNodeForExport)
212
+ this._getNodesMarkedForExport(true).forEach(mesh => (0, geometry_helper_1.bakeGeometryOfMesh)(mesh));
213
+ // reset transformation of all "TransformNodes", which couldn't be handled by the geometry baking algorithm
214
+ // it's important that this is done AFTER all geometries have been baked
215
+ this._getNodesMarkedForExport().forEach(node => (0, geometry_helper_1.resetTransformation)(node));
216
+ });
217
+ }
218
+ /**
219
+ * Cleans up scene after export
220
+ */
221
+ _exportPostProcess(optimizeForAR) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ if (!optimizeForAR) {
224
+ // nothing to do, since no changes have been made without AR optimizations
225
+ return;
226
+ }
227
+ this._animationGroupsToRestore.forEach(x => this.viewer.scene.addAnimationGroup(x));
228
+ this._animationGroupsToRestore = [];
229
+ // dispose all nodes, materials and textures that have only been created for the export
230
+ this.viewer.scene.rootNodes
231
+ .filter(rootNode => (0, metadata_helper_1.getInternalMetadataValue)(rootNode, 'deleteAfterExport'))
232
+ .forEach(rootNode => rootNode.dispose());
233
+ this.viewer.scene.materials
234
+ .filter(mat => (0, metadata_helper_1.getInternalMetadataValue)(mat, 'deleteAfterExport'))
235
+ .forEach(material => material.dispose(false, false));
236
+ this.viewer.scene.textures
237
+ .filter(texture => (0, metadata_helper_1.getInternalMetadataValue)(texture, 'deleteAfterExport'))
238
+ .forEach(texture => texture.dispose());
239
+ // reset engines max texture size and resume rendering
240
+ this.viewer.engine.getCaps().maxTextureSize = this._maxTextureSize;
241
+ this.viewer.resumeRendering();
242
+ });
243
+ }
244
+ /**
245
+ * Creates a clone of the node which should be used for the export.
246
+ * Also switches to the cloned material if required.
247
+ */
248
+ _prepareNodeForExport(node, clonedParent, excluded) {
249
+ if (!GltfExportManager._shouldExportNode(node, excluded)) {
250
+ return;
251
+ }
252
+ // from here on we only have TransformNodes
253
+ const transformNode = node;
254
+ // clone original node and create unique name (via uniqueId) for the export
255
+ const clonedNodeName = `${transformNode.name}_${transformNode.uniqueId}`;
256
+ const clonedNode = transformNode instanceof index_1.InstancedMesh
257
+ ? (0, geometry_helper_1.createMeshFromInstancedMesh)(transformNode, clonedNodeName, clonedParent)
258
+ : transformNode.clone(clonedNodeName, clonedParent, true);
259
+ (0, metadata_helper_1.cloneInternalMetadata)(transformNode, clonedNode);
260
+ // exchange material
261
+ if (clonedNode instanceof index_1.Mesh) {
262
+ const exchangeWithMaterial = clonedNode.material && (0, metadata_helper_1.getInternalMetadataValue)(clonedNode.material, 'exchangeMaterialWith');
263
+ if (exchangeWithMaterial) {
264
+ clonedNode.material = this.viewer.scene.getMaterialByUniqueID(exchangeWithMaterial);
265
+ }
266
+ }
267
+ // signalize that this is a cloned node
268
+ (0, metadata_helper_1.setInternalMetadataValue)(clonedNode, 'exportNode', true);
269
+ (0, metadata_helper_1.setInternalMetadataValue)(clonedNode, 'deleteAfterExport', true);
270
+ // handle children
271
+ const childs = transformNode.getChildTransformNodes(true);
272
+ childs.forEach(child => this._prepareNodeForExport(child, clonedNode, excluded));
273
+ }
274
+ /**
275
+ * Help function for receiving all nodes that are marked for the export
276
+ */
277
+ _getNodesMarkedForExport(meshesOnly) {
278
+ const nodes = [...this.viewer.scene.meshes];
279
+ if (!meshesOnly) {
280
+ nodes.push(...this.viewer.scene.transformNodes);
281
+ }
282
+ const filteredNodes = nodes.filter(node => (0, metadata_helper_1.getInternalMetadataValue)(node, 'exportNode') &&
283
+ // in the desired use cases we want to exclude the export root node
284
+ // maybe add a parameter if we have to include it in certain scenarios in the future
285
+ node.name !== GltfExportManager._EXPORT_ROOT_NAME);
286
+ return filteredNodes;
287
+ }
288
+ }
289
+ exports.GltfExportManager = GltfExportManager;
290
+ GltfExportManager._EXPORT_ROOT_NAME = '__export_root__';
279
291
  //# sourceMappingURL=gltf-export-manager.js.map