mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +00:00
rework image stuff
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.api.math;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.NormalizationUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -35,7 +35,7 @@ public class ProbabilityCollection<E> {
|
||||
return (E) array[r.nextInt(array.length)];
|
||||
}
|
||||
|
||||
public E get(FastNoiseLite n, double x, double z) {
|
||||
public E get(NoiseSampler n, double x, double z) {
|
||||
if(array.length == 0) return null;
|
||||
return (E) array[NormalizationUtil.normalize(n.getNoise(x, z), array.length, 1)];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.api.math.noise;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.util.hash.HashMapDoubleDouble;
|
||||
import parsii.eval.Expression;
|
||||
@@ -7,7 +8,7 @@ import parsii.eval.Expression;
|
||||
import java.util.List;
|
||||
|
||||
public class NoiseFunction2 implements NoiseFunction {
|
||||
private final FastNoiseLite gen;
|
||||
private final NoiseSampler gen;
|
||||
private final Cache cache = new Cache();
|
||||
|
||||
public NoiseFunction2(long seed, NoiseBuilder builder) {
|
||||
@@ -43,7 +44,7 @@ public class NoiseFunction2 implements NoiseFunction {
|
||||
private static final long serialVersionUID = 8915092734723467010L;
|
||||
private static final int cacheSize = 384;
|
||||
|
||||
public double get(FastNoiseLite noise, double x, double z) {
|
||||
public double get(NoiseSampler noise, double x, double z) {
|
||||
double xx = x >= 0 ? x * 2 : x * -2 - 1;
|
||||
double zz = z >= 0 ? z * 2 : z * -2 - 1;
|
||||
double key = (xx >= zz) ? (xx * xx + xx + zz) : (zz * zz + xx);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.api.math.noise;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import parsii.eval.Expression;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NoiseFunction3 implements NoiseFunction {
|
||||
private final FastNoiseLite gen;
|
||||
private final NoiseSampler gen;
|
||||
|
||||
public NoiseFunction3(long seed, NoiseBuilder builder) {
|
||||
this.gen = builder.build((int) seed);
|
||||
|
||||
+905
-961
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
package com.dfsek.terra.api.math.noise.samplers;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
|
||||
public interface NoiseSampler {
|
||||
/**
|
||||
* 2D noise at given position using current settings
|
||||
* <p>
|
||||
* Noise output bounded between -1...1
|
||||
*/
|
||||
double getNoise(/*FNLdouble*/ double x, /*FNLdouble*/ double y);
|
||||
|
||||
/**
|
||||
* 3D noise at given position using current settings
|
||||
* <p>
|
||||
* Noise output bounded between -1...1
|
||||
*/
|
||||
double getNoise(/*FNLdouble*/ double x, /*FNLdouble*/ double y, /*FNLdouble*/ double z);
|
||||
|
||||
default double getNoise(Vector3 vector3) {
|
||||
return getNoise(vector3.getX(), vector3.getY(), vector3.getZ());
|
||||
}
|
||||
|
||||
default double getNoise(Vector2 vector2) {
|
||||
return getNoise(vector2.getX(), vector2.getZ());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.dfsek.terra.api.math.noise.samplers;
|
||||
|
||||
public abstract class Normalizer implements NoiseSampler {
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
protected Normalizer(NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
public abstract double normalize(double in);
|
||||
|
||||
@Override
|
||||
public double getNoise(double x, double y) {
|
||||
return normalize(sampler.getNoise(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return normalize(sampler.getNoise(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -172,6 +172,12 @@ public class Vector2 implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 add(double x, double z) {
|
||||
this.x += x;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + z + ")";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.api.math.voxel;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
|
||||
public class DeformedSphere extends VoxelGeometry {
|
||||
public DeformedSphere(Vector3 start, int rad, double deform, FastNoiseLite noise) {
|
||||
public DeformedSphere(Vector3 start, int rad, double deform, NoiseSampler noise) {
|
||||
for(int x = -rad; x <= rad; x++) {
|
||||
for(int y = -rad; y <= rad; y++) {
|
||||
for(int z = -rad; z <= rad; z++) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.api.world.biome;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.api.world.palette;
|
||||
|
||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
|
||||
import java.util.List;
|
||||
@@ -104,7 +104,7 @@ public abstract class Palette<E> {
|
||||
return m;
|
||||
}
|
||||
|
||||
public E get(FastNoiseLite random, int x, int z) {
|
||||
public E get(NoiseSampler random, int x, int z) {
|
||||
if(col) return this.collection.get(random, x, z);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.dfsek.terra.api.world.palette;
|
||||
|
||||
import com.dfsek.terra.api.math.noise.FastNoiseLite;
|
||||
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SimplexPalette<E> extends Palette<E> {
|
||||
private final FastNoiseLite r;
|
||||
private final NoiseSampler r;
|
||||
|
||||
public SimplexPalette(FastNoiseLite r) {
|
||||
public SimplexPalette(NoiseSampler r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user