I have simple question regarding materials in render preview via grasshopper (custom preview component).
How can I display breps or meshes with a reflective or shiny material?
If I just create custom material in grasshopper, it only changes color.
You can only create very basic materials through the components, back when they were written things like reflection weren’t supported in the display at all so there was no point to them.
If you want the advanced stuff, right now you have to make a material in Rhino and reference it by name.
Yes, probably the next release candidate. Previews are back to the way they used to be, except for Custom Preview components. They now either draw previews in non-render viewports, or they add meshes+materials (no curves or points) to render viewports.
ps. Here’s a C# script which allows you to create metal like materials: metil_or_normil.gh (8.0 KB)
It must be, because that’s how Custom Preview works.
DisplayPipeline.DrawMeshShaded() takes a Rhino.Display.DisplayMaterial as an argument.
If you have a RenderMaterial instead of a DisplayMaterial, then you can generate the latter from the former by using the SimulateMaterial() method:
var dmat = new DisplayMaterial(RenderMaterial.SimulateMaterial(true))
It does not show up in render preview.
What I did wrong between these lines:
private void RunScript(Mesh x, ref object A)
{
bbox.Union(x.GetBoundingBox(false));
Material material = new Material();
material.ReflectionColor = Color.Gray;
material.DiffuseColor = Color.Gray;
material.AmbientColor = Color.Black;
material.EmissionColor = Color.Black;
material.Reflectivity = 0;
material.ReflectionGlossiness = 1;
Rhino.Render.RenderMaterial renderMaterial = Rhino.Render.RenderMaterial.CreateBasicMaterial(material);
Rhino.Display.DisplayMaterial m_ = new Rhino.Display.DisplayMaterial(renderMaterial.SimulateMaterial(true));
this.m = m_;
}
// <Custom additional code>
//PreviewStuff
Mesh mesh = new Mesh();
BoundingBox bbox = new BoundingBox();
Rhino.Display.DisplayMaterial m;
//Return a BoundingBox that contains all the geometry you are about to draw.
public override BoundingBox ClippingBox
{
get
{
return bbox;
}
}
//Draw all meshes in this method.
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
args.Display.DrawMeshShaded(mesh, m);
}
Ah, it seems there’s a problem in Rendered if the 3dm file is empty. The method is called, but Rhino is not showing the box if there’s nothing else to show.
Hi! I am trying to make grasshopper to custom preview my geometries, but it is slow. So I wonder is it possible such that the custom preview only shows the edges of the objects? If so, any clues on how this could be achieved? Thanks!
Hi Jacqueline, in my experience you can significantly speed it up by converting your geometry to mesh and joining it all up into one (or few) disjoint meshes.
This is an old question but maybe someone sees this.
How can one modify this C# script in such a way that the reflection color comes from a texture color map instead of being the same everywhere? I.e. the material should have not the same reflection color everywhere, but set the reflection color according to the u-v coordinate. All other material properties (diffuse color, ambient color, emission color, reflectivity, glossiness) should stay as in the example.
I tried to call the SetTexture method on the material but it seems it will overwrite all material properties; there’s no way to set only the “reflection texture”.
Thanks.