Created
March 30, 2025 22:11
-
-
Save wallstop/8587e4efd096554d50018061d969b5a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private struct Job : IJobParallelFor | |
| { | |
| [NativeDisableParallelForRestriction] | |
| private NativeArray<float3> _vertices; | |
| [ReadOnly] | |
| private NativeArray<CharData> _data; | |
| private readonly NativeCurve _curve; | |
| private readonly TransformType _type; | |
| private readonly float3 _intensity; | |
| private readonly float2 _pivot; | |
| private readonly float _progress; | |
| private readonly float3 _maskedIntensity; | |
| public Job( | |
| NativeArray<float3> vertices, | |
| NativeArray<CharData> data, | |
| NativeCurve curve, | |
| float3 intensity, | |
| float2 pivot, | |
| TransformType type, | |
| float progress | |
| ) | |
| { | |
| _vertices = vertices; | |
| _data = data; | |
| _curve = curve; | |
| _type = type; | |
| _intensity = intensity; | |
| _pivot = pivot; | |
| _progress = progress; | |
| _maskedIntensity = new float3( | |
| MaskZeroToOne(intensity.x), | |
| MaskZeroToOne(intensity.y), | |
| MaskZeroToOne(intensity.z) | |
| ); | |
| } | |
| public void Execute(int index) | |
| { | |
| CharData characterData = _data[index]; | |
| int vertexOffset = characterData.VertexIndex; | |
| float3 offset = Offset(_vertices, vertexOffset, _pivot); | |
| float p = _curve.Evaluate(Remap(_progress, characterData.Interval)); | |
| float4x4 m = GetTransformation(p); | |
| for (int i = 0; i < characterData.VertexCount; i++) | |
| { | |
| _vertices[vertexOffset + i] -= offset; | |
| _vertices[vertexOffset + i] = math.mul( | |
| m, | |
| new float4(_vertices[vertexOffset + i], 1) | |
| ).xyz; | |
| _vertices[vertexOffset + i] += offset; | |
| } | |
| } | |
| private float4x4 GetTransformation(float progress) | |
| { | |
| float3 fp = float3.zero; | |
| quaternion fr = quaternion.identity; | |
| float3 fs = 1; | |
| switch (_type) | |
| { | |
| case TransformType.Position: | |
| fp = _intensity * progress; | |
| break; | |
| case TransformType.Rotation: | |
| fr = quaternion.Euler(math.radians(_intensity * progress)); | |
| break; | |
| case TransformType.Scale: | |
| fs = _maskedIntensity * progress; | |
| break; | |
| default: | |
| return float4x4.identity; | |
| } | |
| return float4x4.TRS(fp, fr, fs); | |
| } | |
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| private static float MaskZeroToOne(float value) | |
| { | |
| int bits = Unsafe.As<float, int>(ref value); | |
| // If bits == 0, set to bits of 1.0f (which is 0x3F800000) | |
| // Otherwise, keep as-is | |
| int masked = bits | ((bits == 0) ? 0x3F800000 : 0); | |
| return Unsafe.As<int, float>(ref masked); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment