To review what I’ve learned about defining materials in R6 over the last few days… Four ways?
Right-click the ‘M’ (Material) input to Custom Preview and choose from the list of materials created in a Rhino file. This has a BIG ADVANTAGE over method #2 since Grasshopper apparently retains the material definition so it still works when the .3dm file (where the material was defined) is not present. Also, the material can be defined on a layer, avoiding a glaring exception error.
Connect a text panel or Value List with the name of a material to the ‘M’ (Material) input of Custom Preview. Two conditions can cause this to fail with a glaring exception error:
A) When the material name is not found in the current .3dm file or
B) When the material was defined on a layer instead of using the ‘+’ in the Materials pane; actually, it can happen then too. Method #2 appears to be flawed?
The standard Create Material component. This seems like a far better approach than depending on a Rhino .3dm file in any way but it too is flawed. The ‘Shine (S)’ input appears to be broken.
The C# method posted by David and extended above.
I applied method #4 to all three files in my current project but was stumped by the inability to rename the output of the C# component to match my programming convention of naming one or both ends of wires…
So I decided to cluster it. At first, I passed geometry to the cluster, thinking I could include the Custom Preview internally. It worked for rendering but baking the cluster had no effect so I had to make it external again.
Still, this is an improvement for me so I created a User Object from it (mMaterial, attached). If one is careful to “disentangle” it from dissimilar copies (standard procedure for working with clusters), unused inputs (I added one more) can be removed to make it more compact.
AFTER: Note the renamed ‘M’ outputs.
mMaterial_2020Jan14a.gh (46.4 KB)
User Object: - Goes in ‘File | Special Folders | User Object Folder’
Create Material.ghuser (7.0 KB)