Пример #1
0
        public bool ProcessPoint(OctreePoint point)
        {
            if (ContainsPoint(point.transform.position))
            {
                //while this cell has no child cells, push the point to this cell
                //subdivide this cell if it contains to many points
                if (m_childCells[0] == null)
                {
                    PushItem(point);
                    SubdivideIfNecessary();
                    return(true);
                }

                //process points on child cells
                foreach (var childNode in m_childCells)
                {
                    if (childNode.ProcessPoint(point))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #2
0
 private void PushItem(OctreePoint point)
 {
     if (!ContainedPoints.Contains(point))
     {
         ContainedPoints.Add(point);
         point.Cells.Add(this);
     }
 }
Пример #3
0
        public void TryReduceSubdivisions(OctreePoint point)
        {
            if (this != Root && !SiblingNodesContainsToManyPoints())
            {
                foreach (var cell in Parent.m_childCells)
                {
                    //trying to avoid null cell, might be already deleted
                    cell?.Delete(Parent.ChildCells.Where(x => !ReferenceEquals(x, this)).ToArray());
                }

                Parent.ClearChildCells();
            }

            ContainedPoints.Remove(point);
            point.Cells.Remove(this);
        }