Export 時の Mesh 詳細

This commit is contained in:
ousttrue 2020-10-02 13:22:08 +09:00
parent dbe302d53c
commit feab5ccc61
3 changed files with 76 additions and 20 deletions

View File

@ -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
{

View File

@ -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<BlendShapeClip> clips)
public static void CalcMeshSize(ref UniGLTF.MeshExportInfo info,
string relativePath, VRMExportSettings settings, IReadOnlyList<BlendShapeClip> 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<BlendShapeClip> 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;
}

View File

@ -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);
}
}
}