Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: A glitched-looking mesh is created http://i.imgur.com/0zSW4UU.png
- // Also, sometimes, depending on the noise function, the ProcessCell call will create indices that are WAY out of bounds, like 268435455
- // Mesh Generation Function
- tree = new Isosurface.ManifoldDC.OctreeNode();
- List<Isosurface.VertexPositionColorNormalNormal> vs = new List<Isosurface.VertexPositionColorNormalNormal>();
- List<Isosurface.VertexPositionColorNormalNormal> VerticesDN = new List<Isosurface.VertexPositionColorNormalNormal>();
- tree.ConstructBase(100, 0, ref vs);
- tree.ClusterCellBase(0);
- tree.GenerateVertexBuffer(VerticesDN);
- List<int> indices = new List<int>();
- List<int> tri_count = new List<int>();
- tree.ProcessCell(indices, tri_count, 10.0f);
- MeshFilter mf = GetComponent<MeshFilter>();
- MeshCollider mc = GetComponent<MeshCollider>();
- print("vs length: " + vs.Count); // 0
- print("vertices length: " + VerticesDN.Count); // 14298
- int highest = 0;
- for (int i = 0; i < indices.Count; i++) {
- indices[i] = indices[i] & 0xFFFFFFF;
- if(indices[i] > highest) highest = indices[i];
- }
- print("highest index: " + highest); // 14278
- // Actual mesh data that is rendered
- Vector3[] vertices = new Vector3[VerticesDN.Count];
- Vector3[] normals = new Vector3[VerticesDN.Count];
- for(int i = 0; i < VerticesDN.Count; i++) {
- vertices[i] = VerticesDN[i].Position;
- normals[i] = VerticesDN[i].Normal;
- }
- // Noise Function (what is returned by Sampler.Sample)
- public static float Noise(Vector3 pos)
- {
- float r = 0.013213f;
- return Perlin.Noise(pos * r); // 3D Noise function that returns a value between -1 and 1
- }
- // Resulting, fragmented-looking mesh
- // http://i.imgur.com/0zSW4UU.png
- // Github Repo
- // https://github.com/brianhoy/ManifoldDualContouring/tree/master/Assets/ManifoldDC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement