Grasshopper Raytraced Display Pipeline

I am trying to build a custom preview component with some functionality not currently covered by either the standard GH Custom Preview or Andrew’s Custom Preview Materials. However, I can’t figure out how to add geometry to the render pipeline in Arctic, Raytraced, or Rendered views. The AppendRenderGeometry(...) override is marked as obsolete in VS and none of the breakpoints inside that method ever get hit. Been searching online to see what replaces it, but came away empty-handed. As expected, simply calling DrawViewportMeshes(...) when in raytraced mode results in a weirdly distorted Shaded preview.

Here is how three preview components look in Shaded mode. All good here:

But then here is what they look like in Arctic:

And here’s the Raytraced:

Since Human also breaks in these render modes, I am guessing the way of interacting with Rhino’s Display Pipeline has changed since the introduction of Cycles. But I couldn’t find any documentation about leveraging it from Grasshopper. Any suggestions are greatly appreciated.

Thanks!

To work in these modes you need to give Rhino render meshes.

Your component needs to implement the IGH_RenderAwareData Interface . On it you’ll find the IGH_RenderAwareData.AppendRenderGeometry Method, through which you’ll receive an instance of GH_RenderArgs Class. On it there is the GH_RenderArgs.Geomety Property which gives you a RenderPrimitiveList Class which is where you can add the mesh for your object with the RenderMaterial Class you have been given via GH_RenderArgs.

Thanks for the prompt reply @nathanletwory! I’ve implemented the interface, however, I’m not hitting any breakpoints inside of the new method either. I imagine it’s not meant to be called manually, right? Anything else I might be missing?

Here’s what I did. This is supposed to simply draw bounding boxes for now (as a quick test):

public void AppendRenderGeometry(GH_RenderArgs args, RenderMaterial material)
{
    if (this._previewItems != null)
    {
        foreach (GH_CustomPreviewItem item in this._previewItems)
        {
            var geometricGoo = item.Geometry as IGH_GeometricGoo;
            if (geometricGoo != null)
            {
                MeshingParameters parameters = new MeshingParameters(0.5);
                args.Geomety.Add(Mesh.CreateFromBrep(geometricGoo.Boundingbox.ToBrep(), parameters).FirstOrDefault(), material);
            }
        }
    }
}

Regardless of whether or not this is properly implemented, this method is never hit for some reason

It will be hit when you connect it to Custom Preview component, which essentially is the trigger to ask for render meshes.

Hmm. I’m not entirely sure what you mean by “connect it to Custom Preview component”. I implemented the interface in the custom preview component that I am writing, as you suggested:

// The preview component I am writing
public class MyCustomGeometryPreview : GH_Component, IGH_RenderAwareData
{
    private List<GH_CustomPreviewItem> _previewItems;

    // Lots of your regular GH component code here...

    public void AppendRenderGeometry(GH_RenderArgs args, RenderMaterial material)
    {
       // See my previous message for implementation
    }
}

Since AppendRenderGeometry method is public, I imagine that it is triggered by something outside of the component itself. Like whatever goes on in Rhino / Grasshopper when you switch to a raytraced view for example. But when I plug in geometry, switch to Arctic, and spin around, the AppendRenderGeometry method does not get hit for whatever reason. So my component being an implementation of IGH_RenderAwareData doesn’t seem to be enough to trigger it. I’m clearly missing something here haha

Hmm. As far as I understand it a component that is connected to the Custom Preview will be queried by Grasshopper for the render geometry, which it will do through the AppendRenderGeometry. This is how the Custom Preview component gets the render meshes with rendermaterials to pass on to Rhino for use in Arctic, Rendered and Raytraced modes.

If you want to do whatever the custom preview does you’ll have to do that yourself. I think you’ll have to use the CustomMeshProvider2 , but I’m not entirely sure how that should go. Either @andy or @DavidRutten are probably better here to answer you.

1 Like

Solved off-screen by @andy and @DavidRutten. If anyone else comes across the same issue, the solution was to directly inherit from GH_CustomPreviewComponent and then override the AppendRenderGeometry(GH_RenderArgs args) method.

2 Likes