Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2434 - manage AO node for base color factor #2437

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading