Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling arcs vs? Beziers curves in paths #2345

Open
PetitPhoenix opened this issue Jan 27, 2025 · 3 comments · May be fixed by #2354
Open

Handling arcs vs? Beziers curves in paths #2345

PetitPhoenix opened this issue Jan 27, 2025 · 3 comments · May be fixed by #2354

Comments

@PetitPhoenix
Copy link

Hello,

I use trimesh to generate STLs from various SVGs and it works great. My repository is generating tags based on various fonts and in the tag svg, I have arcs. When creating a mesh from this path, the one that has arcs is not watertight and has no volume:

shape_svg = trimesh.load_path(r'./inputs/shape.svg')
shape_svg.fill_gaps()
shape_mesh = shape_svg.extrude(3)

shape_ink_svg = trimesh.load_path(r'./inputs/shape_ink.svg')
shape_ink_mesh = shape_ink_svg.extrude(3)

Image
Image

In order to get the second one, I opened the first one in Inkscape and saved after changing the arcs in Bezier curves.

Wondering of there were limitations due to use in arc in paths or any special things to prepare my inputs.

Several parameters are very similar except the lenght:

Comparison:
bounds:
[[-17.49998212   0.        ]
 [ 80.          35.        ]]
-----===-----
[[-17.5   0. ]
 [ 80.   35. ]]


vertices:
[[  0.    0. ]
 [ 80.    0. ]
 [-17.5  17.5]
 [  0.   35. ]
 [ 80.   35. ]]
-----===-----
[[ -9.6649897   0.       ]
 [  0.          0.       ]
 [ 80.          0.       ]
 [-17.5         7.8350171]
 [-17.5        17.5      ]
 [-17.5        27.164983 ]
 [ -9.6649897  35.       ]
 [  0.         35.       ]
 [ 80.         35.       ]]


centroid:
[31.25000894 17.5       ]
-----===-----
[31.25 17.5 ]


length:
304.9557428756427
-----===-----
249.98557190148313


area:
3280.5362900551977
-----===-----
3281.159374448326


identifier:
[0.00000000e+00 3.28053629e+03 2.49963008e+02 3.28053629e+03
 2.49963008e+02 2.49963008e+02 2.42600946e+06 3.22584626e+05]
-----===-----
[0.00000000e+00 3.28115937e+03 2.49984680e+02 3.28115937e+03
 2.49984680e+02 2.49984680e+02 2.42724435e+06 3.22679987e+05]
@mikedh
Copy link
Owner

mikedh commented Jan 29, 2025

Hey, glad it's useful! Arcs should work fine assuming they're part of a closed contour. Does fill_gaps(distance=1.0) or some larger value work? Can you share the SVG that's failing?

@PetitPhoenix
Copy link
Author

Hello,

fill_gaps(distance=1.0) doesn't work and fill_gaps(distance=10) neither.

the source is just above but if you need it, the code is:

<svg xmlns="http://www.w3.org/2000/svg" width="97.5mm" height="35mm" viewBox="-17.5 0 97.5 35">

<path d="M 0 0 h 80 v 35 h -80 a 17.5 17.5 0 0 1 0 -35 z" fill="none" stroke="black" stroke-width="0.1" />
</svg>

mikedh pushed a commit that referenced this issue Feb 11, 2025
@mikedh
Copy link
Owner

mikedh commented Feb 11, 2025

It looks like it's the arc discretization not exactly matching the endpoints:


In [18]: p.discrete[0][[0,-1]]
Out[18]:
array([[ 0.00000000e+00,  0.00000000e+00],
       [-2.14313190e-15,  3.55271368e-15]])

1e-15 is below the trimesh threshold, but apparently above the earcut triangulation threshold. I added an endpoint snap to both bezier and 3-point arc discretization since both bezier curves and 3-point arcs start and end exactly on their control points and we don't have to approximate.

@mikedh mikedh linked a pull request Feb 11, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants