Rotation Problems


I'm writing my first importer and exporter in maxscript. But I'm reading and writing a file format for a program called MikuMikuDance..

I have to deal with translating data between MAX and MMD so that they're interchangeable. so far import and export of the geometry, and skeleton, including uvs, vertweights, materials, morph targets, ik chains, rigidbodies, and physics controllers are somewhat working.. but working.

the main problem I'm having now is with the animations, which include rotations...
the MMD model format on its own, doesn't contain any bone rotations.. all bones are given a rotation axis of the grid upon import to MMD.
Then the animations are then created off of those bone axises and stored to a separate animation file

So the difference here is that in MAX, my bones are constructed, and given direction based on the following child bone.. thus giving it a local pivot rotation..
But in MMD!, the pivot for rotation is along the Axis of the grid, then set like that.

In MAX, I tried importing the animation rotations using local,World, and Grid Pivots, but this is totally different. as in MMD, the bones actually assume an axis pivot of the grid on import, then set as the permanent pivot in MMD. as in MAX, the closet I can get is using world, which is the same as view.. so as soon as a chain of bones is rotated, their pivot changes with the grid.

I just wondered if you guy's have any ideas, on how I could properly import rotations? I was thinking I could somehow reset the axis of all my bones in max, to follow the Axis of the grid.. then import my animations using the new local bone pivot. I'm just not sure how to go about it.

another idea I had, was to gather the transform matrix of all my bones in max, then get the rotation transform difference between each bone and the grid. then when I import the bones, I just add that difference.

still, I've never dealt with this before, and guidance, is appreciated.