- Home /
Rounding edges of cubes (Voxels and Marching Cubes)
Hello,
Over the passed few weeks I have been playing around with a voxel based engine as a pet project. More of a learning exercise. I recently discovered marching cubes and how interesting the algorithm is!
Long-story short, I do not quite understand the marching cube algorithm enough to modify it to reproduce this effect: http://www.youtube.com/watch?v=3FuS8PYj2TM
I am using binary voxel data, so my implementation gives this effect: http://www.youtube.com/watch?v=9B9_tNRavs4
Please note neither of those videos are my own!
Would anyone please be able to enlighten me?
Thanks!
Sorry, I have implemented a marching cubes algorithm from http://paulbourke.net/geometry/polygonise/ and adapted it to work with my array of voxels. The array is just a 3-dimensional array of structs holding a "block type". The block is either transparent, or not. I do not have any videos I captured myself, but the ones above show what I have and what I would like to have.
To achieve the desired effect would I have to make changes to the edge and triangle look up tables? Or would I be modifying the way the algorithm interpolates vertex locations?
I hope this was more specific.
I don't understand the problem I think... If you implemented marching cubes and you want your voxel data to be changeable, just change your voxel data(block type array) and recreate the mesh...
If that's not your problem, you need to explain better
$$anonymous$$y problem is that my implementation of marching cubes look as shown in the first video I posted. The second video shows a completely different effect from the algorithm. I am wanting to get this effect as shown in the second youtube video.
Answer by HappyMoo · Jan 09, 2014 at 03:03 AM
Well, first of all, I think your text above links movies in the wrong order. I think you want to get the effect you see in the russian video, but you text says you have that effect and want the other one.
Anyway... the effect you see in the russian video isn't vanilla marching cubes. One can clearly see that they get arbitrary angles, which marching cubes can't do. Marching cubes look like this:
http://upload.wikimedia.org/wikipedia/commons/6/63/Marchingcubes-head.png
As you see, only certain angles are generated
Now, if what this is about is the effect that you apply some effect to the voxel field and you get kind of a melting away effect, where the material is pushed away slowly, this can be achieved, but every single angle on the small voxel cubes will still be kind of blocky like in the picture I showed.
First: Don't use binary voxels... don't just store 0 for air or 1 for solid... store a float between 0 and 1 and have a threshold value - 0.5 for starters - to interpret the voxel as air or solid.
This threshold value can also be animated by the way, which gives nice effects. Raise it, to only show denser material or lower it, to also show less dense material.
For this to be visible at all, you need a good a good scalar field to play with - something that does not only have 0 or 1, but values in between and it needs to be somewhat coherent when you move through it.
So grab your favorite 3D noise function and initialize your scalar field - the unity Perlin noise isn't good enough, because it's only 2D.
I recommend this for a simple single-file drop-in solution:
http://code.google.com/p/simplexnoise/source/browse/trunk/SimplexNoise/Noise.cs
But watch out - this returns values between 1 and -1, so scale it accordingly to get [0..1]
Now - the above should be no problem for you, you only have to change your code where you check for voxelvalue==1 to check for voxelvalue>threshold
Once you have the above, make the threshold changeable on the fly and see how the mesh gets recreated. On the fly is important here... you want to see it in the same scalar field, not a new one after you restart with a new threshold.
If you got that far, now the melting effect can be achieved by not setting the values directly in the scalar field when you click with your mouse, but use subtractive smooth brushes - e.g. define a brush with a radius of 6 and a falloff of the brush value from 1 in the middle to 0 at distance=6 from the middle point.
Now if you click somewhere, you subtract the brush value for every voxel it overlaps. You can multiply the brush value with 0.05 or something like that, if it'S to fast to see.
Now with this brush, your density values will slowly melt away till they fall below the threshold and pop out of existance.
Thank you for the great explanation! Although, the videos above are the correct order. I would like the more "cube" like effect of the first video. I can (and already have) the effect achieved in the Russian video. I am also able to get a very smooth terrain by using floating point values as you suggest. I switched to using binary voxel data in hopes of getting a more cubic effect, but again I now have something that looks like the Russian video.
then it should be easy to get the effect by directly making 1 block holes in your data. Do you really get the arbitrary angles like in the russian video? How so? You know marching cubes has a static list of geometry it can copy into the scene, so there should be no arbitrary angles.
Or did you both implement a variant of marching cubes that does this?
I implemented the marching cubes algorithm based off of http://paulbourke.net/geometry/polygonise/ All I did was slightly modify it to accept accept boolean values.
Also, wouldn't creating 1 block holes cause a checkerboard like pattern? I would imagine it would if I was getting the effect I am looking for.
I also downloaded this marching cubes plugin http://scrawkblog.com/2013/04/01/marching-cubes-plugin-for-unity/ and modified it slightly to accept 0 and 1, this causes the same effect I currently have (the same as the Russian video).
EDIT: I noticed in the first video (my desired effect) that the poster of the video says that "It's marching cubes, just using vertices in simple averaged locations ins$$anonymous$$d of smoothed. I did this intentionally because I wanted symmetric, geometric terrain rather than a smoothed or realistic look. $$anonymous$$C supports doing it either way, I just chose the less common method." I am not quite sure where he did this.
Are you using any kind of smoothing or grid resolution?
I just skimmed the code, but I find it strange that they are interpolating (VertexInterp). Basic marching cubes as I understood it, just copies over the defined triangles and doesn't change them in any way. $$anonymous$$aybe they do this to make it smoother.
Can you create some screenshots of what your implementation renders? $$anonymous$$aybe with some basic patterns, like a 5x5x5 block and alternating 0/1 blocks or alternating 00/11 etc in all dimensions.
That is what I thought my problem was, the implementation shown here http://paulbourke.net/geometry/polygonise/ also interpolates, and this is the version I implemented from. I figured from what the owner of the YouTube video said about averaging locations it may have something to do with this interpolation step.
Your answer
Follow this Question
Related Questions
How to remove small & thin triangles from a marching cubes voxel engine? 2 Answers
Generating scalar field for a sphere 1 Answer
How can I smoothen my cubic mesh using marching cubes? 0 Answers
Introduction to Voxels and More 2 Answers
How to mix different amplitudes and frequencies when procedurally generating terrain? (Perlin Noise) 0 Answers