forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BabylonJS#3 from alexchuber/uncomment-material-tex…
…ture-extensions Restoring all material and texture extensions
- Loading branch information
Showing
16 changed files
with
1,208 additions
and
1,234 deletions.
There are no files selected for viewing
167 changes: 84 additions & 83 deletions
167
packages/dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,84 @@ | ||
// import type { IMaterial, IKHRMaterialsAnisotropy } from "babylonjs-gltf2interface"; | ||
// import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension"; | ||
// import { GLTFExporter } from "../glTFExporter"; | ||
// import type { Material } from "core/Materials/material"; | ||
// import { PBRBaseMaterial } from "core/Materials/PBR/pbrBaseMaterial"; | ||
// import type { BaseTexture } from "core/Materials/Textures/baseTexture"; | ||
|
||
// const NAME = "KHR_materials_anisotropy"; | ||
|
||
// /** | ||
// * @internal | ||
// */ | ||
// // eslint-disable-next-line @typescript-eslint/naming-convention | ||
// export class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 { | ||
// /** Name of this extension */ | ||
// public readonly name = NAME; | ||
|
||
// /** Defines whether this extension is enabled */ | ||
// public enabled = true; | ||
|
||
// /** Defines whether this extension is required */ | ||
// public required = false; | ||
|
||
// private _exporter: GLTFExporter; | ||
|
||
// private _wasUsed = false; | ||
|
||
// constructor(exporter: GLTFExporter) { | ||
// this._exporter = exporter; | ||
// } | ||
|
||
// public dispose() {} | ||
|
||
// /** @internal */ | ||
// public get wasUsed() { | ||
// return this._wasUsed; | ||
// } | ||
|
||
// public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] { | ||
// const additionalTextures: BaseTexture[] = []; | ||
// if (babylonMaterial instanceof PBRBaseMaterial) { | ||
// if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) { | ||
// if (babylonMaterial.anisotropy.texture) { | ||
// additionalTextures.push(babylonMaterial.anisotropy.texture); | ||
// } | ||
// return additionalTextures; | ||
// } | ||
// } | ||
|
||
// return []; | ||
// } | ||
|
||
// public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> { | ||
// return new Promise((resolve) => { | ||
// if (babylonMaterial instanceof PBRBaseMaterial) { | ||
// if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) { | ||
// resolve(node); | ||
// return; | ||
// } | ||
|
||
// this._wasUsed = true; | ||
|
||
// node.extensions = node.extensions || {}; | ||
|
||
// const anisotropyTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.anisotropy.texture); | ||
|
||
// const anisotropyInfo: IKHRMaterialsAnisotropy = { | ||
// anisotropyStrength: babylonMaterial.anisotropy.intensity, | ||
// anisotropyRotation: babylonMaterial.anisotropy.angle, | ||
// anisotropyTexture: anisotropyTextureInfo ?? undefined, | ||
// hasTextures: () => { | ||
// return anisotropyInfo.anisotropyTexture !== null; | ||
// }, | ||
// }; | ||
|
||
// node.extensions[NAME] = anisotropyInfo; | ||
// } | ||
// resolve(node); | ||
// }); | ||
// } | ||
// } | ||
|
||
// GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter)); | ||
import type { IMaterial, IKHRMaterialsAnisotropy } from "babylonjs-gltf2interface"; | ||
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension"; | ||
import { GLTFExporter } from "../glTFExporter"; | ||
import type { Material } from "core/Materials/material"; | ||
import { PBRBaseMaterial } from "core/Materials/PBR/pbrBaseMaterial"; | ||
import type { BaseTexture } from "core/Materials/Textures/baseTexture"; | ||
|
||
const NAME = "KHR_materials_anisotropy"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 { | ||
/** Name of this extension */ | ||
public readonly name = NAME; | ||
|
||
/** Defines whether this extension is enabled */ | ||
public enabled = true; | ||
|
||
/** Defines whether this extension is required */ | ||
public required = false; | ||
|
||
private _exporter: GLTFExporter; | ||
|
||
private _wasUsed = false; | ||
|
||
constructor(exporter: GLTFExporter) { | ||
this._exporter = exporter; | ||
} | ||
|
||
public dispose() {} | ||
|
||
/** @internal */ | ||
public get wasUsed() { | ||
return this._wasUsed; | ||
} | ||
|
||
public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] { | ||
const additionalTextures: BaseTexture[] = []; | ||
if (babylonMaterial instanceof PBRBaseMaterial) { | ||
if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) { | ||
if (babylonMaterial.anisotropy.texture) { | ||
additionalTextures.push(babylonMaterial.anisotropy.texture); | ||
} | ||
return additionalTextures; | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
|
||
public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> { | ||
return new Promise((resolve) => { | ||
if (babylonMaterial instanceof PBRBaseMaterial) { | ||
if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) { | ||
resolve(node); | ||
return; | ||
} | ||
|
||
this._wasUsed = true; | ||
|
||
node.extensions = node.extensions || {}; | ||
|
||
const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture); | ||
|
||
const anisotropyInfo: IKHRMaterialsAnisotropy = { | ||
anisotropyStrength: babylonMaterial.anisotropy.intensity, | ||
anisotropyRotation: babylonMaterial.anisotropy.angle, | ||
anisotropyTexture: anisotropyTextureInfo ?? undefined, | ||
}; | ||
|
||
if (anisotropyInfo.anisotropyTexture !== null) { | ||
this._exporter._materialNeedsUVsSet.add(babylonMaterial); | ||
} | ||
|
||
node.extensions[NAME] = anisotropyInfo; | ||
} | ||
resolve(node); | ||
}); | ||
} | ||
} | ||
|
||
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter)); |
219 changes: 110 additions & 109 deletions
219
packages/dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,110 @@ | ||
// import type { IMaterial, IKHRMaterialsClearcoat } from "babylonjs-gltf2interface"; | ||
// import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension"; | ||
// import { GLTFExporter } from "../glTFExporter"; | ||
// import type { Material } from "core/Materials/material"; | ||
// import { PBRBaseMaterial } from "core/Materials/PBR/pbrBaseMaterial"; | ||
// import type { BaseTexture } from "core/Materials/Textures/baseTexture"; | ||
|
||
// import { Tools } from "core/Misc/tools"; | ||
|
||
// const NAME = "KHR_materials_clearcoat"; | ||
|
||
// /** | ||
// * @internal | ||
// */ | ||
// // eslint-disable-next-line @typescript-eslint/naming-convention | ||
// export class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 { | ||
// /** Name of this extension */ | ||
// public readonly name = NAME; | ||
|
||
// /** Defines whether this extension is enabled */ | ||
// public enabled = true; | ||
|
||
// /** Defines whether this extension is required */ | ||
// public required = false; | ||
|
||
// private _exporter: GLTFExporter; | ||
|
||
// private _wasUsed = false; | ||
|
||
// constructor(exporter: GLTFExporter) { | ||
// this._exporter = exporter; | ||
// } | ||
|
||
// public dispose() {} | ||
|
||
// /** @internal */ | ||
// public get wasUsed() { | ||
// return this._wasUsed; | ||
// } | ||
|
||
// public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] { | ||
// const additionalTextures: BaseTexture[] = []; | ||
// if (babylonMaterial instanceof PBRBaseMaterial) { | ||
// if (babylonMaterial.clearCoat.isEnabled) { | ||
// if (babylonMaterial.clearCoat.texture) { | ||
// additionalTextures.push(babylonMaterial.clearCoat.texture); | ||
// } | ||
// if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) { | ||
// additionalTextures.push(babylonMaterial.clearCoat.textureRoughness); | ||
// } | ||
// if (babylonMaterial.clearCoat.bumpTexture) { | ||
// additionalTextures.push(babylonMaterial.clearCoat.bumpTexture); | ||
// } | ||
// return additionalTextures; | ||
// } | ||
// } | ||
|
||
// return []; | ||
// } | ||
|
||
// public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> { | ||
// return new Promise((resolve) => { | ||
// if (babylonMaterial instanceof PBRBaseMaterial) { | ||
// if (!babylonMaterial.clearCoat.isEnabled) { | ||
// resolve(node); | ||
// return; | ||
// } | ||
|
||
// this._wasUsed = true; | ||
|
||
// node.extensions = node.extensions || {}; | ||
|
||
// const clearCoatTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture); | ||
// let clearCoatTextureRoughnessInfo; | ||
// if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) { | ||
// clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture); | ||
// } else { | ||
// clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.textureRoughness); | ||
// } | ||
|
||
// if (babylonMaterial.clearCoat.isTintEnabled) { | ||
// Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`); | ||
// } | ||
|
||
// if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) { | ||
// Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`); | ||
// } | ||
|
||
// const clearCoatNormalTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.bumpTexture); | ||
|
||
// const clearCoatInfo: IKHRMaterialsClearcoat = { | ||
// clearcoatFactor: babylonMaterial.clearCoat.intensity, | ||
// clearcoatTexture: clearCoatTextureInfo ?? undefined, | ||
// clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness, | ||
// clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined, | ||
// clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined, | ||
// hasTextures: () => { | ||
// return clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null; | ||
// }, | ||
// }; | ||
|
||
// node.extensions[NAME] = clearCoatInfo; | ||
// } | ||
// resolve(node); | ||
// }); | ||
// } | ||
// } | ||
|
||
// GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter)); | ||
import type { IMaterial, IKHRMaterialsClearcoat } from "babylonjs-gltf2interface"; | ||
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension"; | ||
import { GLTFExporter } from "../glTFExporter"; | ||
import type { Material } from "core/Materials/material"; | ||
import { PBRBaseMaterial } from "core/Materials/PBR/pbrBaseMaterial"; | ||
import type { BaseTexture } from "core/Materials/Textures/baseTexture"; | ||
|
||
import { Tools } from "core/Misc/tools"; | ||
|
||
const NAME = "KHR_materials_clearcoat"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 { | ||
/** Name of this extension */ | ||
public readonly name = NAME; | ||
|
||
/** Defines whether this extension is enabled */ | ||
public enabled = true; | ||
|
||
/** Defines whether this extension is required */ | ||
public required = false; | ||
|
||
private _exporter: GLTFExporter; | ||
|
||
private _wasUsed = false; | ||
|
||
constructor(exporter: GLTFExporter) { | ||
this._exporter = exporter; | ||
} | ||
|
||
public dispose() {} | ||
|
||
/** @internal */ | ||
public get wasUsed() { | ||
return this._wasUsed; | ||
} | ||
|
||
public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] { | ||
const additionalTextures: BaseTexture[] = []; | ||
if (babylonMaterial instanceof PBRBaseMaterial) { | ||
if (babylonMaterial.clearCoat.isEnabled) { | ||
if (babylonMaterial.clearCoat.texture) { | ||
additionalTextures.push(babylonMaterial.clearCoat.texture); | ||
} | ||
if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) { | ||
additionalTextures.push(babylonMaterial.clearCoat.textureRoughness); | ||
} | ||
if (babylonMaterial.clearCoat.bumpTexture) { | ||
additionalTextures.push(babylonMaterial.clearCoat.bumpTexture); | ||
} | ||
return additionalTextures; | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
|
||
public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> { | ||
return new Promise((resolve) => { | ||
if (babylonMaterial instanceof PBRBaseMaterial) { | ||
if (!babylonMaterial.clearCoat.isEnabled) { | ||
resolve(node); | ||
return; | ||
} | ||
|
||
this._wasUsed = true; | ||
|
||
node.extensions = node.extensions || {}; | ||
|
||
const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture); | ||
let clearCoatTextureRoughnessInfo; | ||
if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) { | ||
clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture); | ||
} else { | ||
clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness); | ||
} | ||
|
||
if (babylonMaterial.clearCoat.isTintEnabled) { | ||
Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`); | ||
} | ||
|
||
if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) { | ||
Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`); | ||
} | ||
|
||
const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture); | ||
|
||
const clearCoatInfo: IKHRMaterialsClearcoat = { | ||
clearcoatFactor: babylonMaterial.clearCoat.intensity, | ||
clearcoatTexture: clearCoatTextureInfo ?? undefined, | ||
clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness, | ||
clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined, | ||
clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined, | ||
}; | ||
|
||
if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) { | ||
this._exporter._materialNeedsUVsSet.add(babylonMaterial); | ||
} | ||
|
||
node.extensions[NAME] = clearCoatInfo; | ||
} | ||
resolve(node); | ||
}); | ||
} | ||
} | ||
|
||
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter)); |
Oops, something went wrong.