Java Code Examples for com.jme3.scene.Mesh#getIndicesAsList()

The following examples show how to use com.jme3.scene.Mesh#getIndicesAsList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrappedIndexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void convertToList(Mesh mesh){
    IndexBuffer inBuf = mesh.getIndicesAsList();
    IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                                                       inBuf.size());

    for (int i = 0; i < inBuf.size(); i++){
        outBuf.put(i, inBuf.get(i));
    }

    mesh.clearBuffer(Type.Index);
    switch (mesh.getMode()){
        case LineLoop:
        case LineStrip:
            mesh.setMode(Mode.Lines);
            break;
        case TriangleStrip:
        case TriangleFan:
            mesh.setMode(Mode.Triangles);
            break;
        default:
            break;
    }
    mesh.setBuffer(Type.Index, 3, outBuf.getFormat(), outBuf.getBuffer());
}
 
Example 2
Source File: MeshCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createCollisionMesh(Mesh mesh) {
    this.triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
    this.vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
    this.numVertices = mesh.getVertexCount();
    this.vertexStride = 12; // 3 verts * 4 bytes per.
    this.numTriangles = mesh.getTriangleCount();
    this.triangleIndexStride = 12; // 3 index entries * 4 bytes each.

    IndexBuffer indices = mesh.getIndicesAsList();
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    for (int i = 0; i < indicesLength; i++) {
        triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    this.createShape(null);
}
 
Example 3
Source File: GImpactCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createCollisionMesh(Mesh mesh) {
        triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
        vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); 
//        triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4);
//        vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4);
        numVertices = mesh.getVertexCount();
        vertexStride = 12; //3 verts * 4 bytes per.
        numTriangles = mesh.getTriangleCount();
        triangleIndexStride = 12; //3 index entries * 4 bytes each.

        IndexBuffer indices = mesh.getIndicesAsList();
        FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
        vertices.rewind();

        int verticesLength = mesh.getVertexCount() * 3;
        for (int i = 0; i < verticesLength; i++) {
            float tempFloat = vertices.get();
            vertexBase.putFloat(tempFloat);
        }

        int indicesLength = mesh.getTriangleCount() * 3;
        for (int i = 0; i < indicesLength; i++) {
            triangleIndexBase.putInt(indices.get(i));
        }
        vertices.rewind();
        vertices.clear();

        createShape();
    }
 
Example 4
Source File: NativeMeshUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Pass a mesh to Native Bullet.
 *
 * @param mesh the JME mesh to pass (not null)
 * @return the unique identifier of the resulting btTriangleIndexVertexArray
 * (not 0)
 */
public static long getTriangleIndexVertexArray(Mesh mesh){
    ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
    ByteBuffer vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
    int numVertices = mesh.getVertexCount();
    int vertexStride = 12; //3 verts * 4 bytes each
    int numTriangles = mesh.getTriangleCount();
    int triangleIndexStride = 12; //3 index entries * 4 bytes each

    IndexBuffer indices = mesh.getIndicesAsList();
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    for (int i = 0; i < indicesLength; i++) {
        triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride);
}
 
Example 5
Source File: Converter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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();
    jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
    jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
    for (int i = 0; i < indicesLength; i++) {
        jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return jBulletIndexedMesh;
}
 
Example 6
Source File: NativeMeshUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static long getTriangleIndexVertexArray(Mesh mesh){
    ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4);
    ByteBuffer vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4);
    int numVertices = mesh.getVertexCount();
    int vertexStride = 12; //3 verts * 4 bytes per.
    int numTriangles = mesh.getTriangleCount();
    int triangleIndexStride = 12; //3 index entries * 4 bytes each.

    IndexBuffer indices = mesh.getIndicesAsList();
    FloatBuffer vertices = mesh.getFloatBuffer(Type.Position);
    vertices.rewind();

    int verticesLength = mesh.getVertexCount() * 3;
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    for (int i = 0; i < indicesLength; i++) {
        triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride);
}
 
Example 7
Source File: Converter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static 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();
    jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per.
    for (int i = 0; i < verticesLength; i++) {
        float tempFloat = vertices.get();
        jBulletIndexedMesh.vertexBase.putFloat(tempFloat);
    }

    int indicesLength = mesh.getTriangleCount() * 3;
    jBulletIndexedMesh.numTriangles = mesh.getTriangleCount();
    jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each.
    for (int i = 0; i < indicesLength; i++) {
        jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i));
    }
    vertices.rewind();
    vertices.clear();

    return jBulletIndexedMesh;
}
 
Example 8
Source File: WrappedIndexBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void convertToList(Mesh mesh){
    IndexBuffer inBuf = mesh.getIndicesAsList();
    IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(),
                                                       inBuf.size());

    for (int i = 0; i < inBuf.size(); i++){
        outBuf.put(i, inBuf.get(i));
    }

    mesh.clearBuffer(Type.Index);
    switch (mesh.getMode()){
        case LineLoop:
        case LineStrip:
            mesh.setMode(Mode.Lines);
            break;
        case TriangleStrip:
        case TriangleFan:
            mesh.setMode(Mode.Triangles);
            break;
        default:
            break;
    }
    if (outBuf instanceof IndexIntBuffer){
        mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer());
    }else{
        mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer());
    }
}