mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-13 22:09:53 -05:00
Merge pull request #1002 from ousttrue/feature/vertex_color_state
VertexColorState を格上げ
This commit is contained in:
commit
909ee484ea
|
|
@ -96,11 +96,11 @@ namespace UniGLTF
|
|||
sb.Append($") x {info.Mesh.vertexCount}");
|
||||
switch (info.VertexColor)
|
||||
{
|
||||
case MeshExportInfo.VertexColorState.ExistsAndIsUsed:
|
||||
case MeshExportInfo.VertexColorState.ExistsAndMixed: // エクスポートする
|
||||
case VertexColorState.ExistsAndIsUsed:
|
||||
case VertexColorState.ExistsAndMixed: // エクスポートする
|
||||
sb.Insert(0, "[use vcolor]");
|
||||
break;
|
||||
case MeshExportInfo.VertexColorState.ExistsButNotUsed:
|
||||
case VertexColorState.ExistsButNotUsed:
|
||||
sb.Insert(0, "[remove vcolor]");
|
||||
break;
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ namespace UniGLTF
|
|||
return false;
|
||||
}
|
||||
|
||||
info.VertexColor = MeshExportInfo.DetectVertexColor(info.Mesh, info.Renderer.sharedMaterials);
|
||||
info.VertexColor = VertexColorUtility.DetectVertexColor(info.Mesh, info.Renderer.sharedMaterials);
|
||||
|
||||
var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(renderer.transform, root.transform);
|
||||
CalcMeshSize(ref info, relativePath);
|
||||
|
|
|
|||
|
|
@ -21,75 +21,8 @@ namespace UniGLTF
|
|||
|
||||
public bool HasSkinning => Mesh.boneWeights != null && Mesh.boneWeights.Length == Mesh.vertexCount;
|
||||
|
||||
/// <summary>
|
||||
/// Mesh に頂点カラーが含まれているか。
|
||||
/// 含まれている場合にマテリアルは Unlit.VColorMultiply になっているか?
|
||||
/// </summary>
|
||||
public enum VertexColorState
|
||||
{
|
||||
// VColorが存在しない
|
||||
None,
|
||||
// VColorが存在して使用している(UnlitはすべてVColorMultiply)
|
||||
ExistsAndIsUsed,
|
||||
// VColorが存在するが使用していない(UnlitはすべてVColorNone。もしくはUnlitが存在しない)
|
||||
ExistsButNotUsed,
|
||||
// VColorが存在して、Unlit.Multiply と Unlit.NotMultiply が混在している。 Unlit.NotMultiply を MToon か Standardに変更した方がよい
|
||||
ExistsAndMixed,
|
||||
}
|
||||
public VertexColorState VertexColor;
|
||||
|
||||
static bool MaterialUseVertexColor(Material m)
|
||||
{
|
||||
if (m == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (m.shader.name != UniGLTF.UniUnlit.Utils.ShaderName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (UniGLTF.UniUnlit.Utils.GetVColBlendMode(m) != UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.Multiply)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static VertexColorState DetectVertexColor(Mesh mesh, Material[] materials)
|
||||
{
|
||||
if (mesh != null && mesh.colors != null && mesh.colors.Length == mesh.vertexCount)
|
||||
{
|
||||
// mesh が 頂点カラーを保持している
|
||||
VertexColorState? state = default;
|
||||
if (materials != null)
|
||||
{
|
||||
foreach (var m in materials)
|
||||
{
|
||||
var currentState = MaterialUseVertexColor(m)
|
||||
? MeshExportInfo.VertexColorState.ExistsAndIsUsed
|
||||
: MeshExportInfo.VertexColorState.ExistsButNotUsed
|
||||
;
|
||||
if (state.HasValue)
|
||||
{
|
||||
if (state.Value != currentState)
|
||||
{
|
||||
state = MeshExportInfo.VertexColorState.ExistsAndMixed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = currentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
return state.GetValueOrDefault(VertexColorState.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
return VertexColorState.None;
|
||||
}
|
||||
}
|
||||
public int VertexCount;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ namespace UniGLTF
|
|||
|
||||
var colorAccessorIndex = -1;
|
||||
|
||||
var vColorState = MeshExportInfo.DetectVertexColor(mesh, materials);
|
||||
if (vColorState == MeshExportInfo.VertexColorState.ExistsAndIsUsed // VColor使っている
|
||||
|| vColorState == MeshExportInfo.VertexColorState.ExistsAndMixed // VColorを使っているところと使っていないところが混在(とりあえずExportする)
|
||||
var vColorState = VertexColorUtility.DetectVertexColor(mesh, materials);
|
||||
if (vColorState == VertexColorState.ExistsAndIsUsed // VColor使っている
|
||||
|| vColorState == VertexColorState.ExistsAndMixed // VColorを使っているところと使っていないところが混在(とりあえずExportする)
|
||||
)
|
||||
{
|
||||
// UniUnlit で Multiply 設定になっている
|
||||
|
|
|
|||
76
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/VertexColorState.cs
Normal file
76
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/VertexColorState.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Mesh に頂点カラーが含まれているか。
|
||||
/// 含まれている場合にマテリアルは Unlit.VColorMultiply になっているか?
|
||||
/// </summary>
|
||||
public enum VertexColorState
|
||||
{
|
||||
// VColorが存在しない
|
||||
None,
|
||||
// VColorが存在して使用している(UnlitはすべてVColorMultiply)
|
||||
ExistsAndIsUsed,
|
||||
// VColorが存在するが使用していない(UnlitはすべてVColorNone。もしくはUnlitが存在しない)
|
||||
ExistsButNotUsed,
|
||||
// VColorが存在して、Unlit.Multiply と Unlit.NotMultiply が混在している。 Unlit.NotMultiply を MToon か Standardに変更した方がよい
|
||||
ExistsAndMixed,
|
||||
}
|
||||
|
||||
public static class VertexColorUtility
|
||||
{
|
||||
static bool MaterialUseVertexColor(Material m)
|
||||
{
|
||||
if (m == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (m.shader.name != UniGLTF.UniUnlit.Utils.ShaderName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (UniGLTF.UniUnlit.Utils.GetVColBlendMode(m) != UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.Multiply)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static VertexColorState DetectVertexColor(Mesh mesh, Material[] materials)
|
||||
{
|
||||
if (mesh != null && mesh.colors != null && mesh.colors.Length == mesh.vertexCount)
|
||||
{
|
||||
// mesh が 頂点カラーを保持している
|
||||
VertexColorState? state = default;
|
||||
if (materials != null)
|
||||
{
|
||||
foreach (var m in materials)
|
||||
{
|
||||
var currentState = MaterialUseVertexColor(m)
|
||||
? VertexColorState.ExistsAndIsUsed
|
||||
: VertexColorState.ExistsButNotUsed
|
||||
;
|
||||
if (state.HasValue)
|
||||
{
|
||||
if (state.Value != currentState)
|
||||
{
|
||||
state = VertexColorState.ExistsAndMixed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state = currentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
return state.GetValueOrDefault(VertexColorState.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
return VertexColorState.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 63e5d425c70cb5f4480e3ad09f323425
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -258,7 +258,7 @@ namespace VRM
|
|||
{
|
||||
switch (meshInfo.VertexColor)
|
||||
{
|
||||
case UniGLTF.MeshExportInfo.VertexColorState.ExistsAndMixed:
|
||||
case UniGLTF.VertexColorState.ExistsAndMixed:
|
||||
Validation.Warning($"{meshInfo.Renderer}: Both vcolor.multiply and not multiply unlit materials exist").DrawGUI();
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user