From edad3f93f6da549456ffe8711336d34c7819dbe7 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 14 Jan 2015 13:00:52 +0100 Subject: [PATCH] Py IO utils: Add helper class to handle orientation (axes). Also 'fix' T43243, since we can easily add a common better behavior now when both axis settings are incompatible, by systematically changing the other axis. Will update 'main' addons in next commit, contrib ones I'll let to the authors (old behavior is still possible anyway). --- .../scripts/modules/bpy_extras/io_utils.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/release/scripts/modules/bpy_extras/io_utils.py b/release/scripts/modules/bpy_extras/io_utils.py index b1877a9d439..d1eb01a4f11 100644 --- a/release/scripts/modules/bpy_extras/io_utils.py +++ b/release/scripts/modules/bpy_extras/io_utils.py @@ -21,6 +21,7 @@ __all__ = ( "ExportHelper", "ImportHelper", + "IOHelperOrientation", "axis_conversion", "axis_conversion_ensure", "create_derived_objects", @@ -116,6 +117,40 @@ class ImportHelper: return _check_axis_conversion(self) +class IOHelperOrientation: + def _update_axis_forward(self, context): + if self.axis_forward[-1] == self.axis_up[-1]: + self.axis_up = self.axis_up[0:-1] + 'XYZ'[('XYZ'.index(self.axis_up[-1]) + 1) % 3] + axis_forward = EnumProperty( + name="Forward", + items=(('X', "X Forward", ""), + ('Y', "Y Forward", ""), + ('Z', "Z Forward", ""), + ('-X', "-X Forward", ""), + ('-Y', "-Y Forward", ""), + ('-Z', "-Z Forward", ""), + ), + default='-Z', + update=_update_axis_forward, + ) + + def _update_axis_up(self, context): + if self.axis_up[-1] == self.axis_forward[-1]: + self.axis_forward = self.axis_forward[0:-1] + 'XYZ'[('XYZ'.index(self.axis_forward[-1]) + 1) % 3] + axis_up = EnumProperty( + name="Up", + items=(('X', "X Up", ""), + ('Y', "Y Up", ""), + ('Z', "Z Up", ""), + ('-X', "-X Up", ""), + ('-Y', "-Y Up", ""), + ('-Z', "-Z Up", ""), + ), + default='Y', + update=_update_axis_up, + ) + + # Axis conversion function, not pretty LUT # use lookup table to convert between any axis _axis_convert_matrix = (