com.badlogic.gdx.graphics.g3d.utils.MeshBuilder Java Examples
The following examples show how to use
com.badlogic.gdx.graphics.g3d.utils.MeshBuilder.
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: NormalBlockRenderer.java From Radix with MIT License | 6 votes |
@Override public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // POSITIVE Z float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); c00.setPos(x1, y1, z).setNor(0, 0, 1); c01.setPos(x1, y2, z).setNor(0, 0, 1); c10.setPos(x2, y1, z).setNor(0, 0, 1); c11.setPos(x2, y2, z).setNor(0, 0, 1); Color c = getColor((int) x1, (int) y1, (int) z - 1); if(pcld == null) { builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a); } else { c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a); c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a); c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a); c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a); } builder.rect(c00, c10, c11, c01); }
Example #2
Source File: Terrain.java From Mundus with Apache License 2.0 | 6 votes |
private Terrain(int vertexResolution) { this.transform = new Matrix4(); this.attribs = MeshBuilder.createAttributes(VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates); this.posPos = attribs.getOffset(VertexAttributes.Usage.Position, -1); this.norPos = attribs.getOffset(VertexAttributes.Usage.Normal, -1); this.uvPos = attribs.getOffset(VertexAttributes.Usage.TextureCoordinates, -1); this.stride = attribs.vertexSize / 4; this.vertexResolution = vertexResolution; this.heightData = new float[vertexResolution * vertexResolution]; this.terrainTexture = new TerrainTexture(); this.terrainTexture.setTerrain(this); material = new Material(); material.set(new TerrainTextureAttribute(TerrainTextureAttribute.ATTRIBUTE_SPLAT0, terrainTexture)); }
Example #3
Source File: GreedyMesher.java From Radix with MIT License | 6 votes |
public void render(MeshBuilder builder) { BlockRenderer renderer = block.getRenderer(); switch (side) { case TOP: renderer.renderTop(block.getTextureIndex(), x1, y1, x2, y2, z + 1, lightLevel, pcld, builder); break; case BOTTOM: renderer.renderBottom(block.getTextureIndex(), x1, y1, x2, y2, z, lightLevel, pcld, builder); break; case NORTH: renderer.renderNorth(block.getTextureIndex(), x1, y1, x2, y2, z + 1, lightLevel, pcld, builder); break; case SOUTH: renderer.renderSouth(block.getTextureIndex(), x1, y1, x2, y2, z, lightLevel, pcld, builder); break; case EAST: renderer.renderEast(block.getTextureIndex(), x1, y1, x2, y2, z + 1, lightLevel, pcld, builder); break; case WEST: renderer.renderWest(block.getTextureIndex(), x1, y1, x2, y2, z, lightLevel, pcld, builder); break; } }
Example #4
Source File: NormalBlockRenderer.java From Radix with MIT License | 6 votes |
@Override public void renderBottom(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // NEGATIVE Y float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); c00.setPos(x1, y, z1).setNor(0, -1, 0); c01.setPos(x1, y, z2).setNor(0, -1, 0); c10.setPos(x2, y, z1).setNor(0, -1, 0); c11.setPos(x2, y, z2).setNor(0, -1, 0); Color c = getColor((int) x1, (int) y, (int) z1); if(pcld == null) { builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a); } else { c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a); c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a); c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a); c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a); } builder.rect(c00, c10, c11, c01); }
Example #5
Source File: NormalBlockRenderer.java From Radix with MIT License | 6 votes |
@Override public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // POSITIVE Y float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); c00.setPos(x1, y, z1).setNor(0, 1, 0); c01.setPos(x1, y, z2).setNor(0, 1, 0); c10.setPos(x2, y, z1).setNor(0, 1, 0); c11.setPos(x2, y, z2).setNor(0, 1, 0); Color c = getColor((int) x1, (int) y - 1, (int) z1); if(pcld == null) { builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a); } else { c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a); c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a); c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a); c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a); } builder.rect(c01, c11, c10, c00); }
Example #6
Source File: NormalBlockRenderer.java From Radix with MIT License | 6 votes |
@Override public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // NEGATIVE X float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); c00.setPos(x, y1, z1).setNor(-1, 0, 0); c01.setPos(x, y1, z2).setNor(-1, 0, 0); c10.setPos(x, y2, z1).setNor(-1, 0, 0); c11.setPos(x, y2, z2).setNor(-1, 0, 0); Color c = getColor((int) x, (int) y1, (int) z1); if(pcld == null) { builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a); } else { c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a); c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a); c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a); c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a); } builder.rect(c01, c11, c10, c00); }
Example #7
Source File: NormalBlockRenderer.java From Radix with MIT License | 6 votes |
@Override public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // POSITIVE X float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); c00.setPos(x, y1, z1).setNor(1, 0, 0); c01.setPos(x, y1, z2).setNor(1, 0, 0); c10.setPos(x, y2, z1).setNor(1, 0, 0); c11.setPos(x, y2, z2).setNor(1, 0, 0); Color c = getColor((int) x - 1, (int) y1, (int) z1); if(pcld == null) { builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a); } else { c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a); c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a); c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a); c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a); } builder.rect(c00, c10, c11, c01); }
Example #8
Source File: NormalBlockRenderer.java From Radix with MIT License | 6 votes |
@Override public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // NEGATIVE Z float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); c00.setPos(x1, y1, z).setNor(0, 0, -1); c01.setPos(x1, y2, z).setNor(0, 0, -1); c10.setPos(x2, y1, z).setNor(0, 0, -1); c11.setPos(x2, y2, z).setNor(0, 0, -1); Color c = getColor((int) x1, (int) y1, (int) z); if(pcld == null) { builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a); } else { c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a); c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a); c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a); c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a); } builder.rect(c01, c11, c10, c00); }
Example #9
Source File: Chunk.java From Radix with MIT License | 5 votes |
@Override public void rerender() { if (cleanedUp) return; boolean neighborSunlightChanging = false; for(int x = startPosition.x - 16; x <= startPosition.x + 16; x += 16) { for(int z = startPosition.z - 16; z <= startPosition.z + 16; z += 16) { IChunk c = getWorld().getChunk(x, z); if(c != null && c.waitingOnLightFinish()) { neighborSunlightChanging = true; } } } if(neighborSunlightChanging) return; if (!setup) { meshBuilder = new MeshBuilder(); modelBuilder = new ModelBuilder(); setup = true; } sunlightChanged = false; if(meshing) { meshWhenDone = true; } else { meshing = true; parentWorld.addToMeshQueue(this::updateFaces); } }
Example #10
Source File: GreedyMesher.java From Radix with MIT License | 5 votes |
public Mesh meshFaces(List<Face> faces, MeshBuilder builder) { builder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, GL20.GL_TRIANGLES); builder.ensureVertices(faces.size() * 4); for (Face f : faces) { f.render(builder); } return builder.end(); }
Example #11
Source File: MetadataHeightRenderer.java From Radix with MIT License | 5 votes |
@Override public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { int zi = MathUtils.floor(z1); int xi = MathUtils.floor(x1); int yi = MathUtils.floor(y - 1); IWorld world = RadixClient.getInstance().getWorld(); IChunk chunk = world.getChunk(xi, zi); short meta = 0; try { meta = chunk.getMeta(xi & (world.getChunkSize()-1), yi, zi & (world.getChunkSize()-1)); } catch (CoordinatesOutOfBoundsException e) { e.printStackTrace(); } super.renderTop(atlasIndex, x1, z1, x2, z2, y - (1 - getHeight(meta)), lightLevel, pcld, builder); }
Example #12
Source File: MetadataHeightRenderer.java From Radix with MIT License | 5 votes |
@Override public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { int zi = MathUtils.floor(z1); int xi = MathUtils.floor(x - 1); int yi = MathUtils.floor(y1); IWorld world = RadixClient.getInstance().getWorld(); IChunk chunk = world.getChunk(xi, zi); short meta = 0; try { meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1)); } catch (CoordinatesOutOfBoundsException e) { e.printStackTrace(); } super.renderEast(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder); }
Example #13
Source File: MetadataHeightRenderer.java From Radix with MIT License | 5 votes |
@Override public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { int zi = MathUtils.floor(z1); int xi = MathUtils.floor(x); int yi = MathUtils.floor(y1); IWorld world = RadixClient.getInstance().getWorld(); IChunk chunk = world.getChunk(xi, zi); short meta = 0; try { meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1)); } catch (CoordinatesOutOfBoundsException e) { e.printStackTrace(); } super.renderWest(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder); }
Example #14
Source File: MetadataHeightRenderer.java From Radix with MIT License | 5 votes |
@Override public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { int zi = MathUtils.floor(z); int xi = MathUtils.floor(x1); int yi = MathUtils.floor(y1); IWorld world = RadixClient.getInstance().getWorld(); IChunk chunk = world.getChunk(xi, zi); short meta = 0; try { meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1)); } catch (CoordinatesOutOfBoundsException e) { e.printStackTrace(); } super.renderSouth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder); }
Example #15
Source File: MetadataHeightRenderer.java From Radix with MIT License | 5 votes |
@Override public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { int zi = MathUtils.floor(z - 1); int xi = MathUtils.floor(x1); int yi = MathUtils.floor(y1); IWorld world = RadixClient.getInstance().getWorld(); IChunk chunk = world.getChunk(xi, zi); short meta = 0; try { meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1)); } catch (CoordinatesOutOfBoundsException e) { e.printStackTrace(); } super.renderNorth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder); }
Example #16
Source File: GrassRenderer.java From Radix with MIT License | 5 votes |
@Override public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { float u = getU(atlasIndex); float v = getV(atlasIndex); builder.setUVRange(u, v, u, v); MeshPartBuilder.VertexInfo c00 = new MeshPartBuilder.VertexInfo().setPos(x1, y, z1).setNor(0, 1, 0); MeshPartBuilder.VertexInfo c01 = new MeshPartBuilder.VertexInfo().setPos(x1, y, z2).setNor(0, 1, 0); MeshPartBuilder.VertexInfo c10 = new MeshPartBuilder.VertexInfo().setPos(x2, y, z1).setNor(0, 1, 0); MeshPartBuilder.VertexInfo c11 = new MeshPartBuilder.VertexInfo().setPos(x2, y, z2).setNor(0, 1, 0); IChunk chunk = RadixClient.getInstance().getWorld().getChunk((int) x1, (int) z1); Biome biome; if(chunk != null) { biome = chunk.getBiome(); } else { biome = RadixAPI.instance.getBiomeByID(0); } int[] color = biome.getGrassColor((int) y - 1); float r = color[0]/255f; float g = color[1]/255f; float b = color[2]/255f; if(pcld == null) { builder.setColor(r*lightLevel, g*lightLevel, b*lightLevel, 1); } else { c00.setCol(r*pcld.l00, g*pcld.l00, b*pcld.l00, 1); c01.setCol(r*pcld.l01, g*pcld.l01, b*pcld.l01, 1); c10.setCol(r*pcld.l10, g*pcld.l10, b*pcld.l10, 1); c11.setCol(r*pcld.l11, g*pcld.l11, b*pcld.l11, 1); } builder.rect(c01, c11, c10, c00); }
Example #17
Source File: FenceRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // POSITIVE Y super.renderTop(atlasIndex, x1 + 0.5f - R, z1 + 0.5f - R, x2 - 0.5f + R, z2 - 0.5f + R, y, lightLevel, pcld, builder); }
Example #18
Source File: FenceRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // POSITIVE Z super.renderNorth(atlasIndex, x1 + 0.5f - R, y1, x2 - 0.5f + R, y2, z - 0.5f + R, lightLevel, pcld, builder); }
Example #19
Source File: FenceRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // NEGATIVE Z super.renderSouth(atlasIndex, x1 + 0.5f - R, y1, x2 - 0.5f + R, y2, z + 0.5f - R, lightLevel, pcld, builder); }
Example #20
Source File: FenceRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // NEGATIVE X super.renderWest(atlasIndex, z1 + 0.5f - R, y1, z2 - 0.5f + R, y2, x + 0.5f - R, lightLevel, pcld, builder); }
Example #21
Source File: GreedyMesher.java From Radix with MIT License | 4 votes |
@Override public Mesh meshVoxels(MeshBuilder builder, UseCondition condition) { List<Face> faces = getFaces(condition); return meshFaces(faces, builder); }
Example #22
Source File: FlatFoliageRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderBottom(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {}
Example #23
Source File: FlatFoliageRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {}
Example #24
Source File: FlatFoliageRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { super.renderEast(atlasIndex, z1, y1, z2, y2, x - 0.5f, lightLevel, pcld, builder); }
Example #25
Source File: FlatFoliageRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { super.renderWest(atlasIndex, z1, y1, z2, y2, x + 0.5f, lightLevel, pcld, builder); }
Example #26
Source File: FlatFoliageRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { super.renderSouth(atlasIndex, x1, y1, x2, y2, z + 0.5f, lightLevel, pcld, builder); }
Example #27
Source File: FlatFoliageRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { super.renderNorth(atlasIndex, x1, y1, x2, y2, z - 0.5f, lightLevel, pcld, builder); }
Example #28
Source File: FenceRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // POSITIVE X super.renderEast(atlasIndex, z1 + 0.5f - R, y1, z2 - 0.5f + R, y2, x - 0.5f + R, lightLevel, pcld, builder); }
Example #29
Source File: GrassRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { super.renderWest(atlasIndex + SIDE_OFFSET, z1, y1, z2, y2, x, lightLevel, pcld, builder); }
Example #30
Source File: FenceRenderer.java From Radix with MIT License | 4 votes |
@Override public void renderBottom(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) { // NEGATIVE Y super.renderBottom(atlasIndex, x1 + 0.5f - R, z1 + 0.5f - R, x2 - 0.5f + R, z2 - 0.5f + R, y, lightLevel, pcld, builder); }