mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using System;
|
|
using Unity.Jobs;
|
|
using UnityEngine.Jobs;
|
|
|
|
|
|
namespace UniGLTF.SpringBoneJobs
|
|
{
|
|
public sealed class FastSpringBoneScheduler : IDisposable
|
|
{
|
|
private readonly FastSpringBoneBufferCombiner _bufferCombiner;
|
|
public FastSpringBoneScheduler(FastSpringBoneBufferCombiner bufferCombiner)
|
|
{
|
|
_bufferCombiner = bufferCombiner;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_bufferCombiner.Dispose();
|
|
}
|
|
|
|
public JobHandle Schedule(float deltaTime)
|
|
{
|
|
var handle = _bufferCombiner.ReconstructIfDirty(default);
|
|
if (!_bufferCombiner.HasBuffer)
|
|
{
|
|
return handle;
|
|
}
|
|
|
|
if (_bufferCombiner.Combined is FastSpringBoneCombinedBuffer combined)
|
|
{
|
|
handle = new PullTransformJob
|
|
{
|
|
Transforms = combined.Transforms
|
|
}.Schedule(combined.TransformAccessArray, handle);
|
|
|
|
combined.FlipBuffer();
|
|
|
|
handle = new UpdateFastSpringBoneJob
|
|
{
|
|
Joints = combined.Joints,
|
|
Logics = combined.Logics,
|
|
CurrentTail = combined.CurrentTails,
|
|
PrevTail = combined.PrevTails,
|
|
NextTail = combined.NextTails,
|
|
Springs = combined.Springs,
|
|
Models = combined.Models,
|
|
Colliders = combined.Colliders,
|
|
Transforms = combined.Transforms,
|
|
DeltaTime = deltaTime,
|
|
}.Schedule(combined.Springs.Length, 1, handle);
|
|
|
|
handle = new PushTransformJob
|
|
{
|
|
Transforms = combined.Transforms
|
|
}.Schedule(combined.TransformAccessArray, handle);
|
|
}
|
|
|
|
return handle;
|
|
}
|
|
}
|
|
} |