BlittableJointImmutableの最適化

This commit is contained in:
AoiKamishiro
2025-06-30 00:53:51 +09:00
parent 24f5b10a63
commit e1bded5bd0
2 changed files with 31 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Unity.Mathematics;
using UnityEngine;
namespace UniGLTF.SpringBoneJobs.Blittables
@@ -9,15 +10,31 @@ namespace UniGLTF.SpringBoneJobs.Blittables
/// 変わりにくいスコープ。
/// </summary>
[Serializable]
public struct BlittableJointImmutable
public readonly struct BlittableJointImmutable
{
public int parentTransformIndex;
public int headTransformIndex;
public int tailTransformIndex;
public float length;
public Quaternion localRotation;
public Vector3 boneAxis;
private readonly float4x3 _data;
public int parentTransformIndex => (int)_data.c2.x;
public int headTransformIndex => (int)_data.c2.y;
public int tailTransformIndex => (int)_data.c2.z;
public float length => _data.c2.w;
public quaternion localRotation => _data.c0;
public float3 boneAxis => _data.c1.xyz;
public BlittableJointImmutable(
int parentTransformIndex = 0,
int headTransformIndex = 0,
int tailTransformIndex = 0,
float length = 0,
quaternion localRotation = default,
float3 boneAxis = default)
{
var c0 = localRotation.value;
var c1 = new float4(boneAxis, 0);
var c2 = new float4(parentTransformIndex, headTransformIndex, tailTransformIndex, length);
_data = new float4x3(c0, c1, c2);
}
public void DrawGizmo(BlittableTransform t, BlittableJointMutable m)
{
Gizmos.matrix = t.localToWorldMatrix;

View File

@@ -129,15 +129,13 @@ namespace UniGLTF.SpringBoneJobs.InputPorts
localPosition.z * scale.z
);
yield return new BlittableJointImmutable
{
headTransformIndex = Array.IndexOf<Transform>(Transforms, joint.Transform),
parentTransformIndex = Array.IndexOf<Transform>(Transforms, joint.Transform.parent),
tailTransformIndex = Array.IndexOf<Transform>(Transforms, tailJoint.Transform),
localRotation = joint.DefaultLocalRotation,
boneAxis = localChildPosition.normalized,
length = localChildPosition.magnitude
};
yield return new BlittableJointImmutable(
headTransformIndex: Array.IndexOf<Transform>(Transforms, joint.Transform),
parentTransformIndex: Array.IndexOf<Transform>(Transforms, joint.Transform.parent),
tailTransformIndex: Array.IndexOf<Transform>(Transforms, tailJoint.Transform),
localRotation: joint.DefaultLocalRotation,
boneAxis: localChildPosition.normalized,
length: localChildPosition.magnitude);
}
}