i am trying to apply a height map to sphere to hopefully create a planet like object at the end… (if you have any different ideas on how i can do this please leave a comment.thanks)
i put together a script but i am getting a Object reference not set to an instance of an object error
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
here is the script (btw im an artist not a programer. please dont judge my programming harshly)
var scale = 1.0;
var speed = 1.0;
var heightMap : Texture2D;
var material : Material;
function Update () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var width : int = Mathf.Min(heightMap.width, 255);
var height : int = Mathf.Min(heightMap.height, 255);
var y = 0;
var x = 0;
var vertices = mesh.vertices;
var uv = mesh.uv;
var tangents = new Vector4[height * width];
var size = gameObject.Vector3.Scale(200, 30, 200);
var uvScale = Vector2 (1.0 / (width - 1), 1.0 / (height - 1));
var sizeScale = Vector3 (size.x / (width - 1), size.y, size.z / (height - 1));
var pixelHeight = heightMap.GetPixel(x, y).grayscale;
var vertex = Vector3 (x, pixelHeight, y);
vertices[y*width + x] = Vector3.Scale(sizeScale, vertex);
uv[y*width + x] = Vector2.Scale(Vector2 (x, y), uvScale);
var vertexL = Vector3( x-1, heightMap.GetPixel(x-1, y).grayscale, y );
var vertexR = Vector3( x+1, heightMap.GetPixel(x+1, y).grayscale, y );
var tan = Vector3.Scale( sizeScale, vertexR - vertexL ).normalized;
tangents[y*width + x] = Vector4( tan.x, tan.y, tan.z, -1.0 );
mesh.vertices = vertices;
mesh.uv = uv;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
}