Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. def withNodes(self, mat):
  2.         with_nodes = False
  3.         outNodeName = self.getNodeOutName(mat)
  4.         linked_node = None
  5.         # temporary fix for blend mat issue( excluding to possible replacement)
  6.         validReplaceNodes = ['shinydiffusemat', 'glossy', 'glass', 'translucent']
  7.         # Checking: if there is nodetree, if it contains a nodeout and if it is linked
  8.         if mat.bounty.nodetree != "" and outNodeName is not 'None':
  9.             ntree = bpy.data.node_groups[mat.bounty.nodetree]          
  10.             inputNodeOut = ntree.nodes[outNodeName].inputs['Surface']
  11.             # check nodetree
  12.             if inputNodeOut.is_linked:
  13.                 if inputNodeOut.links[0].from_node.bl_label == 'blend':
  14.                     nodelink = inputNodeOut.links[0].from_node
  15.                     # one
  16.                     mat1 = bpy.data.materials[nodelink.BlendOne]
  17.                     if mat1 not in self.materialMap:
  18.                         self.writeMaterial(mat1)
  19.                    
  20.                     print('blend value: ', nodelink.blend_amount)
  21.                     #mat.bounty.blend_value = nodelink.blend_amount
  22.                     # two
  23.                     mat2 = bpy.data.materials[nodelink.BlendTwo]
  24.                     if mat2 not in self.materialMap:
  25.                         self.writeMaterial(mat2)
  26.                        
  27.                     with_nodes= True                            
  28.                 # check a valid node type solo se usa cuando el nodo out no esta conectado
  29.                 # a un nodo valido
  30.                 if inputNodeOut.links[0].from_node.bl_label not in validMaterialTypes:
  31.                
  32.                     ntree.links.remove(inputNodeOut.links[0])
  33.                     # Trying to connect a valid node among those that compose the node tree
  34.                     linked = False
  35.                     for n in ntree.nodes:
  36.                         if n.bl_label in validReplaceNodes:
  37.                             ntree.links.new(inputNodeOut, n.outputs[0])
  38.                             linked = True
  39.                             break                            
  40.                     # If no nodes are supported, one is created
  41.                     if not linked:
  42.                         n = ntree.nodes.new("ShinyDiffuseShaderNode")
  43.                         n.location = [-200, 0]
  44.                         ntree.links.new(inputNodeOut, n.outputs[0])
  45.                     #
  46.                     with_nodes= True
  47.                     self.yi.printWarning('An invalid node has been connected. Changing to a valid one')
  48.                 #
  49.                 linked_node = inputNodeOut.links[0].from_node
  50.                 mat.bounty.mat_type = linked_node.bl_label
  51.         #
  52.         return with_nodes, linked_node
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement