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..19d720102 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -329,5 +329,49 @@ namespace UniGLTF return (GetBytesFromUri(image.uri), image.mimeType); } } + + // not black(0, 0, 0, 1) + static readonly UnityEngine.Color ZERO = new UnityEngine.Color(0, 0, 0, 0); + + public bool HasVertexColor(glTFAttributes attributes) + { + 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) + { + 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 (prim.material == materialIndex && 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);