|
@@ -811,29 +811,31 @@ module BABYLON.GLTF2 {
|
|
}
|
|
}
|
|
|
|
|
|
private _loadMaterialMetallicRoughnessProperties(material: IGLTFMaterial): void {
|
|
private _loadMaterialMetallicRoughnessProperties(material: IGLTFMaterial): void {
|
|
|
|
+ var babylonMaterial = material.babylonMaterial as PBRMaterial;
|
|
|
|
+
|
|
// Ensure metallic workflow
|
|
// Ensure metallic workflow
|
|
- material.babylonMaterial.metallic = 1;
|
|
|
|
- material.babylonMaterial.roughness = 1;
|
|
|
|
|
|
+ babylonMaterial.metallic = 1;
|
|
|
|
+ babylonMaterial.roughness = 1;
|
|
|
|
|
|
var properties = material.pbrMetallicRoughness;
|
|
var properties = material.pbrMetallicRoughness;
|
|
if (!properties) {
|
|
if (!properties) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- material.babylonMaterial.albedoColor = properties.baseColorFactor ? Color3.FromArray(properties.baseColorFactor) : new Color3(1, 1, 1);
|
|
|
|
- material.babylonMaterial.metallic = properties.metallicFactor === undefined ? 1 : properties.metallicFactor;
|
|
|
|
- material.babylonMaterial.roughness = properties.roughnessFactor === undefined ? 1 : properties.roughnessFactor;
|
|
|
|
|
|
+ babylonMaterial.albedoColor = properties.baseColorFactor ? Color3.FromArray(properties.baseColorFactor) : new Color3(1, 1, 1);
|
|
|
|
+ babylonMaterial.metallic = properties.metallicFactor === undefined ? 1 : properties.metallicFactor;
|
|
|
|
+ babylonMaterial.roughness = properties.roughnessFactor === undefined ? 1 : properties.roughnessFactor;
|
|
|
|
|
|
if (properties.baseColorTexture) {
|
|
if (properties.baseColorTexture) {
|
|
- material.babylonMaterial.albedoTexture = this.loadTexture(properties.baseColorTexture);
|
|
|
|
|
|
+ babylonMaterial.albedoTexture = this.loadTexture(properties.baseColorTexture);
|
|
this.loadMaterialAlphaProperties(material);
|
|
this.loadMaterialAlphaProperties(material);
|
|
}
|
|
}
|
|
|
|
|
|
if (properties.metallicRoughnessTexture) {
|
|
if (properties.metallicRoughnessTexture) {
|
|
- material.babylonMaterial.metallicTexture = this.loadTexture(properties.metallicRoughnessTexture);
|
|
|
|
- material.babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
|
|
- material.babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
|
|
- material.babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
|
|
|
|
|
+ babylonMaterial.metallicTexture = this.loadTexture(properties.metallicRoughnessTexture);
|
|
|
|
+ babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
|
|
|
|
+ babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
|
|
|
|
+ babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -857,52 +859,57 @@ module BABYLON.GLTF2 {
|
|
}
|
|
}
|
|
|
|
|
|
public createPbrMaterial(material: IGLTFMaterial): void {
|
|
public createPbrMaterial(material: IGLTFMaterial): void {
|
|
- material.babylonMaterial = new PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
|
|
|
|
- material.babylonMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
|
|
|
|
- material.babylonMaterial.useScalarInLinearSpace = true;
|
|
|
|
|
|
+ var babylonMaterial = new PBRMaterial(material.name || "mat" + material.index, this._babylonScene);
|
|
|
|
+ babylonMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
|
|
|
|
+ babylonMaterial.useScalarInLinearSpace = true;
|
|
|
|
+ material.babylonMaterial = babylonMaterial;
|
|
}
|
|
}
|
|
|
|
|
|
public loadMaterialBaseProperties(material: IGLTFMaterial): void {
|
|
public loadMaterialBaseProperties(material: IGLTFMaterial): void {
|
|
- material.babylonMaterial.useEmissiveAsIllumination = (material.emissiveFactor || material.emissiveTexture) ? true : false;
|
|
|
|
- material.babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
|
|
|
|
|
|
+ var babylonMaterial = material.babylonMaterial as PBRMaterial;
|
|
|
|
+
|
|
|
|
+ babylonMaterial.useEmissiveAsIllumination = (material.emissiveFactor || material.emissiveTexture) ? true : false;
|
|
|
|
+ babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
|
|
if (material.doubleSided) {
|
|
if (material.doubleSided) {
|
|
- material.babylonMaterial.backFaceCulling = false;
|
|
|
|
- material.babylonMaterial.twoSidedLighting = true;
|
|
|
|
|
|
+ babylonMaterial.backFaceCulling = false;
|
|
|
|
+ babylonMaterial.twoSidedLighting = true;
|
|
}
|
|
}
|
|
|
|
|
|
if (material.normalTexture) {
|
|
if (material.normalTexture) {
|
|
- material.babylonMaterial.bumpTexture = this.loadTexture(material.normalTexture);
|
|
|
|
|
|
+ babylonMaterial.bumpTexture = this.loadTexture(material.normalTexture);
|
|
if (material.normalTexture.scale !== undefined) {
|
|
if (material.normalTexture.scale !== undefined) {
|
|
- material.babylonMaterial.bumpTexture.level = material.normalTexture.scale;
|
|
|
|
|
|
+ babylonMaterial.bumpTexture.level = material.normalTexture.scale;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (material.occlusionTexture) {
|
|
if (material.occlusionTexture) {
|
|
- material.babylonMaterial.ambientTexture = this.loadTexture(material.occlusionTexture);
|
|
|
|
- material.babylonMaterial.useAmbientInGrayScale = true;
|
|
|
|
|
|
+ babylonMaterial.ambientTexture = this.loadTexture(material.occlusionTexture);
|
|
|
|
+ babylonMaterial.useAmbientInGrayScale = true;
|
|
if (material.occlusionTexture.strength !== undefined) {
|
|
if (material.occlusionTexture.strength !== undefined) {
|
|
- material.babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
|
|
|
|
|
|
+ babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (material.emissiveTexture) {
|
|
if (material.emissiveTexture) {
|
|
- material.babylonMaterial.emissiveTexture = this.loadTexture(material.emissiveTexture);
|
|
|
|
|
|
+ babylonMaterial.emissiveTexture = this.loadTexture(material.emissiveTexture);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public loadMaterialAlphaProperties(material: IGLTFMaterial): void {
|
|
public loadMaterialAlphaProperties(material: IGLTFMaterial): void {
|
|
|
|
+ var babylonMaterial = material.babylonMaterial as PBRMaterial;
|
|
|
|
+
|
|
var alphaMode = material.alphaMode || "OPAQUE";
|
|
var alphaMode = material.alphaMode || "OPAQUE";
|
|
switch (alphaMode) {
|
|
switch (alphaMode) {
|
|
case "OPAQUE":
|
|
case "OPAQUE":
|
|
// default is opaque
|
|
// default is opaque
|
|
break;
|
|
break;
|
|
case "MASK":
|
|
case "MASK":
|
|
- material.babylonMaterial.albedoTexture.hasAlpha = true;
|
|
|
|
- material.babylonMaterial.useAlphaFromAlbedoTexture = false;
|
|
|
|
|
|
+ babylonMaterial.albedoTexture.hasAlpha = true;
|
|
|
|
+ babylonMaterial.useAlphaFromAlbedoTexture = false;
|
|
break;
|
|
break;
|
|
case "BLEND":
|
|
case "BLEND":
|
|
- material.babylonMaterial.albedoTexture.hasAlpha = true;
|
|
|
|
- material.babylonMaterial.useAlphaFromAlbedoTexture = true;
|
|
|
|
|
|
+ babylonMaterial.albedoTexture.hasAlpha = true;
|
|
|
|
+ babylonMaterial.useAlphaFromAlbedoTexture = true;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
Tools.Warn("Invalid alpha mode '" + material.alphaMode + "'");
|
|
Tools.Warn("Invalid alpha mode '" + material.alphaMode + "'");
|