Author Topic: load 5 md2 models at the same time  (Read 1081 times)

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
load 5 md2 models at the same time
« 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. :-\

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: load 5 md2 models at the same time
« Reply #1 on: November 14, 2011, 10:37:37 am »
2M is the file size of the md2?

Offline Davi

  • byte
  • *
  • Posts: 33
    • View Profile
Re: load 5 md2 models at the same time
« Reply #2 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?   
« Last Edit: November 15, 2011, 06:09:57 am by Davi »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: load 5 md2 models at the same time
« Reply #3 on: November 15, 2011, 07:04:45 am »
Maybe this thread helps: 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...