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

Topics - romromrom

#1
Support / load a 3d model
March 08, 2013, 05:14:39 PM
I try to load a 3d model in jpct-ae.
I looked at all the tutorials and I think I understood, but I don't succeed to use the 3d files I have.

Indeed, I use the code that I found on this forum and which is present on tutorials for jpct. (-> http://www.jpct.net/forum2/index.php/topic,2076.msg15290/topicseen.html#msg15290)

Normally, it's working and it's without errors.

these is the code

    package com.example.jpct;

    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 com.threed.jpct.*;

    import android.app.Activity;
    import android.opengl.GLSurfaceView;
    import android.os.Bundle;
    import android.view.MotionEvent;
    import android.content.res.AssetManager;
    import android.content.res.Resources;
    import android.opengl.GLSurfaceView.EGLConfigChooser;
    import android.opengl.GLSurfaceView.Renderer;
    import android.util.Log;

     public class MainActivity extends Activity {
    private String thingName = "exquisit3dchair";
    private int thingScale = 1;//end
private static MainActivity 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("res/" + thingName + ".3ds", 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 = MainActivity.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.load3DS(is,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;
    }
}
     }


As you see, I use one object: exquisitchair.3ds, that I have found on this site:

http://thefree3dmodels.com/stuff/furniture/exquisite_3d_chair/12-1-0-120

My problem is simple: How tu put his file in Eclipse ?

I have tried in the "res" directory, it's said error, "invalid resource directory name", I have tried without the extension, I have tried other 3dfiles, and I have tried to create a "raw directory" or an example directory and to change the path.
But the problem remains the same.

The code has nos errors, but of course I couldn't compile for the moment.

Can you help me please ?