diff --git a/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java b/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java index 5e85378ff..ac6b05a8c 100644 --- a/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java +++ b/jme3-core/src/main/java/com/jme3/util/TangentBinormalGenerator.java @@ -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) { diff --git a/jme3-core/src/main/java/com/jme3/util/TangentUtils.java b/jme3-core/src/main/java/com/jme3/util/TangentUtils.java new file mode 100644 index 000000000..ae227896a --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/util/TangentUtils.java @@ -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); + } + } + } +} 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 af20b842b..f6815c159 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 @@ -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()); } }