Skip to content

Show primitive mapping in the Mesh Boolean examples - #6817

Merged
Fedr merged 3 commits into
masterfrom
examples-boolean-mapper
Sep 9, 2026
Merged

Fedr merged 3 commits into
masterfrom
examples-boolean-mapper

Conversation

@Fedr

@Fedr Fedr commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Nothing in the examples demonstrated BooleanResultMapper — the way to relate faces, vertices and edges of the input meshes to the primitives of the boolean result.

All five language variants (C++, C, Python, C#, JavaScript) now pass a mapper to the operation and use it to report:

  • the faces of the result produced by each input mesh, and the faces the cut itself created (map over the inputs' valid faces, newFaces);
  • one particular face of the first input mesh mapped forward to the faces of the result it produced — the cut can split one input face into several, or drop it entirely;
  • a face of the result mapped back to the input face it came from, via getNew2OldFaceMap.

For the two spheres in the examples that prints:

faces from sphere1: 2670
faces from sphere2: 2670
faces created by the cut: 1344
face 793 of sphere1 produced 4 faces of the result: 8542 8543 8544 8545
face 8542 of the result came from face 793 of sphere1

Fix in getNew2OldFaceMap

Writing the reverse example surfaced an off-by-one: the map was sized maxNewFace (the largest new face id) rather than maxNewFace + 1, so outMap[nf] = of for that largest id wrote one element past the end of the vector — an assert in a Debug build, an out-of-bounds write in Release — and the returned map never contained the entry for the last mapped face. For the spheres above, the last face of the result coming from A is 8863 while the map's size was 8863; it is now 8864 and that face resolves to its origin, 7199.

No test asserted on the size of the returned map, so nothing else changes.

Docs

  • doxygen/examples/MeshBoolean.dox mentions the mapper and the reverse map above the tabs.
  • MR::BooleanResultMapper's doc comment now shows the two new C++ snippets (markers 1 and 2), the same way MR::boolean shows marker 0.

Verification

  • The C++ example compiles and links against a locally built MRMesh (with the fix) and prints the output above; the reverse lookup of the last A face was checked separately against both the old and the new sizing.
  • The Python example prints the same numbers with the installed meshlib wheel.
  • The C example compiles clean (cl /W3) against the generated MeshLibC2 headers.
  • The C# and JS variants mirror API usage already covered by MRDotNet2Test/src/BooleanTests.cs, MRWasmTest/booleanMapper.test.mjs and the neighbouring examples (FaceBitSet.fromIndices, FaceMap.toArray, the using disposal style).

CI: ubuntu-x64 (C++ and C examples, MRTest) and windows (C# examples) are enabled; the other platforms are disabled.

All five Mesh Boolean examples now pass a BooleanResultMapper to the
operation and use it to report which faces of the result came from each
input mesh and which ones the cut created.
Fedr added 2 commits September 9, 2026 15:51
Every Mesh Boolean example now maps one particular face of the first input
mesh to the faces of the result it produced, and maps a face of the result
back to the face it came from via getNew2OldFaceMap.

getNew2OldFaceMap sized its output as the largest new face id instead of
that id plus one, so it wrote one element past the end of the vector and
never returned the entry for the last mapped face.
@Fedr
Fedr requested a review from Grantim September 9, 2026 13:26
@Fedr
Fedr merged commit 18c53bb into master Sep 9, 2026
37 checks passed
@Fedr
Fedr deleted the examples-boolean-mapper branch September 9, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants