mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-14 14:29:52 -05:00
SpringBoneに対してグローバルで外力を渡すインターフェースを実装する
This commit is contained in:
parent
75e9a82ee8
commit
dc3b6afd8c
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
|
|
@ -13,5 +13,6 @@ namespace UniVRM10.FastSpringBones.Blittables
|
|||
public BlittableSpan logicSpan;
|
||||
public int centerTransformIndex;
|
||||
public int transformIndexOffset;
|
||||
public Vector3 externalForce;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,8 @@ namespace UniVRM10.FastSpringBones.System
|
|||
public NativeArray<BlittableCollider> Colliders => _colliders;
|
||||
public NativeArray<BlittableLogic> Logics => _logics;
|
||||
|
||||
public bool HasBuffer => _batchedBuffers != null && _batchedBuffers.Length > 0;
|
||||
|
||||
public void Register(FastSpringBoneBuffer buffer)
|
||||
{
|
||||
_buffers.AddLast(buffer);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ namespace UniVRM10.FastSpringBones.System
|
|||
public sealed class FastSpringBoneScheduler : IDisposable
|
||||
{
|
||||
private readonly FastSpringBoneBufferCombiner _bufferCombiner;
|
||||
public Vector3 ExternalForce { get; set; }
|
||||
|
||||
public FastSpringBoneScheduler(FastSpringBoneBufferCombiner bufferCombiner)
|
||||
{
|
||||
|
|
@ -18,6 +19,10 @@ namespace UniVRM10.FastSpringBones.System
|
|||
{
|
||||
var handle = default(JobHandle);
|
||||
handle = _bufferCombiner.ReconstructIfDirty(handle);
|
||||
if (!_bufferCombiner.HasBuffer)
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
|
||||
handle = new PullTransformJob
|
||||
{
|
||||
|
|
@ -32,6 +37,7 @@ namespace UniVRM10.FastSpringBones.System
|
|||
Springs = _bufferCombiner.Springs,
|
||||
Transforms = _bufferCombiner.Transforms,
|
||||
DeltaTime = Time.deltaTime,
|
||||
ExternalForce = ExternalForce
|
||||
}.Schedule(_bufferCombiner.Springs.Length, 1, handle);
|
||||
|
||||
handle = new PushTransformJob
|
||||
|
|
|
|||
|
|
@ -27,6 +27,12 @@ namespace UniVRM10.FastSpringBones.System
|
|||
}
|
||||
}
|
||||
|
||||
public Vector3 ExternalForce
|
||||
{
|
||||
get => _fastSpringBoneScheduler.ExternalForce;
|
||||
set => _fastSpringBoneScheduler.ExternalForce = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 専有しているインスタンスを破棄する
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace UniVRM10.FastSpringBones.System
|
|||
[NativeDisableParallelForRestriction] public NativeArray<BlittableTransform> Transforms;
|
||||
|
||||
public float DeltaTime;
|
||||
public Vector3 ExternalForce;
|
||||
|
||||
public void Execute(int index)
|
||||
{
|
||||
|
|
@ -43,7 +44,6 @@ namespace UniVRM10.FastSpringBones.System
|
|||
? Transforms[spring.centerTransformIndex + transformIndexOffset]
|
||||
: (BlittableTransform?)null;
|
||||
|
||||
|
||||
// 親があったら、親に依存するTransformを再計算
|
||||
if (parentTransform.HasValue)
|
||||
{
|
||||
|
|
@ -62,7 +62,7 @@ namespace UniVRM10.FastSpringBones.System
|
|||
var parentRotation = parentTransform?.rotation ?? Quaternion.identity;
|
||||
|
||||
// verlet積分で次の位置を計算
|
||||
var external = joint.gravityDir * joint.gravityPower * DeltaTime;
|
||||
var external = (joint.gravityDir * joint.gravityPower + ExternalForce) * DeltaTime;
|
||||
var nextTail = currentTail
|
||||
+ (currentTail - prevTail) * (1.0f - joint.dragForce) // 前フレームの移動を継続する(減衰もあるよ)
|
||||
+ parentRotation * logic.localRotation * logic.boneAxis *
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user