www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Davi on November 14, 2011, 08:56:33 am

Title: load 5 md2 models at the same time
Post by: Davi on November 14, 2011, 08:56:33 am
Hello,I have 5 md2 models,each model is about 2M,I want to load them at the same time,I don't know how to load it correctly, maybe there will be out of memorry? I have no idea,please give me a hint. :-\
Title: Re: load 5 md2 models at the same time
Post by: EgonOlsen on November 14, 2011, 10:37:37 am
2M is the file size of the md2?
Title: Re: load 5 md2 models at the same time
Post by: Davi on November 15, 2011, 04:29:20 am
yeh,that is file size,oh my mistake,each model about 600kB,and each texture picture about 100kB ,I have use a thread to load them at the same time. but when I load about the third one, my app is crashed,the log error is out of memory.my code as following:
Code: [Select]
for(int i=0;i<5;i++){
modelList.add(Loader.loadMD2(this.getResources().getAssets().open(modelName[i], AssetManager.ACCESS_UNKNOWN), 3f));
TextureManager.getInstance().addTexture(texturesName[i], 
new Texture(BitmapFactory.decodeResource(this.getResources(), texturePictureId[i])));
}

I know there must be a good way to deal with this situation like my question.can you help me how to do that?   
Title: Re: load 5 md2 models at the same time
Post by: EgonOlsen on November 15, 2011, 07:04:45 am
Maybe this thread helps: http://www.jpct.net/forum2/index.php/topic,2361.0.html (http://www.jpct.net/forum2/index.php/topic,2361.0.html)

However, keyframe animations are expensive memory wise. That's the trade-off that you do: You trade memory for performance. I'm not sure if there's a way to make all your models fit into memory. If the idea of calling strip() on the animation like the thread mentions it doesn't work out, the only way would be to reduce the complexity of the animation. I suggest to serialize them with the desktop version to see if you can load them in that form. The serialization process already strips them, so they come in the smallest form possible that way (you might have to load them via a ZipInputStream, because serializes meshes tend to create large files).
If nothing else helps, have a look at Bones for skeletal animation instead...