Skip to content

Commit bf2369a

Browse files
committed
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
1 parent 8d818a2 commit bf2369a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

jme3-core/src/main/java/com/jme3/util/mikktspace/MikkTSpaceImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ public class MikkTSpaceImpl implements MikkTSpaceContext {
2121

2222
public MikkTSpaceImpl(Mesh mesh) {
2323
this.mesh = mesh;
24-
VertexBuffer tangentBuffer = mesh.getBuffer(VertexBuffer.Type.Tangent);
25-
if(tangentBuffer == null){
26-
FloatBuffer fb = BufferUtils.createFloatBuffer(mesh.getVertexCount() * 4);
27-
mesh.setBuffer(VertexBuffer.Type.Tangent, 4, fb);
28-
}
29-
30-
//TODO ensure the Tangent buffer exists, else create one.
24+
//replacing any existing tangent buffer, if you came here you want them new.
25+
mesh.clearBuffer(VertexBuffer.Type.Tangent);
26+
FloatBuffer fb = BufferUtils.createFloatBuffer(mesh.getVertexCount() * 4);
27+
mesh.setBuffer(VertexBuffer.Type.Tangent, 4, fb);
3128
}
3229

3330
@Override

jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static void MergeVertsSlow(int piTriList_in_and_out[], final MikkTSpaceContext m
512512
}
513513
}
514514

515-
//TODO Nehon : Not used...seemsit's used in the original version if the structure to store the data in the regular method failed...
515+
//TODO Nehon : Not used...seems it's used in the original version if the structure to store the data in the regular method failed...
516516
static void generateSharedVerticesIndexListSlow(int piTriList_in_and_out[], final MikkTSpaceContext mikkTSpace, final int iNrTrianglesIn) {
517517
int iNumUniqueVerts = 0;
518518
for (int t = 0; t < iNrTrianglesIn; t++) {

0 commit comments

Comments
 (0)