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

The following examples show how to use com.jme3.scene.Mesh#getId() . 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: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void renderMeshVertexArray(Mesh mesh, int lod, int count, VertexBuffer instanceData) {
        if (mesh.getId() == -1) {
            updateVertexArray(mesh, instanceData);
        } else {
            // TODO: Check if it was updated
        }

        if (context.boundVertexArray != mesh.getId()) {
            gl3.glBindVertexArray(mesh.getId());
            context.boundVertexArray = mesh.getId();
        }

//        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        VertexBuffer indices;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);
        }
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
            drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
        }
        clearVertexAttribs();
    }
 
Example 2
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateDisplayList(Mesh mesh) {
    if (mesh.getId() != -1) {
        // delete list first
        gl.glDeleteLists(mesh.getId(), mesh.getId());
        mesh.setId(-1);
    }

    // create new display list
    // first set state to NULL
    applyRenderState(RenderState.NULL);

    // disable lighting
    setLighting(null);

    int id = gl.glGenLists(1);
    mesh.setId(id);
    gl.glNewList(id, gl.GL_COMPILE);
    renderMeshDefault(mesh, 0, 1);
    gl.glEndList();
}
 
Example 3
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateDisplayList(Mesh mesh) {
    GL gl = GLContext.getCurrentGL();
    if (mesh.getId() != -1) {
        // delete list first
        gl.getGL2().glDeleteLists(mesh.getId(), mesh.getId());
        mesh.setId(-1);
    }

    // create new display list
    // first set state to NULL
    applyRenderState(RenderState.NULL);

    // disable lighting
    setLighting(null);

    int id = gl.getGL2().glGenLists(1);
    mesh.setId(id);
    gl.getGL2().glNewList(id, GL2.GL_COMPILE);
    renderMeshDefault(mesh, 0, 1);
    gl.getGL2().glEndList();
}
 
Example 4
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void updateVertexArray(Mesh mesh, VertexBuffer instanceData) {
    int id = mesh.getId();
    if (id == -1) {
        IntBuffer temp = intBuf1;
        gl3.glGenVertexArrays(temp);
        id = temp.get(0);
        mesh.setId(id);
    }

    if (context.boundVertexArray != id) {
        gl3.glBindVertexArray(id);
        context.boundVertexArray = id;
    }

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

    if (instanceData != null) {
        setVertexAttrib(instanceData, null);
    }

    for (VertexBuffer vb : mesh.getBufferList().getArray()) {
        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 5
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    int id = mesh.getId();
    if (id == -1) {
        IntBuffer temp = intBuf1;
        ARBVertexArrayObject.glGenVertexArrays(temp);
        id = temp.get(0);
        mesh.setId(id);
    }

    if (context.boundVertexArray != id) {
        ARBVertexArrayObject.glBindVertexArray(id);
        context.boundVertexArray = id;
    }

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

    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        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: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
        if (mesh.getId() == -1){
            updateVertexArray(mesh);
        }else{
            // TODO: Check if it was updated
        }

        if (context.boundVertexArray != mesh.getId()) {
            ARBVertexArrayObject.glBindVertexArray(mesh.getId());
            context.boundVertexArray = mesh.getId();
        }

//        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        VertexBuffer indices = null;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);
        }
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
            drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
        }
        clearVertexAttribs();
        clearTextureUnits();
    }
 
Example 7
Source File: MeshPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent, @NotNull final VBox container,
                            @NotNull final ModelChangeConsumer changeConsumer) {

    if (!(object instanceof Mesh)) return;

    final Mesh mesh = (Mesh) object;
    final Mesh.Mode mode = mesh.getMode();

    final int id = mesh.getId();
    final int instanceCount = mesh.getInstanceCount();
    final int vertexCount = mesh.getVertexCount();
    final int numLodLevels = mesh.getNumLodLevels();
    final int triangleCount = mesh.getTriangleCount();

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> idControl =
            new DefaultSinglePropertyControl<>(id, Messages.MODEL_PROPERTY_ID, changeConsumer);

    idControl.setSyncHandler(Mesh::getId);
    idControl.setToStringFunction(value -> Integer.toString(value));
    idControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> instanceCountControl =
            new DefaultSinglePropertyControl<>(instanceCount, Messages.MODEL_PROPERTY_INSTANCE_COUNT, changeConsumer);

    instanceCountControl.setSyncHandler(Mesh::getInstanceCount);
    instanceCountControl.setToStringFunction(value -> Integer.toString(value));
    instanceCountControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> vertexCountControl =
            new DefaultSinglePropertyControl<>(vertexCount, Messages.MODEL_PROPERTY_VERTEX_COUNT, changeConsumer);

    vertexCountControl.setSyncHandler(Mesh::getVertexCount);
    vertexCountControl.setToStringFunction(value -> Integer.toString(value));
    vertexCountControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> triangleCountControl =
            new DefaultSinglePropertyControl<>(triangleCount, Messages.MODEL_PROPERTY_TRIANGLE_COUNT, changeConsumer);

    triangleCountControl.setSyncHandler(Mesh::getTriangleCount);
    triangleCountControl.setToStringFunction(value -> Integer.toString(value));
    triangleCountControl.setEditObject(mesh);

    final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> numLodLevelsControl =
            new DefaultSinglePropertyControl<>(numLodLevels, Messages.MODEL_PROPERTY_NUM_LOD_LEVELS, changeConsumer);

    numLodLevelsControl.setSyncHandler(Mesh::getNumLodLevels);
    numLodLevelsControl.setToStringFunction(value -> Integer.toString(value));
    numLodLevelsControl.setEditObject(mesh);

    final EnumPropertyControl<ModelChangeConsumer, Mesh, Mesh.Mode> modeControl =
            new EnumPropertyControl<>(mode, Messages.MODEL_PROPERTY_MODE, changeConsumer, MODES);
    modeControl.setApplyHandler(Mesh::setMode);
    modeControl.setSyncHandler(Mesh::getMode);
    modeControl.setEditObject(mesh);

    FXUtils.addToPane(idControl, container);
    FXUtils.addToPane(instanceCountControl, container);
    FXUtils.addToPane(vertexCountControl, container);
    FXUtils.addToPane(triangleCountControl, container);
    FXUtils.addToPane(numLodLevelsControl, container);
    FXUtils.addToPane(modeControl, container);
}
 
Example 8
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 9
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDisplayList(Mesh mesh) {
    if (mesh.getId() == -1) {
        updateDisplayList(mesh);
    }
    gl.glCallList(mesh.getId());
}
 
Example 10
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 11
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderMeshDisplayList(Mesh mesh) {
    if (mesh.getId() == -1) {
        updateDisplayList(mesh);
    }
    GLContext.getCurrentGL().getGL2().glCallList(mesh.getId());
}