Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Jbullet to 3ds max  (Read 1691 times)
0 Members and 1 Guest are viewing this topic.
Offline gelerox

Junior Newbie





« Posted 2009-12-29 16:13:46 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//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??

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
    //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);
                }
           }
     }
       


1  
2  
3  
4  
5  
//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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
-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?
Offline gelerox

Junior Newbie





« Reply #1 - Posted 2010-01-04 21:00:38 »

Solved. The model loads fine.
 Tongue
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (53 views)
2014-04-15 18:08:23

BurntPizza (51 views)
2014-04-15 03:46:01

UprightPath (65 views)
2014-04-14 17:39:50

UprightPath (48 views)
2014-04-14 17:35:47

Porlus (65 views)
2014-04-14 15:48:38

tom_mai78101 (89 views)
2014-04-10 04:04:31

BurntPizza (149 views)
2014-04-08 23:06:04

tom_mai78101 (245 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!