@combeenation/3d-viewer 5.0.1 → 5.0.3-beta2
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 +111 -114
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +187 -187
- package/dist/lib-cjs/api/classes/element.d.ts +139 -139
- package/dist/lib-cjs/api/classes/element.js +794 -794
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js +135 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js.map +1 -0
- package/dist/lib-cjs/api/classes/event.d.ts +326 -326
- package/dist/lib-cjs/api/classes/event.js +371 -371
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
- package/dist/lib-cjs/api/classes/parameter.d.ts +316 -259
- package/dist/lib-cjs/api/classes/parameter.js +451 -388
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +101 -101
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +44 -44
- package/dist/lib-cjs/api/classes/placementAnimation.js +163 -163
- package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
- package/dist/lib-cjs/api/classes/variant.js +1154 -1154
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
- package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +99 -99
- package/dist/lib-cjs/api/classes/viewer.d.ts +177 -175
- package/dist/lib-cjs/api/classes/viewer.js +717 -701
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +392 -392
- package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
- package/dist/lib-cjs/api/internal/debugViewer.js +86 -86
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -10
- package/dist/lib-cjs/api/internal/sceneSetup.js +238 -234
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
- package/dist/lib-cjs/api/manager/animationManager.js +130 -130
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
- package/dist/lib-cjs/api/manager/gltfExportManager.js +223 -222
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -32
- package/dist/lib-cjs/api/manager/sceneManager.js +153 -132
- package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +335 -335
- package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
- package/dist/lib-cjs/api/store/specStorage.js +51 -51
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -166
- package/dist/lib-cjs/api/util/babylonHelper.js +575 -497
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -356
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -53
- package/dist/lib-cjs/api/util/resourceHelper.js +257 -242
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/stringHelper.js +25 -25
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +48 -44
- package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/index.d.ts +49 -49
- package/dist/lib-cjs/index.js +89 -89
- package/dist/webpack-stats.json +0 -0
- package/package.json +87 -87
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +690 -692
- package/src/api/classes/event.ts +367 -367
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/parameter.ts +474 -405
- package/src/api/classes/parameterObservable.ts +100 -100
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +160 -160
- package/src/api/classes/variant.ts +845 -845
- package/src/api/classes/variantInstance.ts +97 -97
- package/src/api/classes/variantParameterizable.ts +85 -85
- package/src/api/classes/viewer.ts +650 -624
- package/src/api/classes/viewerLight.ts +334 -334
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +10 -10
- package/src/api/internal/sceneSetup.ts +204 -201
- package/src/api/manager/animationManager.ts +142 -142
- package/src/api/manager/gltfExportManager.ts +191 -191
- package/src/api/manager/sceneManager.ts +128 -102
- package/src/api/manager/variantInstanceManager.ts +265 -265
- package/src/api/store/specStorage.ts +51 -51
- package/src/api/util/babylonHelper.ts +628 -538
- package/src/api/util/globalTypes.ts +413 -402
- package/src/api/util/resourceHelper.ts +189 -173
- package/src/api/util/stringHelper.ts +23 -23
- package/src/api/util/structureHelper.ts +49 -43
- package/src/buildinfo.json +3 -3
- package/src/commonjs.tsconfig.json +10 -10
- package/src/declaration.tsconfig.json +8 -8
- package/src/dev.ts +42 -42
- package/src/es6.tsconfig.json +10 -10
- package/src/index.ts +94 -94
- package/src/pagesconfig.json +77 -73
- package/src/tsconfig.json +32 -32
- package/src/tsconfig.types.json +9 -9
- package/src/types.d.ts +3 -3
|
@@ -1,223 +1,224 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GltfExportManager = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var GltfExportManager = /** @class */ (function () {
|
|
13
|
-
/**
|
|
14
|
-
* Constructor.
|
|
15
|
-
*/
|
|
16
|
-
function GltfExportManager(viewer) {
|
|
17
|
-
this.viewer = viewer;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Creates an {@link GltfExportManager}.
|
|
21
|
-
*/
|
|
22
|
-
GltfExportManager.create = function (viewer) {
|
|
23
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
24
|
-
return tslib_1.__generator(this, function (_a) {
|
|
25
|
-
return [2 /*return*/, new GltfExportManager(viewer)];
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Exports selected nodes to a file.
|
|
31
|
-
* @param filename optional name of the exported .GLB file.
|
|
32
|
-
* @param exportOptions export options to be merged with default options.
|
|
33
|
-
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
34
|
-
*/
|
|
35
|
-
GltfExportManager.prototype.exportGlb = function (filename, exportOptions, excluded) {
|
|
36
|
-
if (filename === void 0) { filename = 'glb-export.glb'; }
|
|
37
|
-
if (exportOptions === void 0) { exportOptions = {}; }
|
|
38
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
39
|
-
var glbData, resBlob;
|
|
40
|
-
return tslib_1.__generator(this, function (_a) {
|
|
41
|
-
switch (_a.label) {
|
|
42
|
-
case 0:
|
|
43
|
-
this.exportPreProcess();
|
|
44
|
-
return [4 /*yield*/,
|
|
45
|
-
case 1:
|
|
46
|
-
glbData = _a.sent();
|
|
47
|
-
this.exportPostProcess();
|
|
48
|
-
resBlob = glbData.glTFFiles['dummy.glb'];
|
|
49
|
-
// check if result is valid, according to the typings this could also be a string
|
|
50
|
-
if (resBlob instanceof Blob) {
|
|
51
|
-
if (!filename.endsWith('.glb')) {
|
|
52
|
-
filename += '.glb';
|
|
53
|
-
}
|
|
54
|
-
return [2 /*return*/, new File([resBlob], filename)];
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// result was not a valid blob
|
|
58
|
-
return [2 /*return*/, undefined];
|
|
59
|
-
}
|
|
60
|
-
return [2 /*return*/];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
|
|
67
|
-
* @param filename name of the main (text-based) .GLTF file referring to separate texture files.
|
|
68
|
-
* @param exportOptions export options to be merged with default options.
|
|
69
|
-
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
70
|
-
*/
|
|
71
|
-
GltfExportManager.prototype.exportGltfToFile = function (filename, exportOptions, excluded) {
|
|
72
|
-
if (exportOptions === void 0) { exportOptions = {}; }
|
|
73
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
74
|
-
return tslib_1.__generator(this, function (_a) {
|
|
75
|
-
switch (_a.label) {
|
|
76
|
-
case 0:
|
|
77
|
-
this.exportPreProcess();
|
|
78
|
-
return [4 /*yield*/,
|
|
79
|
-
glb.downloadFiles();
|
|
80
|
-
})];
|
|
81
|
-
case 1:
|
|
82
|
-
_a.sent();
|
|
83
|
-
this.exportPostProcess();
|
|
84
|
-
return [2 /*return*/];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Exports selected nodes to GLB. This results in one binary file.
|
|
91
|
-
* @param filename name of the .GLB file.
|
|
92
|
-
* @param exportOptions export options to be merged with default options.
|
|
93
|
-
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
94
|
-
*/
|
|
95
|
-
GltfExportManager.prototype.exportGlbToFile = function (filename, exportOptions, excluded) {
|
|
96
|
-
if (exportOptions === void 0) { exportOptions = {}; }
|
|
97
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
98
|
-
return tslib_1.__generator(this, function (_a) {
|
|
99
|
-
switch (_a.label) {
|
|
100
|
-
case 0:
|
|
101
|
-
this.exportPreProcess();
|
|
102
|
-
return [4 /*yield*/,
|
|
103
|
-
glb.downloadFiles();
|
|
104
|
-
})];
|
|
105
|
-
case 1:
|
|
106
|
-
_a.sent();
|
|
107
|
-
this.exportPostProcess();
|
|
108
|
-
return [2 /*return*/];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Gets predefined {@link IExportOptions } merged with given ones.
|
|
115
|
-
*/
|
|
116
|
-
GltfExportManager.prototype.gltfExportOptions = function (mergeWithOptions, excluded) {
|
|
117
|
-
if (mergeWithOptions === void 0) { mergeWithOptions = {}; }
|
|
118
|
-
var defaultOptions = {
|
|
119
|
-
// includeCoordinateSystemConversionNodes: true,
|
|
120
|
-
shouldExportNode: function (node) {
|
|
121
|
-
if (!node.isEnabled()) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (node.isVisible === false) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (node.name === '__bounding_box__') {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
if (excluded && node instanceof
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
return lodash_es_1.merge({}, defaultOptions, mergeWithOptions);
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* Stuff to be done before exporting to GLTF
|
|
140
|
-
*/
|
|
141
|
-
GltfExportManager.prototype.exportPreProcess = function () {
|
|
142
|
-
this.viewer.pauseRendering();
|
|
143
|
-
this.exchangeRefractionMaterials();
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Stuff to be done after the GLTF export
|
|
147
|
-
*/
|
|
148
|
-
GltfExportManager.prototype.exportPostProcess = function () {
|
|
149
|
-
this.restoreRefractionMaterials();
|
|
150
|
-
this.viewer.resumeRendering();
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Materials with refraction set are not exported properly.
|
|
154
|
-
* Exchange all such (relevant) materials with a more export-friendly version
|
|
155
|
-
*/
|
|
156
|
-
GltfExportManager.prototype.exchangeRefractionMaterials = function () {
|
|
157
|
-
for (var _i = 0, _a = this.viewer.scene.getNodes(); _i < _a.length; _i++) {
|
|
158
|
-
var n = _a[_i];
|
|
159
|
-
if (!(n instanceof abstractMesh_1.AbstractMesh))
|
|
160
|
-
continue;
|
|
161
|
-
if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
|
|
162
|
-
continue;
|
|
163
|
-
if (!n.material.subSurface.isRefractionEnabled)
|
|
164
|
-
continue;
|
|
165
|
-
if (n.material.transparencyMode !== pbrMaterial_1.PBRMaterial.PBRMATERIAL_OPAQUE)
|
|
166
|
-
continue;
|
|
167
|
-
// if we're here, we have a node holding a material with set refraction whose transparencyMode is set to PBRMATERIAL_OPAQUE
|
|
168
|
-
n.material = this.createRefractionMaterialReplacement(n.material);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Restore original materials with set refraction.
|
|
173
|
-
*/
|
|
174
|
-
GltfExportManager.prototype.restoreRefractionMaterials = function () {
|
|
175
|
-
for (var _i = 0, _a = this.viewer.scene.getNodes(); _i < _a.length; _i++) {
|
|
176
|
-
var n = _a[_i];
|
|
177
|
-
if (!(n instanceof abstractMesh_1.AbstractMesh))
|
|
178
|
-
continue;
|
|
179
|
-
if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
|
|
180
|
-
continue;
|
|
181
|
-
if (!this.isMaterialClonedForExport(n.material))
|
|
182
|
-
continue;
|
|
183
|
-
// at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
|
|
184
|
-
// restore and dispose
|
|
185
|
-
var currMaterial = n.material;
|
|
186
|
-
var prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
|
|
187
|
-
if (prevMaterial) {
|
|
188
|
-
n.material = prevMaterial; // restore previous material
|
|
189
|
-
currMaterial.dispose(false, true); // dispose of clone
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* Create an export-friendly replacement material for a material using refraction.
|
|
195
|
-
* @param mat Material to be replaced
|
|
196
|
-
*/
|
|
197
|
-
GltfExportManager.prototype.createRefractionMaterialReplacement = function (mat) {
|
|
198
|
-
// if we're dealing with a clone already, return it instead of cloning
|
|
199
|
-
if (this.isMaterialClonedForExport(mat))
|
|
200
|
-
return mat;
|
|
201
|
-
// change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
|
|
202
|
-
var clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
|
|
203
|
-
clonedMaterial.metadata = tslib_1.__assign(tslib_1.__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
|
|
204
|
-
clonedMaterial.refractionTexture = null;
|
|
205
|
-
clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
|
|
206
|
-
clonedMaterial.alpha = 0.7;
|
|
207
|
-
clonedMaterial.albedoColor = new math_color_1.Color3(0.3, 0.3, 0.3);
|
|
208
|
-
clonedMaterial.transparencyMode = pbrMaterial_1.PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
209
|
-
clonedMaterial.metallic = 0.65;
|
|
210
|
-
clonedMaterial.roughness = 0.15;
|
|
211
|
-
return clonedMaterial;
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Inspect if a material was temporarily cloned for GLB export
|
|
215
|
-
* @param mat Material to be inspected
|
|
216
|
-
*/
|
|
217
|
-
GltfExportManager.prototype.isMaterialClonedForExport = function (mat) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GltfExportManager = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var pbrMaterial_1 = require("@babylonjs/core/Materials/PBR/pbrMaterial");
|
|
6
|
+
var math_color_1 = require("@babylonjs/core/Maths/math.color");
|
|
7
|
+
var abstractMesh_1 = require("@babylonjs/core/Meshes/abstractMesh");
|
|
8
|
+
var _2_0_1 = require("@babylonjs/serializers/glTF/2.0");
|
|
9
|
+
var structureHelper_1 = require("../util/structureHelper");
|
|
10
|
+
var lodash_es_1 = require("lodash-es");
|
|
11
|
+
var mesh_1 = require("@babylonjs/core/Meshes/mesh");
|
|
12
|
+
var GltfExportManager = /** @class */ (function () {
|
|
13
|
+
/**
|
|
14
|
+
* Constructor.
|
|
15
|
+
*/
|
|
16
|
+
function GltfExportManager(viewer) {
|
|
17
|
+
this.viewer = viewer;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an {@link GltfExportManager}.
|
|
21
|
+
*/
|
|
22
|
+
GltfExportManager.create = function (viewer) {
|
|
23
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
24
|
+
return tslib_1.__generator(this, function (_a) {
|
|
25
|
+
return [2 /*return*/, new GltfExportManager(viewer)];
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Exports selected nodes to a file.
|
|
31
|
+
* @param filename optional name of the exported .GLB file.
|
|
32
|
+
* @param exportOptions export options to be merged with default options.
|
|
33
|
+
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
34
|
+
*/
|
|
35
|
+
GltfExportManager.prototype.exportGlb = function (filename, exportOptions, excluded) {
|
|
36
|
+
if (filename === void 0) { filename = 'glb-export.glb'; }
|
|
37
|
+
if (exportOptions === void 0) { exportOptions = {}; }
|
|
38
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
39
|
+
var glbData, resBlob;
|
|
40
|
+
return tslib_1.__generator(this, function (_a) {
|
|
41
|
+
switch (_a.label) {
|
|
42
|
+
case 0:
|
|
43
|
+
this.exportPreProcess();
|
|
44
|
+
return [4 /*yield*/, _2_0_1.GLTF2Export.GLBAsync(this.viewer.scene, 'dummy', this.gltfExportOptions(exportOptions, excluded))];
|
|
45
|
+
case 1:
|
|
46
|
+
glbData = _a.sent();
|
|
47
|
+
this.exportPostProcess();
|
|
48
|
+
resBlob = glbData.glTFFiles['dummy.glb'];
|
|
49
|
+
// check if result is valid, according to the typings this could also be a string
|
|
50
|
+
if (resBlob instanceof Blob) {
|
|
51
|
+
if (!filename.endsWith('.glb')) {
|
|
52
|
+
filename += '.glb';
|
|
53
|
+
}
|
|
54
|
+
return [2 /*return*/, new File([resBlob], filename)];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// result was not a valid blob
|
|
58
|
+
return [2 /*return*/, undefined];
|
|
59
|
+
}
|
|
60
|
+
return [2 /*return*/];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
|
|
67
|
+
* @param filename name of the main (text-based) .GLTF file referring to separate texture files.
|
|
68
|
+
* @param exportOptions export options to be merged with default options.
|
|
69
|
+
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export.
|
|
70
|
+
*/
|
|
71
|
+
GltfExportManager.prototype.exportGltfToFile = function (filename, exportOptions, excluded) {
|
|
72
|
+
if (exportOptions === void 0) { exportOptions = {}; }
|
|
73
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
74
|
+
return tslib_1.__generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
this.exportPreProcess();
|
|
78
|
+
return [4 /*yield*/, _2_0_1.GLTF2Export.GLTFAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(function (glb) {
|
|
79
|
+
glb.downloadFiles();
|
|
80
|
+
})];
|
|
81
|
+
case 1:
|
|
82
|
+
_a.sent();
|
|
83
|
+
this.exportPostProcess();
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Exports selected nodes to GLB. This results in one binary file.
|
|
91
|
+
* @param filename name of the .GLB file.
|
|
92
|
+
* @param exportOptions export options to be merged with default options.
|
|
93
|
+
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
94
|
+
*/
|
|
95
|
+
GltfExportManager.prototype.exportGlbToFile = function (filename, exportOptions, excluded) {
|
|
96
|
+
if (exportOptions === void 0) { exportOptions = {}; }
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
98
|
+
return tslib_1.__generator(this, function (_a) {
|
|
99
|
+
switch (_a.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
this.exportPreProcess();
|
|
102
|
+
return [4 /*yield*/, _2_0_1.GLTF2Export.GLBAsync(this.viewer.scene, filename, this.gltfExportOptions(exportOptions, excluded)).then(function (glb) {
|
|
103
|
+
glb.downloadFiles();
|
|
104
|
+
})];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
this.exportPostProcess();
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Gets predefined {@link IExportOptions } merged with given ones.
|
|
115
|
+
*/
|
|
116
|
+
GltfExportManager.prototype.gltfExportOptions = function (mergeWithOptions, excluded) {
|
|
117
|
+
if (mergeWithOptions === void 0) { mergeWithOptions = {}; }
|
|
118
|
+
var defaultOptions = {
|
|
119
|
+
// includeCoordinateSystemConversionNodes: true,
|
|
120
|
+
shouldExportNode: function (node) {
|
|
121
|
+
if (!node.isEnabled()) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (node.isVisible === false) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (node.name === '__bounding_box__') {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (excluded && node instanceof mesh_1.Mesh && structureHelper_1.isMeshIncludedInExclusionList(node, excluded)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return lodash_es_1.merge({}, defaultOptions, mergeWithOptions);
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Stuff to be done before exporting to GLTF
|
|
140
|
+
*/
|
|
141
|
+
GltfExportManager.prototype.exportPreProcess = function () {
|
|
142
|
+
this.viewer.pauseRendering();
|
|
143
|
+
this.exchangeRefractionMaterials();
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Stuff to be done after the GLTF export
|
|
147
|
+
*/
|
|
148
|
+
GltfExportManager.prototype.exportPostProcess = function () {
|
|
149
|
+
this.restoreRefractionMaterials();
|
|
150
|
+
this.viewer.resumeRendering();
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Materials with refraction set are not exported properly.
|
|
154
|
+
* Exchange all such (relevant) materials with a more export-friendly version
|
|
155
|
+
*/
|
|
156
|
+
GltfExportManager.prototype.exchangeRefractionMaterials = function () {
|
|
157
|
+
for (var _i = 0, _a = this.viewer.scene.getNodes(); _i < _a.length; _i++) {
|
|
158
|
+
var n = _a[_i];
|
|
159
|
+
if (!(n instanceof abstractMesh_1.AbstractMesh))
|
|
160
|
+
continue;
|
|
161
|
+
if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
|
|
162
|
+
continue;
|
|
163
|
+
if (!n.material.subSurface.isRefractionEnabled)
|
|
164
|
+
continue;
|
|
165
|
+
if (n.material.transparencyMode !== pbrMaterial_1.PBRMaterial.PBRMATERIAL_OPAQUE)
|
|
166
|
+
continue;
|
|
167
|
+
// if we're here, we have a node holding a material with set refraction whose transparencyMode is set to PBRMATERIAL_OPAQUE
|
|
168
|
+
n.material = this.createRefractionMaterialReplacement(n.material);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Restore original materials with set refraction.
|
|
173
|
+
*/
|
|
174
|
+
GltfExportManager.prototype.restoreRefractionMaterials = function () {
|
|
175
|
+
for (var _i = 0, _a = this.viewer.scene.getNodes(); _i < _a.length; _i++) {
|
|
176
|
+
var n = _a[_i];
|
|
177
|
+
if (!(n instanceof abstractMesh_1.AbstractMesh))
|
|
178
|
+
continue;
|
|
179
|
+
if (!(n.material instanceof pbrMaterial_1.PBRMaterial))
|
|
180
|
+
continue;
|
|
181
|
+
if (!this.isMaterialClonedForExport(n.material))
|
|
182
|
+
continue;
|
|
183
|
+
// at this point we have a pbrmaterial tagged as cloned in its metadata that's set on a mesh
|
|
184
|
+
// restore and dispose
|
|
185
|
+
var currMaterial = n.material;
|
|
186
|
+
var prevMaterial = this.viewer.scene.getMaterialByUniqueID(n.material.metadata.clonedFrom);
|
|
187
|
+
if (prevMaterial) {
|
|
188
|
+
n.material = prevMaterial; // restore previous material
|
|
189
|
+
currMaterial.dispose(false, true); // dispose of clone
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Create an export-friendly replacement material for a material using refraction.
|
|
195
|
+
* @param mat Material to be replaced
|
|
196
|
+
*/
|
|
197
|
+
GltfExportManager.prototype.createRefractionMaterialReplacement = function (mat) {
|
|
198
|
+
// if we're dealing with a clone already, return it instead of cloning
|
|
199
|
+
if (this.isMaterialClonedForExport(mat))
|
|
200
|
+
return mat;
|
|
201
|
+
// change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
|
|
202
|
+
var clonedMaterial = mat.clone(mat.name); // clone material. clone uses same name
|
|
203
|
+
clonedMaterial.metadata = tslib_1.__assign(tslib_1.__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
|
|
204
|
+
clonedMaterial.refractionTexture = null;
|
|
205
|
+
clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
|
|
206
|
+
clonedMaterial.alpha = 0.7;
|
|
207
|
+
clonedMaterial.albedoColor = new math_color_1.Color3(0.3, 0.3, 0.3);
|
|
208
|
+
clonedMaterial.transparencyMode = pbrMaterial_1.PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
209
|
+
clonedMaterial.metallic = 0.65;
|
|
210
|
+
clonedMaterial.roughness = 0.15;
|
|
211
|
+
return clonedMaterial;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Inspect if a material was temporarily cloned for GLB export
|
|
215
|
+
* @param mat Material to be inspected
|
|
216
|
+
*/
|
|
217
|
+
GltfExportManager.prototype.isMaterialClonedForExport = function (mat) {
|
|
218
|
+
var _a;
|
|
219
|
+
return !!((_a = mat.metadata) === null || _a === void 0 ? void 0 : _a.clonedFrom);
|
|
220
|
+
};
|
|
221
|
+
return GltfExportManager;
|
|
222
|
+
}());
|
|
223
|
+
exports.GltfExportManager = GltfExportManager;
|
|
223
224
|
//# sourceMappingURL=gltfExportManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltfExportManager.js","sourceRoot":"","sources":["../../../../src/api/manager/gltfExportManager.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"gltfExportManager.js","sourceRoot":"","sources":["../../../../src/api/manager/gltfExportManager.ts"],"names":[],"mappings":";;;;AAAA,yEAAwE;AACxE,+DAA0D;AAC1D,oEAAmE;AACnE,wDAA8E;AAC9E,2DAAwE;AACxE,uCAAkC;AAClC,oDAAmD;AAEnD;IACE;;OAEG;IACH,2BAAgC,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAElD;;OAEG;IACiB,wBAAM,GAA1B,UAA2B,MAAc;;;gBACvC,sBAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAC;;;KACtC;IAED;;;;;OAKG;IACU,qCAAS,GAAtB,UACE,QAA2B,EAC3B,aAAkC,EAClC,QAA+B;QAF/B,yBAAA,EAAA,2BAA2B;QAC3B,8BAAA,EAAA,kBAAkC;;;;;;wBAGlC,IAAI,CAAC,gBAAgB,EAAE,CAAC;wBACR,qBAAM,kBAAW,CAAC,QAAQ,CACxC,IAAI,CAAC,MAAM,CAAC,KAAK,EACjB,OAAO,EACP,IAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAChD,EAAA;;wBAJK,OAAO,GAAG,SAIf;wBACD,IAAI,CAAC,iBAAiB,EAAE,CAAC;wBACnB,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;wBAE/C,iFAAiF;wBACjF,IAAI,OAAO,YAAY,IAAI,EAAE;4BAC3B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gCAC9B,QAAQ,IAAI,MAAM,CA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AAU,EAAE,GAAG,CAAC,QAAQ,GAAE,CAAC,CAAC,6KAA6K;QACtP,cAAc,CAAC,iBAAiB,GAAG,IAAI,CAAC;QACxC,cAAc,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAAC,kDAAkD;QACpG,cAAc,CAAC,KAAK,GAAG,GAAG,CAAC;QAC3B,cAAc,CAAC,WAAW,GAAG,IAAI,mBAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACvD,cAAc,CAAC,gBAAgB,GAAG,yBAAW,CAAC,sBAAsB,CAAC;QACrE,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,cAAc,CAAC,SAAS,GAAG,IAAI,CAAC;QAEhC,OAAO,cAAc,CAAC;IACxB,CAAC;IAED;;;OAGG;IACO,qDAAyB,GAAnC,UAAoC,GAAgB;;QAClD,OAAO,CAAC,QAAC,GAAG,CAAC,QAAQ,0CAAE,UAAU,CAAA,CAAC;IACpC,CAAC;IACH,wBAAC;AAAD,CAAC,AAtLD,IAsLC;AAtLY,8CAAiB"}
|
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { Camera } from '@babylonjs/core/Cameras/camera';
|
|
2
|
-
import { Scene as BabylonScene } from '@babylonjs/core/scene';
|
|
3
|
-
import { ParameterObservable } from '../classes/parameterObservable';
|
|
4
|
-
export declare class SceneManager extends ParameterObservable {
|
|
5
|
-
scene: BabylonScene;
|
|
6
|
-
protected readonly _parameterObservers: Map<string, ParameterObserver[]>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
1
|
+
import { Camera } from '@babylonjs/core/Cameras/camera';
|
|
2
|
+
import { Scene as BabylonScene } from '@babylonjs/core/scene';
|
|
3
|
+
import { ParameterObservable } from '../classes/parameterObservable';
|
|
4
|
+
export declare class SceneManager extends ParameterObservable {
|
|
5
|
+
scene: BabylonScene;
|
|
6
|
+
protected readonly _parameterObservers: Map<string, ParameterObserver[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Constructor.
|
|
9
|
+
*/
|
|
10
|
+
protected constructor(scene: BabylonScene);
|
|
11
|
+
/**
|
|
12
|
+
* Creates a {@link SceneManager} based on given BabylonJS scene.
|
|
13
|
+
*/
|
|
14
|
+
static create(scene: BabylonScene): Promise<SceneManager>;
|
|
15
|
+
/**
|
|
16
|
+
* The active `Camera`.
|
|
17
|
+
*/
|
|
18
|
+
get activeCamera(): Camera;
|
|
19
|
+
/**
|
|
20
|
+
* Places the given {@link ParameterBag} in the {@link SceneManager}'s parameters, replaces all patterns in the
|
|
21
|
+
* {@link StructureJson} and broadcasts all {@link ParameterObserver}s.
|
|
22
|
+
*
|
|
23
|
+
* @emit {@link Event.SCENE_PARAMETER_COMMITTED}
|
|
24
|
+
*/
|
|
25
|
+
commitParameters(parameters?: ParameterBag): Promise<SceneManager>;
|
|
26
|
+
protected addParameterObservers(): SceneManager;
|
|
27
|
+
/**
|
|
28
|
+
* Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
|
|
29
|
+
*/
|
|
30
|
+
protected bootstrapParameters(parameters?: ParameterBag): Promise<SceneManager>;
|
|
31
|
+
}
|