load a .obj file in JPCT-AE demo

Started by nico_r_a, July 21, 2011, 09:50:18 AM

Previous topic - Next topic

EgonOlsen

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(...).

RhoX

Hey folks,

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


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!

EgonOlsen

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...

nico_r_a

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??


EgonOlsen

Wait 15 min...for what exactly? For loading the models?

nico_r_a

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)

EgonOlsen

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

nico_r_a

#22
my file is 3.5Mo, is there a solution? and my obj is in ASCII

EgonOlsen

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.

nico_r_a

#24
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??

EgonOlsen

...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:


nico_r_a

#26
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?


EgonOlsen

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). 

nico_r_a

#28
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

EgonOlsen

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.