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

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));
line = scanner.nextLine();
String tempStrAr1[] = line.split("\\s+");

Float[] tempFloatAr = new Float[3];
for(int i = 1; i < 4; ++i){
tempFloatAr[i-1] = Float.parseFloat(tempStrAr1[i]);
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]);
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]);
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];

} catch (FileNotFoundException ex) {
Logger.getLogger(Szakdoga_real.class.getName()).lo g(Level.SEVERE, null, ex);

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?

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".



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

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?