[bvhExporter]How to calculate bvh axis angels in three.js?

I am currently writing bvh exporter for threejs, passing Skeleton and AnimationClip and it should returns a bvh string.
I am now getting stucks at parsing keyframe datas to bvh’s motion session.
From what I have gathered, the motion session consist of position of root, rotations offset from initial rotations( in euler angles) for each bones in every frame representing lines in order.

Two questions I have are:
is it make sense for me to able to get the angle results from:

  1. extracting a offset rotation quaternion from keyframetracks in a frame
  2. convert initial rotation of a bone, invert it and multipy it with the offset quaternion.

If above is correct, how exactly will the syntax in three.js will be?

I am new to three.js and 3d computation, any feedbacks are much appreciated.

The repository:

Red part is the part to be solve.