Merge pull request #1119 from ousttrue/feature/runtime_export_use_normalize

ラインタイムエクスポート時に正規化を実行する例
This commit is contained in:
PoChang007
2021-07-30 23:38:54 +09:00
committed by GitHub

View File

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