private void Subdivide() { Vector3 oppositeBound = bound1 - bound0; Vector3 offset; // Creating the sub-cubes. for (int i = 0; i < 8; i++) { offset = GetOffset(bound0, oppositeBound, i); children[i] = new VertexTree(bound0 + offset, split + offset); } // Sending the vertices (and corresponding indices) to the correct sub-cubes. int childIndex; for (int i = 0; i < MAX_VERTICES; i++) { childIndex = GetChildIndex(vertices[i]); children[childIndex].AddVertexToLeaf(vertices[i], indices[i]); } // Now this cube is not a leaf anymore, but a node. // It must be cleared, and no more vertices should be added to it. vertices.Clear(); indices.Clear(); isLeaf = false; }
public ShapeLayer(int width, int height, GeomCoordinate centerCoordinate, int level) : base(width, height, centerCoordinate, level) { CoordinateTolerance = 0; _rVertexTree = new VertexTree(); _rCableTree = new CableTree(); }
public NetLayer(int width, int height, Coordinate centerCoordinate, int level) : base(width, height, centerCoordinate, level) { CoordinateTolerance = 0; _rVertexTree = new VertexTree(); _rCableTree = new CableTree(); }
public static MeshData Weld(int[] triangles, Vector3[] vertices, Vector3 b0, Vector3 b1) { Vector3[] verts = vertices; VertexTree vertexTree = new VertexTree(b0, b1); // Build new vertex buffer and remove "duplicate" verticies // that are within the given threshold. List <Vector3> newVerts = new List <Vector3>(); int vIndex = 0; foreach (Vector3 vert in verts) { // This adds the vertex to the tree, returns true if it was already there if (!vertexTree.FindOrAddVertex(vert, vIndex)) { newVerts.Add(vert); vIndex++; } } // Rebuild triangles using new verticies int[] tris = triangles; for (int i = 0; i < tris.Length; ++i) { // We need to find the index of the new vertex closest to verts[tris[i]] tris[i] = vertexTree.GetIndex(verts[tris[i]]); } int max = -1; foreach (int index in tris) { if (index > max) { max = index; } } MeshData result = new MeshData(); Debug.Log("GenerateMesh::AutoWeld > Number of new vertices in list, and max triangle index in new triangle array."); Debug.Log(newVerts.Count.ToString()); Debug.Log(max.ToString()); //Debug.Log(vertices.Length.ToString()); result.triangles = tris; // BEFORE VERTICES!!! result.vertices = newVerts.ToArray(); //mesh.uv = newUVs.ToArray(); return(result); }
private void ReadVertexes() { var vertexTree = new VertexTree(); vertexTree.LoadData(); try { _lockVr.EnterWriteLock(); _rVertexTree = vertexTree; } finally { _lockVr.ExitWriteLock(); } }
public void ClearData() { try { _lockCr.EnterWriteLock(); _rCableTree = new CableTree(); } finally { _lockCr.ExitWriteLock(); } try { _lockVr.EnterWriteLock(); _rVertexTree = new VertexTree(); } finally { _lockVr.ExitWriteLock(); } Update(new Rectangle(0, 0, Width, Height)); }
//static public Mesh CreateMesh(float[,,] voxels, int xStart, int xEnd, static public MeshData CreateMesh(float[,,] voxels, int xStart, int xEnd, int yStart, int yEnd, int zStart, int zEnd) { List <Vector3> verts = new List <Vector3>(); List <int> index = new List <int>(); float[] cube = new float[8]; int vXDim = voxels.GetLength(0); int vYDim = voxels.GetLength(1); int vZDim = voxels.GetLength(2); Vector3 lowerBound = Vector3.zero; Vector3 upperBound = new Vector3(vXDim, vYDim, vZDim); //Debug.Log("MarchingCubes::CreateMesh() > Creating the vertex tree: " + Time.time.ToString()); vertexTree = new VertexTree(lowerBound, upperBound); // Gaps otherwise if (xStart > 0) { xStart--; } if (yStart > 0) { yStart--; } if (zStart > 0) { zStart--; } for (int x = xStart; x < xEnd - 1; x++) { for (int y = yStart; y < yEnd - 1; y++) { for (int z = zStart; z < zEnd - 1; z++) { //Get the values in the 8 neighbours which make up a cube FillCube(x, y, z, voxels, cube); //Perform algorithm Mode_Func(new Vector3(x, y, z), cube, verts, index); } } } //Debug.Log("MarchingCubes::CreateMesh() > End of vertex tree creation: " + Time.realtimeSinceStartup.ToString()); // Mesh mesh = new Mesh(); MeshData mData = new MeshData(); // mData = GenerateMesh.AutoWeld(index.ToArray(), verts.ToArray()); mData.triangles = index.ToArray(); mData.vertices = verts.ToArray(); /* * if(mData.vertices.Length > 65000) { * //If you get this error its means that the voxels array contaions to much information and * //a mesh larger than 65000 verts is need to represent it. You can fix this by using a smaller arrays of voxel, * //make less 'noisey' data, or manually split up the mesh into sub meshes. * Debug.Log("MarchingCubes::CreateMesh - Number of mesh verts greater than 65000. Cannot create mesh"); * Debug.Log(mData.vertices.Length.ToString()); * return null; * } */ /* * Debug.Log("MarchingCubes::CreateMesh() > Number of vertices and triangles created:"); * Debug.Log(mData.vertices.Length.ToString()); * Debug.Log( (mData.triangles.Length / 3).ToString()); */ /* * mesh.Clear(); * mesh.vertices = mData.vertices; * mesh.triangles = mData.triangles; * * return mesh; */ return(mData); }