Grasshopper Mesh Rendering Preview in C#

I am trying to create look out of my component similar to the one from the Custom Preview Component. As you can see from my images below, my geometry is transparent is not casting shadows. Any ideas on how I should be doing it?

public override void DrawViewportMeshes(IGH_PreviewArgs args)
    if (BuildingGeometries == null) { return; }
    Material material = new Material();
    material.ReflectionColor = Color.LightGray;
    Rhino.Display.DisplayMaterial renderMaterial = new Rhino.Display.DisplayMaterial(material);

    foreach (Brep brep in BuildingGeometries)
        Mesh[] meshes = Mesh.CreateFromBrep(brep, MeshingParameters.Default);
        foreach (Mesh mesh in meshes)
            args.Display.DrawMeshShaded(mesh, renderMaterial);

Custom Preview

My Current Preview


Custom Preview does not use the display pipeline to draw geometry, in rendered viewports it will add meshes to the rendering pipeline.

From what I understand I need to implement a CustomMeshProvider as per this link ( After that, I will need to run BuildCustomMeshes method in order to append the geometry to the render view.

If that is the case, I have been trying to extract the RenderPrimitiveList object from a RhinoObject but I am getting null values. Here is a simple snippet of me trying to get the RenderPrimitiveList. When I run this command I do have an active view with Render view on.

//Get Rhino Object
List<RhinoObject> objects = Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(typeof(ExtrusionObject)).ToList();
RhinoObject rhinoObject = objects.First();

//Get View information
Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;
ViewportInfo viewportInfo = new ViewportInfo(view.ActiveViewport);            
Rhino.Display.DisplayPipelineAttributes displayPipelineAttributes = view.DisplayPipeline.DisplayPipelineAttributes;

//Get Render mesh
int number = rhinoObject.CreateMeshes(MeshType.Render, new MeshingParameters(), true);
Mesh[] meshes = rhinoObject.GetMeshes(MeshType.Render);

//Get RenderPrimitiveList
bool willRender = rhinoObject.SupportsRenderPrimitiveList(viewportInfo, displayPipelineAttributes);
RenderPrimitiveList renderPrimitiveList = rhinoObject.GetRenderPrimitiveList(viewportInfo, displayPipelineAttributes);

Any help would be much appreciated.


@andy can you help out? You know more about this api and how to use it correctly than anyone else.

Some help here? I am also interested in using the rendered view from GH components.

Nope - you just need to create a class derived from CustomMeshProvider, give it a public constructor and you should find that your BuildCustomMeshes function is called automatically.

In the case of Grasshopper meshes, you should only supply meshes when RenderPrimitiveList.RhinoObject is null.