Author Topic: Unclear documentation on connections.  (Read 1951 times)

Hello.

I'm trying to write a python script that fixes the unity issues related to smoothness and metallic.

I wrote a script that finds the metallic and roughness outputs, gets the connections to the left and then connects those nodes to a bunch of new nodes (invert, channel shuffle, a new output).

This works really well when the nodes the outputs are connected to are simple things, like a levels, or a blur and so on. Now, I've stumbled upon a case where the node on the left hand of the connection has multiple outputs (in fact, it's a whole material).

The issue is that since I don't specify what output to connect to, they always get connected to the first one (a diffuse in this case). Is there any way to know what output from a node a connection is made to? I might not be understanding this so well since I'm a bit new to python but I'm "fluent" in c++ and other more normal languages.

Here's the code that handles this roughness/metallic->metalSmoothenss issue:

Code: [Select]
          #Get Metallic and RoughnessNodes
          metallicOutput = graph.getGraphOutputNode(aOutputIdentifier = 'metallic')
          metallicNodeUid = graph.getNode(metallicOutput.mUID).mConnections[0].getConnectedNodeUID()
          metallicNode = graph.getNode(metallicNodeUid)


          roughnessOutput = graph.getGraphOutputNode(aOutputIdentifier = 'roughness')
          roughnessNodeUid = graph.getNode(roughnessOutput.mUID).mConnections[0].getConnectedNodeUID()
          roughnessNode = graph.getNode(roughnessNodeUid)
         

          #Create MetallicSmoothness output
          invertedRoughness = graph.createCompFilterNode(aFilter = pysbs.sbsenum.FilterEnum.LEVELS,
                                                         aParameters = {
                                                             pysbs.sbsenum.CompNodeParamEnum.LEVEL_IN_LOW : '0.0 0.0 0.0 0.0',
                                                             pysbs.sbsenum.CompNodeParamEnum.LEVEL_IN_HIGH: '1.0 1.0 1.0 1.0',
                                                             pysbs.sbsenum.CompNodeParamEnum.LEVEL_IN_MID:  '0.5 0.5 0.5 0.5',
                                                             pysbs.sbsenum.CompNodeParamEnum.LEVEL_OUT_LOW: '1.0 1.0 1.0 1.0',
                                                             pysbs.sbsenum.CompNodeParamEnum.LEVEL_OUT_HIGH:'0.0 0.0 0.0 0.0',
                                                             pysbs.sbsenum.CompNodeParamEnum.CLAMP_IN_TERM: '1'             
                                                             }
                                                         )

          graph.connectNodes(aLeftNode = roughnessNodeUid, aRightNode = invertedRoughness)
         
          metallicSmoothMerge = graph.createCompFilterNode(aFilter = pysbs.sbsenum.FilterEnum.SHUFFLE,
                                                           aParameters = {
                                                               pysbs.sbsenum.CompNodeParamEnum.CHANNEL_RED: pysbs.sbsenum.ChannelShuffleEnum.INPUT1_RED,
                                                               pysbs.sbsenum.CompNodeParamEnum.CHANNEL_GREEN: pysbs.sbsenum.ChannelShuffleEnum.INPUT1_RED,
                                                               pysbs.sbsenum.CompNodeParamEnum.CHANNEL_BLUE: pysbs.sbsenum.ChannelShuffleEnum.INPUT1_RED,
                                                               pysbs.sbsenum.CompNodeParamEnum.CHANNEL_ALPHA: pysbs.sbsenum.ChannelShuffleEnum.INPUT2_RED
                                                               })
          graph.connectNodes(aLeftNode = metallicNodeUid, aRightNode = metallicSmoothMerge, aRightNodeInput = pysbs.sbsenum.InputEnum.INPUT1)
          graph.connectNodes(aLeftNode = invertedRoughness, aRightNode = metallicSmoothMerge, aRightNodeInput = pysbs.sbsenum.InputEnum.INPUT2)
         
          outMetallicSmoothness = graph.createOutputNode(aIdentifier = 'metallicSmoothness',
                                                         aUsages = {pysbs.sbsenum.UsageEnum.ANY: pysbs.sbsenum.ComponentsEnum.RGBA})

          graph.deleteNode(graph.getNode(metallicOutput.mUID))
          graph.deleteNode(graph.getNode(roughnessOutput.mUID))

If anyone of you could help me out with this, I'd greatly appreciate it.

Also, on a more unrelated note, when using sbsrender it would be great if there would be an option to invert the normals(only the ones in the output since others might be used for curvature sobel or something). So far I've had to do this from within Unity and it's rather tedious to figure out how the TextureImporter works.

Regards,
Lorin

Should be able to determine which output you want to connect to, then add the output arg to this function:
graph.connectNodes(aLeftNode = materialCompNode, aRightNode = inputCompNode, aLeftNodeOutput="OutputEnum|NameOfOutput")

https://support.allegorithmic.com/documentation/display/SAT/graph
^ Search for connectNodes

Yes but that first part "Should be able to determine which output you want to connect to" is the one I can't figure out. I do know how to connect nodes as seen in my example code. As far as I see in the documentation there's no way to get the output/input names from the connection.

Query the comp node for it.
https://support.allegorithmic.com/documentation/display/SAT/compnode
^search mCompOutputs

Code: [Select]
output_list=aCompNode.mCompOutputs
returns a list of this type:
https://support.allegorithmic.com/documentation/display/SAT/common#compnode.common.SBSCompOutput
Can find uid of the output and be able find out enough about the specific output to plug it back into the connection function.