Grasshopper Mesh Rendering Preview in C#

unhandled
csharp
custom-preview
#1

Hi,
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

Best,
M

(David Rutten) #2

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

#4

From what I understand I need to implement a CustomMeshProvider as per this link (https://github.com/mcneel/rhino-developer-samples/blob/53f7108408fd4905e48bda566d15bd87458c7369/rhinocommon/cs/SampleCsRdk/TestCustomMeshProvider.cs) 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.

Best,

(David Rutten) #5

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

#6

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