From a153f30898dde9c53a833b65d2e0a009e0890fff Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 11 Sep 2020 18:11:51 +0900 Subject: [PATCH] =?UTF-8?q?Mesh=E3=82=B5=E3=82=A4=E3=82=BA=E3=81=AE?= =?UTF-8?q?=E4=BA=8B=E5=89=8D=E8=A8=88=E7=AE=97=E3=80=82ReduceBlendShape?= =?UTF-8?q?=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/Format/VRMExporterVaildator.cs | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExporterVaildator.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExporterVaildator.cs index 9182dbf50..3a1fd6ea2 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExporterVaildator.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExporterVaildator.cs @@ -22,6 +22,7 @@ namespace VRM List m_validations = new List(); public IEnumerable Validations => m_validations; + public int ExpectedByteSize = 0; /// /// ボーン名の重複を確認 @@ -187,6 +188,11 @@ namespace VRM public void Validate(GameObject ExportRoot, VRMExportSettings m_settings, VRMMetaObject meta) { m_validations.Clear(); + if (ExportRoot == null) + { + return; + } + m_validations.AddRange(_Validate(ExportRoot, m_settings)); if (ExportRoot != null) { @@ -198,6 +204,103 @@ namespace VRM } } MetaHasError = meta.Validate().Any(); + + // サイズ の 計算 + var proxy = ExportRoot.GetComponent(); + var clips = new List(); + if (proxy != null && proxy.BlendShapeAvatar != null) + { + clips.AddRange(proxy.BlendShapeAvatar.Clips); + } + + ExpectedByteSize = 0; + foreach (var renderer in ExportRoot.GetComponentsInChildren()) + { + var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(renderer.transform, ExportRoot.transform); + var mesh = GetMesh(renderer); + ExpectedByteSize += CalcMeshSize(relativePath, mesh, m_settings, clips); + } + } + + static bool ClipsContainsName(List clips, bool onlyPreset, BlendShapeBinding binding) + { + foreach (var c in clips) + { + if (onlyPreset) + { + if (c.Preset == BlendShapePreset.Unknown) + { + continue; + } + } + + foreach (var b in c.Values) + { + if (b.RelativePath == binding.RelativePath && b.Index == binding.Index) + { + return true; + } + } + } + return false; + } + + static int CalcMeshSize(string relativePath, Mesh m, VRMExportSettings m_settings, List clips) + { + int size = 0; + // vertices + size += m.vertexCount * 4 * 3; // vector3 + if (m.normals != null) + { + size += m.vertexCount * 4 * 3; + } + if (m.uv != null) + { + size += m.vertexCount * 4 * 2; + } + if (m.colors != null) + { + size += m.vertexCount * 4 * 4; + } + // indices + size += m.triangles.Length * 4; // int ? + // blendshapes + for (var i = 0; i < m.blendShapeCount; ++i) + { + // var name = m.GetBlendShapeName(i); + if (m_settings.ReduceBlendshape) + { + if (!ClipsContainsName(clips, m_settings.ReduceBlendshapeClip, new BlendShapeBinding + { + Index = i, + RelativePath = relativePath, + })) + { + // skip + continue; + } + } + + size += m.vertexCount * 4 * (3 + 3); + } + return size; + } + + static Mesh GetMesh(Renderer r) + { + if (r is SkinnedMeshRenderer smr) + { + return smr.sharedMesh; + } + if (r is MeshRenderer) + { + MeshFilter f = r.GetComponent(); + if (f != null) + { + return f.sharedMesh; + } + } + return null; } IEnumerable _Validate(GameObject ExportRoot, VRMExportSettings m_settings)