mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-03-21 18:05:03 -05:00
commit
52d868c4ba
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UniGLTF;
|
||||||
using UniGLTF.Utils;
|
using UniGLTF.Utils;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -51,14 +53,19 @@ namespace UniHumanoid
|
||||||
x => x);
|
x => x);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Avatar を保持する既存の Animatorヒエラルキーの Transform を変更したのちに、
|
/// Recreates an animiator's humanoid avatar.
|
||||||
/// HumanBone のマッピングを流用して、新たな Avatar を作り直す。
|
/// The old Avatar is discarded.
|
||||||
/// 古い Avatar は破棄する。
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
public static void RebuildHumanAvatar(Animator animator)
|
||||||
/// This method runs asynchronously only in play mode.
|
{
|
||||||
/// </remarks>
|
var task = RebuildHumanAvatarAsync(animator, new ImmediateCaller());
|
||||||
public static async Awaitable RebuildHumanAvatar(Animator animator)
|
if (!task.IsCompleted)
|
||||||
|
{
|
||||||
|
throw new Exception("task not completed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task RebuildHumanAvatarAsync(Animator animator, IAwaitCaller awaitCaller)
|
||||||
{
|
{
|
||||||
if (animator == null)
|
if (animator == null)
|
||||||
{
|
{
|
||||||
|
|
@ -76,19 +83,22 @@ namespace UniHumanoid
|
||||||
newAvatar.name = "re-created";
|
newAvatar.name = "re-created";
|
||||||
|
|
||||||
// var newAvatar = LoadHumanoidAvatarFromAnimator(animator);
|
// var newAvatar = LoadHumanoidAvatarFromAnimator(animator);
|
||||||
// Animator.avatar を代入したときに副作用でTransformが変更されるのを回避するために削除します。
|
// 1. Delete this to avoid changing Transform as a side effect when assigning Animator.avatar.
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
{
|
{
|
||||||
GameObject.Destroy(animator);
|
GameObject.Destroy(animator);
|
||||||
|
|
||||||
|
// https://github.com/vrm-c/UniVRM/pull/2764
|
||||||
|
// Require IAwaitCaller that has NextFrame capability. RuntimeOnlyAwaitCaller etc. not ImmediateCaller.
|
||||||
// Else, the following AddComponent call will fail.
|
// Else, the following AddComponent call will fail.
|
||||||
await Awaitable.NextFrameAsync();
|
await awaitCaller.NextFrame();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GameObject.DestroyImmediate(animator);
|
GameObject.DestroyImmediate(animator);
|
||||||
}
|
}
|
||||||
// 新たに AddComponent する
|
|
||||||
|
// 2. Attach a new one
|
||||||
target.AddComponent<Animator>().avatar = newAvatar;
|
target.AddComponent<Animator>().avatar = newAvatar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using UniGLTF;
|
using UniGLTF;
|
||||||
using UniGLTF.MeshUtility;
|
using UniGLTF.MeshUtility;
|
||||||
using UniGLTF.Utils;
|
using UniGLTF.Utils;
|
||||||
|
|
@ -53,10 +54,16 @@ namespace VRM
|
||||||
/// <param name="go">対象モデルのルート</param>
|
/// <param name="go">対象モデルのルート</param>
|
||||||
/// <param name="forceTPose">強制的にT-Pose化するか</param>
|
/// <param name="forceTPose">強制的にT-Pose化するか</param>
|
||||||
/// <param name="useCurrentBlendShapeWeight">BlendShape の現状をbakeするか</param>
|
/// <param name="useCurrentBlendShapeWeight">BlendShape の現状をbakeするか</param>
|
||||||
/// <remarks>
|
public static void Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
|
||||||
/// This method runs asynchronously only in play mode.
|
{
|
||||||
/// </remarks>
|
var task = ExecuteAsync(go, forceTPose, useCurrentBlendShapeWeight, new ImmediateCaller());
|
||||||
public static async Awaitable Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
|
if (!task.IsCompleted)
|
||||||
|
{
|
||||||
|
throw new Exception("task not completed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task ExecuteAsync(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight, IAwaitCaller awaitCaller)
|
||||||
{
|
{
|
||||||
if (forceTPose)
|
if (forceTPose)
|
||||||
{
|
{
|
||||||
|
|
@ -86,7 +93,7 @@ namespace VRM
|
||||||
// 回転とスケールが除去された新しいヒエラルキーからAvatarを作る
|
// 回転とスケールが除去された新しいヒエラルキーからAvatarを作る
|
||||||
if (go.TryGetComponent<Animator>(out var animator))
|
if (go.TryGetComponent<Animator>(out var animator))
|
||||||
{
|
{
|
||||||
await HumanoidLoader.RebuildHumanAvatar(animator);
|
await HumanoidLoader.RebuildHumanAvatarAsync(animator, awaitCaller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||||
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
||||||
"GUID:f9fe54bb3090be448aa10ac92648a614",
|
"GUID:f9fe54bb3090be448aa10ac92648a614",
|
||||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
|
||||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||||
"GUID:0acc523941302664db1f4e527237feb3"
|
"GUID:0acc523941302664db1f4e527237feb3",
|
||||||
|
"GUID:1cd941934d098654fa21a13f28346412"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||||
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
||||||
"GUID:f9fe54bb3090be448aa10ac92648a614",
|
"GUID:f9fe54bb3090be448aa10ac92648a614",
|
||||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
|
||||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||||
"GUID:0acc523941302664db1f4e527237feb3"
|
"GUID:0acc523941302664db1f4e527237feb3",
|
||||||
|
"GUID:1cd941934d098654fa21a13f28346412"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user