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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniGLTF.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -51,14 +53,19 @@ namespace UniHumanoid
|
|||
x => x);
|
||||
|
||||
/// <summary>
|
||||
/// Avatar を保持する既存の Animatorヒエラルキーの Transform を変更したのちに、
|
||||
/// HumanBone のマッピングを流用して、新たな Avatar を作り直す。
|
||||
/// 古い Avatar は破棄する。
|
||||
/// Recreates an animiator's humanoid avatar.
|
||||
/// The old Avatar is discarded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method runs asynchronously only in play mode.
|
||||
/// </remarks>
|
||||
public static async Awaitable RebuildHumanAvatar(Animator animator)
|
||||
public static void RebuildHumanAvatar(Animator animator)
|
||||
{
|
||||
var task = RebuildHumanAvatarAsync(animator, new ImmediateCaller());
|
||||
if (!task.IsCompleted)
|
||||
{
|
||||
throw new Exception("task not completed");
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task RebuildHumanAvatarAsync(Animator animator, IAwaitCaller awaitCaller)
|
||||
{
|
||||
if (animator == null)
|
||||
{
|
||||
|
|
@ -76,19 +83,22 @@ namespace UniHumanoid
|
|||
newAvatar.name = "re-created";
|
||||
|
||||
// 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)
|
||||
{
|
||||
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.
|
||||
await Awaitable.NextFrameAsync();
|
||||
await awaitCaller.NextFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject.DestroyImmediate(animator);
|
||||
}
|
||||
// 新たに AddComponent する
|
||||
|
||||
// 2. Attach a new one
|
||||
target.AddComponent<Animator>().avatar = newAvatar;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniGLTF.MeshUtility;
|
||||
using UniGLTF.Utils;
|
||||
|
|
@ -53,10 +54,16 @@ namespace VRM
|
|||
/// <param name="go">対象モデルのルート</param>
|
||||
/// <param name="forceTPose">強制的にT-Pose化するか</param>
|
||||
/// <param name="useCurrentBlendShapeWeight">BlendShape の現状をbakeするか</param>
|
||||
/// <remarks>
|
||||
/// This method runs asynchronously only in play mode.
|
||||
/// </remarks>
|
||||
public static async Awaitable Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
|
||||
public static void Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
|
||||
{
|
||||
var task = ExecuteAsync(go, forceTPose, useCurrentBlendShapeWeight, new ImmediateCaller());
|
||||
if (!task.IsCompleted)
|
||||
{
|
||||
throw new Exception("task not completed");
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ExecuteAsync(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight, IAwaitCaller awaitCaller)
|
||||
{
|
||||
if (forceTPose)
|
||||
{
|
||||
|
|
@ -86,7 +93,7 @@ namespace VRM
|
|||
// 回転とスケールが除去された新しいヒエラルキーからAvatarを作る
|
||||
if (go.TryGetComponent<Animator>(out var animator))
|
||||
{
|
||||
await HumanoidLoader.RebuildHumanAvatar(animator);
|
||||
await HumanoidLoader.RebuildHumanAvatarAsync(animator, awaitCaller);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
||||
"GUID:f9fe54bb3090be448aa10ac92648a614",
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||
"GUID:0acc523941302664db1f4e527237feb3"
|
||||
"GUID:0acc523941302664db1f4e527237feb3",
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
||||
"GUID:f9fe54bb3090be448aa10ac92648a614",
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||
"GUID:0acc523941302664db1f4e527237feb3"
|
||||
"GUID:0acc523941302664db1f4e527237feb3",
|
||||
"GUID:1cd941934d098654fa21a13f28346412"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user