mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-23 11:05:29 -05:00
FastSpringBone作り直しのため、データ構造を再構築
This commit is contained in:
@@ -3,18 +3,11 @@ using UnityEngine;
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// VRMSpringBoneのSphereColliderをBlittableにしたもの
|
||||
/// 位置情報は親であるColliderGroupが持つ
|
||||
/// Blittableなコライダ
|
||||
/// </summary>
|
||||
public readonly struct BlittableCollider
|
||||
{
|
||||
public Vector3 Offset { get; }
|
||||
public float Radius { get; }
|
||||
|
||||
public BlittableCollider(Vector3 offset, float radius)
|
||||
{
|
||||
Offset = offset;
|
||||
Radius = radius;
|
||||
}
|
||||
public struct BlittableCollider
|
||||
{
|
||||
public Vector3 Offset;
|
||||
public float Radius;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// VRMSpringBoneのColliderGroupをBlittableにしたもの
|
||||
/// </summary>
|
||||
public readonly struct BlittableColliderGroup
|
||||
{
|
||||
public BlittableColliders Colliders { get; }
|
||||
public unsafe BlittableTransform* Transform { get; }
|
||||
|
||||
public unsafe BlittableColliderGroup(NativeArray<BlittableCollider> colliders, BlittableTransform* transform)
|
||||
{
|
||||
Colliders = new BlittableColliders((BlittableCollider*)colliders.GetUnsafePtr(), colliders.Length);
|
||||
Transform = transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 478b0f68277d5a346a9e909e398451aa
|
||||
timeCreated: 1550223602
|
||||
@@ -1,34 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittableColliderGroupのポインタの配列
|
||||
/// </summary>
|
||||
public readonly unsafe struct BlittableColliderGroups
|
||||
{
|
||||
private readonly BlittableColliderGroup* _data;
|
||||
public int Length { get; }
|
||||
|
||||
public BlittableColliderGroup this[int i] => _data[i];
|
||||
|
||||
public void DrawGizmos()
|
||||
{
|
||||
for (var i = 0; i < Length; i++)
|
||||
{
|
||||
var group = this[i];
|
||||
var colliders = group.Colliders;
|
||||
for (var j = 0; j < colliders.Count; ++j)
|
||||
{
|
||||
Gizmos.DrawWireSphere(group.Transform->WorldPosition, colliders[j].Radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlittableColliderGroups(BlittableColliderGroup* data, int length)
|
||||
{
|
||||
_data = data;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8ecae557f477ff4fa60ef840e6b6167
|
||||
timeCreated: 1550563011
|
||||
@@ -1,19 +0,0 @@
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittableColliderのポインタの配列
|
||||
/// </summary>
|
||||
public unsafe struct BlittableColliders
|
||||
{
|
||||
private readonly BlittableCollider* _colliders;
|
||||
public int Count { get; }
|
||||
|
||||
public BlittableCollider this[int i] => _colliders[i];
|
||||
|
||||
public BlittableColliders(BlittableCollider* colliders, int count)
|
||||
{
|
||||
_colliders = colliders;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14be485b03404da4a9a5ba19211f9c1b
|
||||
timeCreated: 1550562383
|
||||
@@ -0,0 +1,17 @@
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// SpringBoneの各関節を表すデータ型
|
||||
/// </summary>
|
||||
public struct BlittableJoint
|
||||
{
|
||||
public float StiffnessForce;
|
||||
public float GravityPower;
|
||||
public Vector3 GravityDir;
|
||||
public float DragForce;
|
||||
public float Radius;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// SpringBoneの各関節を表すデータ型
|
||||
/// </summary>
|
||||
public struct BlittableLogic
|
||||
{
|
||||
public float Length;
|
||||
public Vector3 CurrentTail;
|
||||
public Vector3 PrevTail;
|
||||
public Vector3 LocalDir;
|
||||
public Quaternion LocalRotation;
|
||||
public Vector3 BoneAxis;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9731a165cdc47b5a6c9452cdab150a5
|
||||
timeCreated: 1633060275
|
||||
@@ -1,149 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// VRMSpringBoneLogicをBlittableにしたもの
|
||||
/// ベルレ積分など、コアな計算を行う
|
||||
/// </summary>
|
||||
public unsafe struct BlittablePoint
|
||||
{
|
||||
private readonly float _length;
|
||||
private readonly Quaternion _localRotation;
|
||||
private readonly Vector3 _boneAxis;
|
||||
private readonly float _radius;
|
||||
private Vector3 _prevPosition;
|
||||
|
||||
private readonly BlittableColliderGroups* _blittableColliderGroups;
|
||||
private readonly BlittableTransform* _center;
|
||||
|
||||
public Vector3 CurrentPosition { get; private set; }
|
||||
|
||||
private readonly BlittableTransform* _transform;
|
||||
|
||||
public BlittablePoint(
|
||||
Transform transform,
|
||||
float radius,
|
||||
BlittableTransform* center,
|
||||
BlittableColliderGroups* blittableColliderGroups,
|
||||
BlittableTransform* blittableTransform)
|
||||
{
|
||||
Vector3 localPosition;
|
||||
if (transform.childCount == 0)
|
||||
{
|
||||
var delta = transform.position - transform.parent.position;
|
||||
var childPosition = transform.position + delta.normalized * 0.07f;
|
||||
localPosition = transform.worldToLocalMatrix.MultiplyPoint(childPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
var firstChild = transform.GetChild(0);
|
||||
var scale = firstChild.lossyScale;
|
||||
localPosition = firstChild.localPosition;
|
||||
localPosition.x *= scale.x;
|
||||
localPosition.y *= scale.y;
|
||||
localPosition.z *= scale.z;
|
||||
}
|
||||
|
||||
var worldChildPosition = (Vector3)transform.TransformPoint(localPosition);
|
||||
_prevPosition = CurrentPosition = center != null ? center->LocalToWorld.inverse.MultiplyPoint3x4(worldChildPosition) : worldChildPosition;
|
||||
|
||||
_localRotation = transform.localRotation;
|
||||
_boneAxis = localPosition.normalized;
|
||||
_length = localPosition.magnitude;
|
||||
_radius = radius;
|
||||
_blittableColliderGroups = blittableColliderGroups;
|
||||
_transform = blittableTransform;
|
||||
_center = center;
|
||||
}
|
||||
|
||||
public void Update(float stiffnessForce, float dragForce, Vector3 external)
|
||||
{
|
||||
// 親のRotationが変わっている可能性があるので更新する
|
||||
_transform->UpdateLocalToWorldMatrix();
|
||||
|
||||
Vector3 currentPosition;
|
||||
Vector3 prevPosition;
|
||||
|
||||
if (_center == null)
|
||||
{
|
||||
currentPosition = CurrentPosition;
|
||||
prevPosition = _prevPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
var centerLocalToWorld = _center->LocalToWorld;
|
||||
currentPosition = centerLocalToWorld.MultiplyPoint3x4(CurrentPosition);
|
||||
prevPosition = centerLocalToWorld.MultiplyPoint3x4(_prevPosition);
|
||||
}
|
||||
|
||||
// verlet積分で次の位置を計算
|
||||
var nextPosition = currentPosition
|
||||
+ (currentPosition - prevPosition) * (1.0f - dragForce) // 前フレームの移動を継続する(減衰もあるよ)
|
||||
+ _transform->ParentWorldRotation * _localRotation * _boneAxis * stiffnessForce // 親の回転による子ボーンの移動目標
|
||||
+ external; // 外力による移動量
|
||||
|
||||
// 長さをboneLengthに強制
|
||||
var position = _transform->WorldPosition;
|
||||
nextPosition = position + (nextPosition - position).normalized * _length;
|
||||
|
||||
nextPosition = Collision(nextPosition, position);
|
||||
|
||||
if (_center == null)
|
||||
{
|
||||
_prevPosition = currentPosition;
|
||||
CurrentPosition = nextPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
var centerWorldToLocal = _center->LocalToWorld.inverse;
|
||||
_prevPosition = centerWorldToLocal.MultiplyPoint3x4(currentPosition);
|
||||
CurrentPosition = centerWorldToLocal.MultiplyPoint3x4(nextPosition);
|
||||
}
|
||||
|
||||
//回転を適用
|
||||
_transform->SetWorldRotation(ApplyRotation(nextPosition));
|
||||
}
|
||||
|
||||
private Vector3 Collision(Vector3 nextPosition, Vector3 position)
|
||||
{
|
||||
for (var i = 0; i < _blittableColliderGroups->Length; ++i)
|
||||
{
|
||||
var colliderGroup = (*_blittableColliderGroups)[i];
|
||||
|
||||
for (var j = 0; j < colliderGroup.Colliders.Count; ++j)
|
||||
{
|
||||
var collider = colliderGroup.Colliders[j];
|
||||
var colliderPosition = colliderGroup.Transform->TransformPoint(collider.Offset);
|
||||
var r = _radius + collider.Radius;
|
||||
|
||||
if (!((nextPosition - colliderPosition).sqrMagnitude <= (r * r))) continue;
|
||||
|
||||
// ヒット。Colliderの半径方向に押し出す
|
||||
var normal = (nextPosition - colliderPosition).normalized;
|
||||
var posFromCollider = colliderPosition + normal * (_radius + collider.Radius);
|
||||
|
||||
// 長さをboneLengthに強制
|
||||
nextPosition = position + (posFromCollider - position).normalized * _length;
|
||||
}
|
||||
}
|
||||
return nextPosition;
|
||||
}
|
||||
|
||||
private static Quaternion FromToRotation(Vector3 from, Vector3 to)
|
||||
=> Quaternion.AxisAngle(
|
||||
angle: Mathf.Acos(Mathf.Clamp(Vector3.Dot(from.normalized, to.normalized), -1f, 1f)),
|
||||
axis: Vector3.Cross(from, to).normalized
|
||||
);
|
||||
|
||||
private Quaternion ApplyRotation(Vector3 nextTail)
|
||||
{
|
||||
var rotation = _transform->ParentWorldRotation * _localRotation;
|
||||
return
|
||||
FromToRotation(
|
||||
rotation * _boneAxis,
|
||||
nextTail - _transform->WorldPosition) *
|
||||
rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittablePointのポインタの配列
|
||||
/// </summary>
|
||||
public unsafe struct BlittablePoints
|
||||
{
|
||||
private readonly BlittablePoint* _points;
|
||||
public int Count { get; }
|
||||
|
||||
public BlittablePoint this[int i]
|
||||
{
|
||||
get => _points[i];
|
||||
set => _points[i] = value;
|
||||
}
|
||||
|
||||
public BlittablePoints(BlittablePoint* points, int count)
|
||||
{
|
||||
_points = points;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55f68ce7085cb7640a50cb133741361b
|
||||
timeCreated: 1550721598
|
||||
@@ -1,64 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// 1本の毛束を示すBlittable型
|
||||
/// </summary>
|
||||
public unsafe readonly struct BlittableRootBone
|
||||
{
|
||||
private readonly float _gravityPower;
|
||||
private readonly Vector3 _gravityDir;
|
||||
private readonly float _dragForce;
|
||||
private readonly float _stiffnessForce;
|
||||
private readonly BlittablePoints* _blittablePoints;
|
||||
|
||||
public void DrawGizmos()
|
||||
{
|
||||
for (var i = 0; i < _blittablePoints->Count; i++)
|
||||
{
|
||||
var point = (*_blittablePoints)[i];
|
||||
Gizmos.DrawWireSphere(point.CurrentPosition, 0.05f);
|
||||
}
|
||||
for (var i = 0; i < _blittablePoints->Count - 1; i++)
|
||||
{
|
||||
var point1 = (*_blittablePoints)[i];
|
||||
var point2 = (*_blittablePoints)[i + 1];
|
||||
Gizmos.DrawLine(point1.CurrentPosition, point2.CurrentPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public BlittableRootBone(
|
||||
float gravityPower,
|
||||
Vector3 gravityDir,
|
||||
float dragForce,
|
||||
float stiffnessForce,
|
||||
BlittablePoints* blittablePoints)
|
||||
{
|
||||
_gravityPower = gravityPower;
|
||||
_gravityDir = gravityDir;
|
||||
_dragForce = dragForce;
|
||||
_stiffnessForce = stiffnessForce;
|
||||
_blittablePoints = blittablePoints;
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
var stiffness = _stiffnessForce * deltaTime;
|
||||
var external = _gravityDir * (_gravityPower * deltaTime);
|
||||
for (var i = 0; i < _blittablePoints->Count; i++)
|
||||
{
|
||||
var point = (*_blittablePoints)[i];
|
||||
|
||||
// Pointを更新
|
||||
point.Update(
|
||||
stiffness,
|
||||
_dragForce,
|
||||
external
|
||||
);
|
||||
|
||||
(*_blittablePoints)[i] = point;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
public struct BlittableSpan
|
||||
{
|
||||
public int StartIndex;
|
||||
public int Count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47daa1c068464f44987de43eba2210dc
|
||||
timeCreated: 1633067618
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// 1本の毛束を表すデータ型
|
||||
/// </summary>
|
||||
public struct BlittableSpring
|
||||
{
|
||||
public BlittableSpan ColliderSpan;
|
||||
public BlittableSpan JointSpan;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,18 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Jobs;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Blittables
|
||||
{
|
||||
/// <summary>
|
||||
/// Transformの必要な機能だけを絞り、Blittableに対応させたクラス
|
||||
/// </summary>
|
||||
public unsafe struct BlittableTransform
|
||||
public struct BlittableTransform
|
||||
{
|
||||
private readonly BlittableTransform* _parent;
|
||||
private Quaternion _worldRotation;
|
||||
private Vector3 _localPosition;
|
||||
private Vector3 _localScale;
|
||||
private Quaternion _localRotation;
|
||||
private Matrix4x4 _localToWorld;
|
||||
|
||||
public Vector3 WorldPosition { get; private set; }
|
||||
|
||||
public void SetWorldRotation(Quaternion rotation)
|
||||
{
|
||||
var parentWorldRotation = ParentWorldRotation;
|
||||
_localRotation = Quaternion.Inverse(parentWorldRotation) * rotation;
|
||||
UpdateLocalToWorldMatrix();
|
||||
}
|
||||
|
||||
public Matrix4x4 LocalToWorld => _localToWorld;
|
||||
|
||||
private Matrix4x4 LocalTransform => Matrix4x4.TRS(_localPosition, _localRotation, _localScale);
|
||||
|
||||
public Quaternion ParentWorldRotation => _parent != null ? _parent->_worldRotation : Quaternion.identity;
|
||||
|
||||
public BlittableTransform(BlittableTransform* parent, Transform transform)
|
||||
{
|
||||
_parent = parent;
|
||||
|
||||
WorldPosition = transform.position;
|
||||
_worldRotation = transform.rotation;
|
||||
_localPosition = transform.localPosition;
|
||||
_localRotation = transform.localRotation;
|
||||
_localScale = transform.localScale;
|
||||
|
||||
_localToWorld = transform.localToWorldMatrix;
|
||||
}
|
||||
|
||||
public void PullFrom(TransformAccess transform)
|
||||
{
|
||||
WorldPosition = transform.position;
|
||||
_worldRotation = transform.rotation;
|
||||
_localPosition = transform.localPosition;
|
||||
_localRotation = transform.localRotation;
|
||||
_localScale = transform.localScale;
|
||||
|
||||
_localToWorld = transform.localToWorldMatrix;
|
||||
}
|
||||
|
||||
public void PushTo(TransformAccess transform)
|
||||
{
|
||||
transform.localPosition = _localPosition;
|
||||
transform.localRotation = _localRotation;
|
||||
}
|
||||
|
||||
public Vector3 TransformPoint(Vector3 offset) => _localToWorld.MultiplyPoint3x4(offset);
|
||||
|
||||
public void UpdateLocalToWorldMatrix()
|
||||
{
|
||||
_localToWorld = _parent == null ? LocalTransform : _parent->_localToWorld * LocalTransform;
|
||||
WorldPosition = _localToWorld.MultiplyPoint3x4(Vector3.zero);
|
||||
_worldRotation = _localToWorld.rotation;
|
||||
}
|
||||
public Vector3 Position;
|
||||
public Quaternion Rotation;
|
||||
public Vector3 LocalPosition;
|
||||
public Quaternion LocalRotation;
|
||||
public Vector3 LocalScale;
|
||||
public Matrix4x4 LocalToWorldMatrix;
|
||||
public Matrix4x4 WorldToLocalMatrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// VRMSpringBoneColliderGroupに対応したクラス
|
||||
/// バッファの作成も行う
|
||||
/// </summary>
|
||||
public sealed unsafe class FastSpringBoneColliderGroup : MonoBehaviour
|
||||
{
|
||||
private NativeTransform _nativeTransform;
|
||||
private NativeColliderGroup _nativeColliderGroup;
|
||||
|
||||
public BlittableColliderGroup* ColliderGroupPtr => _nativeColliderGroup.GetUnsafePtr();
|
||||
|
||||
public void Initialize(TransformRegistry transformRegistry, BlittableCollider[] colliders)
|
||||
{
|
||||
_nativeTransform = new NativeTransform(transformRegistry, TransformSynchronizationType.PullOnly, transform);
|
||||
_nativeColliderGroup = new NativeColliderGroup(colliders, _nativeTransform);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_nativeTransform?.Dispose();
|
||||
_nativeColliderGroup?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5fe6672f5b7b1049bb9e1bed44ee015
|
||||
timeCreated: 1550213674
|
||||
@@ -1,100 +0,0 @@
|
||||
using Unity.Jobs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
using UniVRM10.FastSpringBones.Schedulers;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Jobを連続して発火させるComponent
|
||||
/// シーンに1つだけあればいい
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(11000)]
|
||||
public sealed class FastSpringBoneScheduler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool showGizmos;
|
||||
|
||||
private CustomSampler _updateSampler;
|
||||
|
||||
private PullTransformJobScheduler _pullTransformJobScheduler;
|
||||
private PushTransformJobScheduler _pushTransformJobScheduler;
|
||||
private UpdateSpringBoneJobScheduler _updateSpringBoneJobScheduler;
|
||||
|
||||
private RootBoneRegistry _rootBoneRegistry;
|
||||
private ColliderGroupRegistry _colliderGroupRegistry;
|
||||
|
||||
private JobHandle _prevJobHandle;
|
||||
|
||||
public bool ShowGizmos { get => showGizmos; set => showGizmos = value; }
|
||||
|
||||
public void Initialize(
|
||||
RootBoneRegistry rootBoneRegistry,
|
||||
TransformRegistry transformRegistry,
|
||||
ColliderGroupRegistry colliderGroupRegistry)
|
||||
{
|
||||
_rootBoneRegistry = rootBoneRegistry;
|
||||
_colliderGroupRegistry = colliderGroupRegistry;
|
||||
|
||||
_updateSampler = CustomSampler.Create("FastSpringBone(Update)");
|
||||
|
||||
_pullTransformJobScheduler = new PullTransformJobScheduler(transformRegistry);
|
||||
_pushTransformJobScheduler = new PushTransformJobScheduler(transformRegistry);
|
||||
_updateSpringBoneJobScheduler = new UpdateSpringBoneJobScheduler(_rootBoneRegistry);
|
||||
|
||||
_rootBoneRegistry.SubscribeOnValueChanged(OnRootBoneChanged);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_rootBoneRegistry.UnSubscribeOnValueChanged(OnRootBoneChanged);
|
||||
_prevJobHandle.Complete();
|
||||
|
||||
_pullTransformJobScheduler.Dispose();
|
||||
_pushTransformJobScheduler.Dispose();
|
||||
_updateSpringBoneJobScheduler.Dispose();
|
||||
}
|
||||
|
||||
private void OnRootBoneChanged()
|
||||
{
|
||||
_prevJobHandle.Complete();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (!ShowGizmos) return;
|
||||
|
||||
_prevJobHandle.Complete();
|
||||
|
||||
Gizmos.color = Color.blue;
|
||||
foreach (var rootBoneWrapper in _rootBoneRegistry.Items)
|
||||
{
|
||||
rootBoneWrapper.Value.DrawGizmos();
|
||||
}
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
foreach (var colliderGroup in _colliderGroupRegistry.Items)
|
||||
{
|
||||
colliderGroup.DrawGizmos();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
_updateSampler.Begin();
|
||||
|
||||
_prevJobHandle.Complete();
|
||||
|
||||
var tempJobHandle = default(JobHandle);
|
||||
tempJobHandle = _pullTransformJobScheduler.Schedule(tempJobHandle);
|
||||
tempJobHandle = _updateSpringBoneJobScheduler.Schedule(tempJobHandle);
|
||||
tempJobHandle = _pushTransformJobScheduler.Schedule(tempJobHandle);
|
||||
|
||||
_prevJobHandle = tempJobHandle;
|
||||
|
||||
_updateSampler.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3affa859639024f439b13d4cd4a9b0f6
|
||||
timeCreated: 1549521562
|
||||
@@ -1,124 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// SpringBoneの1本の毛束の処理を担当するクラス
|
||||
/// </summary>
|
||||
public sealed class FastSpringRootBone : IDisposable
|
||||
{
|
||||
private readonly TransformRegistry _transformRegistry;
|
||||
private readonly RootBoneRegistry _rootBoneRegistry;
|
||||
private readonly ColliderGroupRegistry _colliderGroupRegistry;
|
||||
private readonly Transform _transform;
|
||||
|
||||
private float _radius;
|
||||
private NativeTransform _center;
|
||||
|
||||
private IReadOnlyDictionary<Transform, int> _transformIndexMap;
|
||||
private NativeColliderGroups _nativeColliderGroups;
|
||||
|
||||
private NativePoints _nativePoints;
|
||||
private NativePointer<BlittableRootBone> _rootBoneWrapper;
|
||||
|
||||
private readonly IList<NativeTransform> _transformWrappers = new List<NativeTransform>();
|
||||
private readonly IList<NativePointer<BlittablePoint>> _points = new List<NativePointer<BlittablePoint>>();
|
||||
|
||||
public FastSpringRootBone(
|
||||
TransformRegistry transformRegistry,
|
||||
Transform transform,
|
||||
RootBoneRegistry rootBoneRegistry,
|
||||
ColliderGroupRegistry colliderGroupRegistry
|
||||
)
|
||||
{
|
||||
_transformRegistry = transformRegistry;
|
||||
_transform = transform;
|
||||
_rootBoneRegistry = rootBoneRegistry;
|
||||
_colliderGroupRegistry = colliderGroupRegistry;
|
||||
}
|
||||
|
||||
public IReadOnlyList<FastSpringBoneColliderGroup> ColliderGroups
|
||||
{
|
||||
get => _nativeColliderGroups.ColliderGroups;
|
||||
set => _nativeColliderGroups.ColliderGroups = value;
|
||||
}
|
||||
|
||||
public unsafe void Initialize(
|
||||
float gravityPower,
|
||||
Vector3 gravityDir,
|
||||
float dragForce,
|
||||
float stiffnessForce,
|
||||
IReadOnlyList<FastSpringBoneColliderGroup> colliderGroups,
|
||||
float radius,
|
||||
Transform center)
|
||||
{
|
||||
_radius = radius;
|
||||
if (center != null)
|
||||
{
|
||||
_center = new NativeTransform(_transformRegistry, TransformSynchronizationType.PullOnly, center);
|
||||
}
|
||||
|
||||
_nativeColliderGroups = new NativeColliderGroups(colliderGroups);
|
||||
|
||||
NativeTransform parent = null;
|
||||
if (_transform.parent)
|
||||
{
|
||||
parent = new NativeTransform(_transformRegistry, TransformSynchronizationType.PullOnly, _transform.parent);
|
||||
}
|
||||
SetupRecursive(_transform, parent);
|
||||
|
||||
_nativePoints = new NativePoints(_points);
|
||||
|
||||
_rootBoneWrapper = new NativePointer<BlittableRootBone>(new BlittableRootBone(gravityPower, gravityDir, dragForce, stiffnessForce, _nativePoints.GetUnsafePtr()));
|
||||
_rootBoneRegistry.Register(_rootBoneWrapper);
|
||||
_colliderGroupRegistry.Register(_nativeColliderGroups);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_colliderGroupRegistry.Unregister(_nativeColliderGroups);
|
||||
_rootBoneRegistry.Unregister(_rootBoneWrapper);
|
||||
|
||||
foreach (var transformWrapper in _transformWrappers)
|
||||
{
|
||||
transformWrapper.Dispose();
|
||||
}
|
||||
|
||||
foreach (var point in _points)
|
||||
{
|
||||
point.Dispose();
|
||||
}
|
||||
|
||||
_center?.Dispose();
|
||||
_nativeColliderGroups?.Dispose();
|
||||
_nativePoints.Dispose();
|
||||
_rootBoneWrapper.Dispose();
|
||||
}
|
||||
|
||||
private unsafe void SetupRecursive(Transform trs, NativeTransform parent = null)
|
||||
{
|
||||
var transformWrapper = new NativeTransform(_transformRegistry, TransformSynchronizationType.PushOnly, trs, parent);
|
||||
_transformWrappers.Add(transformWrapper);
|
||||
|
||||
var point = new NativePointer<BlittablePoint>(
|
||||
new BlittablePoint(
|
||||
trs,
|
||||
_radius,
|
||||
_center != null ? _center.GetUnsafePtr() : null,
|
||||
_nativeColliderGroups.GetUnsafePtr(),
|
||||
transformWrapper.GetUnsafePtr())
|
||||
);
|
||||
_points.Add(point);
|
||||
|
||||
for (var i = 0; i < trs.childCount; ++i)
|
||||
{
|
||||
SetupRecursive(trs.GetChild(i), transformWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03e3a3dad32f6e64a9fd0327d74c8305
|
||||
timeCreated: 1550036996
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57b934d4e245cef49acc06524c3e1f7d
|
||||
guid: bc529d8de129fe44ca6bfa94972f8951
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
[Serializable]
|
||||
public struct FastSpringBoneCollider
|
||||
{
|
||||
public Transform Transform;
|
||||
public BlittableCollider Collider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffca416cb15a43239b73ed6067076458
|
||||
timeCreated: 1633066289
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
[Serializable]
|
||||
public struct FastSpringBoneJoint
|
||||
{
|
||||
public Transform Transform;
|
||||
public BlittableJoint Joint;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6742aa2a6a34bd395add629c17ab952
|
||||
timeCreated: 1633066253
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
[Serializable]
|
||||
public struct FastSpringBoneSpring
|
||||
{
|
||||
public FastSpringBoneJoint[] Joints;
|
||||
public FastSpringBoneCollider[] Colliders;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0a972985499416e8e95acdf16fae6ba
|
||||
timeCreated: 1633066412
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.NativeWrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittableColliderGroupのライフサイクルを管理するWrapper
|
||||
/// </summary>
|
||||
public sealed unsafe class NativeColliderGroup : IDisposable
|
||||
{
|
||||
private readonly NativePointer<BlittableColliderGroup> _nativePointer;
|
||||
|
||||
private NativeArray<BlittableCollider> Colliders { get; }
|
||||
|
||||
public BlittableColliderGroup* GetUnsafePtr() => _nativePointer.GetUnsafePtr();
|
||||
|
||||
public NativeColliderGroup(BlittableCollider[] colliders, NativeTransform nativeTransform)
|
||||
{
|
||||
Colliders = new NativeArray<BlittableCollider>(colliders, Allocator.Persistent);
|
||||
_nativePointer = new NativePointer<BlittableColliderGroup>(new BlittableColliderGroup(Colliders, nativeTransform.GetUnsafePtr()));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Colliders.IsCreated) Colliders.Dispose();
|
||||
|
||||
_nativePointer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8d248be1ab9abe46abd06caa4758d6b
|
||||
timeCreated: 1550640666
|
||||
@@ -1,78 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.Components;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.NativeWrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittableColliderGroupsのライフサイクルを管理するWrapper
|
||||
/// </summary>
|
||||
public sealed unsafe class NativeColliderGroups : IDisposable
|
||||
{
|
||||
private readonly NativePointer<BlittableColliderGroups> _nativePointer = new NativePointer<BlittableColliderGroups>();
|
||||
private NativeArray<BlittableColliderGroup> _colliderGroupArray;
|
||||
private IReadOnlyList<FastSpringBoneColliderGroup> _colliderGroups;
|
||||
|
||||
//Disposeされた後にUpdateColliderGroupsが呼ばれるのを防ぐためのフラグ
|
||||
private bool _isDisposed;
|
||||
|
||||
public BlittableColliderGroups* GetUnsafePtr() => _nativePointer.GetUnsafePtr();
|
||||
public void DrawGizmos() => _nativePointer.Value.DrawGizmos();
|
||||
|
||||
public IReadOnlyList<FastSpringBoneColliderGroup> ColliderGroups
|
||||
{
|
||||
get => _colliderGroups;
|
||||
set
|
||||
{
|
||||
_colliderGroups = value;
|
||||
UpdateColliderGroups();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateColliderGroups()
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
if (_colliderGroupArray.IsCreated)
|
||||
{
|
||||
_colliderGroupArray.Dispose();
|
||||
}
|
||||
CreateColliderGroupArray(_colliderGroups);
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
public NativeColliderGroups(IReadOnlyList<FastSpringBoneColliderGroup> colliderGroups)
|
||||
{
|
||||
_colliderGroups = colliderGroups;
|
||||
UpdateColliderGroups();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_colliderGroupArray.IsCreated)
|
||||
{
|
||||
_colliderGroupArray.Dispose();
|
||||
_isDisposed = true;
|
||||
}
|
||||
_nativePointer.Dispose();
|
||||
}
|
||||
|
||||
private void CreateColliderGroupArray(IReadOnlyList<FastSpringBoneColliderGroup> colliderGroups)
|
||||
{
|
||||
_colliderGroupArray = new NativeArray<BlittableColliderGroup>(colliderGroups.Count, Allocator.Persistent);
|
||||
for (var i = 0; i < _colliderGroupArray.Length; ++i)
|
||||
{
|
||||
_colliderGroupArray[i] = *colliderGroups[i].ColliderGroupPtr;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateData()
|
||||
{
|
||||
_nativePointer.Value = new BlittableColliderGroups(
|
||||
(BlittableColliderGroup*)_colliderGroupArray.GetUnsafePtr(),
|
||||
_colliderGroupArray.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73c3eb940b180fc48a3e7cdacc621543
|
||||
timeCreated: 1550645184
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.NativeWrappers
|
||||
{
|
||||
public sealed class NativePointer<T> : IDisposable where T : unmanaged
|
||||
{
|
||||
private readonly unsafe T* _unsafePtr;
|
||||
|
||||
public unsafe T* GetUnsafePtr() => _unsafePtr;
|
||||
|
||||
public unsafe T Value
|
||||
{
|
||||
get => *_unsafePtr;
|
||||
set => *_unsafePtr = value;
|
||||
}
|
||||
|
||||
public unsafe NativePointer()
|
||||
{
|
||||
_unsafePtr = (T*)UnsafeUtility.Malloc(sizeof(T), 16, Allocator.Persistent);
|
||||
}
|
||||
|
||||
public unsafe NativePointer(T value)
|
||||
{
|
||||
_unsafePtr = (T*)UnsafeUtility.Malloc(sizeof(T), 16, Allocator.Persistent);
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public unsafe void Dispose()
|
||||
{
|
||||
UnsafeUtility.Free(_unsafePtr, Allocator.Persistent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c4d1058273489b478b053eb13702d6e
|
||||
timeCreated: 1595316733
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.NativeWrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittablePointsGroupのライフサイクルを管理するWrapper
|
||||
/// </summary>
|
||||
public sealed unsafe class NativePoints : IDisposable
|
||||
{
|
||||
private readonly NativePointer<BlittablePoints> _nativePointer;
|
||||
private NativeArray<BlittablePoint> _buffer;
|
||||
|
||||
public BlittablePoints* GetUnsafePtr() => _nativePointer.GetUnsafePtr();
|
||||
|
||||
public NativePoints(IList<NativePointer<BlittablePoint>> points)
|
||||
{
|
||||
_buffer = new NativeArray<BlittablePoint>(points.Count, Allocator.Persistent);
|
||||
for (var i = 0; i < _buffer.Length; ++i)
|
||||
{
|
||||
_buffer[i] = points[i].Value;
|
||||
}
|
||||
|
||||
_nativePointer = new NativePointer<BlittablePoints>(new BlittablePoints((BlittablePoint*) _buffer.GetUnsafePtr(), _buffer.Length));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_buffer.IsCreated)
|
||||
{
|
||||
_buffer.Dispose();
|
||||
}
|
||||
_nativePointer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91cb239111add8342b25267432c53894
|
||||
timeCreated: 1550723674
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.NativeWrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// BlittableTransformのライフサイクルを管理するWrapper
|
||||
/// </summary>
|
||||
public sealed class NativeTransform : IDisposable
|
||||
{
|
||||
private readonly NativePointer<BlittableTransform> _nativePointer;
|
||||
public Transform Transform { get; }
|
||||
|
||||
private readonly TransformRegistry _transformRegistry;
|
||||
|
||||
public unsafe BlittableTransform* GetUnsafePtr() => _nativePointer.GetUnsafePtr();
|
||||
public BlittableTransform Value => _nativePointer.Value;
|
||||
|
||||
public unsafe NativeTransform(
|
||||
TransformRegistry transformRegistry,
|
||||
TransformSynchronizationType transformSynchronizationType,
|
||||
Transform transform,
|
||||
NativeTransform parent = null
|
||||
)
|
||||
{
|
||||
_nativePointer = new NativePointer<BlittableTransform>(new BlittableTransform(parent != null ? parent.GetUnsafePtr() : null, transform));
|
||||
|
||||
Transform = transform;
|
||||
|
||||
_transformRegistry = transformRegistry;
|
||||
_transformRegistry.Register(this, transformSynchronizationType);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_transformRegistry.Unregister(this);
|
||||
|
||||
_nativePointer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31fdb7a504d498242a3e459e3a63bf2d
|
||||
timeCreated: 1550545201
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a590127469e104049996cf9b123db183
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Registries
|
||||
{
|
||||
public sealed class ColliderGroupRegistry : Registry<NativeColliderGroups>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f5847b2d8bb16242aac76bda14b0202
|
||||
timeCreated: 1594963749
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Registries
|
||||
{
|
||||
public class Registry<T>
|
||||
{
|
||||
private readonly List<T> _items = new List<T>();
|
||||
private Action _onValueChanged;
|
||||
|
||||
public IReadOnlyList<T> Items => _items;
|
||||
|
||||
public void Register(T value)
|
||||
{
|
||||
_items.Add(value);
|
||||
_onValueChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void Unregister(T value)
|
||||
{
|
||||
_items.Remove(value);
|
||||
_onValueChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void SubscribeOnValueChanged(Action action) => _onValueChanged += action;
|
||||
public void UnSubscribeOnValueChanged(Action action) => _onValueChanged -= action;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d127e4a4d5d05a46929eb3d3692d720
|
||||
timeCreated: 1595407071
|
||||
@@ -1,12 +0,0 @@
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Registries
|
||||
{
|
||||
/// <summary>
|
||||
/// 今生きているRootBoneの一覧を返すクラス
|
||||
/// </summary>
|
||||
public sealed class RootBoneRegistry : Registry<NativePointer<BlittableRootBone>>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34da1f63315656e479315841b7112d7c
|
||||
timeCreated: 1550734399
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Registries
|
||||
{
|
||||
/// <summary>
|
||||
/// 今生きているTransformの一覧を返すクラス
|
||||
/// </summary>
|
||||
public sealed class TransformRegistry
|
||||
{
|
||||
private readonly List<NativeTransform> _transforms = new List<NativeTransform>();
|
||||
public IReadOnlyList<NativeTransform> Transforms => _transforms;
|
||||
|
||||
private readonly List<NativeTransform> _pullTargets = new List<NativeTransform>();
|
||||
public IReadOnlyList<NativeTransform> PullTargets => _pullTargets;
|
||||
|
||||
private readonly List<NativeTransform> _pushTargets = new List<NativeTransform>();
|
||||
public IReadOnlyList<NativeTransform> PushTargets => _pushTargets;
|
||||
|
||||
private Action _onValueChanged;
|
||||
|
||||
public void SubscribeOnValueChanged(Action action) => _onValueChanged += action;
|
||||
|
||||
public void UnSubscribeOnValueChanged(Action action) => _onValueChanged -= action;
|
||||
|
||||
public void Register(NativeTransform nativeTransform, TransformSynchronizationType synchronizationType)
|
||||
{
|
||||
_transforms.Add(nativeTransform);
|
||||
switch (synchronizationType)
|
||||
{
|
||||
case TransformSynchronizationType.PullOnly:
|
||||
_pullTargets.Add(nativeTransform);
|
||||
break;
|
||||
case TransformSynchronizationType.PushOnly:
|
||||
_pushTargets.Add(nativeTransform);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(synchronizationType), synchronizationType, null);
|
||||
}
|
||||
_onValueChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void Unregister(NativeTransform nativeTransform)
|
||||
{
|
||||
_transforms.Remove(nativeTransform);
|
||||
|
||||
if (_pullTargets.Contains(nativeTransform))
|
||||
{
|
||||
_pullTargets.Remove(nativeTransform);
|
||||
}
|
||||
|
||||
if (_pushTargets.Contains(nativeTransform))
|
||||
{
|
||||
_pushTargets.Remove(nativeTransform);
|
||||
}
|
||||
_onValueChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0603b4348a649df4fa966eeb3cd1011a
|
||||
timeCreated: 1550666913
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace UniVRM10.FastSpringBones.Registries
|
||||
{
|
||||
public enum TransformSynchronizationType
|
||||
{
|
||||
PullOnly,
|
||||
PushOnly,
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03978423768dd5542875359a745a0d6d
|
||||
timeCreated: 1551169872
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 160bc0dc84d022a48862d46add47a26c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,119 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if ENABLE_SPRINGBONE_BURST
|
||||
using Unity.Burst;
|
||||
#endif
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine.Jobs;
|
||||
using UnityEngine.Profiling;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Schedulers
|
||||
{
|
||||
/// <summary>
|
||||
/// GameObjectの世界からBlittableな世界へTransformを複製する処理を行うクラス
|
||||
/// </summary>
|
||||
public sealed unsafe class PullTransformJobScheduler : IDisposable
|
||||
{
|
||||
private BlittableTransform** _transformPointers;
|
||||
private TransformAccessArray _transformAccessArray;
|
||||
|
||||
private readonly CustomSampler _sampler = CustomSampler.Create("Schedule CopyFromTransformJob");
|
||||
private readonly TransformRegistry _transformRegistry;
|
||||
|
||||
private bool _dirty = true;
|
||||
|
||||
private IReadOnlyList<NativeTransform> Targets => _transformRegistry.PullTargets;
|
||||
|
||||
public PullTransformJobScheduler(TransformRegistry transformRegistry)
|
||||
{
|
||||
_transformRegistry = transformRegistry;
|
||||
|
||||
_transformRegistry.SubscribeOnValueChanged(OnTransformChanged);
|
||||
}
|
||||
|
||||
private void OnTransformChanged()
|
||||
{
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public JobHandle Schedule(JobHandle dependOn = default(JobHandle))
|
||||
{
|
||||
if (Targets.Count == 0)
|
||||
{
|
||||
return dependOn;
|
||||
}
|
||||
|
||||
_sampler.Begin();
|
||||
|
||||
// リストが変更されていたらバッファを再構築
|
||||
if (_dirty)
|
||||
{
|
||||
ReconstructBuffers();
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
// ジョブを発火
|
||||
var job = new Job { TransformPointers = _transformPointers };
|
||||
var jobHandle = job.Schedule(_transformAccessArray, dependOn);
|
||||
|
||||
_sampler.End();
|
||||
|
||||
return jobHandle;
|
||||
}
|
||||
|
||||
private void ReconstructBuffers()
|
||||
{
|
||||
ReleaseBuffers();
|
||||
|
||||
var transforms = Targets;
|
||||
_transformPointers = (BlittableTransform**)UnsafeUtility.Malloc(
|
||||
sizeof(BlittableTransform*) * transforms.Count,
|
||||
16,
|
||||
Allocator.Persistent
|
||||
);
|
||||
|
||||
_transformAccessArray = new TransformAccessArray(transforms.Count);
|
||||
|
||||
for (var i = 0; i < transforms.Count; i++)
|
||||
{
|
||||
_transformPointers[i] = transforms[i].GetUnsafePtr();
|
||||
_transformAccessArray.Add(transforms[i].Transform);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ReleaseBuffers();
|
||||
_transformRegistry.UnSubscribeOnValueChanged(OnTransformChanged);
|
||||
}
|
||||
|
||||
private void ReleaseBuffers()
|
||||
{
|
||||
if (_transformAccessArray.isCreated) _transformAccessArray.Dispose();
|
||||
if (_transformPointers != null)
|
||||
{
|
||||
UnsafeUtility.Free(_transformPointers, Allocator.Persistent);
|
||||
_transformPointers = null;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_SPRINGBONE_BURST
|
||||
[BurstCompile]
|
||||
#endif
|
||||
private struct Job : IJobParallelForTransform
|
||||
{
|
||||
[NativeDisableUnsafePtrRestriction] public BlittableTransform** TransformPointers;
|
||||
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
TransformPointers[index]->PullFrom(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ac8728e24e9f5240aa45867878dcc10
|
||||
timeCreated: 1550547066
|
||||
@@ -1,119 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if ENABLE_SPRINGBONE_BURST
|
||||
using Unity.Burst;
|
||||
#endif
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine.Jobs;
|
||||
using UnityEngine.Profiling;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Schedulers
|
||||
{
|
||||
/// <summary>
|
||||
/// Blittableな世界からGameObjectの世界へTransformを送り込む処理を行うクラス
|
||||
/// </summary>
|
||||
public sealed unsafe class PushTransformJobScheduler : IDisposable
|
||||
{
|
||||
private BlittableTransform** _transformPointers;
|
||||
private TransformAccessArray _transformAccessArray;
|
||||
|
||||
private readonly CustomSampler _sampler = CustomSampler.Create("Schedule CopyFromTransformJob");
|
||||
private readonly TransformRegistry _transformRegistry;
|
||||
|
||||
private bool _dirty = true;
|
||||
|
||||
private IReadOnlyList<NativeTransform> Targets => _transformRegistry.PushTargets;
|
||||
|
||||
public PushTransformJobScheduler(TransformRegistry transformRegistry)
|
||||
{
|
||||
_transformRegistry = transformRegistry;
|
||||
|
||||
_transformRegistry.SubscribeOnValueChanged(OnTransformChanged);
|
||||
}
|
||||
|
||||
private void OnTransformChanged()
|
||||
{
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public JobHandle Schedule(JobHandle dependOn = default(JobHandle))
|
||||
{
|
||||
if (Targets.Count == 0)
|
||||
{
|
||||
return dependOn;
|
||||
}
|
||||
|
||||
_sampler.Begin();
|
||||
|
||||
// リストが変更されていたらバッファを再構築
|
||||
if (_dirty)
|
||||
{
|
||||
ReconstructBuffers();
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
// Jobを発火
|
||||
var job = new Job { TransformPointers = _transformPointers };
|
||||
var jobHandle = job.Schedule(_transformAccessArray, dependOn);
|
||||
|
||||
_sampler.End();
|
||||
|
||||
return jobHandle;
|
||||
}
|
||||
|
||||
private void ReconstructBuffers()
|
||||
{
|
||||
ReleaseBuffers();
|
||||
|
||||
var transforms = Targets;
|
||||
_transformPointers = (BlittableTransform**)UnsafeUtility.Malloc(
|
||||
sizeof(BlittableTransform*) * transforms.Count,
|
||||
16,
|
||||
Allocator.Persistent
|
||||
);
|
||||
|
||||
_transformAccessArray = new TransformAccessArray(transforms.Count);
|
||||
|
||||
for (var i = 0; i < transforms.Count; i++)
|
||||
{
|
||||
_transformPointers[i] = transforms[i].GetUnsafePtr();
|
||||
_transformAccessArray.Add(transforms[i].Transform);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ReleaseBuffers();
|
||||
_transformRegistry.UnSubscribeOnValueChanged(OnTransformChanged);
|
||||
}
|
||||
|
||||
private void ReleaseBuffers()
|
||||
{
|
||||
if (_transformAccessArray.isCreated) _transformAccessArray.Dispose();
|
||||
if (_transformPointers != null)
|
||||
{
|
||||
UnsafeUtility.Free(_transformPointers, Allocator.Persistent);
|
||||
_transformPointers = null;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_SPRINGBONE_BURST
|
||||
[BurstCompile]
|
||||
#endif
|
||||
private struct Job : IJobParallelForTransform
|
||||
{
|
||||
[NativeDisableUnsafePtrRestriction] public BlittableTransform** TransformPointers;
|
||||
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
TransformPointers[index]->PushTo(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91e1bc2d3c93f1b4db3e08534237e6a0
|
||||
timeCreated: 1550717407
|
||||
@@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if ENABLE_SPRINGBONE_BURST
|
||||
using Unity.Burst;
|
||||
#endif
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.NativeWrappers;
|
||||
using UniVRM10.FastSpringBones.Registries;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.Schedulers
|
||||
{
|
||||
/// <summary>
|
||||
/// SpringBoneを更新する処理を行うクラス
|
||||
/// </summary>
|
||||
public sealed unsafe class UpdateSpringBoneJobScheduler : IDisposable
|
||||
{
|
||||
private BlittableRootBone** _rootBonePointers;
|
||||
|
||||
private readonly RootBoneRegistry _rootBoneRegistry;
|
||||
private readonly CustomSampler _sampler = CustomSampler.Create("Schedule CopyFromTransformJob");
|
||||
|
||||
private bool _dirty = true;
|
||||
|
||||
private IReadOnlyList<NativePointer<BlittableRootBone>> Targets => _rootBoneRegistry.Items;
|
||||
|
||||
public UpdateSpringBoneJobScheduler(RootBoneRegistry rootBoneRegistry)
|
||||
{
|
||||
_rootBoneRegistry = rootBoneRegistry;
|
||||
|
||||
_rootBoneRegistry.SubscribeOnValueChanged(OnRootBoneChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ReleaseBuffer();
|
||||
_rootBoneRegistry.UnSubscribeOnValueChanged(OnRootBoneChanged);
|
||||
}
|
||||
|
||||
private void OnRootBoneChanged()
|
||||
{
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public JobHandle Schedule(JobHandle dependOn = default(JobHandle))
|
||||
{
|
||||
if (Targets.Count == 0)
|
||||
{
|
||||
return dependOn;
|
||||
}
|
||||
|
||||
_sampler.Begin();
|
||||
|
||||
// リストが変更されていたらバッファを再構築
|
||||
if (_dirty)
|
||||
{
|
||||
ReconstructBuffers();
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
// Jobを発火
|
||||
var job = new Job { RootBonePointers = _rootBonePointers, DeltaTime = Time.deltaTime };
|
||||
var jobHandle = job.Schedule(Targets.Count, 0, dependOn);
|
||||
|
||||
_sampler.End();
|
||||
|
||||
return jobHandle;
|
||||
}
|
||||
|
||||
private void ReconstructBuffers()
|
||||
{
|
||||
ReleaseBuffer();
|
||||
|
||||
_rootBonePointers = (BlittableRootBone**)UnsafeUtility.Malloc(
|
||||
sizeof(BlittableTransform*) * Targets.Count,
|
||||
16,
|
||||
Allocator.Persistent
|
||||
);
|
||||
|
||||
for (var i = 0; i < Targets.Count; i++)
|
||||
{
|
||||
_rootBonePointers[i] = Targets[i].GetUnsafePtr();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseBuffer()
|
||||
{
|
||||
if (_rootBonePointers == null) return;
|
||||
UnsafeUtility.Free(_rootBonePointers, Allocator.Persistent);
|
||||
_rootBonePointers = null;
|
||||
}
|
||||
|
||||
#if ENABLE_SPRINGBONE_BURST
|
||||
[BurstCompile]
|
||||
#endif
|
||||
private struct Job : IJobParallelFor
|
||||
{
|
||||
[NativeDisableUnsafePtrRestriction] public BlittableRootBone** RootBonePointers;
|
||||
public float DeltaTime;
|
||||
|
||||
public void Execute(int index)
|
||||
{
|
||||
// 各点を更新する
|
||||
RootBonePointers[index]->Update(DeltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39839e9c65fc7a54abacaadf2d519fbf
|
||||
timeCreated: 1549516763
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6633497ce721ce4c81d514187ef4407
|
||||
guid: af417d77d895bc84ba5d2c8f0542bdd8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using UnityEngine.Jobs;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
[BurstCompile]
|
||||
public struct PullTransformJob : IJobParallelForTransform
|
||||
{
|
||||
[WriteOnly] public NativeArray<BlittableTransform> Transforms;
|
||||
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
Transforms[index] = new BlittableTransform
|
||||
{
|
||||
Position = transform.position,
|
||||
Rotation = transform.rotation,
|
||||
LocalPosition = transform.localPosition,
|
||||
LocalRotation = transform.localRotation,
|
||||
LocalScale = transform.localScale,
|
||||
LocalToWorldMatrix = transform.localToWorldMatrix,
|
||||
WorldToLocalMatrix = transform.worldToLocalMatrix
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9fd53b4431b41909c1b1d882a2d446b
|
||||
timeCreated: 1633072084
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Collections;
|
||||
using UnityEngine.Jobs;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
public sealed class FastSpringBoneBuffers : IDisposable
|
||||
{
|
||||
private NativeArray<BlittableSpring> _springs;
|
||||
|
||||
private NativeArray<BlittableJoint> _joints;
|
||||
private NativeArray<BlittableTransform> _jointTransforms;
|
||||
private TransformAccessArray _jointsTransformAccessArray;
|
||||
|
||||
private NativeArray<BlittableCollider> _colliders;
|
||||
private NativeArray<BlittableTransform> _colliderTransforms;
|
||||
private TransformAccessArray _colliderTransformAccessArray;
|
||||
|
||||
public NativeArray<BlittableSpring> Springs => _springs;
|
||||
|
||||
public NativeArray<BlittableJoint> Joints => _joints;
|
||||
public NativeArray<BlittableTransform> JointTransforms => _jointTransforms;
|
||||
public TransformAccessArray JointsTransformAccessArray => _jointsTransformAccessArray;
|
||||
|
||||
public NativeArray<BlittableCollider> Colliders => _colliders;
|
||||
public NativeArray<BlittableTransform> ColliderTransforms => _colliderTransforms;
|
||||
public TransformAccessArray ColliderTransformAccessArray => _colliderTransformAccessArray;
|
||||
|
||||
public FastSpringBoneBuffers(IReadOnlyList<FastSpringBoneSpring> springs)
|
||||
{
|
||||
_springs = new NativeArray<BlittableSpring>(springs.Count, Allocator.Persistent);
|
||||
|
||||
// _springsを構築しつつ、joints, collidersの総数を数える
|
||||
ConstructBlittableSprings(springs, out var jointsCount, out var collidersCount);
|
||||
|
||||
// 各種bufferの初期化
|
||||
_joints = new NativeArray<BlittableJoint>(jointsCount, Allocator.Persistent);
|
||||
_jointTransforms = new NativeArray<BlittableTransform>(jointsCount, Allocator.Persistent);
|
||||
_jointsTransformAccessArray = new TransformAccessArray(jointsCount);
|
||||
|
||||
_colliders = new NativeArray<BlittableCollider>(collidersCount, Allocator.Persistent);
|
||||
_colliderTransforms = new NativeArray<BlittableTransform>(collidersCount, Allocator.Persistent);
|
||||
_colliderTransformAccessArray = new TransformAccessArray(collidersCount);
|
||||
|
||||
// 各種bufferの構築
|
||||
var jointIndex = 0;
|
||||
var colliderIndex = 0;
|
||||
foreach (var spring in springs)
|
||||
{
|
||||
foreach (var joint in spring.Joints)
|
||||
{
|
||||
var parent = joint.Transform.parent;
|
||||
|
||||
_joints[jointIndex] = joint.Joint;
|
||||
_jointsTransformAccessArray.Add(joint.Transform);
|
||||
_jointTransforms[jointIndex] = new BlittableTransform();
|
||||
++jointIndex;
|
||||
}
|
||||
|
||||
foreach (var collider in spring.Colliders)
|
||||
{
|
||||
var parent = collider.Transform.parent;
|
||||
|
||||
_colliders[colliderIndex] = collider.Collider;
|
||||
_colliderTransformAccessArray.Add(collider.Transform);
|
||||
_colliderTransforms[colliderIndex] = new BlittableTransform();
|
||||
++colliderIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// _springsを構築しつつ、joints, collidersの総数を数える
|
||||
/// </summary>
|
||||
private void ConstructBlittableSprings(IReadOnlyList<FastSpringBoneSpring> springs, out int jointsCount,
|
||||
out int collidersCount)
|
||||
{
|
||||
jointsCount = 0;
|
||||
collidersCount = 0;
|
||||
for (var i = 0; i < springs.Count; i++)
|
||||
{
|
||||
var spring = springs[i];
|
||||
var blittableSpring = new BlittableSpring();
|
||||
|
||||
blittableSpring.JointSpan.StartIndex = jointsCount;
|
||||
blittableSpring.ColliderSpan.StartIndex = jointsCount;
|
||||
blittableSpring.JointSpan.Count = spring.Joints.Length;
|
||||
blittableSpring.ColliderSpan.Count = spring.Colliders.Length;
|
||||
_springs[i] = blittableSpring;
|
||||
|
||||
jointsCount += spring.Joints.Length;
|
||||
collidersCount += spring.Colliders.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_springs.Dispose();
|
||||
_joints.Dispose();
|
||||
_jointTransforms.Dispose();
|
||||
_jointsTransformAccessArray.Dispose();
|
||||
_colliders.Dispose();
|
||||
_colliderTransforms.Dispose();
|
||||
_colliderTransformAccessArray.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b0299bf5bfe431e8e18a9b033b719a3
|
||||
timeCreated: 1633072502
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine.Jobs;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
public sealed class FastSpringBoneScheduler : IDisposable
|
||||
{
|
||||
private readonly FastSpringBoneBuffers _fastSpringBoneBuffers;
|
||||
|
||||
public FastSpringBoneScheduler(IReadOnlyList<FastSpringBoneSpring> springs)
|
||||
{
|
||||
_fastSpringBoneBuffers = new FastSpringBoneBuffers(springs);
|
||||
}
|
||||
|
||||
public void Schedule()
|
||||
{
|
||||
var handle = JobHandle.CombineDependencies(
|
||||
new PullTransformJob
|
||||
{
|
||||
Transforms = _fastSpringBoneBuffers.ColliderTransforms
|
||||
}.Schedule(_fastSpringBoneBuffers.ColliderTransformAccessArray),
|
||||
new PullTransformJob
|
||||
{
|
||||
Transforms = _fastSpringBoneBuffers.JointTransforms
|
||||
}.Schedule(_fastSpringBoneBuffers.JointsTransformAccessArray));
|
||||
|
||||
handle = JobHandle.CombineDependencies(
|
||||
new PushTransformJob()
|
||||
{
|
||||
Transforms = _fastSpringBoneBuffers.ColliderTransforms
|
||||
}.Schedule(_fastSpringBoneBuffers.ColliderTransformAccessArray, handle),
|
||||
new PushTransformJob()
|
||||
{
|
||||
Transforms = _fastSpringBoneBuffers.JointTransforms
|
||||
}.Schedule(_fastSpringBoneBuffers.JointsTransformAccessArray, handle));
|
||||
|
||||
|
||||
handle.Complete();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_fastSpringBoneBuffers.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 897b4e814c0b5dc4d8d1f8a859ef746b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
public sealed class FastSpringBoneTest : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private FastSpringBoneSpring[] springs;
|
||||
|
||||
private FastSpringBoneScheduler _scheduler;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_scheduler = new FastSpringBoneScheduler(springs);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
_scheduler.Schedule();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_scheduler.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13e3ed9705fb4aca9601f6dc764830d9
|
||||
timeCreated: 1633073221
|
||||
@@ -0,0 +1,19 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using UnityEngine.Jobs;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
|
||||
namespace UniVRM10.FastSpringBones.System
|
||||
{
|
||||
[BurstCompile]
|
||||
public struct PushTransformJob : IJobParallelForTransform
|
||||
{
|
||||
[ReadOnly]
|
||||
public NativeArray<BlittableTransform> Transforms;
|
||||
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
transform.localRotation = Transforms[index].LocalRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd0a0bfba0ec4bc6b050527b92d4decf
|
||||
timeCreated: 1633075989
|
||||
Reference in New Issue
Block a user