def main(aSDContext): """ This sample show how to create graph object such as: Pins, Comments, Frames :param aSDContext: The SDContext :return: None """ cGridSize = GraphGrid.sGetFirstLevelSize() sbsPackageName = os.path.split(__file__)[1].split('.')[ 0] # Get the package name from the current python file base name # ========================================================================= # Create a new Package sdPackageMgr = aSDContext.getSDApplication().getPackageMgr() sdPackage = sdPackageMgr.newUserPackage() # ========================================================================= # Create a new Substance Compositing Graph in this package sdSBSCompGraph = SDSBSCompGraph.sNew(sdPackage) # - Set the graph identifier sdSBSCompGraph.setIdentifier(sbsPackageName) # ========================================================================= # Create new Pin sdGraphObjectPin = SDGraphObjectPin.sNew(sdSBSCompGraph) sdGraphObjectPin.setPosition(float2(2 * cGridSize, 0)) sdGraphObjectPin.setDescription('The Pin') # ========================================================================= # Create a uniform color node sdSBSCompNodeUniform = sdSBSCompGraph.newNode('sbs::compositing::uniform') # ========================================================================= # Create New Comment attached on a Node sdGraphObjectComment = SDGraphObjectComment.sNewAsChild( sdSBSCompNodeUniform) sdGraphObjectComment.setPosition(float2(-cGridSize * 0.5, cGridSize * 0.5)) sdGraphObjectComment.setDescription('The Uniform node\'s comment') # ========================================================================= # Create new Frame sdGraphObjectFrame = SDGraphObjectFrame.sNew(sdSBSCompGraph) sdGraphObjectFrame.setPosition(float2(-cGridSize, -cGridSize)) sdGraphObjectFrame.setTitle('The Frame Title') sdGraphObjectFrame.setDescription('The frame description') sdGraphObjectFrame.setColor(ColorRGBA(0.2, 0.5, 0.7, 0.8)) sdGraphObjectFrame.setSize(float2(2 * cGridSize, 2 * cGridSize)) # ========================================================================= # Save the new package on disk dstFileAbsPath = os.path.join(io.getUserDocumentOutputDir(__file__), sbsPackageName + '.sbs') sdPackageMgr.savePackageAs(sdPackage, dstFileAbsPath) print('Save output file to ' + dstFileAbsPath)
def main(aSDContext): """ This sample show how to setup a parameter that is controled by a function on a uniform node in a Substance Compositing graph. :param aSDContext: The SDContext :return: None """ cGridSize = GraphGrid.sGetFirstLevelSize() sbsPackageName = os.path.split(__file__)[1].split('.')[ 0] # Get the package name from the current python file base name # ========================================================================= # Create a new Package sdPackageMgr = aSDContext.getSDApplication().getPackageMgr() sdPackage = sdPackageMgr.newUserPackage() # ========================================================================= # Create a new Substance Compositing Graph in this package sdSBSCompGraph = SDSBSCompGraph.sNew(sdPackage) # - Set the graph identifier sdSBSCompGraph.setIdentifier(sbsPackageName) # ========================================================================= # Create a uniform color node sdSBSCompNodeUniform = sdSBSCompGraph.newNode('sbs::compositing::uniform') sdSBSCompNodeUniform.setPosition(float2(-2 * cGridSize, cGridSize)) # - Get the input property that controls the output color uniformNodePropertyOutputColor = sdSBSCompNodeUniform.getPropertyFromId( 'outputcolor', SDPropertyCategory.Input) # - Create a new property graph of type SDSBSFunctionGraph propertySBSFunctionGraph = sdSBSCompNodeUniform.newPropertyGraph( uniformNodePropertyOutputColor, 'SDSBSFunctionGraph') # - Fill the property function. Here create a simple constant node that will return a green value float4ConstantNode = 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 SBSFunctionGraph propertySBSFunctionGraph.setOutputNode(float4ConstantNode, True) # ========================================================================= # Save the new package on disk dstFileAbsPath = os.path.join(io.getUserDocumentOutputDir(__file__), sbsPackageName + '.sbs') sdPackageMgr.savePackageAs(sdPackage, dstFileAbsPath) print('Save output file to ' + dstFileAbsPath)
def main(aSDContext): """ Sample used to show how to instanciate a Substance Compositing graph in another and also how to setup a gradient node :param aSDContext: The SDContext :return: None """ cGridSize = GraphGrid.sGetFirstLevelSize() sbsPackageName = os.path.split(__file__)[1].split('.')[ 0] # Get the package name from the current python file base name # ========================================================================= # Create a new Package sdApplication = aSDContext.getSDApplication() sdPackageMgr = sdApplication.getPackageMgr() sdPackage = sdPackageMgr.newUserPackage() # ========================================================================= # Create a new Substance Compositing Graph in this package sdSBSCompGraph = SDSBSCompGraph.sNew(sdPackage) # - Set the graph identifier sdSBSCompGraph.setIdentifier(sbsPackageName) # ========================================================================= # Create output Node BaseColor sdSBSCompNodeOutputBaseColor = sdSBSCompGraph.newNode( 'sbs::compositing::output') sdSBSCompNodeOutputBaseColor.setPosition(float2(0, -cGridSize)) sdValueArray = SDValueArray.sNew(SDTypeUsage.sNew(), 0) sdValueArray.pushBack( SDValueUsage.sNew(SDUsage.sNew('baseColor', 'RGBA', 'sRGB'))) sdSBSCompNodeOutputBaseColor.setAnnotationPropertyValueFromId( 'usages', sdValueArray) # Create output Node Normal sdSBSCompNodeOutputNormal = sdSBSCompGraph.newNode( 'sbs::compositing::output') sdSBSCompNodeOutputNormal.setPosition(float2(0, cGridSize)) sdValueArray = SDValueArray.sNew(SDTypeUsage.sNew(), 0) sdValueArray.pushBack( SDValueUsage.sNew(SDUsage.sNew('normal', 'RGBA', 'sRGB'))) sdSBSCompNodeOutputNormal.setAnnotationPropertyValueFromId( 'usages', sdValueArray) # ========================================================================= sdSBSCompNodeGradient = sdSBSCompGraph.newNode( 'sbs::compositing::gradient') sdSBSCompNodeGradient.setPosition(float2(-2 * cGridSize, -cGridSize)) sdTypeStructGradientKeyRGBAStructType = SDTypeStruct.sNew( 'sbs::compositing::gradient_key_rgba') # Create key 0 to Red sdValueStructKey0 = SDValueStruct.sNew( sdTypeStructGradientKeyRGBAStructType) sdValueStructKey0.setPropertyValueFromId( 'value', SDValueColorRGBA.sNew(ColorRGBA(1, 0, 0, 1))) sdValueStructKey0.setPropertyValueFromId('position', SDValueFloat.sNew(0)) sdValueStructKey0.setPropertyValueFromId('midpoint', SDValueFloat.sNew(0.5)) # Create key 1 to Green sdValueStructKey1 = SDValueStruct.sNew( sdTypeStructGradientKeyRGBAStructType) sdValueStructKey1.setPropertyValueFromId( 'value', SDValueColorRGBA.sNew(ColorRGBA(0, 1, 0, 1))) sdValueStructKey1.setPropertyValueFromId('position', SDValueFloat.sNew(0.5)) sdValueStructKey1.setPropertyValueFromId('midpoint', SDValueFloat.sNew(0.5)) # Create key 2 to Blue sdValueStructKey2 = SDValueStruct.sNew( sdTypeStructGradientKeyRGBAStructType) sdValueStructKey2.setPropertyValueFromId( 'value', SDValueColorRGBA.sNew(ColorRGBA(0, 0, 1, 1))) sdValueStructKey2.setPropertyValueFromId('position', SDValueFloat.sNew(1)) sdValueStructKey2.setPropertyValueFromId('midpoint', SDValueFloat.sNew(0.5)) # Create array of keys sdValueArray = SDValueArray.sNew(sdTypeStructGradientKeyRGBAStructType, 0) sdValueArray.pushBack(sdValueStructKey0) sdValueArray.pushBack(sdValueStructKey1) sdValueArray.pushBack(sdValueStructKey2) # Set the key array to the node property sdSBSCompNodeGradient.setInputPropertyValueFromId('gradientrgba', sdValueArray) sdSBSCompNodeGradient.newPropertyConnectionFromId( 'unique_filter_output', sdSBSCompNodeOutputBaseColor, 'inputNodeOutput') # ========================================================================= sdSBSCompNodeNormal = sdSBSCompGraph.newNode('sbs::compositing::normal') sdSBSCompNodeNormal.setPosition(float2(-2 * cGridSize, cGridSize)) sdSBSCompNodeNormal.newPropertyConnectionFromId('unique_filter_output', sdSBSCompNodeOutputNormal, 'inputNodeOutput') # ========================================================================= resourcePath = sdApplication.getPath(SDApplicationPath.DefaultResourcesDir) sdPackageAlveolus = sdPackageMgr.loadUserPackage( os.path.join(resourcePath, 'packages', 'pattern_alveolus.sbs'), True) sdSBSCompNodeInstanceAlveolus = sdSBSCompGraph.newInstanceNode( sdPackageAlveolus.findResourceFromUrl('alveolus')) sdSBSCompNodeInstanceAlveolus.setPosition(float2(-4 * cGridSize, 0)) sdSBSCompNodeInstanceAlveolus.setInputPropertyValueFromId( 'Tiling', SDValueInt.sNew(5)) sdSBSCompNodeInstanceAlveolusFirstOutputProperty = sdSBSCompNodeInstanceAlveolus.getProperties( SDPropertyCategory.Output)[0] sdSBSCompNodeInstanceAlveolusFirstOutputPropertyId = sdSBSCompNodeInstanceAlveolusFirstOutputProperty.getId( ) sdSBSCompNodeInstanceAlveolus.newPropertyConnectionFromId( sdSBSCompNodeInstanceAlveolusFirstOutputPropertyId, sdSBSCompNodeGradient, 'input1') sdSBSCompNodeInstanceAlveolus.newPropertyConnectionFromId( sdSBSCompNodeInstanceAlveolusFirstOutputPropertyId, sdSBSCompNodeNormal, 'input1') # ========================================================================= # Save the new package on disk dstFileAbsPath = os.path.join(io.getUserDocumentOutputDir(__file__), sbsPackageName + '.sbs') sdPackageMgr.savePackageAs(sdPackage, dstFileAbsPath) print('Save output file to ' + dstFileAbsPath)
def main(aSDContext): """ This sample show how to create a simple Substance Compositing Graph that uses: - a Bitmap Node - a Uniform Color - a Blend Node - an Output Node - Bitmap Resource that links a bitmap file :param aSDContext: The SDContext :return: None """ cGridSize = GraphGrid.sGetFirstLevelSize() sbsPackageName = os.path.split(__file__)[1].split('.')[0] # Get the package name from the current python file base name # ========================================================================= # Create a new Package sdPackageMgr = aSDContext.getSDApplication().getPackageMgr() sdPackage = sdPackageMgr.newUserPackage() # ========================================================================= # Create a new Substance Compositing Graph in this package sdSBSCompGraph = SDSBSCompGraph.sNew(sdPackage) # - Set the graph identifier sdSBSCompGraph.setIdentifier(sbsPackageName) # ========================================================================= # Create a uniform color node sdSBSCompNodeUniform = sdSBSCompGraph.newNode('sbs::compositing::uniform') # - Set the position of the uniform node sdSBSCompNodeUniform.setPosition(float2(-2*cGridSize, cGridSize)) # - Set the inheritance mode of the '$format' property to absolute sdSBSCompNodeUniform.setInputPropertyInheritanceMethodFromId('$format', SDPropertyInheritanceMethod.Absolute) # - Change the Output format of the '$format' property to 'hdr_high_precision' sdSBSCompNodeUniform.setInputPropertyValueFromId('$format', SDValueEnum.sFromValueId('sbs::compositing::format', 'hdr_high_precision')) # - Change the color property of this node # - Create the value color. The SDValueColorRGBA embeds the base type value of type ColorRGBA sdValueColorRGBA = SDValueColorRGBA.sNew(ColorRGBA(0.2, 0.5, 0.8, 1.0)) # - Set the color value to the 'outputcolor' input property of the node sdSBSCompNodeUniform.setInputPropertyValueFromId('outputcolor', sdValueColorRGBA) # ========================================================================= # Create a bitmap node # - Import bitmap resource # - Get the bitmap file path from the 'assets' directory bitmapFileAbsPath = os.path.join(io.getAssetsDir(__file__), 'substance-128x128.png') # - Create a new resource in the package that link the specified bitmap linkedSDResourceBitmap = SDResourceBitmap.sNewFromFile(sdPackage, bitmapFileAbsPath, EmbedMethod.Linked) # - Change the resource identifier linkedSDResourceBitmap.setIdentifier('linked_bitmap_resource') # - Instantiate the bitmap resource to the graph to have a node that will refers the created bitmap resource sdSBSCompNodeBitmap = sdSBSCompGraph.newInstanceNode(linkedSDResourceBitmap) # - Set the position of the bitmap node sdSBSCompNodeBitmap.setPosition(float2(-2*cGridSize, -cGridSize)) # ========================================================================= # Create a blend Node sdSBSCompNodeBlend = sdSBSCompGraph.newNode('sbs::compositing::blend') # - Set the position of the output node sdSBSCompNodeBlend.setPosition(float2(0, 0)) # ========================================================================= # Create an output Node sdSBSCompNodeOutput = sdSBSCompGraph.newNode('sbs::compositing::output') # - Set the position of the output node sdSBSCompNodeOutput.setPosition(float2(2*cGridSize, 0)) # - Add one usage 'baseColor' to the output node # The usages of an output (or input node) are define from/to an array. # - Create an array value of usages (of undefined size) sdValueArray = SDValueArray.sNew(SDTypeUsage.sNew(), 0) # - Create an usage value that embed the usage to add to the node sdValueUsage = SDValueUsage.sNew(SDUsage.sNew('baseColor', 'RGBA', 'sRGB')) # - Add the usage value to the array sdValueArray.pushBack(sdValueUsage) # - Set the value array to the 'usages' annotation of the output node sdSBSCompNodeOutput.setAnnotationPropertyValueFromId('usages', sdValueArray) # ========================================================================= # Create connections # - Connect the Bitmap node to the Blend node # - 'unique_filter_output': The identifier of the output property of the Uniform Node. # This property is Connectable (i.e. SDProperty.isConnectable() is True), it means that a Connector is displayed for this property in the graph, # and a connection can be defined from/to this property. # - 'sdSBSCompNodeOutput': This is the other Node to connect # - 'source': This is the input property of the other Node sdSBSCompNodeBitmap.newPropertyConnectionFromId('unique_filter_output', sdSBSCompNodeBlend, 'source') # - Connect the Uniform node to the Blend node # - 'unique_filter_output': The identifier of the output property of the Uniform Node. # This property is Connectable (i.e. SDProperty.isConnectable() is True), it means that a Connector is displayed for this property in the graph, # and a connection can be defined from/to this property. # - 'sdSBSCompNodeOutput': This is the other Node to connect # - 'destination': This is the input property of the other Node sdSBSCompNodeUniform.newPropertyConnectionFromId('unique_filter_output', sdSBSCompNodeBlend, 'destination') # - Connect the Blend node to the output node # - 'unique_filter_output': The identifier of the output property of the Uniform Node. # This property is Connectable (i.e. SDProperty.isConnectable() is True), it means that a Connector is displayed for this property in the graph, # and a connection can be defined from/to this property. # - 'sdSBSCompNodeOutput': This is the other Node to connect # - 'inputNodeOutput': This is the input property of the other Node sdSBSCompNodeBlend.newPropertyConnectionFromId('unique_filter_output', sdSBSCompNodeOutput, 'inputNodeOutput') # ========================================================================= # Save the new package on disk dstFileAbsPath = os.path.join(io.getUserDocumentOutputDir(__file__), sbsPackageName + '.sbs') sdPackageMgr.savePackageAs(sdPackage, dstFileAbsPath) print('Save output file to ' + dstFileAbsPath)
def main(aSDContext): """ This sample show how to create the "Metallic" MDL material as defined by the template "Metallic" of Substance Designer :param aSDContext: The SDContext :return: None """ cGridSize = GraphGrid.sGetFirstLevelSize() colSize = 2 * cGridSize rowSize = 2 * cGridSize sbsPackageName = os.path.split(__file__)[1].split('.')[ 0] # Get the package name from the current python file base name # Create a new Package sdPackageMgr = aSDContext.getSDApplication().getPackageMgr() sdPackage = sdPackageMgr.newUserPackage() # Create a new MDL Graph in this package sdMDLGraph = SDMDLGraph.sNew(sdPackage) sdMDLGraph.setIdentifier(sbsPackageName) # Get the output Node that has been created automatically when the graph has been created sdMDLNodeMaterial = sdMDLGraph.getOutputNodes()[0] sdMDLNodeMaterial.setPosition(float2(-colSize, 0)) # Create 'material_surface' node sdMDLNodeMaterialSurface = sdMDLGraph.newNode( 'mdl::material_surface(bsdf,material_emission)') sdMDLNodeMaterialSurface.setPosition(float2(-2 * colSize, 0)) sdMDLNodeMaterialSurface.newPropertyConnectionFromId( 'output', sdMDLNodeMaterial, 'surface') # Create 'microfacet_ggx_smith_bsdf' node sdMDLNodeMicrofacetGGX = sdMDLGraph.newNode( 'mdl::df::microfacet_ggx_smith_bsdf(float,float,color,float3,::df::scatter_mode,string)' ) sdMDLNodeMicrofacetGGX.setPosition(float2(-3 * colSize, 0)) sdMDLNodeMicrofacetGGX.newPropertyConnectionFromId( 'output', sdMDLNodeMaterialSurface, 'scattering') # Create constant 'color' node sdMDLNodeConstantColor = sdMDLGraph.newNode('mdl::color') sdMDLNodeConstantColor.setPosition(float2(-4 * colSize, rowSize)) # - Set the color as a linear value (MDL works in linear) sdMDLNodeConstantColor.setInputPropertyValueFromId( 'color', SDValueColorRGB.sNew( SDColorSpace.sConvertColorRGB(ColorRGB(0.5, 0.5, 0.5), 'sRGB', 'Linear'))) sdMDLNodeConstantColor.setExposed(True) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'identifier', SDValueString.sNew('basecolor')) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'description', SDValueString.sNew('The Base Color of the material')) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'in_group', SDValueString.sNew('Base Color')) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'display_name', SDValueString.sNew('Base Color')) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'gamma_type', SDValueInt.sNew(SDGammaType.SRGB.value)) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'visible_by_default', SDValueBool.sNew(True)) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'type_modifier', SDValueInt.sNew(SDTypeModifier.Uniform.value)) sdMDLNodeConstantColor.setAnnotationPropertyValueFromId( 'sampler_usage', SDValueString.sNew('baseColor')) sdMDLNodeConstantColor.newPropertyConnectionFromId('output', sdMDLNodeMicrofacetGGX, 'tint') # Create constant 'operator*' node sdMDLNodeMultFloat = sdMDLGraph.newNode('mdl::operator*(float,float)') sdMDLNodeMultFloat.setPosition(float2(-4 * colSize, -rowSize)) sdMDLNodeMultFloat.newPropertyConnectionFromId('output', sdMDLNodeMicrofacetGGX, 'roughness_u') sdMDLNodeMultFloat.newPropertyConnectionFromId('output', sdMDLNodeMicrofacetGGX, 'roughness_v') # Create float constant node sdMDLNodeConstantRoughness = sdMDLGraph.newNode('mdl::float') sdMDLNodeConstantRoughness.setPosition(float2(-5 * colSize, -rowSize)) sdMDLNodeConstantRoughness.setInputPropertyValueFromId( 'float', SDValueFloat.sNew(0.5)) sdMDLNodeConstantRoughness.setExposed(True) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'identifier', SDValueString.sNew('roughness')) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'display_name', SDValueString.sNew('Roughness')) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'description', SDValueString.sNew('The Roughness of the material')) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'in_group', SDValueString.sNew('Roughness')) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'gamma_type', SDValueInt.sNew(SDGammaType.Linear.value)) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'visible_by_default', SDValueBool.sNew(True)) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'type_modifier', SDValueInt.sNew(SDTypeModifier.Auto.value)) sdMDLNodeConstantRoughness.setAnnotationPropertyValueFromId( 'sampler_usage', SDValueString.sNew('roughness')) # TODO: Setup the Hard Range to [0; 1] sdMDLNodeConstantRoughness.newPropertyConnectionFromId( 'output', sdMDLNodeMultFloat, 'x') sdMDLNodeConstantRoughness.newPropertyConnectionFromId( 'output', sdMDLNodeMultFloat, 'y') # Geometry Part sdMDLNodeMaterialGeometry = sdMDLGraph.newNode( 'mdl::material_geometry(float3,float,float3)') sdMDLNodeMaterialGeometry.setPosition(float2(-2 * colSize, 2 * rowSize)) sdMDLNodeMaterialGeometry.newPropertyConnectionFromId( 'output', sdMDLNodeMaterial, 'geometry') sdMDLNodeConstantNormal = sdMDLGraph.newNode('mdl::float3') sdMDLNodeConstantNormal.setPosition(float2(-3 * colSize, 2 * rowSize)) sdMDLNodeConstantNormal.setExposed(True) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'identifier', SDValueString.sNew('normal')) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'display_name', SDValueString.sNew('Normal')) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'in_group', SDValueString.sNew('Normal')) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'gamma_type', SDValueInt.sNew(SDGammaType.Linear.value)) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'visible_by_default', SDValueBool.sNew(True)) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'type_modifier', SDValueInt.sNew(SDTypeModifier.Auto.value)) sdMDLNodeConstantNormal.setAnnotationPropertyValueFromId( 'sampler_usage', SDValueString.sNew('normal')) sdMDLNodeConstantNormal.newPropertyConnectionFromId( 'output', sdMDLNodeMaterialGeometry, 'normal') # Create 'normal' function node sdMDLNodeNormal = sdMDLGraph.newNode('mdl::state::normal()') sdMDLNodeNormal.setPosition(float2(-4 * colSize, 2 * rowSize)) sdMDLNodeNormal.newPropertyConnectionFromId('output', sdMDLNodeConstantNormal, 'normal') # Save the new package on disk dstFileAbsPath = os.path.join(io.getUserDocumentOutputDir(__file__), sbsPackageName + '.sbs') sdPackageMgr.savePackageAs(sdPackage, dstFileAbsPath) print('Save output file to ' + dstFileAbsPath)
def getTestOutputDir(aPyFile): """ :rtype: string """ return io.getUserDocumentOutputDir(aPyFile)