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