From feab5ccc616dc1089e5ba02bdfd64c21ea49a485 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 2 Oct 2020 13:22:08 +0900 Subject: [PATCH] =?UTF-8?q?Export=20=E6=99=82=E3=81=AE=20Mesh=20=E8=A9=B3?= =?UTF-8?q?=E7=B4=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs | 4 +- .../UniVRM/Editor/Format/VRMExportMeshes.cs | 49 ++++++++++++++++--- .../Editor/Format/VRMExportMeshesEditor.cs | 43 +++++++++++----- 3 files changed, 76 insertions(+), 20 deletions(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs index e5ed04f6e..9969922fe 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MeshExporter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using UnityEngine; namespace UniGLTF @@ -53,8 +54,9 @@ namespace UniGLTF public int ExportBlendShapeCount; public int ExportByteSize => ExportVertexSize * VertexCount + IndicesSize + ExportBlendShapeCount * ExportBlendShapeVertexSize * VertexCount; - } + public string Summary; + } public struct MeshExportSettings { diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshes.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshes.cs index e7aaa06e2..b21dadd88 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshes.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshes.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using UnityEngine; namespace VRM @@ -66,8 +67,15 @@ namespace VRM return UniGLTF.UniUnlit.Utils.GetVColBlendMode(m) == UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.Multiply; } - public static void CalcMeshSize(UniGLTF.MeshExportInfo info, string relativePath, VRMExportSettings settings, IReadOnlyList clips) + public static void CalcMeshSize(ref UniGLTF.MeshExportInfo info, + string relativePath, VRMExportSettings settings, IReadOnlyList clips) { + var sb = new StringBuilder(); + if (!info.IsRendererActive) + { + sb.Append("[NotActive]"); + } + info.VertexCount = info.Mesh.vertexCount; info.ExportVertexSize = 0; info.TotalBlendShapeCount = 0; @@ -75,21 +83,26 @@ namespace VRM // float4 x 3 // vertices - if (info.Mesh.normals != null) + sb.Append($"(Pos"); + if (info.Mesh.normals != null && info.Mesh.normals.Length == info.Mesh.vertexCount) { + sb.Append("+Nom"); info.ExportVertexSize += 4 * 3; } - if (info.Mesh.uv != null) + if (info.Mesh.uv != null && info.Mesh.uv.Length == info.Mesh.vertexCount) { + sb.Append("+UV"); info.ExportVertexSize += 4 * 2; } - if (info.Mesh.colors != null) + if (info.Mesh.colors != null && info.Mesh.colors.Length == info.Mesh.vertexCount) { + sb.Append("+Col"); info.ExportVertexSize += 4 * 4; } - if (info.Mesh.boneWeights != null) + if (info.Mesh.boneWeights != null && info.Mesh.boneWeights.Length == info.Mesh.vertexCount) { // short, float x 4 weights + sb.Append("+Skin"); info.ExportVertexSize += (2 + 4) * 4; } // indices @@ -116,6 +129,23 @@ namespace VRM ++info.ExportBlendShapeCount; } + + if (info.ExportBlendShapeCount > 0) + { + sb.Append($"+Morph x {info.ExportBlendShapeCount}"); + } + sb.Append($") x {info.Mesh.vertexCount}"); + switch (info.VertexColor) + { + case UniGLTF.MeshExportInfo.VertexColorState.ExistsAndIsUsed: + sb.Insert(0, "[use vcolor]"); + break; + case UniGLTF.MeshExportInfo.VertexColorState.ExistsButNotUsed: + sb.Insert(0, "[remove vcolor]"); + break; + } + sb.Insert(0, $"{info.ExportByteSize:#,0} Bytes = "); + info.Summary = sb.ToString(); } bool TryGetMeshInfo(GameObject root, Renderer renderer, IReadOnlyList clips, VRMExportSettings settings, out UniGLTF.MeshExportInfo info) @@ -123,10 +153,12 @@ namespace VRM info = default; if (root == null) { + info.Summary = ""; return false; } if (renderer == null) { + info.Summary = "no Renderer"; return false; } info.Renderer = renderer; @@ -148,12 +180,10 @@ namespace VRM } else { + info.Summary = "no Mesh"; return false; } - var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(renderer.transform, root.transform); - CalcMeshSize(info, relativePath, settings, clips); - if (info.Mesh.colors != null && info.Mesh.colors.Length == info.Mesh.vertexCount) { if (renderer.sharedMaterials.Any(x => MaterialUseVertexColor(x))) @@ -166,6 +196,9 @@ namespace VRM } } + var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(renderer.transform, root.transform); + CalcMeshSize(ref info, relativePath, settings, clips); + return true; } diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshesEditor.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshesEditor.cs index 5efb7297f..f650385c3 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshesEditor.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportMeshesEditor.cs @@ -9,24 +9,45 @@ namespace VRM [CustomEditor(typeof(VRMExportMeshes))] public class VRMExportMeshesEditor : Editor { - VRMExportMeshes m_meshes; + VRMExportMeshes m_target; + private void OnEnable() { - m_meshes = target as VRMExportMeshes; - // m_forceTPose = new CheckBoxProp(serializedObject.FindProperty(nameof(ForceTPose)), Options.FORCE_T_POSE); - // m_poseFreeze = new CheckBoxProp(serializedObject.FindProperty(nameof(PoseFreeze)), Options.NORMALIZE); - // m_useSparseAccessor = new CheckBoxProp(serializedObject.FindProperty(nameof(UseSparseAccessor)), Options.BLENDSHAPE_USE_SPARSE); - // m_onlyBlendShapePosition = new CheckBoxProp(serializedObject.FindProperty(nameof(OnlyBlendshapePosition)), Options.BLENDSHAPE_EXCLUDE_NORMAL_AND_TANGENT); - // m_reduceBlendShape = new CheckBoxProp(serializedObject.FindProperty(nameof(ReduceBlendshape)), Options.BLENDSHAPE_ONLY_CLIP_USE); - // m_reduceBlendShapeClip = new CheckBoxProp(serializedObject.FindProperty(nameof(ReduceBlendshapeClip)), Options.BLENDSHAPE_EXCLUDE_UNKNOWN); - // m_removeVertexColor = new CheckBoxProp(serializedObject.FindProperty(nameof(RemoveVertexColor)), Options.REMOVE_VERTEX_COLOR); + m_target = target as VRMExportMeshes; } public override void OnInspectorGUI() { - base.OnInspectorGUI(); + for (int i = 0; i < m_target.Meshes.Count; ++i) + { + DrawElement(i, m_target.Meshes[i]); + } + } - EditorGUILayout.HelpBox($"Mesh size: {m_meshes.ExpectedExportByteSize / 1000000.0f:0.0} MByte", MessageType.Info); + 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); } } }