diff --git a/Scripts/Format/Editor/VRMExporter.cs b/Scripts/Format/Editor/VRMExporter.cs index 19800ebfe..9a3f7f673 100644 --- a/Scripts/Format/Editor/VRMExporter.cs +++ b/Scripts/Format/Editor/VRMExporter.cs @@ -12,13 +12,19 @@ namespace VRM public VRMExporter(glTF_VRM gltf) : base(gltf) { } - public static glTF Export(GameObject go, string path = null) + public static glTF Export(GameObject go, string path = null, Action callback=null) { var gltf = new glTF_VRM(); gltf.asset.generator = "Unity VRM Exporter"; using (var exporter = new VRMExporter(gltf)) { _Export(gltf, exporter, go); + + if (callback != null) + { + callback(gltf); + } + if (!string.IsNullOrEmpty(path)) { exporter.WriteTo(path); diff --git a/Scripts/Format/Editor/VRMExporterMenu.cs b/Scripts/Format/Editor/VRMExporterMenu.cs index 3b7ba602c..8252c8b8a 100644 --- a/Scripts/Format/Editor/VRMExporterMenu.cs +++ b/Scripts/Format/Editor/VRMExporterMenu.cs @@ -4,6 +4,7 @@ using UnityEditor; using UnityEngine; using UniGLTF; using System.IO; +using System.Text; namespace VRM { @@ -12,6 +13,11 @@ namespace VRM const string EXTENSION = ".vrm"; public GameObject Target; + VRMMeta m_meta; + + public string Title; + + public string Author; public bool ForceTPose; @@ -30,24 +36,50 @@ namespace VRM wiz.ForceTPose = true; wiz.PoseFreeze = true; } + + var meta = wiz.Target.GetComponent(); + if (meta != null && meta.Meta != null) + { + wiz.Title = meta.Meta.Title; + wiz.Author = meta.Meta.Author; + } + else + { + wiz.Title = wiz.Target.name; + } } - static string m_dir = Path.GetFullPath(Application.dataPath); + string m_dir; + string Dir + { + get + { + if (m_dir == null) + { + m_dir = Path.GetFullPath(Application.dataPath); ; + } + return m_dir; + } + set + { + m_dir = value; + } + } void OnWizardCreate() { // save dialog - Debug.LogFormat("OnWizardCreate: {0}", m_dir); + Debug.LogFormat("OnWizardCreate: {0}", Dir); var path = EditorUtility.SaveFilePanel( "Save vrm", - m_dir, + Dir, Target.name + EXTENSION, EXTENSION.Substring(1)); if (string.IsNullOrEmpty(path)) { return; } - m_dir = Path.GetDirectoryName(path); + Dir = Path.GetDirectoryName(path); // export var target = Target; @@ -60,7 +92,12 @@ namespace VRM Undo.PerformUndo(); } - VRMExporter.Export(target, path); + VRMExporter.Export(target, path, gltf => { + + gltf.extensions.VRM.meta.title = Title; + gltf.extensions.VRM.meta.author = Author; + + }); if (Target!=target) { @@ -75,8 +112,26 @@ namespace VRM void OnWizardUpdate() { - helpString = @"select humanoid root(require Animator with valid humanoid avatar). -"; + isValid = true; + var helpBuilder = new StringBuilder(); + var errorBuilder = new StringBuilder(); + + helpBuilder.Append("select humanoid root(require Animator with valid humanoid avatar).\n"); + + if (string.IsNullOrEmpty(Title)) + { + isValid = false; + errorBuilder.Append("input vrm Title\n"); + } + + if (string.IsNullOrEmpty(Author)) + { + isValid = false; + errorBuilder.Append("input vrm Author\n"); + } + + helpString = helpBuilder.ToString(); + errorString = errorBuilder.ToString(); } } diff --git a/Scripts/Format/VRMVersion.cs b/Scripts/Format/VRMVersion.cs index 2a84d20c9..8cb52810b 100644 --- a/Scripts/Format/VRMVersion.cs +++ b/Scripts/Format/VRMVersion.cs @@ -4,11 +4,11 @@ namespace VRM public static class VRMVersion { public const int MAJOR = 0; - public const int MINOR = 27; + public const int MINOR = 28; - public const string VERSION = "0.27"; + public const string VERSION = "0.28"; - public const string DecrementMenuName = "VRM/Version(0.27) Decrement"; - public const string IncrementMenuName = "VRM/Version(0.27) Increment"; + public const string DecrementMenuName = "VRM/Version(0.28) Decrement"; + public const string IncrementMenuName = "VRM/Version(0.28) Increment"; } }