diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 92d828bb9cc91f7e5b8a90013535e973b91ae485..57bdf3d5d611222c2a0e4f4af48d724639d39165 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -15,7 +15,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin SchmithĂĽsen, Jim Eckerlein, and many external contributors', - "version": (1, 3, 38), + "version": (1, 3, 39), 'blender': (2, 90, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/com/gltf2_blender_math.py b/io_scene_gltf2/blender/com/gltf2_blender_math.py index 72eb124ad91dc170b7a4310da22a0bf8252fdaae..bddc79a69b329404e2edd99575643c00733fb721 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 c28fddf964363cadba962ccd03480ddce916a8ae..6389d9dc7f13673f4a7f17e08413bc47769f0974 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 f2375bb1846732ec2f3ab8b37e94ba8fa6df3a78..c39133672c7aefbfae3b830261a7c815b9e8b072 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 1cb2655191f2f84bdb3a5e54be7e820db4036b50..dff55d17f4d9f6ce3318aab6bd6cc11ded415f4d 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 b2ca5be5b1a26b15a5618ff2efcc8c71a8c50dab..b09e7aa123e1a0eabfbe77763c9a1c92a22e1d2b 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 fa95e54324b9960c7ff179e2bcf4eaf1fabb0aa7..7f645272493f4e58d0617c91317b8715e9c6c994 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()