Hi everyone,

I'm developing an android application for my thesis and I need to load
a 3D model into it. I have decided to use the .obj file structure as
input. After some searching in the internet and also here in the
Android Developers group I found an object loader provided by the
project android-gl (http://code.google.com/p/android-gl/). Its
ObjectLoader.java file provides the following load methods:

public Model load(InputStream in)
        throws IOException

public Model load(String file)
        throws IOException

My problem at the moment is to correctly load the model into my
application so that I can see it on the display. I have integrated the
loader call inside the onDrawFrame method:

public void onDrawFrame(GL10 gl) {

                gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                gl.glFrontFace(GL10.GL_CW);
                gl.glEnable(GL10.GL_CULL_FACE);
                gl.glCullFace(GL10.GL_BACK);

                for(int loop = 0; loop < 2; loop++) {

                        if(loop==0) {
                                gl.glViewport(0, 0, w, h);
                                gl.glMatrixMode(GL10.GL_PROJECTION);
                                gl.glLoadIdentity();
                                gl.glOrthof(-1.0f, 1.0f, -1.0f * h / w, 1.0f * 
h / w, -2.0f,
10.0f);
                        }

                        if(loop==1) {
                                gl.glViewport(0, 65, w/2, w/2);
                                gl.glMatrixMode(GL10.GL_PROJECTION);
                                gl.glLoadIdentity();
                                GLU.gluPerspective(gl, 45.0f, (float) w / 
(float) h, -2.0f,
10.0f);
                        }

                        gl.glMatrixMode(GL10.GL_MODELVIEW);
                        gl.glLoadIdentity();

                        gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);

                        if(loop==0) {
                                gl.glPushMatrix();
                                        
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
                                        
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
                                        gl.glBindTexture(GL10.GL_TEXTURE_2D, 
textureId);

                                        gl.glTranslatef(0.0f, 0.0f, 10.0f);

                                        gl.glVertexPointer(2, GL10.GL_FLOAT, 0, 
vertices);
                                        gl.glEnable(GL10.GL_TEXTURE_2D);
                                        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 
0, texCoords);
                                        gl.glDrawElements(GL10.GL_TRIANGLES, 
mIndices.length,
GL10.GL_UNSIGNED_SHORT, indices);
                                gl.glPopMatrix();
                                gl.glDisable(GL10.GL_TEXTURE_2D);
                        }


                        // NOW THE PART WITH THE LOADER


                        if(loop==1) {
                                gl.glPushMatrix();
                                        gl.glTranslatef(0.0f, 0.0f, 5.0f);
                                        // loading 3D model
                                        try {
                --------->                 loader.load(new 
FileInputStream("sdcard/
pixbag.obj"));
                                        } catch (FileNotFoundException e) {
                                           e.printStackTrace();
                                        } catch (Exception e) {
                                           e.printStackTrace();
                                        }
                                gl.glPopMatrix();
                        }
                }

                gl.glDisable(GL10.GL_CULL_FACE);
                gl.glFlush();
}

Since I'm working with the android emulator I wanted to load the obj
file out of the emulated sdcard device. But when I'm trying to push a
file onto it using DDMS in eclipse the console returns the following
lines:

Failed to push the item(s).
(null)

I also tried to push the file using the command line tool without
result :( So for now without the model I'm even not sure if the loader
does what it's supposed to do.

Another way I tried was to have the obj file in the assets folder of
my eclipse project from where I also load my texture file. So I have
modified the above-mentioned lines concerning the loader to:

InputStream in = getAssets().open("pixbag.obj");
loader.load(in);

This revision neither worked. I still cannot see the 3d model. Any
help and advise on how I can load and display the 3d data in the
emulator is more than appreciated!

thanks in advance,
Sadi






-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to