From 658a67a4837b46aa5338cc0aae22298119cf4256 Mon Sep 17 00:00:00 2001 From: Jifeng Date: Fri, 7 Dec 2018 16:50:18 +0800 Subject: [PATCH] fix transparency problem if dissolve value set to 0; package version to 1.0.1 --- src/Obj23dTiles/Obj23dTiles.csproj | 1 + src/Obj2Gltf/Converter.cs | 6 +++--- src/Obj2Gltf/Gltf/Material.cs | 4 ++-- src/Obj2Gltf/Obj2Gltf.csproj | 1 + src/Obj2Gltf/WaveFront/MtlParser.cs | 12 ++++++++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Obj23dTiles/Obj23dTiles.csproj b/src/Obj23dTiles/Obj23dTiles.csproj index 924653f..5a28655 100644 --- a/src/Obj23dTiles/Obj23dTiles.csproj +++ b/src/Obj23dTiles/Obj23dTiles.csproj @@ -12,6 +12,7 @@ https://github.com/arcplus/ObjConvert Copyright © Arcplus 2018 Convert wavefront obj file to 3d tiles, which can be used in cesium + 1.0.1 diff --git a/src/Obj2Gltf/Converter.cs b/src/Obj2Gltf/Converter.cs index 8d9b6e7..2a6355d 100644 --- a/src/Obj2Gltf/Converter.cs +++ b/src/Obj2Gltf/Converter.cs @@ -437,10 +437,10 @@ private Gltf.Material GetDefault() { AlphaMode = AlphaMode.OPAQUE, Name = "default", - EmissiveFactor = new double[] { 1, 1, 1 }, + //EmissiveFactor = new double[] { 1, 1, 1 }, PbrMetallicRoughness = new PbrMetallicRoughness { - BaseColorFactor = new double[] { 1, 1, 1, 1 }, + BaseColorFactor = new double[] { 0.5, 0.5, 0.5, 1 }, MetallicFactor = 0.0, RoughnessFactor = 0.0 } @@ -462,7 +462,7 @@ private int AddMaterial(WaveFront.Material mat) AlphaMode = AlphaMode.OPAQUE }; var alpha = 1.0; - if (mat.Dissolve != null) + if (mat.Dissolve != null && mat.Dissolve.Factor > 0) { gMat.AlphaMode = AlphaMode.BLEND; alpha = mat.Dissolve.Factor; diff --git a/src/Obj2Gltf/Gltf/Material.cs b/src/Obj2Gltf/Gltf/Material.cs index 47be20b..7233ce6 100644 --- a/src/Obj2Gltf/Gltf/Material.cs +++ b/src/Obj2Gltf/Gltf/Material.cs @@ -43,7 +43,7 @@ public class Material /// The emissive color of the material. /// [JsonProperty("emissiveFactor")] - public double[] EmissiveFactor = new double[] { 0, 0, 0 }; + public double[] EmissiveFactor { get; set; } // = new double[] { 0, 0, 0 }; /// /// The alpha rendering mode of the material. /// @@ -105,6 +105,6 @@ public class PbrMetallicRoughness /// * A value of 1.0 means the material is completely rough. /// * A value of 0.0 means the material is completely smooth. [JsonProperty("roughnessFactor")] - public double RoughnessFactor { get; set; } + public double RoughnessFactor { get; set; } = 0.9; } } diff --git a/src/Obj2Gltf/Obj2Gltf.csproj b/src/Obj2Gltf/Obj2Gltf.csproj index bd88e47..bfa87a6 100644 --- a/src/Obj2Gltf/Obj2Gltf.csproj +++ b/src/Obj2Gltf/Obj2Gltf.csproj @@ -13,6 +13,7 @@ https://github.com/arcplus/ObjConvert Copyright © Arcplus 2018 Convert wavefront obj file to gltf/glb file + 1.0.1 diff --git a/src/Obj2Gltf/WaveFront/MtlParser.cs b/src/Obj2Gltf/WaveFront/MtlParser.cs index 18c2057..eabb494 100644 --- a/src/Obj2Gltf/WaveFront/MtlParser.cs +++ b/src/Obj2Gltf/WaveFront/MtlParser.cs @@ -166,5 +166,17 @@ public void Dispose() _reader.Close(); } } + /// + /// Translate the blinn-phong model to the pbr metallic-roughness model + /// Roughness factor is a combination of specular intensity and shininess + /// Metallic factor is 0.0 + /// Textures are not converted for now + /// + /// + /// + public static double Luminance(Color color) + { + return color.Red * 0.2125 + color.Green * 0.7154 + color.Blue * 0.0721; + } } }