Created
February 13, 2017 22:54
-
-
Save davepape/31002e10c8c74f3f79ee0fa04d64fceb 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 | |
// Script to create a Unity mesh containing a sphere | |
// The sphere is warped with a sine wave pattern over time | |
var verts1 : Vector3[]; | |
function Start () { | |
gameObject.AddComponent(MeshFilter); | |
gameObject.AddComponent(MeshRenderer); | |
GetComponent(Renderer).material = new Material(Shader.Find("Custom/Vertex Colored")); | |
var m = GetComponent(MeshFilter).mesh; | |
var verts = Array(); | |
var cols = Array(); | |
var tris = Array(); | |
for (var j=0; j < 30; j++) | |
{ | |
var lat = (j/30.0)*Mathf.PI - Mathf.PI/2.0; | |
for (var i=0; i < 30; i++) | |
{ | |
var lon = (i/30.0)*2.0*Mathf.PI; | |
var p = Vector3(Mathf.Cos(lat)*Mathf.Sin(lon), Mathf.Sin(lat), Mathf.Cos(lat)*Mathf.Cos(lon)); | |
verts.push(p*4); | |
var c = Random.ColorHSV(); | |
cols.push(c); | |
} | |
} | |
for (j=0; j < 29; j++) | |
{ | |
for (i=0; i < 29; i++) | |
{ | |
var index = j*30 + i; | |
tris.push(index); | |
tris.push(index+1); | |
tris.push(index+30); | |
tris.push(index+1); | |
tris.push(index+31); | |
tris.push(index+30); | |
} | |
} | |
verts1 = verts; | |
m.vertices = verts; | |
m.colors = cols; | |
m.triangles = tris; | |
} | |
function Update () { | |
var m = GetComponent(MeshFilter).mesh; | |
var v = m.vertices; | |
var index=0; | |
for (var j=0; j < 30; j++) | |
{ | |
for (var i=0; i < 30; i++) | |
{ | |
v[index] = verts1[index]*(Mathf.Sin(Time.time*20+i*0.5+j)/20.0 + 1.0); | |
index++; | |
} | |
} | |
m.vertices = v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment