SHARE
TWEET

Untitled

a guest Jul 17th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def append_color_ramp(editor='Compositor',
  2.                       node_tree=None,
  3.                       name='ColorRamp',
  4.                       parent=None,
  5.                       custom_color=None,
  6.                       color_mode='RGB',
  7.                       rgb_interpolation='EASE',
  8.                       hue_interpolation='NEAR',
  9.                       elements=[
  10.                           {'position': 0.0,
  11.                            'color': [0.0, 0.0, 0.0, 1.0]},
  12.                           {'position': 1.0,
  13.                            'color': [1.0, 1.0, 1.0, 1.0]}],
  14.                       use_adjust_gamma=False,
  15.                       fac_default=0.5,
  16.                       fac_input=None,
  17.                       color_outputs=[],
  18.                       alpha_outputs=[]):
  19.  
  20.     request_id = 'ShaderNodeValToRGB'
  21.     if editor == 'Compositor':
  22.         request_id = 'CompositorNodeValToRGB'
  23.         if not node_tree:
  24.             node_tree = context.scene.node_tree
  25.  
  26.     # Create and set basic properties of node.
  27.     clr_rmp_node = node_tree.nodes.new(request_id)
  28.     clr_rmp_node.name = name
  29.     clr_rmp_node.parent = parent
  30.     if custom_color:
  31.         clr_rmp_node.use_custom_color = True
  32.         clr_rmp_node.color = custom_color
  33.  
  34.     # Initialize color keys.
  35.     color_ramp = clr_rmp_node.color_ramp
  36.     init_color_ramp(
  37.         color_ramp=color_ramp,
  38.         color_mode=color_mode,
  39.         rgb_interpolation=rgb_interpolation,
  40.         hue_interpolation=hue_interpolation,
  41.         elements=elements,
  42.         use_adjust_gamma=use_adjust_gamma)
  43.  
  44.     # Cache inputs and outputs.
  45.     fac_socket = clr_rmp_node.inputs['Fac']
  46.     alpha_socket = clr_rmp_node.outputs['Alpha']
  47.  
  48.     # In ShaderNodeValToRGB, this output is 'Color';
  49.     # In CompositorNodeValToRGB, this output is 'Image'.
  50.     color_socket = clr_rmp_node.outputs[0]
  51.  
  52.     # Cache node links to link up nodes.
  53.     node_links = node_tree.links
  54.  
  55.     # Set fac input.
  56.     fac_socket.default_value = fac_default
  57.     if fac_input:
  58.         node_links.new(fac_socket, fac_input)
  59.  
  60.     # Set color outputs.
  61.     for color_output in color_outputs:
  62.         if color_output:
  63.             node_links.new(
  64.                 color_output,
  65.                 color_socket)
  66.  
  67.     # Set alpha outputs.
  68.     for alpha_output in alpha_outputs:
  69.         if alpha_output:
  70.             node_links.new(
  71.                 alpha_output,
  72.                 alpha_socket)
  73.  
  74.     return clr_rmp_node
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top