The component inherits GH_CustomPreviewComponent and overrides the AppendRenderGeometry method.
I followed the recommendations of @andy and @DavidRutten in the thread @enmerk4r
However, this does not work, the debugger does not hit the breakpoint, and the AppendRenderGeometry method is not called. I suspect something has changed in Rhino 8. The component worked fine in Rhino 7, but stopped working correctly in Rhino 8.
I have attached a test cs file of the Component, as well as 3dm and gh files of the test scene.
Thanks for the answer, @kike
Yes, everything works fine in Rhino 7. But in Rhino 8, the Preview component of the Human plugin does not work correctly, just like the Component of my plugin.
Ok, in that case, how to solve the problem with shadows in the Custom Preview Component? In Rhino 7, I was helped by inheriting the GH_CustomPreviewComponent class and overriding the AppendRenderGeometry method. In Rhino 8 this no longer works.
and in raytraced, it completely disappears @kiteboardshaper it’s working for you? are you doing anything in addition to what i’m doing below?
Am I missing something?
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
if (this.Locked || _items.Count == 0)
return;
if (this.Attributes.Selected)
{
GH_PreviewMeshArgs args2 = new(args.Viewport, args.Display, args.ShadeMaterial_Selected, args.MeshingParameters);
foreach (GH_CustomPreviewItem item in _items)
item.Geometry.DrawViewportMeshes(args2);
return;
}
foreach (GH_CustomPreviewItem item in _items)
{
GH_PreviewMeshArgs args2 = new(args.Viewport, args.Display, item.Shader, args.MeshingParameters);
item.Geometry.DrawViewportMeshes(args2);
}
}
[Obsolete] // For Rhino 7
public override void AppendRenderGeometry(GH_RenderArgs args)
{
GH_Document gH_Document = OnPingDocument();
if (gH_Document != null && (gH_Document.PreviewMode == GH_PreviewMode.Disabled || _items != null || _items.Count == 0 || gH_Document.PreviewMode == GH_PreviewMode.Wireframe))
return;
foreach (var item in _items)
item.PushToRenderPipeline(args);
}
public override void AppendRenderGeometry(GH_RenderArgs args)
{
// You don't need to check Preview Mode,
// this method is only called when Grasshopper shows meshes so only in Shaded.
//
//GH_Document gH_Document = OnPingDocument();
//if (gH_Document is null) return;
//if (gH_Document.PreviewMode != GH_PreviewMode.Shaded) return;
if (_items is null) return;
foreach (var item in _items)
item.PushToRenderPipeline(args);
}
See the attached code (it’s basically the same, I only use a shader parameter for the material, but as you can see it works fine on Rhino 7. Also, still bugged by the fact that Rhino 8 ground plane ignores Grasshopper geometry preview…)