Create RenderMaterial from DisplayMaterial

Is there a way to create a RenderMaterial or Material from a DisplayMaterial using Rhinocommon?

I’ve created a DisplayMaterial to customize the visualization of objects in a GH_Component by overriding DrawViewportMeshes(IGH_PreviewArgs args). Now I want to override the baking behavior of the component, and turn the DisplayMaterial into a Material (or RenderMaterial, not sure what the difference is?), add it to the document’s MaterialTable and finally assign the material index to the objects attributes. The end result should be that the baked object has the material that was previewed in GH_Component assigned to it.

Any clue? Am I missing anything?

1 Like

How to cast RenderMaterial to DisplayMaterial. Did you find the answer?
I know that can be done because CustomPreview component can load .rmtl.

Nope, I’m still looking for a solution to this.

What I find so far. DocObjects.Material is the base.Both RenderMaterial and DisplayMaterial can cast from it. but I don’t know how to cover RenderMaterial back to DocObjects.Material.

1 Like
DocObjectsMaterial doesn’t have any Method can directly take RenderMaterial or .rmlt. or .xml.

This post mentioned need to transfer material properity by each.
Once get DocOBjectMaterial done, use “var dm = new Rhino.Display.DisplayMaterial(DocObject.Material);”

@andy and/or @nathanletwory - is this something you can help with?

1 Like

As @zhuangjia777 mentions you can get a DisplayMaterial from a Material by using the correct constructor.

A material you can get from a RenderMaterial by using RenderMaterial.SimulatedMaterial()

I have been searched the answer around. I think the conclsion can be made so far. The conclusion is that IGH_PreviewArgs interface doesn’t have rendering method, it only draw shaded.

So the only way that you can render your geometry without bake it, is to use “custom preview” component.


And when you use the Custom Preview component you should use the RenderMaterial approach as I explained in Now you can select rhino material in grasshopper - #9 by nathanletwory

1 Like