From e9a78c5b619b1cd9b0b2f3452beb8d43967ccae4 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 30 Oct 2011 22:17:10 +0000 Subject: [PATCH] * Added RenderState.isApply*** methods * TangentBinormalGenerator now generates TBN lines properly for the new 4 dimensional tangents that it generates git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8554 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core/com/jme3/material/RenderState.java | 2 -- .../jme3/util/TangentBinormalGenerator.java | 24 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/engine/src/core/com/jme3/material/RenderState.java b/engine/src/core/com/jme3/material/RenderState.java index 7dd400801..c6360557d 100644 --- a/engine/src/core/com/jme3/material/RenderState.java +++ b/engine/src/core/com/jme3/material/RenderState.java @@ -915,7 +915,6 @@ public class RenderState implements Cloneable, Savable { return alphaFallOff; } -/* public boolean isApplyAlphaFallOff() { return applyAlphaFallOff; } @@ -955,7 +954,6 @@ public class RenderState implements Cloneable, Savable { public boolean isApplyWireFrame() { return applyWireFrame; } -*/ /** * Merges this state and additionalState into diff --git a/engine/src/core/com/jme3/util/TangentBinormalGenerator.java b/engine/src/core/com/jme3/util/TangentBinormalGenerator.java index 5e36ecbeb..6b9606e64 100644 --- a/engine/src/core/com/jme3/util/TangentBinormalGenerator.java +++ b/engine/src/core/com/jme3/util/TangentBinormalGenerator.java @@ -370,8 +370,6 @@ public class TangentBinormalGenerator { Vector3f tangentUnit = new Vector3f(); Vector3f binormalUnit = new Vector3f(); - - for (int i = 0; i < vertices.length; i++) { float wCoord = -1; @@ -592,11 +590,22 @@ public class TangentBinormalGenerator { IntBuffer lineIndex = BufferUtils.createIntBuffer(vertexBuffer.capacity() / 3 * 6); FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.capacity() * 4); FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.capacity() / 3 * 4 * 4); - + + boolean hasParity = mesh.getBuffer(Type.Tangent).getNumComponents() == 4; + float tangentW = 1; + for (int i = 0; i < vertexBuffer.capacity() / 3; i++) { populateFromBuffer(origin, vertexBuffer, i); populateFromBuffer(normal, normalBuffer, i); - populateFromBuffer(tangent, tangentBuffer, i); + + if (hasParity){ + tangent.x = tangentBuffer.get(i * 4); + tangent.y = tangentBuffer.get(i * 4 + 1); + tangent.z = tangentBuffer.get(i * 4 + 2); + tangentW = tangentBuffer.get(i * 4 + 3); + }else{ + populateFromBuffer(tangent, tangentBuffer, i); + } int index = i * 4; @@ -617,13 +626,16 @@ public class TangentBinormalGenerator { setInBuffer(point, lineVertex, index + 1); setInBuffer(tangentColor, lineColor, index + 1); + // wvBinormal = cross(wvNormal, wvTangent) * -inTangent.w + if (binormalBuffer == null) { normal.cross(tangent, point); + point.multLocal(-tangentW); point.normalizeLocal(); - } - else { + } else { populateFromBuffer(point, binormalBuffer, i); } + point.multLocal(scale); point.addLocal(origin); setInBuffer(point, lineVertex, index + 2);