Exemple #1
0
    // this script loops through certains points on the map. These points are the corners of (big) triangle shaped areas.
    // It checks which other points are part of that triangle, and [...] does something?

    // gets the triangleData
    public static TriangleData Generate(float[,] noise, float heightMultiplier)
    {
        int width  = noise.GetLength(0);
        int length = noise.GetLength(1);

        TriangleData _mesh   = new TriangleData(width, length);
        int          pointNr = 0; // The number of the point on the map that will be used to create a traingle

        for (int w = 0; w < width; w++)
        {
            for (int l = 0; l < length; l++)
            {
                _mesh.vertices[pointNr] = new Vector3(l, noise[l, w] * heightMultiplier, w); // location of the vertices (same as the waypoints)
                _mesh.uvMap[pointNr]    = new Vector2(l / (float)length, w / (float)width);  // the location for the UVmap (percantage based)

                if (w < width - 1 && l < length - 1)                                         // loop through all points, except the right edge and bottom edge, as they will not be used
                {
                    _mesh.CreateTriangle(pointNr, pointNr + width + 1, pointNr + width);
                    _mesh.CreateTriangle(pointNr + width + 1, pointNr, pointNr + 1);
                }
                pointNr++;
            }
        }
        return(_mesh);
    }