Grasshopper Python Component Render Material Vray

Hi All,

in a Grasshopper Python Component I would like to get a list of all materials in the document to read their RGB values (of the diffuse channel). My materials are Vray materials. There are no Rhino materials present in the file. I cannot use Rhino materials for this.

Rhino Version 6 SR26
Vray Version 3.60.03

I tried so far:

  1. scriptcontext.doc.Materials -> not supported in GH
  2. Rhino.RhinoDoc.ActiveDoc.Materials -> Holds the same number of materials as listed in the Vray Asset Editor UI. So I assume those are the Vray materials. But all Rhino.RhinoDoc.ActiveDoc.Materials[i].DiffuseColor values are unrelated to the actual values set up in the Vray materials.
  3. Rhino.RhinoDoc.ActiveDoc.RenderMaterials -> is empty
  4. I applied the Vray materials in Rhino to Brep objects. Loaded those objects into GH as Geometry and use them inside the GH Python Component to do rhinoscriptsyntax.ObjectMaterialIndex(guid) -> always gives me -1. This works in normal Rhino Python Scripts, but not in the GH Python component.

EDIT
Further tests I did

  1. Using the Vray Material from Project component to get to the material and plugging it into the GH Python Script component. Inside the script this gives me -1, same when you plug it into a panel. Those Vray components hardly implement anything.

I know @clement did some work in this direction with Python Script. Did you ever get it to work in GH Python?

Any ideas are greatly appreciated. Thanks for your help.
Silvan

There are Vray GH components here: https://docs.chaosgroup.com/m/mobile.action#page/35857641

Looks like they work with Vray materials and material files.

Hi @silvano, it’s been a long time since i used this, but GH was not involved. Does it work better if you load (reference) the objects not as geometry but using their Id ?

_
c.

Vray next allows grasshopper objects to be rendered directly, bypassing rhino all together if wanted.

There is a Vray window on the grasshopper canvas. No baking

https://www.chaosgroup.com/blog/jan-kokol-v-ray-for-grasshopper

Not sure if this will work in gh, but this is what I used for manipulating materials in python:


import rhinoscriptsyntax as rs
import System
vray = rs.GetPlugInObject("V-Ray for Rhino")

materials = vray.Scene().Materials()

for m in materials:
    material = m.Name()+"/Base/V-Ray BRDF"
    brdf=vray.Scene().Plugin(material)
    brdf.Param("diffuse_color").Value = System.Array[System.Single]([0, 1, 1])
vray.Scene().Refresh()

for vray-next (latest update) that would be:


import rhinoscriptsyntax as rs
import System
vray = rs.GetPlugInObject("V-Ray for Rhino")

materials = vray.Scene().Materials()

for m in materials:
    
    
    material = m.Name()+"/Bump/VRay Mtl"
    brdf=vray.Scene().Plugin(material)
    brdf.Param("diffuse_color").Value = System.Array[System.Single]([0, 1, 1])
vray.Scene().Refresh()

this example would change the diffuse color to rgb 0 255 255 (cyan)
note that you can read values with:

print brdf.Param("diffuse_color").Value()

so with the parenthesis, but assigning a new value, you’ll address it without those parenthesis.
the above would return:

Array[Single]((0.0, 1.0, 1.0))

hth

One more note: by saving out a material (.mat) and opening it in a editor (notepad++) you can read out the values. Best is to save your material, change one aspect of it through the UI, save that as well, then compare the two files with notepad++ to see which parameter gets changed, then convert it into script form.

Also note that you need to assign values using explicit types (for example System.Single) otherwise it won’t work.

here are a couple more examples of what you can change:

    brdf.Param("option_reflect_on_back").Value = True #turn on backside reflection
    brdf.Param("reflect_depth").Value = System.Int32(20) #change reflection depth to 20
    brdf.Param("refract_depth").Value= System.Int32(20) #change refraction depth to 20
    brdf.Param("fresnel_ior_float").Value = System.Single(1.55) #change fresnel reflection value to 1.55
    brdf.Param("refract_ior_float").Value = System.Single(1.55) #change fresnel refraction value to 1.55
    brdf.Param("fresnel_ior_lock").Value = True #lock reflection fresnel to refraction fresnel
    brdf.Param("reflect_color").Value = System.Array[System.Single]([.7, .7, .7]) #change reflection to 70%
    brdf.Param("reflect_glossiness_float").Value = System.Single(0.9) #change reflection glossiness to 0.9

seems to work quite well:

1 Like

Hello Everybody,

many thanks for all the valuable tips and inputs! I tried them all. Unfortunately without success to get to the RGB values of the Vray material. Still it was very interesting feedback.

I am currently using a workaround that works for myself. But the resulting GH Python Component was supposed to be used by the whole office and has to be self explanatory. This is currently not possible.

Does anybody know, if it could work if Chaosgroup/Vray would implement the the necessary interfaces so that Rhino.RhinoDoc.ActiveDoc.RenderMaterials[i] returns the same information as a Rhino material? Could somebody point me to the right developer contact here in the forum?

Thanks again and have a nice weekend.

Hi @clement, thanks for the tip. Do I understand correctly you mean the guid? I do not seem to be able to do that in a GH Python component.

Hi Scott, rendering works fine via the Vray GH Components thanks for the tip. Unfortunately it does not solve my original problem. I have to assign materials based on their RGB values of the diffuse channel, thus I was looking for a solution to get to those values.

Hi Gijs
many thanks for the script and tips. Yes, the whole process works in Rhino Python, it just does not work in GH Python. The com object that you get from rs.GetPlugInObject("V-Ray for Rhino").Scene() does not have a method Materials().

I doubt that Chaosgroup can do that because they have their own ecosystem. Anyhow I think @Nikolay should be able to answer you on that.

Could be a 3.6 thing. Here it seems to work (v-ray 4.20.01). What code do you use?

Hi Gijs, thanks a lot for the contact and the information that your script works in a Grasshopper Python Component with Vray 4.2. If this is related to the old Vray Version, we might have to upgrade.

Hi Silvano, I’m not sure if you really need the method .Materials()
It’s also not completely clear what you want to achieve. I was trying a few more things the other day and got something like this:

I was looking back at the forum, and I think indeed that most of this was added to Vray Next.

Hi Gijs, thanks for checking this with a GH component and clarifying that it was added in Vray Next. This is a good way forward for us.
Just to clarify what I am trying to achieve: I need to get the RGB values of the diffuse channel of a multitude of Vray materials stored in a file. They have to be matched to a large table of outside RGB values, assigned to objects and eventually I have to make copies of those materials and change the diffuse channel and fog color.

ah ok, in that case remind yourself that the colors in Vray are linear and some conversion is needed as I showed in the screenshot.
here is the gh: vray-material-manipulation.gh (21.1 KB)

1 Like

Thanks for all your help and the GH file!

1 Like