Greetings everyone,

I've been looking for spherical terrains, spherical heightmap and procedural planets.

All what i've got are just suggests on how to, without many examples or code easy to understand

(hell yes, i'm new in Unity). I combined two scripts i got on this website, my goal would be:

1) Generate a simple heightmap on a plane.

2) Morph it into a sphere.

The crappy code is here, if some guru can help would be very appreciated. Thanks.

Code:

// This script is placed in public domain. The author takes no responsibility for any possible harm. var heightMap : Texture2D; var material : Material; var collision : boolean; var numSegments: int; var numStrips: int; { } { // Create the game object containing the renderer if (material) renderer.material = material; else // Retrieve a mesh instance // The number of rings of vertices is one greater then the number of // horizontal strips and each ring has two vertices at the seam. var numYLevels = numStrips + 1; var numRingSteps = numSegments + 1; var y = 0; var x = 0; // Build vertices and UVs for (y=0;y<height;y++) { for (x=0;x<width;x++) { // Calculate tangent vector: a vector that goes from previous vertex // to next along X direction. We need tangents if we intend to // use bumpmap shaders on the mesh. } } // Assign them to the mesh mesh.uv = uv; // -------------------------------------------------------------------------------------------------------------- // Store the normalised X and Z values of a ring for repeated usage (this // saves a few Cos and Sin calls overall). var fracCircle: float; for (i = 0; i <= numSegments; i++) { fracCircle = (i * 1.0) / (numSegments * 1.0); } // Calculate the vertex positions from the parameter values. The vertex position // is the same as the normal vector multiplied by the radius and the UV is easily // obtained from the parameter values. for (l = 0; l <= numStrips; l++) { var fracArc = (l * 1.0) / (numStrips * 1.0); for (s = 0; s <= numSegments; s++) { fracCircle = (s * 1.0) / (numSegments * 1.0); var normVert = ring[s] * radFrac; normVert.y = yCoord; } } // -------------------------------------------------------------------------------------------------------------- // Build triangle indices: 3 indices into vertex array for each triangle var index = 0; for (y=0;y<height-1;y++) { for (x=0;x<width-1;x++) { // For each grid cell output two triangles } } // And assign them to the mesh // Auto-calculate vertex normals from the mesh // Assign tangents after recalculating normals // Assign collision if (collision == true) { } }