예제 #1
0
 public void Interesect(IPaintingTool tool, bool erase)
 {
     if (m_Root != null)
     {
         m_Root.Interesect(tool, erase, Vector2.zero, Vector2.right, Vector2.up, vertex0, vertex1, vertex2, 0, m_MaxDepth);
     }
 }
        public void Interesect(IPaintingTool tool, bool erase, Vector2 weight0, Vector2 weight1, Vector2 weight2, Vector3 v0, Vector3 v1, Vector3 v2, int depth, int maxDepth)
        {
            Vector3 vertex0 = (1 - weight0.x - weight0.y) * v0 + weight0.x * v1 + weight0.y * v2;
            Vector3 vertex1 = (1 - weight1.x - weight1.y) * v0 + weight1.x * v1 + weight1.y * v2;
            Vector3 vertex2 = (1 - weight2.x - weight2.y) * v0 + weight2.x * v1 + weight2.y * v2;

            if (tool.IntersectsTriangle(vertex0, vertex1, vertex2))
            {
                bool continuePaint = m_PaintedType == PaintedType.Mix;
                if (m_PaintedType == PaintedType.Painted && erase)
                {
                    continuePaint = true;
                }
                if (m_PaintedType == PaintedType.None && !erase)
                {
                    continuePaint = true;
                }
                if (!continuePaint)
                {
                    return;
                }

                if (depth <= maxDepth)
                {
                    if (m_CenterNode == null)
                    {
                        m_CenterNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                    if (m_TopNode == null)
                    {
                        m_TopNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                    if (m_LeftNode == null)
                    {
                        m_LeftNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                    if (m_RightNode == null)
                    {
                        m_RightNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                }

                Vector2 halfw01 = weight0 + (weight1 - weight0) * 0.5f;
                Vector2 halfw02 = weight0 + (weight2 - weight0) * 0.5f;
                Vector2 halfw12 = weight1 + (weight2 - weight1) * 0.5f;

                if (m_CenterNode != null)
                {
                    m_CenterNode.Interesect(tool, erase, halfw01, halfw12, halfw02, v0, v1, v2, depth + 1, maxDepth);
                }

                if (m_TopNode != null)
                {
                    m_TopNode.Interesect(tool, erase, halfw01, weight1, halfw12, v0, v1, v2, depth + 1, maxDepth);
                }

                if (m_LeftNode != null)
                {
                    m_LeftNode.Interesect(tool, erase, weight0, halfw01, halfw02, v0, v1, v2, depth + 1, maxDepth);
                }

                if (m_RightNode != null)
                {
                    m_RightNode.Interesect(tool, erase, halfw02, halfw12, weight2, v0, v1, v2, depth + 1, maxDepth);
                }

                ResetPaintMark(!erase);
            }
        }