void PrepareVoxels() { //for each voxel above ISO, making sure neighboring lower voxels exist foreach (VoxelTree t in voxelStorage.GetEnumerable()) { Voxel v = t.Voxel; if (v == null) { Debug.Log("something is wrong, VoxelTree has null voxel"); continue; } //clear the stored triangle data used to compute voxel normal v.trianglesIndicies.Clear(); //create lower padding voxels as needed, so marching cubes will work correctly if (v.value > isolevel) { //neighboring 3 QueryCreateVoxel(v.xID - 1, v.yID, v.zID); QueryCreateVoxel(v.xID - 1, v.yID - 1, v.zID); QueryCreateVoxel(v.xID, v.yID - 1, v.zID); //lower four QueryCreateVoxel(v.xID, v.yID, v.zID - 1); QueryCreateVoxel(v.xID - 1, v.yID, v.zID - 1); QueryCreateVoxel(v.xID - 1, v.yID - 1, v.zID - 1); QueryCreateVoxel(v.xID, v.yID - 1, v.zID - 1); } } }
//IEnumerator and IEnumerable require these methods. public IEnumerable <VoxelTree> GetEnumerable() { if (leftTree != null) { foreach (VoxelTree n in leftTree.GetEnumerable()) { yield return(n); } } yield return(this); if (rightTree != null) { foreach (VoxelTree n in rightTree.GetEnumerable()) { yield return(n); } } }