mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-24 19:45:37 -05:00
Merge pull request #1119 from ousttrue/feature/runtime_export_use_normalize
ラインタイムエクスポート時に正規化を実行する例
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user