Java Code Examples for com.badlogic.gdx.graphics.Mesh#setVertices()
The following examples show how to use
com.badlogic.gdx.graphics.Mesh#setVertices() .
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: Terrain.java From Mundus with Apache License 2.0 | 6 votes |
public void init() { final int numVertices = this.vertexResolution * vertexResolution; final int numIndices = (this.vertexResolution - 1) * (vertexResolution - 1) * 6; mesh = new Mesh(true, numVertices, numIndices, attribs); this.vertices = new float[numVertices * stride]; mesh.setIndices(buildIndices()); buildVertices(); mesh.setVertices(vertices); MeshPart meshPart = new MeshPart(null, mesh, 0, numIndices, GL20.GL_TRIANGLES); meshPart.update(); ModelBuilder mb = new ModelBuilder(); mb.begin(); mb.part(meshPart, material); model = mb.end(); modelInstance = new ModelInstance(model); modelInstance.transform = transform; }
Example 2
Source File: Main.java From graphicsfuzz with Apache License 2.0 | 5 votes |
private Mesh buildMeshFromVertices(List<Double> vertexCoords) { if ((vertexCoords.size() % 3) != 0) { throw new RuntimeException("Vertex coordinates size is " + vertexCoords.size() + "; must be a multiple of 3"); } float[] data = new float[vertexCoords.size()]; for (int i = 0; i < vertexCoords.size(); i++) { data[i] = (float) vertexCoords.get(i).doubleValue(); } Mesh mesh = new Mesh( true, vertexCoords.size() / 3, 0, new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); mesh.setVertices(data); return mesh; }
Example 3
Source File: Main.java From graphicsfuzz with Apache License 2.0 | 5 votes |
private Mesh buildMeshFromVerticesAndTexCoords(List<Double> vertexCoords, List<Double> texCoords) { if ((vertexCoords.size() % 3) != 0) { throw new RuntimeException("Vertex coordinates size is " + vertexCoords.size() + "; must be a multiple of 3"); } if ((texCoords.size() % 2) != 0) { throw new RuntimeException("Texture coordinates size is " + texCoords.size() + "; must be a multiple of 2"); } if (vertexCoords.size() / 3 != texCoords.size() / 2) { throw new RuntimeException("There is vertex data for " + vertexCoords.size() / 3 + " triangle(s), " + "and texture data for " + texCoords.size() / 2 + " triangle(s) -- these should match"); } float[] data = new float[vertexCoords.size() + texCoords.size()]; int vertexIndex = 0; int texIndex = 0; int dataIndex = 0; for (int i = 0; i < vertexCoords.size() / 3; i++) { data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue(); data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue(); data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue(); data[dataIndex++] = (float) texCoords.get(texIndex++).doubleValue(); data[dataIndex++] = (float) texCoords.get(texIndex++).doubleValue(); } Mesh mesh = new Mesh( true, vertexCoords.size() / 3, 0, new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(data); return mesh; }
Example 4
Source File: FullscreenQuad.java From uracer-kotd with Apache License 2.0 | 5 votes |
private Mesh createFullscreenQuad () { // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0")); tmpMesh.setVertices(verts); return tmpMesh; }
Example 5
Source File: GameWorldRenderer.java From uracer-kotd with Apache License 2.0 | 5 votes |
private void createBackPlane () { plane = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); // @formatter:off float size = 10f; float verts[] = {-size / 2, 0, size / 2, size / 2, 0, size / 2, size / 2, 0, -size / 2, -size / 2, 0, -size / 2}; // float verts[] = {size, 0, size, size, 0, 0, 0, 0, 0, 0, 0, size}; float normals[] = {0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0}; // @formatter:on int vidx = 0, nidx = 0; int length = 6 * 4; float[] vertices = new float[length]; for (int i = 0; i < length;) { vertices[i++] = verts[vidx++]; vertices[i++] = verts[vidx++]; vertices[i++] = verts[vidx++]; vertices[i++] = normals[nidx++]; vertices[i++] = normals[nidx++]; vertices[i++] = normals[nidx++]; } plane.setVertices(vertices); plane.setIndices(new short[] {0, 1, 2, 3}); }
Example 6
Source File: LightMap.java From uracer-kotd with Apache License 2.0 | 5 votes |
private Mesh createLightMapMesh() { // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh( true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ), new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoord" ) ); tmpMesh.setVertices( verts ); return tmpMesh; }
Example 7
Source File: LightMap.java From box2dlights with Apache License 2.0 | 5 votes |
private Mesh createLightMapMesh() { float[] verts = new float[VERT_SIZE]; // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh(true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position"), new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoord")); tmpMesh.setVertices(verts); return tmpMesh; }
Example 8
Source File: SunRenderer.java From Cubes with MIT License | 5 votes |
private SunRenderer(boolean moon) { this.moon = moon; String texturePath = moon ? moonTexturePath : sunTexturePath; material = Assets.getMaterial(texturePath); textureRegion = Assets.getTextureRegion(texturePath); indices = new short[6]; short j = 0; for (int i = 0; i < indices.length; i += 6, j += 4) { indices[i + 0] = (short) (j + 0); indices[i + 1] = (short) (j + 1); indices[i + 2] = (short) (j + 2); indices[i + 3] = (short) (j + 2); indices[i + 4] = (short) (j + 3); indices[i + 5] = (short) (j + 0); } vertices = new float[CubesVertexAttributes.COMPONENTS * 4]; mesh = new Mesh(false, 4, 6, CubesVertexAttributes.VERTEX_ATTRIBUTES); mesh.setIndices(indices); FaceVertices.createMinY(new Vector3(-0.5f, 0f, -0.5f), textureRegion, null, 0, 0, 0, FULL_LIGHT, vertices, 0); mesh.setVertices(vertices); renderable = new CubesRenderable(); renderable.meshPart.primitiveType = GL20.GL_TRIANGLES; renderable.meshPart.offset = 0; renderable.meshPart.size = 6; renderable.meshPart.mesh = mesh; renderable.material = material; renderable.setFogEnabled(false); }
Example 9
Source File: FullscreenQuad.java From RuinsOfRevenge with MIT License | 5 votes |
private Mesh createFullscreenQuad() { // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh( VertexDataType.VertexArray, true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ), new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoord0" ) ); tmpMesh.setVertices( verts ); return tmpMesh; }
Example 10
Source File: ViewportQuadMesh.java From gdx-vfx with Apache License 2.0 | 4 votes |
public ViewportQuadMesh(VertexAttribute... vertexAttributes) { mesh = new Mesh(true, 4, 0, vertexAttributes); mesh.setVertices(verts); }
Example 11
Source File: G3dtLoader.java From uracer-kotd with Apache License 2.0 | 4 votes |
private static StillSubMesh readStillSubMesh (BufferedReader in, boolean flipV) throws IOException { String name = readString(in); IntArray indices = readFaces(in); int numVertices = readInt(in); int numAttributes = readInt(in); if (!readString(in).equals("position")) throw new GdxRuntimeException("first attribute must be position."); int numUvs = 0; boolean hasNormals = false; for (int i = 1; i < numAttributes; i++) { String attributeType = readString(in); if (!attributeType.equals("normal") && !attributeType.equals("uv")) throw new GdxRuntimeException("attribute name must be normal or uv"); if (attributeType.equals("normal")) { if (i != 1) throw new GdxRuntimeException("attribute normal must be second attribute"); hasNormals = true; } if (attributeType.equals("uv")) { numUvs++; } } VertexAttribute[] vertexAttributes = createVertexAttributes(hasNormals, numUvs); int vertexSize = new VertexAttributes(vertexAttributes).vertexSize / 4; float[] vertices = new float[numVertices * vertexSize]; int idx = 0; int uvOffset = hasNormals ? 6 : 3; for (int i = 0; i < numVertices; i++) { readFloatArray(in, vertices, idx); if (flipV) { for (int j = idx + uvOffset + 1; j < idx + uvOffset + numUvs * 2; j += 2) { vertices[j] = 1 - vertices[j]; } } idx += vertexSize; } Mesh mesh = new Mesh(true, numVertices, indices.size, vertexAttributes); mesh.setVertices(vertices); mesh.setIndices(convertToShortArray(indices)); return new StillSubMesh(name, mesh, GL20.GL_TRIANGLES); }