UniVRM/Assets/VRM_Samples/SimpleViewer/Loaded.cs
ousttrue fc117b8332 IVrm0XSpringBoneRuntime の実装
SpringboneRuntime を介した reset, reconstruct, scaling係数オプション, externalForce, 一時停止(FastSpringboneのみ)
の操作を実装
2024-10-08 17:07:06 +09:00

126 lines
3.5 KiB
C#

using System;
using UniGLTF;
using UniGLTF.SpringBoneJobs.Blittables;
using UniHumanoid;
using UnityEngine;
namespace VRM.SimpleViewer
{
class Loaded : IDisposable
{
RuntimeGltfInstance _instance;
VRMBlendShapeProxy m_proxy;
Blinker m_blink;
bool m_enableBlinkValue;
public bool EnableBlinkValue
{
set
{
if (m_blink == value) return;
m_enableBlinkValue = value;
if (m_blink != null)
{
m_blink.enabled = m_enableBlinkValue;
}
}
}
AIUEO m_lipSync;
bool m_enableLipSyncValue;
public bool EnableLipSyncValue
{
set
{
if (m_enableLipSyncValue == value) return;
m_enableLipSyncValue = value;
if (m_lipSync != null)
{
m_lipSync.enabled = m_enableLipSyncValue;
}
}
}
IVrm0XSpringBoneRuntime _springbone;
public Loaded(RuntimeGltfInstance instance, HumanPoseTransfer src, Transform lookAtTarget, IVrm0XSpringBoneRuntime springbone)
{
_instance = instance;
_springbone = springbone;
var lookAt = instance.GetComponent<VRMLookAtHead>();
if (lookAt != null)
{
// vrm
_pose = _instance.gameObject.AddComponent<HumanPoseTransfer>();
_pose.Source = src;
_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
m_lipSync = instance.gameObject.AddComponent<AIUEO>();
m_blink = instance.gameObject.AddComponent<Blinker>();
lookAt.Target = lookAtTarget;
lookAt.UpdateType = UpdateType.LateUpdate; // after HumanPoseTransfer's setPose
m_proxy = instance.GetComponent<VRMBlendShapeProxy>();
}
// not vrm
var animation = instance.GetComponent<Animation>();
if (animation && animation.clip != null)
{
animation.Play(animation.clip.name);
}
}
public void Dispose()
{
// Destroy game object. not RuntimeGltfInstance
GameObject.Destroy(_instance.gameObject);
}
public void Update()
{
if (m_proxy != null)
{
m_proxy.Apply();
}
}
HumanPoseTransfer _pose;
public void EnableBvh(HumanPoseTransfer src)
{
if (_pose != null)
{
_pose.Source = src;
_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
}
}
public void EnableTPose(HumanPoseClip pose)
{
if (_pose != null)
{
_pose.PoseClip = pose;
_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseClip;
}
}
public void ResetSpringbone()
{
_springbone.RestoreInitialTransform();
}
public void ReconstructSpringbone()
{
_springbone.ReconstructSpringBone();
}
public void SetSpringboneModelLevel(BlittableModelLevel modelSettings)
{
_springbone.SetModelLevel(_instance.transform, modelSettings);
}
}
}