Skip to content

Commit

Permalink
Merge pull request #2338 from jMonkeyEngine/yaRnMcDonuts-patch-1
Browse files Browse the repository at this point in the history
Fix NullPointer in MikktspaceTangentGenerator
  • Loading branch information
yaRnMcDonuts authored Jan 6, 2025
2 parents 63d5259 + ae03745 commit f90188e
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.scene.*;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.*;

import java.util.ArrayList;
Expand Down Expand Up @@ -129,12 +130,19 @@ public static void generate(Mesh mesh) {
private static boolean generateTangents(Mesh mesh) {
Mesh.Mode mode = mesh.getMode();
boolean hasTriangles;

if (mesh.getBuffer(Type.TexCoord) == null || mesh.getBuffer(Type.Normal) == null) {
logger.log(Level.SEVERE, "Tangent generation requires both a normal and texCoord buffer");
return false;
}

switch (mode) {
case Points:
case Lines:
case LineStrip:
case LineLoop:
hasTriangles = false; // skip this mesh
logger.log(Level.SEVERE, "Tangent generation requires a mesh with Triangles", mode);
break;

case Triangles:
Expand All @@ -148,12 +156,12 @@ private static boolean generateTangents(Mesh mesh) {
logger.log(Level.SEVERE, "Tangent generation isn't implemented for mode={0}", mode);
return false;
}

if (hasTriangles) {
MikkTSpaceImpl context = new MikkTSpaceImpl(mesh);
boolean result = genTangSpaceDefault(context);
boolean results = genTangSpaceDefault(context);
TangentUtils.generateBindPoseTangentsIfNecessary(mesh);
return result;
return results;
}
return false;
}
Expand Down

0 comments on commit f90188e

Please sign in to comment.