CapersProject/Packages/com.arongranberg.astar/Graphs/Navmesh/Jobs/JobTransformTileCoordinates.cs

31 lines
1.0 KiB
C#
Raw Normal View History

2024-11-28 23:07:50 +00:00
using Pathfinding.Util;
using Pathfinding.Collections;
2024-06-03 18:26:03 +00:00
using Unity.Burst;
using Unity.Jobs;
using UnityEngine;
namespace Pathfinding.Graphs.Navmesh.Jobs {
/// <summary>
/// Transforms vertices from voxel coordinates to tile coordinates.
///
/// This essentially constitutes multiplying the vertices by the <see cref="matrix"/>.
///
/// Note: The input space is in raw voxel coordinates, the output space is in tile coordinates stored in millimeters (as is typical for the Int3 struct. See <see cref="Int3.Precision"/>).
/// </summary>
[BurstCompile(FloatMode = FloatMode.Fast)]
public struct JobTransformTileCoordinates : IJob {
2024-11-28 23:07:50 +00:00
public unsafe UnsafeSpan<Int3> vertices;
2024-06-03 18:26:03 +00:00
public Matrix4x4 matrix;
public void Execute () {
unsafe {
2024-11-28 23:07:50 +00:00
for (uint i = 0; i < vertices.length; i++) {
2024-06-03 18:26:03 +00:00
// Transform from voxel indices to a proper Int3 coordinate, then convert it to a Vector3 float coordinate
2024-11-28 23:07:50 +00:00
var p = vertices[i];
vertices[i] = (Int3)matrix.MultiplyPoint3x4(new Vector3(p.x, p.y, p.z));
2024-06-03 18:26:03 +00:00
}
}
}
}
}