From b709b6ce7b7aa96a96ebf2635e7ae1ad7d49bdb4 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 6 Aug 2018 17:10:07 +0900 Subject: [PATCH] Updated UniGLTF --- Scripts/Format/VRMPreShaderPropExporter.cs | 16 ++ .../VRMPreShaderPropExporter.cs.meta | 2 +- Scripts/Format/glTF_VRM_Material.cs | 18 +- .../VRMPreShaderPropExporter.cs | 168 ------------------ Scripts/PreExportShaderProps/VRM_MToon.cs | 68 +++---- .../PreExportShaderProps/VRM_MToon.cs.meta | 2 +- .../PreExportShaderProps/VRM_UnlitCutout.cs | 12 +- .../VRM_UnlitCutout.cs.meta | 2 +- .../PreExportShaderProps/VRM_UnlitTexture.cs | 10 +- .../VRM_UnlitTexture.cs.meta | 2 +- .../VRM_UnlitTransparent.cs | 10 +- .../VRM_UnlitTransparent.cs.meta | 2 +- .../VRM_UnlitTransparentZWrite.cs | 10 +- .../VRM_UnlitTransparentZWrite.cs.meta | 2 +- UniGLTF | 2 +- 15 files changed, 87 insertions(+), 239 deletions(-) create mode 100644 Scripts/Format/VRMPreShaderPropExporter.cs rename Scripts/{PreExportShaderProps => Format}/VRMPreShaderPropExporter.cs.meta (85%) delete mode 100644 Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs diff --git a/Scripts/Format/VRMPreShaderPropExporter.cs b/Scripts/Format/VRMPreShaderPropExporter.cs new file mode 100644 index 000000000..945ad83b0 --- /dev/null +++ b/Scripts/Format/VRMPreShaderPropExporter.cs @@ -0,0 +1,16 @@ +namespace UniGLTF.ShaderPropExporter +{ + public static partial class PreShaderPropExporter + { + const string VRM_TARGET_FOLDER = "VRM/Scripts"; + [PreExportShaders] + public static SupportedShader[] VRMSupportedShaders = new SupportedShader[] + { + new SupportedShader(VRM_TARGET_FOLDER, "VRM/MToon", "_BumpMap"), + new SupportedShader(VRM_TARGET_FOLDER, "VRM/UnlitTexture"), + new SupportedShader(VRM_TARGET_FOLDER, "VRM/UnlitCutout"), + new SupportedShader(VRM_TARGET_FOLDER, "VRM/UnlitTransparent"), + new SupportedShader(VRM_TARGET_FOLDER, "VRM/UnlitTransparentZWrite"), + }; + } +} diff --git a/Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs.meta b/Scripts/Format/VRMPreShaderPropExporter.cs.meta similarity index 85% rename from Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs.meta rename to Scripts/Format/VRMPreShaderPropExporter.cs.meta index 431e9cca2..d0fd45cad 100644 --- a/Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs.meta +++ b/Scripts/Format/VRMPreShaderPropExporter.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 50935dd2f9f3fa445a687f30d4dd663b +guid: 625b5ee8b5811dc4a915a2fbb2cb319d timeCreated: 1533035131 licenseType: Free MonoImporter: diff --git a/Scripts/Format/glTF_VRM_Material.cs b/Scripts/Format/glTF_VRM_Material.cs index de1cc87b2..4ee67229e 100644 --- a/Scripts/Format/glTF_VRM_Material.cs +++ b/Scripts/Format/glTF_VRM_Material.cs @@ -4,7 +4,7 @@ using System.Linq; using UniGLTF; using UnityEngine; using UniJSON; - +using UniGLTF.ShaderPropExporter; namespace VRM { @@ -106,13 +106,13 @@ namespace VRM renderQueue = m.renderQueue, }; - var prop = VRMPreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); + var prop = PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); if (prop == null) { #if UNITY_EDITOR // fallback Debug.LogWarningFormat("Unsupported shader: {0}", m.shader.name); - prop = VRMPreShaderPropExporter.ShaderProps.FromShader(m.shader); + prop = ShaderProps.FromShader(m.shader); #endif } @@ -126,24 +126,24 @@ namespace VRM //material.SetProp(prop); foreach (var kv in prop.Properties) { - switch (kv.Value) + switch (kv.ShaderPropertyType) { - case VRMPreShaderPropExporter.ShaderPropertyType.Color: + case ShaderPropertyType.Color: { var value = m.GetColor(kv.Key).ToArray(); material.vectorProperties.Add(kv.Key, value); } break; - case VRMPreShaderPropExporter.ShaderPropertyType.Range: - case VRMPreShaderPropExporter.ShaderPropertyType.Float: + case ShaderPropertyType.Range: + case ShaderPropertyType.Float: { var value = m.GetFloat(kv.Key); material.floatProperties.Add(kv.Key, value); } break; - case VRMPreShaderPropExporter.ShaderPropertyType.TexEnv: + case ShaderPropertyType.TexEnv: { var texture = m.GetTexture(kv.Key); if (texture != null) @@ -167,7 +167,7 @@ namespace VRM } break; - case VRMPreShaderPropExporter.ShaderPropertyType.Vector: + case ShaderPropertyType.Vector: { var value = m.GetVector(kv.Key).ToArray(); material.vectorProperties.Add(kv.Key, value); diff --git a/Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs b/Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs deleted file mode 100644 index 7cff9cdb6..000000000 --- a/Scripts/PreExportShaderProps/VRMPreShaderPropExporter.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using UniGLTF; -using UnityEngine; -#if UNITY_EDITOR -using UnityEditor; -#endif - - -namespace VRM -{ - public class VRMPreExportShaderAttribute : Attribute { } - - public static partial class VRMPreShaderPropExporter - { - public static string[] SupportedShaders = new string[] - { - "VRM/MToon", - "VRM/UnlitTexture", - "VRM/UnlitCutout", - "VRM/UnlitTransparent", - "VRM/UnlitTransparentZWrite", - }; - -#if UNITY_EDITOR - [MenuItem(VRMVersion.VRM_VERSION + "/PreExport ShaderProps")] - static void PreExport() - { - foreach (var shaderName in SupportedShaders) - { - var shader = Shader.Find(shaderName); - PreExport(shader); - } - } - - static string EscapeShaderName(string name) - { - return name.Replace("/", "_").Replace(" ", "_"); - } - - const string EXPORT_DIR = "Assets/VRM/Scripts/PreExportShaderProps/"; - static void PreExport(Shader shader) - { - var path = UnityPath.FromUnityPath(EXPORT_DIR + EscapeShaderName(shader.name) + ".cs"); - Debug.LogFormat("PreExport: {0}", path.FullPath); - - var props = ShaderProps.FromShader(shader); - - File.WriteAllText(path.FullPath, props.ToString(shader.name)); - } -#endif - - public enum ShaderPropertyType - { - TexEnv, - Color, - Range, - Float, - Vector, - } - - public class ShaderProps - { - public KeyValuePair[] Properties; - -#if UNITY_EDITOR - static ShaderPropertyType ConvType(ShaderUtil.ShaderPropertyType src) - { - switch (src) - { - case ShaderUtil.ShaderPropertyType.TexEnv: return ShaderPropertyType.TexEnv; - case ShaderUtil.ShaderPropertyType.Color: return ShaderPropertyType.Color; - case ShaderUtil.ShaderPropertyType.Float: return ShaderPropertyType.Float; - case ShaderUtil.ShaderPropertyType.Range: return ShaderPropertyType.Range; - case ShaderUtil.ShaderPropertyType.Vector: return ShaderPropertyType.Vector; - default: throw new NotImplementedException(); - } - } - - public static ShaderProps FromShader(Shader shader) - { - var properties = new List>(); - for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); ++i) - { - var name = ShaderUtil.GetPropertyName(shader, i); - var propType = ShaderUtil.GetPropertyType(shader, i); - properties.Add(new KeyValuePair(name, ConvType(propType))); - } - - return new ShaderProps - { - Properties = properties.ToArray(), - }; - } - - public string ToString(string shaderName) - { - var list = new List(); - foreach(var kv in Properties) - { - list.Add(string.Format("new KeyValuePair(\"{0}\", ShaderPropertyType.{1})\r\n", kv.Key, kv.Value)); - } - - return string.Format(@"using System.Collections.Generic; - - -namespace VRM -{{ - public static partial class VRMPreShaderPropExporter - {{ - [VRMPreExportShader] - static KeyValuePair {0} - {{ - get - {{ - return new KeyValuePair( - ""{1}"", - new ShaderProps - {{ - Properties = new KeyValuePair[]{{ -{2} - }} - }} - ); - }} - }} - }} -}} -" -, EscapeShaderName(shaderName) -, shaderName -, String.Join(",", list.ToArray())); - } -#endif - } - - #region Runtime - static Dictionary m_shaderPropMap; - - public static ShaderProps GetPropsForSupportedShader(string shaderName) - { - if (m_shaderPropMap == null) - { - m_shaderPropMap = new Dictionary(); - foreach (var prop in typeof(VRMPreShaderPropExporter).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) - { - if (prop.GetCustomAttributes(typeof(VRMPreExportShaderAttribute), true).Any()) - { - var kv = (KeyValuePair)prop.GetValue(null, null); - m_shaderPropMap.Add(kv.Key, kv.Value); - } - } - } - - ShaderProps props; - if (!m_shaderPropMap.TryGetValue(shaderName, out props)) - { - return null; - } - - return props; - } - #endregion - } -} diff --git a/Scripts/PreExportShaderProps/VRM_MToon.cs b/Scripts/PreExportShaderProps/VRM_MToon.cs index 4bfc0f263..614774d51 100644 --- a/Scripts/PreExportShaderProps/VRM_MToon.cs +++ b/Scripts/PreExportShaderProps/VRM_MToon.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -namespace VRM +namespace UniGLTF.ShaderPropExporter { - public static partial class VRMPreShaderPropExporter + public static partial class PreShaderPropExporter { - [VRMPreExportShader] + [PreExportShader] static KeyValuePair VRM_MToon { get @@ -14,37 +14,37 @@ namespace VRM "VRM/MToon", new ShaderProps { - Properties = new KeyValuePair[]{ -new KeyValuePair("_Cutoff", ShaderPropertyType.Range) -,new KeyValuePair("_Color", ShaderPropertyType.Color) -,new KeyValuePair("_ShadeColor", ShaderPropertyType.Color) -,new KeyValuePair("_MainTex", ShaderPropertyType.TexEnv) -,new KeyValuePair("_ShadeTexture", ShaderPropertyType.TexEnv) -,new KeyValuePair("_BumpScale", ShaderPropertyType.Float) -,new KeyValuePair("_BumpMap", ShaderPropertyType.TexEnv) -,new KeyValuePair("_ReceiveShadowRate", ShaderPropertyType.Range) -,new KeyValuePair("_ReceiveShadowTexture", ShaderPropertyType.TexEnv) -,new KeyValuePair("_ShadeShift", ShaderPropertyType.Range) -,new KeyValuePair("_ShadeToony", ShaderPropertyType.Range) -,new KeyValuePair("_LightColorAttenuation", ShaderPropertyType.Range) -,new KeyValuePair("_SphereAdd", ShaderPropertyType.TexEnv) -,new KeyValuePair("_EmissionColor", ShaderPropertyType.Color) -,new KeyValuePair("_EmissionMap", ShaderPropertyType.TexEnv) -,new KeyValuePair("_OutlineWidthTexture", ShaderPropertyType.TexEnv) -,new KeyValuePair("_OutlineWidth", ShaderPropertyType.Range) -,new KeyValuePair("_OutlineScaledMaxDistance", ShaderPropertyType.Range) -,new KeyValuePair("_OutlineColor", ShaderPropertyType.Color) -,new KeyValuePair("_OutlineLightingMix", ShaderPropertyType.Range) -,new KeyValuePair("_DebugMode", ShaderPropertyType.Float) -,new KeyValuePair("_BlendMode", ShaderPropertyType.Float) -,new KeyValuePair("_OutlineWidthMode", ShaderPropertyType.Float) -,new KeyValuePair("_OutlineColorMode", ShaderPropertyType.Float) -,new KeyValuePair("_CullMode", ShaderPropertyType.Float) -,new KeyValuePair("_OutlineCullMode", ShaderPropertyType.Float) -,new KeyValuePair("_SrcBlend", ShaderPropertyType.Float) -,new KeyValuePair("_DstBlend", ShaderPropertyType.Float) -,new KeyValuePair("_ZWrite", ShaderPropertyType.Float) -,new KeyValuePair("_IsFirstSetup", ShaderPropertyType.Float) + Properties = new ShaderProperty[]{ +new ShaderProperty("_Cutoff", ShaderPropertyType.Range, false) +,new ShaderProperty("_Color", ShaderPropertyType.Color, false) +,new ShaderProperty("_ShadeColor", ShaderPropertyType.Color, false) +,new ShaderProperty("_MainTex", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_ShadeTexture", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_BumpScale", ShaderPropertyType.Float, false) +,new ShaderProperty("_BumpMap", ShaderPropertyType.TexEnv, true) +,new ShaderProperty("_ReceiveShadowRate", ShaderPropertyType.Range, false) +,new ShaderProperty("_ReceiveShadowTexture", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_ShadeShift", ShaderPropertyType.Range, false) +,new ShaderProperty("_ShadeToony", ShaderPropertyType.Range, false) +,new ShaderProperty("_LightColorAttenuation", ShaderPropertyType.Range, false) +,new ShaderProperty("_SphereAdd", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_EmissionColor", ShaderPropertyType.Color, false) +,new ShaderProperty("_EmissionMap", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_OutlineWidthTexture", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_OutlineWidth", ShaderPropertyType.Range, false) +,new ShaderProperty("_OutlineScaledMaxDistance", ShaderPropertyType.Range, false) +,new ShaderProperty("_OutlineColor", ShaderPropertyType.Color, false) +,new ShaderProperty("_OutlineLightingMix", ShaderPropertyType.Range, false) +,new ShaderProperty("_DebugMode", ShaderPropertyType.Float, false) +,new ShaderProperty("_BlendMode", ShaderPropertyType.Float, false) +,new ShaderProperty("_OutlineWidthMode", ShaderPropertyType.Float, false) +,new ShaderProperty("_OutlineColorMode", ShaderPropertyType.Float, false) +,new ShaderProperty("_CullMode", ShaderPropertyType.Float, false) +,new ShaderProperty("_OutlineCullMode", ShaderPropertyType.Float, false) +,new ShaderProperty("_SrcBlend", ShaderPropertyType.Float, false) +,new ShaderProperty("_DstBlend", ShaderPropertyType.Float, false) +,new ShaderProperty("_ZWrite", ShaderPropertyType.Float, false) +,new ShaderProperty("_IsFirstSetup", ShaderPropertyType.Float, false) } } diff --git a/Scripts/PreExportShaderProps/VRM_MToon.cs.meta b/Scripts/PreExportShaderProps/VRM_MToon.cs.meta index fd900fccd..26afcbf63 100644 --- a/Scripts/PreExportShaderProps/VRM_MToon.cs.meta +++ b/Scripts/PreExportShaderProps/VRM_MToon.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 4629d794c8969c141a4724e182af082e -timeCreated: 1533041756 +timeCreated: 1533542890 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs b/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs index dedfa93bf..f642d49ba 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs +++ b/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -namespace VRM +namespace UniGLTF.ShaderPropExporter { - public static partial class VRMPreShaderPropExporter + public static partial class PreShaderPropExporter { - [VRMPreExportShader] + [PreExportShader] static KeyValuePair VRM_UnlitCutout { get @@ -14,9 +14,9 @@ namespace VRM "VRM/UnlitCutout", new ShaderProps { - Properties = new KeyValuePair[]{ -new KeyValuePair("_MainTex", ShaderPropertyType.TexEnv) -,new KeyValuePair("_Cutoff", ShaderPropertyType.Range) + Properties = new ShaderProperty[]{ +new ShaderProperty("_MainTex", ShaderPropertyType.TexEnv, false) +,new ShaderProperty("_Cutoff", ShaderPropertyType.Range, false) } } diff --git a/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs.meta b/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs.meta index e8189be1c..3f6607d2a 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs.meta +++ b/Scripts/PreExportShaderProps/VRM_UnlitCutout.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 611b546ea471ad34cb7d94740c63b558 -timeCreated: 1533041756 +timeCreated: 1533542890 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs b/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs index b5ba277e6..298a4b1a7 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs +++ b/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -namespace VRM +namespace UniGLTF.ShaderPropExporter { - public static partial class VRMPreShaderPropExporter + public static partial class PreShaderPropExporter { - [VRMPreExportShader] + [PreExportShader] static KeyValuePair VRM_UnlitTexture { get @@ -14,8 +14,8 @@ namespace VRM "VRM/UnlitTexture", new ShaderProps { - Properties = new KeyValuePair[]{ -new KeyValuePair("_MainTex", ShaderPropertyType.TexEnv) + Properties = new ShaderProperty[]{ +new ShaderProperty("_MainTex", ShaderPropertyType.TexEnv, false) } } diff --git a/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs.meta b/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs.meta index 66b977400..181adad30 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs.meta +++ b/Scripts/PreExportShaderProps/VRM_UnlitTexture.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 22a8083880389b3498f421e6a5c340d5 -timeCreated: 1533041756 +timeCreated: 1533542890 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs b/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs index ef5d8fe7a..f1edc22e2 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs +++ b/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -namespace VRM +namespace UniGLTF.ShaderPropExporter { - public static partial class VRMPreShaderPropExporter + public static partial class PreShaderPropExporter { - [VRMPreExportShader] + [PreExportShader] static KeyValuePair VRM_UnlitTransparent { get @@ -14,8 +14,8 @@ namespace VRM "VRM/UnlitTransparent", new ShaderProps { - Properties = new KeyValuePair[]{ -new KeyValuePair("_MainTex", ShaderPropertyType.TexEnv) + Properties = new ShaderProperty[]{ +new ShaderProperty("_MainTex", ShaderPropertyType.TexEnv, false) } } diff --git a/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs.meta b/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs.meta index c86b4cc0f..eeaf3b8d6 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs.meta +++ b/Scripts/PreExportShaderProps/VRM_UnlitTransparent.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 140d6538826e0eb448929d3e4bb2f1cd -timeCreated: 1533041756 +timeCreated: 1533542890 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs b/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs index 68dcd5f7d..35dea7bdf 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs +++ b/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -namespace VRM +namespace UniGLTF.ShaderPropExporter { - public static partial class VRMPreShaderPropExporter + public static partial class PreShaderPropExporter { - [VRMPreExportShader] + [PreExportShader] static KeyValuePair VRM_UnlitTransparentZWrite { get @@ -14,8 +14,8 @@ namespace VRM "VRM/UnlitTransparentZWrite", new ShaderProps { - Properties = new KeyValuePair[]{ -new KeyValuePair("_MainTex", ShaderPropertyType.TexEnv) + Properties = new ShaderProperty[]{ +new ShaderProperty("_MainTex", ShaderPropertyType.TexEnv, false) } } diff --git a/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs.meta b/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs.meta index 559b57d77..6efeb43e5 100644 --- a/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs.meta +++ b/Scripts/PreExportShaderProps/VRM_UnlitTransparentZWrite.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: 165ec79b7aac1564a850fb3d3d19396e -timeCreated: 1533041756 +timeCreated: 1533542890 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/UniGLTF b/UniGLTF index dfdfbfe21..c481c92e0 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit dfdfbfe2156bae29bab301b203d94ad087712fc4 +Subproject commit c481c92e0bef78ef8920e28343fdbbba5a04fdad