use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TangentBinormalGenerator method processTriangles.
private static List<VertexData> processTriangles(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t, boolean splitMirrored) {
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
if (mesh.getBuffer(Type.TexCoord) == null) {
throw new IllegalArgumentException("Can only generate tangents for " + "meshes with texture coordinates");
}
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
for (int i = 0; i < indexBuffer.size() / 3; i++) {
for (int j = 0; j < 3; j++) {
index[j] = indexBuffer.get(i * 3 + j);
populateFromBuffer(v[j], vertexBuffer, index[j]);
populateFromBuffer(t[j], textureBuffer, index[j]);
}
TriangleData triData = processTriangle(index, v, t);
if (splitMirrored) {
triData.setIndex(index);
triData.triangleOffset = i * 3;
}
vertices.get(index[0]).triangles.add(triData);
vertices.get(index[1]).triangles.add(triData);
vertices.get(index[2]).triangles.add(triData);
}
return vertices;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TangentBinormalGenerator method generate.
public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
int[] index = new int[3];
Vector3f[] v = new Vector3f[3];
Vector2f[] t = new Vector2f[3];
for (int i = 0; i < 3; i++) {
v[i] = new Vector3f();
t[i] = new Vector2f();
}
if (mesh.getBuffer(Type.Normal) == null) {
throw new IllegalArgumentException("The given mesh has no normal data!");
}
List<VertexData> vertices;
switch(mesh.getMode()) {
case Triangles:
vertices = processTriangles(mesh, index, v, t, splitMirrored);
if (splitMirrored) {
splitVertices(mesh, vertices, splitMirrored);
}
break;
case TriangleStrip:
vertices = processTriangleStrip(mesh, index, v, t);
break;
case TriangleFan:
vertices = processTriangleFan(mesh, index, v, t);
break;
default:
throw new UnsupportedOperationException(mesh.getMode() + " is not supported.");
}
processTriangleData(mesh, vertices, approxTangents, splitMirrored);
//if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer
TangentUtils.generateBindPoseTangentsIfNecessary(mesh);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TangentBinormalGenerator method processTriangleStrip.
private static List<VertexData> processTriangleStrip(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
IndexBuffer indexBuffer = mesh.getIndexBuffer();
FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
index[0] = indexBuffer.get(0);
index[1] = indexBuffer.get(1);
populateFromBuffer(v[0], vertexBuffer, index[0]);
populateFromBuffer(v[1], vertexBuffer, index[1]);
populateFromBuffer(t[0], textureBuffer, index[0]);
populateFromBuffer(t[1], textureBuffer, index[1]);
for (int i = 2; i < indexBuffer.size(); i++) {
index[2] = indexBuffer.get(i);
BufferUtils.populateFromBuffer(v[2], vertexBuffer, index[2]);
BufferUtils.populateFromBuffer(t[2], textureBuffer, index[2]);
boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]);
TriangleData triData = processTriangle(index, v, t);
if (!isDegenerate) {
vertices.get(index[0]).triangles.add(triData);
vertices.get(index[1]).triangles.add(triData);
vertices.get(index[2]).triangles.add(triData);
}
Vector3f vTemp = v[0];
v[0] = v[1];
v[1] = v[2];
v[2] = vTemp;
Vector2f tTemp = t[0];
t[0] = t[1];
t[1] = t[2];
t[2] = tTemp;
index[0] = index[1];
index[1] = index[2];
}
return vertices;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method multInBuffer.
/**
* Multiply and store a Vector2f in-buffer.
*
* @param toMult
* the vector to multiply against
* @param buf
* the buffer to find the Vector2f within
* @param index
* the position (in terms of vectors, not floats) of the vector
* to multiply
*/
public static void multInBuffer(Vector2f toMult, FloatBuffer buf, int index) {
TempVars vars = TempVars.get();
Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
tempVec2.multLocal(toMult);
setInBuffer(tempVec2, buf, index);
vars.release();
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method addInBuffer.
/**
* Add to a Vector2f in-buffer.
*
* @param toAdd
* the vector to add from
* @param buf
* the buffer to find the Vector2f within
* @param index
* the position (in terms of vectors, not floats) of the vector
* to add to
*/
public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) {
TempVars vars = TempVars.get();
Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
tempVec2.addLocal(toAdd);
setInBuffer(tempVec2, buf, index);
vars.release();
}
Aggregations