Skip to content

Commit

Permalink
Preparing for creating transparent meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
macbury committed Nov 15, 2014
1 parent b123bef commit 88d784f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 156 deletions.
47 changes: 28 additions & 19 deletions core/src/macbury/forge/graphics/builders/TerrainBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
/**
* Created by macbury on 16.10.14.
*/
public class TerrainBuilder extends VoxelsAssembler {
public class TerrainBuilder {
private static final double SHADE_AO_AMPLUTUDE = 10;
private static final double SHADE_AO_FREQUENCY = 0.1;
private static final float SHADE_AO_FACTOR = 0.35f;
private final VoxelsAssembler solidVoxelAssembler;
private final VoxelsAssembler transparentVoxelAssembler;
private float[][][] aoArray;
private boolean haveTransparency;


public enum Face {
Left(Vector3i.LEFT), Right(Vector3i.RIGHT), Top(Vector3i.TOP), Bottom(Vector3i.BOTTOM), Front(Vector3i.FRONT), Back(Vector3i.BACK);
public final Vector3i direction;
Expand All @@ -49,11 +52,9 @@ public TerrainBuilder(VoxelMap voxelMap) {
this.cursor = new TerrainCursor();
this.perlinNoise = new PerlinNoise(System.currentTimeMillis());
this.voxelDef = new VoxelDef(map);

this.solidVoxelAssembler = new VoxelsAssembler();
this.transparentVoxelAssembler = new VoxelsAssembler();
generatePrettyShadeArray();
//perlinNoise.setLacunarity(3);
//perlinNoise.setPersistence(2);
//perlinNoise.setOctaves(9);

}

Expand Down Expand Up @@ -87,33 +88,33 @@ private void buildFace(Vector3i checkTileInDirection, Face face) {
voxelDef.voxelPosition.set(x,y,z);
voxelDef.size.set(map.voxelSize);

if (map.isEmptyNotOutOfBounds(nextTileToCheck)) {
if (map.isTransparent(nextTileToCheck) || map.isEmptyNotOutOfBounds(nextTileToCheck)) {
Block block = map.getBlockForPosition(x,y,z);
voxelDef.block = block;
voxelDef.calculateAoFor(aoArray[x][y][z], face);
switch (face) {
case Top:
top(voxelDef);
solidVoxelAssembler.top(voxelDef);
break;

case Bottom:
bottom(voxelDef);
solidVoxelAssembler.bottom(voxelDef);
break;

case Front:
front(voxelDef);
solidVoxelAssembler.front(voxelDef);
break;

case Back:
back(voxelDef);
solidVoxelAssembler.back(voxelDef);
break;

case Left:
left(voxelDef);
solidVoxelAssembler.left(voxelDef);
break;

case Right:
right(voxelDef);
solidVoxelAssembler.right(voxelDef);
break;
}

Expand Down Expand Up @@ -179,14 +180,19 @@ public void facesForMap() {
facesForPart(new Vector3i(0,0,0), new Vector3i(map.getWidth(), map.getHeight(), map.getDepth()), new Vector3());
}

@Override
public void begin() {
super.begin();
solidVoxelAssembler.begin();
transparentVoxelAssembler.begin();
facesToBuild.clear();
facesToBuild.addAll(Face.values());
haveTransparency = false;
}

public void end() {
solidVoxelAssembler.end();
transparentVoxelAssembler.end();
}

public boolean next() {
return facesToBuild.size > 0;
}
Expand All @@ -196,7 +202,7 @@ public VoxelFaceRenderable buildFaceForChunk(Chunk chunk) {
haveTransparency = false;
buildFace(face.direction, face);

if (isEmpty()) {
if (solidVoxelAssembler.isEmpty()) {
return null;
} else {
VoxelFaceRenderable renderable = getRenderable();
Expand All @@ -216,12 +222,15 @@ private VoxelFaceRenderable getRenderable() {
renderable.primitiveType = GL30.GL_TRIANGLES;

if (ForgE.config.generateWireframe)
renderable.wireframe = this.wireframe();
renderable.triangleCount = triangleArrayList.size();
renderable.mesh = this.mesh(MeshVertexInfo.AttributeType.Position, MeshVertexInfo.AttributeType.Normal, MeshVertexInfo.AttributeType.TextureCord, MeshVertexInfo.AttributeType.Material);
renderable.wireframe = solidVoxelAssembler.wireframe();
renderable.triangleCount = solidVoxelAssembler.getTriangleCount();
renderable.mesh = solidVoxelAssembler.mesh(MeshVertexInfo.AttributeType.Position, MeshVertexInfo.AttributeType.Normal, MeshVertexInfo.AttributeType.TextureCord, MeshVertexInfo.AttributeType.Material);

return renderable;
}


public void dispose() {
solidVoxelAssembler.dispose();
transparentVoxelAssembler.dispose();
}
}
4 changes: 4 additions & 0 deletions core/src/macbury/forge/graphics/mesh/MeshAssembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,8 @@ public boolean isEmpty() {
public boolean haveGeometry() {
return !isEmpty();
}

public int getTriangleCount() {
return this.triangleArrayList.size();
}
}
135 changes: 0 additions & 135 deletions core/src/macbury/forge/systems/TerrainSystem.java

This file was deleted.

14 changes: 13 additions & 1 deletion core/src/macbury/forge/terrain/TerrainEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,24 @@ private void occulsion() {
Chunk visibleChunk = (Chunk) tempObjects.pop();
if (visibleChunk.renderables.size > 0) {
visibleChunks.add(visibleChunk);

boolean visibleFront = false;
//TODO: if i can see front face, that means i cant see back face, if i can see right face that means i cant see left face
for (int i = 0; i < visibleChunk.renderables.size; i++) {
VoxelFaceRenderable renderable = visibleChunk.renderables.get(i);
/*if (renderable.direction.epsilonEquals(TerrainBuilder.Face.Front.direction, 0.1f)) {
visibleFront = true;
}
if (visibleFront && renderable.direction.equals(TerrainBuilder.Face.Back)) {
} else {
visibleFaces.add(renderable);
}*/

if (camera.boundsInFrustum(renderable.boundingBox)) {
visibleFaces.add(renderable);
}
//visibleFaces.add(renderable);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion editor/src/macbury/forge/editor/windows/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void focusGained(FocusEvent e) {

@Override
public void focusLost(FocusEvent e) {
//mainContentPane.grabFocus();
mainContentPane.grabFocus();
//mainContentPane.setFocusable(true);
}
}

0 comments on commit 88d784f

Please sign in to comment.