Comments (4)
I tried running this and it seemed to work
Oh, yes you're right. Brainfart.
I think it's one of those things where there isn't a right solution, just need to pick one and stick to it.
Yes, in that case, let's stay close to the Maya API. The only one I can spot that isn't doing this right now is time.
cmds.currentTime(1)
t = cmdx.encode("time1")
t["outTime"].read() == 1 # Ui Unit
t["outTime"] = 1 # Seconds
t["outTime"].read() == 24
Which I'll fix now since it's low-hanging fruit.
from cmdx.
Eeeek, yes. You are right. They differ, and that's bad. I've attempted a fix in exactly the way you propose, dealing with UI units only since that's both expected (and I think also what you get with cmds
?).
However, there's a subtlety!
Picture having written this code.
node["rx"] = 5
Which cmdx
interprets as degrees because that's what the UI has been set to. Your code depends on a 5 degree angle between node
and otherNode
because maybe you're doing physics simulation or IK solving or what not. Then the user changes UI units to radians.
Suddenly, your code has changed. Your simulation and IK has changed. IK would flip, as it's past 180 degrees and physics would encounter a massive change in angle over that one frame or whatever.
So, I think what we want is for both reading and writing of plugs to happen in a consistent unit. Which unit? The API, both Python and Maya, uses radians for angles hence cmdx
does too. It's helpful for when you pass values between API and cmdx. For distances, it's centimeters, which conveniently happens to be the default UI unit as well.
At least that's my rationale. It's not immediately obvious, which I agree is bad. And it's bit me a few times. But I haven't figured out an alternative, how to better balance the principle-of-least-astonishment for both first-use and long-term reliability.
The "solution" at the moment is..
node["rx"] = cmdx.radians(5)
Although if there's one thing we could fix it would be writing to plugs with that same unit qualifier which is something I would like to see.
node["rx", cmdx.Degrees] = 5
Under the Units section of the README it mentions that cmdx takes and returns values in units used by the UI
That's a bummer, it must have been written during my initial implementation of this mechanism, before I realised why it cannot be. That should also be updated.
Thanks for highlighting this, haven't really spoken it out loud before but it still bothers me on a weekly basis so if you think of a cure, this would be a good time to get it in.
from cmdx.
I feel like both UI units and internal units have their merits.
cmds
does use UI units so people used to that may be confused initially. Whereas the issue about the user changing the UI units and getting wildly different results is alarming (though I've never experienced it myself using cmds
)
I think it's one of those things where there isn't a right solution, just need to pick one and stick to it. Using Maya's internal units would probably require less code so would hopefully be easier to maintain (plus it already works this way). It's really up to you, I'm happy with either way :).
Also, I tried running this and it seemed to work as expected so I'm not sure if I'm missing something?
node["rx", cmdx.Degrees] = 5
Plug.write()
doesn't accept a unit though.
from cmdx.
As mentioned in #23 I discovered that Maya uses UI units for setting and getting MTime
in MFnAnimCurve
. I'm not sure if it changes how I feel about this issue but I thought it worth mentioning.
I'm wondering if there's any other areas where Maya is inconsistent with units.
from cmdx.
Related Issues (20)
- cmdx.listRelatives always returns None HOT 18
- 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
- Set a nodes transform HOT 7
- 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.