Skip to content

Commit

Permalink
Merge pull request #903 from ousttrue/feature10/export_dialog_validator
Browse files Browse the repository at this point in the history
Feature10/export dialog validator
  • Loading branch information
PoChang007 authored Apr 22, 2021
2 parents 354d8b1 + 81a4b1f commit c3a5965
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 101 deletions.
22 changes: 19 additions & 3 deletions Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ private static void ExportFromMenu()
window.Show();
}

private static void Export(GameObject go, string path, MeshExportSettings settings, Axises inverseAxis)

enum Tabs
{
Mesh,
ExportSettings,
}
Tabs _tab;


GltfExportSettings m_settings;
Editor m_settingsInspector;
Expand Down Expand Up @@ -57,8 +62,19 @@ protected override bool DoGUI(bool isValid)
return false;
}

m_settings.Root = State.ExportRoot;
m_settingsInspector.OnInspectorGUI();
// tabbar
_tab = MeshUtility.TabBar.OnGUI(_tab);
switch (_tab)
{
case Tabs.Mesh:
break;

case Tabs.ExportSettings:
m_settings.Root = State.ExportRoot;
m_settingsInspector.OnInspectorGUI();
break;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

using System;
using UnityEditor;
using UnityEngine;

namespace UniGLTF
{
[CustomEditor(typeof(MeshExportValidator))]
public class MeshExportValidatorEditor : Editor
{
MeshExportValidator m_target;

private void OnEnable()
{
m_target = target as MeshExportValidator;
}

public override void OnInspectorGUI()
{
for (int i = 0; i < m_target.Meshes.Count; ++i)
{
DrawElement(i, m_target.Meshes[i]);
}
}

static (Rect, Rect) LeftRight(float x, float y, float left, float right, float height)
{
return (
new Rect(x, y, left, height),
new Rect(x + left, y, right, height)
);
}

void DrawElement(int i, UniGLTF.MeshExportInfo info)
{
var r = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(EditorGUIUtility.singleLineHeight * 3 + 20));
var col0 = 32;
var (left, right) = LeftRight(r.x, r.y, col0, r.width - col0, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(left, $"{i,3}");

GUI.enabled = false;
EditorGUI.ObjectField(right, info.Renderer, info.Renderer.GetType(), true);

right.y += EditorGUIUtility.singleLineHeight;
EditorGUI.ObjectField(right, info.Mesh, info.Renderer.GetType(), true);
GUI.enabled = true;

right.y += EditorGUIUtility.singleLineHeight;
EditorGUI.LabelField(right, info.Summary);
}
}
}

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

46 changes: 2 additions & 44 deletions Assets/VRM/Editor/Format/VRMExportMeshesEditor.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@

using System;
using UniGLTF;
using UnityEditor;
using UnityEngine;

namespace VRM
{
[CustomEditor(typeof(VRMExportMeshes))]
public class VRMExportMeshesEditor : Editor
public class VRMExportMeshesEditor : MeshExportValidatorEditor
{
VRMExportMeshes m_target;

private void OnEnable()
{
m_target = target as VRMExportMeshes;
}

public override void OnInspectorGUI()
{
for (int i = 0; i < m_target.Meshes.Count; ++i)
{
DrawElement(i, m_target.Meshes[i]);
}
}

static (Rect, Rect) LeftRight(float x, float y, float left, float right, float height)
{
return (
new Rect(x, y, left, height),
new Rect(x + left, y, right, height)
);
}

void DrawElement(int i, UniGLTF.MeshExportInfo info)
{
var r = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(EditorGUIUtility.singleLineHeight * 3 + 20));
var col0 = 32;
var (left, right) = LeftRight(r.x, r.y, col0, r.width - col0, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(left, $"{i,3}");

GUI.enabled = false;
EditorGUI.ObjectField(right, info.Renderer, info.Renderer.GetType(), true);

right.y += EditorGUIUtility.singleLineHeight;
EditorGUI.ObjectField(right, info.Mesh, info.Renderer.GetType(), true);
GUI.enabled = true;

right.y += EditorGUIUtility.singleLineHeight;
EditorGUI.LabelField(right, info.Summary);
}
}
}
49 changes: 26 additions & 23 deletions Assets/VRM/Editor/Format/VRMExporterWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private static void ExportFromMenu()
window.Show();
}


enum Tabs
{
Meta,
Expand All @@ -29,8 +30,14 @@ enum Tabs
}
Tabs _tab;


VRMExportSettings m_settings;
Editor m_settingsInspector;


VRMExportMeshes m_meshes;
Editor m_meshesInspector;


VRMMetaObject m_meta;
VRMMetaObject Meta
Expand All @@ -50,12 +57,9 @@ VRMMetaObject Meta
m_meta = value;
}
}

VRMMetaObject m_tmpMeta;

Editor m_metaEditor;
Editor m_settingsInspector;
Editor m_meshesInspector;


protected override void Initialize()
{
Expand Down Expand Up @@ -118,12 +122,6 @@ protected override void Clear()
m_meshes = null;
}

protected override string SaveTitle => "Save vrm0";

protected override string SaveName => $"{State.ExportRoot.name}.vrm";

protected override string[] SaveExtensions => new string[] { "vrm" };

protected override IEnumerable<Validator> ValidatorFactory()
{
HumanoidValidator.MeshInformations = m_meshes.Meshes;
Expand Down Expand Up @@ -156,19 +154,6 @@ protected override IEnumerable<Validator> ValidatorFactory()
yield return meta.Validate;
}

protected override void ExportPath(string path)
{
var bytes = VRMEditorExporter.Export(State.ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings);

File.WriteAllBytes(path, bytes);

if (path.StartsWithUnityAssetPath())
{
// 出力ファイルのインポートを発動
AssetDatabase.ImportAsset(path.ToUnityRelativePath());
}
}

protected override void OnLayout()
{
// m_settings, m_meshes.Meshes
Expand Down Expand Up @@ -256,6 +241,23 @@ protected override bool DoGUI(bool isValid)
return DrawWizardGUI();
}

protected override string SaveTitle => "Save vrm0";
protected override string SaveName => $"{State.ExportRoot.name}.vrm";
protected override string[] SaveExtensions => new string[] { "vrm" };

protected override void ExportPath(string path)
{
var bytes = VRMEditorExporter.Export(State.ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings);

File.WriteAllBytes(path, bytes);

if (path.StartsWithUnityAssetPath())
{
// 出力ファイルのインポートを発動
AssetDatabase.ImportAsset(path.ToUnityRelativePath());
}
}

bool DrawWizardGUI()
{
if (m_tmpMeta == null)
Expand Down Expand Up @@ -334,6 +336,7 @@ void OnBlendShapeGUI(VRMBlendShapeProxy proxy)

if (!proxy)
{
EditorGUILayout.HelpBox("no BlendShapeProxy", MessageType.Warning);
return;
}
var avatar = proxy.BlendShapeAvatar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class VRM10SpringSelectorWindow : EditorWindow
{
const string MENU_KEY = VRMVersion.MENU + "/SpringBone Window";

[MenuItem(MENU_KEY, false, 0)]
[MenuItem(MENU_KEY, false, 1)]
private static void ExportFromMenu()
{
var window = (VRM10SpringSelectorWindow)GetWindow(typeof(VRM10SpringSelectorWindow));
Expand Down
31 changes: 31 additions & 0 deletions Assets/VRM10/Editor/VRM10ExportSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using UniGLTF;
using UnityEngine;

namespace UniVRM10
{
[Serializable]
public class VRM10ExportSettings : ScriptableObject
{
/// <summary>
/// エクスポート時にBlendShapeClipから参照されないBlendShapeを削除する
/// </summary>
[Tooltip("Remove blendshape that is not used from BlendShapeClip")]
public bool ReduceBlendshape = false;

/// <summary>
/// skip if BlendShapeClip.Preset == Unknown
/// </summary>
[Tooltip("Remove blendShapeClip that preset is Unknown")]
public bool ReduceBlendshapeClip = false;

public MeshExportSettings MeshExportSettings => new MeshExportSettings
{
UseSparseAccessorForMorphTarget = true,
ExportOnlyBlendShapePosition = true,
DivideVertexBuffer = true,
};

public GameObject Root { get; set; }
}
}
11 changes: 11 additions & 0 deletions Assets/VRM10/Editor/VRM10ExportSettings.cs.meta

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

Loading

0 comments on commit c3a5965

Please sign in to comment.