Nodes: Defaults for Integer Math node depend on operation

When adding an Integer Math node, the inputs are initialized to 1 or 0
depending on the operation.

Defaults:

1st and 2nd inputs set to 1:
- Multiply
- Divide
- Divide Round
- Divide Floor
- Divide Ceil
- Floored Modulo
- Modulo

1st input to 1, 2nd to 0:
- Multiply Add

Pull Request: https://projects.blender.org/blender/blender/pulls/156823
This commit is contained in:
Habib Gahbiche 2026-04-08 12:08:26 +02:00
parent 777082b391
commit 9eab44d630
2 changed files with 25 additions and 2 deletions

View file

@ -13,7 +13,8 @@ __all__ = (
"add_repeat_zone",
"add_simulation_zone",
"draw_node_group_add_menu",
"set_math_node_default_props"
"set_math_node_default_props",
"set_int_math_node_default_props",
)
import bpy
@ -140,6 +141,23 @@ def set_math_node_default_props(enum_identifier, props):
set_socket_default_value(props.settings, "Value_002", "0.0")
def set_int_math_node_default_props(enum_identifier, props):
if enum_identifier in (
'MULTIPLY',
'DIVIDE',
'DIVIDE_ROUND',
'DIVIDE_FLOOR',
'DIVIDE_CEIL',
'FLOORED_MODULO',
'MODULO'):
set_socket_default_value(props.settings, "Value", "1")
set_socket_default_value(props.settings, "Value_001", "1")
elif enum_identifier == 'MULTIPLY_ADD':
set_socket_default_value(props.settings, "Value", "1")
set_socket_default_value(props.settings, "Value_001", "0")
class NodeMenu(Menu):
"""A base-class defining the shared methods for AddNodeMenu and SwapNodeMenu."""
draw_assets: bool

View file

@ -851,7 +851,12 @@ class NODE_MT_gn_utilities_math_base(node_add_menu.NodeMenu):
context, layout, "FunctionNodeBitMath", "operation", search_weight=-1.0,
)
self.node_operator_with_searchable_enum(context, layout, "FunctionNodeBooleanMath", "operation")
self.node_operator_with_searchable_enum(context, layout, "FunctionNodeIntegerMath", "operation")
self.node_operator_with_searchable_enum(
context,
layout,
"FunctionNodeIntegerMath",
"operation",
defaults_callback=node_add_menu.set_int_math_node_default_props)
self.node_operator(layout, "ShaderNodeClamp")
self.node_operator(layout, "FunctionNodeCompare")
self.node_operator(layout, "ShaderNodeFloatCurve")