Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt
Use this file to discover all available pages before exploring further.
GeometryCSG (in Prowl.Vector.Geometry) implements Constructive Solid Geometry (CSG) boolean operations on GeometryData meshes. Given two solid input meshes, it computes their set-theoretic combination — union, intersection, or subtraction — and returns the result as a new GeometryData object. UVs stored in the loop attribute "uv" are carried through the operation and interpolated correctly on split triangles.
Prerequisites: Triangulation
Both input meshes must be fully triangulated (every face must have exactly 3 vertices) before you call any CSG method. The internal algorithm works triangle-by-triangle and cannot handle quads or N-gons.The Operation Enum
PerformOperation, or use the dedicated convenience methods.
What each operation produces:
- Union (
A ∪ B) — all geometry that belongs to A or B. Overlapping interior surfaces are removed. The result is the combined outer hull. - Intersection (
A ∩ B) — only the geometry that is inside both A and B. The result is the shared volume. - Subtraction (
A − B) — geometry that is inside A but not inside B. B is carved out of A; the faces of B that lie inside A are flipped and retained as the inner walls of the cavity.
Methods
General entry point
| Parameter | Type | Description |
|---|---|---|
operation | Operation | Union, Intersection, or Subtraction |
meshA | GeometryData | First operand (must be triangulated) |
meshB | GeometryData | Second operand (must be triangulated) |
GeometryData containing the result. Neither input mesh is modified.
Union
meshA and meshB with interior surfaces removed.
Intersect
meshA and meshB.
Subtraction
meshA with the volume of meshB carved out of it (meshA − meshB). Faces of meshB that form the interior cavity walls are flipped and included in the result.
Complete Example
Using PerformOperation at Runtime
Triangle Data Helper
GeometryCSG exposes a public helper for reading triangle vertex and UV data from a face:
GetTriangleData throws InvalidOperationException if the face is not a triangle. UVs are read from the loop attribute named "uv" if it exists; otherwise Float2.Zero is used.
Performance Notes
The CSG algorithm is O(n²) in the number of triangles: every triangle in mesh A is tested against every triangle in mesh B to find intersections. This is accelerated by an AABB-based BVH (Bounding Volume Hierarchy) that skips pairs whose bounding boxes do not overlap, but the worst case for two highly overlapping meshes remains quadratic. Practical guidance:- CSG is well-suited to edit-time operations such as level design, tool brushes, or asset baking.
- Avoid calling CSG methods per-frame in a real-time render loop, especially with high-resolution meshes.
- Keep input meshes as low-poly as possible for interactive CSG. Subdivide the result afterward if detail is needed.
- For animated CSG (as in the demo), pre-cache the base meshes and only re-run the operation when the overlap changes significantly.