Java Code Examples for com.jme3.scene.VertexBuffer#getFormat()
The following examples show how to use
com.jme3.scene.VertexBuffer#getFormat() .
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: 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 2
Source File: FloatToFixed.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static void compressIndexBuffer(Mesh mesh){ int vertCount = mesh.getVertexCount(); VertexBuffer vb = mesh.getBuffer(Type.Index); Format targetFmt; if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){ if (vertCount <= 256) targetFmt = Format.UnsignedByte; else targetFmt = Format.UnsignedShort; }else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){ targetFmt = Format.UnsignedByte; }else{ return; } IndexBuffer src = mesh.getIndexBuffer(); Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size()); VertexBuffer newVb = new VertexBuffer(Type.Index); newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf); mesh.clearBuffer(Type.Index); mesh.setBuffer(newVb); IndexBuffer dst = mesh.getIndexBuffer(); for (int i = 0; i < src.size(); i++){ dst.put(i, src.get(i)); } }
Example 3
Source File: FloatToFixed.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static VertexBuffer convertToFixed(VertexBuffer vb){ if (vb.getFormat() == Format.Int) return vb; FloatBuffer fb = (FloatBuffer) vb.getData(); IntBuffer ib = BufferUtils.createIntBuffer(fb.capacity()); convertToFixed(fb, ib); VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); newVb.setupData(vb.getUsage(), vb.getNumComponents(), Format.Int, ib); return newVb; }
Example 4
Source File: FloatToFixed.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static VertexBuffer convertToFloat(VertexBuffer vb){ if (vb.getFormat() == Format.Float) return vb; IntBuffer ib = (IntBuffer) vb.getData(); FloatBuffer fb = BufferUtils.createFloatBuffer(ib.capacity()); convertToFloat(ib, fb); VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); newVb.setupData(vb.getUsage(), vb.getNumComponents(), Format.Float, fb); return newVb; }
Example 5
Source File: GLRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void updateBufferData(VertexBuffer vb) { int bufId = vb.getId(); boolean created = false; if (bufId == -1) { // create buffer gl.glGenBuffers(intBuf1); bufId = intBuf1.get(0); vb.setId(bufId); objManager.registerObject(vb); //statistics.onNewVertexBuffer(); created = true; } // bind buffer int target; if (vb.getBufferType() == VertexBuffer.Type.Index) { target = GL.GL_ELEMENT_ARRAY_BUFFER; if (context.boundElementArrayVBO != bufId) { gl.glBindBuffer(target, bufId); context.boundElementArrayVBO = bufId; //statistics.onVertexBufferUse(vb, true); } else { //statistics.onVertexBufferUse(vb, false); } } else { target = GL.GL_ARRAY_BUFFER; if (context.boundArrayVBO != bufId) { gl.glBindBuffer(target, bufId); context.boundArrayVBO = bufId; //statistics.onVertexBufferUse(vb, true); } else { //statistics.onVertexBufferUse(vb, false); } } int usage = convertUsage(vb.getUsage()); vb.getData().rewind(); switch (vb.getFormat()) { case Byte: case UnsignedByte: gl.glBufferData(target, (ByteBuffer) vb.getData(), usage); break; case Short: case UnsignedShort: gl.glBufferData(target, (ShortBuffer) vb.getData(), usage); break; case Int: case UnsignedInt: glext.glBufferData(target, (IntBuffer) vb.getData(), usage); break; case Float: gl.glBufferData(target, (FloatBuffer) vb.getData(), usage); break; default: throw new UnsupportedOperationException("Unknown buffer format."); } vb.clearUpdateNeeded(); }
Example 6
Source File: LodGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private VertexBuffer makeLod(Mesh mesh) { VertexBuffer indexBuffer = mesh.getBuffer(VertexBuffer.Type.Index); boolean isShortBuffer = indexBuffer.getFormat() == VertexBuffer.Format.UnsignedShort; // Create buffers. VertexBuffer lodBuffer = new VertexBuffer(VertexBuffer.Type.Index); int bufsize = indexCount == 0 ? 3 : indexCount; if (isShortBuffer) { lodBuffer.setupData(VertexBuffer.Usage.Static, 3, VertexBuffer.Format.UnsignedShort, BufferUtils.createShortBuffer(bufsize)); } else { lodBuffer.setupData(VertexBuffer.Usage.Static, 3, VertexBuffer.Format.UnsignedInt, BufferUtils.createIntBuffer(bufsize)); } lodBuffer.getData().rewind(); //Check if we should fill it with a "dummy" triangle. if (indexCount == 0) { if (isShortBuffer) { for (int m = 0; m < 3; m++) { ((ShortBuffer) lodBuffer.getData()).put((short) 0); } } else { for (int m = 0; m < 3; m++) { ((IntBuffer) lodBuffer.getData()).put(0); } } } // Fill buffers. Buffer buf = lodBuffer.getData(); buf.rewind(); for (Triangle triangle : triangleList) { if (!triangle.isRemoved) { // assert (indexCount != 0); if (isShortBuffer) { for (int m = 0; m < 3; m++) { ((ShortBuffer) buf).put((short) triangle.vertexId[m]); } } else { for (int m = 0; m < 3; m++) { ((IntBuffer) buf).put(triangle.vertexId[m]); } } } } buf.clear(); lodBuffer.updateData(buf); return lodBuffer; }