Fix #119030: Only access Location node input when available

Our `node_shader_utils.py` module needs to be updated to account for API
changes made during the 4.0 release cycle [1].

Here we need to guard against accessing the "Location" node input if not
dealing with the appropriate type of Mapping node.

[1] e4ad58114b

Pull Request: https://projects.blender.org/blender/blender/pulls/119354
This commit is contained in:
Jesse Yurkovich
2024-03-13 05:22:43 +01:00
committed by Jesse Yurkovich
parent 6b81fbced8
commit 0b19f1f4a0
@@ -36,6 +36,22 @@ def values_clamp(val, minv, maxv):
else:
return max(minv, min(maxv, val))
# TODO: Consider moving node_input_value_set/node_input_value_get into a common utility module if
# more usage merits doing so. If that is done, abstract out the validity check and make it usable
# for node outputs as well. See PR #119354 for details.
def node_input_value_set(node, input, value):
if node is None or input not in node.inputs:
return
node.inputs[input].default_value = value
def node_input_value_get(node, input, default_value=None):
if node is None or input not in node.inputs:
return default_value
return node.inputs[input].default_value
class ShaderWrapper():
"""
@@ -798,13 +814,11 @@ class ShaderImageTextureWrapper():
node_mapping = property(node_mapping_get)
def translation_get(self):
if self.node_mapping is None:
return Vector((0.0, 0.0, 0.0))
return self.node_mapping.inputs["Location"].default_value
return node_input_value_get(self.node_mapping, "Location", Vector((0.0, 0.0, 0.0)))
@_set_check
def translation_set(self, translation):
self.node_mapping.inputs["Location"].default_value = translation
node_input_value_set(self.node_mapping, "Location", translation)
translation = property(translation_get, translation_set)