Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[springbone] SpringBone が無いモデルの NullReferenceException を修正 #1

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ public class Vrm0XFastSpringboneRuntime : IVrm0XSpringBoneRuntime
SpringBoneJobs.FastSpringBoneService m_service;
FastSpringBoneBuffer m_buffer;

public Vrm0XFastSpringboneRuntime()
{
m_service = SpringBoneJobs.FastSpringBoneService.Instance;
}

public async Task InitializeAsync(GameObject vrm, IAwaitCaller awaitCaller)
{
m_vrm = vrm;
m_service = SpringBoneJobs.FastSpringBoneService.Instance;

// default update の停止
foreach (VRMSpringBone sb in vrm.GetComponentsInChildren<VRMSpringBone>())
Expand Down Expand Up @@ -69,9 +73,8 @@ async Task RegisterAsync(IAwaitCaller awaitCaller)

public void ReconstructSpringBone()
{
var disposer = m_vrm.gameObject.GetComponent<FastSpringBoneDisposer>();
Unregister();
var task = RegisterAsync(new ImmediateCaller());
var _ = RegisterAsync(new ImmediateCaller());
}

public void RestoreInitialTransform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class Vrm10FastSpringboneRuntime : IVrm10SpringBoneRuntime
private FastSpringBones.FastSpringBoneService m_fastSpringBoneService;
private FastSpringBoneBuffer m_fastSpringBoneBuffer;

public Vrm10FastSpringboneRuntime()
{
m_fastSpringBoneService = FastSpringBones.FastSpringBoneService.Instance;
}

public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings)
{
if (m_fastSpringBoneService.BufferCombiner.Combined is FastSpringBoneCombinedBuffer combined)
Expand All @@ -37,7 +42,6 @@ public void SetModelLevel(Transform modelRoot, BlittableModelLevel modelSettings

public async Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCaller)
{
m_fastSpringBoneService = FastSpringBones.FastSpringBoneService.Instance;
m_instance = instance;

// NOTE: FastSpringBoneService は UnitTest などでは動作しない
Expand All @@ -49,8 +53,11 @@ public async Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCall

public void Dispose()
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
if (m_fastSpringBoneBuffer != null)
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
}
}

/// <summary>
Expand Down
15 changes: 8 additions & 7 deletions Assets/VRM10/Runtime/IO/Vrm10Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller)
if (UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(Data.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone))
{
await LoadSpringBoneAsync(awaitCaller, controller, springBone);
}

if (Application.isPlaying)
{
// EditorImport では呼ばない
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
// RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128
await m_springboneRuntime.InitializeAsync(controller, awaitCaller);
}
if (Application.isPlaying)
{
// EditorImport では呼ばない
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
// RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128
// VRMC_springBone が無くても初期化する v0.127.2
await m_springboneRuntime.InitializeAsync(controller, awaitCaller);
}

// constraint
Expand Down