From 2371e3777e72f3f4a3a6eab4b14ed2adbcf91218 Mon Sep 17 00:00:00 2001 From: Onek8 Date: Fri, 19 Sep 2025 19:08:03 +0000 Subject: [PATCH] t3du - Probabilistic Index Node --- .../random/LN_probabilistic_index.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 leenkx/blender/lnx/logicnode/random/LN_probabilistic_index.py diff --git a/leenkx/blender/lnx/logicnode/random/LN_probabilistic_index.py b/leenkx/blender/lnx/logicnode/random/LN_probabilistic_index.py new file mode 100644 index 0000000..6c68a23 --- /dev/null +++ b/leenkx/blender/lnx/logicnode/random/LN_probabilistic_index.py @@ -0,0 +1,51 @@ +from lnx.logicnode.lnx_nodes import * + + +class ProbabilisticIndexNode(LnxLogicTreeNode): + """This system gets an index based on probabilistic values, + ensuring that the total sum of the probabilities equals 1. + If the probabilities do not sum to 1, they will be adjusted + accordingly to guarantee a total sum of 1. Only one output will be + triggered at a time. + @output index: the index. + """ + + bl_idname = 'LNProbabilisticIndexNode' + bl_label = 'Probabilistic Index' + lnx_section = 'logic' + lnx_version = 1 + + num_choices: IntProperty(default=0, min=0) + + def __init__(self): + array_nodes[str(id(self))] = self + + def lnx_init(self, context): + + self.add_output('LnxIntSocket', 'Index') + + def draw_buttons(self, context, layout): + row = layout.row(align=True) + + op = row.operator('lnx.node_call_func', text='New', icon='PLUS', emboss=True) + op.node_index = str(id(self)) + op.callback_name = 'add_func' + op2 = row.operator('lnx.node_call_func', text='', icon='X', emboss=True) + op2.node_index = str(id(self)) + op2.callback_name = 'remove_func' + + def add_func(self): + self.add_input('LnxFloatSocket', f'Prob Index {self.num_choices}') + self.num_choices += 1 + + def remove_func(self): + if len(self.inputs) > 0: + self.inputs.remove(self.inputs[-1]) + self.num_choices -= 1 + + def draw_label(self) -> str: + if self.num_choices == 0: + return self.bl_label + + return f'{self.bl_label}: [{self.num_choices}]' +