Example #1
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="item"></param>
 public void Add(NavMeshTriangle item)
 {
     if (m_Root != null)
     {
         NavMeshOcTreeNode node = m_Root.Insert(item, 0, m_MaxDepth);
         if (node != null)
         {
             {
                 m_Count++;
             }
         }
     }
 }
Example #2
0
 public NavMeshOcTreeNode Insert(NavMeshTriangle item, int depth, int maxDepth)
 {
     if (depth < maxDepth)
     {
         NavMeshOcTreeNode node = GetContainerNode(item);
         if (node != null)
         {
             return(node.Insert(item, depth + 1, maxDepth));
         }
     }
     m_ItemList.Add(item);
     return(this);
 }
Example #3
0
        private NavMeshOcTreeNode GetContainerNode(ref NavMeshOcTreeNode node, Vector3 centerPos, Vector3 size, NavMeshTriangle item)
        {
            NavMeshOcTreeNode result = null;
            Bounds            bd     = item.bounds;

            if (node == null)
            {
                Bounds bounds = new Bounds(centerPos, size);
                if (bounds.IsBoundsContainsAnotherBounds(bd))
                {
                    node   = new NavMeshOcTreeNode(bounds);
                    result = node;
                }
            }
            else if (node.bounds.IsBoundsContainsAnotherBounds(bd))
            {
                result = node;
            }
            return(result);
        }
Example #4
0
 /// <summary>
 /// 构造八叉树
 /// </summary>
 /// <param name="center">八叉树中心坐标</param>
 /// <param name="size">八叉树区域大小</param>
 /// <param name="maxDepth">最大深度</param>
 public NavMeshOcTree(Vector3 center, Vector3 size, int maxDepth)
 {
     this.m_MaxDepth = maxDepth;
     this.m_Root     = new NavMeshOcTreeNode(new Bounds(center, size));
 }
Example #5
0
        private NavMeshOcTreeNode GetContainerNode(NavMeshTriangle item)
        {
            Vector3           halfSize = bounds.size / 2;
            NavMeshOcTreeNode result   = null;

            result = GetContainerNode(ref m_ChildNodes[0], bounds.center + new Vector3(-halfSize.x / 2, halfSize.y / 2, halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[1], bounds.center + new Vector3(-halfSize.x / 2, halfSize.y / 2, -halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[2], bounds.center + new Vector3(halfSize.x / 2, halfSize.y / 2, halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[3], bounds.center + new Vector3(halfSize.x / 2, halfSize.y / 2, -halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[4], bounds.center + new Vector3(-halfSize.x / 2, -halfSize.y / 2, halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[5], bounds.center + new Vector3(-halfSize.x / 2, -halfSize.y / 2, -halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[6], bounds.center + new Vector3(halfSize.x / 2, -halfSize.y / 2, halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            result = GetContainerNode(ref m_ChildNodes[7], bounds.center + new Vector3(halfSize.x / 2, -halfSize.y / 2, -halfSize.z / 2),
                                      halfSize, item);
            if (result != null)
            {
                return(result);
            }

            return(null);
        }