Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.45 KB | None | 0 0
  1. diff --git a/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs b/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs
  2. index ec278c5..ffe47ee 100644
  3. --- a/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs
  4. +++ b/Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs
  5. @@ -582,13 +582,12 @@ and have a low memory footprint because of their smaller size to describe the sa
  6.         }
  7.  
  8.         public static void UpdateArea (GraphUpdateObject o, INavmesh graph) {
  9. -
  10. -           //System.DateTime startTime = System.DateTime.UtcNow;
  11. -
  12.             Bounds bounds = o.bounds;
  13.  
  14. +           // Bounding rectangle with floating point coordinates
  15.             Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);
  16.  
  17. +           // Bounding rectangle with int coordinates
  18.             var r2 = new IntRect(
  19.                 Mathf.FloorToInt(bounds.min.x*Int3.Precision),
  20.                 Mathf.FloorToInt(bounds.min.z*Int3.Precision),
  21. @@ -596,11 +595,16 @@ and have a low memory footprint because of their smaller size to describe the sa
  22.                 Mathf.FloorToInt(bounds.max.z*Int3.Precision)
  23.             );
  24.  
  25. +           // Corners of the bounding rectangle
  26.             var a = new Int3(r2.xmin,0,r2.ymin);
  27.             var b = new Int3(r2.xmin,0,r2.ymax);
  28.             var c = new Int3(r2.xmax,0,r2.ymin);
  29.             var d = new Int3(r2.xmax,0,r2.ymax);
  30.  
  31. +           var ymin = ((Int3)bounds.min).y;
  32. +           var ymax = ((Int3)bounds.min).y;
  33. +
  34. +           // Loop through all nodes
  35.             graph.GetNodes (_node => {
  36.                 var node = _node as TriangleMeshNode;
  37.  
  38. @@ -611,8 +615,8 @@ and have a low memory footprint because of their smaller size to describe the sa
  39.                 int allTop = 0;
  40.                 int allBottom = 0;
  41.  
  42. +               // Check bounding box rect in XZ plane
  43.                 for (int v=0;v<3;v++) {
  44. -
  45.                     Int3 p = node.GetVertex(v);
  46.                     var vert = (Vector3)p;
  47.  
  48. @@ -626,13 +630,15 @@ and have a low memory footprint because of their smaller size to describe the sa
  49.                     if (vert.z < r.yMin) allTop++;
  50.                     if (vert.z > r.yMax) allBottom++;
  51.                 }
  52. +
  53.                 if (!inside) {
  54.                     if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
  55.                         return true;
  56.                     }
  57.                 }
  58.  
  59. -               for (int v=0;v<3;v++) {
  60. +               // Check if the polygon edges intersect the bounding rect
  61. +               for (int v = 0; v < 3; v++) {
  62.                     int v2 = v > 1 ? 0 : v+1;
  63.  
  64.                     Int3 vert1 = node.GetVertex(v);
  65. @@ -644,7 +650,8 @@ and have a low memory footprint because of their smaller size to describe the sa
  66.                     if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
  67.                 }
  68.  
  69. -               if (node.ContainsPoint (a) || node.ContainsPoint (b) || node.ContainsPoint (c) || node.ContainsPoint (d)) {
  70. +               // Check if the node contains any corner of the bounding rect
  71. +               if (inside || node.ContainsPoint (a) || node.ContainsPoint (b) || node.ContainsPoint (c) || node.ContainsPoint (d)) {
  72.                     inside = true;
  73.                 }
  74.  
  75. @@ -652,6 +659,22 @@ and have a low memory footprint because of their smaller size to describe the sa
  76.                     return true;
  77.                 }
  78.  
  79. +               int allAbove = 0;
  80. +               int allBelow = 0;
  81. +
  82. +               // Check y coordinate
  83. +               for (int v = 0; v < 3; v++) {
  84. +                   Int3 p = node.GetVertex(v);
  85. +                   var vert = (Vector3)p;
  86. +                   if (vert.y < ymin) allBelow++;
  87. +                   if (vert.y > ymax) allAbove++;
  88. +               }
  89. +
  90. +               // Polygon is either completely above the bounding box or completely below it
  91. +               if (allBelow == 3 || allAbove == 3) return true;
  92. +
  93. +               // Triangle is inside the bounding box!
  94. +               // Update it!
  95.                 o.WillUpdateNode(node);
  96.                 o.Apply (node);
  97.                 return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement