From aae6170cc5a3cc991330bd0c93716cdb229920e6 Mon Sep 17 00:00:00 2001 From: Nehon Date: Fri, 30 Dec 2016 10:08:21 +0100 Subject: [PATCH] Fixed MikktSpaceTangentGenerator that was not replacing existing Tangent buffers on the mesh. That could cause crashes when the old tangent buffer did not have the same amount of components --- .../java/com/jme3/util/mikktspace/MikkTSpaceImpl.java | 11 ++++------- .../util/mikktspace/MikktspaceTangentGenerator.java | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/util/mikktspace/MikkTSpaceImpl.java b/jme3-core/src/main/java/com/jme3/util/mikktspace/MikkTSpaceImpl.java index 190a2e2c4..607272a70 100644 --- a/jme3-core/src/main/java/com/jme3/util/mikktspace/MikkTSpaceImpl.java +++ b/jme3-core/src/main/java/com/jme3/util/mikktspace/MikkTSpaceImpl.java @@ -21,13 +21,10 @@ public class MikkTSpaceImpl implements MikkTSpaceContext { public MikkTSpaceImpl(Mesh mesh) { this.mesh = mesh; - VertexBuffer tangentBuffer = mesh.getBuffer(VertexBuffer.Type.Tangent); - if(tangentBuffer == null){ - FloatBuffer fb = BufferUtils.createFloatBuffer(mesh.getVertexCount() * 4); - mesh.setBuffer(VertexBuffer.Type.Tangent, 4, fb); - } - - //TODO ensure the Tangent buffer exists, else create one. + //replacing any existing tangent buffer, if you came here you want them new. + mesh.clearBuffer(VertexBuffer.Type.Tangent); + FloatBuffer fb = BufferUtils.createFloatBuffer(mesh.getVertexCount() * 4); + mesh.setBuffer(VertexBuffer.Type.Tangent, 4, fb); } @Override diff --git a/jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java b/jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java index f6815c159..b13658473 100644 --- a/jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java +++ b/jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java @@ -512,7 +512,7 @@ public class MikktspaceTangentGenerator { } } - //TODO Nehon : Not used...seemsit's used in the original version if the structure to store the data in the regular method failed... + //TODO Nehon : Not used...seems it's used in the original version if the structure to store the data in the regular method failed... static void generateSharedVerticesIndexListSlow(int piTriList_in_and_out[], final MikkTSpaceContext mikkTSpace, final int iNrTrianglesIn) { int iNumUniqueVerts = 0; for (int t = 0; t < iNrTrianglesIn; t++) {