Java Code Examples for com.jme3.scene.Mesh#getBuffers()
The following examples show how to use
com.jme3.scene.Mesh#getBuffers() .
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: MeshTreeNode.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) { final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class); final Mesh element = getElement(); final IntMap<VertexBuffer> buffers = element.getBuffers(); buffers.forEach(entry -> result.add(FACTORY_REGISTRY.createFor(entry.getValue()))); return result; }
Example 2
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void renderMeshDefault(Mesh mesh, int lod, int count) { VertexBuffer indices = null; VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); IntMap<VertexBuffer> buffers = mesh.getBuffers(); if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = buffers.get(Type.Index.ordinal()); } for (Entry<VertexBuffer> entry : buffers) { VertexBuffer vb = entry.getValue(); if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly) // ignore cpu-only buffers { continue; } if (vb.getBufferType() == Type.Index) { indices = vb; } else { if (vb.getStride() == 0) { // not interleaved setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } } } if (indices != null) { drawTriangleList(indices, mesh, count); } else { gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); } clearVertexAttribs(); clearTextureUnits(); }
Example 3
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void renderMeshVBO(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(); if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = buffers.get(Type.Index.ordinal()); } 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 setVertexAttribVBO(vb, null); } else { // interleaved setVertexAttribVBO(vb, interleavedData); } } if (indices != null) { drawTriangleListVBO(indices, mesh, count); } else { gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); } clearVertexAttribs(); clearTextureUnits(); }
Example 4
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void renderMesh(Mesh mesh, int lod, int count) { if (mesh.getVertexCount() == 0) return; if (context.pointSize != mesh.getPointSize()) { gl.glPointSize(mesh.getPointSize()); context.pointSize = mesh.getPointSize(); } if (context.lineWidth != mesh.getLineWidth()) { gl.glLineWidth(mesh.getLineWidth()); context.lineWidth = mesh.getLineWidth(); } checkTexturingUsed(); if (vbo) { renderMeshVBO(mesh, lod, count); } else { boolean dynamic = false; if (mesh.getNumLodLevels() == 0) { IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (Entry<VertexBuffer> entry : bufs) { if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) { dynamic = true; break; } } } else { dynamic = true; } if (!dynamic) { // dealing with a static object, generate display list renderMeshDisplayList(mesh); } else { renderMeshDefault(mesh, lod, count); } } }
Example 5
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void renderMesh(Mesh mesh, int lod, int count) { GL gl = GLContext.getCurrentGL(); if (context.pointSize != mesh.getPointSize()) { gl.getGL2().glPointSize(mesh.getPointSize()); context.pointSize = mesh.getPointSize(); } if (context.lineWidth != mesh.getLineWidth()) { gl.glLineWidth(mesh.getLineWidth()); context.lineWidth = mesh.getLineWidth(); } checkTexturingUsed(); if (vbo) { renderMeshVBO(mesh, lod, count); } else { boolean dynamic = false; if (mesh.getNumLodLevels() == 0) { IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (Entry<VertexBuffer> entry : bufs) { if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) { dynamic = true; break; } } } else { dynamic = true; } if (!dynamic) { // dealing with a static object, generate display list renderMeshDisplayList(mesh); } else { renderMeshDefault(mesh, lod, count); } } }
Example 6
Source File: LwjglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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 7
Source File: ModelConverter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static void optimize(Mesh mesh, boolean toFixed){ // update any data that need updating mesh.updateBound(); mesh.updateCounts(); // set all buffers into STATIC_DRAW mode mesh.setStatic(); if (mesh.getBuffer(Type.Index) != null){ // compress index buffer from UShort to UByte (if possible) FloatToFixed.compressIndexBuffer(mesh); // generate triangle strips stitched with degenerate tris generateStrips(mesh, false, false, 16, 0); } IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (Entry<VertexBuffer> entry : bufs){ VertexBuffer vb = entry.getValue(); if (vb == null || vb.getBufferType() == Type.Index) continue; if (vb.getFormat() == Format.Float){ if (vb.getBufferType() == Type.Color){ // convert the color buffer to UByte vb = FloatToFixed.convertToUByte(vb); vb.setNormalized(true); }else if (toFixed){ // convert normals, positions, and texcoords // to fixed-point (16.16) vb = FloatToFixed.convertToFixed(vb); // vb = FloatToFixed.convertToFloat(vb); } mesh.clearBuffer(vb.getBufferType()); mesh.setBuffer(vb); } } mesh.setInterleaved(); }
Example 8
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Preloads a scene for rendering. * <p> * After invocation of this method, the underlying * renderer would have uploaded any textures, shaders and meshes * used by the given scene to the video driver. * Using this method is useful when wishing to avoid the initial pause * when rendering a scene for the first time. Note that it is not * guaranteed that the underlying renderer will actually choose to upload * the data to the GPU so some pause is still to be expected. * * @param scene The scene to preload */ public void preloadScene(Spatial scene) { if (scene instanceof Node) { // recurse for all children Node n = (Node) scene; List<Spatial> children = n.getChildren(); for (int i = 0; i < children.size(); i++) { preloadScene(children.get(i)); } } else if (scene instanceof Geometry) { // add to the render queue Geometry gm = (Geometry) scene; if (gm.getMaterial() == null) { throw new IllegalStateException("No material is set for Geometry: " + gm.getName()); } gm.getMaterial().preload(this); Mesh mesh = gm.getMesh(); if (mesh != null) { for (Entry<VertexBuffer> entry : mesh.getBuffers()) { VertexBuffer buf = entry.getValue(); if (buf.getData() != null) { renderer.updateBufferData(buf); } } } } }
Example 9
Source File: GdxRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * renderMeshVertexArray renders a mesh using vertex arrays * @param mesh * @param lod * @param count */ private void renderMeshVertexArray(Mesh mesh, int lod, int count) { if (verboseLogging) { logger.info("renderMeshVertexArray"); } // IntMap<VertexBuffer> buffers = mesh.getBuffers(); IntMap<VertexBuffer> buffers = mesh.getBuffers(); IntMap.Entry<VertexBuffer> table[] = buffers.getTable(); for (IntMap.Entry<VertexBuffer> entry : table) { if (entry == null) { continue; } 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_Array(vb); } else { // interleaved VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); setVertexAttrib_Array(vb, interleavedData); } } VertexBuffer indices = null; if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal()); } clearVertexAttribs(); // clearTextureUnits(); if (indices != null) { drawTriangleList_Array(indices, mesh, count); } else { if (verboseLogging) { logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})", new Object[]{mesh.getMode(), 0, mesh.getVertexCount()}); } Gdx.gl20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); } }
Example 10
Source File: OGLESShaderRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * renderMeshVertexArray renders a mesh using vertex arrays * @param mesh * @param lod * @param count */ private void renderMeshVertexArray(Mesh mesh, int lod, int count) { if (verboseLogging) { logger.info("renderMeshVertexArray"); } // IntMap<VertexBuffer> buffers = mesh.getBuffers(); IntMap<VertexBuffer> buffers = mesh.getBuffers(); IntMap.Entry<VertexBuffer> table[] = buffers.getTable(); for (IntMap.Entry<VertexBuffer> entry : table) { if (entry == null) { continue; } 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_Array(vb); } else { // interleaved VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); setVertexAttrib_Array(vb, interleavedData); } } VertexBuffer indices = null; if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal()); } clearVertexAttribs(); // clearTextureUnits(); if (indices != null) { drawTriangleList_Array(indices, mesh, count); } else { if (verboseLogging) { logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})", new Object[]{mesh.getMode(), 0, mesh.getVertexCount()}); } GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); } }
Example 11
Source File: AbstractRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
protected 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(); if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = buffers.get(Type.Index.ordinal()); } for (Entry<VertexBuffer> entry : buffers) { VertexBuffer vb = entry.getValue(); if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly || vb.getBufferType() == Type.Index) { continue; } /*if (vb.getBufferType() == Type.Index) { indices = vb; } else {*/ if (vb.getStride() == 0) { // not interleaved setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } /*}*/ } if (indices != null) { drawTriangleList(indices, mesh, count); } else { drawArrays(mesh); } clearVertexAttribs(); clearTextureUnits(); }
Example 12
Source File: AbstractRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
protected void renderMeshVBO(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(); if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = buffers.get(Type.Index.ordinal()); } 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 setVertexAttribVBO(vb, null); } else { // interleaved setVertexAttribVBO(vb, interleavedData); } } if (indices != null) { drawTriangleListVBO(indices, mesh, count); } else { drawArrays(mesh); } clearVertexAttribs(); clearTextureUnits(); }