Beispiel #1
0
    // fusion de la forme de base (liner, margelle) et rectangle exterieur
    // pour la triangulation
    // voir http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
    protected void MergedInnerAndOuter()
    {
        Bounds polyBounds = _polygon.bounds;
        Vector3 extents = polyBounds.extents;
        Vector3 center = polyBounds.center;

        // Pythagore
        float translation = _outlineOffset * 1.41421356f; // sqrt (2)

        Vector2 upRightDir = new Vector2 (1, 1).normalized * translation;
        Vector2 upRight = new Vector2 (center.x + extents.x, center.z + extents.z) + upRightDir;

        Vector2 downRightDir = new Vector2 (1, -1).normalized * translation;
        Vector2 downRight = new Vector2 (center.x + extents.x, center.z - extents.z) + downRightDir;

        Vector2 downLeftDir = new Vector2 (-1, -1).normalized * translation;
        Vector2 downLeft = new Vector2 (center.x - extents.x, center.z - extents.z) + downLeftDir;

        Vector2 upLeftDir = new Vector2 (-1, 1).normalized * translation;
        Vector2 upLeft = new Vector2 (center.x - extents.x, center.z + extents.z) + upLeftDir;

        PolygonRawData outerRawPoly = new PolygonRawData ();
        outerRawPoly.Add (upRight);
        outerRawPoly.Add (downRight);
        outerRawPoly.Add (downLeft);
        outerRawPoly.Add (upLeft);

        Polygon outerPolygon = new Polygon (outerRawPoly);
        _mergedPolygon = PolygonOperation.MergeInnerAndOuter (_polygon, outerPolygon);
    }
Beispiel #2
0
    // fusionne deux polygones. Inner doit etre totalement inclus dans outer
    // permet la triangulation d'un polygonr avec un trou --> plage
    // voir http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
    public static MergedPolygon MergeInnerAndOuter(Polygon inner, Polygon outer)
    {
        MergedPolygon mergedPolygon = new MergedPolygon ();
        PolygonRawData mergedPolyRaw = new PolygonRawData ();

        MutuallyVisibleVertices mvv = FindMutuallyVisibleVertices (inner, outer);

        LoopedList<Point2> innerPoints = inner.GetPoints ();
        LoopedList<Point2> outerPoints = outer.GetPoints ();

        int innerIndex = 0;
        for (; innerIndex <= mvv.innerIndex; ++innerIndex)
        {
            mergedPolyRaw.Add (innerPoints[innerIndex]);
        }

        mergedPolygon.originalIndex0 = mergedPolyRaw.Count - 1;
        mergedPolygon.originalIndex1 = mergedPolyRaw.Count;

        for (int counter = 0, outerIndex = mvv.outerIndex;
            counter < outerPoints.Count;
            ++counter, --outerIndex)
        {
            mergedPolyRaw.Add (outerPoints[outerIndex]);
        }

        mergedPolyRaw.Add (outerPoints[mvv.outerIndex] + mvv.duplicatedMVVOffset);
        mergedPolygon.duplicatedIndex1 = mergedPolyRaw.Count - 1;

        mergedPolyRaw.Add (innerPoints[mvv.innerIndex] + mvv.duplicatedMVVOffset);
        mergedPolygon.duplicatedIndex0 = mergedPolyRaw.Count - 1;

        for (; innerIndex < innerPoints.Count; ++innerIndex)
        {
            mergedPolyRaw.Add (innerPoints[innerIndex]);
        }

        mergedPolygon.polygonRawData = mergedPolyRaw;

        //		Debug.Log (mergedPolygon.originalIndex0 + " " + mergedPolygon.originalIndex1 + " " + mergedPolygon.duplicatedIndex0 + " " + mergedPolygon.duplicatedIndex1);

        return mergedPolygon;
    }