Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - sienioslaw

#1
Support / Re: load a .obj file in JPCT-AE demo
July 26, 2011, 12:40:24 AM
Hello! I'm new one to this forum, and I also have problem with loading obj models...
Here is some info: I'm using Eclipse and Android SDK 2.1
I'm following this tutorial: http://www.jpct.net/wiki/index.php/Loading_3ds_Models_from_Blender - only changed loading function from 3ds into OBJ(as far I understood from doc's, I don't need mtl, so left it null),
I put my model, a example file from http://people.sc.fsu.edu/~jburkardt/data/obj/obj.html in 'assets' folder

Tried to test it on emulator but crashing like hell  :-\ and looks like it's OutOfMemory problem, but how if I only load simple cube file? 

Here is code and log:
source:

package com.threed.jpct.example;

import java.io.*;
import java.lang.reflect.Field;

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 android.app.Activity;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;


import com.threed.jpct.*;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;
/**
* A simple demo. This shows more how to use jPCT-AE than it shows how to write
* a proper application for Android.
* It includes basic activity management to handle pause and resume...
*
* @author EgonOlsen
*
*/
public class HelloWorld extends Activity {
    private String thingName = "temp";
    private int thingScale = 1;//end
private static HelloWorld master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer buffer = null;

private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Object3D thing = null;
private int fps = 0;

private Light sun = null;
private Camera cam = null;

AssetManager assMan;
InputStream is;
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}

protected void onStop() {
super.onStop();
}

public boolean onTouchEvent(MotionEvent me) {

if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;

xpos = me.getX();
ypos = me.getY();

touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();
private boolean stop = false;

public MyRenderer() {
}

public void stop() {
stop = true;
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
if (buffer != null) {
buffer.dispose();
}
buffer = new FrameBuffer(gl, w, h);

if (master == null) {

world = new World();
        world.setAmbientLight(150, 150, 150);

sun = new Light(world);
sun.setIntensity(250, 250, 250);

thing = loadModel("assets/model.obj", thingScale);
        thing.build();

world.addObject(thing);

cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(thing.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(thing.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
//MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}

public void onDrawFrame(GL10 gl) {

try {
if (!stop) {
if (touchTurn != 0) {
thing.rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
thing.rotateX(touchTurnUp);
touchTurnUp = 0;
}

buffer.clear(back);
world.renderScene(buffer);
world.draw(buffer);
buffer.display();

if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
} else {
if (buffer != null) {
buffer.dispose();
buffer = null;
}
}
} catch (Exception e) {
Logger.log(e, Logger.MESSAGE);
}
}

    private Object3D loadModel(String filename, float scale) {
assMan = getResources().getAssets();
is = new InputStream() {
@Override
public int read() throws IOException {
return 0;
}
};
        Object3D[] model = Loader.loadOBJ(is, null, scale);
        Object3D o3d = new Object3D(0);
        Object3D temp = null;
        for (int i = 0; i < model.length; i++) {
            temp = model[i];
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setRotationMatrix(new Matrix());
            o3d = Object3D.mergeObjects(o3d, temp);
            o3d.build();
        }
        return o3d;
    }
}
}





log:
07-25 22:33:48.269: WARN/ActivityManager(65): Activity idle timeout for HistoryRecord{44ffd098 com.threed.jpct.example/.HelloWorld}
07-25 22:33:48.549: INFO/dalvikvm-heap(466): Grow heap (frag case) to 13.402MB for 6378722-byte allocation
07-25 22:33:51.678: INFO/dalvikvm-heap(466): Forcing collection of SoftReferences for 9568078-byte allocation
07-25 22:33:51.798: ERROR/dalvikvm-heap(466): Out of memory on a 9568078-byte allocation.
07-25 22:33:51.798: INFO/dalvikvm(466): "GLThread 8" prio=5 tid=7 RUNNABLE
07-25 22:33:51.809: INFO/dalvikvm(466):   | group="main" sCount=0 dsCount=0 s=N obj=0x44e85270 self=0x11f848
07-25 22:33:51.809: INFO/dalvikvm(466):   | sysTid=472 nice=0 sched=0/0 cgrp=default handle=1283576
07-25 22:33:51.809: INFO/dalvikvm(466):   | schedstat=( 10442697916 807643615 403 )
07-25 22:33:51.828: INFO/dalvikvm(466):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~97)
07-25 22:33:51.828: INFO/dalvikvm(466):   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:157)
07-25 22:33:51.838: INFO/dalvikvm(466):   at java.lang.StringBuffer.append(StringBuffer.java:215)
07-25 22:33:51.838: INFO/dalvikvm(466):   at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1076)
07-25 22:33:51.850: INFO/dalvikvm(466):   at com.threed.jpct.Loader.loadTextFile(Loader.java:71)
07-25 22:33:51.850: INFO/dalvikvm(466):   at com.threed.jpct.Loader.loadOBJ(Loader.java:302)
07-25 22:33:51.850: INFO/dalvikvm(466):   at com.threed.jpct.Loader.loadOBJ(Loader.java:207)
07-25 22:33:51.858: INFO/dalvikvm(466):   at com.threed.jpct.example.HelloWorld$MyRenderer.loadModel(HelloWorld.java:218)
07-25 22:33:51.858: INFO/dalvikvm(466):   at com.threed.jpct.example.HelloWorld$MyRenderer.onSurfaceChanged(HelloWorld.java:148)
07-25 22:33:51.878: INFO/dalvikvm(466):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1325)
07-25 22:33:51.878: INFO/dalvikvm(466):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
07-25 22:33:51.928: INFO/ActivityManager(65): Displayed activity com.threed.jpct.example/.HelloWorld: 14353 ms (total 418702 ms)
07-25 22:33:51.958: WARN/dalvikvm(466): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
07-25 22:33:52.078: ERROR/AndroidRuntime(466): FATAL EXCEPTION: GLThread 8
07-25 22:33:52.078: ERROR/AndroidRuntime(466): java.lang.OutOfMemoryError
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:157)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at java.lang.StringBuffer.append(StringBuffer.java:215)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1076)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at com.threed.jpct.Loader.loadTextFile(Loader.java:71)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at com.threed.jpct.Loader.loadOBJ(Loader.java:302)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at com.threed.jpct.Loader.loadOBJ(Loader.java:207)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at com.threed.jpct.example.HelloWorld$MyRenderer.loadModel(HelloWorld.java:218)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at com.threed.jpct.example.HelloWorld$MyRenderer.onSurfaceChanged(HelloWorld.java:148)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1325)
07-25 22:33:52.078: ERROR/AndroidRuntime(466):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
07-25 22:33:52.168: WARN/ActivityManager(65):   Force finishing activity com.threed.jpct.example/.HelloWorld


Any advices?
Btw. Sorry for my english...