deadsy / sdfx

A simple CAD package using signed distance functions
MIT License
533 stars 52 forks source link

Hollowing #54

Closed Megidd closed 1 year ago

Megidd commented 1 year ago

Playing around with the hollowing example.

deadsy commented 1 year ago

Weird artifacts at the top of the model. There are probably bugs in the SDF calculation for an STL mesh. Even so - I understood that the original model was clean (based on beziers) so I don't understand the assymmetric weirdness around the lid. Screenshot_20221027_055837

I switched to uniform marching cubes for a better render.

Megidd commented 1 year ago

@deadsy That's right. The weird artifacts are observed by me too.

Megidd commented 1 year ago

Observation with Octree MarchingCubes

My original input STL is this:

Screenshot_20221027_155942

The inside of the input model carved out by the following statement is:

inside := sdf.Offset3D(imported, -wallThickness) // Pass negative value for inside.
render.ToSTL(inside, "inside-carved-out.stl", render.NewMarchingCubesOctree(300))

Screenshot_20221027_160651

Problem

The problem is that the rendered mesh has some artifacts. Like missing polygons.

Screenshot_20221027_161018

deadsy commented 1 year ago

Nominally the octree and uniform renderers should produce the same result. If you have code where the SDF is not computed exactly (E.g. screw threads) then the octree renderer shows errors (missing polygons) while the uniform renderer is typically ok because it gets in closer to the surface.

That's what is happening here - There are some concavities that the uniform renderer shows up while the octree renderer leaves gaps.

General thoughts:

1) I didn't write ImportSTL :-). I haven't done much with it. I suspect it has bugs for some cases.

2) Are the artefacts coming from the model? I'd probably rotate a few bezier curves, do the offset and see what it looks like.

Megidd commented 1 year ago

Observation with Uniform MarchingCubes

@deadsy Right :+1: Now, the inside mesh is a bit messed up, but no polygon is missing. That's good enough for our use cases which is hollowing 3D models. Because, no body is actually able to see the inside of a 3D model. They just want to hollow it out :slightly_smiling_face:

Screenshot_20221027_165004