@combeenation/3d-viewer 12.4.0 → 12.4.1-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/dist/lib-cjs/api/manager/gltfExportManager.d.ts +10 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js +26 -8
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api/manager/gltfExportManager.ts +32 -8
package/package.json
CHANGED
|
@@ -4,12 +4,14 @@ import { getIsScaledDownDevice } from '../util/deviceHelper';
|
|
|
4
4
|
import { bakeGeometryOfMesh, createMeshFromInstancedMesh, resetTransformation } from '../util/geometryHelper';
|
|
5
5
|
import { isNodeIncludedInExclusionList } from '../util/structureHelper';
|
|
6
6
|
import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
|
|
7
|
+
import { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture';
|
|
7
8
|
import { RenderTargetTexture } from '@babylonjs/core/Materials/Textures/renderTargetTexture';
|
|
8
9
|
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
9
10
|
import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
|
|
10
11
|
import { Mesh } from '@babylonjs/core/Meshes/mesh';
|
|
11
12
|
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
12
13
|
import { Node as BjsNode } from '@babylonjs/core/node';
|
|
14
|
+
import '@babylonjs/serializers/glTF/2.0/Extensions/KHR_texture_transform';
|
|
13
15
|
import { GLTF2Export } from '@babylonjs/serializers/glTF/2.0/glTFSerializer';
|
|
14
16
|
|
|
15
17
|
export class GltfExportManager {
|
|
@@ -292,20 +294,42 @@ export class GltfExportManager {
|
|
|
292
294
|
/**
|
|
293
295
|
* Creates a clone of the material which should be used for the export.
|
|
294
296
|
* This is mostly required for recreating textures with lower sizes.
|
|
295
|
-
*
|
|
297
|
+
* CAUTION: Material exchanging is not supported for materials that contain certain texture types:
|
|
298
|
+
* - Dynamic textures (Paintables): Cloning dynamic textures doesn't clone the canvas context
|
|
299
|
+
* => so the clone is just empty
|
|
300
|
+
* - Render target textures: Disposing the clone will leave the scene in a "not ready" state
|
|
301
|
+
* => this scenario is not fully analyzed yet, but it's not really worth the effort right now, since this kind of
|
|
302
|
+
* of texture is not really used ATM
|
|
303
|
+
*
|
|
304
|
+
* dynamic textures (paintables) or render
|
|
305
|
+
* target textures, as there are speci
|
|
296
306
|
*/
|
|
297
307
|
protected static _exchangeMaterial(material: Material) {
|
|
308
|
+
const baseTextures = material.getActiveTextures();
|
|
309
|
+
const hasDynamicTextures = baseTextures.some(texture => texture instanceof DynamicTexture);
|
|
310
|
+
const hasRenderTargetTextures = baseTextures.some(texture => texture instanceof RenderTargetTexture);
|
|
311
|
+
if (hasDynamicTextures || hasRenderTargetTextures) {
|
|
312
|
+
const textureTypesString = [
|
|
313
|
+
hasDynamicTextures ? 'Dynamic Textures' : '',
|
|
314
|
+
hasRenderTargetTextures ? 'Render Target Textures' : '',
|
|
315
|
+
]
|
|
316
|
+
.filter(Boolean)
|
|
317
|
+
.join();
|
|
318
|
+
console.warn(
|
|
319
|
+
`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.`
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
298
325
|
const newName = `${material.name}_clone`;
|
|
299
326
|
const clonedMaterial = material.clone(newName)!;
|
|
327
|
+
const clonedTextures = clonedMaterial.getActiveTextures();
|
|
300
328
|
|
|
301
329
|
// mark all exported textures, so that they will be deleted after the export
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
clonedMaterial
|
|
306
|
-
.getActiveTextures()
|
|
307
|
-
.filter(texture => !(texture instanceof RenderTargetTexture))
|
|
308
|
-
.forEach(texture => injectMetadata(texture, { [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true }));
|
|
330
|
+
clonedTextures.forEach(texture =>
|
|
331
|
+
injectMetadata(texture, { [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true })
|
|
332
|
+
);
|
|
309
333
|
|
|
310
334
|
injectMetadata(material, { [GltfExportManager._METADATA_PROPS.exchangeMaterialWith]: clonedMaterial.uniqueId });
|
|
311
335
|
injectMetadata(clonedMaterial, { [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true });
|