コード例 #1
0
    public LucygenEdge clone()
    {
        LucygenPolygon cloneInnerPolygon = new LucygenPolygon(m_innerPolygon.m_vertices[0], m_innerPolygon.m_vertices[1], m_innerPolygon.m_vertices[2]);
        LucygenPolygon cloneOuterPolgon  = new LucygenPolygon(m_outerPolygon.m_vertices[0], m_outerPolygon.m_vertices[1], m_outerPolygon.m_vertices[2]);
        LucygenEdge    cloneEdge         = new LucygenEdge(cloneInnerPolygon, cloneOuterPolgon);

        return(cloneEdge);
    }
コード例 #2
0
ファイル: LucygenPlanet.cs プロジェクト: gamesbylucy/lucygen
    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];
            }
        }
    }
コード例 #3
0
 public void ReplaceNeighbor(LucygenPolygon oldPoly, LucygenPolygon newPoly)
 {
     for (int i = 0; i < m_neighbors.Count; i++)
     {
         if (oldPoly == m_neighbors[i])
         {
             m_neighbors[i] = newPoly;
             return;
         }
     }
 }
コード例 #4
0
    public LucygenEdge(LucygenPolygon innerPolygon, LucygenPolygon outerPolygon)
    {
        m_innerPolygon   = innerPolygon;
        m_outerPolygon   = outerPolygon;
        m_sharedVertices = new List <int>();

        foreach (int vertex in innerPolygon.m_vertices)
        {
            if (outerPolygon.m_vertices.Contains(vertex))
            {
                m_sharedVertices.Add(vertex);
            }
        }
    }
コード例 #5
0
    //determines that this polygon is a neighbor of the arg if the polys have
    //more than 2 shared vertices
    public bool isNeighborOf(LucygenPolygon other_poly)
    {
        bool result = false;

        int shared_vertices = 0;

        foreach (int vertex in m_vertices)
        {
            if (other_poly.m_vertices.Contains(vertex))
            {
                shared_vertices++;
            }
        }

        return(shared_vertices == 2);
    }
コード例 #6
0
ファイル: LucygenPlanet.cs プロジェクト: gamesbylucy/lucygen
    public void Start()
    {
        GetComponent <MeshFilter>().mesh = m_mesh = new Mesh();
        InitAsIcosohedron(size);
        Subdivide(subdivisions);
        List <Vector3> tempVertices = new List <Vector3>();

        LucygenPolygonSet hills     = new LucygenPolygonSet();
        LucygenPolygonSet mountains = new LucygenPolygonSet();
        LucygenPolygonSet plains    = new LucygenPolygonSet();
        LucygenPolygonSet valleys   = new LucygenPolygonSet();
        LucygenPolygonSet canyons   = new LucygenPolygonSet();

        int numMountains = (int)(percentMountain * (float)m_LucygenPolygons.Count);
        int numHills     = (int)(percentHills * (float)m_LucygenPolygons.Count);
        int numPlains    = (int)(percentPlains * (float)m_LucygenPolygons.Count);
        int numValleys   = (int)(percentValleys * (float)m_LucygenPolygons.Count);
        int numCanyons   = (int)(percentCanyons * (float)m_LucygenPolygons.Count);
        int sum          = numMountains + numHills + numPlains + numValleys + numCanyons;

        docstring += ("Sum of polys: " + sum + "\n" + "Mountain polys: " + numMountains + "\n" +
                      "Hill polys: " + numHills + "\n" + "Plains polys: " + numPlains + "\n" + "Valley polys: "
                      + numValleys + "\n" + "Canyon polys: " + numCanyons + "\n");

        foreach (LucygenPolygon polygon in m_LucygenPolygons)
        {
            if (sum > m_LucygenPolygons.Count)
            {
                numPlains = numPlains - (m_LucygenPolygons.Count - sum);
            }
            else if (sum < m_LucygenPolygons.Count)
            {
                numPlains = numValleys - (m_LucygenPolygons.Count - sum);
            }

            while (sum > 0)
            {
                int index = Random.Range(0, m_LucygenPolygons.Count);

                LucygenPolygon current = m_LucygenPolygons[index];

                if (numMountains > 0)
                {
                    mountains.Add(current);
                    numMountains--;
                }
                else if (numHills > 0)
                {
                    hills.Add(current);
                    numHills--;
                }
                else if (numPlains > 0)
                {
                    plains.Add(current);
                    numPlains--;
                }
                else if (numValleys > 0)
                {
                    valleys.Add(current);
                    numValleys--;
                }
                else if (numCanyons > 0)
                {
                    canyons.Add(current);
                    numCanyons--;
                }
                sum--;
            }
        }

        extrude(mountains, .1f);
        extrude(hills, .05f);
        extrude(valleys, -.05f);
        extrude(canyons, -.1f);

        foreach (Vector3 vertex in m_VerticesList)
        {
            Vector3 newVertex = vertex * size;
            tempVertices.Add(newVertex);
        }



        m_VerticesList   = tempVertices;
        m_mesh.vertices  = m_VerticesList.ToArray();
        m_mesh.triangles = new int[m_LucygenPolygons.Count * 3];
        m_mesh.triangles = buildTriangles(m_LucygenPolygons, m_mesh.triangles);

        m_mesh.RecalculateNormals();

        docstring += ("Number of Polys: " + m_LucygenPolygons.Count + "\n" +
                      "Triangles array length: " + m_mesh.triangles.Length + "\n" +
                      "Vertices array length: " + m_mesh.vertices.Length + "\n" +
                      "Normals array length: " + m_mesh.normals.Length);

        for (int i = 0; i < m_mesh.triangles.Length; i++)
        {
            docstring += m_mesh.triangles[i] + " ";
            if ((i + 1) % 3 == 0)
            {
                docstring += "\n";
            }
        }
        Debug.Log(docstring);
    }