Jbullet to 3ds max

Hi there.
I am trying to export animation from jBullet to 3ds max.
But the final animation in 3ds max is ending a bit joggy.

This is what I am doing inside jbullet:


//Paint the window and render the objects
public void clientMoveAndDisplay() {
        gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        float ms = getDeltaTimeMicroseconds();

        if(dynamicsWorld != null && !idle) {
            dynamicsWorld.stepSimulation(1 / 30);
            
        }

        renderme();
    }


Now grab the objects flagged to export animation and get their world transform.
Is this right??


    //in the main render flow

      for(int i = 0; i < numObjects; i++) {
            final CollisionObject colObj = dynamicsWorld.getCollisionObjectArray().get(i);
            final RigidBody body = RigidBody.upcast(colObj);

            if(body != null && body.getMotionState() != null) {
                final DefaultMotionState myMotionState = (DefaultMotionState) body.getMotionState();
                debugTransform.set(myMotionState.graphicsWorldTrans);
                if(body.getRecordAnimation()) {
                    Transform t3d = new Transform();
                    myMotionState.getWorldTransform(t3d);
                    AnimationCache.record(body, t3d);
                }
           }
     }
        


//This class save the animation's frameNumber and the current transformation
//AnimationCache class
public static void record(final CollisionObject collisionObject, final Transform worldTransform) {
        objects.get(collisionObject).add(new FrameInfo(frameCounter, worldTransform));
}

Then save the animation to a file on this format
pos.x pos.y pos.z quat.x quat.y quat.z quat.w


public static void saveAnimation() throws IOException {
        final Iterator<CollisionObject> itObj = objects.keySet().iterator();
        while(itObj.hasNext()) {
            final CollisionObject collisionObject = itObj.next();
            final BufferedWriter output = new BufferedWriter(new FileWriter(".\\out\\" + collisionObject.getName() + ".dat"));
            output.write(collisionObject.getName() + "\n");
            output.write(objects.get(collisionObject).size() + "\n");
            for(final FrameInfo frameInfo : objects.get(collisionObject)) {
                final Transform t = frameInfo.getWorldTransform();
                final Quat4f quat = new Quat4f();
                t.getRotation(quat);
                String transformation = t.origin.x + " " + t.origin.y + " " + t.origin.z + " " + quat.x + " " + quat.y + " " + quat.z + " " + quat.w;
                output.write(/* frameInfo.getFrame() + " " + */transformation + " \n");

            }
            output.close();
        }
    }

And finally read everything from maxscript like this:


while not eof f2 AND not errorState do (
         --Based on 6 items per line...will give screwy results if that is not the case
					
        object.pos.controller = bezier_position ()
	object.rotation.controller = bezier_rotation ()
					
	at time frameNumber object.pos.x = readValue f2
	at time frameNumber object.pos.z = readValue f2
	at time frameNumber object.pos.y = readValue f2
						
	qt = quat (readValue f2) (readValue f2) (readValue f2) (readValue f2)
	at time frameNumber object.rotation = qt
)

And here is the snippet of the list generated by the jBullet implementation:


-7.000207 2.9911888 2.999814 -4.107783E-4 -1.7762213E-5 4.1528684E-4 0.9999998 
-7.000335 2.9798827 2.9997628 -5.624294E-4 1.0352664E-5 5.876959E-4 0.99999964 
-7.0012197 2.9665523 2.9996061 -0.0011199893 2.864436E-4 0.00124055 0.99999857 
-7.004677 2.9636376 2.9993298 -0.0012620256 2.5463334E-4 7.622685E-4 0.99999887 
-7.008398 2.967768 2.999191 -0.0017345948 4.2187166E-4 3.6495627E-4 0.99999833 
-7.009858 2.9741921 2.9996693 -0.0017635843 3.577837E-4 4.8657088E-4 0.9999983 
-7.0134134 2.9883368 3.001272 -0.0018693976 5.0782727E-4 2.7283697E-4 0.9999981 
-7.014315 2.9899888 3.0029392 -0.0017539648 5.522331E-4 4.9749546E-4 0.99999815 
-7.0163903 2.9918454 3.0063407 -4.3341625E-4 2.313659E-4 1.04258484E-4 0.9999999 
-7.017004 2.9897406 3.008818 -3.0255402E-4 1.4276913E-4 7.255005E-4 0.99999964 
-7.018611 2.987876 3.0144236 8.316229E-4 3.0872683E-4 0.0018217392 0.9999979 
-7.018618 2.9887652 3.0165792 0.0014158944 2.9269894E-4 0.0022854072 0.99999636 
-7.0169835 2.9905205 3.0216334 0.0020224128 2.823276E-4 0.0018376223 0.9999962 
-7.0154414 2.9912636 3.022513 0.0020788629 3.1878965E-4 0.0013048297 0.9999969 
-7.01305 2.9930182 3.02532 0.0021114894 2.6886715E-4 0.0010094913 0.9999972 
-7.0108914 2.9941247 3.0269902 0.0020880918 4.7242292E-4 7.5766357E-4 0.99999744 
-7.008967 2.9946783 3.0278869 0.0019483349 4.068205E-4 5.989755E-4 0.99999785 
-7.0068746 2.9948816 3.0285518 0.0018824388 3.313562E-4 4.2963063E-4 0.99999803 
-7.004844 2.9937909 3.028725 0.0021439963 2.1812133E-4 9.0445035E-5 0.9999977 
-7.0037045 2.9930723 3.026589 0.0017745745 2.460887E-4 1.0532421E-4 0.9999984 
-7.0023766 2.9934387 3.0235438 0.0014615756 2.557883E-4 -9.372302E-5 0.99999887 
-7.0013795 2.9943132 3.0198746 0.0010445961 1.3627057E-4 1.0653105E-4 0.9999994 
-6.9992614 2.9947402 3.0183303 6.200564E-4 6.1223796E-4 6.866971E-5 0.9999996 
-6.9988275 2.9947445 3.019064 7.8080187E-4 3.2051373E-4 -3.2027478E-5 0.99999964 



The position seems to be quite right but the rotation is jumpy.

What I am doing wrong? Is the frequency calling the stepSimulation method? I have to do something else with the quarternions before exporting?

Solved. The model loads fine.
:stuck_out_tongue: