GHPython, Rhino Materials and Custom Preview-supports texture/bump?!


(Chris Hanley) #1

First off, I can’t believe I missed this. I don’t use textures/materials in GH very often, (beyond basic coloring/shading so it wasn’t on my radar.). TLDR; spent afternoon writing up something for functionality that already exists…at least in the current Rhino 6 version)

Someone asked me if we could use materials from their Rhino Document as preview materials. They were using an older material table plugin from Human and they were using the shader output to feed the custom preview component. Setting the viewport display mode to Rendered was not showing the texture/bump, (which I didn’t expect to, but like I said, I missed the above link).
So I spent a little time writing up a python version of the Material table component…which…I totally didn’t need to do.
For whatever reason, when I searched the forum , (before starting my task), I didn’t see the post I listed above, and was totally unaware of the fact that you can use the freaking name of the material as input to the native custom preview component.
Any who…here is the result of my fairly pointless exercise. The only bit that might be useful is seeing, one way, to create a gh_material from the xml property of a Rhino render material. which…is not needed because you just use the name!

"""Material Table: Retrieves materials from the currently active rhino document
        U: Update
        Names: Name of Material
        GHMaterial: a grasshopper shader object"""
__author__ = "chanley"
__version__ = "2019.03.14"

import Rhino
import ghpythonlib.treehelpers as th
import Grasshopper as GH

MatNames = []
DisplayMaterial = []

# example to show a way to create a an GH_Material
for mat in Rhino.RhinoDoc.ActiveDoc.RenderMaterials:

# output nested lists as data tree
Names = th.list_to_tree(MatNames)
GHMaterial = th.list_to_tree(DisplayMaterial)

Clipping Planes with Hatches in Grasshopper