VelocityOrientationProperty with "manual" pitch roll

Hi,

I'm animating a model based on recorded data, using lat/lon, altitude and heading/pitch/roll. The model is animated along a path. This works well, but then I have a case where the heading is faulty and I'm trying to correct it. I'm trying to use heading from VelocityOrientationProperty but with my own pitch and roll.

This is not a bug in Cesium, I just can't figure out the math.

I think I'm confusing my units, since I can't get even get this working:

  let q = orientation_velocity.getValue(time);
  let velocity_hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);
  let orientation = Cesium.Transforms.headingPitchRollQuaternion(
      posSamples.getValue(time),
      velocity_hpr
  );
  orientationSamples.addSample(time, orientation);

If I convert a Quaternion to a HeadingPitchRoll, then convert HPR to a Quaternion (using the same position) shouldn't it work? Obviously it's fictitious example, but if I can't even get that to work.. the above sample gives me the same odd behaviour as TRY #2 below, i.e the forward tip of the model points upwards.

Longer Story:
When I have a working heading (these are executed in a for loop):

  let hpRoll = new Cesium.HeadingPitchRoll(
      Cesium.Math.toRadians(data['HEADING'][i]),
      Cesium.Math.toRadians(data['PITCH'][i]),
      Cesium.Math.toRadians(data['BANK'][i]),
  );
  let orientation = Cesium.Transforms.headingPitchRollQuaternion(
      positions[i], // position
      hpRoll,
      Cesium.Ellipsoid.WGS84,
      Cesium.Transforms.northWestUpToFixedFrame,
  );
  orientationSamples.addSample(time, orientation);

I can also use the VelocityOrientationProperty:

TRY #1:
  orientation_velocity = new Cesium.VelocityOrientationProperty(posSamples);

Gives a perfect heading along the path, but obviously without PITCH/ROLL.

However, now I'm trying to use heading from VelocityOrientationProperty but my own PITCH and BANK.

TRY #2 (TLDR: 90 degrees (forward tip of the model points upwards)
  let q = orientation_velocity.getValue(time);
  let velocity_hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);

  let hpRoll = new Cesium.HeadingPitchRoll(
      Cesium.Math.toRadians(data['HEADING'][i]),
      Cesium.Math.toRadians(data['PITCH'][i]),
      Cesium.Math.toRadians(data['BANK'][i])
  );

  // Replace pitch and roll from VelocityOrientationProperty Quaternion
  hpRoll['pitch'] = velocity_hpr['pitch']
  hpRoll['roll'] = velocity_hpr['roll']

  let orientation = Cesium.Transforms.headingPitchRollQuaternion(
      posSamples.getValue(time),
      hpRoll,
      Cesium.Ellipsoid.WGS84,
      Cesium.Transforms.northWestUpToFixedFrame,
  );

This creates a model where the front of the model points pretty much straight up and not forward.

TRY #3: (TLDR: Doesn't point straight forwards, rotates 180 degrees randomly when turning)
  let q = orientation_velocity.getValue(time);
  let velocity_hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);
  let heading = Cesium.Math.toDegrees(velocity_hpr['heading']);

  let hpRoll = new Cesium.HeadingPitchRoll(
      velocity_hpr['heading'],
      Cesium.Math.toRadians(data['PITCH'][i]),
      Cesium.Math.toRadians(data['BANK'][i])
  );
  let orientation = Cesium.Transforms.headingPitchRollQuaternion(
      positions[i], // position
      hpRoll,
      Cesium.Ellipsoid.WGS84,
  );
  orientationSamples.addSample(time, orientation);

Hi,

I hope I'm not breaking any forum rules here, but I would like to offer a gratitude reward (150USD) if anyone can solve this within 12 hours.

Regards,
Niklas