Author Topic: Out of memory when load 3ds file.  (Read 3345 times)

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
Out of memory when load 3ds file.
« on: March 17, 2011, 03:03:05 am »
Hi guys,

I created a teaport with 3ds Max, then export it to .3ds file.
On Android, i load that 3ds file to display. The teaport was displayed, but after a while, the error happened.

on LogCat, i saw this message appeared about 2116 times:

03-17 08:44:52.635: INFO/jPCT-AE(xxx): Additional visibility list (xxxx) created with size: 512

Here is my code:

Code: [Select]
package com.dlh.Second_jPCT;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.OcTree;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.BitmapHelper;

import android.app.Activity;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
import android.util.Log;

public class Second_jPCT extends Activity {
   
GLSurfaceView glSurface;

World world;
FrameBuffer fb;
TextureManager ttman;
Camera cam;
Object3D terrain, teaport;
Light sun;

boolean first=true;
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        glSurface= new GLSurfaceView(getApplication());
        glSurface.setRenderer(new MyRenderer());
       
        setContentView(glSurface);   
    }
    @Override
    protected void onPause() {
    // TODO Auto-generated method stub
        glSurface.onPause();
    super.onPause();
    }
    @Override
    protected void onResume() {
    // TODO Auto-generated method stub
        glSurface.onResume();
    super.onResume();
    }
    class MyRenderer implements Renderer{

@Override
public void onDrawFrame(GL10 arg0) {
// TODO Auto-generated method stub
fb.clear(new RGBColor(20,20,20));
world.renderScene(fb);
world.draw(fb);
}

@Override
public void onSurfaceChanged(GL10 arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
if(fb!=null){
fb.dispose();
}
fb= new FrameBuffer(arg0, arg1, arg2);
}

@Override
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
// TODO Auto-generated method stub

world= new World();
        world.setAmbientLight(30, 30, 30);
               
        Drawable image= getResources().getDrawable(R.drawable.rocks);
        Texture rock= new Texture(BitmapHelper.rescale(BitmapHelper.convert(image), 64, 64) );
        TextureManager.getInstance().addTexture("ground",rock);

AssetManager assMan = getResources().getAssets();
InputStream is= new InputStream() {

@Override
public int read() throws IOException {
// TODO Auto-generated method stub
return 0;
}
};
try {
is =  assMan.open("teaport.3ds", AssetManager.ACCESS_UNKNOWN);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Object3D[] objs= Loader.load3DS(is, 1);

if(objs.length>0){
teaport= objs[0];
teaport.setTexture("ground");
}
teaport.enableLazyTransformations();
world.addObject(teaport);
teaport.build();
teaport.strip();

         cam= world.getCamera();
         cam.setPosition(new SimpleVector(0,-5,0));
         cam.lookAt(teaport.getTransformedCenter());
         
         sun = new Light(world);
         sun.setIntensity(250, 250, 250);
         sun.setPosition(new SimpleVector(0,-20,0));
}
   
    }
   
}

how can resolve this?

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Out of memory when load 3ds file.
« Reply #1 on: March 17, 2011, 06:09:42 am »
this is my mistake!

I didn't use fb.display() in onDrawFrame function