It appears that it looks for a quick change in velocity in the y angle when it gets near 0. Notice the sharp change in direction on the green line in figure A. If it detects that sharp change then it makes all of the following y values negative then adjusts the x and z to make the orientation the same with the new y angle.

Without diving into more detail about Euler angles, what do you need this for? Odds are you can have a much cleaner and easier to manage solution using Quaternions.

Thanks, I would prefer to use quaternions, but my problem is importing it into a 3D modelling app that doesn't use them.

They want Euler angles probably because they're easier for humans to read on a graph.

I can convert quaternions to Euler angles, but a new problem arises. Conversion limits all values -180 to 180 degrees.

This causes rotation to become more susceptible to flipping. But, we can fix this by unrolling the curve to make it more continuous.

If it detects that sharp change then it makes all of the following y values negative then adjusts the x and z to make the orientation

the same with the new y angle.

That's what I don't fully understand. Exactly, how does a change in y affect x and z?

If you have known Euler angles (x,y,z), and change y, how to re-compute x and z, but still keep the same orientation?

I don't think they're just adding 360 degrees to all of them?