diff --git a/Assets/UniGLTF/Runtime/SpringBoneJobs/Blittables/BlittableCollider.cs b/Assets/UniGLTF/Runtime/SpringBoneJobs/Blittables/BlittableCollider.cs index 9bacf616d..119b4712e 100644 --- a/Assets/UniGLTF/Runtime/SpringBoneJobs/Blittables/BlittableCollider.cs +++ b/Assets/UniGLTF/Runtime/SpringBoneJobs/Blittables/BlittableCollider.cs @@ -1,4 +1,5 @@ using System; +using Unity.Mathematics; using UnityEngine; namespace UniGLTF.SpringBoneJobs.Blittables @@ -7,15 +8,35 @@ namespace UniGLTF.SpringBoneJobs.Blittables /// Blittableなコライダ /// [Serializable] - public struct BlittableCollider + public readonly struct BlittableCollider { - public BlittableColliderType colliderType; - public Vector3 offset; - public float radius; - // capsule tail or plane normal - public Vector3 tailOrNormal; - public int transformIndex; + private readonly float3x3 _data; + public BlittableColliderType colliderType => (BlittableColliderType)(int)_data.c2.y; + public float3 offset => _data.c0; + public float radius => _data.c2.x; + // capsule tail or plane normal + public float3 tailOrNormal => _data.c1; + public int transformIndex => (int)_data.c2.z; + + public BlittableCollider( + float3 offset = default, + float radius = 0, + float3 tailOrNormal = default, + BlittableColliderType colliderType = default, + int colliderTransformIndex = 0) + { + var c0 = offset; + var c1 = tailOrNormal; + var c2 = new float3(radius,(int)colliderType, colliderTransformIndex); + _data = new float3x3(c0, c1, c2); + } + + public BlittableCollider SetTransformIndex(int index) + { + return new BlittableCollider(offset, radius, tailOrNormal, colliderType, index); + } + public void DrawGizmo(BlittableTransform t) { Gizmos.matrix = t.localToWorldMatrix; diff --git a/Assets/UniGLTF/Runtime/SpringBoneJobs/InputPorts/FastSpringBoneBuffer.cs b/Assets/UniGLTF/Runtime/SpringBoneJobs/InputPorts/FastSpringBoneBuffer.cs index f420ed10e..5822c248f 100644 --- a/Assets/UniGLTF/Runtime/SpringBoneJobs/InputPorts/FastSpringBoneBuffer.cs +++ b/Assets/UniGLTF/Runtime/SpringBoneJobs/InputPorts/FastSpringBoneBuffer.cs @@ -86,8 +86,8 @@ namespace UniGLTF.SpringBoneJobs.InputPorts blittableColliders.AddRange(spring.colliders.Select(collider => { var blittable = collider.Collider; - blittable.transformIndex = Array.IndexOf(Transforms, collider.Transform); - return blittable; + var transformIndex = Array.IndexOf(Transforms, collider.Transform); + return blittable.SetTransformIndex(transformIndex); })); blittableJoints.AddRange(spring.joints .Take(spring.joints.Length - 1).Select(joint => diff --git a/Assets/VRM/Runtime/SpringBone/Jobs/FastSpringBoneReplacer.cs b/Assets/VRM/Runtime/SpringBone/Jobs/FastSpringBoneReplacer.cs index 58d6192b6..270658005 100644 --- a/Assets/VRM/Runtime/SpringBone/Jobs/FastSpringBoneReplacer.cs +++ b/Assets/VRM/Runtime/SpringBone/Jobs/FastSpringBoneReplacer.cs @@ -40,13 +40,10 @@ namespace VRM.SpringBoneJobs var c = new FastSpringBoneCollider { Transform = group.transform, - Collider = new BlittableCollider - { - offset = collider.Offset, - radius = collider.Radius, - tailOrNormal = default, - colliderType = BlittableColliderType.Sphere - } + Collider = new BlittableCollider( + offset: collider.Offset, + radius: collider.Radius, + colliderType: BlittableColliderType.Sphere) }; colliders.Add(c); } diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/FastSpringBoneBufferFactory.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/FastSpringBoneBufferFactory.cs index f176a5e19..ce1fa24c5 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/FastSpringBoneBufferFactory.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/FastSpringBoneBufferFactory.cs @@ -49,13 +49,11 @@ namespace UniVRM10 .Select(collider => new FastSpringBoneCollider { Transform = collider.transform, - Collider = new BlittableCollider - { - offset = collider.Offset, - radius = collider.Radius, - tailOrNormal = collider.TailOrNormal, - colliderType = TranslateColliderType(collider.ColliderType) - } + Collider = new BlittableCollider( + offset: collider.Offset, + radius: collider.Radius, + tailOrNormal: collider.TailOrNormal, + colliderType: TranslateColliderType(collider.ColliderType)) }).ToArray(), joints = spring.Joints .Select(joint => new FastSpringBoneJoint diff --git a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs index e4461c273..8e2181786 100644 --- a/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs +++ b/Assets/VRM10_Samples/ClothSample/ClothWarp/Runtime/Jobs/ClothWarpJobRuntime.cs @@ -193,14 +193,12 @@ namespace UniVRM10.ClothWarp.Jobs var colliderTransformIndex = GetOrAddColliderTransform(collider.transform); colliderRef.Add(colliderInfo.Count); - colliderInfo.Add(new BlittableCollider - { - offset = collider.Offset, - radius = collider.Radius, - tailOrNormal = collider.TailOrNormal, - colliderType = TranslateColliderType(collider.ColliderType), - transformIndex = colliderTransformIndex, - }); + colliderInfo.Add(new BlittableCollider( + offset: collider.Offset, + radius: collider.Radius, + tailOrNormal: collider.TailOrNormal, + colliderType: TranslateColliderType(collider.ColliderType), + colliderTransformIndex: colliderTransformIndex)); _colliders.Add(collider); }