Skip to content

Commit bff6b83

Browse files
author
Mike Bond
committed
OpenPBRMaterial export to glTF for diffuse roughness
1 parent bb191ec commit bff6b83

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

packages/dev/core/src/Materials/imageProcessing.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import type { Observer } from "../Misc/observable";
66
import type { BaseTexture } from "../Materials/Textures/baseTexture";
77
import type { ColorCurves } from "../Materials/colorCurves";
88

9-
// Explicit re-export of types to help TypeScript resolve them in declaration files
10-
// export type { Observer } from "../Misc/observable";
11-
// export type { ColorCurves } from "./colorCurves";
12-
139
type ImageProcessingMixinConstructor<T = {}> = new (...args: any[]) => T;
1410

1511
/**

packages/dev/inspector/src/components/actionTabs/tabs/propertyGridTabComponent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ export class PropertyGridTabComponent extends PaneComponent {
398398
onPropertyChangedObservable={this.props.onPropertyChangedObservable}
399399
/>
400400
);
401-
} else if (className === "OpenPBRMaterial") {
401+
}
402+
403+
if (className === "OpenPBRMaterial") {
402404
const material = entity as OpenPBRMaterial;
403405
return (
404406
<OpenPBRMaterialPropertyGridComponent

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

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { GLTFExporter } from "../glTFExporter";
44
import type { Material } from "core/Materials/material";
55
import { PBRBaseMaterial } from "core/Materials/PBR/pbrBaseMaterial";
66
import type { BaseTexture } from "core/Materials/Textures/baseTexture";
7+
import { OpenPBRMaterial } from "core/Materials/PBR/openPbrMaterial";
8+
import type { Nullable } from "core/types";
79

810
const NAME = "EXT_materials_diffuse_roughness";
911

@@ -45,6 +47,13 @@ export class EXT_materials_diffuse_roughness implements IGLTFExporterExtensionV2
4547
}
4648
return additionalTextures;
4749
}
50+
} else if (babylonMaterial instanceof OpenPBRMaterial) {
51+
if (babylonMaterial.baseDiffuseRoughness) {
52+
if (babylonMaterial.baseDiffuseRoughnessTexture) {
53+
additionalTextures.push(babylonMaterial.baseDiffuseRoughnessTexture);
54+
}
55+
return additionalTextures;
56+
}
4857
}
4958

5059
return [];
@@ -53,29 +62,37 @@ export class EXT_materials_diffuse_roughness implements IGLTFExporterExtensionV2
5362
// eslint-disable-next-line no-restricted-syntax
5463
public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {
5564
return new Promise((resolve) => {
65+
let diffuseRoughnessFactor: Nullable<number> = null;
66+
let diffuseRoughnessTexture: Nullable<BaseTexture> = null;
5667
if (babylonMaterial instanceof PBRBaseMaterial) {
57-
if (!babylonMaterial._baseDiffuseRoughness) {
58-
resolve(node);
59-
return;
60-
}
61-
62-
this._wasUsed = true;
68+
diffuseRoughnessFactor = babylonMaterial._baseDiffuseRoughness;
69+
diffuseRoughnessTexture = babylonMaterial._baseDiffuseRoughnessTexture;
70+
} else if (babylonMaterial instanceof OpenPBRMaterial) {
71+
diffuseRoughnessFactor = babylonMaterial.baseDiffuseRoughness;
72+
diffuseRoughnessTexture = babylonMaterial.baseDiffuseRoughnessTexture;
73+
}
74+
if (!diffuseRoughnessFactor) {
75+
resolve(node);
76+
return;
77+
}
6378

64-
node.extensions = node.extensions || {};
79+
this._wasUsed = true;
6580

66-
const diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial._baseDiffuseRoughnessTexture);
81+
node.extensions = node.extensions || {};
6782

68-
const diffuseRoughnessInfo: IEXTMaterialsDiffuseRoughness = {
69-
diffuseRoughnessFactor: babylonMaterial._baseDiffuseRoughness,
70-
diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,
71-
};
83+
const diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(diffuseRoughnessTexture);
7284

73-
if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {
74-
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
75-
}
85+
const diffuseRoughnessInfo: IEXTMaterialsDiffuseRoughness = {
86+
diffuseRoughnessFactor: diffuseRoughnessFactor,
87+
diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,
88+
};
7689

77-
node.extensions[NAME] = diffuseRoughnessInfo;
90+
if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {
91+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
7892
}
93+
94+
node.extensions[NAME] = diffuseRoughnessInfo;
95+
7996
resolve(node);
8097
});
8198
}

0 commit comments

Comments
 (0)