Python - ShaderDef + Dictionary

Discussions concerning programming of SOFTIMAGE©
Post Reply
User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 16:00

Python - ShaderDef + Dictionary

Post by TwinSnakes007 » 02 Jul 2012, 01:38

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-

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 16:00

Re: Python - ShaderDef + Dictionary

Post by TwinSnakes007 » 02 Jul 2012, 16:59

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests