MikktSpace tangent generator now properly generates the BindPoseTangent buffer when necessary

cleanup_build_scripts
Nehon 8 years ago
parent 7e458e496c
commit 95bf9efe9b
  1. 18
      jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java
  2. 29
      jme3-core/src/main/java/com/jme3/util/TangentUtils.java
  3. 7
      jme3-core/src/main/java/com/jme3/util/mikktspace/MikktspaceTangentGenerator.java

@ -226,23 +226,7 @@ public class TangentBinormalGenerator {
processTriangleData(mesh, vertices, approxTangents,splitMirrored); processTriangleData(mesh, vertices, approxTangents,splitMirrored);
//if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer //if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer
if (mesh.getBuffer(Type.BindPosePosition) != null) { TangentUtils.generateBindPoseTangentsIfNecessary(mesh);
VertexBuffer tangents = mesh.getBuffer(Type.Tangent);
if (tangents != null) {
VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent);
bindTangents.setupData(Usage.CpuOnly,
4,
Format.Float,
BufferUtils.clone(tangents.getData()));
if (mesh.getBuffer(Type.BindPoseTangent) != null) {
mesh.clearBuffer(Type.BindPoseTangent);
}
mesh.setBuffer(bindTangents);
tangents.setUsage(Usage.Stream);
}
}
} }
public static void generate(Mesh mesh, boolean approxTangents) { public static void generate(Mesh mesh, boolean approxTangents) {

@ -0,0 +1,29 @@
package com.jme3.util;
import com.jme3.scene.*;
/**
* Created by Nehon on 03/10/2016.
*/
public class TangentUtils {
public static void generateBindPoseTangentsIfNecessary(Mesh mesh){
if (mesh.getBuffer(VertexBuffer.Type.BindPosePosition) != null) {
VertexBuffer tangents = mesh.getBuffer(VertexBuffer.Type.Tangent);
if (tangents != null) {
VertexBuffer bindTangents = new VertexBuffer(VertexBuffer.Type.BindPoseTangent);
bindTangents.setupData(VertexBuffer.Usage.CpuOnly,
4,
VertexBuffer.Format.Float,
BufferUtils.clone(tangents.getData()));
if (mesh.getBuffer(VertexBuffer.Type.BindPoseTangent) != null) {
mesh.clearBuffer(VertexBuffer.Type.BindPoseTangent);
}
mesh.setBuffer(bindTangents);
tangents.setUsage(VertexBuffer.Usage.Stream);
}
}
}
}

@ -7,9 +7,9 @@ package com.jme3.util.mikktspace;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.*;
import com.jme3.scene.Node; import com.jme3.util.*;
import com.jme3.scene.Spatial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -84,6 +84,7 @@ public class MikktspaceTangentGenerator {
if(!genTangSpaceDefault(context)){ if(!genTangSpaceDefault(context)){
Logger.getLogger(MikktspaceTangentGenerator.class.getName()).log(Level.SEVERE, "Failed to generate tangents for geometry " + g.getName()); Logger.getLogger(MikktspaceTangentGenerator.class.getName()).log(Level.SEVERE, "Failed to generate tangents for geometry " + g.getName());
} }
TangentUtils.generateBindPoseTangentsIfNecessary(g.getMesh());
} }
} }

Loading…
Cancel
Save