Scrawk/Marching-Cubes

Mesh generates above surface for one block thick!!

SpicyMelonYT opened this issue · 1 comments

Hi,

Sorry for asking for help again. Well this is more about bringing up an issue with the code. Basically I have found that in the positive x, y and z directions, a layer of "empty" will build as though its actually the ground.

Here is an image showing the problem areas:

Good side:
image_2022-06-20_153208885

Bad Side:
image

Everywhere you see BLACK or NOTHING is where there are air blocks in my game. Air blocks should be "above" the surface of the mesh since the mesh should be all the land in the world and not the air.

At first I thought this was a uv mapping issue since I build that part myself and assumed I must have poorly integrated something. However, I debugged block types for a 5 by 5 region of land and air and from that I can tell that the block is air blocks and not wrongly mapped land blocks like grass and dirt.

I believe this comes from the fact that a blocks generated section of the final mesh is not centered on the block position but rather the blocks position is the bottom-left-back corner of the block.

Would you happen to know how to fix this? I understand that when using the marching cubes code at large scale without textures, it seems fine. But for my game this is completely unusable if this stays in. Any fix is fine, even patchy/hacky fixes for the time being.

Please let me know if you need any clarification on the issue. I am more than happy to create some way to visualize the issue further!

Thank you!

For anyone seeing this in the future, its because Marching Cubes, unlike normal cubes, go from
x = 0 to max_x + 1,
y = 0 to max_y + 1,
z = 0 to max_z + 1

Cubes go from
x = -1 to max_x + 1,
y = -1 to max_y + 1,
z = -1 to max_z + 1

So for marching cubes the negative x, y, z don't get created since they march only in the positive directions, while for cubes you check if the density is 1 and if so create a face for every neightbour that's density is 0.