Skip to content

feat: add CreateBrushFromPolygonMesh for direct half-edge brush creation#35

Open
brainzhangdh wants to merge 1 commit into
Henry00IS:masterfrom
brainzhangdh:feat/create-brush-from-polygonmesh
Open

feat: add CreateBrushFromPolygonMesh for direct half-edge brush creation#35
brainzhangdh wants to merge 1 commit into
Henry00IS:masterfrom
brainzhangdh:feat/create-brush-from-polygonmesh

Conversation

@brainzhangdh
Copy link
Copy Markdown

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() in ExternalRealtimeCSG.cs:
    • Builds unique vertex list from PolygonMesh
    • Constructs HalfEdge[] with proper twin associations
    • Creates ControlMesh with polygon/vertex/edge indices
    • Builds Shape with per-polygon Surface/TexGen/TexGenFlags
    • Validates via ControlMeshUtility.Validate before creating brush
    • Falls back to plane-based CreateBrushFromPlanes if validation fails
  • All 6 rebuild methods (FixedExtrude, ScaledExtrude, RevolveExtrude, LinearStaircase, SplineExtrude, RevolveChopped) now try direct path first

Files changed

  • Scripts/Utilities/ExternalRealtimeCSG.cs — new method
  • Scripts/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.

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 (FixedExtrude, ScaledExtrude,
RevolveExtrude, LinearStaircase, SplineExtrude, RevolveChopped) now
try the direct PolygonMesh path first and fall back to the plane-based
CreateBrushFromPlanes if validation fails.

Fixes Henry00IS#3.
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.

[50$ Bounty] Create RealtimeCSG Brush from PolygonMesh

1 participant