Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.91 KB | None | 0 0
  1. From 855366c72b9c563cff262f879acc7fbc6e2663db Mon Sep 17 00:00:00 2001
  2. From: Aron Granberg <aron.granberg@gmail.com>
  3. Date: Mon, 18 Jan 2016 22:58:26 +0100
  4. Subject: [PATCH 1/2] Fixed objects being rasterized 0.5 voxels from where they
  5.  should be rasterized.
  6.  
  7. ---
  8. .../Generators/Utilities/Voxels/VoxelRasterization.cs     | 15 ++++++++-------
  9.  1 file changed, 8 insertions(+), 7 deletions(-)
  10.  
  11. diff --git a/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs b/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs
  12. index 42113f4..d8ada90 100644
  13. --- a/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs
  14. +++ b/Assets/AstarPathfindingProject/Generators/Utilities/Voxels/VoxelRasterization.cs
  15. @@ -73,13 +73,13 @@ namespace Pathfinding.Voxels {
  16.         public Vector3 voxelOffset;
  17.  
  18.         public Vector3 CompactSpanToVector (int x, int z, int i) {
  19. -           return voxelOffset+new Vector3(x*cellSize, voxelArea.compactSpans[i].y*cellHeight, z*cellSize);
  20. +           return voxelOffset+new Vector3((x+0.5f)*cellSize, voxelArea.compactSpans[i].y*cellHeight, (z+0.5f)*cellSize);
  21.         }
  22.  
  23.         public void VectorToIndex (Vector3 p, out int x, out int z) {
  24.             p -= voxelOffset;
  25. -           x = Mathf.RoundToInt(p.x / cellSize);
  26. -           z = Mathf.RoundToInt(p.z / cellSize);
  27. +           x = Mathf.RoundToInt((p.x / cellSize) - 0.5f);
  28. +           z = Mathf.RoundToInt((p.z / cellSize) - 0.5f);
  29.         }
  30.  
  31.         #endregion
  32. @@ -164,12 +164,10 @@ namespace Pathfinding.Voxels {
  33.  
  34.             AstarProfiler.StartProfile("Voxelizing - Step 1");
  35.  
  36. -
  37. -           //Debug.DrawLine (forcedBounds.min,forcedBounds.max,Color.blue);
  38. -
  39.             Vector3 min = forcedBounds.min;
  40.             voxelOffset = min;
  41.  
  42. +           // Scale factor from world space to voxel space
  43.             float ics = 1F/cellSize;
  44.             float ich = 1F/cellHeight;
  45.  
  46. @@ -179,6 +177,7 @@ namespace Pathfinding.Voxels {
  47.  
  48.             float slopeLimit = Mathf.Cos(Mathf.Atan(Mathf.Tan(maxSlope*Mathf.Deg2Rad)*(ich*cellSize)));
  49.  
  50. +           // Temporary arrays used for rasterization
  51.             float[] vTris = new float[3*3];
  52.             float[] vOut = new float[7*3];
  53.             float[] vRow = new float[7*3];
  54. @@ -197,7 +196,9 @@ namespace Pathfinding.Voxels {
  55.             //Create buffer, here vertices will be stored multiplied with the local-to-voxel-space matrix
  56.             Vector3[] verts = new Vector3[maxVerts];
  57.  
  58. -           Matrix4x4 voxelMatrix = Matrix4x4.Scale(new Vector3(ics, ich, ics)) * Matrix4x4.TRS(-min, Quaternion.identity, Vector3.one);
  59. +           // First subtract min, then scale to voxel space (one unit equals one voxel along the x and z axes)
  60. +           // then subtract half a voxel to fix rounding
  61. +           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);
  62.  
  63.             AstarProfiler.EndProfile("Voxelizing - Step 2 - Init");
  64.             AstarProfiler.StartProfile("Voxelizing - Step 2");
  65. --
  66. 2.6.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement