Skip to content

Decode the quantised Granny curve encodings that D2R actually uses #2

Description

@Darithos

Blocked on #1 — implement in the frequency order d2rmv curves reports, not all fifteen on spec.

Six of Granny's 21 curve encodings are decoded today (DaIdentity, the three constant forms, DaKeyframes32f, DaK32fC32f). The rest quantise knots and controls into 8- and 16-bit fields. They are recognised and reported, and GrannyCurve.Decode throws GrannyCurveException naming the format rather than guessing.

That refusal is deliberate: a wrong quantisation layout does not raise an error, it produces animation that plays at the wrong speed or twists the wrong way — discovered in the SC2 editor weeks later, not in a stack trace.

Three things to confirm against real data first

Detail in docs/GR2-FORMAT.md.

  1. Knot reconstruction. These formats store OneOverKnotScaleTrunc as a uint16 holding the high half of a float. Whether the reconstructed value multiplies or divides the raw knots decides whether a clip plays at the right speed — and the field's name and its usage disagree across public sources.
  2. D4nK16uC15u bit packing. A "smallest three" quaternion: three 15-bit components plus a selector for the dropped one, packed into 48 bits. Which bits hold the selector, and how the dropped component's sign is recovered, needs reading off real data.
  3. Degree. A degree-2 curve is a quadratic B-spline with more controls than knots; sampling at its knots is not evaluating it. GrannyCurve.Decode currently refuses a DaK32fC32f whose control count is not a whole multiple of its knot count, reporting both numbers. If real files hit that, spline evaluation is the work.

Route

Norbyte/lslib is MIT and has working curve decoders for Divinity and Baldur's Gate GR2s. Adapting the ones the survey names, with attribution in the README alongside the existing credits, is the intended path.

Do not copy from neptuwunium/Knit — it is EUPL-1.2, incompatible with keeping this MIT. Read it for a second opinion only.

Done when

  • Each newly implemented encoding has a fixture in SyntheticGrannyAnimation covering it.
  • GrannyCurve.Implemented is updated so d2rmv curves reports the new coverage.
  • An animated monster exported to .glb plays in Blender at the same speed and direction as in Noesis. That end-to-end check is the one that catches a wrong scale convention; the unit tests cannot.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions