-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set a nodes transform #67
Comments
Hm, yes you will need to set translate/rotate/scale explicitly, as well as account for any parent. Try this. def align_transforms_x(node1, node2):
node1 = cmdx.encode(node1)
node2 = cmdx.encode(node2)
try:
parent = node1.parent()
parent_inverse_matrix = parent["worldInverseMatrix"][0].as_matrix()
except AttributeError:
parent_inverse_matrix = cmdx.Matrix4()
matrix2 = node2["worldMatrix"][0].as_matrix()
matrix2 = matrix2 * parent_inverse_matrix
tm = cmdx.TransformationMatrix(matrix2)
node1["translate"] = tm.translation()
node1["rotate"] = tm.rotation()
node1["scale"] = tm.scale() Then if your source and target nodes have pivots and custom axes you'll need to take those into account as well, and for undo you should use |
ah thanks for the super detailed reply - my initial intention was to get/set it in world space, but parent space will likely be useful at some point too. |
Hey @mottosso - I have the basic logic in place, but I am struggling with getting undo to be recorded. |
Yes, I think that's what has to happen. Setting the transform of a
And if the input is a And, if the node isn't a With that that in mind, manual use might look something like.. tm = cmdx.TransformationMatrix()
with cmdx.DagModifier() as mod:
mod.setAttr(node["translate"], tm.translation())
mod.setAttr(node["rotatePivot"], tm.rotatePivot())
mod.setAttr(node["rotatePivotTranslate"], tm.rotatePivotTranslate())
# etc... Whereas some kind of wrapper function would do those things under the hoodl. mod.setTransform(node, tm)
# Or..
node.setTransform(tm) Undo would then be handled as any other call to |
ah I see - I had completely overlooked setAttr for some reason - that works perfectly in my prototype function |
Yes, except not inheriting from DagNode as joints don't have things like rotatePivot. It would need to inherit from Node. Would welcome a PR with a |
Although that said, you can |
Hey!
I am trying to align the transform of one node to another, but have got to a point where I can't see a way forward.
Here is my function:
Is there something I am missing?
The text was updated successfully, but these errors were encountered: