fremag
Junior Member
Posts: 73
Member is Online

Post by fremag on Mar 7, 2020 15:06:31 GMT
Hi,
Marching cubes is an algorithm to extract a triangle mesh of an isosurface from a scalar field.
Let's say you have a math function like this f(x, y, z,). An isosurface is the set of (x, y, z) points where (f(x, y, z) = V V is scalar constant defined by user.
Marching cubes will sample this isosurface and the result will be a list of triangles. Once you have the triangle list, you can find the points present in more than one triangle and compute an average normal for this point and then create some smooth triangles.
Here is an example with a metaball:
There was no OBJ file for this picture, only a math formula and the marching cubes algorithm.
More information:


madox
New Member
Posts: 22

Post by madox on Mar 8, 2020 21:26:56 GMT
Thats cool but isnt it more efficient to render objects as the nonmesh representation (since you have such a representation)? Did you implement marching cubes? And want to share your work? Also did you implement a metaball primative??


fremag
Junior Member
Posts: 73
Member is Online

Post by fremag on Mar 9, 2020 8:41:53 GMT
Please, define "efficient" I mean: I agree that rendering a mesh of triangles may be slower than a direct representation (it's obvious if you compare with a simple sphere). Not all surfaces have a representation you can solve to find instersection. The metaball for instance is a polynom wich degree increases with the number of balls / points and can be very costly to solve (there is no explicit formula for degree > 5). I found a page (in french) about metaballs.
The marching cube is generic, it works for any surface so I think it's more efficient in terms of code It's quite simple in my opinion, it relies on lookup tables to find the triangles to create and linear interpolation to find their position.
You can have a look at this code:
They both uses only basic features: "for" loops, arrays, etc that can translated in any language. You can check my code too (I've literally copy/paste Scrawk's code and modified it to add more object / class features so it's easier to use in my ray tracer)
As the main volume is sampled with small cubes, the triangles are not random as they are inside the cubes. I think it could be easy to group them in bigger boxes so it saves a lot of intersection checks (not tested yet).



Post by Jamis on Mar 14, 2020 21:28:23 GMT
Very cool! I've been curious about metaballs for a long time, but have never taken the time to dig into them. Thanks for the pointers!

