From a20d6b581c8581b66903eb391938963114dd4672 Mon Sep 17 00:00:00 2001 From: Onek8 Date: Tue, 8 Apr 2025 17:24:50 +0000 Subject: [PATCH] Update leenkx/blender/lnx/nodes_logic.py --- leenkx/blender/lnx/nodes_logic.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/leenkx/blender/lnx/nodes_logic.py b/leenkx/blender/lnx/nodes_logic.py index 5f43e33..dc125bd 100644 --- a/leenkx/blender/lnx/nodes_logic.py +++ b/leenkx/blender/lnx/nodes_logic.py @@ -344,6 +344,8 @@ class LNX_PT_NodeDevelopment(bpy.types.Panel): layout.separator() layout.operator('lnx.node_replace_all') + layout.operator('lnx.recalculate_rotations') + @staticmethod def _draw_row(col: bpy.types.UILayout, text: str, val: Any): @@ -366,6 +368,40 @@ class LNX_OT_ReplaceNodesOperator(bpy.types.Operator): def poll(cls, context): return context.space_data is not None and context.space_data.type == 'NODE_EDITOR' +class LNX_OT_RecalculateRotations(bpy.types.Operator): + """Recalculates internal rotation values for all rotation sockets in the tree""" + bl_idname = "lnx.recalculate_rotations" + bl_label = "Recalculate Rotations" + bl_description = "Forces recalculation of internal quaternion values for all LnxRotationSockets in the active tree using their current settings. Useful for fixing old files." + bl_options = {'REGISTER', 'UNDO'} + + @classmethod + def poll(cls, context): + return (context.space_data is not None and + context.space_data.type == 'NODE_EDITOR' and + context.space_data.tree_type == 'LnxLogicTreeType' and + context.space_data.edit_tree is not None) + + def execute(self, context): + tree = context.space_data.edit_tree + if not tree: + self.report({'WARNING'}, "No active Logic Node tree found") + return {'CANCELLED'} + recalculated_count = 0 + for node in tree.nodes: + for socket in list(node.inputs) + list(node.outputs): + if hasattr(socket, 'do_update_raw') and callable(socket.do_update_raw): + try: + socket.do_update_raw(context) + recalculated_count += 1 + except Exception as e: + print(f"Error recalculating socket '{socket.name}' on node '{node.name}': {e}") + + self.report({'INFO'}, f"Recalculated {recalculated_count} rotation sockets in tree '{tree.name}'") + tree.update_tag() + return {'FINISHED'} + + class LNX_UL_InterfaceSockets(bpy.types.UIList): """UI List of input and output sockets""" def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): @@ -421,6 +457,7 @@ __REG_CLASSES = ( LnxOpenNodePythonSource, LnxOpenNodeWikiEntry, LNX_OT_ReplaceNodesOperator, + LNX_OT_RecalculateRotations, LNX_MT_NodeAddOverride, LNX_OT_AddNodeOverride, LNX_UL_InterfaceSockets,