I am developing a custom Make2D command using Rhino.Geometry.HiddenLineDrawing in C#. I have successfully implemented the standard hidden line drawing (Visible/Hidden curves), but I am stuck on getting Clipping Planes to work.
The Goal: I want to generate a 2D drawing of selected objects that respects the active Clipping Planes in the view, exactly like the native Rhino Make2D command does with “Clipping Plane Intersections” enabled.
The Issue: Even though I am adding the active clipping planes to the HiddenLineDrawingParameters and enabling OccludingSectionOption, the Compute method returns the full, uncut geometry. It acts as if the clipping planes do not exist.
What I have tried:
-
Checking that the Clipping Plane is active in the specific Viewport ID.
-
Setting
hldParams.OccludingSectionOption = true. -
Adding the plane using
hldParams.AddClippingPlane(plane). -
I have tried Global Clipping (implicit) and Selective Clipping using
hldParams.AddGeometryAndPlanes(...).
In all cases, the output is the complete object, ignoring the cut.
Code Snippet: Here is the core logic I am using to set up the parameters. Am I missing a step to “link” the planes to the view or the geometry?
public void CalculateMake2D(Rhino.Display.RhinoViewport viewport, List objects)
{
var hldParams = new HiddenLineDrawingParameters
{
AbsoluteTolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance,
IncludeTangentEdges = false,
IncludeHiddenCurves = true,
Flatten = true, // We want the 2D projection
OccludingSectionOption = true // Enabled for solid caps
};
hldParams.SetViewport(new ViewportInfo(viewport));
// 1. Find and Add Active Clipping Planes
List<Plane> activePlanes = new List<Plane>();
foreach (var obj in RhinoDoc.ActiveDoc.Objects.FindByObjectType(ObjectType.ClipPlane))
{
if (obj is ClippingPlaneObject cp && cp.ClippingPlaneGeometry.ViewportIds().Contains(viewport.Id))
{
// The plane is active in this view
var plane = cp.ClippingPlaneGeometry.Plane;
activePlanes.Add(plane);
// Register the plane
hldParams.AddClippingPlane(plane);
}
}
// 2. Add Geometry
foreach (var objRef in objects)
{
var geo = objRef.Geometry();
if (geo is Brep || geo is Mesh)
{
// Attempt 1: Selective Clipping (Explicitly passing the planes)
if (activePlanes.Count > 0)
{
// Using overload: (geometry, xform, id, occluding_sections, clips)
hldParams.AddGeometryAndPlanes(geo, Transform.Identity, objRef.ObjectId, true, activePlanes);
}
// Attempt 2: Standard Add (hoping for implicit global clipping)
else
{
hldParams.AddGeometry(geo, Transform.Identity, objRef.ObjectId, true);
}
}
}
// 3. Compute
// The result here contains all curves (Visible/Hidden) but NO intersection cuts
// and the geometry is fully drawn as if uncut.
var hld = HiddenLineDrawing.Compute(hldParams, true);
// ... Processing hld.Segments ...
}
