From 2fce44159d7ea911d1fca96077b9d27f560cd58c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 20 May 2020 17:07:16 +0900 Subject: [PATCH] add shader.name check --- .../UniGLTF/Scripts/IO/MaterialExporter.cs | 22 +++++++++++---- .../Scripts/Format/VRMExportSettings.cs | 27 ++++++++++++++++++- .../Scripts/Format/VRMMaterialExporter.cs | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs index 388cc21a4..9ef70c542 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using UniGLTF.UniUnlit; +using UniGLTF.UniUnlit; using UnityEngine; -using UnityEngine.Rendering; namespace UniGLTF @@ -185,7 +182,7 @@ namespace UniGLTF static void Export_TextureTransform(Material m, glTFTextureInfo textureInfo, string propertyName) { - if( textureInfo != null && m.HasProperty(propertyName)) + if (textureInfo != null && m.HasProperty(propertyName)) { var offset = m.GetTextureOffset(propertyName); var scale = m.GetTextureScale(propertyName); @@ -202,6 +199,21 @@ namespace UniGLTF } } + public static bool UseUnlit(string shaderName) + { + switch (shaderName) + { + case "Unlit/Color": + case "Unlit/Texture": + case "Unlit/Transparent": + case "Unlit/Transparent Cutout": + case "UniGLTF/UniUnlit": + return true; + } + return false; + + } + protected virtual glTFMaterial CreateMaterial(Material m) { switch (m.shader.name) diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs index d6f57a812..1872b82aa 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMExportSettings.cs @@ -112,10 +112,35 @@ namespace VRM yield return Validation.Error("ReduceBlendshapeSize is need VRMBlendShapeProxy, you need to convert to VRM once."); } - if (Source.GetComponentsInChildren().All(x => !x.gameObject.activeInHierarchy)) + var renderers = Source.GetComponentsInChildren(); + if (renderers.All(x => !x.gameObject.activeInHierarchy)) { yield return Validation.Error("No active mesh"); } + + var materials = renderers.SelectMany(x => x.sharedMaterials).Distinct(); + foreach (var material in materials) + { + if (material.shader.name == "Standard") + { + // standard + continue; + } + + if (MaterialExporter.UseUnlit(material.shader.name)) + { + // unlit + continue; + } + + if (VRMMaterialExporter.VRMExtensionShaders.Contains(material.shader.name)) + { + // VRM supported + continue; + } + + yield return Validation.Warning(string.Format("unknown material '{0}' is used. this will export as `Standard` fallback", material.shader.name)); + } } public void InitializeFrom(GameObject go) diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMMaterialExporter.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMMaterialExporter.cs index 06817d91d..fb759d1c8 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMMaterialExporter.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMMaterialExporter.cs @@ -101,7 +101,7 @@ namespace VRM } #region CreateFromMaterial - private static readonly string[] VRMExtensionShaders = new string[] + public static readonly string[] VRMExtensionShaders = new string[] { "VRM/UnlitTransparentZWrite", "VRM/MToon"