Doc.RenderMaterials Children

python

(Tom Norris23) #1

Any one know where I can find a list of the children of scriptcontext.doc.RenderMaterials:

I have “bitmap-texture” for the color bitmap

but would also like to get the transparency and bump maps?

Thanks
Tom


(Nathan 'jesterKing' Letwory) #2

For a RenderMaterial use GetTextureForUsage

Here a short script that gets that diffuse texture:

It should give you enough info to get started.


(Tom Norris23) #3

Hi Nathan

So I have this script for resetting the repeat of a color bitmap on a material but I want to do the same for the bump bitmap and for the transparency bitmap?

  for m in scriptcontext.doc.RenderMaterials:
  
    tex = m.FindChild("bitmap-texture")
    if tex != None:
        repeat = tex.GetRepeat()
        tempx = repeat.X
        tempy = repeat.Y
        if tempx!=1.0 and tempy!=1.0:
            reset = rg.Vector3d(1,1,0)
            tex.SetRepeat(reset,0)

Thanks I advanced!


(Nathan 'jesterKing' Letwory) #4

As I wrote use GetTextureForUsage() instead of FindChild(). From the documentarion you should be able to find the correct childslot enum values to use.


(Tom Norris23) #5

Ohh got ya, Thanks!

Diffuse 100 Corresponds to ON_Texture::TYPE::bitmap_texture.
Transparency 101 Corresponds to ON_Texture::transparancy_texture.
Bump 102 Corresponds to ON_Texture::TYPE::bump_texture.
Environment 103 Corresponds to ON_Texture::TYPE::emap_texture.

Im not sure im using it correct but I find it really hard to stuff in the SDK!


(Nathan 'jesterKing' Letwory) #6

You should use the documentation pane in the Rhino Python Editor (which you get through command _EditPythonScript):

Once more the example script directly in this thread:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Render as rr

for rm in sc.doc.RenderMaterials:
    rt = rm.GetTextureFromUsage(rr.RenderMaterial.StandardChildSlots.Diffuse)

    rt.BeginChange(rr.RenderContent.ChangeContexts.Program)
    rt.SetProjectionMode(rr.TextureProjectionMode.MappingChannel, rr.RenderContent.ChangeContexts.Program)
    rt.SetMappingChannel(1, rr.RenderContent.ChangeContexts.Program)
    rt.EndChange()

Please pay attention to GetTextureFromUsage and the StandardChildSlots enumeration.


(Nathan 'jesterKing' Letwory) #7

As an extra bit of information: since the Python integration in Rhino is done with IronPython, a .NET implementation of Python, you have access to .NET, including the .NET SDK for Rhino called RhinoCommon. That is where you should be looking at for your API docs - it is what the tree I showed in the animated gif is generated from: http://developer.rhino3d.com/api/RhinoCommon/html/N_Rhino.htm