DrawViewportMeshes preview problem

Hi everyone!

I am working on a custom toolset for grasshopper and I have some custom parameters. I want to override the DrawViewportMeshes method that’s inherited from IGH_PreviewData (for the GH_GeometricGoo) to add more functionality, but I couldn’t even reproduce how a normal DrawViewportMeshes for a GH_Brep works.

My code produces previews like this:

But when I cast all the custom breps to normal GH_Breps, they look like this:

I tried playing with Depth Writing/Testing, Lighting, ClippingPlane, CullFaceMode methods (and DepthMode and ZBiasMode Properties) that are inside args.Pipeline and some of the DisplayMaterial properties. But I couldn’t figure out what they exactly do and how to solve this issue.

My preview was generated with this code:

public void DrawMeshes(GH_PreviewMeshArgs args)
{
args.Pipeline.PushCullFaceMode(Rhino.Display.CullFaceMode.DrawFrontAndBack);
if (this.Brep != null)
args.Pipeline.DrawBrepShaded(this.Brep, args.Material);
}

Thank you for your time
Ömer

(I noticed something that I should probably clarify:)
DrawMeshes method is located somewhere outside the GH_PersistentGeometry object that I want produce the previews for. Inside the DrawViewportMeshes method of that object, I only call this method (DrawMeshes method).

Hi again!

(For anyone who cares or who might care in the future) I might have gotten really close to finding a solution, and also might have discovered a bug?

After I posted my question, I found that DrawBrepShaded and DrawCurves (which I was using to display the Brep edges by iterating over Brep.Edges) was working very very (I mean very!!) slow. And producing Meshes from breps with Mesh.CreateFromBrep(brep, GH_PreviewMeshArgs.MeshingParameters) whenever the MeshingParameters are changed while storing the results and then calling DrawMeshShaded was much closer to a native Grasshopper Brep Parameter in terms of speed (FPS) and final Grasshopper preview.

But what I discovered was; whenever I would change the material I provide to DrawMeshShaded method or I alter the properties of GH_PreviewMeshArgs.Material, although the DepthMode of the DisplayPipeline doesn’t change, it doesn’t behave the same with when the non-altered GH_PreviewMeshArgs.Material is passed in to DrawMeshShaded. Although wire display seems to be fine, the parts of the geometry surface which are behind other geometries doesn’t seem to be colored at all; while geometries behind this geometry gets colored correctly. The same problem also can be seen with how the Custom Preview Component behaves.

This is the normal brep preview:

Custom parameter preview (2 different colors):


Custom Preview component (2 different colors):


I don’t think I am doing something wrong, because the only thing I am changing is the display material that’s passed in to the DrawMeshShaded method; and the custom preview component also seems to be showing a similar behavior? If this is a known problem I wonder if there is a workaround or maybe its fixed in the later versions?
(I tried this both on the Rhino 6.11.18 and 7.8.21 and the behavior was the same.)

Any help is appreciated

I also noticed something curious when I was digging around to find why this was happening. I produced a new material that’s exactly the same with the GH_PreviewMeshArgs.Material (that’s inside the IGH_PreviewData.DrawViewportMeshes) with all the same properties and checked and made sure if all the properties are the same (even the different textures). Although everything was the same, the only difference was a non-public member called “OneShotNonConstCallback”. While it was null for the material I produced, it had the value of:

Method = {Void b__0(System.Object, System.EventArgs)}}

At this point, I am way past my comfort zone with my C# and RhinoCommon knowledge, but maybe someone who is more knowledgeable could make a sense of this?