From 0be6b87cea848f40672e83ac9e00768014306e7f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 29 Jul 2021 18:25:03 +0900 Subject: [PATCH] use VRMBoneNormalizer --- .../VRM.Samples/Scripts/VRMRuntimeExporter.cs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs b/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs index cd14c02fdb..5c8d662ef7 100644 --- a/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs +++ b/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs @@ -1,4 +1,6 @@ -using System.IO; +using System; +using System.IO; +using System.Linq; using UniGLTF; using UnityEngine; using UnityEngine.UI; @@ -14,6 +16,9 @@ public class VRMRuntimeExporter : MonoBehaviour [SerializeField] Button m_exportButton = default; + [SerializeField] + public bool UseNormalize = true; + GameObject m_model; private void Awake() @@ -92,12 +97,35 @@ void OnExportClicked() return; } - var vrm = VRMExporter.Export(new UniGLTF.GltfExportSettings(), m_model, new RuntimeTextureSerializer()); - var bytes = vrm.ToGlbBytes(); + var bytes = UseNormalize ? ExportCustom(m_model) : ExportSimple(m_model); + File.WriteAllBytes(path, bytes); Debug.LogFormat("export to {0}", path); } + static byte[] ExportSimple(GameObject model) + { + var vrm = VRMExporter.Export(new UniGLTF.GltfExportSettings(), model, new RuntimeTextureSerializer()); + var bytes = vrm.ToGlbBytes(); + return bytes; + } + + static byte[] ExportCustom(GameObject exportRoot, bool forceTPose = false) + { + // normalize + var target = VRMBoneNormalizer.Execute(exportRoot, forceTPose); + + try + { + return ExportSimple(target); + } + finally + { + // cleanup + GameObject.Destroy(target); + } + } + void OnExported(UniGLTF.glTF vrm) { Debug.LogFormat("exported");