0
\$\begingroup\$

I'm doing some voxel based game, where I want to have voxel planets. I decided to use the marching cubes algorithm, and I successfully created a planet (even with noise) with the following density function:

"xx+yy+z*z -r - someNoiseFunction()" no problem there...

But as it comes to implementing chunks to my voxel planet, I run into some problems. I tried various things to "cut" my planet into parts but I wasn't successful. I tried copying the density values from the level array to some other chunk arrays, but somehow if I do that, the result is not what I was expecting. being more preceisly, the result was no mesh to a complete other mesh.

Now another idea came to my mind. With 3 FOR loops I could iterate through every voxel in the level array and check if it IS IN THE CHUNK, and check if it IS IN THE SPHERE. IF IT IS the density value it positive, if it IS NOT the density value is negative. so I could iterate through every chunk and in the end I have some chunks, which form my planet if I put them together... but before I spend another day coding some code which is maybe nonsense I might ask you guys what do you think about this idea, or are there better solutions for getting a sphere chunked with marching cubes?

\$\endgroup\$
  • \$\begingroup\$ You have to run the for loops on the chunk, not on the whole level. Only the chunk contains level data. \$\endgroup\$ – ElDuderino Jan 30 '17 at 13:25
0
\$\begingroup\$

no matter what you do you'll have to run through the triple for loop to set up the float values to input into the marching cubes. normally you would use some form of noise to create 2d/3d maps. in your case I would do something like define a size, and then change all blocks to positive if their absolute x,y,z values added together equal less than the size*1.43. I do that in 2d to tell my voxel chunks which should render around the player, otherwise the corner are way farther out than the center of the edges.

give each section a worldPoX, worldPosY, worldPosZ and then within it an x,y,z. use the worldPos values along with the chunkSize to determine where its personal cubes are.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.