private void ResetPaintMark(bool paint)
        {
            m_PaintedType = paint ? PaintedType.Painted : PaintedType.None;
            if (m_CenterNode != null && (m_CenterNode.m_PaintedType != m_PaintedType || m_CenterNode.m_PaintedType == PaintedType.Mix))
            {
                m_PaintedType = PaintedType.Mix;
                return;
            }
            if (m_TopNode != null && (m_TopNode.m_PaintedType != m_PaintedType || m_TopNode.m_PaintedType == PaintedType.Mix))
            {
                m_PaintedType = PaintedType.Mix;
                return;
            }
            if (m_LeftNode != null && (m_LeftNode.m_PaintedType != m_PaintedType || m_LeftNode.m_PaintedType == PaintedType.Mix))
            {
                m_PaintedType = PaintedType.Mix;
                return;
            }
            if (m_RightNode != null && (m_RightNode.m_PaintedType != m_PaintedType || m_RightNode.m_PaintedType == PaintedType.Mix))
            {
                m_PaintedType = PaintedType.Mix;
                return;
            }

            m_CenterNode = null;
            m_TopNode    = null;
            m_LeftNode   = null;
            m_RightNode  = null;
        }
        public NavMeshTriangleNode SampleTexture(Vector2 w0, Vector2 w1, Vector2 w2, Vector2 u0, Vector2 u1, Vector2 u2,
                                                 Texture2D texture, int depth, int maxDepth)
        {
            if (depth <= maxDepth)
            {
                Vector2             halfw01 = w0 + (w1 - w0) * 0.5f;
                Vector2             halfw02 = w0 + (w2 - w0) * 0.5f;
                Vector2             halfw12 = w1 + (w2 - w1) * 0.5f;
                NavMeshTriangleNode center  = SampleTexture(halfw01, halfw12, halfw02, u0, u1, u2, texture, depth + 1, maxDepth);
                NavMeshTriangleNode top     = SampleTexture(halfw01, w1, halfw12, u0, u1, u2, texture, depth + 1, maxDepth);
                NavMeshTriangleNode left    = SampleTexture(w0, halfw01, halfw02, u0, u1, u2, texture, depth + 1, maxDepth);
                NavMeshTriangleNode right   = SampleTexture(halfw02, halfw12, w2, u0, u1, u2, texture, depth + 1, maxDepth);

                NavMeshTriangleNode node = new NavMeshTriangleNode();
                node.m_CenterNode = center;
                node.m_TopNode    = top;
                node.m_LeftNode   = left;
                node.m_RightNode  = right;
                node.ResetPaintMark();
                //node.isMix = mix;
                return(node);
            }
            else
            {
                NavMeshTriangleNode node = new NavMeshTriangleNode();
                if (node.SampleTexture(w0, w1, w2, u0, u1, u2, texture))
                {
                    node.m_PaintedType = PaintedType.Painted;
                    return(node);
                }
                return(node);
            }
        }
예제 #3
0
        public NavMeshTriangle(Vector2 uv0, Vector2 uv1, Vector2 uv2)
        {
            m_Root = new NavMeshTriangleNode();

            this.uv0 = uv0;
            this.uv1 = uv1;
            this.uv2 = uv2;
        }
        public void SamplingFromTexture(Vector2 weight0, Vector2 weight1, Vector2 weight2, Vector2 u0, Vector2 u1, Vector2 u2, Texture2D texture, int depth, int maxDepth)
        {
            if (depth <= maxDepth)
            {
                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.SamplingFromTexture(halfw01, halfw12, halfw02, u0, u1, u2, texture, depth + 1, maxDepth);
                }
                else
                {
                    m_CenterNode = SampleTexture(halfw01, halfw12, halfw02, u0, u1, u2, texture, depth + 1, maxDepth);
                }

                if (m_TopNode != null)
                {
                    m_TopNode.SamplingFromTexture(halfw01, weight1, halfw12, u0, u1, u2, texture, depth + 1, maxDepth);
                }
                else
                {
                    m_TopNode = SampleTexture(halfw01, weight1, halfw12, u0, u1, u2, texture, depth + 1, maxDepth);
                }

                if (m_LeftNode != null)
                {
                    m_LeftNode.SamplingFromTexture(weight0, halfw01, halfw02, u0, u1, u2, texture, depth + 1, maxDepth);
                }
                else
                {
                    m_LeftNode = SampleTexture(weight0, halfw01, halfw02, u0, u1, u2, texture, depth + 1, maxDepth);
                }

                if (m_RightNode != null)
                {
                    m_RightNode.SamplingFromTexture(halfw02, halfw12, weight2, u0, u1, u2, texture, depth + 1, maxDepth);
                }
                else
                {
                    m_RightNode = SampleTexture(halfw02, halfw12, weight2, u0, u1, u2, texture, depth + 1, maxDepth);
                }

                ResetPaintMark();
            }
            else
            {
                bool painted = SampleTexture(weight0, weight1, weight2, u0, u1, u2, texture);
                //if (blendMode == TextureBlendMode.Replace)
                {
                    m_PaintedType = painted ? PaintedType.Painted : PaintedType.None;
                }
            }
        }
예제 #5
0
        public NavMeshTriangle(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, Vector2 uv0, Vector2 uv1, Vector2 uv2)
        {
            m_Root = new NavMeshTriangleNode();

            float maxX = Mathf.Max(vertex0.x, vertex1.x, vertex2.x);
            float maxY = Mathf.Max(vertex0.y, vertex1.y, vertex2.y);
            float maxZ = Mathf.Max(vertex0.z, vertex1.z, vertex2.z);

            float minX = Mathf.Min(vertex0.x, vertex1.x, vertex2.x);
            float minY = Mathf.Min(vertex0.y, vertex1.y, vertex2.y);
            float minZ = Mathf.Min(vertex0.z, vertex1.z, vertex2.z);

            Vector3 si = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);

            if (si.x <= 0)
            {
                si.x = 0.1f;
            }
            if (si.y <= 0)
            {
                si.y = 0.1f;
            }
            if (si.z <= 0)
            {
                si.z = 0.1f;
            }
            Vector3 ct = new Vector3(minX, minY, minZ) + si / 2;

            this.m_Bounds = new Bounds(ct, si);

            this.vertex0 = vertex0;
            this.vertex1 = vertex1;
            this.vertex2 = vertex2;
            this.uv0     = uv0;
            this.uv1     = uv1;
            this.uv2     = uv2;
        }
예제 #6
0
 public void Clear()
 {
     m_Root = new NavMeshTriangleNode();
 }
        private void ResetPaintMark()
        {
            bool initPaintedtype = false;

            if (m_CenterNode != null)
            {
                initPaintedtype = true;
                m_PaintedType   = m_CenterNode.m_PaintedType;
            }
            if (m_TopNode != null)
            {
                if (!initPaintedtype)
                {
                    initPaintedtype = true;
                    m_PaintedType   = m_TopNode.m_PaintedType;
                }
                else
                {
                    if (m_TopNode.m_PaintedType != m_PaintedType || m_TopNode.m_PaintedType == PaintedType.Mix)
                    {
                        m_PaintedType = PaintedType.Mix;
                    }
                }
            }
            if (m_LeftNode != null)
            {
                if (!initPaintedtype)
                {
                    initPaintedtype = true;
                    m_PaintedType   = m_LeftNode.m_PaintedType;
                }
                else
                {
                    if (m_LeftNode.m_PaintedType != m_PaintedType || m_LeftNode.m_PaintedType == PaintedType.Mix)
                    {
                        m_PaintedType = PaintedType.Mix;
                    }
                }
            }
            if (m_RightNode != null)
            {
                if (!initPaintedtype)
                {
                    m_PaintedType = m_RightNode.m_PaintedType;
                }
                else
                {
                    if (m_RightNode.m_PaintedType != m_PaintedType || m_RightNode.m_PaintedType == PaintedType.Mix)
                    {
                        m_PaintedType = PaintedType.Mix;
                    }
                }
            }

            if (m_PaintedType != PaintedType.Mix)
            {
                m_CenterNode = null;
                m_TopNode    = null;
                m_LeftNode   = null;
                m_RightNode  = null;
            }
        }
        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);
            }
        }