[SOLVED] - Rotation maths

nategovannategovan Posts: 35

Hi,

TLDR; How can I convert a rotations with 3 >90° rotations to under 90°.

I'm programmatically importing and mapping some animations from another source but some of the rotations are extreme (in the 1000s of degrees) and look very strange in daz for obvious reasons. My simple brain says 'surely there is a better way to represent these angles all under +/-90 degress', but I haven't been able to work it out. I've tried converting the original angles to quaternions and recalculating the euler angles etc (to get the xyz rotations for daz), the result is similar, but not exact. (Eg, https://www.andre-gaschler.com/rotationconverter/)

Is there a simple solution that I can't see, or is it just a case of completely incompatible rotations in my source?

Example: 

  normalised source angle roughly expected **
x 152.0317 -30.24771
y -148.5373 -32.39716
z -153.8322 24.66619

** A visually similar angle as per the photo: These are not the same angles, just an attempt to manually dialling them in.

Any help would be appreciated.

Thanks,

Dan


For some reason, I cannot add another post on this topic... so...

SOLVED - Thanks all for your inputs. I've solved my immediate problem with a destructive transformation from euler angles into Quarternions and back into euler angles, but it works perfectly.

I was actually doing this in blender (primarily because the Daz FBX import doesn't work in my case), so I programmatically changed the rotation order of the bones to Quarternion then back again to the original euler rotation order and in doing so, it sets them at much more reasonable values with an impercetible difference. This works perfectly and gets me to the xyz angles of -20.43, -31.46, 26.17. Much better. For completeness, I then use these to write a .duf within blender and the imported animation in Daz works perfectly.

 


 

At risk of causing some fuss, I appreciate that there are issues and clarity regarding the coordinate system and rotation mechanism, but for this specific task, I have found what I need and will mark it as resolved. @TheMysteryIsThePoint 's point remains, but I feel as though this is probably not the correct location to address it.

I myself haven't found any issues with the co-ordinate system as of yet and I generally have been using euler angle's with their respective rotation orders for a number of imported animations without issue so far, but I'm a relative beginner when it comes to 3d rotations so I still have a way to go. Thanks all.

Post edited by nategovan on

Comments

  • felisfelis Posts: 4,305

    As I see it, then no.

    A full circle is 360, so it can only be within -180 to 180.

  • I've struggled with this for a long time. The term "Euler angles" is vague and doesn't tell you all you need to know to have a precise understanding of how they are caculated/interpreted. I've seen countless people confused about this. It would be really nice if a dev could step in and set us all straight with just a few sentences.... Maybe @DAZ_sam or @DAZ_vish could treat this all-important subject for us? If there were some code samples for how bone orientation and rotations are reckoned, I think I'd faint :)

  • NorthOf45NorthOf45 Posts: 5,480

    It depends on the orientation of the coordinate system and the order of the rotations. I still get twisted around by it.

  • TheMysteryIsThePointTheMysteryIsThePoint Posts: 2,946
    edited June 2021

    NorthOf45 said:

    It depends on the orientation of the coordinate system and the order of the rotations. I still get twisted around by it.

    @NorthOf45 I wish it were that simple. We know Daz Studio's handedness, and we can get the rotation order for each bone. Unfortunately, it is worse than that.

    There are several notions that are colloquially referred to as "Euler Angles" and they fall into at least two gross sets, one where the successive rotations are made against the original unrotated reference frame, and another where they are made against the new, rotated reference frame at each step. One can prove analytically that both ways can still represent all rotations, so they are both valid. Neither of the two seem to work the way Daz Studio does, and there are even more possibilities for things that people call "Euler Angles".

    We need to know specfically how Daz reckons rotations. Code would be the definitive answer.

     

    Post edited by TheMysteryIsThePoint on
  • richardandtracyrichardandtracy Posts: 5,661
    edited June 2021

    Front-Back Resultant = -180-current value. 

    Example: Current value of Front-Back = -148.54. so, -180 - (-148.54) = -31.46 which is almost the figure in the ticked value of -32.40

    Bend Resultant = 180 + current value

    Twist Resultant = current value - 180.

    Is it a common thing you get? If so it may be worth a 'fix' script.

    Regards,

    Richard.

    Post edited by richardandtracy on
  • nategovannategovan Posts: 35

    SOLVED - Thanks all for your inputs. I've solved my immediate problem with a destructive transformation from euler angles into Quarternions and back into euler angles, but it works perfectly.

    I was actually doing this in blender (primarily because the Daz FBX import doesn't work in my case), so I programmatically changed the rotation order of the bones to Quarternion then back again to the original euler rotation order and in doing so, it sets them at much more reasonable values with an impercetible difference. This works perfectly and gets me to the xyz angles of -20.43, -31.46, 26.17. Much better. For completeness, I then use these to write a .duf within blender and the imported animation in Daz works perfectly.

     


     

    At risk of causing some fuss, I appreciate that there are issues and clarity regarding the coordinate system and rotation mechanism, but for this specific task, I have found what I need and will mark it as resolved. @TheMysteryIsThePoint 's point remains, but I feel as though this is probably not the correct location to address it.

    I myself haven't found any issues with the co-ordinate system as of yet and I generally have been using euler angle's with their respective rotation orders for a number of imported animations without issue so far, but I'm a relative beginner when it comes to 3d rotations so I still have a way to go. Thanks all.

  • @dangarfielduk

    I'm happy that you've found something that seems to work. But could you clarify something?

    It seems like you're saying that we may not know precisely what Daz Studio is doing, but whatever it is, it seems to be compatible with the way that Blender reckons rotations? I tried having Blender write quaternions and Daz Studio read them, but it did not even remotely work.

    Are you saying that you did not have to apply the fixes @richardandtracy mentioned?

    If you have the time, and are so inclined, could you describe what you had to do in pseudocode on the Blender and Daz sides to get it to work?

     

  • nategovannategovan Posts: 35
    edited June 2021

    @TheMysteryIsThePoint Sure, I'll happy to elaborate.

    My Core Objective:
    - I have a large number of humanoid FBXs that I want to translate to Daz animations

    Notes:
    - Ultimately, this is a rigging and mapping question but I haven't found a tool that accomplishes this well as there are some unusual orientations in the source FBX bones
    - I had tried using the standard DAZ bridge and it works, but it seemed a little less consistent than using the diffeomorphic tool. At least at first, I might try later

    Process (all programmatic):
    - Process the source models and animations into individual FBX files (2020.0.1 format works the best with blender but not at all with Daz, FBX 2006 works in Daz (albeit badly), but not in blender)
    - Create a male and female Genesis 8 Dev kit characters and scenes in Daz and save as scenes & diffeomorphic .dbz's
    - Import both gen 8 chars into Blender using diffeomorphic import
    - Define a bone mapping list from the source to Gen 8
    - As not all bones are correctly oriented (not only slight tpose adjustments, but some bones (abdomen, chest, shoulders) actually face different directions), create a basic shape in blender and apply a rotation to it specific to the adjustment required
    - Sequentially import each source FBX and:
    - Reset all gen 8 pose data and properly orient Daz character
    - For each gen 8 bone in the bone mapping list, apply a copy rotation constraint from the mapped bone on the source model
    - For each 'problem' bone, also apply a copy rotation constraint from the basic shape created to correct the rotation - This is incredibly useful
    - The animations will then look the same (well, as similar as two different humanoid figures are going to be) but there is no actual rotation data associated with the gen 8 bones
    - Iterate through each animation frame and apply `bpy.ops.pose.visual_transform_apply()` which sets the rotation result which is the OUTPUT of the constraints into an absolute value on the gen 8 bone itself
    - For each bone in each frame, get the euler rotation mode and value
    - Some of these values are crazy because the source data doesn't have skin affectable twists etc, eg 720 is pretty common, hence this question. In this case, change the rotation mode to Quaternion, then back to the original mode, and convert to sensible degrees number (eg, 359 = -1)
    - Create an export list of all bones' x, y, z rotations for each frame (take care to apply apply ThighBend.y to ThighTwist.y, ShldrBend.x to ShldrTwist.x and ForearmBend.x to ForearmTwist.x)
    - Create json file and write the output to a .duf
    - Render a small .png preview within blender to the same path as the .duf


    I believe the reason why this works well is that the diffeomorphic importer maps the euler modes used by the Daz model bones (eg, lShldrBend - XYZ, lForearmBend - XZY, lThighBend, pelvis - YZX etc). This way, when the rotation values are taken from blender and applied in Daz, everything seems to line up correctly.

    I'm not sure if this is or isn't useful, but it's been a nice learning curve for me to understand both tools.

    Post edited by nategovan on
  • @dangarfielduk Thanks for that detailed explanation. It's frustrating when the math around nested reference frames is so simple but figuring out the particulars of Daz Studio is so hard.

  • @nategovan Almost a year and a half later, I realize that I thanked the wrong user :) Sorry about that.

Sign In or Register to comment.