public bool Remove(OTMeshTriangle item)
 {
     if (m_ItemList.Remove(item))
     {
         return(true);
     }
     return(false);
 }
Example #2
0
 /// <summary>
 /// 是否包含对象
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(OTMeshTriangle item)
 {
     if (m_NodeLists != null && m_NodeLists.Count > 0)
     {
         return(m_NodeLists[0].Contains(item, m_NodeLists));
     }
     else
     {
         return(false);
     }
 }
 public MeshOcTreeNode Insert(OTMeshTriangle item, int depth, int maxDepth, List <MeshOcTreeNode> nodeList)
 {
     if (depth < maxDepth)
     {
         MeshOcTreeNode node = GetContainerNode(item, nodeList);
         if (node != null)
         {
             return(node.Insert(item, depth + 1, maxDepth, nodeList));
         }
     }
     m_ItemList.Add(item);
     return(this);
 }
Example #4
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="item"></param>
 public void Add(OTMeshTriangle item)
 {
     if (m_NodeLists != null && m_NodeLists.Count > 0)
     {
         MeshOcTreeNode node = m_NodeLists[0].Insert(item, 0, maxDepth, m_NodeLists);
         if (node != null)
         {
             int index = m_NodeLists.IndexOf(node);
             if (index >= 0)
             {
                 m_DataList.Add(item);
                 m_NodeIndexList.Add(index);
                 m_Count++;
             }
         }
     }
 }
        public bool Contains(OTMeshTriangle item, List <MeshOcTreeNode> nodeList)
        {
            for (int i = 0; i < m_ChildNodes.Length; i++)
            {
                if (m_ChildNodes[i] > 0)
                {
                    if (nodeList[m_ChildNodes[i]].Contains(item, nodeList))
                    {
                        return(true);
                    }
                }
            }

            if (m_ItemList.Contains(item))
            {
                return(true);
            }
            return(false);
        }
Example #6
0
        /// <summary>
        /// 从树中移除对象
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Remove(OTMeshTriangle item)
        {
            if (count <= 0)
            {
                return(false);
            }
            int index = m_DataList.IndexOf(item);

            if (index >= 0)
            {
                int nodeIndex = m_NodeIndexList[index];
                if (m_NodeLists[nodeIndex].Remove(item))
                {
                    m_Count--;
                    return(true);
                }
            }
            return(false);
        }
        private int GetContainerNode(ref int node, Vector3 centerPos, Vector3 size, OTMeshTriangle item, List <MeshOcTreeNode> nodeList)
        {
            int    result = -1;
            Bounds bd     = item.bounds;

            if (node < 0)
            {
                Bounds bounds = new Bounds(centerPos, size);
                if (bounds.IsBoundsContainsAnotherBounds(bd))
                {
                    nodeList.Add(new MeshOcTreeNode(bounds));
                    node   = nodeList.Count - 1;
                    result = node;
                }
            }
            else if (nodeList[node].bounds.IsBoundsContainsAnotherBounds(bd))
            {
                result = node;
            }
            return(result);
        }
        /// <summary>
        /// 添加三角面
        /// </summary>
        /// <param name="triangle"></param>
        public void AddTriangle(OTMeshTriangle triangle)
        {
            //lock (m_Lock)
            {
                m_VertexList.Add(triangle.vertex0);
                m_VertexList.Add(triangle.vertex1);
                m_VertexList.Add(triangle.vertex2);

                Vector3 pj0 = m_WorldToProjector.MultiplyPoint(triangle.vertex0);
                Vector3 pj1 = m_WorldToProjector.MultiplyPoint(triangle.vertex1);
                Vector3 pj2 = m_WorldToProjector.MultiplyPoint(triangle.vertex2);

                m_UVList.Add(new Vector2(pj0.x * 0.5f + 0.5f, pj0.y * 0.5f + 0.5f));
                m_UVList.Add(new Vector2(pj1.x * 0.5f + 0.5f, pj1.y * 0.5f + 0.5f));
                m_UVList.Add(new Vector2(pj2.x * 0.5f + 0.5f, pj2.y * 0.5f + 0.5f));

                m_Indexes.Add(m_Index + 0);
                m_Indexes.Add(m_Index + 1);
                m_Indexes.Add(m_Index + 2);
                m_Index += 3;
            }
        }
        private MeshOcTreeNode GetContainerNode(OTMeshTriangle item, List <MeshOcTreeNode> nodeList)
        {
            Vector3 halfSize = bounds.size / 2;
            int     result   = -1;

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

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

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

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

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

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

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

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

            return(null);
        }