www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: gaurav on August 27, 2014, 07:43:15 am

Title: loading large OBJ File
Post by: gaurav on August 27, 2014, 07:43:15 am
i am trying to load large obj file (12mb) but app is crashing . but same code is working to load obj file having 1 mb

My code is

File sdRoot = Environment.getExternalStorageDirectory();
            File file = new File(sdRoot+ "/WatchApp/12345.obj");
            InputStream inputStream = null;
            try {
               inputStream = new FileInputStream(file);
            } catch (FileNotFoundException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
            }
            cube = Object3D.mergeAll(Loader.loadOBJ(inputStream, null, 5f));

cube.build();

            world.addObject(cube);
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 09:05:01 am
Yes, most likely because is too large and you run into an out of memory error. "is crashing" is of the same quality as "doesn't work"...nobody can derive anything from that description. Please post a stack trace or at least an error message.
However, in this case, it's most likely a simple out of memory. There's not much you can do about this. You can increase the memory on newer devices by adding

Code: [Select]
android:largeHeap="true"
to your manifest file, but that only cures the symptoms. Personally, i would consider a 12mb file to be too large for a mobile device anyway. If you absolutely have to use it, have a look at serialized objects: http://www.jpct.net/wiki/index.php/Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects (http://www.jpct.net/wiki/index.php/Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects)
Title: Re: loading large OBJ File
Post by: gaurav on August 27, 2014, 09:17:58 am
Logcat :
    08-27 12:44:59.225: I/jPCT-AE(3387): OpenGL renderer initialized (using 2/8 texture stages)
08-27 12:44:59.230: I/jPCT-AE(3387): Adding Lightsource: 0
08-27 12:44:59.235: I/jPCT-AE(3387): Loading file from InputStream
08-27 12:44:59.530: I/Timeline(3387): Timeline: Activity_idle id: android.os.BinderProxy@41e95420 time:16428502
08-27 12:45:00.210: I/dalvikvm-heap(3387): Forcing collection of SoftReferences for 25022388-byte allocation
08-27 12:45:00.225: E/dalvikvm-heap(3387): Out of memory on a 25022388-byte allocation.
08-27 12:45:00.225: I/dalvikvm(3387): "GLThread 7412" prio=5 tid=12 RUNNABLE
08-27 12:45:00.225: I/dalvikvm(3387):   | group="main" sCount=0 dsCount=0 obj=0x42347a10 self=0x5e31c960
08-27 12:45:00.225: I/dalvikvm(3387):   | sysTid=4091 nice=0 sched=0/0 cgrp=apps handle=1576216776
08-27 12:45:00.225: I/dalvikvm(3387):   | state=R schedstat=( 906733878 74624665 440 ) utm=73 stm=17 core=1
08-27 12:45:00.225: I/dalvikvm(3387):   at java.lang.String.<init>(String.java:~422)
08-27 12:45:00.225: I/dalvikvm(3387):   at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:642)
08-27 12:45:00.225: I/dalvikvm(3387):   at java.lang.StringBuilder.toString(StringBuilder.java:663)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1188)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadTextFile(Loader.java:78)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadOBJ(Loader.java:331)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadOBJ(Loader.java:229)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.emgeesons.watchapp.Model$MyRenderer.onSurfaceChanged(Model.java:431)
08-27 12:45:00.230: I/dalvikvm(3387):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1514)
08-27 12:45:00.230: I/dalvikvm(3387):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1242)
08-27 12:45:00.230: I/jPCT-AE(3387): [ 1409123700235 ] - ERROR: Couldn't read file from InputStream
08-27 12:45:00.240: W/dalvikvm(3387): threadid=12: thread exiting with uncaught exception (group=0x41bbfce0)
08-27 12:45:00.240: E/AndroidRuntime(3387): FATAL EXCEPTION: GLThread 7412
08-27 12:45:00.240: E/AndroidRuntime(3387): Process: com.emgeesons.watchapp, PID: 3387
08-27 12:45:00.240: E/AndroidRuntime(3387): java.lang.RuntimeException: [ 1409123700235 ] - ERROR: Couldn't read file from InputStream
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Logger.log(Logger.java:193)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1192)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadTextFile(Loader.java:78)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadOBJ(Loader.java:331)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadOBJ(Loader.java:229)


and it crash on this line
cube = Object3D.mergeAll(Loader.loadOBJ(inputStream, null, 5f));
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 09:33:19 am
As said, it's out of memory

Code: [Select]
Out of memory on a 25022388-byte allocation.
Title: Re: loading large OBJ File
Post by: gaurav on August 27, 2014, 09:38:47 am
am i doing wrong to load? even android:largeHeap="true" giving same result ..any way avoid this
            
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 10:16:44 am
Just read the rest of my post above and try to use serialized objects instead. If that still doesn't work, your object is simply too large.

Also make sure that you've used android:largeHeap="true" correctly. I find it hard to believe that it doesn't help unless you are using a pretty old device.
Title: Re: loading large OBJ File
Post by: gaurav on August 27, 2014, 10:55:56 am
i am using gt-i9300(s3) ,running 4.4.4 even i tested on moto G (4.4.4)  ..any tut for using serialized objects
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 11:54:24 am
The easiest way might be to try the ecplise plugin that the wiki mentions. If that's not an option, you have to do something like this:

Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 12:00:21 pm
One addition: You might want to zip the resulting file and load it via a ZipInputStream, because otherwise, it will be pretty large.
Title: Re: loading large OBJ File
Post by: gaurav on August 27, 2014, 02:18:34 pm
android:largeHeap="true" is  working , perv i have puted in wrong place .
for 12 mb obj file it took ard 3 min and 2048*2048 texture 1 min so overall it took 4 min to load that model.is it right behaviour

Thanks For help
 one more qus can i apply pinch zoom for that obj model ?
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 02:41:19 pm
As said: 12mb is huge for a mobile device. The loading times are reasonable for that size. Use serialized objects to cut them down. That's why they have been invented in the first place.
Title: Re: loading large OBJ File
Post by: gaurav on August 27, 2014, 03:46:53 pm
I tired using eclipse plug-in but it requires folder name, i am storing obj file in sd card
Title: Re: loading large OBJ File
Post by: gaurav on August 27, 2014, 04:10:13 pm
Still i am not getting how to use  serialized. I knw i am asking too much any sample code is present
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 04:13:40 pm
I tired using eclipse plug-in but it requires folder name, i am storing obj file in sd card
Just copy the file from the plugin's folder to your sd-card. I fail to see the problem here... ???
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 27, 2014, 04:16:32 pm
Still i am not getting how to use  serialized. I knw i am asking too much any sample code is present
Actually, there isn't much to show. In your serializer project as described above, you simply do:

Code: [Select]
new DeSerializer().serialize(yourObject3D, someOutputStream, true);

then you copy the result and on Android, you do something like

Code: [Select]
Loader.loadSerializedObject(someInputStream);

That's basically it.
Title: Re: loading large OBJ File
Post by: gaurav on August 28, 2014, 03:57:10 am
I tired using eclipse plug-in but it requires folder name, i am storing obj file in sd card
Just copy the file from the plugin's folder to your sd-card. I fail to see the problem here... ???


Ok will try today,  i only thought its nt possible coz i am downloading obj file from my server in runtime
Thank for help will try and let you know how it goes
Title: Re: loading large OBJ File
Post by: EgonOlsen on August 28, 2014, 09:14:27 am
You can store the serialized version on your server as well. If the solution has to be more flexible (like letting the user pick some object from some url), you would have to create a server component in Java that does the conversion on the fly. If that's not possible, then a 12mb obj file is simply too large.
Title: Re: loading large OBJ File
Post by: AGP on September 04, 2014, 08:50:44 am
Usually I write myself a simple class as a separate utility to serialize my objects (more often than not it's not just a single object). That way, if you have to keep modifying your models (if you're constantly re-exporting your OBJs), it keeps things simple. Besides, depending on your model and how you're using it you will sometimes have to use DeSerializer.serializeArray(...). By the way, when loading the OBJ, it may help to do--again, depending on what your needs are--Object3D.mergeAll(Loader.loadOBJ(...)). It's possible this goes smoother for you (it still has to load the multiple parts, I know, but depending on the garbage collector it could work).