Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 855366c72b9c563cff262f879acc7fbc6e2663db Mon Sep 17 00:00:00 2001
- From: Aron Granberg <aron.granberg@gmail.com>
- Date: Mon, 18 Jan 2016 22:58:26 +0100
- Subject: [PATCH 1/2] Fixed objects being rasterized 0.5 voxels from where they
- should be rasterized.
- ---
- .../Generators/Utilities/Voxels/VoxelRasterization.cs | 15 ++++++++-------
- 1 file changed, 8 insertions(+), 7 deletions(-)
- diff --git a/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs b/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs
- index 42113f4..d8ada90 100644
- --- a/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs
- +++ b/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs
- @@ -73,13 +73,13 @@ namespace Pathfinding.Voxels {
- public Vector3 voxelOffset;
- public Vector3 CompactSpanToVector (int x, int z, int i) {
- - return voxelOffset+new Vector3(x*cellSize, voxelArea.compactSpans[i].y*cellHeight, z*cellSize);
- + return voxelOffset+new Vector3((x+0.5f)*cellSize, voxelArea.compactSpans[i].y*cellHeight, (z+0.5f)*cellSize);
- }
- public void VectorToIndex (Vector3 p, out int x, out int z) {
- p -= voxelOffset;
- - x = Mathf.RoundToInt(p.x / cellSize);
- - z = Mathf.RoundToInt(p.z / cellSize);
- + x = Mathf.RoundToInt((p.x / cellSize) - 0.5f);
- + z = Mathf.RoundToInt((p.z / cellSize) - 0.5f);
- }
- #endregion
- @@ -164,12 +164,10 @@ namespace Pathfinding.Voxels {
- AstarProfiler.StartProfile("Voxelizing - Step 1");
- -
- - //Debug.DrawLine (forcedBounds.min,forcedBounds.max,Color.blue);
- -
- Vector3 min = forcedBounds.min;
- voxelOffset = min;
- + // Scale factor from world space to voxel space
- float ics = 1F/cellSize;
- float ich = 1F/cellHeight;
- @@ -179,6 +177,7 @@ namespace Pathfinding.Voxels {
- float slopeLimit = Mathf.Cos(Mathf.Atan(Mathf.Tan(maxSlope*Mathf.Deg2Rad)*(ich*cellSize)));
- + // Temporary arrays used for rasterization
- float[] vTris = new float[3*3];
- float[] vOut = new float[7*3];
- float[] vRow = new float[7*3];
- @@ -197,7 +196,9 @@ namespace Pathfinding.Voxels {
- //Create buffer, here vertices will be stored multiplied with the local-to-voxel-space matrix
- Vector3[] verts = new Vector3[maxVerts];
- - Matrix4x4 voxelMatrix = Matrix4x4.Scale(new Vector3(ics, ich, ics)) * Matrix4x4.TRS(-min, Quaternion.identity, Vector3.one);
- + // First subtract min, then scale to voxel space (one unit equals one voxel along the x and z axes)
- + // then subtract half a voxel to fix rounding
- + Matrix4x4 voxelMatrix = Matrix4x4.TRS(-new Vector3(0.5f, 0, 0.5f), Quaternion.identity, Vector3.one) * Matrix4x4.Scale(new Vector3(ics, ich, ics)) * Matrix4x4.TRS(-min, Quaternion.identity, Vector3.one);
- AstarProfiler.EndProfile("Voxelizing - Step 2 - Init");
- AstarProfiler.StartProfile("Voxelizing - Step 2");
- --
- 2.6.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement