Marching Cubes "Fun"

Started by
12 comments, last by thelordposeidon 6 years ago

So the only difference between mine and scrawks code seems to be the code below.

Scrawk's code :


//Get the values in the 8 neighbours which make up a cube
                        for (i = 0; i < 8; i++)
                        {
                            ix = x + VertexOffset[i, 0];
                            iy = y + VertexOffset[i, 1];
                            iz = z + VertexOffset[i, 2];

                            Cube[i] = voxels[ix + iy * width + iz * width * height];
                        }

 

My code :


private static boolean checkIfExpose(Voxel[][][] voxels, int x, int y, int z, float[] cube) {

		Voxel[] surroundingVoxels = getSurroundingVoxels(voxels, x, y, z);
		boolean bool = false;

		for (int i = 0; i < cube.length; i++) {
			cube[i] = 0;
		}

		if (surroundingVoxels[0].getMaterial().equals(VoxelMaterial.Air)) {

			cube[0] = 1f;
			cube[1] = 1f;
			cube[4] = 1f;
			cube[5] = 1f;
			bool = true;

		}

		if (surroundingVoxels[1].getMaterial().equals(VoxelMaterial.Air)) {

			cube[0] = 1f;
			cube[3] = 1f;
			cube[4] = 1f;
			cube[7] = 1f;
			bool = true;

		}

		if (surroundingVoxels[2].getMaterial().equals(VoxelMaterial.Air)) {

			cube[4] = 1f;
			cube[5] = 1f;
			cube[6] = 1f;
			cube[7] = 1f;
			bool = true;

		}

		if (surroundingVoxels[3].getMaterial().equals(VoxelMaterial.Air)) {

			cube[0] = 1f;
			cube[1] = 1f;
			cube[2] = 1f;
			cube[3] = 1f;
			bool = true;

		}

		if (surroundingVoxels[4].getMaterial().equals(VoxelMaterial.Air)) {

			cube[1] = 1f;
			cube[2] = 1f;
			cube[5] = 1f;
			cube[6] = 1f;
			bool = true;

		}

		if (surroundingVoxels[5].getMaterial().equals(VoxelMaterial.Air)) {

			cube[2] = 1f;
			cube[3] = 1f;
			cube[6] = 1f;
			cube[7] = 1f;
			bool = true;

		}

		return bool;
	}

Bare in mind my code is Java and his is C#. If anyone has any ideas, please let me know. Here's a link to the file overall : here

Edit : when I print out the value of a single cube to be rendered (a grid of 1 x 1 x 1) the corners all return 1, shouldn't that mean they are to be rendered?

Advertisement

I have a C++ Marching Cubes code if you want to look at it:

https://github.com/sjhalayka/marching_cubes

Unfortunately I can't read c++, I try and fail miserably, but thanks for the code. I'll see if anyone I know can talk me through it.

This topic is closed to new replies.

Advertisement