Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tpose button #895

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ static BeginVerticalScrollViewFunc BeginVerticalScrollView
void OnGUI()
{
var modified = false;
if (BeginGUI())
{
modified = DoGUI();
}
var isValid = BeginGUI();
modified = DoGUI(isValid);
EndGUI();

if (modified)
Expand All @@ -89,7 +87,7 @@ void OnGUI()
}
}

protected abstract bool DoGUI();
protected abstract bool DoGUI(bool isValid);

protected virtual void OnLayout()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ protected override IEnumerable<Validator> ValidatorFactory()
yield break;
}
}
protected override bool DoGUI()
protected override bool DoGUI(bool isValid)
{
if (!isValid)
{
return false;
}

m_settings.Root = State.ExportRoot;
m_settingsInspector.OnInspectorGUI();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UniGLTF;
using UniGLTF.M17N;
using UnityEngine;

namespace VRM
namespace UniGLTF
{
public enum EnableTPose
{
[LangMsg(Languages.ja, "このボタンで自動で T-Pose にできます。手動で T-Pose にしたり、ボタンの後で手直ししてもOKです。")]
[LangMsg(Languages.en, "T-Pose can be made automatically with this button, or you can make the model as T-Pose manually. Adjusting T-Pose manually after applying this function is also OK")]
ENALBE_TPOSE_BUTTON,

[LangMsg(Languages.ja, "このボタンで自動で T-Pose にできます。prefab には実行できません。")]
[LangMsg(Languages.en, "T-Pose can be made automatically with this button. It cannot be run on prefabs.")]
DISABLE_TPOSE_BUTTON,
}

public static class InternalTPose
{
struct TRS
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 0 additions & 54 deletions Assets/VRM/Editor/Format/VRMExportSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
using System;
using UnityEditor;
using UnityEngine;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using UniGLTF;
using UniGLTF.M17N;

namespace VRM
Expand Down Expand Up @@ -86,14 +82,6 @@ public enum Options
[LangMsg(Languages.en, "Vertex color will not be exported")]
REMOVE_VERTEX_COLOR,

[LangMsg(Languages.ja, "このボタンで自動で T-Pose にできます。手動で T-Pose にしたり、ボタンの後で手直ししてもOKです。")]
[LangMsg(Languages.en, "T-Pose can be made automatically with this button, or you can make the model as T-Pose manually. Adjusting T-Pose manually after applying this function is also OK")]
ENALBE_TPOSE_BUTTON,

[LangMsg(Languages.ja, "このボタンで自動で T-Pose にできます。prefab には実行できません。")]
[LangMsg(Languages.en, "T-Pose can be made automatically with this button. It cannot be run on prefabs.")]
DISABLE_TPOSE_BUTTON,

[LangMsg(Languages.ja, "T-Pose にする")]
[LangMsg(Languages.en, "Make T-Pose")]
DO_TPOSE,
Expand All @@ -119,48 +107,6 @@ public override void OnInspectorGUI()
GUILayout.Space(20);
var settings = (VRMExportSettings)target;
var root = settings.Root;
var backup = GUI.enabled;
GUI.enabled = root.scene.IsValid();
if (GUI.enabled)
{
EditorGUILayout.HelpBox(Options.ENALBE_TPOSE_BUTTON.Msg(), MessageType.Info);
}
else
{
EditorGUILayout.HelpBox(Options.DISABLE_TPOSE_BUTTON.Msg(), MessageType.Warning);
}

//
// T-Pose
//
if (GUILayout.Button(VRMExportSettingsEditor.Options.DO_TPOSE.Msg()))
{
if (settings.Root != null)
{
// fallback
Undo.RecordObjects(settings.Root.GetComponentsInChildren<Transform>(), "tpose");
VRMBoneNormalizer.EnforceTPose(settings.Root);
}
}

if (GUILayout.Button(VRMExportSettingsEditor.Options.DO_TPOSE.Msg() + "(unity internal)"))
{
if (settings.Root != null)
{
Undo.RecordObjects(settings.Root.GetComponentsInChildren<Transform>(), "tpose.internal");
if (InternalTPose.TryMakePoseValid(settings.Root))
{
// done
}
else
{
Debug.LogWarning("not found");
}
}
}

GUI.enabled = backup;
GUILayout.Space(20);

// ToDo: 任意の BlendShapeClip を適用する

Expand Down
63 changes: 62 additions & 1 deletion Assets/VRM/Editor/Format/VRMExporterWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,71 @@ protected override void OnLayout()
m_meshes.SetRoot(State.ExportRoot, m_settings);
}

protected override bool DoGUI()
protected override bool DoGUI(bool isValid)
{
if (State.ExportRoot == null)
{
return false;
}

//
// T-Pose
//
if (State.ExportRoot.GetComponent<Animator>() != null)
{
var backup = GUI.enabled;
GUI.enabled = State.ExportRoot.scene.IsValid();
if (GUI.enabled)
{
EditorGUILayout.HelpBox(EnableTPose.ENALBE_TPOSE_BUTTON.Msg(), MessageType.Info);
}
else
{
EditorGUILayout.HelpBox(EnableTPose.DISABLE_TPOSE_BUTTON.Msg(), MessageType.Warning);
}

//
// T-Pose
//
if (GUILayout.Button(VRMExportSettingsEditor.Options.DO_TPOSE.Msg()))
{
if (State.ExportRoot != null)
{
// fallback
Undo.RecordObjects(State.ExportRoot.GetComponentsInChildren<Transform>(), "tpose");
VRMBoneNormalizer.EnforceTPose(State.ExportRoot);
Repaint();
}
}

if (GUILayout.Button(VRMExportSettingsEditor.Options.DO_TPOSE.Msg() + "(unity internal)"))
{
if (State.ExportRoot != null)
{
Undo.RecordObjects(State.ExportRoot.GetComponentsInChildren<Transform>(), "tpose.internal");
if (InternalTPose.TryMakePoseValid(State.ExportRoot))
{
// done
Repaint();
}
else
{
Debug.LogWarning("not found");
}
}
}

GUI.enabled = backup;
}

if (!isValid)
{
return false;
}

EditorGUILayout.HelpBox($"Mesh size: {m_meshes.ExpectedExportByteSize / 1000000.0f:0.0} MByte", MessageType.Info);


//
// GUI
//
Expand Down
87 changes: 58 additions & 29 deletions Assets/VRM10/Editor/Vrm10ExportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using UniGLTF;
using UniGLTF.M17N;
using UnityEditor;
using UnityEngine;
using VrmLib;
Expand Down Expand Up @@ -134,36 +135,64 @@ protected override IEnumerable<Validator> ValidatorFactory()
yield return meta.Validate;
}

// private void OnGUI()
// {
// {
// var path = SaveFileDialog.GetPath("Save vrm1", $"{State.ExportRoot.name}.vrm", "vrm");
// if (!string.IsNullOrEmpty(path))
// {
// // export
// Export(State.ExportRoot, path);
// // close
// Close();
// GUIUtility.ExitGUI();
// }
// }
// GUI.enabled = true;

// GUILayout.EndHorizontal();
// }
// GUILayout.EndVertical();
// }

// GUILayout.Space(8);

// if (modified)
// {
// State.Invalidate();
// }
// }

protected override bool DoGUI()
protected override bool DoGUI(bool isValid)
{
if (State.ExportRoot == null)
{
return false;
}

if (State.ExportRoot.GetComponent<Animator>() != null)
{
//
// T-Pose
//
// if (GUILayout.Button("T-Pose"))
// {
// if (State.ExportRoot != null)
// {
// // fallback
// Undo.RecordObjects(State.ExportRoot.GetComponentsInChildren<Transform>(), "tpose");
// VRMBoneNormalizer.EnforceTPose(State.ExportRoot);
// }
// }

var backup = GUI.enabled;
GUI.enabled = State.ExportRoot.scene.IsValid();
if (GUI.enabled)
{
EditorGUILayout.HelpBox(EnableTPose.ENALBE_TPOSE_BUTTON.Msg(), MessageType.Info);
}
else
{
EditorGUILayout.HelpBox(EnableTPose.DISABLE_TPOSE_BUTTON.Msg(), MessageType.Warning);
}

if (GUILayout.Button("T-Pose" + "(unity internal)"))
{
if (State.ExportRoot != null)
{
Undo.RecordObjects(State.ExportRoot.GetComponentsInChildren<Transform>(), "tpose.internal");
if (InternalTPose.TryMakePoseValid(State.ExportRoot))
{
// done
Repaint();
}
else
{
Debug.LogWarning("not found");
}
}
}

GUI.enabled = backup;
}

if (!isValid)
{
return false;
}

if (m_tmpMeta == null)
{
// disabled
Expand Down