Author Topic: Obj file format does NOT contain animation?  (Read 5097 times)

Offline riscbus

  • byte
  • *
  • Posts: 15
    • View Profile
Obj file format does NOT contain animation?
« on: February 16, 2015, 06:56:23 am »
Hello, Sir:
  I find a model make with blender and export it with obj file format

  but I can not find any animation info in it, and I find this page: http://stackoverflow.com/questions/757145/do-wavefront-obj-files-support-animation

  I try to export with animation checked, but I got 30 obj & mtl files(total 60)

  How can I try animation with obj file? any one familliar with blender & obj file format? many thanks!

Offline riscbus

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Obj file format does NOT contain animation?
« Reply #1 on: February 16, 2015, 07:07:03 am »
Chinese Spring Festival is arriving, My reply will not very often

I will check this time by time...

Offline riscbus

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Obj file format does NOT contain animation?
« Reply #2 on: February 16, 2015, 08:56:08 am »
I use this way to  add animation  http://www.jpct.net/forum2/index.php/topic,2559.msg18872.html#msg18872

but when addkeyframe, I got error: java.lang.RuntimeException: [ 1420062253543 ] - ERROR: Bounding box missing in this mesh!

it is the problem with model self? how can I avoid it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Obj file format does NOT contain animation?
« Reply #3 on: February 16, 2015, 09:17:12 am »
Use this to calculate a bounding box: http://www.jpct.net/doc/com/threed/jpct/Object3D.html#calcBoundingBox().

Anyway, OBJ indeed doesn't support animations and neither does 3ds. jPCT by itself eithers loads MD2 (old keyframe based format) or you have to import single keyframes (it might be best to do this on the desktop and serialize the result for Android). Another option is to use the Bones API in addition, which adds skeletal animation support to jPCT.

Offline riscbus

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Obj file format does NOT contain animation?
« Reply #4 on: February 16, 2015, 09:25:24 am »
before I add mesh as keyframes, I call
            obj.calcNormals();
            obj.calcBoundingBox();
            obj.build();
as you suggestion, but the animation is empty, because the bound box is missing from the mesh

My total source as below:


   private void loadWalk(Animation walk) {
      walk.createSubSequence("walk");
      for (int i = 10; i <= 30; i++) {// I got 30 obj & mtl files, I use 20 to make up a animation
         try {
            InputStream objStream = m_context.getAssets().open(
                  "sara3d_2015_0000" + i + ".obj");
            InputStream mtlStream = m_context.getAssets().open(
                  "sara3d_2015_0000" + i + ".mtl");
            Object3D obj = Loader.loadOBJ(objStream, mtlStream, 1)[0];
            obj.setCenter(SimpleVector.ORIGIN);
            obj.calcNormals();
            obj.calcBoundingBox();
            obj.build();
            Object3D tmp = new Object3D(0);
            tmp = Object3D.mergeObjects(tmp, obj);
            tmp.strip();
            walk.addKeyFrame(tmp.getMesh()); // can I use objct3D from loader directly?
            objStream.close();
            mtlStream.close();
         } catch (Exception e) {
            String err = e.toString();// I always here...
            err += "!";
         }
      }
   }
« Last Edit: February 16, 2015, 09:27:26 am by riscbus »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Obj file format does NOT contain animation?
« Reply #5 on: February 17, 2015, 08:45:15 am »
This part

Code: [Select]
Object3D tmp = new Object3D(0);
tmp = Object3D.mergeObjects(tmp, obj);
tmp.strip();

makes no sense. Just add the mesh directly from the obj instance to the animation. What is this part supposed to do?

Offline riscbus

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Obj file format does NOT contain animation?
« Reply #6 on: March 06, 2015, 12:10:40 pm »
now I find the root cause:

the model has no bounding box, so when I load it first, no bounding box

then I load model again, & add keyframe to make animation, if I NOT caleBounding box, the mesh can not add to keyframe
                                                                                               if I caleBounding box, after cale, the mesh is diff from orgin one

so I caleBounding box when I first load the model, the problem solved

Another question: the model has 3-4K faces, 30 frame for walk, the loading speed is very slow, how can I enhance it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Obj file format does NOT contain animation?
« Reply #7 on: March 06, 2015, 12:26:45 pm »
Another question: the model has 3-4K faces, 30 frame for walk, the loading speed is very slow, how can I enhance it?
Load the models and animation with the desktop version, serialize them to disk (http://www.jpct.net/doc/com/threed/jpct/DeSerializer.html) and load that file on Android (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Loader.html#loadSerializedObject(java.io.InputStream)). It's much faster this way (http://www.jpct.net/wiki/index.php/Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects).