Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: 3ds max file does not work properly in opengl

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    9

    3ds max file does not work properly in opengl

    Hey there! I wrote an obj reader in java, i think it works properly, but my textures on my object are backfaced. I exported the obj file from 3ds max. How can i fix this? Here's my obj reading class:
    Code :
    package szakdoga_real;
     
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    import java.util.Vector;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    public class Mesh {
            private Vector<Float[]> vertices;
            private Vector<Float[]> normals;
            private Vector<Float[]> textures;
            private Vector<Integer[]> vIndex;
            private Vector<Integer[]> tIndex;
            private Vector<Integer[]> nIndex;
        public Mesh(String filePath){
            Scanner scanner;
            String line;
            vertices    = new Vector<Float[]>();
            normals     = new Vector<Float[]>();
            textures    = new Vector<Float[]>();
            vIndex      = new Vector<Integer[]>();
            tIndex      = new Vector<Integer[]>();
            nIndex      = new Vector<Integer[]>();
     
            try {
                scanner = new Scanner(new File(filePath));
                while(scanner.hasNext()){
                    line = scanner.nextLine();
                    String tempStrAr1[] = line.split("\\s+");
     
                    if(tempStrAr1[0].equals("v")){
                        Float[] tempFloatAr       = new Float[3];
                        for(int i = 1; i < 4; ++i){
                            tempFloatAr[i-1] = Float.parseFloat(tempStrAr1[i]);
                        }
                        vertices.add(tempFloatAr);
                    }
                    else if(tempStrAr1[0].equals("vn")){
                        Float[] tempFloatAr       = new Float[3];
                        for(int i = 1; i < 4; ++i){
                            tempFloatAr[i-1] = Float.parseFloat(tempStrAr1[i]);
                        }
                        normals.add(tempFloatAr);
                    }
                    else if(tempStrAr1[0].equals("vt")){
                        Float[] tempFloatAr       = new Float[3];
                        for(int i = 1; i < 4; ++i){
                            tempFloatAr[i-1] = Float.parseFloat(tempStrAr1[i]);
                        }
                        textures.add(tempFloatAr);
                    }
                    else if(tempStrAr1[0].equals("f")){
                        Integer tempIntVAr[]      = new Integer[3];
                        Integer tempIntTAr[]      = new Integer[3];
                        Integer tempIntNAr[]      = new Integer[3];
                        for(int i = 0; i < 3; ++i){
                            String tempStrAr2[]  = tempStrAr1[i+1].split("/");    
                            tempIntVAr[i] = Integer.parseInt(tempStrAr2[0]);
                            tempIntTAr[i] = Integer.parseInt(tempStrAr2[1]);
                            tempIntNAr[i] = Integer.parseInt(tempStrAr2[2]);
                        }
                        Integer[]  strar = new Integer[3];
                        for(int i=0; i < 3; ++i){
                            strar[i] = tempIntTAr[i];
                        }
     
                        //tempIntTAr[0] = strar[2];
                        //tempIntTAr[1] = strar[1];
                       // tempIntTAr[2] = strar[0];
     
                        vIndex.add(tempIntVAr);
                        tIndex.add(tempIntTAr);
                        nIndex.add(tempIntNAr);
                    }
                }        
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Szakdoga_real.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128

    Re: 3ds max file does not work properly in opengl

    [..]textures on my object are backfaced.
    The textures are what? Can you post screenshots showing what it should be and what it looks like now?

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    9

    Re: 3ds max file does not work properly in opengl

    err sorry, i thought it makes sense, my english isn 't the best. so the faces wich supposed to be inside the object, they are outside, and the ones supposed to be outside they are inside.

    Look at the string on it: 'Madagascar' is "mirrored".


    outside


    inside

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128

    Re: 3ds max file does not work properly in opengl

    Looks like the vertex winding is inverted. You should try to re-invert it during OBJ loading.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    9

    Re: 3ds max file does not work properly in opengl

    i have rewritten the code, now i'm using quads. i dropped the backsides of my primitives with: gl.glEnable(GL.GL_CULLFACE);
    the textures still "mirrored". I don't know where the mistake should be and what code should i paste here, i really don't. Any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •