add a bounding volume to TileChunkMesh and check this against the frustum when rendering
This is to ensure that we still render chunks when they contain tile meshes which may be bigger then the 1x1x1 unit size and could then potentially cause the chunk mesh bounds to be larger then the chunk tile grid bounds.
This commit is contained in:
parent
211a76dfc2
commit
8b2c7452fa
|
@ -145,10 +145,8 @@ public class ChunkVertexGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
chunk.mesh.mesh = builder.end();
|
||||
chunk.mesh.meshPartSize = chunk.mesh.mesh.getNumVertices();
|
||||
chunk.alphaMesh.mesh = alphaBuilder.end();
|
||||
chunk.alphaMesh.meshPartSize = chunk.alphaMesh.mesh.getNumVertices();
|
||||
chunk.mesh.setMesh(builder.end());
|
||||
chunk.alphaMesh.setMesh(alphaBuilder.end());
|
||||
}
|
||||
|
||||
private void addMesh(MeshBuilder builder, TileMesh sourceMesh, TileChunk chunk, TileCoord position, Matrix4 transform, Color color, int firstVertex, int numVertices) {
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package com.blarg.gdx.tilemap3d;
|
||||
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Mesh;
|
||||
import com.badlogic.gdx.graphics.g3d.Renderable;
|
||||
import com.badlogic.gdx.graphics.g3d.materials.Material;
|
||||
import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.blarg.gdx.graphics.TextureAtlas;
|
||||
|
||||
public class TileChunkMesh extends Renderable implements Disposable {
|
||||
public final BoundingBox bounds;
|
||||
|
||||
public TileChunkMesh(TileChunk chunk) {
|
||||
meshPartOffset = 0;
|
||||
meshPartSize = 0;
|
||||
|
@ -19,6 +23,17 @@ public class TileChunkMesh extends Renderable implements Disposable {
|
|||
|
||||
TextureAtlas tileMapAtlas = chunk.tileMap.tileMeshes.atlas;
|
||||
material = new Material(TextureAttribute.createDiffuse(tileMapAtlas.texture));
|
||||
|
||||
bounds = new BoundingBox();
|
||||
}
|
||||
|
||||
public void setMesh(Mesh mesh) {
|
||||
this.mesh = mesh;
|
||||
this.meshPartSize = mesh.getNumVertices();
|
||||
if (this.meshPartSize > 0)
|
||||
mesh.calculateBoundingBox(bounds);
|
||||
else
|
||||
bounds.clr();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,13 +12,10 @@ public class TileMapRenderer {
|
|||
for (int x = 0; x < tileMap.widthInChunks; ++x)
|
||||
{
|
||||
TileChunk chunk = tileMap.getChunk(x, y, z);
|
||||
if (camera.frustum.boundsInFrustum(chunk.getBounds()))
|
||||
{
|
||||
if (chunk.mesh.mesh.getNumVertices() > 0)
|
||||
modelBatch.render(chunk.mesh);
|
||||
if (chunk.alphaMesh.mesh.getNumVertices() > 0)
|
||||
modelBatch.render(chunk.alphaMesh);
|
||||
}
|
||||
if (chunk.mesh.mesh.getNumVertices() > 0 && camera.frustum.boundsInFrustum(chunk.mesh.bounds))
|
||||
modelBatch.render(chunk.mesh);
|
||||
if (chunk.alphaMesh.mesh.getNumVertices() > 0 && camera.frustum.boundsInFrustum(chunk.alphaMesh.bounds))
|
||||
modelBatch.render(chunk.alphaMesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue