예제 #1
0
    /* parameters: None
     * returns: ObjectUpdate with information neccesary to actually make the planet in unity.
     */
    public int[] GeneratePlanet(DateTime start, out List <int>[] map, out List <Vector3> pts, out List <int>[][] trianglesHash)
    {
        map = ObjectUpdate.GetMap(connections);
        pts = Points;
        Debug.Log(pts.Count);

        triangles = new ObjectUpdate().GetTrianglesFromConnections(Points, map, out trianglesHash);
        //EventSystemMono.cacheObjMap = new List<int>[Points.Count];
        List <Vector3> pointsCopy = new List <Vector3>();

        foreach (Vector3 v in Points)
        {
            pointsCopy.Add(v);
        }
        //EventSystemMono.SetPoints(pointsCopy);
        //EventSystemMono.map = map;
        int[] mesh = MeshBuilder3D.GetMeshFrom(Points, triangles, map, trianglesHash);
        return(mesh);
    }
예제 #2
0
    //radius is (minimum) radius of the planet AKA distance from core to surface corners/points
    //variance is maximum radius - minimum, AKA variance is maximum radius added at any 1 point/corner
    //variance seed is just the rom seed
    //numPointsLat is number of points around (horizontally) on the sphere
    //numPointsLong is number of layers of points (layers horizontal and vertical in a way too)
    //points is an output bascially
    //cons (connections) is another output basically
    public static void MakePlanet(float radius, float variance, System.Random r, int numPointsLat, int numPointsLong, out List <Vector3> points, out List <int[]> cons)
    {
        points = new List <Vector3>();
        cons   = new List <int[]>();

        float  thetaSlerp = 0;
        double rot        = 0;

        //making points
        for (int i = 0; i < numPointsLat - 1; i++)
        {
            for (int i1 = 0; i1 < numPointsLong; i1++)
            {
                float  theta = Mathf.Lerp((float)(-Mathf.PI / 2 + Math.PI / (numPointsLat)), (float)(Mathf.PI / 2 - Math.PI / (numPointsLat)), thetaSlerp);
                double rad   = radius + Mathf.PerlinNoise(theta, (float)rot) * variance;
                float  x     = (float)(Math.Cos(rot) * Math.Cos(theta) * (rad));
                float  y     = (float)(Math.Sin(theta) * (rad));
                float  z     = (float)(Math.Sin(rot) * Math.Cos(theta) * (rad));
                points.Add(new Vector3(x, y, z));
                rot += 2 * Math.PI / (numPointsLong);
            }
            thetaSlerp += 1.0f / numPointsLat;
        }


        for (int i = 0; i < points.Count - numPointsLong; i++)
        {
            if ((i + 1) % numPointsLong == 0)
            {
                cons.Add(new int[] { i, i + 1 - numPointsLong });
                cons.Add(new int[] { i, i + numPointsLong });
                cons.Add(new int[] { i, i + 1 });
            }
            else
            {
                cons.Add(new int[] { i, i + 1 });
                cons.Add(new int[] { i, i + numPointsLong });
                cons.Add(new int[] { i, i + 1 + numPointsLong });
            }
        }
        int count = points.Count;

        points.Add(new Vector3(0, radius, 0));
        points.Add(new Vector3(0, -radius, 0));

        for (int i = 0; i < numPointsLong; i++)
        {
            cons.Add(new int[] { i, points.Count - 1 });
            cons.Add(new int[] { i + count - numPointsLong, points.Count - 2 });
            if (i != numPointsLong - 1)
            {
                cons.Add(new int[] { i + count - numPointsLong, i + count - numPointsLong + 1 });
            }
        }
        cons.Add(new int[] { count - 1, count - numPointsLong });

        List <int>[] map = ObjectUpdate.GetMap(cons);


        //valley
        int num = r.Next(10, 15);

        for (int i = 0; i < num; i++)
        {
            int index = r.Next(0, points.Count);
            points[index] = points[index].normalized * radius * 0.75f;
            points        = Smooth(index, 5, 0.6f, map, points);
        }

        //hill
        num = r.Next(5, 8);
        for (int i = 0; i < num; i++)
        {
            int index = r.Next(0, points.Count);
            points[index] = points[index].normalized * radius * 1.2f;
            points        = Smooth(index, 5, 0.65f, map, points);
        }

        //plateau
        num = r.Next(5, 8);
        for (int i = 0; i < num; i++)
        {
            int index = r.Next(0, points.Count);
            points[index] = points[index].normalized * radius * 1.2f;
            points        = Smooth(index, 2, 1f, map, points);
        }

        //flat
        num = r.Next(1, 3);
        for (int i = 0; i < num; i++)
        {
            int index = r.Next(0, points.Count);
            points[index] = points[index].normalized * radius * 1.1f;
            points        = Smooth(index, 5, 0.95f, map, points);
        }

        //rolling hill
        num = r.Next(5, 8);
        for (int i = 0; i < num; i++)
        {
            int index = r.Next(0, points.Count);
            points[index] = points[index].normalized * radius * 1f;
            points        = Smooth(index, 5, 0.3f, map, points);
        }

        for (int i = 0; i < points.Count; i++)
        {
            points[i] += points[i].normalized * variance * (float)r.NextDouble();
        }
    }