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).
This commit is contained in:
Bastien Montagne 2015-01-14 13:00:52 +01:00
parent c8a9a563a7
commit edad3f93f6

@ -21,6 +21,7 @@
__all__ = ( __all__ = (
"ExportHelper", "ExportHelper",
"ImportHelper", "ImportHelper",
"IOHelperOrientation",
"axis_conversion", "axis_conversion",
"axis_conversion_ensure", "axis_conversion_ensure",
"create_derived_objects", "create_derived_objects",
@ -116,6 +117,40 @@ class ImportHelper:
return _check_axis_conversion(self) 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 # Axis conversion function, not pretty LUT
# use lookup table to convert between any axis # use lookup table to convert between any axis
_axis_convert_matrix = ( _axis_convert_matrix = (