SpringBoneの内部構造を動的に変更するための仕組みを追加

This commit is contained in:
notargs
2021-10-15 16:53:38 +09:00
parent e2cc73b03c
commit cfd246fce2
2 changed files with 26 additions and 12 deletions

View File

@@ -57,17 +57,16 @@ namespace UniVRM10
Vrm10InstanceRuntime m_runtime;
/// <summary>
/// delay new Vrm10InstanceRuntime
/// </summary>
/// <returns></returns>
Vrm10InstanceRuntime GetOrCreate()
public Vrm10InstanceRuntime Runtime
{
if (m_runtime == null)
get
{
m_runtime = new Vrm10InstanceRuntime(this);
if (m_runtime == null)
{
m_runtime = new Vrm10InstanceRuntime(this);
}
return m_runtime;
}
return m_runtime;
}
void Start()
@@ -85,7 +84,7 @@ namespace UniVRM10
{
if (UpdateType == UpdateTypes.Update)
{
GetOrCreate().Process();
Runtime.Process();
}
}
@@ -93,13 +92,13 @@ namespace UniVRM10
{
if (UpdateType == UpdateTypes.LateUpdate)
{
GetOrCreate().Process();
Runtime.Process();
}
}
private void OnDestroy()
{
GetOrCreate().Dispose();
Runtime.Dispose();
}
}
}

View File

@@ -15,7 +15,8 @@ namespace UniVRM10
private readonly VRM10Constraint[] m_constraints;
private readonly Transform m_head;
private readonly FastSpringBoneService m_fastSpringBoneService;
private readonly FastSpringBoneBuffer m_fastSpringBoneBuffer;
private FastSpringBoneBuffer m_fastSpringBoneBuffer;
public Vrm10InstanceRuntime(Vrm10Instance target)
{
@@ -46,6 +47,20 @@ namespace UniVRM10
m_fastSpringBoneService.BufferCombiner.Register(m_fastSpringBoneBuffer);
}
/// <summary>
/// このVRMに紐づくSpringBone関連のバッファを再構築する
/// ランタイム実行時にSpringBoneに対して変更を行いたいときは、このメソッドを明示的に呼ぶ必要がある
/// </summary>
public void ReconstructSpringBone()
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
m_fastSpringBoneBuffer = CreateFastSpringBoneBuffer(m_target.SpringBone);
m_fastSpringBoneService.BufferCombiner.Register(m_fastSpringBoneBuffer);
}
private FastSpringBoneBuffer CreateFastSpringBoneBuffer(Vrm10InstanceSpringBone springBone)
{
return new FastSpringBoneBuffer(