build123d icon indicating copy to clipboard operation
build123d copied to clipboard

Basic cone generates bugged geometry

Open MatthiasJ1 opened this issue 1 year ago • 4 comments

Cone(10, 0, 20)

Gives: Image

MatthiasJ1 avatar Feb 27 '25 21:02 MatthiasJ1

It seems like the problem may be in display and not in the object itself. If I do:

sections = [section(c, Plane.XY.offset(height)) for height in [8, 9, 9.5, 9.75]]

calculated_volume = pi * 10**2 * 20 / 3

print(calculated_volume, c.volume, abs(calculated_volume - c.
2094.3951023931954 2094.395102393195 4.547473508864641e-13

the volumes are the same and the sections look as follows:

Image

Any suggestion on how to isolate this to a build123d vs display problem?

gumyr avatar Mar 04 '25 00:03 gumyr

Any suggestion on how to isolate this to a build123d vs display problem?

F3D can open both .brep and .vtp files so you could compare the OCCT dump and the VTK conversion

from pathlib import Path
from build123d import Cone, export_brep
from build123d.vtk_tools import to_vtkpoly_string

cone = Cone(10, 0, 20)
export_brep(cone, "/tmp/cone.brep")
Path("/tmp/cone.vtp").write_text(to_vtkpoly_string(cone))

Triangulation looks ok on both .brep and .vtp files but they both show the same kind of issue near the tip which looks like it's due to the normals (not really sure what's up with that tho, F3D uses face normals from OCCT for the .brep, and the .vtp has normals computed by VTK on export via build123d).

On the build123d side, changing the FeatureAngle param to 90 seems to fix the tip artifact but the normals aren't smoothed as nicely everywhere https://github.com/gumyr/build123d/blob/e9c6b93cb70d7c8eab149330254ff7acab6e12ca/src/build123d/vtk_tools.py#L116

snoyer avatar Mar 05 '25 03:03 snoyer

When I "porcupine" the cone the normals all look good well into the zone that would have trouble:

Image

Does OCCT have some special logic when tessellating a cone to handle the tip? Maybe we're seeing an artifact of that.

gumyr avatar Mar 05 '25 14:03 gumyr

Looks like the cone itself is fine but there's something going on when exporting through VTK. For example, exporting to .vtp after changing the n_filter.SetFeatureAngle(360) line as mentioned in my earlier message I see (visualizing the Y-component of the normals because F3D doesn't do hedgehogs yet):

Image Image Image Image Image

with 360 (current default) and 180 there is a discontinuity at the tip and the reflection/highlight "bends" the same as in the original screenshot. With lower values this discontinuity goes away but the rest of the normals aren't as smooth.

snoyer avatar Mar 05 '25 14:03 snoyer