forked from vrm-c/UniVRM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vrm-c#1002 from ousttrue/feature/vertex_color_state
VertexColorState を格上げ
- Loading branch information
Showing
6 changed files
with
95 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/VertexColorState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/VertexColorState.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters