I'm currently working on a plugin to establish a neat connection between C4D and Houdini. ( https://twitter.com/lasse_lauch/status/1319296533016182787?s=20 )
However, one thing that always drives me insane when transferring data between different apps is the matrix-rotation-euler-quaternion-endless-rabbit-hole when animation comes into play.
Currently I'm using these functions from the documentation as a base...
return c4d.utils.MatrixToHPB(obj.GetMg(), #order=c4d.ROTATIONORDER_XYZGLOBAL !? )
m = obj.GetMg()
return c4d.Vector( m.v1.GetLength(),
... and write the components into a dict like:
myDict[frame]['tx'] = pos.x
myDict[frame]['ty'] = pos.y
myDict[frame]['tz'] = pos.z
myDict[frame]['sx'] = scale.x
myDict[frame]['sy'] = scale.y
myDict[frame]['sz'] = scale.z
# getter in cinema4D (rotation in radians)
myDict[frame]['rx'] = rot.x
myDict[frame]['ry'] = rot.y
myDict[frame]['rz'] = rot.z
# setter in houdini (radians to degrees):
But I'm sure I somehow need to deconstruct the matrix and reconstruct in houdini.
(BTW - For my AEC4DPRO plugin we've found a solution after working closely with @r_gigante in using the c4d.utils.GetOptimalAngle(hpb_old, hpb_new, rotation_order function as described -> here...
c4d.utils.GetOptimalAngle(hpb_old, hpb_new, rotation_order
Is this the way to go in general, or are there some other pointers to break this down to it's bare bones... I'm looking at you: @zipit … HELP!
When it comes to Matrices and Rotations my brain sloooowly starts to melt……
(…and yes, I've watched the 3Blue1Brown videos on quaternions... )
Would love to provide further code details if needed.
I am not sure if I am able to be of great help, because I do not know much about Houdini (cool project btw ;)).
Hi @lasselauch , nice to see you again around.
About your question on transferring object transformation to Houdini, given that I've no clue on the communication mechanism you've setup, I agree with @zipit that you should use transformation matrixes to transfer data from C4D to Houdini and pay attention to coordinate system handedness matching.
A right handed coordinate system can be converted to a left handed coordination system (or vice-versa) by:
just wanted to let you know, that I've cracked the case in the meantime.
Here are my findings:
# m = op.GetMg()
new_m = c4d.Matrix( m.off,
# Construct your own matrix based on rotation of axis
x = c4d.Vector(-1, 0, 0)
y = c4d.Vector(0, 1, 0)
z = c4d.Vector(0, 0, -1)
off = c4d.Vector(0, 0, 0)
return c4d.Matrix(off, x, y, z)
m = obj.GetMg()
new_m = rotate_y_axis_180() * convert_matrix_left_to_right(m)
return c4d.utils.MatrixToHPB(new_m, order=c4d.ROTATIONORDER_XYZGLOBAL)
Indeed you have to convert from a left-handed (c4d) (hpb) to a right-handed (houdini) (xyz) coordinate system... plus I've found that you need to add 180° to the y axis, so I constructed a matrix in rotate_y_axis_180 that I can multiply to my converted matrix.
Hope it helps someone...
Thank you guys for your input! Have a great weekend and stay safe!