PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.13k stars 1.22k forks source link

Euler filter for XformCommonAPI #410

Open AlexSchwank opened 6 years ago

AlexSchwank commented 6 years ago

Description of Issue

When using more advanced xform ops, getting rotation values via the XformCommonAPI can lead to Euler flips.

eulerTest.usda zip

//...
float3 xformOp:rotateXYZ.timeSamples = {
    0: (0, 80, 0),
    1: (0, 90, 0),
    2: (0, 100, 0),
}
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:translate:rotatePivotOffset", "xformOp:translate:rotatePivot", "xformOp:rotateXYZ:rotateOffset", "xformOp:rotateXYZ", "!invert!xformOp:translate:rotatePivot", "xformOp:translate:scalePivotOffset", "xformOp:translate:scalePivot", "xformOp:transform:shear", "xformOp:scale:scaleOffset", "xformOp:scale", "!invert!xformOp:translate:scalePivot"]
//...

XformCommonAPI::GetXformVectors() result

0: (0, 80, 0)
1: (0, 90, -0)
2: (180, 80, 180)

For now, we can fix the rotation for example with Mayas MEulerRotation::setToClosestSolution() but Usd itself should include a

feature for Euler filters.

Thanks, Alex

Steps to Reproduce

>>> from pxr import Usd, UsdGeom
>>> stage = Usd.Stage.Open("/path/to/eulerTest.usda")
>>> prim = stage.GetPrimAtPath("/myXform")
>>> xformAPI = UsdGeom.XformCommonAPI(prim)
>>> xformAPI.GetXformVectors(0)
(Gf.Vec3d(0.0, 0.0, 0.0), Gf.Vec3f(0.0, 80.0, 0.0), Gf.Vec3f(1.0, 1.0, 1.0), Gf.Vec3f(0.0, 0.0, 0.0), UsdGeom.XformCommonAPI.RotationOrderXYZ)
>>> xformAPI.GetXformVectors(1)
(Gf.Vec3d(0.0, 1.0, 0.0), Gf.Vec3f(0.0, 90.0, -0.0), Gf.Vec3f(1.0, 1.100000023841858, 1.0), Gf.Vec3f(0.0, 0.0, 0.0), UsdGeom.XformCommonAPI.RotationOrderXYZ)
>>> xformAPI.GetXformVectors(2)
(Gf.Vec3d(0.0, 2.0, 0.0), Gf.Vec3f(180.0, 80.0, 180.0), Gf.Vec3f(1.0, 1.2000000476837158, 1.0), Gf.Vec3f(0.0, 0.0, 0.0), UsdGeom.XformCommonAPI.RotationOrderXYZ)

Package Versions

Tested in 0.8.2 & 0.8.3

jtran56 commented 6 years ago

Filed as internal issue #157012.

chadrik commented 6 years ago

Hi @AlexSchwank, @elrond79 made a PR that adds euler filtering to Maya exports but I think it could be very interesting to see this at a higher level in USD.

AlexSchwank commented 6 years ago

Thanks @chadrik , I'm not too concerned about exports at the moment. Importing is a bigger issue for us so I'll fix it in a similar way for now. That said, you're right, this issue is meant to track/discuss general solutions to fix Euler flips at a higher level in USD.

pmolodo commented 6 years ago

So, it looks like the problem here is that the input rotation doesn't conform the "common xform" stack - the xform stack you give is maya's:

["xformOp:translate", "xformOp:translate:rotatePivotOffset", "xformOp:translate:rotatePivot", "xformOp:rotateXYZ:rotateOffset", "xformOp:rotateXYZ", "!invert!xformOp:translate:rotatePivot", "xformOp:translate:scalePivotOffset", "xformOp:translate:scalePivot", "xformOp:transform:shear", "xformOp:scale:scaleOffset", "xformOp:scale", "!invert!xformOp:translate:scalePivot"]

...while the (fairly simple) common xform only supports stacks with these elements:

["xformOp:translate", "xformOp:translate:pivot", "xformOp:rotateXYZ", "xformOp:scale", "!invert!xformOp:translate:pivot"]

(or other appropriate 1 or 3-axis rotate in place of rotateXYZ).

So the reason why the flip happens in your code snippet is that, since it's not compatible with it's xform stack, it converts to matrix, then decomposes the matrix.

pmolodo commented 6 years ago

Having said that... noticed you link to a PR that's dealing specifically with maya imports... maya should be able to understand it's own xform stack, and import your test correctly. So something wrong is definitely going on there...

pmolodo commented 6 years ago

Well, left full details in a comment for the PR, but figured out what was going on... the input xform stack is not actually a maya stack, as I first assumed it was. I still agree that there's a need for a euler filtering option, though, specifically to deal with situations where xform stacks can't be directly translated...