Author Topic: load a .obj file in JPCT-AE demo  (Read 20904 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #15 on: July 29, 2011, 05:53:04 pm »
It's not about your questions being beginner questions...that's perfectly fine. I just get the feeling, that you aren't really reading the docs...anyway...this has nothing to do with DeepExploration. It's just an example and the only viewer program that i own, which is why i used that. What you need (and DE can help you with that) are the names of the textures in the file. You then load a texture and add it using the exact same name to the TextureManager. When loading your object, the loader will assign this texture to the corresponding polygons based on this name. Then again, that's what the wiki page has already said... ???

Transparency can be taken from the file or set in code by using...setTransparency(...).

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #16 on: July 29, 2011, 08:29:09 pm »
Hey folks,

I was reading those posts about the .OBJ models loading  and I tried the following code in my app:

Code: [Select]
for (int i = 0; i < model.length; i++) {
            temp = model[i];
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setRotationMatrix(new Matrix());
            o3d = Object3D.mergeObjects(o3d, temp);
            o3d.build();

I suppose its purpose is position the models correctly at the scene [based on another topic]. But, with me, it didn't work (the objects are still at the wrong positions). Some suggestions?

Thanks!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #17 on: July 29, 2011, 11:01:09 pm »
This hasn't much to do with positioning. It's just to compensate for the different coordinate systems. What do you mean with "wrong positions"? The loader is for loading the objects, not for loading a scene setup. I'm not even sure if that is actually part of the OBJ-format...

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #18 on: August 01, 2011, 11:44:01 am »
thank you, I read your docs wiki but like i am french i don't understant all , I am working on your advice.
But can i optimize the time to run the application android. Because i must to wait 15 minutes in each time. Is there a solution??


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #19 on: August 01, 2011, 11:50:30 am »
Wait 15 min...for what exactly? For loading the models?

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #20 on: August 01, 2011, 11:52:09 am »
yes when i am with the emulator, i run the application and i must to wait 15 minutes to see the scene (my file obj)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #21 on: August 01, 2011, 12:21:34 pm »
How large is that object? Loading obj-files isn't particularly fast on Android and even slower in the emulator (also depends on the underlying PC hardware), which is why jPCT-AE introduced serialized obects which are loaded with the desktop version and stored in an Android friendly format. However, your file seems to be rather large... :o

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #22 on: August 01, 2011, 01:44:35 pm »
my file is 3.5Mo, is there a solution? and my obj is in ASCII
« Last Edit: August 01, 2011, 01:48:21 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #23 on: August 01, 2011, 01:54:47 pm »
Can you send me that object file for testing? The basic solution is to load the object in desktop JPCT and save it in an optimized format and load that in Android. You'll find information on that in the wiki and in this forum. However, i would like to see for myself why it is THAT slow.

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #24 on: August 01, 2011, 02:01:02 pm »
sorry, but i can't send this file obj. I can really not. it's my subject of training
but in 3ds it s fastest??
« Last Edit: August 01, 2011, 02:19:19 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #25 on: August 01, 2011, 04:09:28 pm »
...that makes it difficult to help you in that particular case. I'm not even sure if your model is in OBJ-format (which is an ASCII based format) or in ASC (which is another ASCII based format)...if loading OBJ takes 15min, loading 3DS won't be much faster...even if it would be 5 times as fast, it would still take 3min to load. I only can repeat myself:


Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #26 on: August 01, 2011, 04:22:27 pm »
where do i get the log??
and i don't understand serialized?? because me, my obj file is a scene.
How can i convert .obj in 3ds??  please

In more another question with my camera, my scene was in reverse, i have done a rotation and the camera are always in reverse, to see the scene correctly i must execute a rotation on the camera and a rotation on the scene but i lose my postition for the camera.
Do you understand this new problem?

« Last Edit: August 01, 2011, 04:42:42 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #27 on: August 01, 2011, 08:23:03 pm »
You are developing for Android without knowing where to find the logcat output?  :o It's available in the DDMS perspective in Eclipse. You should really check out your tools...

Serialized objects are briefly described in the wiki link that i gave you. Another desription: http://www.jpct.net/forum2/index.php/topic,1578.msg11888.html#msg11888
jPCT doesn't care about "scenes"...for the loader, your OBJ-file is just a bunch of objects, which is why the loader returns an array of Object3D. You can either (de)serialize single objects or arrays of objects.

You can convert obj to 3ds with any tool that can do that. DeepExploration for example. If you still have that, give it a try.

I'm not sure what you mean with "in reverse". The coordinate system between jPCT and your editor may differ. Usually, a obj.rotateX((float) (-.5 * Math.PI)); should rotate the scene correctly. As said above, there is no "scene loading"...it just loads the objects from the file. The camera will remain default, unless you are changing it (i.e. located at the origin looking down the positive z-axis). 

Offline nico_r_a

  • byte
  • *
  • Posts: 48
    • View Profile
Re: load a .obj file in JPCT-AE demo
« Reply #28 on: August 02, 2011, 09:44:09 am »
but i asked this question because on the wiki I do not understand everything (because i am french ^^)
"in reverse" is to mean the scene is turn up (upside down), i must turn my head of 180 degré to see correctly the scene.
so i do always a rotate?
i have try to turn the obj but it's not correct



i have convert my file obj in 3ds but i don't arrive to load :
''private Object loadModel(InputStream filename, float scale) {
         Object3D[] model = Loader.load3DS(filename, scale);"
 this is correct??


i wish to serialiaze my object. in your demo there is a file .ser. how do you create this file?
thank you
« Last Edit: August 02, 2011, 03:47:51 pm by nico_r_a »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: load a .obj file in JPCT-AE demo
« Reply #29 on: August 02, 2011, 04:14:40 pm »
The rotation of the model after loading depends on how it has been stored in the file. In most cases, you have to rotate it -90 (Pi/2) degrees around x. In your case, it seems that you have to rotate it 180 degrees (Pi). It's always better to rotate the mesh instead of rotating the camera, because its more difficult to work with a camera that it upside-down. What do you mean by "not correct". The rotation itself IS correct. It might happen that the rotation pivot (i.e. the point around which the rotation happens in object space) is not what you expect it to be. It's calculated by jPCT when calling build(). If it's different for your model, you might have to adjust it. Just play around with rotations and translation to get it right.

Your loading code is correct as long as filename really is a valid inputstream. What the problem with loading it that way?

About serialization...i can't say more about that it than i did in the link that i already gave you: http://www.jpct.net/forum2/index.php/topic,1578.msg11888.html#msg11888. Remember that you need the desktop version of jPCT to do this.