From 38a3c761166dc3408926f2d38d4029963c1145fe Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Dec 2021 19:31:01 +0900 Subject: [PATCH 1/3] mv MaterialHasVertexColor to GltfData --- Assets/UniGLTF/Runtime/UniGLTF/Format/glTF.cs | 27 ------------------- .../Runtime/UniGLTF/Format/glTFMesh.cs | 8 ------ Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs | 27 +++++++++++++++++++ .../MaterialIO/GltfUnlitMaterialImporter.cs | 2 +- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTF.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTF.cs index 6cc4a0912..e4557cea1 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTF.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTF.cs @@ -81,36 +81,9 @@ namespace UniGLTF } } - public bool MaterialHasVertexColor(glTFMaterial material) - { - if (material == null) - { - return false; - } - - var materialIndex = materials.IndexOf(material); - if (materialIndex == -1) - { - return false; - } - - return MaterialHasVertexColor(materialIndex); - } - [JsonSchema(MinItems = 1, ExplicitIgnorableItemLength = 0)] public List meshes = new List(); - public bool MaterialHasVertexColor(int materialIndex) - { - if (materialIndex < 0 || materialIndex >= materials.Count) - { - return false; - } - - var hasVertexColor = meshes.SelectMany(x => x.primitives).Any(x => x.material == materialIndex && x.HasVertexColor); - return hasVertexColor; - } - [JsonSchema(MinItems = 1, ExplicitIgnorableItemLength = 0)] public List nodes = new List(); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMesh.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMesh.cs index 480f00519..9d945e064 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMesh.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMesh.cs @@ -84,14 +84,6 @@ namespace UniGLTF [JsonSchema(Required = true, SkipSchemaComparison = true)] public glTFAttributes attributes; - public bool HasVertexColor - { - get - { - return attributes.COLOR_0 != -1; - } - } - [JsonSchema(Minimum = 0)] public int material; diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index 614dc3ad2..9ae339707 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -329,5 +329,32 @@ namespace UniGLTF return (GetBytesFromUri(image.uri), image.mimeType); } } + + public bool HasVertexColor(glTFAttributes attributes) + { + return attributes.COLOR_0 != -1; + } + + public bool MaterialHasVertexColor(int materialIndex) + { + if (materialIndex < 0 || materialIndex >= GLTF.materials.Count) + { + // index out of range. material not exists + return false; + } + + foreach (var mesh in GLTF.meshes) + { + foreach (var prim in mesh.primitives) + { + if (HasVertexColor(prim.attributes)) + { + return true; + } + } + } + + return false; + } } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs index bd422a7a0..7bbde1681 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs @@ -91,7 +91,7 @@ namespace UniGLTF } // VColor - var hasVertexColor = data.GLTF.MaterialHasVertexColor(i); + var hasVertexColor = data.MaterialHasVertexColor(i); if (hasVertexColor) { UniUnlitUtil.SetVColBlendMode(material, UniUnlitVertexColorBlendOp.Multiply); From 8e5479772d9d5fe4aef2dc07dc8e36239b39b32e Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Dec 2021 19:39:30 +0900 Subject: [PATCH 2/3] =?UTF-8?q?HasVertexColor=20=E3=81=A7=E4=B8=AD?= =?UTF-8?q?=E8=BA=AB=E3=82=92=E8=A6=8B=E3=81=A6=E5=88=A4=E6=96=AD=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index 9ae339707..2a6227ad4 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -330,9 +330,26 @@ namespace UniGLTF } } + // not black(0, 0, 0, 1) + static readonly UnityEngine.Color ZERO = new UnityEngine.Color(0, 0, 0, 0); + public bool HasVertexColor(glTFAttributes attributes) { - return attributes.COLOR_0 != -1; + if (attributes.COLOR_0 == -1) + { + return false; + } + + var colors = GetArrayFromAccessor(attributes.COLOR_0); + foreach (var color in colors) + { + if (color != ZERO) + { + return true; + } + } + // すべて (0, 0, 0, 0) だった。使っていないと見做す。 + return false; } public bool MaterialHasVertexColor(int materialIndex) From c55d2cc851cf0f2d8905e95af3d85fa365d50b72 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Dec 2021 20:00:39 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index 2a6227ad4..19d720102 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -364,7 +364,7 @@ namespace UniGLTF { foreach (var prim in mesh.primitives) { - if (HasVertexColor(prim.attributes)) + if (prim.material == materialIndex && HasVertexColor(prim.attributes)) { return true; }