Changeset View
Changeset View
Standalone View
Standalone View
node_wrangler.py
| Show First 20 Lines • Show All 1,616 Lines • ▼ Show 20 Lines | def invoke(self, context, event): | ||||
| nodes, links = get_nodes_links(context) | nodes, links = get_nodes_links(context) | ||||
| in_group = context.active_node != space.node_tree.nodes.active | in_group = context.active_node != space.node_tree.nodes.active | ||||
| active = nodes.active | active = nodes.active | ||||
| output_types = [x[1] for x in shaders_output_nodes_props] | output_types = [x[1] for x in shaders_output_nodes_props] | ||||
| valid = False | valid = False | ||||
| if active: | if active: | ||||
| if (active.name != "Emission Viewer") and (active.type not in output_types) and not in_group: | if (active.name != "Emission Viewer") and (active.type not in output_types) and not in_group: | ||||
| for out in active.outputs: | for out in active.outputs: | ||||
| if not out.hide: | if not out.hide and out.enabled: | ||||
| valid = True | valid = True | ||||
| break | break | ||||
| if valid: | if valid: | ||||
| # get material_output node, store selection, deselect all | # get material_output node, store selection, deselect all | ||||
| materialout = None # placeholder node | materialout = None # placeholder node | ||||
| selection = [] | selection = [] | ||||
| for node in nodes: | for node in nodes: | ||||
| if node.type == shader_output_type: | if node.type == shader_output_type: | ||||
| Show All 19 Lines | def invoke(self, context, event): | ||||
| materialout = nodes.new(shader_output_ident) | materialout = nodes.new(shader_output_ident) | ||||
| materialout.location.x = new_locx | materialout.location.x = new_locx | ||||
| materialout.location.y = new_locy | materialout.location.y = new_locy | ||||
| materialout.select = False | materialout.select = False | ||||
| # Analyze outputs, add "Emission Viewer" if needed, make links | # Analyze outputs, add "Emission Viewer" if needed, make links | ||||
| out_i = None | out_i = None | ||||
| valid_outputs = [] | valid_outputs = [] | ||||
| for i, out in enumerate(active.outputs): | for i, out in enumerate(active.outputs): | ||||
| if not out.hide: | if not out.hide and out.enabled: | ||||
| valid_outputs.append(i) | valid_outputs.append(i) | ||||
| if valid_outputs: | if valid_outputs: | ||||
| out_i = valid_outputs[0] # Start index of node's outputs | out_i = valid_outputs[0] # Start index of node's outputs | ||||
| for i, valid_i in enumerate(valid_outputs): | for i, valid_i in enumerate(valid_outputs): | ||||
| for out_link in active.outputs[valid_i].links: | for out_link in active.outputs[valid_i].links: | ||||
| if "Emission Viewer" in out_link.to_node.name or (out_link.to_node == materialout and out_link.to_socket == materialout.inputs[0]): | if "Emission Viewer" in out_link.to_node.name or (out_link.to_node == materialout and out_link.to_socket == materialout.inputs[0]): | ||||
| if i < len(valid_outputs) - 1: | if i < len(valid_outputs) - 1: | ||||
| out_i = valid_outputs[i + 1] | out_i = valid_outputs[i + 1] | ||||
| ▲ Show 20 Lines • Show All 1,536 Lines • ▼ Show 20 Lines | class NWLinkToOutputNode(Operator, NWBase): | ||||
| bl_options = {'REGISTER', 'UNDO'} | bl_options = {'REGISTER', 'UNDO'} | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| valid = False | valid = False | ||||
| if nw_check(context): | if nw_check(context): | ||||
| if context.active_node is not None: | if context.active_node is not None: | ||||
| for out in context.active_node.outputs: | for out in context.active_node.outputs: | ||||
| if not out.hide: | if not out.hide and out.enabled: | ||||
| valid = True | valid = True | ||||
| break | break | ||||
| return valid | return valid | ||||
| def execute(self, context): | def execute(self, context): | ||||
| nodes, links = get_nodes_links(context) | nodes, links = get_nodes_links(context) | ||||
| active = nodes.active | active = nodes.active | ||||
| output_node = None | output_node = None | ||||
| Show All 18 Lines | def execute(self, context): | ||||
| elif tree_type == 'CompositorNodeTree': | elif tree_type == 'CompositorNodeTree': | ||||
| output_node = nodes.new('CompositorNodeComposite') | output_node = nodes.new('CompositorNodeComposite') | ||||
| elif tree_type == 'TextureNodeTree': | elif tree_type == 'TextureNodeTree': | ||||
| output_node = nodes.new('TextureNodeOutput') | output_node = nodes.new('TextureNodeOutput') | ||||
| output_node.location.x = active.location.x + active.dimensions.x + 80 | output_node.location.x = active.location.x + active.dimensions.x + 80 | ||||
| output_node.location.y = active.location.y | output_node.location.y = active.location.y | ||||
| if (output_node and active.outputs): | if (output_node and active.outputs): | ||||
| for i, output in enumerate(active.outputs): | for i, output in enumerate(active.outputs): | ||||
| if not output.hide: | if not output.hide and output.enabled: | ||||
| output_index = i | output_index = i | ||||
| break | break | ||||
| for i, output in enumerate(active.outputs): | for i, output in enumerate(active.outputs): | ||||
| if output.type == output_node.inputs[0].type and not output.hide: | if output.type == output_node.inputs[0].type and not output.hide and output.enabled: | ||||
| output_index = i | output_index = i | ||||
| break | break | ||||
| out_input_index = 0 | out_input_index = 0 | ||||
| if tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context): | if tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context): | ||||
| if active.outputs[output_index].name == 'Volume': | if active.outputs[output_index].name == 'Volume': | ||||
| out_input_index = 1 | out_input_index = 1 | ||||
| elif active.outputs[output_index].type != 'SHADER': # connect to displacement if not a shader | elif active.outputs[output_index].type != 'SHADER': # connect to displacement if not a shader | ||||
| ▲ Show 20 Lines • Show All 1,578 Lines • Show Last 20 Lines | |||||