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

The following examples show how to use com.jme3.scene.Mesh#getBufferList() . 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: GeometryOptimizer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void optimize2() {
    for(Mesh mesh : meshSet) {
        mesh.setInterleaved();
        for(VertexBuffer vb : mesh.getBufferList()) {
            System.out.println(
                    "type = "+vb.getBufferType()
                    + "stride = "+vb.getStride()
                    + "offset "+vb.getOffset()
                    );
            
        }
        System.out.println("done");
    }
}
 
Example 2
Source File: GeometryOptimizer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
int calcInterleavedSize() {
        interleavedSize = 0;
        for(Mesh mesh : meshSet) {
            for(VertexBuffer vb : mesh.getBufferList()) {
                if (vb.getBufferType().equals(VertexBuffer.Type.Index)
                        || vb.getBufferType().equals(VertexBuffer.Type.InterleavedData)){
                    continue;
                }
                int limit = vb.getData().capacity();
//                interleavedSize += vb.getComponentsLength() * vb.get
                interleavedSize += limit * vb.getFormat().getComponentSize();
            }
        }
        return interleavedSize;
    }
 
Example 3
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    logger.log(Level.INFO, "updateVertexArray({0})", mesh);
    int id = mesh.getId();
    /*
    if (id == -1){
    IntBuffer temp = intBuf1;
    //      ARBVertexArrayObject.glGenVertexArrays(temp);
    GLES20.glGenVertexArrays(temp);
    id = temp.get(0);
    mesh.setId(id);
    }
    
    if (context.boundVertexArray != id){
    //     ARBVertexArrayObject.glBindVertexArray(id);
    GLES20.glBindVertexArray(id);
    context.boundVertexArray = id;
    }
     */
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
    for (int i = 0; i < buffersList.size(); i++) {
        VertexBuffer vb = buffersList.get(i);

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        } else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
    }
}
 
Example 4
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.log(Level.INFO, "renderMeshDefault({0}, {1}, {2})",
                    new Object[]{mesh, lod, count});
        }
        VertexBuffer indices = null;

        VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
        if (interleavedData != null && interleavedData.isUpdateNeeded()) {
            updateBufferData(interleavedData);
        }

        //IntMap<VertexBuffer> buffers = mesh.getBuffers();     ;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);// buffers.get(Type.Index.ordinal());
        }
        SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
        for (int i = 0; i < buffersList.size(); i++) {
            VertexBuffer vb = buffersList.get(i);

            if (vb.getBufferType() == Type.InterleavedData
                    || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                    || vb.getBufferType() == Type.Index) {
                continue;
            }

            if (vb.getStride() == 0) {
                // not interleaved
                setVertexAttrib(vb);
            } else {
                // interleaved
                setVertexAttrib(vb, interleavedData);
            }
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
//            throw new UnsupportedOperationException("Cannot render without index buffer");
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, 0, {1})",
                        new Object[]{convertElementMode(mesh.getMode()), mesh.getVertexCount()});
            }

            Gdx.gl20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 5
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    logger.log(Level.INFO, "updateVertexArray({0})", mesh);
    int id = mesh.getId();
    /*
    if (id == -1){
    IntBuffer temp = intBuf1;
    //      ARBVertexArrayObject.glGenVertexArrays(temp);
    GLES20.glGenVertexArrays(temp);
    id = temp.get(0);
    mesh.setId(id);
    }
    
    if (context.boundVertexArray != id){
    //     ARBVertexArrayObject.glBindVertexArray(id);
    GLES20.glBindVertexArray(id);
    context.boundVertexArray = id;
    }
     */
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
    for (int i = 0; i < buffersList.size(); i++) {
        VertexBuffer vb = buffersList.get(i);

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        } else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
    }
}
 
Example 6
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.log(Level.INFO, "renderMeshDefault({0}, {1}, {2})",
                    new Object[]{mesh, lod, count});
        }
        VertexBuffer indices = null;

        VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
        if (interleavedData != null && interleavedData.isUpdateNeeded()) {
            updateBufferData(interleavedData);
        }

        //IntMap<VertexBuffer> buffers = mesh.getBuffers();     ;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);// buffers.get(Type.Index.ordinal());
        }
        SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
        for (int i = 0; i < buffersList.size(); i++) {
            VertexBuffer vb = buffersList.get(i);

            if (vb.getBufferType() == Type.InterleavedData
                    || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                    || vb.getBufferType() == Type.Index) {
                continue;
            }

            if (vb.getStride() == 0) {
                // not interleaved
                setVertexAttrib(vb);
            } else {
                // interleaved
                setVertexAttrib(vb, interleavedData);
            }
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
//            throw new UnsupportedOperationException("Cannot render without index buffer");
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, 0, {1})",
                        new Object[]{convertElementMode(mesh.getMode()), mesh.getVertexCount()});
            }

            GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 7
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;

    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    //IntMap<VertexBuffer> buffers = mesh.getBuffers();
    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();

    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    } else {
        indices = mesh.getBuffer(Type.Index);
    }
    //for (Entry<VertexBuffer> entry : buffers) {
    //     VertexBuffer vb = entry.getValue();
    for (int i = 0; i < buffersList.size(); i++){
        VertexBuffer vb = buffersList.get(i);

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        } else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
    }

    if (indices != null) {
        drawTriangleList(indices, mesh, count);
    } else {
        drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
    }
    clearVertexAttribs();
    clearTextureUnits();
}