Comments (7)
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 cmdx.DagModifier()
instead of setting things directly. There might be a function in the API, e.g. MFnTransform
that can handle this I think? If you're up for it, it would be good to expose that to cmdx.
from cmdx.
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.
Once I get things in working order I will submit a PR.
from cmdx.
Hey @mottosso - I have the basic logic in place, but I am struggling with getting undo to be recorded.
Was your suggestion to expose MFnTransform
to the DagModifier
, effectively setting a nodes transform in a similar way to the createNode
and parent
methods?
from cmdx.
Yes, I think that's what has to happen. Setting the transform of a kTransform
node implies setting a whole bunch of things at once..
- Translate
- Rotation
- Scale
- Shear
- Scale pivot
- Scale pivot translation
- Rotate pivot
- Rotate pivot translation
- Rotation orientation
- Reference
And if the input is a MMatrix
as in your initial example, rather than a MTransformationMatrix
that actually carries all of this information, then we'll also have to assume the user means to zero out everything but translate, rotate, scale and shear since a MMatrix doesn't carry anymore than that.
And, if the node isn't a kTransform
but a e.g. kJoint
then we'll also have to zero out the jointOrient
as neither the MMatrix
nor MTransformationMatrix
carries that.
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 setAttr
.
from cmdx.
ah I see - I had completely overlooked setAttr for some reason - that works perfectly in my prototype function
Would it make sense to create JointNode as a child class of DagNode, with access to joint specific attributes and methods such as jointOrient or do class specific checks on DagNode methods?
from cmdx.
Would it make sense to create JointNode
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 JointNode
implementation.
from cmdx.
Although that said, you can node.isA(cmdx.kJoint)
to find the type (along with node.type() == "joint"
) and node["jointOrient"]
to get the attribute. So there's not much benefit having a dedicated class for it.
from cmdx.
Related Issues (20)
- cmdx.listRelatives always returns None HOT 18
- Plugs not taking and returning UI units HOT 4
- DagNode.addChild crashes in certain circumstances HOT 6
- Modifiers and data types HOT 2
- design proposition for components HOT 10
- attributes' default value not saved in scene HOT 3
- Support for proxy attributes
- DGModifier.disconnect and Undo
- Attribute reuse and undo
- Multiple versions simultaneously
- How to debug Maya crashes? HOT 9
- Deploy on CI HOT 1
- Direct passing of cmdx.Node to vanilla cmds HOT 3
- Support keyframing of pairBlended attributes
- MObjectHandle hashCode... HOT 3
- Two users, one machine
- Thoughts on code formatter such as Black? HOT 5
- Auto offset group
- Add type annotations HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmdx.