예제 #1
0
    public void StitchPolygons(LucygenPolygonSet polys)
    {
        LucygenEdgeSet oldEdges    = polys.createEdgeSet();
        List <int>     oldVertices = oldEdges.GetUniqueVertices();
        List <int>     newVertices = cloneVertices(oldVertices);
        LucygenEdgeSet newEdges    = oldEdges.clone();

        for (int i = 0; i < oldEdges.Count; i++)
        {
            LucygenEdge oldEdge = oldEdges[i];
            LucygenEdge newEdge = newEdges[i];

            //Make sure that the vertices in newEdge
            //are the ones we recently cloned, instead
            //of the old vertices.

            for (int j = 0; j < 2; j++)
            {
                int oldVertex = oldEdge.m_sharedVertices[j];
                int index     = oldVertices.IndexOf(oldVertex);
                newEdge.m_sharedVertices[j] = newVertices[index];
            }

            //Create new polys along the stitched edge. These
            //will connect the original poly to its former neighbor.

            LucygenPolygon stitchPoly1 = new LucygenPolygon(oldEdge.m_sharedVertices[0],
                                                            oldEdge.m_sharedVertices[1],
                                                            oldEdge.m_sharedVertices[0]);

            LucygenPolygon stitchPoly2 = new LucygenPolygon(oldEdge.m_sharedVertices[1],
                                                            oldEdge.m_sharedVertices[1],
                                                            oldEdge.m_sharedVertices[0]);

            oldEdge.m_innerPolygon.ReplaceNeighbor(oldEdge.m_outerPolygon, stitchPoly2);
            oldEdge.m_outerPolygon.ReplaceNeighbor(oldEdge.m_innerPolygon, stitchPoly1);

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

        //Swap to the new vertices on the inner polys.

        foreach (LucygenPolygon poly in polys)
        {
            for (int i = 0; i < 3; i++)
            {
                int vertID = poly.m_vertices[i];
                if (!oldVertices.Contains(vertID))
                {
                    continue;
                }

                int vertIndex = oldVertices.IndexOf(vertID);
                poly.m_vertices[i] = newVertices[vertIndex];
            }
        }
    }
예제 #2
0
    public LucygenEdgeSet clone()
    {
        LucygenEdgeSet clone = new LucygenEdgeSet();

        foreach (LucygenEdge edge in this)
        {
            clone.Add(edge.clone());
        }
        return(clone);
    }
예제 #3
0
    public LucygenEdgeSet createEdgeSet()
    {
        LucygenEdgeSet edgeSet = new LucygenEdgeSet();

        foreach (LucygenPolygon polygon in this)
        {
            foreach (LucygenPolygon neighbor in polygon.m_neighbors)
            {
                if (this.Contains(neighbor))
                {
                    continue;
                }

                LucygenEdge edge = new LucygenEdge(polygon, neighbor);
                edgeSet.Add(edge);
            }
        }
        return(edgeSet);
    }