Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Created April 3, 2019 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukpazera/e6052e157bf549f25ae46532b2e26924 to your computer and use it in GitHub Desktop.
Save lukpazera/e6052e157bf549f25ae46532b2e26924 to your computer and use it in GitHub Desktop.
This gist will calculate rotation offset angle values for a rotation constraint between two items in MODO.
""" This gist will calculate rotation offset angle values for a rotation constraint
between two items in MODO. It'll be exactly the same as setting up the constraint
with compensation turned on.
This code can be useed to update existing rotation constraint setup with new offset
without reapplying the constraint again.
The process is simple.
- get the world rotation matrix of the target and invert it.
- multiply source world rotation matrix by the inverted target matrix.
- Invert the resulting matrix - it looks like the offset is an inverted matrix so
this step is required.
- convert result to euler angles with 'xyz' rotation order.
"""
import modo
# Select source item first and the target (the item to constrain to) second.
selection = modo.Scene().selected
source = selection[0]
target = selection[1]
# IMPORTANT : You have to get world rotation matrix as Matrix4!!!!
# It looks like Matrix3 has different column/row order so if you get
# world rotation as Matrix3 you will get inverted matrix.
# It could be useful in this case since we're going to invert the matrix
# but for clarity I'll do this as separate step.
m = target.channel('wrotMatrix').get()
targetWRotMtx = modo.Matrix4(m)
targetWRotMtxInv = targetWRotMtx.inverted()
m = source.channel('wrotMatrix').get()
sourceWRotMtx = modo.Matrix4(m)
transformedMtx = modo.Matrix4(sourceWRotMtx)
transformedMtx *= targetWRotMtxInv
transformedMtx.invert()
# Be sure to use 'xyz' order as this seems to be the order
# MODO is doing it in constraint offset properties.
euler = transformedMtx.asEuler(degrees=True, order='xyz')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment