Merge pull request #1444 from ousttrue/fix/MaterialHasVertexColor

Fix/material has vertex color
This commit is contained in:
ousttrue
2022-01-06 14:55:28 +09:00
committed by GitHub
4 changed files with 45 additions and 36 deletions

View File

@@ -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<glTFMesh> meshes = new List<glTFMesh>();
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<glTFNode> nodes = new List<glTFNode>();

View File

@@ -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;

View File

@@ -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<UnityEngine.Color>(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;
}
}
}

View File

@@ -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);