Skip to content

Commit

Permalink
add jlibnoise dependency. remove noise implementations. add individua…
Browse files Browse the repository at this point in the history
…l textures.
  • Loading branch information
Sleaker committed Feb 16, 2014
1 parent 635762c commit db13a26
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 246 deletions.
Binary file added assets/Textures/cubes/brick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Textures/cubes/dirt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Textures/cubes/grass_side.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Textures/cubes/grass_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Textures/cubes/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/Textures/cubes/terrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added jars/jlibnoise-1.0.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions src/com/jme3/cubed/BlockMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
*/
public class BlockMaterial extends Material {

public BlockMaterial(AssetManager assetManager, String blockTextureFilePath){
public BlockMaterial(AssetManager assetManager, String texturePath){
super(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture texture = assetManager.loadTexture(blockTextureFilePath);

Texture texture = assetManager.loadTexture(texturePath);
texture.setMagFilter(Texture.MagFilter.Nearest);
texture.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
texture.setMinFilter(Texture.MinFilter.NearestNearestMipMap);
setTexture("ColorMap", texture);
getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
}
Expand Down
30 changes: 23 additions & 7 deletions src/com/jme3/cubed/ChunkTerrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public byte[] getBlocks() {
return blocks;
}

public void setBlock(Class<? extends Block> blockClass, int x, int y, int z) {
if (isInChunk(x, y, z)) {
if (blockClass == null) {
blocks[(x << X_SHIFT) + z + (y << Y_SHIFT)] = 0;
} else {
blocks[(x << X_SHIFT) + z + (y << Y_SHIFT)] = MaterialManager.getInstance().getType(blockClass).getType();
}
needsMeshUpdate = true;
}
}

public void setBlock(Class<? extends Block> blockClass, Vector3i loc) {
int x = loc.getX();
int y = loc.getY();
Expand All @@ -90,20 +101,21 @@ public void setBlock(Class<? extends Block> blockClass, Vector3i loc) {
}
}

public byte getBlock(Vector3i loc) {
int x = loc.getX();
int y = loc.getY();
int z = loc.getZ();
if (isInChunk(loc)) {
public byte getBlock(int x, int y, int z) {
if (isInChunk(x, y, z)) {
return blocks[(x << X_SHIFT) + z + (y << Y_SHIFT)];
} else {
return 0;
}
}

public byte getBlock(Vector3i loc) {
return getBlock(loc.getX(), loc.getY(), loc.getZ());
}

public boolean isFaceVisible(Vector3i loc, Face face) {
Vector3i vec = loc.add(face.getOffsetVector());
byte type = 0;
byte type;
if (!isInChunk(vec)) {
type = chunkControl.getBlock(vec.add(blockLocation));
} else {
Expand All @@ -112,8 +124,12 @@ public boolean isFaceVisible(Vector3i loc, Face face) {
return type == 0 || MaterialManager.getInstance().getType(type).getSkin().isTransparent();
}

private boolean isInChunk(int x, int y, int z) {
return x < C_SIZE && y < C_SIZE && z < C_SIZE && x > -1 && y > -1 && z > -1;
}

private boolean isInChunk(Vector3i vec) {
return vec.getX() < C_SIZE && vec.getY() < C_SIZE && vec.getZ() < C_SIZE && vec.getX() > -1 && vec.getY() > -1 && vec.getZ() > -1;
return isInChunk(vec.getX(), vec.getY(), vec.getZ());
}

public Vector3i getLocation() {
Expand Down
4 changes: 2 additions & 2 deletions src/com/jme3/cubed/ChunkTerrainControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setBlock(Class<? extends Block> blockClass, Vector3i loc, boolean ge
return;
}
}
terrain.setBlock(blockClass, new Vector3i(loc.getX() & ChunkTerrain.MASK, loc.getY() & ChunkTerrain.MASK, loc.getZ() & ChunkTerrain.MASK));
terrain.setBlock(blockClass, loc.getX() & ChunkTerrain.MASK, loc.getY() & ChunkTerrain.MASK, loc.getZ() & ChunkTerrain.MASK);
}

public BlockMaterial getMaterial() {
Expand All @@ -64,7 +64,7 @@ public BlockMaterial getMaterial() {
/**
* Gets a ChunkTerrain from the given chunk vector
* @param vec
* @return
* @return chunk
*/
public ChunkTerrain getTerrain(Vector3i vec) {
return chunks.get(vec);
Expand Down
26 changes: 0 additions & 26 deletions src/com/jme3/cubed/noise/Noise.java

This file was deleted.

198 changes: 0 additions & 198 deletions src/com/jme3/cubed/noise/Simplex.java

This file was deleted.

2 changes: 0 additions & 2 deletions src/com/jme3/cubed/render/VoxelMesher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*
* @author Nicholas Minkler <sleaker@gmail.com>
*/


public abstract class VoxelMesher {
public abstract Mesh generateMesh(ChunkTerrain terrain);

Expand Down
21 changes: 13 additions & 8 deletions src/com/jme3/cubed/test/CubedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.jme3.cubed.MaterialManager;
import com.jme3.cubed.math.Vector2i;
import com.jme3.cubed.math.Vector3i;
import com.jme3.cubed.noise.Simplex;
import com.jme3.cubed.render.GreedyMesher;
import com.jme3.cubed.render.MarchingCubesMesher;
import com.jme3.cubed.render.NaiveMesher;
Expand All @@ -38,6 +37,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.jlibnoise.NoiseQuality;
import net.jlibnoise.module.source.Perlin;

public class CubedTest extends SimpleApplication {

Expand Down Expand Up @@ -108,7 +109,7 @@ public void simpleInitApp() {
//ctc.setBlock(Block_Stone.class, Vector3i.ZERO, true);
//ctc.setBlock(Block_Water.class, Vector3i.UNIT_Y, true);

cam.setLocation(new Vector3f(-10, 10, 16));
cam.setLocation(new Vector3f(-10, 64, 16));
cam.lookAtDirection(new Vector3f(1, -0.56f, -1), Vector3f.UNIT_Y);
flyCam.setMoveSpeed(50);
}
Expand Down Expand Up @@ -168,14 +169,18 @@ private static FilterPostProcessor getFilterPostProcessor(SimpleApplication simp
}

private void genTerrainFromNoise(ChunkTerrainControl ctc) {
Simplex noise = new Simplex(150);
Simplex noise2 = new Simplex(150 + 250);
Perlin noise = new Perlin();
noise.setFrequency(0.01);
noise.setLacunarity(2.0);
noise.setNoiseQuality(NoiseQuality.BEST);
noise.setOctaveCount(8);
noise.setPersistence(0.5);
noise.setSeed(DEFAULT_SEED);
Vector3i point = new Vector3i();
for (int x = 0; x < 160; x++) {
for (int x = -160; x < 160; x++) {
point.setX(x);
for (int z = 0; z < 160; z++) {
int landHeight = (int) (Math.floor(noise.getValue(x, 0, z) * 5 + 10));
landHeight += (int) (Math.floor(noise.getValue(x, 0, z) * 3));
for (int z = -160; z < 160; z++) {
int landHeight = (int) (Math.floor(noise.getValue(x, 0, z) * 20 + 20));
int dirtHeight = (int) (Math.floor((hash(x, z) >> 8 & 0xf) / 15f * 3) + 1);
point.setZ(z);
for (int y = 0; y < 64; y++) {
Expand Down

0 comments on commit db13a26

Please sign in to comment.