diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs index bf6d15af4..b1c9f32a5 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs @@ -3,6 +3,9 @@ using UnityEngine; namespace UniGLTF { + /// + /// MeshExportValidator から使われる + /// public interface IMaterialValidator { /// diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs index 976a39ff4..5ab9e55a8 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs @@ -85,7 +85,7 @@ namespace UniGLTF var gltfMaterial = MaterialValidator.GetGltfMaterialTypeFromUnityShaderName(m.shader.name); if (string.IsNullOrEmpty(gltfMaterial)) { - yield return Validation.Warning($"{m}: unknown shader: {m.shader.name} => export as gltf default"); + yield return Validation.Warning($"{m}: unknown shader: {m.shader.name} => export as gltf default", ValidationContext.Create(m)); } var used = new HashSet(); diff --git a/Assets/VRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/Editor/Format/VRMExporterWizard.cs index 171533f06..be621b52f 100644 --- a/Assets/VRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/Editor/Format/VRMExporterWizard.cs @@ -121,42 +121,6 @@ namespace VRM m_meshes = null; } - /// - /// VRM0 - /// - class VRMMaterialValidator : DefaultMaterialValidator - { - public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName) - { - var name = VRMMaterialExporter.VrmMaterialName(shaderName); - if (!string.IsNullOrEmpty(name)) - { - return name; - } - return base.GetGltfMaterialTypeFromUnityShaderName(shaderName); - } - - public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) - { - if (m.shader.name != "VRM/MToon") - { - foreach (var x in base.EnumerateTextureProperties(m)) - { - yield return x; - } - } - - var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); - foreach (var kv in prop.Properties) - { - if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv) - { - yield return (kv.Key, m.GetTexture(kv.Key)); - } - } - } - } - protected override IEnumerable ValidatorFactory() { // ヒエラルキー のチェック diff --git a/Assets/VRM/Editor/Format/VRMMaterialValidator.cs b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs new file mode 100644 index 000000000..941e59038 --- /dev/null +++ b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace VRM +{ + /// + /// VRM0 + /// + class VRMMaterialValidator : UniGLTF.DefaultMaterialValidator + { + public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName) + { + var name = VRMMaterialExporter.VrmMaterialName(shaderName); + if (!string.IsNullOrEmpty(name)) + { + return name; + } + return base.GetGltfMaterialTypeFromUnityShaderName(shaderName); + } + + public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) + { + /// 歴史的経緯により処理ロジックが2種類ある + if (m.shader.name == "VRM/MToon") + { + // [Unity列挙] + // * UnityEditor.ShaderUtil により Shader の Property を列挙する。Editor専用。 + // * あらかじめEditorで実行して property 一覧をハードコーディングしてある `Assets\VRMShaders\VRM\IO\Runtime\VRM\PreExportShaders_VRM.cs` 界隈。 + // * 今は "VRM/MToon" のみ + // + // extensions.VRM.materialProperties に記録する + // + var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); + foreach (var kv in prop.Properties) + { + if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv) + { + yield return (kv.Key, m.GetTexture(kv.Key)); + } + } + } + else + { + // [Shaderの定義から手で記述] + // + // PBR, Unlit + // * DefaultMaterialValidator.EnumerateTextureProperties + // + // glTF.materials に記録する + // + foreach (var textureProperty in base.EnumerateTextureProperties(m)) + { + yield return textureProperty; + } + } + } + } +} diff --git a/Assets/VRM10/Editor/GeneratorMenu.cs.meta b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta similarity index 83% rename from Assets/VRM10/Editor/GeneratorMenu.cs.meta rename to Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta index da8113e9c..375a03af3 100644 --- a/Assets/VRM10/Editor/GeneratorMenu.cs.meta +++ b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7f8755f9d806837408cd04ebb587489c +guid: 43a9939275e36534797e9be6fb83c71e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Editor/Components/VRM10Window.cs b/Assets/VRM10/Editor/Components/VRM10Window.cs index 588d262d8..3612409eb 100644 --- a/Assets/VRM10/Editor/Components/VRM10Window.cs +++ b/Assets/VRM10/Editor/Components/VRM10Window.cs @@ -10,11 +10,8 @@ namespace UniVRM10 /// public class VRM10Window : EditorWindow { - const string MENU_KEY = VRMVersion.MENU + "/VRM1 Window"; const string WINDOW_TITLE = "VRM1 Window"; - - [MenuItem(MENU_KEY, false, 1)] - private static void ExportFromMenu() + public static void Open() { var window = (VRM10Window)GetWindow(typeof(VRM10Window)); window.titleContent = new GUIContent(WINDOW_TITLE); diff --git a/Assets/VRM10/Editor/VRM10MaterialValidator.cs b/Assets/VRM10/Editor/VRM10MaterialValidator.cs new file mode 100644 index 000000000..083557e46 --- /dev/null +++ b/Assets/VRM10/Editor/VRM10MaterialValidator.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UniVRM10 +{ + /// + /// VRM0 + /// + class VRM10MaterialValidator : UniGLTF.DefaultMaterialValidator + { + const string MTOON_SHADER_NAME = "VRM10/MToon10"; + + public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName) + { + switch (shaderName) + { + case MTOON_SHADER_NAME: + return "VRMC_materials_mtoon"; + } + + // TODO: VRM-0.X + + return base.GetGltfMaterialTypeFromUnityShaderName(shaderName); + } + + public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) + { + if (m.shader.name == MTOON_SHADER_NAME) + { + // TODO + } + else + { + foreach (var x in base.EnumerateTextureProperties(m)) + { + yield return x; + } + } + } + } +} diff --git a/Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta b/Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta new file mode 100644 index 000000000..8d92b1cf7 --- /dev/null +++ b/Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 77bcf6c00ae8990488aaea60f0ec9173 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/Vrm10ExportDialog.cs b/Assets/VRM10/Editor/Vrm10ExportDialog.cs index b2518cd9c..2650292df 100644 --- a/Assets/VRM10/Editor/Vrm10ExportDialog.cs +++ b/Assets/VRM10/Editor/Vrm10ExportDialog.cs @@ -13,10 +13,7 @@ namespace UniVRM10 { public class VRM10ExportDialog : ExportDialogBase { - const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0"; - - [MenuItem(CONVERT_HUMANOID_KEY, false, 0)] - private static void ExportFromMenu() + public static void Open() { var window = (VRM10ExportDialog)GetWindow(typeof(VRM10ExportDialog)); window.titleContent = new GUIContent("VRM-1.0 Exporter"); @@ -136,6 +133,10 @@ namespace UniVRM10 yield break; } + // Mesh/Renderer のチェック + m_meshes.MaterialValidator = new VRM10MaterialValidator(); + yield return m_meshes.Validate; + yield return HumanoidValidator.Validate_TPose; // MeshUtility.Validators.HumanoidValidator.EnableFreeze = false; diff --git a/Assets/VRM10/Editor/GeneratorMenu.cs b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs similarity index 89% rename from Assets/VRM10/Editor/GeneratorMenu.cs rename to Assets/VRM10/Editor/Vrm10SerializerGenerator.cs index 1b4294680..e1c22f856 100644 --- a/Assets/VRM10/Editor/GeneratorMenu.cs +++ b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs @@ -13,22 +13,8 @@ namespace UniVRM10 /// は SubModuleになった。 `$ git submodule update --init` しておくこと。 /// /// - public static class Menu + public static class Vrm10SerializerGenerator { -#if VRM_DEVELOP - [MenuItem(UniVRM10.VRMVersion.MENU + "/Generate from JsonSchema")] - public static void Generate() - { - Run(false); - } - - [MenuItem(UniVRM10.VRMVersion.MENU + "/Generate from JsonSchema(debug)")] - public static void Parse() - { - Run(true); - } -#endif - struct GenerateInfo { public string JsonSchema; @@ -49,7 +35,7 @@ namespace UniVRM10 const string SPEC_DIR = "vrm-specification/specification"; - static void Run(bool debug) + public static void Run(bool debug) { var projectRoot = new DirectoryInfo(Path.GetFullPath(Path.Combine(Application.dataPath, "../"))); diff --git a/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs.meta b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs.meta new file mode 100644 index 000000000..1b098ddea --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7e5497454373c2a458526799422de3ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/Vrm10TopMenu.cs b/Assets/VRM10/Editor/Vrm10TopMenu.cs new file mode 100644 index 000000000..426024e81 --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10TopMenu.cs @@ -0,0 +1,25 @@ +using UnityEditor; + +namespace UniVRM10 +{ + public static class Vrm10TopMenu + { + private const string UserMenuPrefix = VRMVersion.MENU; + private const string DevelopmentMenuPrefix = VRMVersion.MENU + "/Development"; + + const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0"; + [MenuItem(UserMenuPrefix + "/Export VRM-1.0", priority = 1)] + static void OpenExportDialog() => VRM10ExportDialog.Open(); + +#if VRM_DEVELOP + [MenuItem(UserMenuPrefix + "/VRM1 Window", false, 2)] + static void OpenWindow() => VRM10Window.Open(); + + [MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema")] + public static void Generate() => Vrm10SerializerGenerator.Run(false); + + [MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema(debug)")] + public static void Parse() => Vrm10SerializerGenerator.Run(true); +#endif + } +} diff --git a/Assets/VRM10/Editor/Vrm10TopMenu.cs.meta b/Assets/VRM10/Editor/Vrm10TopMenu.cs.meta new file mode 100644 index 000000000..9750afd3e --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10TopMenu.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 935fd2eb9940f5d48933733f69a96113 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: