mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-22 18:45:06 -05:00
Merge pull request #2435 from ousttrue/feature/vrm0_springbone_runtime
[VRM0][Importer]IVrm0XSpringBoneRuntime
This commit is contained in:
@@ -20,16 +20,20 @@ namespace VRM
|
||||
}
|
||||
}
|
||||
|
||||
IVrm0XSpringBoneRuntime _springBoneRuntime;
|
||||
|
||||
public VRMImporterContext(
|
||||
VRMData data,
|
||||
IReadOnlyDictionary<SubAssetKey, Object> externalObjectMap = null,
|
||||
ITextureDeserializer textureDeserializer = null,
|
||||
IMaterialDescriptorGenerator materialGenerator = null,
|
||||
ImporterContextSettings settings = null)
|
||||
ImporterContextSettings settings = null,
|
||||
IVrm0XSpringBoneRuntime springboneRuntime = null)
|
||||
: base(data.Data, externalObjectMap, textureDeserializer, materialGenerator ?? VrmMaterialDescriptorGeneratorUtility.GetValidVrmMaterialDescriptorGenerator(data.VrmExtension), settings ?? new ImporterContextSettings(false))
|
||||
{
|
||||
_data = data;
|
||||
TextureDescriptorGenerator = new VrmTextureDescriptorGenerator(Data, VRM);
|
||||
_springBoneRuntime = springboneRuntime ?? new Vrm0XSpringBoneDefaultRuntime();
|
||||
}
|
||||
|
||||
#region OnLoad
|
||||
@@ -57,8 +61,8 @@ namespace VRM
|
||||
|
||||
using (MeasureTime("VRM LoadSecondary"))
|
||||
{
|
||||
VRMSpringUtility.LoadSecondary(Root.transform, TryGetNode,
|
||||
VRM.secondaryAnimation);
|
||||
VRMSpringUtility.LoadSecondary(Root.transform, TryGetNode, VRM.secondaryAnimation);
|
||||
await _springBoneRuntime.InitializeAsync(Root, awaitCaller);
|
||||
}
|
||||
await awaitCaller.NextFrame();
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ namespace VRM
|
||||
MaterialGeneratorCallback materialGeneratorCallback = null,
|
||||
MetaCallback metaCallback = null,
|
||||
ITextureDeserializer textureDeserializer = null,
|
||||
bool loadAnimation = false
|
||||
bool loadAnimation = false,
|
||||
IVrm0XSpringBoneRuntime springboneRuntime = null
|
||||
)
|
||||
{
|
||||
if (bytes == null)
|
||||
@@ -102,7 +103,9 @@ namespace VRM
|
||||
vrm,
|
||||
textureDeserializer: textureDeserializer,
|
||||
materialGenerator: materialGen,
|
||||
settings: importerContextSettings))
|
||||
settings: importerContextSettings,
|
||||
springboneRuntime: springboneRuntime
|
||||
))
|
||||
{
|
||||
if (metaCallback != null)
|
||||
{
|
||||
|
||||
11
Assets/VRM/Runtime/SpringBone/IVrm0XSpringBoneRuntime.cs
Normal file
11
Assets/VRM/Runtime/SpringBone/IVrm0XSpringBoneRuntime.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public interface IVrm0XSpringBoneRuntime
|
||||
{
|
||||
public Task InitializeAsync(GameObject vrm, IAwaitCaller awaitCaller);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dde51548cb9bb7546b6a9824b8710315
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniGLTF.SpringBoneJobs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
/// <summary>
|
||||
/// FastSpringbone(job + singleton) で動作します。
|
||||
///
|
||||
/// VRMSpringBone.m_updateType = Manual
|
||||
///
|
||||
/// により、各VRMSpringBoneの自力Updateは停止します。
|
||||
/// FastSpringBoneService に登録します。
|
||||
/// FastSpringBoneService.LateUpdate[DefaultExecutionOrder(11000)] で動作します。
|
||||
/// </summary>
|
||||
public class Vrm0XFastSpringboneRuntime : IVrm0XSpringBoneRuntime
|
||||
{
|
||||
public async Task InitializeAsync(GameObject vrm, IAwaitCaller awaitCaller)
|
||||
{
|
||||
// default update の停止
|
||||
foreach (VRMSpringBone sb in vrm.GetComponentsInChildren<VRMSpringBone>())
|
||||
{
|
||||
sb.m_updateType = VRMSpringBone.SpringBoneUpdateType.Manual;
|
||||
}
|
||||
|
||||
// create
|
||||
var buffer = await SpringBoneJobs.FastSpringBoneReplacer.MakeBufferAsync(vrm, awaitCaller);
|
||||
SpringBoneJobs.FastSpringBoneService.Instance.BufferCombiner.Register(buffer);
|
||||
|
||||
// disposer
|
||||
var disposer = vrm.AddComponent<FastSpringBoneDisposer>()
|
||||
.AddAction(() =>
|
||||
{
|
||||
SpringBoneJobs.FastSpringBoneService.Instance.BufferCombiner.Unregister(buffer);
|
||||
buffer.Dispose();
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8315a3b319fd3f4a892def8ae68e812
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
/// <summary>
|
||||
/// デフォルトの VRMSPringBone 実装です。
|
||||
///
|
||||
/// VRMSpringBone.m_updateType = LateUpdate
|
||||
///
|
||||
/// により、各VRMSpringBoneが自力で LateUpdate に動作します。
|
||||
/// </summary>
|
||||
public class Vrm0XSpringBoneDefaultRuntime : IVrm0XSpringBoneRuntime
|
||||
{
|
||||
public async Task InitializeAsync(GameObject vrm, IAwaitCaller awaitCaller)
|
||||
{
|
||||
foreach (VRMSpringBone sb in vrm.GetComponentsInChildren<VRMSpringBone>())
|
||||
{
|
||||
sb.m_updateType = VRMSpringBone.SpringBoneUpdateType.LateUpdate;
|
||||
}
|
||||
await awaitCaller.NextFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08914ddaedc7d394ab58a879662341b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniGLTF.SpringBoneJobs;
|
||||
using UniHumanoid;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -267,6 +268,13 @@ namespace VRM.SimpleViewer
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if DEBUG
|
||||
NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_version.text = string.Format("VRMViewer {0}.{1}",
|
||||
@@ -382,23 +390,13 @@ namespace VRM.SimpleViewer
|
||||
}
|
||||
|
||||
// vrm
|
||||
VrmUtility.MaterialGeneratorCallback materialCallback = (VRM.glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm);
|
||||
VrmUtility.MaterialGeneratorCallback materialCallback = (glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm);
|
||||
VrmUtility.MetaCallback metaCallback = m_texts.UpdateMeta;
|
||||
var instance = await VrmUtility.LoadBytesAsync(path, bytes, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback, loadAnimation: m_loadAnimation.isOn);
|
||||
|
||||
if (m_useFastSpringBone.isOn)
|
||||
{
|
||||
// job用バッファ作成
|
||||
var buffer = await SpringBoneJobs.FastSpringBoneReplacer.MakeBufferAsync(instance.Root);
|
||||
|
||||
// 登録
|
||||
SpringBoneJobs.FastSpringBoneService.Instance.BufferCombiner.Register(buffer);
|
||||
|
||||
// 削除登録
|
||||
instance.Root.AddComponent<FastSpringBoneDisposer>()
|
||||
.AddAction(()=>{ SpringBoneJobs.FastSpringBoneService.Instance.BufferCombiner.Unregister(buffer);})
|
||||
.Add(buffer);
|
||||
}
|
||||
var instance = await VrmUtility.LoadBytesAsync(path, bytes, GetIAwaitCaller(m_useAsync.isOn),
|
||||
materialCallback, metaCallback,
|
||||
loadAnimation: m_loadAnimation.isOn,
|
||||
springboneRuntime: m_useFastSpringBone.isOn ? new Vrm0XFastSpringboneRuntime() : new Vrm0XSpringBoneDefaultRuntime()
|
||||
);
|
||||
|
||||
instance.EnableUpdateWhenOffscreen();
|
||||
instance.ShowMeshes();
|
||||
|
||||
Reference in New Issue
Block a user