Advertisement
epitaque_

Untitled

Jan 27th, 2017
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. // Problem: A glitched-looking mesh is created http://i.imgur.com/0zSW4UU.png
  2.  
  3. // Also, sometimes, depending on the noise function, the ProcessCell call will create indices that are WAY out of bounds, like 268435455
  4.  
  5. // Mesh Generation Function
  6.         tree = new Isosurface.ManifoldDC.OctreeNode();
  7.         List<Isosurface.VertexPositionColorNormalNormal> vs = new List<Isosurface.VertexPositionColorNormalNormal>();
  8.         List<Isosurface.VertexPositionColorNormalNormal> VerticesDN = new List<Isosurface.VertexPositionColorNormalNormal>();
  9.  
  10.         tree.ConstructBase(100, 0, ref vs);
  11.         tree.ClusterCellBase(0);
  12.         tree.GenerateVertexBuffer(VerticesDN);
  13.  
  14.         List<int> indices = new List<int>();
  15.         List<int> tri_count = new List<int>();
  16.         tree.ProcessCell(indices, tri_count, 10.0f);
  17.  
  18.         MeshFilter mf = GetComponent<MeshFilter>();
  19.         MeshCollider mc = GetComponent<MeshCollider>();
  20.  
  21.         print("vs length: " + vs.Count); // 0
  22.         print("vertices length: " + VerticesDN.Count); // 14298
  23.  
  24.         int highest = 0;
  25.  
  26.         for (int i = 0; i < indices.Count; i++) {
  27.             indices[i] = indices[i] & 0xFFFFFFF;
  28.             if(indices[i] > highest) highest = indices[i];
  29.         }
  30.  
  31.         print("highest index: " + highest); // 14278
  32.  
  33.         // Actual mesh data that is rendered
  34.         Vector3[] vertices = new Vector3[VerticesDN.Count];
  35.         Vector3[] normals = new Vector3[VerticesDN.Count];
  36.  
  37.         for(int i = 0; i < VerticesDN.Count; i++) {
  38.             vertices[i] = VerticesDN[i].Position;
  39.             normals[i] = VerticesDN[i].Normal;
  40.         }
  41.  
  42.  
  43. // Noise Function (what is returned by Sampler.Sample)
  44.         public static float Noise(Vector3 pos)
  45.         {
  46.             float r = 0.013213f;
  47.             return Perlin.Noise(pos * r); // 3D Noise function that returns a value between -1 and 1
  48.         }
  49.  
  50. // Resulting, fragmented-looking mesh
  51. // http://i.imgur.com/0zSW4UU.png
  52.  
  53. // Github Repo
  54. // https://github.com/brianhoy/ManifoldDualContouring/tree/master/Assets/ManifoldDC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement