Skip to content

Commit 5d6f663

Browse files
authored
glTF Exporter: Some pruning (#17037)
Some staging for upcoming PRs related to texture work. - Clean up some dead code surrounding preExportTextureAsync - mimeType is eventually sourced from either the texture and/or manually set while converting to metal/rough in exporter. No need to pass it around.
1 parent 0dc6cc1 commit 5d6f663

File tree

4 files changed

+67
-95
lines changed

4 files changed

+67
-95
lines changed

packages/dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { IMaterial, IKHRMaterialsTransmission } from "babylonjs-gltf2interface";
2-
import { ImageMimeType } from "babylonjs-gltf2interface";
32
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
43
import { GLTFExporter } from "../glTFExporter";
54
import type { Material } from "core/Materials/material";
@@ -98,7 +97,7 @@ export class KHR_materials_transmission implements IGLTFExporterExtensionV2 {
9897

9998
if (subSurface.refractionIntensityTexture) {
10099
if (subSurface.useGltfStyleTextures) {
101-
const transmissionTexture = await this._exporter._materialExporter.exportTextureAsync(subSurface.refractionIntensityTexture, ImageMimeType.PNG);
100+
const transmissionTexture = await this._exporter._materialExporter.exportTextureAsync(subSurface.refractionIntensityTexture);
102101
if (transmissionTexture) {
103102
volumeInfo.transmissionTexture = transmissionTexture;
104103
}

packages/dev/serializers/src/glTF/2.0/glTFExporter.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import type {
1515
ITextureInfo,
1616
ISkin,
1717
ICamera,
18+
ImageMimeType,
1819
} from "babylonjs-gltf2interface";
19-
import { AccessorComponentType, AccessorType, CameraType, ImageMimeType } from "babylonjs-gltf2interface";
20+
import { AccessorComponentType, AccessorType, CameraType } from "babylonjs-gltf2interface";
2021
import type { FloatArray, IndicesArray, Nullable } from "core/types";
2122
import { TmpVectors, Quaternion } from "core/Maths/math.vector";
2223
import type { Matrix } from "core/Maths/math.vector";
@@ -30,7 +31,6 @@ import type { Mesh } from "core/Meshes/mesh";
3031
import { AbstractMesh } from "core/Meshes/abstractMesh";
3132
import { InstancedMesh } from "core/Meshes/instancedMesh";
3233
import type { BaseTexture } from "core/Materials/Textures/baseTexture";
33-
import type { Texture } from "core/Materials/Textures/texture";
3434
import { Material } from "core/Materials/material";
3535
import { Engine } from "core/Engines/engine";
3636
import type { Scene } from "core/scene";
@@ -308,12 +308,6 @@ export class GLTFExporter {
308308
return this._ApplyExtension(node, extensions, 0, actionAsync);
309309
}
310310

311-
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/promise-function-async
312-
public _extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>> {
313-
// eslint-disable-next-line @typescript-eslint/promise-function-async
314-
return this._ApplyExtensions(babylonTexture, (extension, node) => extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType));
315-
}
316-
317311
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/promise-function-async
318312
public _extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {
319313
return this._ApplyExtensions(
@@ -1414,9 +1408,9 @@ export class GLTFExporter {
14141408
const hasUVs = vertexBuffers && Object.keys(vertexBuffers).some((kind) => kind.startsWith("uv"));
14151409
babylonMaterial = babylonMaterial instanceof MultiMaterial ? babylonMaterial.subMaterials[subMesh.materialIndex]! : babylonMaterial;
14161410
if (babylonMaterial instanceof PBRBaseMaterial) {
1417-
materialIndex = await this._materialExporter.exportPBRMaterialAsync(babylonMaterial, ImageMimeType.PNG, hasUVs);
1411+
materialIndex = await this._materialExporter.exportPBRMaterialAsync(babylonMaterial, hasUVs);
14181412
} else if (babylonMaterial instanceof StandardMaterial) {
1419-
materialIndex = await this._materialExporter.exportStandardMaterialAsync(babylonMaterial, ImageMimeType.PNG, hasUVs);
1413+
materialIndex = await this._materialExporter.exportStandardMaterialAsync(babylonMaterial, hasUVs);
14201414
} else {
14211415
Logger.Warn(`Unsupported material '${babylonMaterial.name}' with type ${babylonMaterial.getClassName()}`);
14221416
return;

packages/dev/serializers/src/glTF/2.0/glTFExporterExtension.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { ImageMimeType, IMeshPrimitive, INode, IMaterial, ITextureInfo, IAccessor } from "babylonjs-gltf2interface";
1+
import type { IMeshPrimitive, INode, IMaterial, ITextureInfo, IAccessor } from "babylonjs-gltf2interface";
22
import type { Node } from "core/node";
33
import type { Nullable } from "core/types";
44

5-
import type { Texture } from "core/Materials/Textures/texture";
65
import type { IDisposable } from "core/scene";
76

87
import type { IGLTFExporterExtension } from "../glTFFileExporter";
@@ -19,15 +18,6 @@ export var __IGLTFExporterExtensionV2 = 0; // I am here to allow dts to be creat
1918
* @internal
2019
*/
2120
export interface IGLTFExporterExtensionV2 extends IGLTFExporterExtension, IDisposable {
22-
/**
23-
* Define this method to modify the default behavior before exporting a texture
24-
* @param context The context when loading the asset
25-
* @param babylonTexture The Babylon.js texture
26-
* @param mimeType The mime-type of the generated image
27-
* @returns A promise that resolves with the exported texture
28-
*/
29-
preExportTextureAsync?(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Promise<Nullable<Texture>>;
30-
3121
/**
3222
* Define this method to get notified when a texture info is created
3323
* @param context The context when loading the asset

0 commit comments

Comments
 (0)