Author Topic: To convert an OBJ into .SER format.  (Read 3165 times)

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
To convert an OBJ into .SER format.
« on: December 21, 2012, 07:07:32 pm »
Hello everyone, i am new to jpct engine and i've tried some examples given on the website. Tried loading some .obj file and it worked fine.

however, i have a question that it is mentioned that jpct-ae also uses .ser files but I dont know how to convert (obj, 3ds etc ) into
.ser format.

Do i need to write my own code for this or is there any other method?

Please help.

Sid,  ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #1 on: December 21, 2012, 08:18:22 pm »
You need the desktop version of jPCT to do this. Load your object with the desktop version and use the DeSerializer class to serialize it. You can serialize it in a special format for Android in case you don't want to load it on the desktop again.

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
Re: To convert an OBJ into .SER format.
« Reply #2 on: December 22, 2012, 11:51:17 am »
How to do it in Android?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #3 on: December 22, 2012, 05:37:10 pm »
You can't. The Android version isn't meant to be used create serialized objects, it only loads them. You have to use the desktop version for this.

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
Re: To convert an OBJ into .SER format.
« Reply #4 on: December 25, 2012, 10:49:50 am »
Okay, sure I have downloaded the desktop version for the same. I have read the javadoc for it but I am clueless on how this works?

Sorry for asking this silly question but I am a newbie here.

Hope you don't mind :) :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #5 on: December 25, 2012, 06:03:48 pm »
You load the model in the desktop version as you do now in jPCT-AE (remember to call build() on it for best results). Then create an instance of the DeSerializer class and call serialize() to serialize the mesh (in reduced mode by setting that attribute to true). Load the resulting file in jPCT-AE.

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
Re: To convert an OBJ into .SER format.
« Reply #6 on: December 26, 2012, 04:01:40 pm »
The desktop version isn't running properly.
I am getting this as an error in the desktop version..
please see to it.

--------------------------------------------------

Loading Texture...box.jpg
Java version is: 1.7.0_01
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
   at java.lang.ClassLoader.loadLibrary(Unknown Source)
   at java.lang.Runtime.loadLibrary0(Unknown Source)
   at java.lang.System.loadLibrary(Unknown Source)
   at org.lwjgl.Sys$1.run(Sys.java:73)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
   at org.lwjgl.Sys.loadLibrary(Sys.java:95)
   at org.lwjgl.Sys.<clinit>(Sys.java:112)
   at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
   at com.threed.jpct.GLHelper.findMode(GLHelper.java:63)
   at com.threed.jpct.GLHelper.findMode(GLHelper.java:58)
   at com.threed.jpct.GLHelper.init(GLHelper.java:156)
   at com.threed.jpct.GLRenderer.init(GLRenderer.java:24)
   at com.threed.jpct.FrameBuffer.enableRenderer(FrameBuffer.java:1134)
   at com.threed.jpct.FrameBuffer.enableRenderer(FrameBuffer.java:753)
   at com.threed.jpct.FrameBuffer.enableRenderer(FrameBuffer.java:700)
   at HelloWorldOGL.loop(HelloWorldOGL.java:38)
   at HelloWorldOGL.main(HelloWorldOGL.java:16)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #7 on: December 26, 2012, 04:15:52 pm »
The desktop version runs fine...you just haven't added the native libraries to the library path. Refer to the wiki for more information. Anyway, for just creating serialized files, you don't need to do this. You need no World, no FrameBuffer....just load the file, call build() and serialize it. You only need something like 4 or 5 lines of code for this.

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
Re: To convert an OBJ into .SER format.
« Reply #8 on: December 26, 2012, 05:02:34 pm »
Hi again,
After reading the wiki, I tried the following code.. and i got this..where am i wrong?

static Object3D cube;
   
   public static void main(String[] args) {

      
      cube = Object3D.mergeAll(Loader.loadOBJ(("models/airboat.obj"), null, 10));
      try {
         new DeSerializer().serialize(cube,  new FileOutputStream("models/cube.ser"), true);
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
        cube.build();
   }









Processing object from OBJ-file: noname
Processing object from OBJ-file: shroud
Object 'shroud_jPCT-2' created using 2224 polygons and 1136 vertices.
Processing object from OBJ-file: boat
Object 'boat_jPCT-1' created using 896 polygons and 454 vertices.
Processing object from OBJ-file: engine
Object 'engine_jPCT0' created using 1852 polygons and 1010 vertices.
Processing object from OBJ-file: heads
Object 'heads_jPCT1' created using 520 polygons and 320 vertices.
Processing object from OBJ-file: cylinders
Object 'cylinders_jPCT2' created using 896 polygons and 544 vertices.
Processing object from OBJ-file: emounts
Object 'emounts_jPCT3' created using 1328 polygons and 712 vertices.
Processing object from OBJ-file: intakes
Object 'intakes_jPCT4' created using 644 polygons and 340 vertices.
Processing object from OBJ-file: exhaust
Object 'exhaust_jPCT5' created using 600 polygons and 314 vertices.
Processing object from OBJ-file: shaft
Object 'shaft_jPCT6' created using 446 polygons and 229 vertices.
Processing object from OBJ-file: hub
Object 'hub_jPCT7' created using 618 polygons and 360 vertices.
Processing object from OBJ-file: prop
Object 'prop_jPCT8' created using 426 polygons and 252 vertices.
Processing object from OBJ-file: rudder
Object 'rudder_jPCT9' created using 160 polygons and 84 vertices.
Processing object from OBJ-file: seat
Object 'seat_jPCT10' created using 242 polygons and 128 vertices.
Processing object from OBJ-file: stand
Object 'stand_jPCT11' created using 268 polygons and 140 vertices.
Processing object from OBJ-file: steer
Object 'steer_jPCT12' created using 94 polygons and 52 vertices.
Processing object from OBJ-file: throttle
Object 'throttle_jPCT13' created using 94 polygons and 52 vertices.
[ Wed Dec 26 21:29:31 IST 2012 ] - WARNING: This OBJ-file contains n-polygons with n>4! These polygons wont be displayed correctly!


The problem is, the obj file is of 301kb but the .ser file is greater than 1mb. :( Wont it affect the performance of the system?
« Last Edit: December 26, 2012, 05:09:13 pm by BABABLACK_911 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #9 on: December 26, 2012, 05:35:43 pm »
No, that's normal. The ser-format is more or less a memory dump without any compression being used. The loader loads it very fast and rendering performance isn't affected by the file format. It will use less memory once loaded and stripped (remember to call strip() on it in your App if possible) You can zip the ser-file and load it via a ZipInputStream if you want to, but that only reduces storage space needed. 
Please note that this particular model contains polygons with more than 4 points. jPCT won't render them correctly, which is why the loader prints out the warning.

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
Re: To convert an OBJ into .SER format.
« Reply #10 on: December 26, 2012, 05:47:40 pm »
Okay, I have one more Question to ask.
There is an OBJ file named minicooper.OBJ of size more than 6 MB which took 30sec to load on a device powered with mali.
Anyways the point is, I got it serialized to a size of 10Mb, Now wont that increase the size of my Apk ?

Both the objects(OBJ files) loaded  correctly without any issues...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #11 on: December 26, 2012, 06:47:43 pm »
It depends. Ser-files compress pretty well and apk is compressed, so it might not matter that much. However, a model of that size might not be suitable for a mobile application anyway.

Offline BABABLACK_911

  • byte
  • *
  • Posts: 14
    • View Profile
Re: To convert an OBJ into .SER format.
« Reply #12 on: December 27, 2012, 04:00:14 pm »
Okay, Thanks for the support.
And I've seen the ninja example that is implemented using Bones in Android.
So All the animation poses will be defined by the 3d animator or by the programmer's end?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: To convert an OBJ into .SER format.
« Reply #13 on: December 27, 2012, 08:25:02 pm »
By the animator. But i've no real clue about Bones. Consider to ask in the Bones sub-forum if you have a specific question.