Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by husainh00 · Jan 24, 2014 at 06:34 AM · heightmapplanet

Applying HeightMap to a Sphere

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();
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ncortiz · Sep 27, 2015 at 04:55 PM

That's probably because you haven't assigned the heightmap or the material in the editor, so it's giving you a NullReferenceException.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

IcoSphere vs. Cube Sphere 0 Answers

Is it possible to generate a high-poly spherical model from a mercator-projection heightmap? 1 Answer

Efficient massive heightmap storage 0 Answers

import terrain from Photoshop 1 Answer

How to procedurally generate a super simple terrain 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges