Skip to content

Commit

Permalink
Fix JOMLification error, and improve compatibility with LODs.
Browse files Browse the repository at this point in the history
  • Loading branch information
4Denthusiast committed Feb 1, 2021
1 parent 5ba3690 commit d169921
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.assets.ResourceUrn;
Expand Down Expand Up @@ -59,14 +61,14 @@ public void generateChunkMesh(ChunkView view, ChunkMesh chunkMesh, int x, int y,
renderType = ChunkMesh.RenderType.WATER_AND_ICE;
}

org.joml.Vector3i pos = new org.joml.Vector3i(x, y, z);
Vector3i pos = new Vector3i(x, y, z);
float[] renderHeight = getRenderHeight(view, pos);
boolean suppressed = view.getBlock(pos.x, pos.y + 1, pos.z) == block; // Render it as full even though it actually isn't.
boolean full = suppressed || isFull(renderHeight);

BlockAppearance appearance = block.getAppearance(null); //TODO: collect information the block wants, or avoid this entirely.
for (Side side : Side.values()) {
org.joml.Vector3i adjacentPos = side.getAdjacentPos(pos, new org.joml.Vector3i());
Vector3i adjacentPos = side.getAdjacentPos(pos, new Vector3i());
Block adjacentBlock = view.getBlock(adjacentPos);
boolean adjacentSuppressed = view.getBlock(adjacentPos.x, adjacentPos.y + 1, adjacentPos.z) == block;
if (isSideVisibleForBlockTypes(adjacentBlock, adjacentSuppressed, block, full, suppressed, side)) {
Expand All @@ -79,7 +81,7 @@ public void generateChunkMesh(ChunkView view, ChunkMesh chunkMesh, int x, int y,
}

// The height of the liquid block, as it is displayed.
private float[] getRenderHeight(ChunkView view, org.joml.Vector3ic pos) {
private float[] getRenderHeight(ChunkView view, Vector3ic pos) {
float[] heights = new float[4];
int[] liquidCount = new int[4];
for (int x = -1; x <= 1; x++) {
Expand Down Expand Up @@ -116,9 +118,9 @@ private BlockMeshPart lowerPart(Side side, BlockMeshPart basePart, float[] heigh
Vector2f[] texCoords = new Vector2f[basePart.size()];
int[] indices = new int[basePart.indicesSize()];
for (int i = 0; i < basePart.size(); i++) {
vertices[i] = basePart.getVertex(i);
normals[i] = basePart.getNormal(i);
texCoords[i] = basePart.getTexCoord(i);
vertices[i] = new Vector3f(basePart.getVertex(i));
normals[i] = new Vector3f(basePart.getNormal(i));
texCoords[i] = new Vector2f(basePart.getTexCoord(i));
}
for (int i = 0; i < basePart.indicesSize(); i++) {
indices[i] = basePart.getIndex(i);
Expand Down Expand Up @@ -146,6 +148,8 @@ private boolean isSideVisibleForBlockTypes(Block blockToCheck, boolean adjacentS
return true;
} else if (blockToCheck == currentBlock) {
return (side != Side.BOTTOM && side != Side.TOP && suppressed && !adjacentSuppressed);
} else if (blockToCheck.getURI().toString().equals("engine:unloaded")) {
return false;
} else {
return currentBlock.isWaving() != blockToCheck.isWaving()
|| blockToCheck.getMeshGenerator() == null
Expand Down

0 comments on commit d169921

Please sign in to comment.