Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ラインタイムエクスポート時に正規化を実行する例 #1119

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions Assets/VRM.Samples/Scripts/VRMRuntimeExporter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using UniGLTF;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -14,6 +16,9 @@ public class VRMRuntimeExporter : MonoBehaviour

[SerializeField] Button m_exportButton = default;

[SerializeField]
public bool UseNormalize = true;

GameObject m_model;

private void Awake()
Expand Down Expand Up @@ -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");
Expand Down