Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

Mesh Normal

$
0
0
So, i am working on a script what reads terrain data values and makes them into a mesh, i can do it fine with voxels, but when it comes to just pretty much printing the heightmap into a mesh, it has these weird " normal " issues, does this look right? is it actually the normals causing this? or could it be something else? ![alt text][1] The flat parts are fine, its the slopes which seem to have normal issues. Here is my script i am using : void renderExternalHeightmap() { Generator noise; RidgeNoise temperature = new RidgeNoise(83573); PinkNoise noiseMod = new PinkNoise(32562356); temperature.Lacunarity = 0.9f; temperature.Frequency = 0.01f; temperature.Offset = 1.2f; // sharpness temperature.OctaveCount = 8; noiseMod.Lacunarity = 0.9f; noiseMod.Frequency = 0.01f; noiseMod.Persistence = 1.2f; // sharpness noiseMod.OctaveCount = 8; noise = noiseMod; int X, Y, Z; X = BaseClass.WORLD_CHUNK_DIMENSION_X * BaseClass.WORLDCHUNK_LOADED_LIMIT_X; Y = BaseClass.WORLD_CHUNK_DIMENSION_Y * BaseClass.WORLDCHUNK_LOADED_LIMIT_Y; Z = BaseClass.WORLD_CHUNK_DIMENSION_Z * BaseClass.WORLDCHUNK_LOADED_LIMIT_Z; List triangles = new List(); List vertices = new List(); List uvs = new List(); int index = 0; // index used for triangle work around for (int i = 0; i < 50; i++) { for (int j = 0; j < 1; j++) { for (int k = 0; k < 50; k++) { vertices.Add(new Vector3(i - 0.5f, Mathf.FloorToInt(noise.GetValue(i - 0.5f, 0.5f, k + 0.5f) * temperature.GetValue(i - 0.5f, 0, k + 0.5f)), k + 0.5f)); vertices.Add(new Vector3(i + 0.5f, Mathf.FloorToInt(noise.GetValue(i + 0.5f, 0.5f, k + 0.5f) * temperature.GetValue(i + 0.5f, 0, k + 0.5f)), k + 0.5f)); vertices.Add(new Vector3(i + 0.5f, Mathf.FloorToInt(noise.GetValue(i + 0.5f, 0.5f, k - 0.5f) * temperature.GetValue(i + 0.5f, 0, k - 0.5f)), k - 0.5f)); vertices.Add(new Vector3(i - 0.5f, Mathf.FloorToInt(noise.GetValue(i - 0.5f, 0.5f, k - 0.5f) * temperature.GetValue(i - 0.5f, 0, k - 0.5f)), k - 0.5f)); triangles.Add(index + 0); triangles.Add(index + 1); triangles.Add(index + 2); triangles.Add(index + 0); triangles.Add(index + 2); triangles.Add(index + 3); index += 4; } } } Mesh mesh = GetComponent().mesh; Vector4[] tangents = new Vector4[vertices.Count]; for (int i = 0; i < vertices.Count; i++) { uvs.Add(new Vector2(vertices[i].x, vertices[i].z)); } mesh.Clear(); mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); mesh.uv = uvs.ToArray(); mesh.tangents = tangents; mesh.RecalculateNormals(); mesh.Optimize(); } [1]: http://i.imgur.com/OdlW5Dq.png

Viewing all articles
Browse latest Browse all 827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>