Esempio n. 1
0
    Mesh CreateRingWaterMesh()
    {
        List <Vector3> insidePoints  = mInsideShore.GetAllShorePoint();
        List <Vector3> outsidePoints = mOutsideShore.GetAllShorePoint();

        List <TriangleShape> generateTriangles = new List <TriangleShape> ();

        List <Vector3> cullPointList1 = new List <Vector3> ();
        List <Vector3> cullPointList2 = new List <Vector3> ();

        for (int i = 0; i < insidePoints.Count; i++)
        {
            Vector3 curInsidePoint  = insidePoints [i];
            int     nextInsideIndex = Utils.GetRingNextIndex(i, insidePoints.Count, false);
            Vector3 nextInsidePoint = insidePoints[nextInsideIndex];
            bool    hasFind         = false;
            for (int j = 0; j < outsidePoints.Count; ++j)
            {
                Vector3 curOutSidePoint  = outsidePoints [j];
                int     nextOutsideIndex = Utils.GetRingNextIndex(j, outsidePoints.Count, false);
                Vector3 nextOutSidePoint = outsidePoints[nextOutsideIndex];
                if (mInsideShore.IsLineIntersection(curInsidePoint, curOutSidePoint))
                {
                    continue;
                }
                if (mInsideShore.IsLineIntersection(nextInsidePoint, nextOutSidePoint))
                {
                    continue;
                }
                if (mOutsideShore.IsLineIntersection(curInsidePoint, curOutSidePoint))
                {
                    continue;
                }
                if (mOutsideShore.IsLineIntersection(nextInsidePoint, nextOutSidePoint))
                {
                    continue;
                }

                //把这四个点单独生成一个多边形
                cullPointList1.Add(curInsidePoint);
                cullPointList1.Add(curOutSidePoint);
                cullPointList1.Add(nextOutSidePoint);
                cullPointList1.Add(nextInsidePoint);

                //把剩余所有的点单独生成多边形
                Utils.CopyList(outsidePoints, cullPointList2, nextOutsideIndex, false);
                Utils.CopyList(insidePoints, cullPointList2, i, true);
                hasFind = true;
                break;
            }
            if (hasFind)
            {
                break;
            }
        }
        generateTriangles.AddRange(Utils.GenerateTriangles(cullPointList1));
        generateTriangles.AddRange(Utils.GenerateTriangles(cullPointList2));
        return(CreateMeshWithTrianglesList(generateTriangles));
    }