Ejemplo n.º 1
0
    void Rebuild()
    {
        noise.Compute();
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                float   xCoord = (i / (float)width);
                float   yCoord = (j / (float)height);
                Vector2 r      = /*Quaternion.AngleAxis(rotation, Vector3.forward) * */ new Vector2(xCoord, yCoord);

                if (noise.colored)
                {
                    Color c = noise.ResolveAsColor(r.x, r.y);
                    texture.SetPixel(i, j, c);
                }
                else
                {
                    float n = noise.Resolve(r.x, r.y);
                    texture.SetPixel(i, j, n * Color.white);
                }
            }
        }
        texture.Apply();
    }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     terrain          = GetComponent <Terrain>();
     float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
     noise.Compute();
     for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
     {
         for (int j = 0; j < terrain.terrainData.heightmapHeight; j++)
         {
             float x     = i / (float)terrain.terrainData.heightmapResolution;
             float y     = j / (float)terrain.terrainData.heightmapResolution;
             float value = noise.Resolve(x, y);
             heights[i, j] = value * maxHeight;
         }
     }
     terrain.terrainData.SetHeights(0, 0, heights);
 }