mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-29 06:13:21 -05:00
BlittableJointImmutableの最適化
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user