diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-07-21 21:30:30 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-07-21 21:30:30 +0300 |
commit | 9313b3a155bbe5b84dca81431ca9167cda94035d (patch) | |
tree | d9ab42dbbcd45ebf98755248189cb154434d1501 /io_scene_gltf2/blender | |
parent | 47ea656bdd61e5d19f577b1155789e443e26e3e3 (diff) |
glTF exporter: refactoring: remove no more needed functions after 2.79
Diffstat (limited to 'io_scene_gltf2/blender')
6 files changed, 22 insertions, 33 deletions
diff --git a/io_scene_gltf2/blender/com/gltf2_blender_math.py b/io_scene_gltf2/blender/com/gltf2_blender_math.py index 72eb124a..bddc79a6 100755 --- a/io_scene_gltf2/blender/com/gltf2_blender_math.py +++ b/io_scene_gltf2/blender/com/gltf2_blender_math.py @@ -19,11 +19,6 @@ from mathutils import Matrix, Vector, Quaternion, Euler from io_scene_gltf2.blender.com.gltf2_blender_data_path import get_target_property_name -def multiply(a, b): - """Multiplication.""" - return a @ b - - def list_to_mathutils(values: typing.List[float], data_path: str) -> typing.Union[Vector, Quaternion, Euler]: """Transform a list to blender py object.""" target = get_target_property_name(data_path) @@ -31,7 +26,7 @@ def list_to_mathutils(values: typing.List[float], data_path: str) -> typing.Unio if target == 'delta_location': return Vector(values) # TODO Should be Vector(values) - Vector(something)? elif target == 'delta_rotation_euler': - return Euler(values).to_quaternion() # TODO Should be multiply(Euler(values).to_quaternion(), something)? + return Euler(values).to_quaternion() # TODO Should be Euler(values).to_quaternion() @ something? elif target == 'location': return Vector(values) elif target == 'rotation_axis_angle': @@ -138,7 +133,7 @@ def transform(v: typing.Union[Vector, Quaternion], data_path: str, transform: Ma def transform_location(location: Vector, transform: Matrix = Matrix.Identity(4)) -> Vector: """Transform location.""" m = Matrix.Translation(location) - m = multiply(transform, m) + m = transform @ m return m.to_translation() @@ -146,7 +141,7 @@ def transform_rotation(rotation: Quaternion, transform: Matrix = Matrix.Identity """Transform rotation.""" rotation.normalize() m = rotation.to_matrix().to_4x4() - m = multiply(transform, m) + m = transform @ m return m.to_quaternion() @@ -156,7 +151,7 @@ def transform_scale(scale: Vector, transform: Matrix = Matrix.Identity(4)) -> Ve m[0][0] = scale.x m[1][1] = scale.y m[2][2] = scale.z - m = multiply(transform, m) + m = transform @ m return m.to_scale() diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py index c28fddf9..6389d9dc 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_extract.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_extract.py @@ -122,12 +122,6 @@ def convert_swizzle_scale(scale, export_settings): return Vector((scale[0], scale[1], scale[2])) -def decompose_transition(matrix, export_settings): - translation, rotation, scale = matrix.decompose() - - return translation, rotation, scale - - def extract_primitives(glTF, blender_mesh, library, blender_object, blender_vertex_groups, modifiers, export_settings): """ Extract primitives from a mesh. Polygons are triangulated and sorted by material. diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py index f2375bb1..c3913367 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py @@ -343,10 +343,12 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve], (0.0, 0.0, 1.0, 0.0), (0.0, -1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0))) - correction_matrix_local = gltf2_blender_math.multiply(axis_basis_change, bone.bone.matrix_local) + correction_matrix_local = axis_basis_change @ bone.bone.matrix_local else: - correction_matrix_local = gltf2_blender_math.multiply( - bone.parent.bone.matrix_local.inverted(), bone.bone.matrix_local) + correction_matrix_local = ( + bone.parent.bone.matrix_local.inverted() @ + bone.bone.matrix_local + ) transform = correction_matrix_local else: diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py index 1cb26551..dff55d17 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py @@ -17,8 +17,6 @@ import mathutils from . import gltf2_blender_export_keys from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached from io_scene_gltf2.io.com import gltf2_io -from io_scene_gltf2.blender.exp import gltf2_blender_extract -from io_scene_gltf2.blender.com import gltf2_blender_math from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions from ..com.gltf2_blender_extras import generate_extras @@ -39,10 +37,12 @@ def gather_joint(blender_object, blender_bone, export_settings): # extract bone transform if blender_bone.parent is None: - correction_matrix_local = gltf2_blender_math.multiply(axis_basis_change, blender_bone.bone.matrix_local) + correction_matrix_local = axis_basis_change @ blender_bone.bone.matrix_local else: - correction_matrix_local = gltf2_blender_math.multiply( - blender_bone.parent.bone.matrix_local.inverted(), blender_bone.bone.matrix_local) + correction_matrix_local = ( + blender_bone.parent.bone.matrix_local.inverted() @ + blender_bone.bone.matrix_local + ) if (blender_bone.bone.use_inherit_rotation == False or blender_bone.bone.inherit_scale != "FULL") and blender_bone.parent != None: rest_mat = (blender_bone.parent.bone.matrix_local.inverted_safe() @ blender_bone.bone.matrix_local) @@ -51,8 +51,7 @@ def gather_joint(blender_object, blender_bone, export_settings): matrix_basis = blender_bone.matrix matrix_basis = blender_object.convert_space(pose_bone=blender_bone, matrix=matrix_basis, from_space='POSE', to_space='LOCAL') - trans, rot, sca = gltf2_blender_extract.decompose_transition( - gltf2_blender_math.multiply(correction_matrix_local, matrix_basis), export_settings) + trans, rot, sca = (correction_matrix_local @ matrix_basis).decompose() translation, rotation, scale = (None, None, None) if trans[0] != 0.0 or trans[1] != 0.0 or trans[2] != 0.0: translation = [trans[0], trans[1], trans[2]] diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py index b2ca5be5..b09e7aa1 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py @@ -189,8 +189,8 @@ def __gather_children(blender_object, blender_scene, export_settings): rot_quat = Quaternion(rot) axis_basis_change = Matrix( ((1.0, 0.0, 0.0, 0.0), (0.0, 0.0, -1.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0))) - mat = gltf2_blender_math.multiply(child.matrix_parent_inverse, child.matrix_basis) - mat = gltf2_blender_math.multiply(mat, axis_basis_change) + mat = child.matrix_parent_inverse @ child.matrix_basis + mat = mat @ axis_basis_change _, rot_quat, _ = mat.decompose() child_node.rotation = [rot_quat[1], rot_quat[2], rot_quat[3], rot_quat[0]] @@ -404,7 +404,7 @@ def __gather_trans_rot_scale(blender_object, export_settings): if blender_object.matrix_local[3][3] != 0.0: - trans, rot, sca = gltf2_blender_extract.decompose_transition(blender_object.matrix_local, export_settings) + trans, rot, sca = blender_object.matrix_local.decompose() else: # Some really weird cases, scale is null (if parent is null when evaluation is done) print_console('WARNING', 'Some nodes are 0 scaled during evaluation. Result can be wrong') diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py index fa95e543..7f645272 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py @@ -20,7 +20,6 @@ from io_scene_gltf2.io.exp import gltf2_io_binary_data from io_scene_gltf2.io.com import gltf2_io_constants from io_scene_gltf2.blender.exp import gltf2_blender_gather_accessors from io_scene_gltf2.blender.exp import gltf2_blender_gather_joints -from io_scene_gltf2.blender.com import gltf2_blender_math from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @@ -85,10 +84,10 @@ def __gather_inverse_bind_matrices(blender_object, export_settings): # traverse the matrices in the same order as the joints and compute the inverse bind matrix def __collect_matrices(bone): - inverse_bind_matrix = gltf2_blender_math.multiply( - axis_basis_change, - gltf2_blender_math.multiply( - blender_object.matrix_world, + inverse_bind_matrix = ( + axis_basis_change @ + ( + blender_object.matrix_world @ bone.bone.matrix_local ) ).inverted() |