public void prepareMesh(Direction direction) { vertices.Clear(); uvs.Clear(); triangles.Clear(); for (int i1 = 0; i1 < voxelGroup.getHighest(); i1++) { voxelRendered = new bool[voxelGroup.getHighest(), voxelGroup.getHighest(), voxelGroup.getHighest()]; for (int i2 = 0; i2 < voxelGroup.getHighest(); i2++) { for (int i3 = 0; i3 < voxelGroup.getHighest(); i3++) { int x = 0; int y = 0; int z = 0; switch (direction) { case Direction.UP: case Direction.DOWN: { x = i2; y = i1; z = i3; break; } case Direction.NORTH: case Direction.SOUTH: { x = i3; y = i2; z = i1; break; } case Direction.EAST: case Direction.WEST: { x = i1; y = i3; z = i2; break; } } Voxel voxel = voxelGroup.getVoxel(x, y, z); if (voxel == null) { continue; } if (shouldRenderVoxel(voxel, direction)) { Voxel originalVoxel = voxelGroup.getVoxel(x, y, z); VoxelFace[] voxelFaces = new VoxelFace[4]; VoxelFace voxelFace = originalVoxel.getVoxelFace(direction); voxelFaces[2] = voxelFace; voxelFaces[3] = voxelFace; int belowIncrease = 0; int nextIncrease = 0; while (getBelowVoxel(voxel, direction) != null) { Voxel lastVoxel = voxel; voxel = getBelowVoxel(voxel, direction); if (shouldRenderVoxel(voxel, direction) == false) { voxel = lastVoxel; break; } setRendered(voxel); belowIncrease++; } VoxelFace vf = voxel.getVoxelFace(direction); voxelFaces[0] = vf; voxelFaces[1] = vf; voxel = originalVoxel; bool exit = false; while (getNextVoxel(voxel, direction) != null && exit == false) { Voxel oriVoxel = getNextVoxel(voxel, direction); voxel = getNextVoxel(voxel, direction); if (shouldRenderVoxel(voxel, direction) == false) { break; } for (int bi = 1; bi <= belowIncrease; bi++) { if (getBelowVoxel(voxel, direction) != null) { voxel = getBelowVoxel(voxel, direction); if (shouldRenderVoxel(voxel, direction) == false) { exit = true; break; } } else { exit = true; break; } } if (exit == false) { voxel = oriVoxel; setRendered(voxel); for (int bi = 1; bi <= belowIncrease; bi++) { voxel = getBelowVoxel(voxel, direction); setRendered(voxel); } nextIncrease++; voxelFaces[2] = oriVoxel.getVoxelFace(direction); voxelFaces[1] = voxel.getVoxelFace(direction); voxel = oriVoxel; } } creatFace(voxelFaces, nextIncrease, belowIncrease); } } } } }
internal Voxel getRelative(VoxelGroup group, Direction direction) { Vector v = loc.add(direction.toVector()); return(group.getVoxel((int)v.getX(), (int)v.getY(), (int)v.getZ())); }