mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-19 16:51:55 -05:00
VrmAnimationInstance
This commit is contained in:
parent
122f15fc42
commit
464a5c8953
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a6fde18d19837ab488a01dac4ddc962e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
using UniHumanoid;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public class VrmAnimationInstance : MonoBehaviour
|
||||
{
|
||||
public SkinnedMeshRenderer BoxMan;
|
||||
public (INormalizedPoseProvider, ITPoseProvider) ControlRig;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var humanoid = gameObject.AddComponent<Humanoid>();
|
||||
if (humanoid.AssignBonesFromAnimator())
|
||||
{
|
||||
// require: transform is T-Pose
|
||||
var provider = new InitRotationPoseProvider(transform, humanoid);
|
||||
ControlRig = (provider, provider);
|
||||
|
||||
// create SkinnedMesh for bone visualize
|
||||
var animator = GetComponent<Animator>();
|
||||
BoxMan = SkeletonMeshUtility.CreateRenderer(animator);
|
||||
var material = new Material(Shader.Find("Standard"));
|
||||
BoxMan.sharedMaterial = material;
|
||||
var mesh = BoxMan.sharedMesh;
|
||||
mesh.name = "box-man";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 69dfb9ffd7c663f4cadc81e38a377672
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -9,50 +9,33 @@ namespace UniVRM10.VRM10Viewer
|
|||
{
|
||||
public class VrmAnimation : IMotion
|
||||
{
|
||||
private RuntimeGltfInstance m_instance;
|
||||
public SkinnedMeshRenderer m_boxMan;
|
||||
public SkinnedMeshRenderer BoxMan => m_boxMan;
|
||||
private (INormalizedPoseProvider, ITPoseProvider) m_controlRig;
|
||||
(INormalizedPoseProvider, ITPoseProvider) IMotion.ControlRig => m_controlRig;
|
||||
private readonly VrmAnimationInstance m_instance;
|
||||
|
||||
(INormalizedPoseProvider, ITPoseProvider) IMotion.ControlRig => m_instance.ControlRig;
|
||||
public IDictionary<ExpressionKey, Transform> ExpressionMap { get; } = new Dictionary<ExpressionKey, Transform>();
|
||||
|
||||
public VrmAnimation(RuntimeGltfInstance instance)
|
||||
public VrmAnimation(VrmAnimationInstance instance)
|
||||
{
|
||||
m_instance = instance;
|
||||
if (instance.GetComponent<Animation>() is Animation animation)
|
||||
{
|
||||
animation.Play();
|
||||
}
|
||||
|
||||
var humanoid = instance.gameObject.AddComponent<Humanoid>();
|
||||
if (humanoid.AssignBonesFromAnimator())
|
||||
{
|
||||
var provider = new InitRotationPoseProvider(instance.transform, humanoid);
|
||||
m_controlRig = (provider, provider);
|
||||
|
||||
// create SkinnedMesh for bone visualize
|
||||
var animator = instance.GetComponent<Animator>();
|
||||
m_boxMan = SkeletonMeshUtility.CreateRenderer(animator);
|
||||
var material = new Material(Shader.Find("Standard"));
|
||||
BoxMan.sharedMaterial = material;
|
||||
var mesh = BoxMan.sharedMesh;
|
||||
mesh.name = "box-man";
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowBoxMan(bool enable)
|
||||
{
|
||||
if (m_boxMan != null)
|
||||
if (m_instance.BoxMan != null)
|
||||
{
|
||||
m_boxMan.enabled = enable;
|
||||
m_instance.BoxMan.enabled = enable;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (m_boxMan != null)
|
||||
if (m_instance.BoxMan != null)
|
||||
{
|
||||
GameObject.Destroy(m_boxMan.gameObject);
|
||||
GameObject.Destroy(m_instance.BoxMan.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +47,10 @@ namespace UniVRM10.VRM10Viewer
|
|||
loader.InvertAxis = Axes.X;
|
||||
var instance = await loader.LoadAsync(new ImmediateCaller());
|
||||
|
||||
var animation = new VrmAnimation(instance);
|
||||
var animationInstance = instance.gameObject.AddComponent<UniVRM10.VrmAnimationInstance>();
|
||||
animationInstance.Initialize();
|
||||
|
||||
var animation = new VrmAnimation(animationInstance);
|
||||
foreach (var (preset, transform) in loader.GetExpressions())
|
||||
{
|
||||
animation.ExpressionMap.Add(preset, transform);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user