Beispiel #1
0
    private static PolySet StitchPolys(ICollection <Polygon> polygons, IList <Vector3> vertices, PolySet polys, out EdgeSet stitchedEdge)
    {
        var stichedPolys = new PolySet {
            StitchedVertexThreshold = vertices.Count
        };

        stitchedEdge = PolySet.CreateEdgeSet(polys);
        IList <int> originalVerts = EdgeSet.GetUniqueVertices(stitchedEdge);
        IList <int> newVerts      = CloneVertices(vertices, originalVerts);

        stitchedEdge.Split(originalVerts, newVerts);

        foreach (Edge edge in stitchedEdge)
        {
            // Create new polys along the stitched edge. These
            // will connect the original poly to its former
            // neighbor.

            var stitchPoly1 = new Polygon(edge.OuterVerts[0],
                                          edge.OuterVerts[1],
                                          edge.InnerVerts[0]);
            var stitchPoly2 = new Polygon(edge.OuterVerts[1],
                                          edge.InnerVerts[1],
                                          edge.InnerVerts[0]);
            // Add the new stitched faces as neighbors to
            // the original Polys.
            Polygon.ReplacePolygon(edge.InnerPoly.Neighbors, edge.OuterPoly, stitchPoly2);
            Polygon.ReplacePolygon(edge.OuterPoly.Neighbors, edge.InnerPoly, stitchPoly1);

            polygons.Add(stitchPoly1);
            polygons.Add(stitchPoly2);

            stichedPolys.Add(stitchPoly1);
            stichedPolys.Add(stitchPoly2);
        }

        //Swap to the new vertices on the inner polys.
        foreach (Polygon poly in polys)
        {
            for (int i = 0; i < 3; i++)
            {
                int vertID = poly.Vertices[i];
                if (!originalVerts.Contains(vertID))
                {
                    continue;
                }

                int vertIndex = originalVerts.IndexOf(vertID);
                poly.Vertices[i] = newVerts[vertIndex];
            }
        }

        return(stichedPolys);
    }
    public PolySet StitchPolys(PolySet polys, out EdgeSet stitchedEdge)
    {
        PolySet stichedPolys = new PolySet();

        stichedPolys.m_StitchedVertexThreshold = m_Vertices.Count;

        stitchedEdge = polys.CreateEdgeSet();
        var originalVerts = stitchedEdge.GetUniqueVertices();
        var newVerts      = CloneVertices(originalVerts);

        stitchedEdge.Split(originalVerts, newVerts);

        foreach (Edge edge in stitchedEdge)
        {
            // Create new polys along the stitched edge. These
            // will connect the original poly to its former
            // neighbor.

            var stitch_poly1 = new Polygon(edge.m_OuterVerts[0],
                                           edge.m_OuterVerts[1],
                                           edge.m_InnerVerts[0]);
            var stitch_poly2 = new Polygon(edge.m_OuterVerts[1],
                                           edge.m_InnerVerts[1],
                                           edge.m_InnerVerts[0]);
            // Add the new stitched faces as neighbors to
            // the original Polys.
            edge.m_InnerPoly.ReplaceNeighbor(edge.m_OuterPoly, stitch_poly2);
            edge.m_OuterPoly.ReplaceNeighbor(edge.m_InnerPoly, stitch_poly1);

            m_Polygons.Add(stitch_poly1);
            m_Polygons.Add(stitch_poly2);

            stichedPolys.Add(stitch_poly1);
            stichedPolys.Add(stitch_poly2);
        }

        //Swap to the new vertices on the inner polys.
        foreach (Polygon poly in polys)
        {
            for (int i = 0; i < 3; i++)
            {
                int vert_id = poly.m_Vertices[i];
                if (!originalVerts.Contains(vert_id))
                {
                    continue;
                }
                int vert_index = originalVerts.IndexOf(vert_id);
                poly.m_Vertices[i] = newVerts[vert_index];
            }
        }

        return(stichedPolys);
    }
Beispiel #3
0
    public PolySet StitchPolys(PolySet polys)
    {
        PolySet stitchedPolys = new PolySet();

        var edgeSet       = polys.CreateEdgeSet();
        var originalVerts = edgeSet.GetUniqueVertices();
        var newVerts      = CloneVertices(originalVerts);

        edgeSet.Split(originalVerts, newVerts);

        foreach (Edge edge in edgeSet)
        {
            var stitch_poly1 = new Polygon(edge.m_OuterVerts[0],
                                           edge.m_OuterVerts[1],
                                           edge.m_InnerVerts[0]);
            var stitch_poly2 = new Polygon(edge.m_OuterVerts[1],
                                           edge.m_InnerVerts[1],
                                           edge.m_InnerVerts[0]);
            edge.m_InnerPoly.ReplaceNeighbor(edge.m_OuterPoly, stitch_poly2);
            edge.m_OuterPoly.ReplaceNeighbor(edge.m_InnerPoly, stitch_poly1);

            m_Polygons.Add(stitch_poly1);
            m_Polygons.Add(stitch_poly2);
            stitchedPolys.Add(stitch_poly1);
            stitchedPolys.Add(stitch_poly2);
        }

        foreach (Polygon poly in polys)
        {
            for (int i = 0; i < 3; i++)
            {
                int vert_id = poly.m_Vertices[i];
                if (!originalVerts.Contains(vert_id))
                {
                    continue;
                }
                int vert_index = originalVerts.IndexOf(vert_id);
                poly.m_Vertices[i] = newVerts[vert_index];
            }
        }
        return(stitchedPolys);
    }