Exemple #1
0
    void Start()
    {
        WallManager.Instance.Register(this);

        var localToWorld = transform.localToWorldMatrix;
        var mesh         = GetComponent <MeshFilter>().mesh;

        Vector3[] vertices  = mesh.vertices;
        var       triangles = mesh.triangles;

        //找到贴紧地面的那些三角形
        for (int i = 0; i < triangles.Length; i += 3)
        {
            var v0 = localToWorld.MultiplyPoint(vertices[triangles[i]]);
            var v1 = localToWorld.MultiplyPoint(vertices[triangles[i + 1]]);
            var v2 = localToWorld.MultiplyPoint(vertices[triangles[i + 2]]);

            if (Mathf.Abs(v0.y) < k_epsilon && Mathf.Abs(v1.y) < k_epsilon && Mathf.Abs(v2.y) < k_epsilon)
            {
                var list = new List <IntPoint>();
                m_polygons.Add(list);
                list.Add(ClipperUtils.Convert(v0));
                list.Add(ClipperUtils.Convert(v1));
                list.Add(ClipperUtils.Convert(v2));
            }
        }

        //去掉重复的顶点
        m_polygons = Clipper.SimplifyPolygons(m_polygons);
    }
Exemple #2
0
    /// <summary>
    /// 生成轮廓线
    /// </summary>
    private void MakeContourLine(List <IntPoint> polygon, Vector2 hitPos)
    {
        //调整起点
        var     list = ClipperUtils.Convert(polygon, k_altitude);
        Vector2 minIntersect;
        int     minIndex;

        FindStartPos(list, hitPos, out minIndex, out minIntersect);

        m_contour = new Vector3[list.Length + 2];
        int index = 0;

        m_contour[index++] = new Vector3(minIntersect.x, k_altitude, minIntersect.y);
        for (int i = minIndex; i < list.Length; i++)
        {
            m_contour[index++] = list[i];
        }
        for (int i = 0; i < minIndex; i++)
        {
            m_contour[index++] = list[i];
        }
        m_contour[index++] = m_contour[0];         //首尾相连

        //设置LineRenderer
        var line = Instantiate(m_contourLine);

        line.transform.SetParent(transform);
        line.transform.position = Vector3.zero;
        line.positionCount      = m_contour.Length;
        line.SetPositions(m_contour);
    }