|
@@ -1,4 +1,4 @@
|
|
|
-package eu.tankernn.gameEngine.loader.obj.normalMapped;
|
|
|
+package eu.tankernn.gameEngine.loader.obj;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
@@ -10,9 +10,9 @@ import org.lwjgl.util.vector.Vector3f;
|
|
|
|
|
|
import eu.tankernn.gameEngine.util.InternalFile;
|
|
|
|
|
|
-public class NormalMappedObjLoader {
|
|
|
+public class ObjLoader {
|
|
|
|
|
|
- public static ModelDataNM loadOBJ(InternalFile objFile) {
|
|
|
+ public static ModelData loadOBJ(InternalFile objFile) {
|
|
|
BufferedReader reader;
|
|
|
try {
|
|
|
reader = objFile.getReader();
|
|
@@ -21,7 +21,7 @@ public class NormalMappedObjLoader {
|
|
|
return null;
|
|
|
}
|
|
|
String line;
|
|
|
- List<VertexNM> vertices = new ArrayList<VertexNM>();
|
|
|
+ List<Vertex> vertices = new ArrayList<Vertex>();
|
|
|
List<Vector2f> textures = new ArrayList<Vector2f>();
|
|
|
List<Vector3f> normals = new ArrayList<Vector3f>();
|
|
|
List<Integer> indices = new ArrayList<Integer>();
|
|
@@ -33,7 +33,7 @@ public class NormalMappedObjLoader {
|
|
|
Vector3f vertex = new Vector3f((float) Float.valueOf(currentLine[1]),
|
|
|
(float) Float.valueOf(currentLine[2]),
|
|
|
(float) Float.valueOf(currentLine[3]));
|
|
|
- VertexNM newVertex = new VertexNM(vertices.size(), vertex);
|
|
|
+ Vertex newVertex = new Vertex(vertices.size(), vertex);
|
|
|
vertices.add(newVertex);
|
|
|
|
|
|
} else if (line.startsWith("vt ")) {
|
|
@@ -56,9 +56,9 @@ public class NormalMappedObjLoader {
|
|
|
String[] vertex1 = currentLine[1].split("/");
|
|
|
String[] vertex2 = currentLine[2].split("/");
|
|
|
String[] vertex3 = currentLine[3].split("/");
|
|
|
- VertexNM v0 = processVertex(vertex1, vertices, indices);
|
|
|
- VertexNM v1 = processVertex(vertex2, vertices, indices);
|
|
|
- VertexNM v2 = processVertex(vertex3, vertices, indices);
|
|
|
+ Vertex v0 = processVertex(vertex1, vertices, indices);
|
|
|
+ Vertex v1 = processVertex(vertex2, vertices, indices);
|
|
|
+ Vertex v2 = processVertex(vertex3, vertices, indices);
|
|
|
calculateTangents(v0, v1, v2, textures);//NEW
|
|
|
line = reader.readLine();
|
|
|
}
|
|
@@ -75,11 +75,11 @@ public class NormalMappedObjLoader {
|
|
|
texturesArray, normalsArray, tangentsArray);
|
|
|
int[] indicesArray = convertIndicesListToArray(indices);
|
|
|
|
|
|
- return new ModelDataNM(verticesArray, texturesArray, normalsArray, tangentsArray, indicesArray, furthest);
|
|
|
+ return new ModelData(verticesArray, texturesArray, normalsArray, tangentsArray, indicesArray, furthest);
|
|
|
}
|
|
|
|
|
|
//NEW
|
|
|
- private static void calculateTangents(VertexNM v0, VertexNM v1, VertexNM v2,
|
|
|
+ private static void calculateTangents(Vertex v0, Vertex v1, Vertex v2,
|
|
|
List<Vector2f> textures) {
|
|
|
Vector3f delatPos1 = Vector3f.sub(v1.getPosition(), v0.getPosition(), null);
|
|
|
Vector3f delatPos2 = Vector3f.sub(v2.getPosition(), v0.getPosition(), null);
|
|
@@ -99,10 +99,10 @@ public class NormalMappedObjLoader {
|
|
|
v2.addTangent(tangent);
|
|
|
}
|
|
|
|
|
|
- private static VertexNM processVertex(String[] vertex, List<VertexNM> vertices,
|
|
|
+ private static Vertex processVertex(String[] vertex, List<Vertex> vertices,
|
|
|
List<Integer> indices) {
|
|
|
int index = Integer.parseInt(vertex[0]) - 1;
|
|
|
- VertexNM currentVertex = vertices.get(index);
|
|
|
+ Vertex currentVertex = vertices.get(index);
|
|
|
int textureIndex = Integer.parseInt(vertex[1]) - 1;
|
|
|
int normalIndex = Integer.parseInt(vertex[2]) - 1;
|
|
|
if (!currentVertex.isSet()) {
|
|
@@ -124,12 +124,12 @@ public class NormalMappedObjLoader {
|
|
|
return indicesArray;
|
|
|
}
|
|
|
|
|
|
- private static float convertDataToArrays(List<VertexNM> vertices, List<Vector2f> textures,
|
|
|
+ private static float convertDataToArrays(List<Vertex> vertices, List<Vector2f> textures,
|
|
|
List<Vector3f> normals, float[] verticesArray, float[] texturesArray,
|
|
|
float[] normalsArray, float[] tangentsArray) {
|
|
|
float furthestPoint = 0;
|
|
|
for (int i = 0; i < vertices.size(); i++) {
|
|
|
- VertexNM currentVertex = vertices.get(i);
|
|
|
+ Vertex currentVertex = vertices.get(i);
|
|
|
if (currentVertex.getLength() > furthestPoint) {
|
|
|
furthestPoint = currentVertex.getLength();
|
|
|
}
|
|
@@ -153,18 +153,18 @@ public class NormalMappedObjLoader {
|
|
|
return furthestPoint;
|
|
|
}
|
|
|
|
|
|
- private static VertexNM dealWithAlreadyProcessedVertex(VertexNM previousVertex, int newTextureIndex,
|
|
|
- int newNormalIndex, List<Integer> indices, List<VertexNM> vertices) {
|
|
|
+ private static Vertex dealWithAlreadyProcessedVertex(Vertex previousVertex, int newTextureIndex,
|
|
|
+ int newNormalIndex, List<Integer> indices, List<Vertex> vertices) {
|
|
|
if (previousVertex.hasSameTextureAndNormal(newTextureIndex, newNormalIndex)) {
|
|
|
indices.add(previousVertex.getIndex());
|
|
|
return previousVertex;
|
|
|
} else {
|
|
|
- VertexNM anotherVertex = previousVertex.getDuplicateVertex();
|
|
|
+ Vertex anotherVertex = previousVertex.getDuplicateVertex();
|
|
|
if (anotherVertex != null) {
|
|
|
return dealWithAlreadyProcessedVertex(anotherVertex, newTextureIndex,
|
|
|
newNormalIndex, indices, vertices);
|
|
|
} else {
|
|
|
- VertexNM duplicateVertex = previousVertex.duplicate(vertices.size());//NEW
|
|
|
+ Vertex duplicateVertex = previousVertex.duplicate(vertices.size());//NEW
|
|
|
duplicateVertex.setTextureIndex(newTextureIndex);
|
|
|
duplicateVertex.setNormalIndex(newNormalIndex);
|
|
|
previousVertex.setDuplicateVertex(duplicateVertex);
|
|
@@ -175,8 +175,8 @@ public class NormalMappedObjLoader {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void removeUnusedVertices(List<VertexNM> vertices) {
|
|
|
- for (VertexNM vertex : vertices) {
|
|
|
+ private static void removeUnusedVertices(List<Vertex> vertices) {
|
|
|
+ for (Vertex vertex : vertices) {
|
|
|
vertex.averageTangents();
|
|
|
if (!vertex.isSet()) {
|
|
|
vertex.setTextureIndex(0);
|