use of com.jme3.scene.mesh.IndexBuffer 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.scene.mesh.IndexBuffer 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.scene.mesh.IndexBuffer in project jmonkeyengine by jMonkeyEngine.
the class MikkTSpaceImpl method getIndex.
private int getIndex(int face, int vert) {
IndexBuffer index = mesh.getIndexBuffer();
int vertIndex = index.get(face * 3 + vert);
return vertIndex;
}
use of com.jme3.scene.mesh.IndexBuffer in project jmonkeyengine by jMonkeyEngine.
the class Converter method convert.
public static synchronized IndexedMesh convert(Mesh mesh) {
IndexedMesh jBulletIndexedMesh = new IndexedMesh();
jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
IndexBuffer indices = mesh.getIndicesAsList();
FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
vertices.rewind();
int verticesLength = mesh.getVertexCount() * 3;
jBulletIndexedMesh.numVertices = mesh.getVertexCount();
//3 verts * 4 bytes per.
jBulletIndexedMesh.vertexStride = 12;
for (int i = 0; i < verticesLength; i++) {
float tempFloat = vertices.get();
jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
}
int indicesLength = mesh.getTriangleCount() * 3;
jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
//3 index entries * 4 bytes each.
jBulletIndexedMesh.triangleIndexStride = 12;
for (int i = 0; i < indicesLength; i++) {
jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
}
vertices.rewind();
vertices.clear();
return jBulletIndexedMesh;
}
use of com.jme3.scene.mesh.IndexBuffer in project jmonkeyengine by jMonkeyEngine.
the class Converter method convert.
public static Mesh convert(IndexedMesh mesh) {
Mesh jmeMesh = new Mesh();
jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3));
jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3));
IndexBuffer indicess = jmeMesh.getIndexBuffer();
FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position);
for (int i = 0; i < mesh.numTriangles * 3; i++) {
indicess.put(i, mesh.triangleIndexBase.getInt(i * 4));
}
for (int i = 0; i < mesh.numVertices * 3; i++) {
vertices.put(i, mesh.vertexBase.getFloat(i * 4));
}
jmeMesh.updateCounts();
jmeMesh.updateBound();
jmeMesh.getFloatBuffer(Type.Position).clear();
return jmeMesh;
}
Aggregations