Vixen
02b45cc4
csharp
public readonly record struct PackedQuaternion

A unit quaternion in eight bytes instead of sixteen, by not storing the component that can be worked out.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Smallest three. A unit quaternion satisfies x² + y² + z² + w² = 1, so any one component is recoverable from the other three up to a sign — and q and −q are the same rotation, so the sign can be chosen rather than stored. Drop the largest component (the one whose recovery is least sensitive to error), negate the quaternion if it was negative, and the three that remain are bounded by 1/√2 because the dropped one was the largest.

Twenty bits each over [−1/√2, 1/√2], plus two bits naming the dropped component: sixty-two bits, in a UInt64. The quantisation step is 1.35 × 10⁻⁶, which is an angular error under 3 × 10⁻⁶ radians — five orders of magnitude below anything a blend of two poses in float will preserve, and four below what a person could see at the end of a two-metre limb.

Why the runtime clip and not the asset. AnimationClipData is the contract a content build writes and the object database stores; changing its storage is a re-import of every animation ever built. A runtime clip is baked at load from that data, so its storage is nobody's contract — which makes it the one place a representation change costs nothing but the code that does it.

Fields and properties (2)

  • public ulong Bits
  • public static PackedQuaternion Identity

    The identity rotation, packed.

Methods (4)

  • public PackedQuaternion(ulong Bits)

    A unit quaternion in eight bytes instead of sixteen, by not storing the component that can be worked out.

  • public static PackedQuaternion Pack(Quaternion value)

    Packs a rotation.

  • public Quaternion Unpack()

    Unpacks a rotation.

  • public static PackedQuaternion[] Pack(ReadOnlySpan<Quaternion> values)

    Packs a whole track.

Used by (2)

  • AnimationClipVixen.Animation
  • CompressionTestsVixen.Animation.Tests