Last active
October 7, 2015 04:19
-
-
Save davepape/4cebb43d091c6f3504e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
public var rows = 30; | |
public var cols = 30; | |
private var myVertices = Array(); | |
private var myColors = Array(); | |
private var myTriangles = Array(); | |
function Start () | |
{ | |
for (var i=0; i < rows; i++) | |
{ | |
for (var j=0; j < cols; j++) | |
{ | |
var lat = i/(rows-1.0) * Mathf.PI - Mathf.PI/2.0; | |
var lon = j/(cols-0.0) * Mathf.PI * 2.0; | |
var x = -Mathf.Cos(lon) * Mathf.Cos(lat); | |
var y = Mathf.Sin(lat); | |
var z = Mathf.Sin(lon) * Mathf.Cos(lat); | |
var radius = 5.0 + Random.value/5.0; | |
myVertices.push(Vector3(x*radius,y*radius,z*radius)); | |
var grey = Random.Range(0.5,0.75); | |
myColors.push(Color(grey,grey,grey)); | |
} | |
} | |
for (i=0; i < rows-1; i++) | |
{ | |
for (j=0; j < cols; j++) | |
{ | |
myTriangles.push(i*cols+j); | |
myTriangles.push(i*cols+(j+1)%cols); | |
myTriangles.push((i+1)*cols+j); | |
myTriangles.push((i+1)*cols+j); | |
myTriangles.push(i*cols+(j+1)%cols); | |
myTriangles.push((i+1)*cols+(j+1)%cols); | |
} | |
} | |
var m = GetComponent.<MeshFilter>().mesh; | |
m.vertices = myVertices; | |
m.colors = myColors; | |
m.triangles = myTriangles; | |
m.RecalculateNormals(); | |
} | |
function Update() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment