dima634 / baby_shark

Geometry processing library in pure rust
MIT License
64 stars 7 forks source link

Remesh of cube causes rounding of cube edges #30

Closed Nevsden closed 4 months ago

Nevsden commented 4 months ago

Using the remeshing algorithm on a simple cube, I would assume that the remeshing holds the property of "keeping the vertex position" of the original mesh, meaning in case of a simple cube, that the edges of the cube stay sharp. In the example voxel_remeshing using the asset cube.stl, the corners come out rounded.

I used a voxel grid size of 0.5. Maybe my idea about the algorithm does not align with what the algorithm actually does.

image

Lowering the grid size makes the remeshed mesh come closer to the edges.

dima634 commented 4 months ago

Voxel re-meshing converts mesh into a distance field and back to mesh using the marching cubes algorithm. MC is not preserving sharp features so cube corners are smoothed.

thelazyone commented 4 months ago

@Nevsden the only way you can preserve the vertices is by applying a voxel remesh which is a fraction of the cube size. It's a rare event "in the wild" but happens regularly when starting with a brand new cube (1 or 2 m side) and applying a new remesh (usually 0.1 m).

In the example below, a remesh of 0.5 and 0.4 for the cube: even though the former is less fine it preserves the vertexes, while the latter smooths it.

image

It's a sampling problem, the only way to solve this is to change the remeshing into something more sophisticate.

Nevsden commented 4 months ago

@thelazyone thank you! That is a great explanation. The issue can be closed.