Some polylines are missing in rendered mode

Dear McNeel Team,

We have found that some polylines sent by DrawEventArgs.Display.DrawPolyline() in our DisplayConduit are missing in Rendered mode when there is a layer (containing Brep, Curve, Point objects) also being visualised at the same time. In other modes such as wireframe and shaded there is no such problem.

The polylines will be displayed as expected if we turn off the layer or uncheck “Shadows On” in View->Display Options->Rendered->Shadows.

Is there a known problem in Rhino? And do you suggest any other workarounds to prevent this from happening?

Hi @yung-yuan can you share a model and sample code we can run that demonstrates this issue?

Hi @Gijs,

Sorry for late response.

I attached Stock.3dm file.
Stock.3dm (56.0 KB)

The issue should be able to be reproduced by open the 3dm file, then draw a polyline with a display conduit: here is the sample code:

    private class EntryClass
    {
         static void Main(string[] args)
        {
            SimpleDisplayConduit conduit = new SimpleDisplayConduit();
            conduit.Enabled = true;
            RhinoDoc.ActiveDoc.Views.Redraw();
        }
    }

    public class SimpleDisplayConduit : Rhino.Display.DisplayConduit
    {
        private Polyline polyline;

        public SimpleDisplayConduit()
        {
            polyline = new Polyline();

            polyline.Add(0, 0, 0);
            polyline.Add(0, 20, 0);
            polyline.Add(20, 20, 0);
            polyline.Add(20, 40, 0);
        }

        protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
        {
            BoundingBox box = new BoundingBox();
            foreach (var pt in polyline)
            {
                box.Union(pt);
            }
            e.IncludeBoundingBox(box);
        }

        protected override void PreDrawObjects(DrawEventArgs e)
        {
            e.Display.DrawPolyline(polyline, Color.Black, 1);
        }
    }

I tested the code with project template and the issue is repeated:
testReadDocument.zip (47.9 KB)

you could open Stock.3dm, install the plugin, and run testReadDocumentCommand.
Please make sure that rendered display option is set as default.

Please let me know if there is more infomation needed. Thank you.

Best regards,
Yung-Yuan Chen

Hi @Gijs,

Is the issue reproducible with the sample code in the plugin template?

Best regards
Yung-Yuan Chen

hi @yung-yuan Looks I totally missed that reply, my apologies,

looking into it right now.

looks like you are drawing the polyline in PreDrawObjects, try PostDrawObjects instead:

Hi @Gijs,

Yes, PostDrawObjects() works in rendered mode. I investigated the reason that we use PreDrawObjects() instead and wonder if you can provide some suggestion for our use case:

We decided to use PreDrawObjects() because we also draw polylines in the area of stock mesh, which is not visible in the ghosted mode if we use PostDrawObjects() with the following code.

protected override void PostDrawObjects(DrawEventArgs e)
{
polyline2 = new Polyline();
polyline2.Add(30, 40, -20);
polyline2.Add(40, 50, -10);
e.Display.DrawPolyline(polyline2, Color.Black, 1);
}

For fulfilling all use cases, We might use Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode.LocalName to decide using pre or post draw. Does it meet the conduit concept of Rhino? Or We can also check if the polylines are in the bounding box of the mesh object.

Best regards
Yung-Yuan Chen

hmm, I don’t follow what you mean with that. What does ‘in the area of stock mesh’ mean?

If you want to be sure that what you draw gets in front, you could also use DrawForeground.

As mentioned on the docs for PostDrawObjects:

Called after all non-highlighted objects have been drawn. Depth writing and testing are still turned on. If you want to draw without depth writing/testing, see DrawForeground.

Hi, sorry to confuse you due to some imprecise term. I mean we are drawing polylines inside the bounding box of the model.( the red one in the screenshot, the model mentioned here is stock.3dm uploaded before)

Our expected behaviour is the polyline is blocked by the model, and we can only see it in ghosted display mode.To achieve it, we used PreDrawObjects().

For the unexpected behaviour in rendered mode, which is the first question in the discussion, we might use PostDrawObjects() to fix it, but we lose the polyline inside the model in this case.

To showing the checked cases in the screenshot below, my idea is that I can decide to draw polyines in PreDrawObjects/PostDrawObjects with the if condition using display mode. Or by checking if the polyline overlapped with the model. (I think the first idea makes more sense, but not quite sure if I missed anything from display conduit perspective and might cause any further issue)

I tried DrawForeground()/EnableDepthWriting(false), but the polyline is too clear that it is not that easy to tell that it is actually covered by the model.

I see what you mean.

I’d simply do both instead of using an if statement based on display mode. That seems to work here:

        protected override void PostDrawObjects(DrawEventArgs e)
        {
            e.Display.DrawPolyline(polyline, Color.Black, 1);
            e.Display.DrawPolyline(polyline2, Color.Red, 2);
        }

        protected override void PreDrawObjects(DrawEventArgs e)
        {
            e.Display.DrawPolyline(polyline, Color.Black, 1);
            e.Display.DrawPolyline(polyline2, Color.Red, 2);
        }

1 Like