Author Topic: Loader.loadOBJ is too slow  (Read 4231 times)

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Loader.loadOBJ is too slow
« on: April 21, 2016, 03:19:24 pm »
Hi,

I am writing application that use vuforia and jpct.
I download this sample https://github.com/TheMaggieSimpson/Vuforia559_jPCT-AE

I try to replace default cylinder object by my own .obj model, but loading of model is very slow.
For example I have model that has 0.75MB and loading takes about 45s.
Line in code that is too slow is: Object3D[] model = Loader.loadOBJ(streamObj, streamMtl, scale);
Loader is default jpct class.

After model is load everything is guick and perfect.

I try different model and different phones, but this line everytime takes 45s minimal.

My model is in assets folder in application.

Is there any way to shorten loading of .obj?

Thanks for reply.

« Last Edit: April 21, 2016, 03:25:32 pm by drdla »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loader.loadOBJ is too slow
« Reply #1 on: April 21, 2016, 05:27:15 pm »
No, there isn't. OBJ is a text-based format. Loading it requires quite a lot of parsing and converting and that takes its time, especially on mobile.
However, you can use serialized objects instead. The idea is to load a model with the desktop version of jPCT, call build() on it and serialize it into a file using an optimized format that can be loaded very fast by jPCT-AE. You can find more information here: http://www.jpct.net/wiki/index.php?title=Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Loader.loadOBJ is too slow
« Reply #2 on: April 22, 2016, 12:06:39 pm »
Thank you!

Its little coplicated for my use of application but its really fast to load a model.

Just one question.
If I serialize my model use this: deSerializer.serialize(o3d, oos, true);

size of serialized object is minimal 2 times bigger than original .obj file.

For exmaple my obj has 7MB and serializable file has 15MB. Or 0.8MB obj to 2MB serializable.

Is there any way to reduce this file size?

Thank you.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loader.loadOBJ is too slow
« Reply #3 on: April 22, 2016, 01:48:11 pm »
Yes, there is. Just zip it and load it via a ZipInputStream like so:

Code: [Select]
zis = new ZipInputStream(assMan.open(name));
zis.getNextEntry();
...Loader.loadSerializedObjectArray(zis);

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Loader.loadOBJ is too slow
« Reply #4 on: April 27, 2016, 03:00:04 pm »
Thank you.

Everything is OK.

For my application I need use same model format for Android and iOS.
Do you think that there is any way to use serializable format on iOS?

I listen that if computing is C based, that is more quick than by Java computing.
jPCT use Java or C code for loading?
 
Or is there any another library which load obj quickly and give me Object that I can use with jPCT?

Thank you for answer!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loader.loadOBJ is too slow
« Reply #5 on: April 27, 2016, 03:08:45 pm »
It's not really feasible to use the serialized format on iOS. It's just a dump of jPCT-AE's internal data structures.
jPCT-AE is plain Java. The Android runtime compiles it to native code on installation time on Android 5.0 and higher and it will be compiled by a JIT compiler at runtime for Android <5.0. It's usually not that much slower than pure C, but of course it highly depends on the performance of the runtime's String and conversion methods.
Why can't you use different formats for different platforms? The build platform and the distribution package is different anyway, so what's the problem with that?

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Loader.loadOBJ is too slow
« Reply #6 on: April 27, 2016, 03:13:15 pm »
Yes that is true that everything is diffrent for this platforms.
But I have models on server and if i have two formats, I have two times more files on server.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loader.loadOBJ is too slow
« Reply #7 on: April 27, 2016, 03:45:24 pm »
But I have models on server and if i have two formats, I have two times more files on server.
...and the problem with that is...which? Is there a limit in file count on your server? Another option is to create the serialized data on-the-fly on the server. So the app wouldn't request the actual model url but something like

http://www.mybestserver.com/models/convert?model=blahblah.obj

and that convert script could then convert the model into serialized format by using desktop jPCT on the server. If the server can run Java/JSP, it's a piece of cake to do that. If it's limited to PHP or some other scripting language, it will become more cumbersome but it's still possible.