MikktSpace tangent generator now properly generates the BindPoseTangent buffer when necessary
This commit is contained in:
parent
903522de91
commit
cf6951af34
@ -226,23 +226,7 @@ public class TangentBinormalGenerator {
|
||||
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) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
TangentUtils.generateBindPoseTangentsIfNecessary(mesh);
|
||||
}
|
||||
|
||||
public static void generate(Mesh mesh, boolean approxTangents) {
|
||||
|
29
jme3-core/src/main/java/com/jme3/util/TangentUtils.java
Normal file
29
jme3-core/src/main/java/com/jme3/util/TangentUtils.java
Normal file
@ -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.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.*;
|
||||
import com.jme3.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -84,6 +84,7 @@ public class MikktspaceTangentGenerator {
|
||||
if(!genTangSpaceDefault(context)){
|
||||
Logger.getLogger(MikktspaceTangentGenerator.class.getName()).log(Level.SEVERE, "Failed to generate tangents for geometry " + g.getName());
|
||||
}
|
||||
TangentUtils.generateBindPoseTangentsIfNecessary(g.getMesh());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user