Java Code Examples for com.badlogic.gdx.graphics.Mesh#setIndices()

The following examples show how to use com.badlogic.gdx.graphics.Mesh#setIndices() . 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 vote down vote up
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: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
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 3
Source File: RainRenderer.java    From Cubes with MIT License 5 votes vote down vote up
private RainMesh() {
  mesh = new Mesh(true, MAX_VERTICES, MAX_INDICES, VERTEX_ATTRIBUTES);
  meshPart = new MeshPart();
  meshPart.mesh = mesh;
  meshPart.primitiveType = GL20.GL_TRIANGLES;
  meshPart.offset = 0;
  mesh.setIndices(indices);
}
 
Example 4
Source File: SunRenderer.java    From Cubes with MIT License 5 votes vote down vote up
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 5
Source File: AreaMesh.java    From Cubes with MIT License 5 votes vote down vote up
public AreaMesh(VertexAttributes vertexAttributes) {
  mesh = new Mesh(true, MAX_VERTICES, MAX_INDICES, vertexAttributes);
  meshPart = new MeshPart();
  meshPart.mesh = mesh;
  meshPart.primitiveType = GL20.GL_TRIANGLES;
  meshPart.offset = 0;
  mesh.setIndices(indices);

  int components = CubesVertexAttributes.components(vertexAttributes);
  maxVertexOffset = MAX_VERTICES * components;

  renderable.material = Assets.blockItemSheet.getMaterial();
  renderable.name = "AreaMesh";
}
 
Example 6
Source File: G3dtLoader.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
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);
}