LNXSDK/leenkx/blender/lnx/logicnode/math/LN_vector_clamp.py

42 lines
1.4 KiB
Python
Raw Normal View History

2025-01-22 16:18:30 +01:00
from lnx.logicnode.lnx_nodes import *
class VectorClampToSizeNode(LnxLogicTreeNode):
"""Clamp the vector's value inside the given range and return the result as a new vector.
@option Clamping Mode: Whether to clamp the length of the vector
or the value of each individual component.
"""
bl_idname = 'LNVectorClampToSizeNode'
bl_label = 'Vector Clamp'
lnx_section = 'vector'
lnx_version = 2
property0: HaxeEnumProperty(
'property0',
name='Clamping Mode', default='length',
description='Whether to clamp the length of the vector or the value of each individual component',
items=[
('length', 'Length', 'Clamp the length (magnitude) of the vector'),
('components', 'Components', 'Clamp the individual components of the vector'),
]
)
def draw_buttons(self, context, layout):
col = layout.column()
col.label(text="Clamping Mode:")
col.prop(self, 'property0', expand=True)
def lnx_init(self, context):
self.add_input('LnxVectorSocket', 'Vector In', default_value=[0.0, 0.0, 0.0])
self.add_input('LnxFloatSocket', 'Min')
self.add_input('LnxFloatSocket', 'Max')
self.add_output('LnxVectorSocket', 'Vector Out')
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.lnx_version not in (0, 1):
raise LookupError()
return NodeReplacement.Identity(self)