Skip to content

Commit

Permalink
Fix #2434 - manage AO node for base color factor
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Dec 10, 2024
1 parent 792535d commit 1493535
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion addons/io_scene_gltf2/blender/exp/material/search_node_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,56 @@ def get_constant(self, in_soc=None):

# Check for a constant in the next node
nav = self.peek_back()
if nav.moved:
# Dev warning: because of loopbacks, this can be an infinite loop if not careful
# Please check all branches of your if statements
while True:
if not nav.moved:
break

if self.in_socket.type == 'RGBA':

# RGB node
if nav.node.type == 'RGB':
color = list(nav.out_socket.default_value)
color = color[:3] # drop unused alpha component (assumes shader tree)
return color, "node_tree." + nav.out_socket.path_from_id() + ".default_value"
# Ambient Occlusion node, not linked
elif nav.node.type == 'AMBIENT_OCCLUSION' and not nav.node.inputs['Color'].is_linked:
color = list(nav.node.inputs['Color'].default_value)
color = color[:3] # drop unused alpha component (assumes shader tree)
return color, "node_tree." + nav.node.inputs['Color'].path_from_id() + ".default_value"
# Ambient Occlusion node, linked, so check the next node
elif nav.node.type == "AMBIENT_OCCLUSION" and nav.node.inputs['Color'].is_linked:
nav.move_back('Color')
continue
else:
break

elif self.in_socket.type == 'SHADER':
# Historicaly, we manage RGB node plugged into a shader socket (output node)
if nav.node.type == 'RGB':
color = list(nav.out_socket.default_value)
color = color[:3]
return color, "node_tree." + nav.out_socket.path_from_id() + ".default_value"
# Ambient Occlusion node, not linked
elif nav.node.type == 'AMBIENT_OCCLUSION' and not nav.node.inputs['Color'].is_linked:
color = list(nav.node.inputs['Color'].default_value)
color = color[:3] # drop unused alpha component (assumes shader tree)
return color, "node_tree." + nav.node.inputs['Color'].path_from_id() + ".default_value"
# Ambient Occlusion node, linked, so check the next node
elif nav.node.type == "AMBIENT_OCCLUSION" and nav.node.inputs['Color'].is_linked:
nav.move_back('Color')
continue
else:
break

elif self.in_socket.type == 'VALUE':
if nav.node.type == 'VALUE':
return nav.out_socket.default_value, "node_tree." + nav.out_socket.path_from_id() + ".default_value"
else:
break
else:
break

return None, None

Expand Down

0 comments on commit 1493535

Please sign in to comment.