The Custom Preview component has lost shadows in Rhino 8

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.

Help me understand the problem.

test.3dm (816.4 KB)
test.gh (433.9 KB)
TestPreviewComponent.cs (4.8 KB)


Human plugin from @andheum


Native Custom Preview Component

I don’t see what the problem is right now.
I logged the issue here.

Ok, I have just a single test user of my plugin on R8 right and they get this error at least once an hour.

I may be using the Human preview components in GH, need to check into this further.

Cheers

DK

Hi @p-e-t-e-r,

This is what I get on Rhino 7. Is not same result as Rhino 8?

1 Like

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.

@p-e-t-e-r, my capture is on Rhino 7 and red previews (Human Custom Preview) are also “transparent” for shadows.

Is not the same issue you are reporting?

1 Like

Oh, really. Sorry, I didn’t notice that.

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.

I see,

Inheriting from GH_CustomPreviewComponent is kind of workaround but you are right it was broken on v8.0.

In theory you should not need to do anything on your side and your component will work again on the next Rhino RC.

2 Likes

Thank you very much, Kike! I will wait for the new version of the Rhino RC.

Hi guys, any idea of timeline for the RC that fixes this issue? I’d like to start testing.

Cheers

DK

The first version that will include this fix will be available as Rhino 8.5 Service Release Candidate on 13th February.

1 Like

OK, after downloading R8.5 this morning I got to do a quick test with my plugin.

More testing is needed but it looks like my display pipeline error has been fixed in this release.

Thanks team!

This should be the last issue with porting my code to R8 sorted.

Cheers

DK

2 Likes

I’m using the code posted by Petr (code below), and i’m on 8.5, but I still don’t see the the fix?


In artic mode it’s mono shade and no shadows

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);
}

@victorlin,

Does something like this works?

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);
}

Same result, does it matter that I’m targetting 7.0 nuget package but using it in Rhino 8?

There is no issue about using v7 nuget in this case.

I guess this is a mesh, can you try with a Brep?
I’m wondering if this is related to the mesh normals.

wrote a simplified component for breps, result is the same.

namespace SimplifiedColour
{
    public class SimplePreview : GH_CustomPreviewComponent
    {
        public SimplePreview()
        : base()
        {
            Name = "Render colour2";
            NickName = "Colour2";
            Description = "Colour";
            Category = "Robots";
            SubCategory = "Utility";
        }

        public override Guid ComponentGuid => new("{47AEFE2F-21CD-4F92-ABB5-14D136006102}");
        private readonly static Color lightBlack = Color.FromArgb(92, 92, 92);
        private BoundingBox _boundingBox;
        public override BoundingBox ClippingBox => _boundingBox;
        private List<GH_CustomPreviewItem> _items;

        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddBrepParameter("breps", "b", "breps to colour", GH_ParamAccess.list);
        }

        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddBrepParameter("breps", "b", "Coloured breps", GH_ParamAccess.list);
            pManager.AddColourParameter("Colour", "C", "", GH_ParamAccess.list);
        }

        protected override void BeforeSolveInstance()
        {
            _items = [];
            _boundingBox = BoundingBox.Empty;
        }
        override protected void AfterSolveInstance()
        { }

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<GH_Brep> breps = [];
            DA.GetDataList(0, breps);

            Color colors = lightBlack;
            DA.SetDataList(0, breps);
            DA.SetData(1, colors);

            foreach (GH_Brep brep in breps)
            {
                GH_Material material = new(colors);
                GH_CustomPreviewItem item = new()
                {
                    Geometry = brep,
                    Shader = material.Value,
                    Colour = material.Value.Diffuse,
                    Material = material,
                };
                _items.Add(item);
                _boundingBox.Union(brep.Value.GetBoundingBox(false));
            }
        }
        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]
        public override void AppendRenderGeometry(GH_RenderArgs args)
        {
            if (_items != null || _items.Count == 0)
                return;
            foreach (var item in _items)
                item.PushToRenderPipeline(args);
        }
    }
}

Hello, I have the same issue as @victorlin on Rhino 8 (SR6), Windows 11.
Rhino 8:

Rhino 7:

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…)

D_MyCustomPreviewComponent.cs (4.3 KB)

Hi @ale2x72,

Both issues will be fixed on the next RC of Rhino.

Thanks for reporting.

1 Like