PDA

View Full Version : 3ds max file does not work properly in opengl



lolzoromg
03-13-2012, 04:13 AM
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:
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()).lo g(Level.SEVERE, null, ex);
}
}

thokra
03-13-2012, 04:37 AM
[..]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?

lolzoromg
03-13-2012, 04:54 AM
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
http://kepfeltoltes.hu/120313/outside_www.kepfeltoltes.hu_.png

inside
http://kepfeltoltes.hu/120313/inside_www.kepfeltoltes.hu_.png

thokra
03-13-2012, 05:27 AM
Looks like the vertex winding is inverted. You should try to re-invert it during OBJ loading.

lolzoromg
03-13-2012, 09:58 AM
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?