From cb90159e817b8d1bb3fbc7ee24699d6b9a0fffda Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Mon, 8 Jul 2013 08:30:47 +0000 Subject: [PATCH] - TangentBinormalGenerator : not joining the similar vertices for computing tangents when not splitting mirrored vertices seems to yeild worse artifacts than before. I reintroduced the joining. That produces wrong lighting anyway, but at least it's consistent with what we had before. after 3.0, I'll default the split mirrored vertice behaviour. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10700 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/util/TangentBinormalGenerator.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/engine/src/core/com/jme3/util/TangentBinormalGenerator.java b/engine/src/core/com/jme3/util/TangentBinormalGenerator.java index 36d2e4a8c..e982e9665 100644 --- a/engine/src/core/com/jme3/util/TangentBinormalGenerator.java +++ b/engine/src/core/com/jme3/util/TangentBinormalGenerator.java @@ -179,7 +179,7 @@ public class TangentBinormalGenerator { mesh.getMode() + " is not supported."); } - processTriangleData(mesh, vertices, approxTangents); + processTriangleData(mesh, vertices, approxTangents,splitMirrored); //if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer if (mesh.getBuffer(Type.BindPosePosition) != null) { @@ -597,7 +597,7 @@ public class TangentBinormalGenerator { (FastMath.abs(u.y - v.y) < tolerance); } - private static ArrayList linkVertices(Mesh mesh) { + private static ArrayList linkVertices(Mesh mesh, boolean splitMirrored) { ArrayList vertexMap = new ArrayList(); FloatBuffer vertexBuffer = mesh.getFloatBuffer(Type.Position); @@ -618,19 +618,20 @@ public class TangentBinormalGenerator { boolean found = false; //Nehon 07/07/2013 //Removed this part, joining splitted vertice to compute tangent space makes no sense to me - //separate vertice should have separate tangent space -// for (int j = 0; j < vertexMap.size(); j++) { -// VertexInfo vertexInfo = vertexMap.get(j); -// if (approxEqual(vertexInfo.position, position) && -// approxEqual(vertexInfo.normal, normal) && -// approxEqual(vertexInfo.texCoord, texCoord)) -// { -// vertexInfo.indices.add(i); -// found = true; -// break; -// } -// } - + //separate vertice should have separate tangent space + if(!splitMirrored){ + for (int j = 0; j < vertexMap.size(); j++) { + VertexInfo vertexInfo = vertexMap.get(j); + if (approxEqual(vertexInfo.position, position) && + approxEqual(vertexInfo.normal, normal) && + approxEqual(vertexInfo.texCoord, texCoord)) + { + vertexInfo.indices.add(i); + found = true; + break; + } + } + } if (!found) { VertexInfo vertexInfo = new VertexInfo(position.clone(), normal.clone(), texCoord.clone()); vertexInfo.indices.add(i); @@ -642,8 +643,8 @@ public class TangentBinormalGenerator { } private static void processTriangleData(Mesh mesh, List vertices, - boolean approxTangent) { - ArrayList vertexMap = linkVertices(mesh); + boolean approxTangent, boolean splitMirrored) { + ArrayList vertexMap = linkVertices(mesh,splitMirrored); FloatBuffer tangents = BufferUtils.createFloatBuffer(vertices.size() * 4);