Skip to content

Commit

Permalink
This got to be the stupidest oversight ever
Browse files Browse the repository at this point in the history
  • Loading branch information
Crowfunder committed Jun 22, 2023
1 parent b404ab1 commit bcf931d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions modules/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def EulerToQuaternion(euler_rotations):
# Trig functs of all angles with abbreviations
# i.e. "cx" for cos(x*0.5)
cx = math.cos(x*0.5)
sx = math.cos(x*0.5)
cy = math.cos(y*0.5)
sy = math.cos(y*0.5)
cz = math.cos(z*0.5)
sz = math.cos(z*0.5)
sx = math.sin(x*0.5)
sy = math.sin(y*0.5)
sz = math.sin(z*0.5)

# Calculate quaternion elements
quaternion['x'] = sx * cy * cz - cx * sy * sz;
quaternion['y'] = cx * sy * cz + sx * cy * sz;
quaternion['z'] = cx * cy * sz - sx * sy * cz;
quaternion['w'] = cx * cy * cz + sx * sy * sz;
quaternion['x'] = sx * cy * cz - cx * sy * sz
quaternion['y'] = cx * sy * cz + sx * cy * sz
quaternion['z'] = cx * cy * sz - sx * sy * cz
quaternion['w'] = cx * cy * cz + sx * sy * sz

return quaternion

Expand Down Expand Up @@ -521,6 +521,12 @@ def ArmatureNodeFinder(main_node, funct_mode, armature_node_name=None):
armature_node = output_node
unnamed_bone_num = 0

# Warning issued if uniform scale approximation is detected
# It sucks, it seriously, seriously sucks, so the user should know
# Var has to be defined outside of the function so that
# it can be sent just once
scale_approx_warn = False

### BEGIN ArmatureNodeToXML
def ArmatureNodeToXML(main_node, path=list(), xml_path=list()):

Expand Down Expand Up @@ -583,10 +589,6 @@ def ArmatureNodeToXML(main_node, path=list(), xml_path=list()):
# Marker that will signify that Euler rotations
# need to be converted to quaternion
euler_rotations_exist = False

# Warning issued if uniform scale approximation is detected
# It sucks, it seriously, seriously sucks, so the user should know
scale_approx_warn = False

# Handle various transform types
# It feels redundant but some tags' data
Expand All @@ -608,6 +610,7 @@ def ArmatureNodeToXML(main_node, path=list(), xml_path=list()):
elif type(node_transform) is collada.scene.ScaleTransform:
xml_trfm_chld_node = ET.SubElement(xml_trfm_node, 'scale')

nonlocal scale_approx_warn
if not scale_approx_warn:
print('[MODULE][WARNING]: Uniform scale approximation detected, '
'it is not accurate and may break the armature, '
Expand Down

1 comment on commit bcf931d

@Crowfunder
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: In case of any problems, an alternate formula for converting Euler Angles to Quaternions is available, sourced from EuclideanSpace

    quaternion['x'] = sx*sy*cz + cx*cy*sz
    quaternion['y'] = sx*cy*cz + cx*sy*sz
    quaternion['z'] = cx*sy*cz - sx*cy*sz
    quaternion['w'] = cx*cy*cz - sx*sy*sz

Please sign in to comment.