VQQV and scale orientation in OpenUSD

The VQM transform keeps the scale/shear part as a full 3x3 matrix. Other formats choose a different encoding. In OpenUSD, a GfTransform holds a scale vector and a second rotation, the scale orientation, that tells along which axes the scale applies. A vector and a quaternion can hold the scale/shear part that a VQV discards. In this series, I call this type VQQV. But this encoding has a cost: its parts do not multiply or interpolate piece by piece, and each product must go through a matrix and a decomposition.

This post is part of the Representing Affine Transforms series.

The transform of GfTransform

The documentation of GfTransform gives its parts: a scale (GfVec3d), a pivot orientation (GfRotation), a rotation (GfRotation), a pivot position (GfVec3d), and a translation (GfVec3d). USD uses row vectors, as RTM does. Without the pivot position, the transform of a point is:

p' = p * O^-1 * S * O * R + v

O is the rotation of the pivot orientation, S = diag(sx, sy, sz) is the scale, R is the rotation, and v is the translation. The first three terms rotate the point into the frame of the pivot orientation, apply the scale along those axes, and rotate back. This is the same idea as the scaleOrientation field of the transform node in VRML and Open Inventor. The GetMatrix function of GfTransform applies the operations in this order: the inverse pivot position, O^-1, S, O, R, the pivot position, and the translation.

The scale/shear part is thus K = O^-1 * S * O = O^T * S * O. This is a symmetric matrix. It has 6 degrees of freedom: 3 for the scale, and 3 for the orientation. The encoding uses 7 values for it: a vector and a quaternion.

Why a symmetric matrix is enough

A general 3x3 matrix has 9 degrees of freedom. K has 6, and R has 3. Is K * R enough for each affine transform? Yes. The polar decomposition says that each invertible 3x3 matrix A is a product of a symmetric matrix and an orthogonal matrix (Ken Shoemake and Tom Duff, Matrix Animation and Polar Decomposition, 1992):

A = K * U

When the determinant of A is positive, K is positive definite and unique, and U is a rotation. When it is negative, a negative scale holds the reflection. Thus [v, q, O, S] can hold any affine transform with an inverse, shear included. On this point, it is as complete as a VQM or an affine matrix, and better than a VQV.

Where is the shear? It is not in one value. A shear is a scale along axes that are not the axes of the rotation. For example, the matrix from the VQM post:

| 1.5  0.5  0 |
| 0.5  1.5  0 |
| 0    0    1 |

is symmetric, thus it is a K with no rotation: a scale of [2, 1, 1] along the axes that a rotation of 45 degrees about Z gives.

The name VQQV

RTM names its types from right to left, in the order of the operations: VQS applies the scale (S), then the rotation (Q), then the translation (V). In this series, I call this type VQQV: the scale (V), the scale orientation (Q), the rotation (Q), and the translation (V). The scale and the scale orientation make one part, the scale/shear K. Thus the type reads as a VQV with one more quaternion, next to the scale that it controls.

The name is not exact. The order of the operations is O^-1, S, O, R, v: the quaternion O applies twice, once before the scale and once after it. VQQV keeps the last four operations.

A full VQQV holds 14 floats: two quaternions and two 3D vectors. In SIMD registers, it takes four registers (16 floats, 64 bytes), the same size as a VQM. Thus a VQQV saves only 2 floats in raw storage, and no SIMD registers, compared to a VQM.

The product needs a decomposition

Let T1 = [v1, q1, O1, S1] be a child and T2 = [v2, q2, O2, S2] its parent. As with the VQM, we expand the two steps:

p'' = (p * K1 * R1 + v1) * K2 * R2 + v2
p'' = p * K1 * R1 * K2 * R2 + v1 * K2 * R2 + v2

As in the VQM post, we can move R1 to the right:

K1 * R1 * K2 * R2 = K1 * (R1 * K2 * R1^T) * R1 * R2

The VQM stops here: M3 = K1 * (R1 * K2 * R1^T) is a valid scale/shear matrix. A VQQV cannot stop here, because K1 * (R1 * K2 * R1^T) is the product of two symmetric matrices, and that product is not symmetric. Thus it is not a valid K. To find K3, we must:

  1. Compute the matrix A = K1 * R1 * K2 * R2. We want A = K3 * R3.
  2. Compute the eigen decomposition of the symmetric matrix A * A^T. It is equal to K3 * R3 * R3^T * K3 = K3 * K3, thus its eigenvalues are the squares of the scale values S3, and its eigenvectors give O3.
  3. Compute the rotation: R3 = K3^-1 * A. This is the polar decomposition of A.
  4. Convert O3 and R3 to quaternions.

Step 2 needs an iterative algorithm, for example a Jacobi iteration. Each product of two transforms is a round trip through a matrix, with an iterative decomposition, and the result is only as precise as the iteration. In a hierarchy of 100 joints, that cost applies 100 times.

GfTransform multiplies this way. Its operator*= calls SetMatrix(GetMatrix() * xf.GetMatrix()), and SetMatrix calls GfMatrix4d::Factor. Factor comes from Open Inventor, and it follows the steps above with a Jacobi iteration of at most 50 sweeps. GfTransform does this for each product, even when the product needs no decomposition, for example when neither transform has a scale. SetMatrix keeps a shear: it goes into the scale and the pivot orientation. Only when the scale is exactly [1, 1, 1] does it set the pivot orientation to the identity.

In practice, a system does not multiply transforms this way. USD does not either. UsdGeomXformable computes the local transform of a prim as the product of the matrices of its xform ops. UsdGeomXformCache multiplies these matrices up the hierarchy, and a USD skeleton multiplies the matrices of its joints. A system converts each transform to a matrix, multiplies the matrices, and decomposes only when it needs the parts again. The parts are then only a storage format.

The inverse

Unlike the product, the inverse of a VQQV needs no decomposition. We solve p' = p * K * R + v for p:

p = (p' - v) * R^T * K^-1

We move R^T to the right, as in the VQM post:

R^T * K^-1 = (R^T * K^-1 * R) * R^T

The inverse of K = O^T * S * O is K^-1 = O^T * S^-1 * O. Thus the new scale/shear part is:

K' = R^T * O^T * S^-1 * O * R = (O * R)^T * S^-1 * (O * R)

K' is symmetric, and it is already in the VQQV form. Its parts come directly from the input:

S' = S^-1
O' = O * R
R' = R^T
v' = -v * R^T * O^T * S^-1 * O

This works whenever no scale component is zero, negative scales included. The same algebra applies to a product when one transform has a uniform scale. If the child has a uniform scale s1, then K3 = (O2 * R1^T)^T * (s1 * S2) * (O2 * R1^T). Only a product where both transforms have a non-uniform scale forces a decomposition.

GfTransform in OpenUSD does not provide an inverse function. To invert one, a caller must call GetMatrix and then GetInverse on the matrix. If it needs a GfTransform again, SetMatrix runs Factor on the result.

Surface normals also avoid a 3x3 matrix inverse. Because K = O^T * S * O is symmetric, (A^-1)^T = K^-1 * R = O^T * S^-1 * O * R. We apply O^T, divide by S, apply O and R, and then normalize the result.

The decomposition is not unique

The eigen decomposition of K is not unique:

  • The order of the scale values is free. A scale of [1, 2, 1] with no orientation and a scale of [2, 1, 1] with an orientation of 90 degrees about Z give the same K.
  • The sign of each axis of O is free, and a quaternion and its negation give the same rotation.
  • When two scale values are equal, the orientation about the third axis is free. A uniform scale has an orientation that can take any value. This is the common case: most objects have a uniform scale, or no scale.

In the last case, the orientation has no value that a decomposition can find. A small change in the scale, for example from [1, 1, 1] to [1.001, 1, 1], can change the orientation by a large angle.

On the left, K = [1 + a, 0.001; 0.001, 1 - a] transforms the unit circle as a sweeps from +0.02 to -0.02. The purple ellipse stays close to the dashed green unit circle, but its eigen orientation O turns by 87 degrees. On the right, the curve of O climbs steeply near a = 0: a change of 0.004 (from +0.002 to -0.002) swings O by 63.4 degrees. With b = 0 (dashed grey), O jumps by 90 degrees at a = 0.

The Jacobi iteration of USD makes these choices in a specific way. It does not sort the scale values. It starts from the X, Y, and Z axes, and each of its rotations is 45 degrees or less. Thus a K that is aligned with the axes comes back with no orientation, and its scale values stay in the order of the axes.

Interpolation

When the parts come from an artist, they are consistent from one key to the next, and each part interpolates on its own: the two quaternions with a slerp, the scale and the translation with a linear or an exponential interpolation. This is the usual case in the local space of a joint.

When the parts come from a decomposition, each key decomposes separately. This is always the case in object space, because each transform there is the product of a chain of transforms. It is also the case in local space when the source is a matrix, for example after a bake or an import. The decomposition can choose a different order of the scale values, or a different orientation, for each key. Then the interpolation of the parts gives a wrong result, even when the two keys are the same transform:

  • Key A: a scale of [1, 2, 1] with no orientation.
  • Key B: a scale of [2, 1, 1] with an orientation of 90 degrees about Z.

The two keys give the same K = diag(1, 2, 1). Halfway, the scale is [1.5, 1.5, 1] and the orientation is 45 degrees. Because the scale is the same on X and Y, the orientation has no effect, and the result is K = diag(1.5, 1.5, 1). Sadly, two identical keys give a different transform between them.

The same problem also appears over time, and there it causes a jump. The matrix of an input can change smoothly while its decomposed parts jump, because the decomposition must make two choices:

  • The order of the scale values. When the choice of the axis for each scale value changes, two scale values change places, and the orientation turns by 90 degrees. A decomposition that sorts the scale values changes this choice when two values cross. When the axes of the scale turn about one coordinate axis, the Jacobi iteration of USD changes this choice at 45 degrees. For other orientations, the choice depends on the order of the Jacobi rotations, and it follows no simple rule.
  • The sign of each axis of O. The decomposition can change the sign of two axes. This is a rotation of 180 degrees, and K does not change.

For one input alone, K stays continuous, because each jump happens where the two choices give the same K. But an interpolation or a blend with a second input pairs the scale values by index, and then the result jumps.

Can a smooth input really give a jump? Yes. Pose A has K(t) = diag(2 - t, 2 + t, 1), and pose B has a scale of [3, 1, 1] with no orientation. We blend the two poses with a weight of 0.5, and we use a decomposition that sorts the scale values and puts the largest first:

Time Scale of A Orientation of A Blended scale Blended orientation Blended K (X and Y)
t = -0.001 [2.001, 1.999, 1] 0 degrees [2.5005, 1.4995, 1] 0 degrees [2.5005, 0; 0, 1.4995]
t = +0.001 [2.001, 1.999, 1] 90 degrees about Z [2.5005, 1.4995, 1] 45 degrees about Z [2, 0.5005; 0.5005, 2]

Between the two times, the matrix of A changes by only 0.002, but the blended K changes by 0.5. On a character, this is a pop in one frame. Keys have the same problem: if a jump falls between two keys that come from a decomposition, the interpolation goes through wrong transforms for the full interval.

With the Jacobi iteration of USD, a simple hierarchy shows this. A parent has a scale of [2, 1, 1], and its child has no scale and turns about Z. The world transform of the child is a product, and SetMatrix decomposes it:

Rotation of the child Scale Orientation
44 degrees [2, 1, 1] -44 degrees about Z
46 degrees [1, 2, 1] 44 degrees about Z

Halfway between these two frames, the interpolation gives a scale of [1.5, 1.5, 1] and an orientation of 0 degrees, thus K = diag(1.5, 1.5, 1). The correct K at 45 degrees is a scale of 2 along a diagonal: [1.5, -0.5; -0.5, 1.5] for X and Y. The child does not need a decomposition: its world scale/shear is R1 * K2 * R1^T, which is symmetric. But GfTransform decomposes each product.

The keys are the child at 44 and 46 degrees under a parent with a scale of [2, 1]. The dashed green outline is the true transform, and the dotted grey lines show the scale orientation axes. On the left, the decomposed VQQV keys swap the scale components and spin O by 88 degrees; halfway, the square loses its shear and misses the axes by 0.500. On the right, VQM stays on top of the true transform.

Thus we cannot interpolate or blend the bones of a character in object space with this encoding. A VQM does not have these problems: its M is the matrix itself. A smooth input gives a smooth M, and the linear interpolation of two identical matrices gives the same matrix.

We can still use the rotation-only approach from the VQV post: put only q in object space, and blend v, S, and O in local space. That avoids any decomposition and keeps the rotation round trip exact. However, it keeps the same limits as VQV under parent scale, shear, or mirrors. It also requires the local S and O parts of the two clips to agree on axis order and orientation.

Near a singular matrix

The rotation R3 from a decomposition also has problems when the matrix is close to singular. Factor gives the sign of the determinant to all three scale values. When a scale value passes through 0, for example in an animation that mirrors an object, the determinant changes sign. With A = diag(x, 1, 1) * Rz(30):

x Scale Rotation
0.01 [0.01, 1, 1] 30 degrees about Z
-0.01 [-0.01, -1, -1] 180 degrees about an axis in the XY plane

Each value of the matrix changes by 0.02 or less, but the rotation jumps by 180 degrees, and the three scale values change sign. Halfway between two keys at x = 0.1 and x = -0.1, the interpolation of the parts gives a scale of [0, 0, 0]: the object becomes a point. The correct result is flat: diag(0, 1, 1) * Rz(30).

The keys are A = diag(x, 1, 1) * Rz(30) at x = +0.1 and x = -0.1, shown in the XY plane. The dashed green line is the true transform. On the left, the decomposed VQQV keys negate all three scale values and turn q by 180 degrees; halfway, the scale hits [0, 0, 0] and the object shrinks to a point at the origin. On the right, VQM keeps the Y scale at 1 and flattens the object cleanly onto the line.

Factor also clamps small scale values. It compares the eigenvalues of A * A^T with eps = 1e-10, and these eigenvalues are the squares of the scale values. Thus it replaces each scale value below 1e-5 with 1e-10. Then the matrix U is not a rotation, and SetMatrix followed by GetMatrix does not give the input back:

x Stored scale Rotation Largest error after the round trip
1e-5 1e-5 30 degrees 6e-17
5e-6 1e-10 0 degrees 0.5
0 1e-10 64.3 degrees 0.43

For x = 5e-6, the determinant is above eps, thus Factor reports success. SetMatrix does not check the result in any case. A scale of 0 is common, for example to hide an object. Then the rotation of the GfTransform is 64.3 degrees instead of 30.

Two scale values near 0 make the rotation unstable in any implementation. The polar decomposition has no stable rotation for a matrix that is close to a line. When two scale values are 1e-4, a change of 0.001 in A turns the rotation by 77 degrees. When only one scale value is near 0, and above the clamp, the same change turns the rotation by only 0.08 degrees.

Other runtime cases

The product cost and the interpolation jumps above affect many common game and animation systems. This list is not exhaustive, but it shows where composed transforms must interpolate or stay consistent:

  • Inertialization. A velocity-based transition computes an offset between two poses (source * inverse(target)) and its rate of change across consecutive frames. It then decays that offset to the identity. A jump or a fast turn of O near a uniform scale creates a large false angular velocity, which causes a visible overshoot.
  • Additive animations. An additive delta (inverse(ref) * pose) is a product. When the two poses have a non-uniform scale, that product needs a decomposition. A partial weight then interpolates that decomposed VQQV from the identity.
  • Parent and space switches. To move an attached object from Parent A to Parent B, a system computes child * A_world * inverse(B_world). A smooth transition across the switch blends an authored VQQV with a decomposed one.
  • Associativity of cached sub-chains. Because an eigen decomposition is iterative and not unique, (T1 * T2) * T3 and T1 * (T2 * T3) agree on the matrix only within solver tolerance. Their parts (O, S, and q) can disagree completely, thus a system cannot cache partial products and assume the same parts.
  • Fixed-timestep physics to variable-rate render. A physics engine steps at a fixed rate and outputs transforms in world space. The renderer interpolates between the last two world-space poses by the leftover frame fraction. With a scaled parent, that interpolates decomposed transforms.
  • Blends with physics. A ragdoll returns joint poses from the physics engine in world space. Hit reactions and get-up transitions blend those world-space poses back into an animated pose, which mixes composed transforms directly.

USD skeletons use VQV

The joint animation of USD does not use the scale orientation. A UsdSkelAnimation stores, for each joint, a translation (float3), a rotation (quatf), and a scale (half3), in the local space of the joint: a VQV. Its SetTransforms function requires orthogonal transforms. Thus a USD skeleton can hold no shear in its local transforms, and a tool that exports a pose with shear from another format must discard it. The UsdSkelDecomposeTransform function of USD does this: it calls Factor, keeps the scale and the rotation, and discards the scale orientation.

UsdSkelSkeletonQuery computes the skeleton space transforms with UsdSkelConcatJointTransforms, which multiplies matrices. Thus the skeleton space transforms keep the shear that a rotation between two non-uniform scales creates. Only the local animation cannot hold an authored shear.

Conclusion

A scale and a scale orientation can hold any scale/shear in 7 values, and a VQQV can hold any affine transform with an inverse. But the parts do not multiply piece by piece: each product needs a round trip through a matrix and an eigen decomposition. The decomposition is not unique, thus the parts from a decomposition do not interpolate. This includes each object space pose. The format works well when artists author a scale along custom axes, because those parts are easier to edit than a raw 3x3 matrix. Outside that case, VQQV gives no advantage over VQM: it saves only 2 floats (no SIMD registers), and decomposed keys can jump. For baked storage and runtime hierarchies, I recommend a VQM instead.

References