|
@@ -2,6 +2,7 @@ import math
|
|
import mathutils
|
|
import mathutils
|
|
import bpy
|
|
import bpy
|
|
from bpy import data, context, types
|
|
from bpy import data, context, types
|
|
|
|
+from bpy_extras.io_utils import axis_conversion
|
|
from .. import constants, logger, utilities, exceptions
|
|
from .. import constants, logger, utilities, exceptions
|
|
from .constants import (
|
|
from .constants import (
|
|
MESH,
|
|
MESH,
|
|
@@ -225,14 +226,8 @@ def position(obj, options):
|
|
|
|
|
|
"""
|
|
"""
|
|
logger.debug('object.position(%s)', obj)
|
|
logger.debug('object.position(%s)', obj)
|
|
- vector = _decompose_matrix(obj)[0]
|
|
|
|
- vector = (vector.x, vector.y, vector.z)
|
|
|
|
-
|
|
|
|
- round_off, round_val = utilities.rounding(options)
|
|
|
|
- if round_off:
|
|
|
|
- vector = utilities.round_off(vector, round_val)
|
|
|
|
-
|
|
|
|
- return vector
|
|
|
|
|
|
+ vector = matrix(obj, options).to_translation()
|
|
|
|
+ return (vector.x, vector.y, vector.z)
|
|
|
|
|
|
|
|
|
|
@_object
|
|
@_object
|
|
@@ -250,23 +245,35 @@ def receive_shadow(obj):
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
+AXIS_CONVERSION = axis_conversion(to_forward='Z', to_up='Y').to_4x4()
|
|
|
|
+
|
|
@_object
|
|
@_object
|
|
-def rotation(obj, options):
|
|
|
|
|
|
+def matrix(obj, options):
|
|
"""
|
|
"""
|
|
|
|
|
|
:param obj:
|
|
:param obj:
|
|
:param options:
|
|
:param options:
|
|
|
|
|
|
"""
|
|
"""
|
|
- logger.debug('object.rotation(%s)', obj)
|
|
|
|
- vector = _decompose_matrix(obj)[1].to_euler(ZYX)
|
|
|
|
- vector = (vector.x, vector.y, vector.z)
|
|
|
|
|
|
+ logger.debug('object.matrix(%s)', obj)
|
|
|
|
+ if options.get(constants.HIERARCHY, False) and obj.parent:
|
|
|
|
+ parent_inverted = obj.parent.matrix_world.inverted(mathutils.Matrix())
|
|
|
|
+ return parent_inverted * obj.matrix_world
|
|
|
|
+ else:
|
|
|
|
+ return AXIS_CONVERSION * obj.matrix_world
|
|
|
|
+
|
|
|
|
|
|
- round_off, round_val = utilities.rounding(options)
|
|
|
|
- if round_off:
|
|
|
|
- vector = utilities.round_off(vector, round_val)
|
|
|
|
|
|
+@_object
|
|
|
|
+def rotation(obj, options):
|
|
|
|
+ """
|
|
|
|
+
|
|
|
|
+ :param obj:
|
|
|
|
+ :param options:
|
|
|
|
|
|
- return vector
|
|
|
|
|
|
+ """
|
|
|
|
+ logger.debug('object.rotation(%s)', obj)
|
|
|
|
+ vector = matrix(obj, options).to_euler(ZYX)
|
|
|
|
+ return (vector.x, vector.y, vector.z)
|
|
|
|
|
|
|
|
|
|
@_object
|
|
@_object
|
|
@@ -278,14 +285,8 @@ def scale(obj, options):
|
|
|
|
|
|
"""
|
|
"""
|
|
logger.debug('object.scale(%s)', obj)
|
|
logger.debug('object.scale(%s)', obj)
|
|
- vector = _decompose_matrix(obj)[2]
|
|
|
|
- vector = (vector.x, vector.y, vector.z)
|
|
|
|
-
|
|
|
|
- round_off, round_val = utilities.rounding(options)
|
|
|
|
- if round_off:
|
|
|
|
- vector = utilities.round_off(vector, round_val)
|
|
|
|
-
|
|
|
|
- return vector
|
|
|
|
|
|
+ vector = matrix(obj, options).to_scale()
|
|
|
|
+ return (vector.x, vector.y, vector.z)
|
|
|
|
|
|
|
|
|
|
@_object
|
|
@_object
|
|
@@ -477,24 +478,6 @@ def extracted_meshes():
|
|
return [key for key in _MESH_MAP.keys()]
|
|
return [key for key in _MESH_MAP.keys()]
|
|
|
|
|
|
|
|
|
|
-def _decompose_matrix(obj, local=False):
|
|
|
|
- """
|
|
|
|
-
|
|
|
|
- :param obj:
|
|
|
|
- :param local: (Default value = False)
|
|
|
|
-
|
|
|
|
- """
|
|
|
|
- rotate_x_pi2 = mathutils.Quaternion((1.0, 0.0, 0.0),
|
|
|
|
- math.radians(-90.0))
|
|
|
|
- rotate_x_pi2 = rotate_x_pi2.to_matrix().to_4x4()
|
|
|
|
-
|
|
|
|
- if local:
|
|
|
|
- matrix = rotate_x_pi2 * obj.matrix_local
|
|
|
|
- else:
|
|
|
|
- matrix = rotate_x_pi2 * obj.matrix_world
|
|
|
|
- return matrix.decompose()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def _on_visible_layer(obj, visible_layers):
|
|
def _on_visible_layer(obj, visible_layers):
|
|
"""
|
|
"""
|
|
|
|
|