I have an object loader that right now takes in textures but I have tried making some textures and they never turn out exactly how I want also I found out that lot of them use a colour I want in one place and puts it on to a different place that I don't want that colour also I have been using like a texture map thingy that has numbers and letters on it like A1 and so on and have been using that to help texture them and lot of times the numbers are shared in different places in the texture and usally its where I don't want them to be also it takes lot longer to texture them then just make the object and colour it regularly...... So how would I be able to add a materials into my Object Loader.... heres the Object Loader
package renderEngine;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import models.RawModel;
public class OBJLoader {
public static RawModel loadObjModel(String fileName, Loader loader) {
FileReader fr = null;
try {
fr = new FileReader(new File("res/objects/"+fileName+".obj"));
} catch (FileNotFoundException e) {
System.err.println("Could not read file!");
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(fr);
String line;
List<Vector3f> vertices = new ArrayList<Vector3f>();
List<Vector2f> textures = new ArrayList<Vector2f>();
List<Vector3f> normals = new ArrayList<Vector3f>();
List<Integer> indices = new ArrayList<Integer>();
float[] verticesArray = null;
float[] normalsArray = null;
float[] textureArray = null;
int[] indicesArray = null;
try {
while(true) {
line = reader.readLine();
String[] currentLine = line.split(" ");
if(line.startsWith("v ")) {
Vector3f vertex = new Vector3f(Float.parseFloat(currentLine[1]),Float.parseFloat(currentLine[2]),Float.parseFloat(currentLine[3]));
vertices.add(vertex);
}else if(line.startsWith("vt ")) {
Vector2f texture = new Vector2f(Float.parseFloat(currentLine[1]),Float.parseFloat(currentLine[2]));
textures.add(texture);
}else if(line.startsWith("vn ")) {
Vector3f normal = new Vector3f(Float.parseFloat(currentLine[1]),Float.parseFloat(currentLine[2]),Float.parseFloat(currentLine[3]));
normals.add(normal);
}else if(line.startsWith("f ")) {
textureArray = new float[vertices.size()*2];
normalsArray = new float[vertices.size()*3];
break;
}
}
while(line!=null) {
if(!line.startsWith("f ")) {
line = reader.readLine();
continue;
}
String[] currentLine = line.split(" ");
String[] vertex1 = currentLine[1].split("/");
String[] vertex2 = currentLine[2].split("/");
String[] vertex3 = currentLine[3].split("/");
processVertex(vertex1,indices,textures,normals,textureArray,normalsArray);
processVertex(vertex2,indices,textures,normals,textureArray,normalsArray);
processVertex(vertex3,indices,textures,normals,textureArray,normalsArray);
line = reader.readLine();
}
reader.close();
}catch(Exception e) {
e.printStackTrace();
}
verticesArray = new float[vertices.size()*3];
indicesArray = new int [indices.size()];
int vertexPointer = 0;
for(Vector3f vertex:vertices) {
verticesArray[vertexPointer++] = vertex.x;
verticesArray[vertexPointer++] = vertex.y;
verticesArray[vertexPointer++] = vertex.z;
}
for(int i=0;i<indices.size();i++) {
indicesArray[i] = indices.get(i);
}
return loader.loadToVAO(verticesArray, textureArray, indicesArray);
}
private static void processVertex(String[] vertexData, List<Integer> indices,List<Vector2f> textures, List<Vector3f> normals,
float[] textureArray, float[] normalsArray) {
int currentVertexPointer = Integer.parseInt(vertexData[0]) - 1;
indices.add(currentVertexPointer);
Vector2f currentTex = textures.get(Integer.parseInt(vertexData[1])-1);
textureArray[currentVertexPointer*2] = currentTex.x;
textureArray[currentVertexPointer*2+1] = 1 - currentTex.y;
Vector3f currentNorm = normals.get(Integer.parseInt(vertexData[2])-1);
normalsArray[currentVertexPointer*3] = currentNorm.x;
normalsArray[currentVertexPointer*3+1] = currentNorm.y;
normalsArray[currentVertexPointer*3+2] = currentNorm.z;
}
}
and heres a little thing I have for material
package textures;
import org.lwjgl.util.vector.Vector3f;
import org.newdawn.slick.opengl.Texture;
public class Material
{
public Texture texture;
public int id;
public String name;
public Vector3f ambient, diffuse, specular;
public float shininess;
public int shader;
}
So how would I use that so it takes those in the OBJLoader? So I don't have to bother with textures anymore also heres the object loader in use Loaded Object
Also the language it's using is Java so it needs to be a way it can be added in Java..... also i serarched all over the internet and I can't find anything on material/mtl file in LWJGL only stuff to like put it in C++ but this has to be for Java.............