Skip to content

Make exact: seams between rounded faces, a ring as one torus, and budgetMs held (#1245) - #2048

Open
marcus040473 wants to merge 3 commits into
henmedia:mainfrom
marcus040473:make-exact-seams-torus
Open

marcus040473 wants to merge 3 commits into
henmedia:mainfrom
marcus040473:make-exact-seams-torus

Conversation

@marcus040473

Copy link
Copy Markdown
Contributor

Summary

Follows up on your measurements on #1245 (Make exact on meshes the kernel made itself). All three points had one root: a triangle went to whichever face reached it first, as long as its corners were within the tolerance. Where two surfaces both fit, that is not enough, and a finer mesh made it worse.

  • Rounded box (60 x 40 x 20 mm, 5 mm, 34,356 triangles): a rounded edge and the rounded corner it runs into lie within the tolerance of each other for about 0.14 mm past their seam. On a fine mesh the seam came out ragged, the faces did not close, and every curved face was given up for facets. Now each triangle at such a seam goes to the neighbour its corners lie on clearly better, and the surfaces are fitted again. The box comes out as its 26 faces (6 planes, 12 cylinders, 8 spheres) in about 5 s instead of 33,493 faces in 101 s.
  • Ring (radii 20 and 6 mm): a band round the tube lies exactly on a sphere, so the ring came out as 72 spheres. Where a sphere, cylinder or cone stops in the middle of a smooth area, a torus is now fitted to it and what lies round it, and taken when it grows further. A torus that goes all the way round its tube is also cut along the plane the ring lies in; such a face could not be built before. The ring is one torus face at 6,048, 40,572 and 180,936 triangles (0.4, 0.9 and 4 s).
  • budgetMs: it now counts from the start and also holds a growing face, the joining of neighbouring faces and the building of the solid. Joining asked the same fit at every edge two faces share (4.5 of 5.1 s on the ring); it is one answer for a pair now. With 2 s given, the ring of 180,936 triangles returns after about 2.5 s.
  • No false success: when the surfaces are given up and the solid would be more than a face for every two triangles, there is no result and the mesh stays.

Testing

  • npm run typecheck
  • npm test (6542 passed)
  • Manually tested the affected workflow (not tried in the editor, only through the kernel tests)
  • tests/e2e/cadMeshExact.e2e.ts (20 passed), with new tests for your cases: the fine rounded box as 26 faces, the ring, half a ring with flat ends, the fine ring, and the time limit with a budget that is too short on purpose.
  • Also run: cadMeshExactWorker, stepExportMesh, hullTangentEdges e2e (green). I did not run the whole e2e suite, npm run guide or npm run i18n:status; there are no new texts.

Notes

  • Touches meshSurfaceSegments.ts, meshSurfaceTopology.ts and cadMeshExact.ts only. No changelog entry; tell me if you want one from me.
  • The first tolerance now has half of the search time and the looser ones what is left (before: a third each), and a quarter of budgetMs is kept for the solid.
  • Still open: when the time runs out the message is still "mostly free-form", not "out of time". Your exact meshes of 127,008 and 201,558 triangles I did not rebuild; I measured 180,936 (ring) and 50,468 (sphere).
  • Showing the triangles before and after in the tool is not in here.

…body would be a face per triangle (PR henmedia#1245)

Stefan's measurements on meshes the kernel made itself:
- A box of 60 x 40 x 20 mm with every edge rounded by 5 mm, finely meshed (34,356 triangles), came back after 101 s
  as 33,493 faces and counted as a success. Its faces are found, but they do not close; every curved one was then
  given up for facets and the mesh built over again. Now there is no result when that would be more than a face for
  every two triangles (7 s), and the mesh stays.
- budgetMs only held the search for seeds. It now counts from the start and holds a growing face, the joining of
  neighbouring faces and the building of the solid; the search has three quarters of it.
- Joining neighbouring faces asked the same fit at every edge two faces share: on a ring found as 72 bands that was
  4.5 of 5.1 s. One answer for a pair now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U6NM2HskD8K3V9JHzW1FGv
henmedia#1245)

A rounded edge and the rounded corner it runs into lie within the tolerance of each other for a little way past
their seam (0.14 mm for a 5 mm rounding at 2 µm). Whichever face grew first took that strip; on a fine mesh, whose
triangles are smaller than it, the seam came out ragged: splines where circles are, slivers taken for cones, and
faces that did not close. Stefan's box of 60 x 40 x 20 mm rounded by 5 mm (34,356 triangles) ended as facets.

After the faces are found, each triangle at such a seam goes to the neighbour its corners lie on clearly better, the
surfaces are fitted again without what was not theirs, and the faces are joined once more. The box now comes out as
its 26 faces (6 planes, 12 cylinders, 8 spheres) in about 5 s.

A later tolerance's try also has only the time the earlier ones left.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U6NM2HskD8K3V9JHzW1FGv
Stefan's ring (radii 20 and 6 mm) came out as 72 spheres with 6,048 triangles and as mostly free-form with more: a
band round the tube lies on a sphere exactly (two of the tube's circles always do) and nearly on a cylinder, and a
torus fitted to the few triangles round a seed did not stand against them.

- Where a sphere, cylinder or cone stops in the middle of a smooth area, a torus is fitted to it and what lies round
  it, and taken when it grows further.
- A torus that goes all the way round its tube (a ring, an elbow) is cut along the plane the ring lies in as well: a
  face with two of the tube's circles for its outline could not be built.
- The first tolerance has half of the search time, the looser ones what is left: with 8 s the ring's face of
  180,936 triangles was cut off at 2 s while growing.
- Taking small pieces into a neighbour added up the neighbour's triangles for each piece; along a half-grown face
  that took longer than the search. Its area and side are kept now.

The ring is one torus face at 6,048, 40,572 and 180,936 triangles (0.4, 0.9 and 4 s).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U6NM2HskD8K3V9JHzW1FGv
@henmedia

Copy link
Copy Markdown
Owner

@marcus040473 thanks, that was quick! I compared it with the old code on 24 bodies in three mesh densities, with a budget of 20 seconds, and the result is much better. The rounded box and the ring come out as you describe, a quarter of the ring as 3 faces instead of 10,048, and every solid that came back is valid.

One thing before I merge: some coarse meshes gave a solid made of facets before and give no result now. These are a sphere (520 triangles), a capsule (386), two fused spheres (736 and 2,830), a filleted cone (828) and a ring (1,512). I think it is the new check for more than a face for every two triangles. From the code, the STEP export would then leave such a body out. Such small bodies took 1 to 6 seconds before, so could the check apply only to larger meshes?

Two smaller things, they don't have to be in this PR:

  • The box of 60 × 40 × 20 mm with 1 mm rounding (9,460 triangles) still comes out as 6,969 faces and took 32 seconds with 20 given.
  • The same box with 9 mm rounding (2,212 triangles) has 28 faces now instead of 26.

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 this pull request may close these issues.

3 participants