diff --git a/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs b/Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs index cd14c02fd..5c8d662ef 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 @@ namespace VRM.Samples [SerializeField] Button m_exportButton = default; + [SerializeField] + public bool UseNormalize = true; + GameObject m_model; private void Awake() @@ -92,12 +97,35 @@ namespace VRM.Samples 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");