@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
- "version": "12.4.0",
3
+ "version": "12.4.1-beta1",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -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
- * Also refraction fixes will be applied.
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
- // CAUTION: disposing `RenderTargetTextures` will leave the scene in a "not ready" state
303
- // I haven't found a solution for this in a certain time, so I'd just leave the in the scene, there are not used
304
- // anyway since their parent material is disposed
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 });