List of usage examples for com.badlogic.gdx.graphics Mesh getIndicesBuffer
public ShortBuffer getIndicesBuffer()
From source file:com.badlogic.gdx.physics.bullet.demo.simulationobjects.MeshSimulationObject.java
public static btBvhTriangleMeshShape createTriangleMeshShape(Mesh mesh, AtomicReference<btTriangleMesh> triangleMesh) { final btTriangleMesh m = new btTriangleMesh(); final ShortBuffer indices = mesh.getIndicesBuffer(); indices.rewind();//from w w w. j a va2 s . co m final FloatBuffer vertices = mesh.getVerticesBuffer(); vertices.rewind(); // Some meshes have vertices but no indices declared final boolean hasIndices = mesh.getNumIndices() != 0; final int vertexStride = mesh.getVertexSize() / 4; final Vector3 v0 = Pools.VECTOR3.obtain(); final Vector3 v1 = Pools.VECTOR3.obtain(); final Vector3 v2 = Pools.VECTOR3.obtain(); // Set up a small array to keep the loop code simpler final Vector3[] vectors = new Vector3[] { v0, v1, v2 }; short vectorIndex = 0; int i = -1; int verticesRead = 0; while (verticesRead < mesh.getNumVertices()) { if (hasIndices) { i = indices.get(); } else { i++; } vectors[vectorIndex++].set(vertices.get(i * vertexStride), vertices.get(i * vertexStride + 1), vertices.get(i * vertexStride + 2)); if (vectorIndex == vectors.length) { m.addTriangle(v0, v1, v2, true); vectorIndex = 0; } verticesRead++; } Pools.VECTOR3.free(v0); Pools.VECTOR3.free(v1); Pools.VECTOR3.free(v2); triangleMesh.set(m); return new btBvhTriangleMeshShape(m, true); }
From source file:com.doom.render.QuadBatch.java
License:Apache License
@Override public void flush() { if (idx == 0) return;/*from w w w. ja v a2 s . com*/ renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
From source file:graphics.widgets.WidgetsPass.java
License:Open Source License
public void flush() { if (idx == 0 || lastTexture == null) return;/*from ww w. ja va 2s . com*/ int spritesInBatch = idx / 20; int count = spritesInBatch * 6; lastTexture.bind(0); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc); } mesh.render(shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.DebugObject.java
License:Apache License
public static void debugMesh(Mesh mesh) { int numVertices = mesh.getNumVertices(); int numIndices = mesh.getNumIndices(); ShortBuffer indicesBuffer = mesh.getIndicesBuffer(); FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); S3Log.log("debugMesh", "NumVertices: " + numVertices); S3Log.log("debugMesh", "NumIndices: " + numIndices); S3Log.log("debugMesh", "vertexSize (bytes): " + mesh.getVertexSize()); S3Log.log("debugMesh", "Indices Buffer:", 1); StringBuilder buffer = new StringBuilder(32); buffer.append('['); buffer.append(indicesBuffer.get(0)); for (int i = 1; i < numIndices; i++) { buffer.append(", "); buffer.append(indicesBuffer.get(i)); }/*from w ww .j a va 2s . com*/ buffer.append(']'); S3Log.log("debugMesh", buffer.toString()); S3Log.log("debugMesh", "Vertices Buffer:", 1); StringBuilder buffer2 = new StringBuilder(32); buffer2.append('['); buffer2.append(verticesBuffer.get(0)); for (int i = 1; i < numIndices; i++) { buffer2.append(", "); buffer2.append(verticesBuffer.get(i)); } buffer.append(']'); S3Log.log("debugMesh", buffer2.toString()); }
From source file:org.interreg.docexplore.reader.gfx.GfxUtils.java
License:Open Source License
public static Mesh buildQuad(float x1, float y1, float s1, float t1, float x2, float y2, float s2, float t2) { Mesh mesh = new Mesh(false, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, "p"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "tc")); FloatBuffer vertexBuffer = mesh.getVerticesBuffer(); vertexBuffer.limit(vertexBuffer.capacity()); vertexBuffer.put(x1).put(y1).put(0).put(s1).put(t1).put(x2).put(y1).put(0).put(s2).put(t1).put(x2).put(y2) .put(0).put(s2).put(t2).put(x1).put(y2).put(0).put(s1).put(t2).flip(); ShortBuffer indexBuffer = mesh.getIndicesBuffer(); indexBuffer.limit(indexBuffer.capacity()); indexBuffer.put(new short[] { 0, 1, 2, 0, 2, 3 }).flip(); return mesh;/*from www .ja va 2 s .c o m*/ }