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:
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 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
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.
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.
@enmerk4r Would you care to share the code implementation for the component in this image? I think I understood the logic and I am trying to do the same, without any luck. Not sure what I am missing…
EDIT: I got it, it was ok from the get-go, I only forgot to put the Rhino view in Rendered mode…