Search in sources :

Example 16 with IndexBuffer

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 17 with IndexBuffer

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 18 with IndexBuffer

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer)

Example 19 with IndexBuffer

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) FloatBuffer(java.nio.FloatBuffer) IndexedMesh(com.bulletphysics.collision.shapes.IndexedMesh)

Example 20 with IndexBuffer

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;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IndexedMesh(com.bulletphysics.collision.shapes.IndexedMesh) Mesh(com.jme3.scene.Mesh) FloatBuffer(java.nio.FloatBuffer)

Aggregations

IndexBuffer (com.jme3.scene.mesh.IndexBuffer)21 FloatBuffer (java.nio.FloatBuffer)21 IntBuffer (java.nio.IntBuffer)10 ShortBuffer (java.nio.ShortBuffer)10 Buffer (java.nio.Buffer)9 VertexBuffer (com.jme3.scene.VertexBuffer)5 Vector3f (com.jme3.math.Vector3f)4 Mesh (com.jme3.scene.Mesh)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 IndexedMesh (com.bulletphysics.collision.shapes.IndexedMesh)2 Vector2f (com.jme3.math.Vector2f)2 IndexIntBuffer (com.jme3.scene.mesh.IndexIntBuffer)2 IndexShortBuffer (com.jme3.scene.mesh.IndexShortBuffer)2 HashMap (java.util.HashMap)2 Matrix4f (com.jme3.math.Matrix4f)1 Spline (com.jme3.math.Spline)1 Vector4f (com.jme3.math.Vector4f)1 Mode (com.jme3.scene.Mesh.Mode)1 CullHint (com.jme3.scene.Spatial.CullHint)1