Skip to content

Commit

Permalink
Fix T73882, T74420: node wrangler operations only working for Cycles …
Browse files Browse the repository at this point in the history
…and Eevee

There were legacy checks remaining for Blender Internal, however now we can
assume that any renderer using the native shader node tree is also using Cycles
and Eevee shading nodes. Custom shader nodes will have a different type of node
tree.
  • Loading branch information
brechtvl committed Mar 4, 2020
1 parent 38d2b94 commit 9896bbd
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions node_wrangler.py
Expand Up @@ -544,9 +544,6 @@
}


def is_cycles_or_eevee(context):
return context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}

def is_visible_socket(socket):
return not socket.hide and socket.enabled

Expand Down Expand Up @@ -1583,10 +1580,9 @@ class NWEmissionViewer(Operator, NWBase):

@classmethod
def poll(cls, context):
is_cycles = is_cycles_or_eevee(context)
if nw_check(context):
space = context.space_data
if space.tree_type == 'ShaderNodeTree' and is_cycles:
if space.tree_type == 'ShaderNodeTree':
if context.active_node:
if context.active_node.type != "OUTPUT_MATERIAL" or context.active_node.type != "OUTPUT_WORLD":
return True
Expand Down Expand Up @@ -2583,7 +2579,7 @@ def poll(cls, context):
valid = False
if nw_check(context):
space = context.space_data
if space.tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context):
if space.tree_type == 'ShaderNodeTree':
valid = True
return valid

Expand Down Expand Up @@ -2687,7 +2683,7 @@ def poll(cls, context):
valid = False
if nw_check(context):
space = context.space_data
if space.tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context):
if space.tree_type == 'ShaderNodeTree':
valid = True
return valid

Expand Down Expand Up @@ -3261,10 +3257,7 @@ def execute(self, context):
if not output_node:
bpy.ops.node.select_all(action="DESELECT")
if tree_type == 'ShaderNodeTree':
if is_cycles_or_eevee(context):
output_node = nodes.new('ShaderNodeOutputMaterial')
else:
output_node = nodes.new('ShaderNodeOutput')
output_node = nodes.new('ShaderNodeOutputMaterial')
elif tree_type == 'CompositorNodeTree':
output_node = nodes.new('CompositorNodeComposite')
elif tree_type == 'TextureNodeTree':
Expand All @@ -3282,7 +3275,7 @@ def execute(self, context):
break

out_input_index = 0
if tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context):
if tree_type == 'ShaderNodeTree':
if active.outputs[output_index].name == 'Volume':
out_input_index = 1
elif active.outputs[output_index].type != 'SHADER': # connect to displacement if not a shader
Expand Down Expand Up @@ -3730,7 +3723,7 @@ def drawlayout(context, layout, mode='non-panel'):
col.menu(NWSwitchNodeTypeMenu.bl_idname, text="Switch Node Type")
col.separator()

if tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context):
if tree_type == 'ShaderNodeTree':
col = layout.column(align=True)
col.operator(NWAddTextureSetup.bl_idname, text="Add Texture Setup", icon='NODE_SEL')
col.operator(NWAddPrincipledSetup.bl_idname, text="Add Principled Setup", icon='NODE_SEL')
Expand Down Expand Up @@ -3815,7 +3808,7 @@ class NWMergeNodesMenu(Menu, NWBase):
def draw(self, context):
type = context.space_data.tree_type
layout = self.layout
if type == 'ShaderNodeTree' and is_cycles_or_eevee(context):
if type == 'ShaderNodeTree':
layout.menu(NWMergeShadersMenu.bl_idname, text="Use Shaders")
layout.menu(NWMergeMixMenu.bl_idname, text="Use Mix Nodes")
layout.menu(NWMergeMathMenu.bl_idname, text="Use Math Nodes")
Expand Down Expand Up @@ -4039,7 +4032,7 @@ def poll(cls, context):
valid = False
if nw_check(context):
snode = context.space_data
valid = snode.tree_type == 'ShaderNodeTree' and is_cycles_or_eevee(context)
valid = snode.tree_type == 'ShaderNodeTree'
return valid

def draw(self, context):
Expand Down Expand Up @@ -4074,22 +4067,14 @@ def draw(self, context):
layout = self.layout
tree = context.space_data.node_tree
if tree.type == 'SHADER':
if is_cycles_or_eevee(context):
layout.menu(NWSwitchShadersInputSubmenu.bl_idname)
layout.menu(NWSwitchShadersOutputSubmenu.bl_idname)
layout.menu(NWSwitchShadersShaderSubmenu.bl_idname)
layout.menu(NWSwitchShadersTextureSubmenu.bl_idname)
layout.menu(NWSwitchShadersColorSubmenu.bl_idname)
layout.menu(NWSwitchShadersVectorSubmenu.bl_idname)
layout.menu(NWSwitchShadersConverterSubmenu.bl_idname)
layout.menu(NWSwitchShadersLayoutSubmenu.bl_idname)
else:
layout.menu(NWSwitchMatInputSubmenu.bl_idname)
layout.menu(NWSwitchMatOutputSubmenu.bl_idname)
layout.menu(NWSwitchMatColorSubmenu.bl_idname)
layout.menu(NWSwitchMatVectorSubmenu.bl_idname)
layout.menu(NWSwitchMatConverterSubmenu.bl_idname)
layout.menu(NWSwitchMatLayoutSubmenu.bl_idname)
layout.menu(NWSwitchShadersInputSubmenu.bl_idname)
layout.menu(NWSwitchShadersOutputSubmenu.bl_idname)
layout.menu(NWSwitchShadersShaderSubmenu.bl_idname)
layout.menu(NWSwitchShadersTextureSubmenu.bl_idname)
layout.menu(NWSwitchShadersColorSubmenu.bl_idname)
layout.menu(NWSwitchShadersVectorSubmenu.bl_idname)
layout.menu(NWSwitchShadersConverterSubmenu.bl_idname)
layout.menu(NWSwitchShadersLayoutSubmenu.bl_idname)
if tree.type == 'COMPOSITING':
layout.menu(NWSwitchCompoInputSubmenu.bl_idname)
layout.menu(NWSwitchCompoOutputSubmenu.bl_idname)
Expand Down

0 comments on commit 9896bbd

Please sign in to comment.