Ver código fonte

Tangent calculation for Collada models

Tankernn 8 anos atrás
pai
commit
079fc5be7d

+ 1 - 0
src/main/java/eu/tankernn/gameEngine/animation/loaders/AnimatedModelLoader.java

@@ -63,6 +63,7 @@ public class AnimatedModelLoader {
 		vao.createAttribute(0, data.getVertices(), 3);
 		vao.createAttribute(1, data.getTextureCoords(), 2);
 		vao.createAttribute(2, data.getNormals(), 3);
+		vao.createAttribute(3, data.getTangents(), 3);
 		vao.createIntAttribute(4, data.getJointIds(), 3);
 		vao.createAttribute(5, data.getVertexWeights(), 3);
 		vao.unbind();

+ 6 - 1
src/main/java/eu/tankernn/gameEngine/loader/colladaLoader/GeometryLoader.java

@@ -25,6 +25,7 @@ public class GeometryLoader {
 	private float[] verticesArray;
 	private float[] normalsArray;
 	private float[] texturesArray;
+	private float[] tangentsArray;
 	private int[] indicesArray;
 	private int[] jointIdsArray;
 	private float[] weightsArray;
@@ -48,7 +49,7 @@ public class GeometryLoader {
 		initArrays();
 		convertDataToArrays();
 		convertIndicesListToArray();
-		return new MeshData(verticesArray, texturesArray, normalsArray, indicesArray, jointIdsArray, weightsArray, 1);
+		return new MeshData(verticesArray, texturesArray, normalsArray, tangentsArray, indicesArray, jointIdsArray, weightsArray, 1);
 	}
 
 	private void readRawData() {
@@ -144,6 +145,7 @@ public class GeometryLoader {
 			Vector3f position = currentVertex.getPosition();
 			Vector2f textureCoord = textures.get(currentVertex.getTextureIndex());
 			Vector3f normalVector = normals.get(currentVertex.getNormalIndex());
+			Vector3f tangent = currentVertex.getAverageTangent();
 			verticesArray[i * 3] = position.x;
 			verticesArray[i * 3 + 1] = position.y;
 			verticesArray[i * 3 + 2] = position.z;
@@ -152,6 +154,9 @@ public class GeometryLoader {
 			normalsArray[i * 3] = normalVector.x;
 			normalsArray[i * 3 + 1] = normalVector.y;
 			normalsArray[i * 3 + 2] = normalVector.z;
+			tangentsArray[i * 3] = tangent.x;
+			tangentsArray[i * 3 + 1] = tangent.y;
+			tangentsArray[i * 3 + 2] = tangent.z;
 			VertexSkinData weights = currentVertex.getWeightsData();
 			jointIdsArray[i * 3] = weights.jointIds.get(0);
 			jointIdsArray[i * 3 + 1] = weights.jointIds.get(1);

+ 6 - 33
src/main/java/eu/tankernn/gameEngine/loader/colladaLoader/MeshData.java

@@ -1,26 +1,19 @@
 package eu.tankernn.gameEngine.loader.colladaLoader;
 
-public class MeshData {
+import eu.tankernn.gameEngine.loader.obj.ModelData;
+
+public class MeshData extends ModelData {
 
 	private static final int DIMENSIONS = 3;
 
-	private float[] vertices;
-	private float[] textureCoords;
-	private float[] normals;
-	private int[] indices;
 	private int[] jointIds;
 	private float[] vertexWeights;
-	private float furthestPoint;
 
-	public MeshData(float[] vertices, float[] textureCoords, float[] normals, int[] indices,
+	public MeshData(float[] vertices, float[] textureCoords, float[] normals, float[] tangents, int[] indices,
 			int[] jointIds, float[] vertexWeights, float furthestPoint) {
-		this.vertices = vertices;
-		this.textureCoords = textureCoords;
-		this.normals = normals;
-		this.indices = indices;
+		super(vertices, textureCoords, normals, tangents, indices, furthestPoint);
 		this.jointIds = jointIds;
 		this.vertexWeights = vertexWeights;
-		this.furthestPoint = furthestPoint;
 	}
 
 	public int[] getJointIds() {
@@ -32,27 +25,7 @@ public class MeshData {
 	}
 
 	public int getVertexCount() {
-		return vertices.length / DIMENSIONS;
-	}
-
-	public float[] getVertices() {
-		return vertices;
-	}
-
-	public float[] getTextureCoords() {
-		return textureCoords;
-	}
-
-	public float[] getNormals() {
-		return normals;
-	}
-
-	public int[] getIndices() {
-		return indices;
-	}
-
-	public float getFurthestPoint() {
-		return furthestPoint;
+		return getVertices().length / DIMENSIONS;
 	}
 
 }