diff --git a/bms_blender_plugin/common/coordinates.py b/bms_blender_plugin/common/coordinates.py index 20b829c..a860ae3 100644 --- a/bms_blender_plugin/common/coordinates.py +++ b/bms_blender_plugin/common/coordinates.py @@ -1,11 +1,11 @@ from mathutils import Vector, Matrix, Quaternion, Euler -# Define the matrices here -BMS_SPACE_MATRIX = Matrix(((1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0), (0, 0, 0, 1))) +# Define the matrices here - updated for correct BMS coordinate system (-Z forward, -X right, Y up) +BMS_SPACE_MATRIX = Matrix(((0, 0, -1, 0), (-1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 0, 1))) BMS_SPACE_MATRIX_INV = BMS_SPACE_MATRIX.inverted_safe() def to_bms_coords(data, space_mat=BMS_SPACE_MATRIX, space_mat_inv=BMS_SPACE_MATRIX_INV): - """Transforms from Blender space to BMS space (-Z forward, Y up).""" + """Transforms from Blender space to BMS space (-Z forward, -X right, Y up).""" # matrix if type(data) is Matrix: return space_mat @ data.to_4x4() @ space_mat_inv diff --git a/bms_blender_plugin/preferences.py b/bms_blender_plugin/preferences.py index 4b32589..e7f8d26 100644 --- a/bms_blender_plugin/preferences.py +++ b/bms_blender_plugin/preferences.py @@ -89,6 +89,20 @@ class ExporterPreferences(bpy.types.AddonPreferences): description="The size of the Empty to display a Scale DOF as" ) + switch_empty_type: EnumProperty( + name="Switch", + description="The Empty to display a Switch as", + items=empty_enum_items, + default="SPHERE", + ) + + switch_empty_size: FloatProperty( + default=1.0, + min=0.01, + name="Size", + description="The size of the Empty to display a Switch as" + ) + def draw(self, context): layout = self.layout @@ -98,8 +112,11 @@ def draw(self, context): box.prop(self, "copy_to_clipboard_command", expand=True) layout.separator() - layout.label(text="DOF Display") + layout.label(text="DOF/Switch") box = layout.box() + # Ajout de l'opérateur RefreshDofList ici + box.operator("bml.refresh_dof_switch_list", icon="FILE_REFRESH", text="Refresh DOF/Switch Lists") + row = box.row() row.prop(self, "dof_rotate_empty_type") row.prop(self, "dof_rotate_empty_size") @@ -112,6 +129,10 @@ def draw(self, context): row.prop(self, "dof_scale_empty_type") row.prop(self, "dof_scale_empty_size") + row = box.row() + row.prop(self, "switch_empty_type") + row.prop(self, "switch_empty_size") + box.operator(ApplyEmptyDisplaysToDofs.bl_idname, icon="CHECKMARK") layout.separator() @@ -125,7 +146,7 @@ def draw(self, context): class ApplyEmptyDisplaysToDofs(Operator): """Applies the preferences for the DOF empties to all objects in the scene""" bl_idname = "bml.apply_empty_displays_to_dofs" - bl_label = "Apply to all DOFs" + bl_label = "Apply sizes to scene" bl_description = "Applies the display preferences to all DOFs in the scene" # noinspection PyMethodMayBeStatic @@ -139,26 +160,23 @@ def execute(self, context): scale_empty = context.preferences.addons["bms_blender_plugin"].preferences.dof_scale_empty_type scale_empty_size = context.preferences.addons["bms_blender_plugin"].preferences.dof_scale_empty_size - translate_empty = context.preferences.addons["bms_blender_plugin"].preferences.dof_translate_empty_type - scale_empty = context.preferences.addons["bms_blender_plugin"].preferences.dof_scale_empty_type + switch_empty = context.preferences.addons["bms_blender_plugin"].preferences.switch_empty_type + switch_empty_size = context.preferences.addons["bms_blender_plugin"].preferences.switch_empty_size for obj in bpy.data.objects: if get_bml_type(obj) == BlenderNodeType.DOF: if obj.dof_type == DofType.ROTATE.name: obj.empty_display_type = rotate_empty obj.empty_display_size = rotate_empty_size - elif obj.dof_type == DofType.TRANSLATE.name: obj.empty_display_type = translate_empty obj.empty_display_size = translate_empty_size - elif obj.dof_type == DofType.SCALE.name: obj.empty_display_type = scale_empty obj.empty_display_size = scale_empty_size - elif obj.dof_type == DofType.TRANSLATE.name: - obj.empty_display_type = translate_empty - elif obj.dof_type == DofType.SCALE.name: - obj.empty_display_type = scale_empty + elif get_bml_type(obj) == BlenderNodeType.SWITCH: + obj.empty_display_type = switch_empty + obj.empty_display_size = switch_empty_size return {"FINISHED"} diff --git a/bms_blender_plugin/ui_tools/dof_behaviour.py b/bms_blender_plugin/ui_tools/dof_behaviour.py index 9ec19b8..7b7c607 100644 --- a/bms_blender_plugin/ui_tools/dof_behaviour.py +++ b/bms_blender_plugin/ui_tools/dof_behaviour.py @@ -170,6 +170,14 @@ def update_dof_display_type(obj, context): obj.empty_display_size = context.preferences.addons[ "bms_blender_plugin" ].preferences.dof_scale_empty_size + + elif get_bml_type(obj) == BlenderNodeType.SWITCH: + obj.empty_display_type = context.preferences.addons[ + "bms_blender_plugin" + ].preferences.switch_empty_type + obj.empty_display_size = context.preferences.addons[ + "bms_blender_plugin" + ].preferences.switch_empty_size def dof_set_input(obj, value): diff --git a/bms_blender_plugin/ui_tools/operators/create_switch.py b/bms_blender_plugin/ui_tools/operators/create_switch.py index c77d4f6..f1250a0 100644 --- a/bms_blender_plugin/ui_tools/operators/create_switch.py +++ b/bms_blender_plugin/ui_tools/operators/create_switch.py @@ -29,6 +29,10 @@ def execute(self, context): ) switch_object.bml_type = str(BlenderNodeType.SWITCH) + # Apply size from preferences + preferences = bpy.context.preferences.addons["bms_blender_plugin"].preferences + switch_object.scale = (preferences.switch_empty_size,) * 3 + if context.active_object: # assumes that every object is linked to at least one collection context.active_object.users_collection[0].objects.link(switch_object) diff --git a/bms_blender_plugin/ui_tools/operators/dof_operators.py b/bms_blender_plugin/ui_tools/operators/dof_operators.py index b0eaaf6..172f81e 100644 --- a/bms_blender_plugin/ui_tools/operators/dof_operators.py +++ b/bms_blender_plugin/ui_tools/operators/dof_operators.py @@ -52,13 +52,73 @@ def execute(self, context): return{'FINISHED'} +class RefreshDofAndSwitchList(Operator): + """Refreshes the DOF/Switch lists from the XML files""" + bl_idname = "bml.refresh_dof_switch_list" + bl_label = "Apply sizes to scene" # Updated label + bl_description = "Refreshes the DOF and Switch lists from the XML files and applies sizes from preferences" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + from bms_blender_plugin.common.util import get_dofs, get_switches + import importlib + import sys + + # Clear stored lists from the scene + if 'dof_list' in context.scene: + del context.scene['dof_list'] + if 'switch_list' in context.scene: + del context.scene['switch_list'] + + # Reload the utility module and clear caches + util_module = sys.modules['bms_blender_plugin.common.util'] + importlib.reload(util_module) + if hasattr(get_dofs, 'cache_clear'): + get_dofs.cache_clear() + if hasattr(get_switches, 'cache_clear'): + get_switches.cache_clear() + + # Load the refreshed data + new_dofs = get_dofs() + new_switches = get_switches() + + # Get size preferences + preferences = context.preferences.addons[__name__].preferences + dof_size = preferences.dof_size + switch_size = preferences.switch_size + + # Populate scene DOF list + for dof in new_dofs: + item = context.scene.dof_list.add() + item.name = dof.name + item.dof_number = int(dof.dof_number) + item.size = dof_size # Apply size from preferences + + # Populate scene Switch list + for switch in new_switches: + item = context.scene.switch_list.add() + item.name = switch.name + item.switch_number = int(switch.switch_number) + item.size = switch_size # Apply size from preferences + + # Force redraw of all UI areas + for area in context.screen.areas: + if area.type == 'PROPERTIES': # Adjust this to the correct area type if needed + area.tag_redraw() + + self.report({'INFO'}, "DOF and Switch lists refreshed and sizes applied") + return {'FINISHED'} + + def register(): bpy.utils.register_class(ResetSingleDof) bpy.utils.register_class(ResetAllDofs) bpy.utils.register_class(CreateDofKeyframe) + bpy.utils.register_class(RefreshDofAndSwitchList) def unregister(): bpy.utils.unregister_class(CreateDofKeyframe) bpy.utils.unregister_class(ResetAllDofs) bpy.utils.unregister_class(ResetSingleDof) + bpy.utils.unregister_class(RefreshDofAndSwitchList)