Page 1 of 1

Python - ShaderDef + Dictionary

Posted: 02 Jul 2012, 01:38
by TwinSnakes007
Need some help with Python.

I've coded some ShaderDef's manually according to the Object model API for Python. But, I'd like to put that information into a dictionary and then declare the ShaderDef's by reading the information from the dictionary. But I dont know how to do that in Python.

So I want to do something like...

Code: Select all

bsdfPlugins = { 
    "diffuse" : {
        "reflectance" : [SpectrumType, TextureType ]
    },

    "roughplastic" : {
        "distribution" : [ EnumerationType(["beckmann", "ggx", "phong"]) ],
        "alpha" : [FloatType ],
        "intIOR" : [ FloatType, EnumerationType(iorPresetNames) ],
        "extIOR" : [ FloatType, EnumerationType(iorPresetNames) ],
        "diffuseReflectance" : [SpectrumType, TextureType ],
        "specularReflectance" : [SpectrumType, TextureType ]
    },

    ...(one entry for every BSDF)...
}
...then read each entry and turn it into the required callbacks for a ShaderDef

Code: Select all

def diffuse_1_0_DefineInfo() {}
def diffuse_1_0_Define() {}
def roughplastic_1_0_DefineInfo() {}
def roughplastic_1_0_Define() {}
etc...
-TS-

Re: Python - ShaderDef + Dictionary

Posted: 02 Jul 2012, 16:59
by TwinSnakes007
If anyone else is trying something like this...the answer is the "exec" statement, which supports dynamic execution of Python code.

Example:

Code: Select all

exec """def fun():
  print 'bbb'
"""
The exec statement will process your string as Python code.