ShapeEditor
ShapeEditor copied to clipboard
feat: add CreateBrushFromPolygonMesh for direct half-edge brush creation
Summary
Adds ExternalRealtimeCSG.CreateBrushFromPolygonMesh() which builds a RealtimeCSG brush directly from a PolygonMesh by constructing the half-edge connectivity data (ControlMesh) and matching Shape/Surface/TexGen data, bypassing the plane-intersection approach which can fail on certain mesh topologies.
All 6 RealtimeCSGTarget rebuild methods now try the direct PolygonMesh path first and fall back to CreateBrushFromPlanes if validation fails.
What changed
- Added
CreateBrushFromPolygonMesh()inExternalRealtimeCSG.cs:- Builds unique vertex list from
PolygonMesh - Constructs
HalfEdge[]with proper twin associations - Creates
ControlMeshwith polygon/vertex/edge indices - Builds
Shapewith per-polygonSurface/TexGen/TexGenFlags - Validates via
ControlMeshUtility.Validatebefore creating brush - Falls back to plane-based
CreateBrushFromPlanesif validation fails
- Builds unique vertex list from
- All 6 rebuild methods (FixedExtrude, ScaledExtrude, RevolveExtrude, LinearStaircase, SplineExtrude, RevolveChopped) now try direct path first
Files changed
Scripts/Utilities/ExternalRealtimeCSG.cs— new methodScripts/Editor/Scene/RealtimeCSGTarget.*.cs— 6 rebuild methods updated
Validation
- Code compiles against Unity 2023.2 (C# 9 / .NET 4.7.2)
- Algorithm follows the half-edge construction pattern from the issue's reference prototype
- Fallback path preserved for degenerate mesh cases
Related issue
Fixes #3.