Rhino Bug: HiddenLineDrawing.Compute

Hi,
I’ve got a huge issue with the latest Rhino releases: the result of HiddenLineDrawing.Compute().segments is not computed anymore, or rather the output is missing:

HiddenLineDrawingSegment.parentcurve => nothing
HiddenLineDrawingSegment.geometry => unsolved

It used to work perfectly with rhino 6 SR9, and it fails with SR14 or later releases. I also tried to force compilation with various rhinocommon versions, but it does not change the issue so Rhino itself has most probably something wrong.

Here is a more detailed sample of code, based on @dale exemple:

Dim HLDParam As New Rhino.Geometry.HiddenLineDrawingParameters
            HLDParam.AbsoluteTolerance = doc.ModelAbsoluteTolerance
            HLDParam.Flatten = True
            HLDParam.IncludeHiddenCurves = True
            HLDParam.IncludeTangentEdges = False
            HLDParam.IncludeTangentSeams = False
            HLDParam.AddClippingPlane(New Plane(Plane.WorldZX) With {.OriginY = Y})
            For Each obj In doc.Objects
                HLDParam.AddGeometry(obj.Geometry, obj.Attributes)
            Next
            HLDParam.SetViewport(viewport)
 Dim HLD As HiddenLineDrawing = Rhino.Geometry.HiddenLineDrawing.Compute(HLDParam, False)
If HLD Is Nothing Then Exit Sub
For Each HLD_Segment As HiddenLineDrawingSegment In HLD.Segments
Dim attr As ObjectAttributes = TryCast(HLD_Segment.ParentCurve.SourceObject.Tag, ObjectAttributes).duplicate
Dim c As Curve = HLD_Segment.CurveGeometry.DuplicateCurve()
...
Next

@rajaa, can you help with this?

@Matthieu_from_NAVINN
I’d like to run your code at my end, can you share more information?
Do you have the Rhino document you are using?
Are you in perspective view?
Is this part of a plugin, or you are running it inside a GH scripting component?
Thanks

Hi @rajaa, it is part of a plugin, with ParallelProjection of Front view. I’ve met the issue with various geometries, including a simple rectangular volume.

I’ve done many tests today and it seems the issue comes from HLDParam.AddClippingPlane(). If I disable this I don’t have these null outputs. Do you know if any changes has been made in Rhino’s recent releases that would impact the clipping planes? Because my code used to work before.

My best guess would be that sometimes objects are computed even when they are on the ‘OFF’ side of the clipping plan, and they end up being Null results.

I can’t send you the plugin since the code is owned by my final user, but I’ll try to do a basic plugin sample.

It looks as if all your objects are behind the clipping plane. If you switch the direction of your clipping plane, does that make any difference?

The following in an example to Compute HLD that uses ClippingPlanes for your reference. It work at my end with the latest release.

//HLD Sample with Clipping Planes
      var _go = new GetObject();
      _go.SetCommandPrompt("Select objects to test Make2D Points");
      _go.GeometryFilter = ObjectType.Point | ObjectType.Surface | ObjectType.PolysrfFilter;
      _go.GroupSelect = true;
      _go.GetMultiple(1, 0);
      if (_go.CommandResult() != Result.Success)
        return _go.CommandResult();
      var _obj_refs = _go.Objects();
      var _view = doc.Views.ActiveView;
      //Set Make2D Parameters
      var _hld_params = new HiddenLineDrawingParameters
      {
        AbsoluteTolerance = doc.ModelAbsoluteTolerance,
        IncludeTangentEdges = false,
        IncludeHiddenCurves = true
      };
      _hld_params.SetViewport(_view.ActiveViewport);

      //add objects to hld_param
      foreach (var obj_ref in _obj_refs)
      {
        if (null == obj_ref)
          continue;
        var obj = obj_ref.Object();
        if (null == obj)
          continue;
        _hld_params.AddGeometry(obj.Geometry, Transform.Identity, obj.Id);
      }

      //Add active clipping planes
      var clipping_planes = doc.Objects.GetObjectsByType<ClippingPlaneObject>().ToArray();
      foreach (var clipping_plane in clipping_planes)
      {
        if (clipping_plane.ClippingPlaneGeometry.ViewportIds().Contains(_view.ActiveViewport.Id))
        {
          var plane = clipping_plane.ClippingPlaneGeometry.Plane;
          plane.Flip();
          _hld_params.AddClippingPlane(plane);
        }
      }

      //perform HLD calculation
      var _hld = HiddenLineDrawing.Compute(_hld_params, true);
      if (_hld != null)
      {
        //transform and add to doc
        var flatten = Transform.PlanarProjection(Plane.WorldXY);
        BoundingBox page_box = _hld.BoundingBox(true);
        var delta2D = new Vector2d(0, 0);
        delta2D = delta2D - new Vector2d(page_box.Min.X, page_box.Min.Y);
        var delta3D = Transform.Translation(new Vector3d(delta2D.X, delta2D.Y, 0.0));
        flatten = delta3D * flatten;
        //add curves to doc
        var h_attribs = new ObjectAttributes();
        h_attribs.Name = "H";
        h_attribs.ColorSource = ObjectColorSource.ColorFromObject;
        h_attribs.ObjectColor = System.Drawing.Color.Cyan;
        var v_attribs = new ObjectAttributes();
        v_attribs.Name = "V";
        var cv_attribs = new ObjectAttributes();
        cv_attribs.Name = "CutV";
        cv_attribs.ColorSource = ObjectColorSource.ColorFromObject;
        cv_attribs.ObjectColor = System.Drawing.Color.Red;
        var ch_attribs = new ObjectAttributes();
        ch_attribs.Name = "CutH";
        ch_attribs.ColorSource = ObjectColorSource.ColorFromObject;
        ch_attribs.ObjectColor = System.Drawing.Color.Pink;
        foreach (HiddenLineDrawingSegment hld_curve in _hld.Segments)
        {
          if (hld_curve == null || hld_curve.ParentCurve == null || hld_curve.ParentCurve.SilhouetteType == SilhouetteType.None)
            continue;
          var crv = hld_curve.CurveGeometry.DuplicateCurve();
          if (crv != null)
          {
            crv.Transform(flatten);
            if (hld_curve.SegmentVisibility == HiddenLineDrawingSegment.Visibility.Visible)
            {
              if (hld_curve.ParentCurve.SilhouetteType == SilhouetteType.SectionCut)
                doc.Objects.AddCurve(crv, cv_attribs);
              else
                doc.Objects.AddCurve(crv, v_attribs);
            }
            else if (hld_curve.SegmentVisibility == HiddenLineDrawingSegment.Visibility.Hidden)
            {
              if (hld_curve.ParentCurve.SilhouetteType == SilhouetteType.SectionCut)
                doc.Objects.AddCurve(crv, ch_attribs);
              else
                doc.Objects.AddCurve(crv, h_attribs);
            }
          }
        }
        //add points to doc
        foreach (HiddenLineDrawingPoint hld_pt in _hld.Points)
        {
          if (hld_pt == null)
            continue;
          var pt = hld_pt.Location;
          if (pt != null)
          {
            pt.Transform(flatten);
            if (hld_pt.PointVisibility == HiddenLineDrawingPoint.Visibility.Visible)
              doc.Objects.AddPoint(pt, v_attribs);
            else if (hld_pt.PointVisibility == HiddenLineDrawingPoint.Visibility.Hidden)
              doc.Objects.AddPoint(pt, h_attribs);
          }
        }
      }
      return Result.Success;

Here is the result using simple example where the current or active viewport is the “Perspective” viewport where the Clipping Plane is applied there.

1 Like

Thanks @rajaa I’ll give it a try as soon as I have some time. What bothers me is that it used to work before, so there must have been a change somewhere in Rhino that caused the issue somehow.