#
# This example demonstrates how to create a completely bogus shader
# definition on the fly (ie., not to be persisted) and then how to
# instantiate it on a scene object
#
from win32com.client import constants as si
app = Application
app.NewScene("", False)
# This function creates a bogus shader definition on the fly and returns its ProgID
def CreateDefOnTheFly () :
otmpShaderDef = XSIFactory.CreateShaderDef("NoParser", "Nunce", 1, 0)
otmpShaderDef.Category = "Test Shaders"
# family
otmpShaderDef.AddShaderFamily("mrTexture")
# paramdef options (in)
otmpShadPDefOpts = XSIFactory.CreateShaderParamDefOptions()
otmpShadPDefOpts.SetTexturable(True)
otmpShadPDefOpts.SetShortName("squelch")
# paramdef (in)
otmpInParams = otmpShaderDef.InputParamDefs
otmpInParams.AddParamDef2("west", si.siColorParameterType, otmpShadPDefOpts)
# paramdef options (out)
otmpShadPDefOpts = XSIFactory.CreateShaderParamDefOptions()
otmpShadPDefOpts.SetTexturable(True)
otmpShadPDefOpts.SetShortName("splosh")
# paramdef (out)
otmpOutParams = otmpShaderDef.OutputParamDefs
otmpOutParams.AddParamDef2("east", si.siColorParameterType, otmpShadPDefOpts)
# renderer
otmpRendDef = otmpShaderDef.AddRendererDef("whoops")
otmpRendOpts = otmpRendDef.RendererOptions
otmpRendOpts.Set("plain", False)
# attributes
otmpAttrs = otmpShaderDef.Attributes
otmpAttrs.Set("chuckle", "on")
otmpAttrs.Set("nbr", 456123)
# return the ProgID of the new shader
return otmpShaderDef.ProgID
# This function tests to see whether the specified parser name is
# a registered parser name already (if it is, the script will not
# attempt to create a definition on the fly (to avoid errors)
def IsNotRegistered( in_name ) :
oPC = Application.Plugins
for p in oPC :
for pi in p.Items :
if pi.Type == "Shader Language Parser" :
if pi.Name == in_name :
return False
# If no match is found, return true
return True
# First check to make sure the parser name isn't already registered
if IsNotRegistered("NoParser"):
# Create the shader definition on the fly and get its ProgID
sProgID = CreateDefOnTheFly()
# Now create a cube and instantiate this shader on it
oCube = app.CreatePrim("Cube", "MeshSurface")
app.CreateShaderFromProgID(sProgID, "Sources.Materials.DefaultLib.Scene_Material")
app.SIConnectShaderToCnxPoint("Sources.Materials.DefaultLib.Scene_Material.Nunce.east",
"Sources.Materials.DefaultLib.Scene_Material.Phong.ambient", False)
# Finally, remove it (we don't want to clutter up the system)
oRemoveMe = app.ShaderDefinitions(sProgID)
if oRemoveMe :
XSIFactory.RemoveShaderDef(oRemoveMe)
else :
app.LogMessage("Parser name is already registered.") |