Parameter controled by a function
This sample shows how to setup a parameter that is controled by a function on a uniform node in a Substance Compositing graph.
To use this example:
- Open Designer
- Go to Windows > Python Editor
- Copy the code below inside the editor
- Press the Play button
Copied to your clipboardimport osimport sdfrom sd.tools import iofrom sd.ui.graphgrid import *from sd.api.sbs.sdsbscompgraph import *from sd.api.sdbasetypes import *from sd.api.sdvaluefloat4 import *def main(aSDContext):cGridSize = GraphGrid.sGetFirstLevelSize()sbsPackageName = "MySample"# =========================================================================# Create a new PackagesdPackageMgr = aSDContext.getSDApplication().getPackageMgr()sdPackage = sdPackageMgr.newUserPackage()# =========================================================================# Create a new Substance Compositing Graph in this packagesdSBSCompGraph = SDSBSCompGraph.sNew(sdPackage)# - Set the graph identifiersdSBSCompGraph.setIdentifier(sbsPackageName)# =========================================================================# Create a uniform color nodesdSBSCompNodeUniform = sdSBSCompGraph.newNode('sbs::compositing::uniform')sdSBSCompNodeUniform.setPosition(float2(-2*cGridSize, cGridSize))# - Get the input property that controls the output coloruniformNodePropertyOutputColor = sdSBSCompNodeUniform.getPropertyFromId('outputcolor', SDPropertyCategory.Input)# - Create a new property graph of type SDSBSFunctionGraphpropertySBSFunctionGraph = sdSBSCompNodeUniform.newPropertyGraph(uniformNodePropertyOutputColor, 'SDSBSFunctionGraph')# - Fill the property function. Here create a simple constant node that will return a green valuefloat4ConstantNode = propertySBSFunctionGraph.newNode('sbs::function::const_float4')float4ConstantNode.setInputPropertyValueFromId('__constant__', SDValueFloat4.sNew(float4(0, 1, 0, 1)))# Set the constant node as output of the property's SBSFunctionGraphpropertySBSFunctionGraph.setOutputNode(float4ConstantNode, True)if __name__ == '__main__':main(sd.getContext())