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