Pathfinding.RecastBBTree.Insert C# (CSharp) Method

Insert() public method

public Insert ( RecastMeshObj mesh ) : void
mesh RecastMeshObj
return void
		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;
					}
				}
			}
		}

Usage Example

Ejemplo n.º 1
0
 private void Register()
 {
     if (!this.registered)
     {
         this.registered = true;
         this.area       = Mathf.Clamp(this.area, -1, 0x2000000);
         Renderer component = base.GetComponent <Renderer>();
         Collider collider  = base.GetComponent <Collider>();
         if ((component == null) && (collider == null))
         {
             throw new Exception("A renderer or a collider should be attached to the GameObject");
         }
         MeshFilter filter = base.GetComponent <MeshFilter>();
         if ((component != null) && (filter == null))
         {
             throw new Exception("A renderer was attached but no mesh filter");
         }
         this.bounds   = (component == null) ? collider.bounds : component.bounds;
         this._dynamic = this.dynamic;
         if (this._dynamic)
         {
             dynamicMeshObjs.Add(this);
         }
         else
         {
             tree.Insert(this);
         }
     }
 }
All Usage Examples Of Pathfinding.RecastBBTree::Insert