diff --git a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMaterialUtil.cs b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMaterialUtil.cs new file mode 100644 index 0000000000..cbec604acf --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMaterialUtil.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +#if UNITY_EDITOR +using UnityEditor; + +namespace UniVRM10 +{ + public static class PreviewMaterialUtil + { + public static PreviewMaterialItem CreateForPreview(Material material) + { + var item = new PreviewMaterialItem(material); + + var propNames = new List(); + for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i) + { + var propType = ShaderUtil.GetPropertyType(material.shader, i); + var name = ShaderUtil.GetPropertyName(material.shader, i); + + switch (propType) + { + case ShaderUtil.ShaderPropertyType.Color: + // 色 + { + var bindType = PreviewMaterialItem.GetBindType(name); + item.PropMap.Add(bindType, new PropItem + { + Name = name, + PropertyType = (UniVRM10.ShaderPropertyType)Enum.Parse(typeof(UniVRM10.ShaderPropertyType), propType.ToString(), true), + DefaultValues = material.GetColor(name), + }); + propNames.Add(name); + } + break; + + case ShaderUtil.ShaderPropertyType.TexEnv: + break; + } + } + item.PropNames = propNames.ToArray(); + return item; + } + } +} +#endif \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMaterialUtil.cs.meta b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMaterialUtil.cs.meta new file mode 100644 index 0000000000..6127749023 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewMaterialUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45f9865ffd894b04bad0c39f53154f55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs index 3f93078f18..b2044cdb32 100644 --- a/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs +++ b/Assets/VRM10/Runtime/Components/Expression/Preview/PreviewSceneManager.cs @@ -97,7 +97,7 @@ private void Initialize(GameObject prefab) //Debug.LogFormat("add material {0}", src.name); materialNames.Add(src.name); - m_materialMap.Add(src.name, PreviewMaterialItem.CreateForPreview(dst)); + m_materialMap.Add(src.name, PreviewMaterialUtil.CreateForPreview(dst)); } return dst; }; diff --git a/Assets/VRM10/Runtime/Components/Expression/PreviewMaterialItem.cs b/Assets/VRM10/Runtime/Components/Expression/PreviewMaterialItem.cs index 1cecedf22d..07091b5f52 100644 --- a/Assets/VRM10/Runtime/Components/Expression/PreviewMaterialItem.cs +++ b/Assets/VRM10/Runtime/Components/Expression/PreviewMaterialItem.cs @@ -2,13 +2,10 @@ using System.Collections.Generic; using UnityEngine; using UniGLTF.Extensions.VRMC_vrm; -#if UNITY_EDITOR -using UnityEditor; -#endif + namespace UniVRM10 { - public enum ShaderPropertyType { // @@ -68,7 +65,7 @@ public PreviewMaterialItem(Material material) public string[] PropNames { get; - private set; + set; } public void RestoreInitialValues() @@ -79,7 +76,6 @@ public void RestoreInitialValues() } } -#if UNITY_EDITOR public const string UV_PROPERTY = "_MainTex_ST"; public const string COLOR_PROPERTY = "_Color"; public const string EMISSION_COLOR_PROPERTY = "_EmissionColor"; @@ -108,69 +104,5 @@ public static MaterialColorType GetBindType(string property) throw new NotImplementedException(); } - - public static PreviewMaterialItem CreateForPreview(Material material) - { - var item = new PreviewMaterialItem(material); - - var propNames = new List(); - for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i) - { - var propType = ShaderUtil.GetPropertyType(material.shader, i); - var name = ShaderUtil.GetPropertyName(material.shader, i); - - switch (propType) - { - case ShaderUtil.ShaderPropertyType.Color: - // 色 - { - var bindType = GetBindType(name); - item.PropMap.Add(bindType, new PropItem - { - Name = name, - PropertyType = (UniVRM10.ShaderPropertyType)Enum.Parse(typeof(UniVRM10.ShaderPropertyType), propType.ToString(), true), - DefaultValues = material.GetColor(name), - }); - propNames.Add(name); - } - break; - - case ShaderUtil.ShaderPropertyType.TexEnv: - // テクスチャ - // { - // name += "_ST"; - // item.PropMap.Add(name, new PropItem - // { - // PropertyType = propType, - // DefaultValues = material.GetVector(name), - // }); - // propNames.Add(name); - // } - // // 縦横分離用 - // { - // var st_name = name + "_S"; - // item.PropMap.Add(st_name, new PropItem - // { - // PropertyType = propType, - // DefaultValues = material.GetVector(name), - // }); - // propNames.Add(st_name); - // } - // { - // var st_name = name + "_T"; - // item.PropMap.Add(st_name, new PropItem - // { - // PropertyType = propType, - // DefaultValues = material.GetVector(name), - // }); - // propNames.Add(st_name); - // } - break; - } - } - item.PropNames = propNames.ToArray(); - return item; - } -#endif } }