Skip to content

Commit

Permalink
Merge pull request KhronosGroup#1134 from scurest/delete-useless-funcs
Browse files Browse the repository at this point in the history
Refactor: delete useless funcs
  • Loading branch information
julienduroure authored Jul 21, 2020
2 parents 143919d + 1a3ce08 commit 8ef625d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 33 deletions.
13 changes: 4 additions & 9 deletions addons/io_scene_gltf2/blender/com/gltf2_blender_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
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)

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':
Expand Down Expand Up @@ -138,15 +133,15 @@ 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()


def transform_rotation(rotation: Quaternion, transform: Matrix = Matrix.Identity(4)) -> Quaternion:
"""Transform rotation."""
rotation.normalize()
m = rotation.to_matrix().to_4x4()
m = multiply(transform, m)
m = transform @ m
return m.to_quaternion()


Expand All @@ -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()

Expand Down
6 changes: 0 additions & 6 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 6 additions & 7 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
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
Expand All @@ -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)
Expand All @@ -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]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def find_parent_joint(joints, name):
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]]
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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


Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8ef625d

Please sign in to comment.