@combeenation/3d-viewer 12.4.0 → 12.4.1-beta1
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 +9 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js +25 -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 +31 -8
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ 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';
|
|
@@ -292,20 +293,42 @@ export class GltfExportManager {
|
|
|
292
293
|
/**
|
|
293
294
|
* Creates a clone of the material which should be used for the export.
|
|
294
295
|
* This is mostly required for recreating textures with lower sizes.
|
|
295
|
-
*
|
|
296
|
+
* CAUTION: Material exchanging is not supported for materials that contain certain texture types:
|
|
297
|
+
* - Dynamic textures (Paintables): Cloning dynamic textures doesn't clone the canvas context
|
|
298
|
+
* => so the clone is just empty
|
|
299
|
+
* - Render target textures: Disposing the clone will leave the scene in a "not ready" state
|
|
300
|
+
* => this scenario is not fully analyzed yet, but it's not really worth the effort right now, since this kind of
|
|
301
|
+
* of texture is not really used ATM
|
|
302
|
+
*
|
|
303
|
+
* dynamic textures (paintables) or render
|
|
304
|
+
* target textures, as there are speci
|
|
296
305
|
*/
|
|
297
306
|
protected static _exchangeMaterial(material: Material) {
|
|
307
|
+
const baseTextures = material.getActiveTextures();
|
|
308
|
+
const hasDynamicTextures = baseTextures.some(texture => texture instanceof DynamicTexture);
|
|
309
|
+
const hasRenderTargetTextures = baseTextures.some(texture => texture instanceof RenderTargetTexture);
|
|
310
|
+
if (hasDynamicTextures || hasRenderTargetTextures) {
|
|
311
|
+
const textureTypesString = [
|
|
312
|
+
hasDynamicTextures ? 'Dynamic Textures' : '',
|
|
313
|
+
hasRenderTargetTextures ? 'Render Target Textures' : '',
|
|
314
|
+
]
|
|
315
|
+
.filter(Boolean)
|
|
316
|
+
.join();
|
|
317
|
+
console.warn(
|
|
318
|
+
`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.`
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
298
324
|
const newName = `${material.name}_clone`;
|
|
299
325
|
const clonedMaterial = material.clone(newName)!;
|
|
326
|
+
const clonedTextures = clonedMaterial.getActiveTextures();
|
|
300
327
|
|
|
301
328
|
// 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 }));
|
|
329
|
+
clonedTextures.forEach(texture =>
|
|
330
|
+
injectMetadata(texture, { [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true })
|
|
331
|
+
);
|
|
309
332
|
|
|
310
333
|
injectMetadata(material, { [GltfExportManager._METADATA_PROPS.exchangeMaterialWith]: clonedMaterial.uniqueId });
|
|
311
334
|
injectMetadata(clonedMaterial, { [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true });
|