RecastBBTreeBox RemoveBox (RecastBBTreeBox c, RecastMeshObj mesh, Rect bounds, ref bool found) { if (!RectIntersectsRect (c.rect,bounds)) { return c; } if (c.mesh == mesh) { found = true; return null; } if (c.mesh == null && !found) { c.c1 = RemoveBox (c.c1, mesh, bounds, ref found); if (c.c1 == null) { return c.c2; } if (!found) { c.c2 = RemoveBox (c.c2, mesh, bounds, ref found); if (c.c2 == null) { return c.c1; } } if (found) { c.rect = ExpandToContain (c.c1.rect, c.c2.rect); } } return c; }
private RecastBBTreeBox RemoveBox(RecastBBTreeBox c, RecastMeshObj mesh, Rect bounds, ref bool found) { if (!RecastBBTree.RectIntersectsRect(c.rect, bounds)) { return(c); } if (c.mesh == mesh) { found = true; return(null); } if (c.mesh == null && !found) { c.c1 = this.RemoveBox(c.c1, mesh, bounds, ref found); if (c.c1 == null) { return(c.c2); } if (!found) { c.c2 = this.RemoveBox(c.c2, mesh, bounds, ref found); if (c.c2 == null) { return(c.c1); } } if (found) { c.rect = RecastBBTree.ExpandToContain(c.c1.rect, c.c2.rect); } } return(c); }
// Token: 0x06002630 RID: 9776 RVA: 0x001A56FC File Offset: 0x001A38FC public RecastBBTreeBox(RecastMeshObj mesh) { this.mesh = mesh; Vector3 min = mesh.bounds.min; Vector3 max = mesh.bounds.max; this.rect = Rect.MinMaxRect(min.x, min.z, max.x, max.z); }
/** Inserts a mesh node in the tree */ public void Insert(RecastMeshObj mesh) { RecastBBTreeBox box = new RecastBBTreeBox(this, mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain(c.rect, box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; RecastBBTreeBox box2 = new RecastBBTreeBox(this, c.mesh); //Console.WriteLine ("Inserted "+box.node+", rect "+box.rect.ToString ()); c.c2 = box2; c.mesh = null; //c.rect = c.rect. return; } else { float e1 = ExpansionRequired(c.c1.rect, box.rect); float e2 = ExpansionRequired(c.c2.rect, box.rect); //Choose the rect requiring the least expansion to contain box.rect if (e1 < e2) { c = c.c1; } else if (e2 < e1) { c = c.c2; } else { //Equal, Choose the one with the smallest area c = RectArea(c.c1.rect) < RectArea(c.c2.rect) ? c.c1 : c.c2; } } } }
/// <summary>Inserts a RecastMeshObj in the tree at its current position</summary> public void Insert(RecastMeshObj mesh) { var box = new RecastBBTreeBox(mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain(c.rect, box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; var box2 = new RecastBBTreeBox(c.mesh); c.c2 = box2; c.mesh = null; return; } else { float e1 = ExpansionRequired(c.c1.rect, box.rect); float e2 = ExpansionRequired(c.c2.rect, box.rect); // Choose the rect requiring the least expansion to contain box.rect if (e1 < e2) { c = c.c1; } else if (e2 < e1) { c = c.c2; } else { // Equal, Choose the one with the smallest area c = RectArea(c.c1.rect) < RectArea(c.c2.rect) ? c.c1 : c.c2; } } } }
/** Removes the specified mesh from the tree. * Assumes that it has the correct bounds information. * * \returns True if the mesh was removed from the tree, false otherwise. */ public bool Remove (RecastMeshObj mesh) { if (mesh == null) throw new ArgumentNullException("mesh"); if (root == null) { return false; } bool found = false; Bounds b = mesh.GetBounds(); //Convert to top down rect Rect r = Rect.MinMaxRect(b.min.x, b.min.z, b.max.x, b.max.z); root = RemoveBox(root, mesh, r, ref found); return found; }
public bool Remove(RecastMeshObj mesh) { if (mesh == null) { throw new ArgumentNullException("mesh"); } if (this.root == null) { return(false); } bool result = false; Bounds bounds = mesh.GetBounds(); Rect bounds2 = Rect.MinMaxRect(bounds.min.x, bounds.min.z, bounds.max.x, bounds.max.z); this.root = this.RemoveBox(this.root, mesh, bounds2, ref result); return(result); }
/*public void SearchBoxCircle (BBTreeBox box, Vector3 p, float radius, NNConstraint constraint, ref NNInfo nnInfo) {//, int intendentLevel = 0) { * * if (box.node != null) { * //Leaf node * if (NodeIntersectsCircle (box.node,p,radius)) { * //Update the NNInfo * #if ASTARDEBUG * Debug.DrawLine ((Vector3)box.node.GetVertex(0),(Vector3)box.node.GetVertex(1),Color.red); * Debug.DrawLine ((Vector3)box.node.GetVertex(1),(Vector3)box.node.GetVertex(2),Color.red); * Debug.DrawLine ((Vector3)box.node.GetVertex(2),(Vector3)box.node.GetVertex(0),Color.red); #endif * * Vector3 closest = box.node.ClosestPointOnNode (p);//NavMeshGraph.ClosestPointOnNode (box.node,graph.vertices,p); * float dist = (closest-p).sqrMagnitude; * * if (nnInfo.node == null) { * nnInfo.node = box.node; * nnInfo.clampedPosition = closest; * } else if (dist < (nnInfo.clampedPosition - p).sqrMagnitude) { * nnInfo.node = box.node; * nnInfo.clampedPosition = closest; * } * if (constraint.Suitable (box.node)) { * if (nnInfo.constrainedNode == null) { * nnInfo.constrainedNode = box.node; * nnInfo.constClampedPosition = closest; * } else if (dist < (nnInfo.constClampedPosition - p).sqrMagnitude) { * nnInfo.constrainedNode = box.node; * nnInfo.constClampedPosition = closest; * } * } * } else { #if ASTARDEBUG * Debug.DrawLine ((Vector3)box.node.GetVertex(0),(Vector3)box.node.GetVertex(1),Color.blue); * Debug.DrawLine ((Vector3)box.node.GetVertex(1),(Vector3)box.node.GetVertex(2),Color.blue); * Debug.DrawLine ((Vector3)box.node.GetVertex(2),(Vector3)box.node.GetVertex(0),Color.blue); #endif * } * return; * } * #if ASTARDEBUG * Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMin),Color.white); * Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMax),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); * Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMin,0,box.rect.yMax),Color.white); * Debug.DrawLine (new Vector3 (box.rect.xMax,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); #endif * * //Search children * if (RectIntersectsCircle (box.c1.rect,p,radius)) { * SearchBoxCircle (box.c1,p, radius, ref nnInfo); * } * * if (RectIntersectsCircle (box.c2.rect,p,radius)) { * SearchBoxCircle (box.c2,p, radius, ref nnInfo); * } * }*/ /*public void SearchBox (BBTreeBox box, Vector3 p, NNConstraint constraint, ref NNInfo nnInfo) {//, int intendentLevel = 0) { * * if (box.node != null) { * //Leaf node * if (box.node.ContainsPoint ((Int3)p)) { * //Update the NNInfo * * if (nnInfo.node == null) { * nnInfo.node = box.node; * } else if (Mathf.Abs(((Vector3)box.node.Position).y - p.y) < Mathf.Abs (((Vector3)nnInfo.node.Position).y - p.y)) { * nnInfo.node = box.node; * } * if (constraint.Suitable (box.node)) { * if (nnInfo.constrainedNode == null) { * nnInfo.constrainedNode = box.node; * } else if (Mathf.Abs(box.node.Position.y - p.y) < Mathf.Abs (nnInfo.constrainedNode.Position.y - p.y)) { * nnInfo.constrainedNode = box.node; * } * } * } * return; * } * * //Search children * if (RectContains (box.c1.rect,p)) { * SearchBox (box.c1,p, constraint, ref nnInfo); * } * * if (RectContains (box.c2.rect,p)) { * SearchBox (box.c2,p, constraint, ref nnInfo); * } * }*/ /** Removes the specified mesh from the tree. * Assumes that it has the correct bounds information. * * \returns True if the mesh was removed from the tree, false otherwise. */ public bool Remove(RecastMeshObj mesh) { if (mesh == null) { throw new System.ArgumentNullException("mesh"); } if (root == null) { return(false); } bool found = false; Bounds b = mesh.GetBounds(); //Convert to top down rect Rect r = Rect.MinMaxRect(b.min.x, b.min.z, b.max.x, b.max.z); root = RemoveBox(root, mesh, r, ref found); return(found); }
public void Insert(RecastMeshObj mesh) { RecastBBTreeBox recastBBTreeBox = new RecastBBTreeBox(this, mesh); if (this.root == null) { this.root = recastBBTreeBox; return; } RecastBBTreeBox recastBBTreeBox2 = this.root; while (true) { recastBBTreeBox2.rect = this.ExpandToContain(recastBBTreeBox2.rect, recastBBTreeBox.rect); if (recastBBTreeBox2.mesh != null) { break; } float num = this.ExpansionRequired(recastBBTreeBox2.c1.rect, recastBBTreeBox.rect); float num2 = this.ExpansionRequired(recastBBTreeBox2.c2.rect, recastBBTreeBox.rect); if (num < num2) { recastBBTreeBox2 = recastBBTreeBox2.c1; } else if (num2 < num) { recastBBTreeBox2 = recastBBTreeBox2.c2; } else { recastBBTreeBox2 = ((this.RectArea(recastBBTreeBox2.c1.rect) >= this.RectArea(recastBBTreeBox2.c2.rect)) ? recastBBTreeBox2.c2 : recastBBTreeBox2.c1); } } recastBBTreeBox2.c1 = recastBBTreeBox; RecastBBTreeBox c = new RecastBBTreeBox(this, recastBBTreeBox2.mesh); recastBBTreeBox2.c2 = c; recastBBTreeBox2.mesh = null; }
public void Insert(RecastMeshObj mesh) { RecastBBTreeBox box = new RecastBBTreeBox(this, mesh); if (this.root == null) { this.root = box; return; } RecastBBTreeBox root = this.root; Label_0022: root.rect = this.ExpandToContain(root.rect, box.rect); if (root.mesh != null) { root.c1 = box; RecastBBTreeBox box3 = new RecastBBTreeBox(this, root.mesh); root.c2 = box3; root.mesh = null; } else { float num = this.ExpansionRequired(root.c1.rect, box.rect); float num2 = this.ExpansionRequired(root.c2.rect, box.rect); if (num < num2) { root = root.c1; } else if (num2 < num) { root = root.c2; } else { root = (this.RectArea(root.c1.rect) >= this.RectArea(root.c2.rect)) ? root.c2 : root.c1; } goto Label_0022; } }
RecastBBTreeBox RemoveBox(RecastBBTreeBox c, RecastMeshObj mesh, Rect bounds, ref bool found) { if (!RectIntersectsRect(c.rect, bounds)) { return(c); } if (c.mesh == mesh) { found = true; return(null); } if (c.mesh == null && !found) { c.c1 = RemoveBox(c.c1, mesh, bounds, ref found); if (c.c1 == null) { return(c.c2); } if (!found) { c.c2 = RemoveBox(c.c2, mesh, bounds, ref found); if (c.c2 == null) { return(c.c1); } } // TODO: Will this ever be called? if (found) { c.rect = ExpandToContain(c.c1.rect, c.c2.rect); } } return(c); }
public RecastBBTreeBox (RecastMeshObj mesh) { this.mesh = mesh; Vector3 min = mesh.bounds.min; Vector3 max = mesh.bounds.max; rect = Rect.MinMaxRect (min.x,min.z,max.x,max.z); }
/** Inserts a RecastMeshObj in the tree at its current position */ public void Insert (RecastMeshObj mesh) { var box = new RecastBBTreeBox (mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain (c.rect,box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; var box2 = new RecastBBTreeBox (c.mesh); c.c2 = box2; c.mesh = null; return; } else { float e1 = ExpansionRequired (c.c1.rect,box.rect); float e2 = ExpansionRequired (c.c2.rect,box.rect); // Choose the rect requiring the least expansion to contain box.rect if (e1 < e2) { c = c.c1; } else if (e2 < e1) { c = c.c2; } else { // Equal, Choose the one with the smallest area c = RectArea (c.c1.rect) < RectArea (c.c2.rect) ? c.c1 : c.c2; } } } }
/** Inserts a mesh node in the tree */ public void Insert (RecastMeshObj mesh) { RecastBBTreeBox box = new RecastBBTreeBox (this,mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain (c.rect,box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; RecastBBTreeBox box2 = new RecastBBTreeBox (this,c.mesh); //Console.WriteLine ("Inserted "+box.node+", rect "+box.rect.ToString ()); c.c2 = box2; c.mesh = null; //c.rect = c.rect. return; } else { float e1 = ExpansionRequired (c.c1.rect,box.rect); float e2 = ExpansionRequired (c.c2.rect,box.rect); //Choose the rect requiring the least expansion to contain box.rect if (e1 < e2) { c = c.c1; } else if (e2 < e1) { c = c.c2; } else { //Equal, Choose the one with the smallest area c = RectArea (c.c1.rect) < RectArea (c.c2.rect) ? c.c1 : c.c2; } } } }
/** Find all relevant RecastMeshObj components and create ExtraMeshes for them */ public void GetRecastMeshObjs(Bounds bounds, List <ExtraMesh> buffer) { List <RecastMeshObj> buffer2 = Util.ListPool <RecastMeshObj> .Claim(); // Get all recast mesh objects inside the bounds RecastMeshObj.GetAllInBounds(buffer2, bounds); var cachedVertices = new Dictionary <Mesh, Vector3[]>(); var cachedTris = new Dictionary <Mesh, int[]>(); // Create an ExtraMesh object // for each RecastMeshObj for (int i = 0; i < buffer2.Count; i++) { MeshFilter filter = buffer2[i].GetMeshFilter(); Renderer rend = filter != null?filter.GetComponent <Renderer>() : null; if (filter != null && rend != null) { Mesh mesh = filter.sharedMesh; #if BNICKSON_UPDATED // extra information about which game object is causing the problem if (null == mesh) { EB.Debug.LogError("RecastGenerator.GetRecastMeshObjs(): {0} has a RecastMeshObj, but does not have a MeshFilter", filter.name); } #endif var smesh = new ExtraMesh(); smesh.matrix = rend.localToWorldMatrix; smesh.original = filter; smesh.area = buffer2[i].area; // Don't read the vertices and triangles from the // mesh if we have seen the same mesh previously if (cachedVertices.ContainsKey(mesh)) { smesh.vertices = cachedVertices[mesh]; smesh.triangles = cachedTris[mesh]; } else { smesh.vertices = mesh.vertices; smesh.triangles = mesh.triangles; cachedVertices[mesh] = smesh.vertices; cachedTris[mesh] = smesh.triangles; } smesh.bounds = rend.bounds; buffer.Add(smesh); } else { Collider coll = buffer2[i].GetCollider(); if (coll == null) { EB.Debug.LogError("RecastMeshObject ({0}) didn't have a collider or MeshFilter+Renderer attached", buffer2[i].gameObject.name); continue; } ExtraMesh smesh = RasterizeCollider(coll); smesh.area = buffer2[i].area; //Make sure a valid ExtraMesh was returned if (smesh.vertices != null) { buffer.Add(smesh); } } } //Clear cache to avoid memory leak capsuleCache.Clear(); Util.ListPool <RecastMeshObj> .Release(buffer2); }