diff --git a/src/main/java/com/volmit/iris/gen/v2/HunkView.java b/src/main/java/com/volmit/iris/gen/v2/HunkView.java deleted file mode 100644 index 96443949c..000000000 --- a/src/main/java/com/volmit/iris/gen/v2/HunkView.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.volmit.iris.gen.v2; - -import com.volmit.iris.gen.v2.scaffold.ArrayHunk; -import com.volmit.iris.gen.v2.scaffold.Hunk; -import com.volmit.iris.gen.v2.scaffold.HunkFace; - -public class HunkView implements Hunk -{ - private final int ox; - private final int oy; - private final int oz; - private final int w; - private final int h; - private final int d; - private final Hunk src; - - public HunkView(Hunk src) - { - this(src, src.getWidth(), src.getHeight(), src.getDepth()); - } - - public HunkView(Hunk src, int w, int h, int d) - { - this(src, w, h, d, 0, 0, 0); - } - - public HunkView(Hunk src, int w, int h, int d, int ox, int oy, int oz) - { - this.src = src; - this.w = w; - this.h = h; - this.d = d; - this.ox = ox; - this.oy = oy; - this.oz = oz; - } - - @Override - public Hunk croppedView(int x1, int y1, int z1, int x2, int y2, int z2) - { - return new HunkView(this, x2 - x1, y2 - y1, z2 - z1, x1 + ox, y1 + oy, z1 + oz); - } - - @Override - public ArrayHunk crop(int x1, int y1, int z1, int x2, int y2, int z2) - { - ArrayHunk h = new ArrayHunk(x2 - x1, y2 - y1, z2 - z1); - - for(int i = x1; i < x2; i++) - { - for(int j = y1; j < y2; j++) - { - for(int k = z1; k < z2; k++) - { - h.set(i - x1, j - y1, k - z1, get(i, j, k)); - } - } - } - - return h; - } - - @Override - public void insert(int offX, int offY, int offZ, Hunk hunk, boolean invertY) - { - if(offX + (hunk.getWidth() - 1) >= w || offY + (hunk.getHeight() - 1) >= h || offZ + (hunk.getDepth() - 1) >= d || offX < 0 || offY < 0 || offZ < 0) - { - throw new RuntimeException("Cannot insert hunk " + hunk.getWidth() + "," + hunk.getHeight() + "," + hunk.getDepth() + " into Hunk " + w + "," + h + "," + d + " with offset " + offZ + "," + offY + "," + offZ); - } - - for(int i = offX; i < offX + hunk.getWidth(); i++) - { - for(int j = offY; j < offY + hunk.getHeight(); j++) - { - for(int k = offZ; k < offZ + hunk.getDepth(); k++) - { - set(i, j, k, hunk.get(i - offX, j - offY, k - offZ)); - } - } - } - } - - @Override - public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t) - { - if(x1 >= w || y1 >= h || z1 >= d || x2 >= w || y2 >= h || z2 >= d) - { - throw new RuntimeException(x1 + "-" + x2 + " " + y1 + "-" + y2 + " " + z1 + "-" + z2 + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1)); - } - - src.set(x1, y1, z1, x2, y2, z2, t); - } - - @Override - public void set(int x, int y, int z, T t) - { - if(x >= w || y >= h || z >= d) - { - throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1)); - } - - src.set(x + ox, y + oy, z + oz, t); - } - - @Override - public T get(int x, int y, int z) - { - if(x >= w || y >= h || z >= d) - { - throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1)); - } - - return src.get(x + ox, y + oy, z + oz); - } - - @Override - public T getClosest(int x, int y, int z) - { - return src.get(x >= w ? w + ox - 1 : x + ox, y >= h ? h + oy - 1 : y + oy, z >= d ? d + oz - 1 : z + oz); - } - - @Override - public void fill(T t) - { - set(0 + ox, 0 + oy, 0 + oz, w - 1 + ox, h - 1 + oy, d - 1 + oz, t); - } - - @Override - public int getWidth() - { - return w; - } - - @Override - public int getDepth() - { - return d; - } - - @Override - public int getHeight() - { - return h; - } - - @Override - public Hunk getFace(HunkFace f) - { - switch(f) - { - case BOTTOM: - return croppedView(0, 0, 0, getWidth() - 1, 0, getDepth() - 1); - case EAST: - return croppedView(getWidth() - 1, 0, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1); - case NORTH: - return croppedView(0, 0, 0, getWidth() - 1, getHeight() - 1, 0); - case SOUTH: - return croppedView(0, 0, 0, 0, getHeight() - 1, getDepth() - 1); - case TOP: - return croppedView(0, getHeight() - 1, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1); - case WEST: - return croppedView(0, 0, getDepth() - 1, getWidth() - 1, getHeight() - 1, getDepth() - 1); - default: - break; - } - - return null; - } - - @Override - public Hunk getSource() - { - return src; - } -} diff --git a/src/main/java/com/volmit/iris/gen/v2/IrisComplex.java b/src/main/java/com/volmit/iris/gen/v2/IrisComplex.java index f18cbdaf6..f156ac823 100644 --- a/src/main/java/com/volmit/iris/gen/v2/IrisComplex.java +++ b/src/main/java/com/volmit/iris/gen/v2/IrisComplex.java @@ -1,14 +1,19 @@ package com.volmit.iris.gen.v2; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + import com.volmit.iris.Iris; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.gen.v2.scaffold.stream.Interpolated; import com.volmit.iris.manager.IrisDataManager; import com.volmit.iris.object.InferredType; import com.volmit.iris.object.IrisBiome; -import com.volmit.iris.object.IrisBiomeGeneratorLink; +import com.volmit.iris.object.IrisBiomePaletteLayer; import com.volmit.iris.object.IrisDimension; +import com.volmit.iris.object.IrisGenerator; import com.volmit.iris.object.IrisRegion; -import com.volmit.iris.object.NoiseStyle; +import com.volmit.iris.util.KList; import com.volmit.iris.util.M; import com.volmit.iris.util.RNG; @@ -18,14 +23,19 @@ import lombok.Data; public class IrisComplex implements DataProvider { private IrisDataManager data; + private KList generators; + private static final BlockData AIR = Material.AIR.createBlockData(); private ProceduralStream regionStream; private ProceduralStream bridgeStream; private ProceduralStream landBiomeStream; private ProceduralStream seaBiomeStream; private ProceduralStream shoreBiomeStream; private ProceduralStream baseBiomeStream; + private ProceduralStream trueBiomeStream; private ProceduralStream heightStream; - private ProceduralStream heightMinStream; + private ProceduralStream terrainStream; + private ProceduralStream rockStream; + private ProceduralStream fluidStream; public IrisComplex() { @@ -60,53 +70,177 @@ public class IrisComplex implements DataProvider public void flash(long seed, IrisDimension dimension, IrisDataManager data) { this.data = data; + double fluidHeight = dimension.getFluidHeight(); + generators = new KList<>(); RNG rng = new RNG(seed); //@builder - regionStream = NoiseStyle.CELLULAR.stream(rng.nextRNG()) - .zoom(4) + dimension.getRegions().forEach((i) -> data.getRegionLoader().load(i) + .getAllBiomes(this).forEach((b) -> b + .getGenerators() + .forEach((c) -> registerGenerator(c.getCachedGenerator(this))))); + rockStream = dimension.getRockPalette().getLayerGenerator(rng.nextRNG(), data).stream() + .select(dimension.getRockPalette().getBlockData(data)) + .convert((v) -> v.getBlockData()); + fluidStream = dimension.getFluidPalette().getLayerGenerator(rng.nextRNG(), data).stream() + .select(dimension.getFluidPalette().getBlockData(data)) + .convert((v) -> v.getBlockData()); + regionStream = dimension.getRegionStyle().create(rng.nextRNG()).stream() + .zoom(dimension.getRegionZoom()) .select(dimension.getRegions()) - .convertCached((s) -> data.getRegionLoader().load(s)); + .convertCached((s) -> data.getRegionLoader().load(s)) + .cache2D(1024); landBiomeStream = regionStream.convertCached((r) - -> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 10000 * r.getLandBiomeZoom()))) + -> dimension.getLandBiomeStyle().create(rng.nextRNG()).stream() .zoom(r.getLandBiomeZoom()) .select(r.getLandBiomes()) .convertCached((s) -> data.getBiomeLoader().load(s)) - ).convertAware2D((str, x, z) -> str.get(x, z)); + ).convertAware2D((str, x, z) -> str.get(x, z)) + .cache2D(1024); seaBiomeStream = regionStream.convertCached((r) - -> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 20000 * r.getSeaBiomeZoom()))) + -> dimension.getSeaBiomeStyle().create(rng.nextRNG()).stream() .zoom(r.getSeaBiomeZoom()) .select(r.getSeaBiomes()) .convertCached((s) -> data.getBiomeLoader().load(s)) - ).convertAware2D((str, x, z) -> str.get(x, z)); + ).convertAware2D((str, x, z) -> str.get(x, z)) + .cache2D(1024); shoreBiomeStream = regionStream.convertCached((r) - -> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 30000 * r.getShoreBiomeZoom()))) + -> dimension.getShoreBiomeStyle().create(rng.nextRNG()).stream() .zoom(r.getShoreBiomeZoom()) .select(r.getShoreBiomes()) .convertCached((s) -> data.getBiomeLoader().load(s)) - ).convertAware2D((str, x, z) -> str.get(x, z)); - bridgeStream = NoiseStyle.CELLULAR.stream(new RNG(seed + 4000)) - .convert((v) -> v >= dimension.getLandChance() ? InferredType.SEA : InferredType.LAND); + ).convertAware2D((str, x, z) -> str.get(x, z)) + .cache2D(1024); + bridgeStream = dimension.getContinentalStyle().create(rng.nextRNG()).stream() + .convert((v) -> v >= dimension.getLandChance() ? InferredType.SEA : InferredType.LAND); baseBiomeStream = bridgeStream.convertAware2D((t, x, z) -> t.equals(InferredType.SEA) - ? seaBiomeStream.get(x, z) : landBiomeStream.get(x, z)); - heightStream = baseBiomeStream.convertAware2D((b, x, z) -> { - double h = 0; - for(IrisBiomeGeneratorLink i : b.getGenerators()) + ? seaBiomeStream.get(x, z) : landBiomeStream.get(x, z)) + .cache2D(1024); + heightStream = baseBiomeStream.convertAware2D((b, x, z) -> getHeight(b, x, z, seed)) + .forceDouble().add(fluidHeight).roundDouble() + .cache2D(1024); + trueBiomeStream = heightStream + .convertAware2D((h, x, z) -> + fixBiomeType(h, baseBiomeStream.get(x, z),regionStream.get(x, z), x, z, fluidHeight)) + .cache2D(1024); + terrainStream = ProceduralStream.of((x, y, z) -> { + double height = heightStream.get(x, z); + IrisBiome biome = trueBiomeStream.get(x, z); + int depth = (int) (Math.round(height) - y); + int atDepth = 0; + + if(depth < -1) + { + return AIR; + } + + for(IrisBiomePaletteLayer i : biome.getLayers()) + { + int th = i.getHeightGenerator(rng, data).fit(i.getMinHeight(), i.getMaxHeight(), x, z); + + if(atDepth + th >= depth) + { + return i.get(rng, x, y, z, data).getBlockData(); + } + + atDepth += th; + } + + return rockStream.get(x, y, z); + }, new Interpolated() + { + @Override + public double toDouble(BlockData t) + { + return 0; + } + + @Override + public BlockData fromDouble(double d) + { + return null; + } + }); + //@done + } + + private IrisBiome fixBiomeType(Double height, IrisBiome biome, IrisRegion region, Double x, Double z, double fluidHeight) + { + double sh = region.getShoreHeight(x, z); + + if(height > fluidHeight && height <= fluidHeight + sh && !biome.isShore()) + { + return shoreBiomeStream.get(x, z); + } + + if(height > fluidHeight + sh && !biome.isLand()) + { + return landBiomeStream.get(x, z); + } + + if(height <= fluidHeight && !biome.isAquatic()) + { + return seaBiomeStream.get(x, z); + } + + return biome; + } + + private double getHeight(IrisBiome b, double x, double z, long seed) + { + double h = 0; + + for(IrisGenerator gen : generators) + { + double hi = gen.getInterpolator().interpolate(x, z, (xx, zz) -> { - // TODO Use gen interp ..... or - // try trilerp again.... try { - h += i.getHeight(this, x, z, seed); + IrisBiome bx = baseBiomeStream.get(xx, zz); + + return bx.getGenLinkMax(gen.getLoadKey()); } catch(Throwable e) { - e.printStackTrace(); + Iris.warn("Failed to sample hi biome at " + xx + " " + zz + " using the generator " + gen.getLoadKey()); } + + return 0; + }); + + double lo = gen.getInterpolator().interpolate(x, z, (xx, zz) -> + { + try + { + IrisBiome bx = baseBiomeStream.get(xx, zz); + + return bx.getGenLinkMin(gen.getLoadKey()); + } + + catch(Throwable e) + { + Iris.warn("Failed to sample lo biome at " + xx + " " + zz + " using the generator " + gen.getLoadKey()); + } + + return 0; + }); + + h += M.lerp(lo, hi, gen.getHeight(x, z, seed + 239945)); + } + + return h; + } + + private void registerGenerator(IrisGenerator cachedGenerator) + { + for(IrisGenerator i : generators) + { + if(i.getLoadKey().equals(cachedGenerator.getLoadKey())) + { + return; } - - return h+63; - }).forceDouble().interpolate().starcast9(12).into().bihermite(4, 0.01, 0); - //@done + } + + generators.add(cachedGenerator); } } diff --git a/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java b/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java index fb113e244..ab80e6762 100644 --- a/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java +++ b/src/main/java/com/volmit/iris/gen/v2/IrisTerrainGenerator.java @@ -35,7 +35,7 @@ public class IrisTerrainGenerator public ProceduralStream height = NoiseStyle.CELLULAR .stream(69) .fit(1, 69) - .interpolate().starcast9(4).into().bilinear(4) + .interpolate().bistarcast9(4).into().bilinear(4) ; public ProceduralStream rock = NoiseStyle.STATIC @@ -46,6 +46,6 @@ public class IrisTerrainGenerator public void generate(int x, int z, Hunk blocks, Hunk biomes) { RNG rng = new RNG((((long) x) << 32) | (z & 0xffffffffL)); - complex.getHeightStream().fill2D(blocks, x * 16, z * 16, Material.STONE.createBlockData()); + complex.getHeightStream().fill2D(blocks, x * 16, z * 16, complex.getTerrainStream()); } } diff --git a/src/main/java/com/volmit/iris/gen/v2/TestGen.java b/src/main/java/com/volmit/iris/gen/v2/TestGen.java index 65c697a52..9cb92daba 100644 --- a/src/main/java/com/volmit/iris/gen/v2/TestGen.java +++ b/src/main/java/com/volmit/iris/gen/v2/TestGen.java @@ -2,8 +2,6 @@ package com.volmit.iris.gen.v2; import java.util.Random; import java.util.UUID; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; import org.bukkit.Material; import org.bukkit.World; @@ -14,8 +12,8 @@ import org.bukkit.generator.ChunkGenerator; import com.volmit.iris.Iris; import com.volmit.iris.gen.v2.scaffold.Hunk; -import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; -import com.volmit.iris.object.NoiseStyle; +import com.volmit.iris.util.Form; +import com.volmit.iris.util.PrecisionStopwatch; public class TestGen { @@ -24,12 +22,20 @@ public class TestGen p.teleport(new WorldCreator("t/" + UUID.randomUUID().toString()).generator(new ChunkGenerator() { IrisTerrainGenerator tg = new IrisTerrainGenerator(1337, Iris.globaldata.getDimensionLoader().load("overworld"), Iris.globaldata); + BlockData st = Material.STONE.createBlockData(); + + public boolean isParallelCapable() + { + return true; + } @Override public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { + PrecisionStopwatch p = PrecisionStopwatch.start(); ChunkData c = createChunkData(world); tg.generate(x, z, Hunk.view(c), null); + Iris.info("Generated " + x + " " + z + " in " + Form.duration(p.getMilliseconds(), 2)); return c; } }).createWorld().getSpawnLocation()); diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/ArraySignificance.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/ArraySignificance.java new file mode 100644 index 000000000..550d9d3cf --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/ArraySignificance.java @@ -0,0 +1,61 @@ +package com.volmit.iris.gen.v2.scaffold; + +import com.volmit.iris.util.KList; + +public class ArraySignificance implements Significance +{ + private final KList types; + private final KList significance; + private final T significant; + + public ArraySignificance(KList types, KList significance, T significant) + { + this.types = types; + this.significance = significance; + this.significant = significant; + } + + public ArraySignificance(KList types, KList significance) + { + this.types = types; + this.significance = significance; + double s = 0; + int v = 0; + for(int i = 0; i < significance.size(); i++) + { + if(significance.get(i) > s) + { + s = significance.get(i); + v = i; + } + } + + significant = types.get(v); + } + + @Override + public KList getFactorTypes() + { + return types; + } + + @Override + public double getSignificance(T t) + { + for(int i = 0; i < types.size(); i++) + { + if(types.get(i).equals(t)) + { + return significance.get(i); + } + } + + return 0; + } + + @Override + public T getMostSignificantType() + { + return significant; + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/Significance.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/Significance.java new file mode 100644 index 000000000..7da91fcb6 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/Significance.java @@ -0,0 +1,12 @@ +package com.volmit.iris.gen.v2.scaffold; + +import com.volmit.iris.util.KList; + +public interface Significance +{ + public KList getFactorTypes(); + + public double getSignificance(T t); + + public T getMostSignificantType(); +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java index 689f4e8fb..b5291b35c 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/layer/ProceduralStream.java @@ -4,34 +4,160 @@ import java.util.List; import java.util.function.Function; import com.volmit.iris.gen.v2.scaffold.Hunk; +import com.volmit.iris.gen.v2.scaffold.Significance; +import com.volmit.iris.gen.v2.scaffold.stream.AddingStream; import com.volmit.iris.gen.v2.scaffold.stream.AwareConversionStream2D; import com.volmit.iris.gen.v2.scaffold.stream.AwareConversionStream3D; import com.volmit.iris.gen.v2.scaffold.stream.CachedConversionStream; import com.volmit.iris.gen.v2.scaffold.stream.CachedStream2D; import com.volmit.iris.gen.v2.scaffold.stream.ClampedStream; import com.volmit.iris.gen.v2.scaffold.stream.ConversionStream; +import com.volmit.iris.gen.v2.scaffold.stream.DividingStream; import com.volmit.iris.gen.v2.scaffold.stream.FittedStream; import com.volmit.iris.gen.v2.scaffold.stream.ForceDoubleStream; +import com.volmit.iris.gen.v2.scaffold.stream.FunctionStream; import com.volmit.iris.gen.v2.scaffold.stream.Interpolated; +import com.volmit.iris.gen.v2.scaffold.stream.ModuloStream; +import com.volmit.iris.gen.v2.scaffold.stream.MultiplyingStream; import com.volmit.iris.gen.v2.scaffold.stream.OffsetStream; +import com.volmit.iris.gen.v2.scaffold.stream.RoundingDoubleStream; import com.volmit.iris.gen.v2.scaffold.stream.RoundingStream; import com.volmit.iris.gen.v2.scaffold.stream.SelectionStream; +import com.volmit.iris.gen.v2.scaffold.stream.SignificanceStream; +import com.volmit.iris.gen.v2.scaffold.stream.SubtractingStream; +import com.volmit.iris.gen.v2.scaffold.stream.To3DStream; import com.volmit.iris.gen.v2.scaffold.stream.ZoomStream; +import com.volmit.iris.util.Function2; import com.volmit.iris.util.Function3; import com.volmit.iris.util.Function4; public interface ProceduralStream extends ProceduralLayer, Interpolated { + public static ProceduralStream ofDouble(Function2 f) + { + return of(f, Interpolated.DOUBLE); + } + + public static ProceduralStream ofDouble(Function3 f) + { + return of(f, Interpolated.DOUBLE); + } + + public static ProceduralStream of(Function2 f, Interpolated helper) + { + return of(f, (x, y, z) -> f.apply(x, z), helper); + } + + public static ProceduralStream of(Function3 f, Interpolated helper) + { + return of((x, z) -> f.apply(x, 0D, z), f, helper); + } + + public static ProceduralStream of(Function2 f, Function3 f2, Interpolated helper) + { + return new FunctionStream<>(f, f2, helper); + } + + default ProceduralStream add(Function3 a) + { + return new AddingStream<>(this, a); + } + + default ProceduralStream add(Function2 a) + { + return new AddingStream<>(this, a); + } + + default ProceduralStream add(double a) + { + return new AddingStream<>(this, a); + } + + default ProceduralStream subtract(Function3 a) + { + return new SubtractingStream<>(this, a); + } + + default ProceduralStream subtract(Function2 a) + { + return new SubtractingStream<>(this, a); + } + + default ProceduralStream subtract(double a) + { + return new SubtractingStream<>(this, a); + } + + default ProceduralStream multiply(Function3 a) + { + return new MultiplyingStream<>(this, a); + } + + default ProceduralStream multiply(Function2 a) + { + return new MultiplyingStream<>(this, a); + } + + default ProceduralStream multiply(double a) + { + return new MultiplyingStream<>(this, a); + } + + default ProceduralStream divide(Function3 a) + { + return new DividingStream<>(this, a); + } + + default ProceduralStream divide(Function2 a) + { + return new DividingStream<>(this, a); + } + + default ProceduralStream divide(double a) + { + return new DividingStream<>(this, a); + } + + default ProceduralStream modulo(Function3 a) + { + return new ModuloStream<>(this, a); + } + + default ProceduralStream modulo(Function2 a) + { + return new ModuloStream<>(this, a); + } + + default ProceduralStream modulo(double a) + { + return new ModuloStream<>(this, a); + } + default ProceduralStream round() { return new RoundingStream(this); } + default ProceduralStream roundDouble() + { + return new RoundingDoubleStream(this); + } + default ProceduralStream forceDouble() { return new ForceDoubleStream(this); } + default ProceduralStream> significance(double radius, int checks) + { + return new SignificanceStream, T>(this, radius, checks); + } + + default ProceduralStream to3D() + { + return new To3DStream(this); + } + default ProceduralStream cache2D(int maxSize) { return new CachedStream2D(this, maxSize); diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/AddingStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/AddingStream.java new file mode 100644 index 000000000..5b0bea654 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/AddingStream.java @@ -0,0 +1,54 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.Function2; +import com.volmit.iris.util.Function3; + +public class AddingStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + private final Function3 add; + + public AddingStream(ProceduralStream stream, Function3 add) + { + super(); + this.stream = stream; + this.add = add; + } + + public AddingStream(ProceduralStream stream, Function2 add) + { + this(stream, (x, y, z) -> add.apply(x, z)); + } + + public AddingStream(ProceduralStream stream, double add) + { + this(stream, (x, y, z) -> add); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return fromDouble(add.apply(x, 0D, z) + stream.getDouble(x, z)); + } + + @Override + public T get(double x, double y, double z) + { + return fromDouble(add.apply(x, y, z) + stream.getDouble(x, y, z)); + } + +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/StarcastStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/BiStarcastStream.java similarity index 85% rename from src/main/java/com/volmit/iris/gen/v2/scaffold/stream/StarcastStream.java rename to src/main/java/com/volmit/iris/gen/v2/scaffold/stream/BiStarcastStream.java index 3d64e0040..97087d11a 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/StarcastStream.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/BiStarcastStream.java @@ -3,13 +3,13 @@ package com.volmit.iris.gen.v2.scaffold.stream; import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; -public class StarcastStream extends BasicLayer implements ProceduralStream, Interpolator +public class BiStarcastStream extends BasicLayer implements ProceduralStream, Interpolator { private ProceduralStream stream; private int rad; private int checks; - public StarcastStream(ProceduralStream stream, int rad, int checks) + public BiStarcastStream(ProceduralStream stream, int rad, int checks) { this.stream = stream; this.rad = rad; diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/DividingStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/DividingStream.java new file mode 100644 index 000000000..93a410082 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/DividingStream.java @@ -0,0 +1,53 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.Function2; +import com.volmit.iris.util.Function3; + +public class DividingStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + private final Function3 add; + + public DividingStream(ProceduralStream stream, Function3 add) + { + super(); + this.stream = stream; + this.add = add; + } + + public DividingStream(ProceduralStream stream, Function2 add) + { + this(stream, (x, y, z) -> add.apply(x, z)); + } + + public DividingStream(ProceduralStream stream, double add) + { + this(stream, (x, y, z) -> add); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return fromDouble(stream.getDouble(x, z) / add.apply(x, 0D, z)); + } + + @Override + public T get(double x, double y, double z) + { + return fromDouble(stream.getDouble(x, y, z) / add.apply(x, y, z)); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/FunctionStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/FunctionStream.java new file mode 100644 index 000000000..cceb7e129 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/FunctionStream.java @@ -0,0 +1,45 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.Function2; +import com.volmit.iris.util.Function3; + +public class FunctionStream extends BasicLayer implements ProceduralStream +{ + private Function2 f2; + private Function3 f3; + private Interpolated helper; + + public FunctionStream(Function2 f2, Function3 f3, Interpolated helper) + { + super(); + this.f2 = f2; + this.f3 = f3; + this.helper = helper; + } + + @Override + public double toDouble(T t) + { + return helper.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return helper.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return f2.apply(x, z); + } + + @Override + public T get(double x, double y, double z) + { + return f3.apply(x, y, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/Interpolated.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/Interpolated.java index d9035559f..ffae4feea 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/Interpolated.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/Interpolated.java @@ -1,9 +1,15 @@ package com.volmit.iris.gen.v2.scaffold.stream; +import java.util.function.Function; + import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; public interface Interpolated { + public static final Interpolated DOUBLE = of((t) -> t, (t) -> t); + public static final Interpolated INT = of((t) -> Double.valueOf(t), (t) -> t.intValue()); + public static final Interpolated LONG = of((t) -> Double.valueOf(t), (t) -> t.longValue()); + public double toDouble(T t); public T fromDouble(double d); @@ -17,4 +23,22 @@ public interface Interpolated return null; } + + public static Interpolated of(Function a, Function b) + { + return new Interpolated() + { + @Override + public double toDouble(T t) + { + return a.apply(t); + } + + @Override + public T fromDouble(double d) + { + return b.apply(d); + } + }; + } } diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatingStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatingStream.java new file mode 100644 index 000000000..ea04ff18b --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatingStream.java @@ -0,0 +1,52 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.object.InterpolationMethod; +import com.volmit.iris.util.IrisInterpolation; +import com.volmit.iris.util.NoiseProvider; + +public class InterpolatingStream extends BasicLayer implements ProceduralStream, Interpolator +{ + private final ProceduralStream stream; + private final InterpolationMethod type; + private final NoiseProvider np; + private final int rx; + + public InterpolatingStream(ProceduralStream stream, int rx, InterpolationMethod type) + { + this.type = type; + this.stream = stream; + this.rx = rx; + this.np = (xf, zf) -> stream.getDouble(xf, zf); + } + + public T interpolate(double x, double y) + { + return fromDouble(IrisInterpolation.getNoise(type, (int) x, (int) y, (double) rx, np)); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return interpolate(x, z); + } + + @Override + public T get(double x, double y, double z) + { + return interpolate(x, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatorFactory.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatorFactory.java index 881b515f8..997b8425f 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatorFactory.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/InterpolatorFactory.java @@ -1,6 +1,7 @@ package com.volmit.iris.gen.v2.scaffold.stream; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.object.InterpolationMethod; public class InterpolatorFactory { @@ -11,6 +12,21 @@ public class InterpolatorFactory this.stream = stream; } + public InterpolatingStream with(InterpolationMethod t, int rx) + { + return new InterpolatingStream(stream, rx, t); + } + + public TrilinearStream trilinear(int rx, int ry, int rz) + { + return new TrilinearStream<>(stream, rx, ry, rz); + } + + public TricubicStream tricubic(int rx, int ry, int rz) + { + return new TricubicStream<>(stream, rx, ry, rz); + } + public BicubicStream bicubic(int rx, int ry) { return new BicubicStream<>(stream, rx, ry); @@ -31,24 +47,44 @@ public class InterpolatorFactory return bilinear(r, r); } - public StarcastStream starcast(int radius, int checks) + public TriStarcastStream tristarcast(int radius, int checks) { - return new StarcastStream<>(stream, radius, checks); + return new TriStarcastStream<>(stream, radius, checks); } - public StarcastStream starcast3(int radius) + public TriStarcastStream tristarcast3(int radius) { - return starcast(radius, 3); + return tristarcast(radius, 3); } - public StarcastStream starcast6(int radius) + public TriStarcastStream tristarcast6(int radius) { - return starcast(radius, 6); + return tristarcast(radius, 6); } - public StarcastStream starcast9(int radius) + public TriStarcastStream tristarcast9(int radius) { - return starcast(radius, 9); + return tristarcast(radius, 9); + } + + public BiStarcastStream bistarcast(int radius, int checks) + { + return new BiStarcastStream<>(stream, radius, checks); + } + + public BiStarcastStream bistarcast3(int radius) + { + return bistarcast(radius, 3); + } + + public BiStarcastStream bistarcast6(int radius) + { + return bistarcast(radius, 6); + } + + public BiStarcastStream bistarcast9(int radius) + { + return bistarcast(radius, 9); } public BiHermiteStream bihermite(int rx, int ry, double tension, double bias) diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/ModuloStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/ModuloStream.java new file mode 100644 index 000000000..ff7bddb04 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/ModuloStream.java @@ -0,0 +1,53 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.Function2; +import com.volmit.iris.util.Function3; + +public class ModuloStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + private final Function3 add; + + public ModuloStream(ProceduralStream stream, Function3 add) + { + super(); + this.stream = stream; + this.add = add; + } + + public ModuloStream(ProceduralStream stream, Function2 add) + { + this(stream, (x, y, z) -> add.apply(x, z)); + } + + public ModuloStream(ProceduralStream stream, double add) + { + this(stream, (x, y, z) -> add); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return fromDouble(stream.getDouble(x, z) % add.apply(x, 0D, z)); + } + + @Override + public T get(double x, double y, double z) + { + return fromDouble(stream.getDouble(x, y, z) % add.apply(x, y, z)); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/MultiplyingStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/MultiplyingStream.java new file mode 100644 index 000000000..bdfbedd32 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/MultiplyingStream.java @@ -0,0 +1,53 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.Function2; +import com.volmit.iris.util.Function3; + +public class MultiplyingStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + private final Function3 add; + + public MultiplyingStream(ProceduralStream stream, Function3 add) + { + super(); + this.stream = stream; + this.add = add; + } + + public MultiplyingStream(ProceduralStream stream, Function2 add) + { + this(stream, (x, y, z) -> add.apply(x, z)); + } + + public MultiplyingStream(ProceduralStream stream, double add) + { + this(stream, (x, y, z) -> add); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return fromDouble(stream.getDouble(x, z) * add.apply(x, 0D, z)); + } + + @Override + public T get(double x, double y, double z) + { + return fromDouble(stream.getDouble(x, y, z) * add.apply(x, y, z)); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/RoundingDoubleStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/RoundingDoubleStream.java new file mode 100644 index 000000000..605ff5101 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/RoundingDoubleStream.java @@ -0,0 +1,45 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; + +public class RoundingDoubleStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + + public RoundingDoubleStream(ProceduralStream stream) + { + super(); + this.stream = stream; + } + + @Override + public double toDouble(Double t) + { + return t.doubleValue(); + } + + @Override + public Double fromDouble(double d) + { + return (double) Math.round(d); + } + + private double round(double v) + { + return Math.round(v); + } + + @Override + public Double get(double x, double z) + { + return round(stream.getDouble(x, z)); + } + + @Override + public Double get(double x, double y, double z) + { + return round(stream.getDouble(x, y, z)); + } + +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/SignificanceStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/SignificanceStream.java new file mode 100644 index 000000000..e507087ee --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/SignificanceStream.java @@ -0,0 +1,79 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.ArraySignificance; +import com.volmit.iris.gen.v2.scaffold.Significance; +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.KList; + +public class SignificanceStream, T> extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + private final double radius; + private final int checks; + + public SignificanceStream(ProceduralStream stream, double radius, int checks) + { + super(); + this.stream = stream; + this.radius = radius; + this.checks = checks; + } + + @Override + public double toDouble(K t) + { + return 0; + } + + @Override + public K fromDouble(double d) + { + return null; + } + + @SuppressWarnings("unchecked") + @Override + public K get(double x, double z) + { + KList ke = new KList<>(8); + KList va = new KList(8); + + double m = (360 / checks); + double v = 0; + + for(int i = 0; i < 360; i += m) + { + double sin = Math.sin(Math.toRadians(i)); + double cos = Math.cos(Math.toRadians(i)); + double cx = x + ((radius * cos) - (radius * sin)); + double cz = z + ((radius * sin) + (radius * cos)); + T t = stream.get(cx, cz); + + if(ke.addIfMissing(t)) + { + va.add(1D); + v++; + } + + else + { + int ind = ke.indexOf(t); + va.set(ind, va.get(ind) + 1D); + } + } + + for(int i = 0; i < va.size(); i++) + { + va.set(i, va.get(i) / (double) v); + } + + return (K) new ArraySignificance(ke, va); + } + + @Override + public K get(double x, double y, double z) + { + return get(x, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/SubtractingStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/SubtractingStream.java new file mode 100644 index 000000000..bf5a21df5 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/SubtractingStream.java @@ -0,0 +1,53 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.Function2; +import com.volmit.iris.util.Function3; + +public class SubtractingStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + private final Function3 add; + + public SubtractingStream(ProceduralStream stream, Function3 add) + { + super(); + this.stream = stream; + this.add = add; + } + + public SubtractingStream(ProceduralStream stream, Function2 add) + { + this(stream, (x, y, z) -> add.apply(x, z)); + } + + public SubtractingStream(ProceduralStream stream, double add) + { + this(stream, (x, y, z) -> add); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return fromDouble(stream.getDouble(x, z) - add.apply(x, 0D, z)); + } + + @Override + public T get(double x, double y, double z) + { + return fromDouble(stream.getDouble(x, y, z) - add.apply(x, y, z)); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/To3DStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/To3DStream.java new file mode 100644 index 000000000..45daba0d1 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/To3DStream.java @@ -0,0 +1,40 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; + +public class To3DStream extends BasicLayer implements ProceduralStream +{ + private final ProceduralStream stream; + + public To3DStream(ProceduralStream stream) + { + super(); + this.stream = stream; + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return stream.get(x, z); + } + + @Override + public T get(double x, double y, double z) + { + return stream.fromDouble(stream.getDouble(x, z) >= y ? 1D : 0D); + } + +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TriHermiteStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TriHermiteStream.java new file mode 100644 index 000000000..8e08fe2ad --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TriHermiteStream.java @@ -0,0 +1,140 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.IrisInterpolation; + +public class TriHermiteStream extends BasicLayer implements ProceduralStream, Interpolator +{ + private final ProceduralStream stream; + private final int rx; + private final int ry; + private final int rz; + private final double tension; + private final double bias; + + public TriHermiteStream(ProceduralStream stream, int rx, int ry, int rz, double tension, double bias) + { + this.stream = stream; + this.rx = rx; + this.ry = ry; + this.rz = rz; + this.tension = tension; + this.bias = bias; + } + + public T interpolate(double x, double y, double z) + { + int fx = (int) Math.floor(x / rx); + int fy = (int) Math.floor(y / ry); + int fz = (int) Math.floor(z / rz); + int x0 = (int) Math.round((fx - 1) * rx); + int y0 = (int) Math.round((fy - 1) * ry); + int z0 = (int) Math.round((fz - 1) * rz); + int x1 = (int) Math.round(fx * rx); + int y1 = (int) Math.round(fy * ry); + int z1 = (int) Math.round(fz * rz); + int x2 = (int) Math.round((fx + 1) * rx); + int y2 = (int) Math.round((fy + 1) * ry); + int z2 = (int) Math.round((fz + 1) * rz); + int x3 = (int) Math.round((fx + 2) * rx); + int y3 = (int) Math.round((fy + 2) * ry); + int z3 = (int) Math.round((fz + 2) * rz); + double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x); + double py = IrisInterpolation.rangeScale(0, 1, y1, y2, y); + double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, z); + + //@builder + return stream.fromDouble(IrisInterpolation.trihermite( + stream.getDouble(x0, y0, z0), + stream.getDouble(x0, y0,z1), + stream.getDouble(x0, y0,z2), + stream.getDouble(x0, y0,z3), + stream.getDouble(x1, y0,z0), + stream.getDouble(x1, y0,z1), + stream.getDouble(x1, y0,z2), + stream.getDouble(x1, y0,z3), + stream.getDouble(x2, y0,z0), + stream.getDouble(x2, y0,z1), + stream.getDouble(x2, y0,z2), + stream.getDouble(x2, y0,z3), + stream.getDouble(x3, y0,z0), + stream.getDouble(x3, y0,z1), + stream.getDouble(x3, y0,z2), + stream.getDouble(x3, y0,z3), + stream.getDouble(x0, y1, z0), + stream.getDouble(x0, y1,z1), + stream.getDouble(x0, y1,z2), + stream.getDouble(x0, y1,z3), + stream.getDouble(x1, y1,z0), + stream.getDouble(x1, y1,z1), + stream.getDouble(x1, y1,z2), + stream.getDouble(x1, y1,z3), + stream.getDouble(x2, y1,z0), + stream.getDouble(x2, y1,z1), + stream.getDouble(x2, y1,z2), + stream.getDouble(x2, y1,z3), + stream.getDouble(x3, y1,z0), + stream.getDouble(x3, y1,z1), + stream.getDouble(x3, y1,z2), + stream.getDouble(x3, y1,z3), + stream.getDouble(x0, y2, z0), + stream.getDouble(x0, y2,z1), + stream.getDouble(x0, y2,z2), + stream.getDouble(x0, y2,z3), + stream.getDouble(x1, y2,z0), + stream.getDouble(x1, y2,z1), + stream.getDouble(x1, y2,z2), + stream.getDouble(x1, y2,z3), + stream.getDouble(x2, y2,z0), + stream.getDouble(x2, y2,z1), + stream.getDouble(x2, y2,z2), + stream.getDouble(x2, y2,z3), + stream.getDouble(x3, y2,z0), + stream.getDouble(x3, y2,z1), + stream.getDouble(x3, y2,z2), + stream.getDouble(x3, y2,z3), + stream.getDouble(x0, y3, z0), + stream.getDouble(x0, y3,z1), + stream.getDouble(x0, y3,z2), + stream.getDouble(x0, y3,z3), + stream.getDouble(x1, y3,z0), + stream.getDouble(x1, y3,z1), + stream.getDouble(x1, y3,z2), + stream.getDouble(x1, y3,z3), + stream.getDouble(x2, y3,z0), + stream.getDouble(x2, y3,z1), + stream.getDouble(x2, y3,z2), + stream.getDouble(x2, y3,z3), + stream.getDouble(x3, y3,z0), + stream.getDouble(x3, y3,z1), + stream.getDouble(x3, y3,z2), + stream.getDouble(x3, y3,z3), + px, pz, py, tension, bias)); + //@done + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return interpolate(x, 0, z); + } + + @Override + public T get(double x, double y, double z) + { + return interpolate(x, y, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TriStarcastStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TriStarcastStream.java new file mode 100644 index 000000000..4236f7e0a --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TriStarcastStream.java @@ -0,0 +1,60 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; + +public class TriStarcastStream extends BasicLayer implements ProceduralStream, Interpolator +{ + private ProceduralStream stream; + private int rad; + private int checks; + + public TriStarcastStream(ProceduralStream stream, int rad, int checks) + { + this.stream = stream; + this.rad = rad; + this.checks = checks; + } + + public T interpolate(double x, double y, double z) + { + double m = (360 / checks); + double v = 0; + + for(int i = 0; i < 360; i += m) + { + double sin = Math.sin(Math.toRadians(i)); + double cos = Math.cos(Math.toRadians(i)); + double cx = x + ((rad * cos) - (rad * sin)); + double cy = y + ((rad * sin) + (rad * cos)); + double cz = z + ((rad * cos) - (rad * sin)); + v += stream.getDouble(cx, cy, cz); + } + + return stream.fromDouble(v / checks); + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return interpolate(x, 0, z); + } + + @Override + public T get(double x, double y, double z) + { + return interpolate(x, y, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TricubicStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TricubicStream.java new file mode 100644 index 000000000..df43e9706 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TricubicStream.java @@ -0,0 +1,139 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.IrisInterpolation; + +public class TricubicStream extends BasicLayer implements ProceduralStream, Interpolator +{ + private final ProceduralStream stream; + private final int rx; + private final int ry; + private final int rz; + + public TricubicStream(ProceduralStream stream, int rx, int ry, int rz) + { + this.stream = stream; + this.rx = rx; + this.ry = ry; + this.rz = rz; + } + + public T interpolate(double x, double y, double z) + { + int fx = (int) Math.floor(x / rx); + int fy = (int) Math.floor(y / ry); + int fz = (int) Math.floor(z / rz); + int x0 = (int) Math.round((fx - 1) * rx); + int y0 = (int) Math.round((fy - 1) * ry); + int z0 = (int) Math.round((fz - 1) * rz); + int x1 = (int) Math.round(fx * rx); + int y1 = (int) Math.round(fy * ry); + int z1 = (int) Math.round(fz * rz); + int x2 = (int) Math.round((fx + 1) * rx); + int y2 = (int) Math.round((fy + 1) * ry); + int z2 = (int) Math.round((fz + 1) * rz); + int x3 = (int) Math.round((fx + 2) * rx); + int y3 = (int) Math.round((fy + 2) * ry); + int z3 = (int) Math.round((fz + 2) * rz); + double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x); + double py = IrisInterpolation.rangeScale(0, 1, y1, y2, y); + double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, z); + + //@builder + return stream.fromDouble(IrisInterpolation.tricubic( + stream.getDouble(x0, y0, z0), + stream.getDouble(x0, y0,z1), + stream.getDouble(x0, y0,z2), + stream.getDouble(x0, y0,z3), + stream.getDouble(x1, y0,z0), + stream.getDouble(x1, y0,z1), + stream.getDouble(x1, y0,z2), + stream.getDouble(x1, y0,z3), + stream.getDouble(x2, y0,z0), + stream.getDouble(x2, y0,z1), + stream.getDouble(x2, y0,z2), + stream.getDouble(x2, y0,z3), + stream.getDouble(x3, y0,z0), + stream.getDouble(x3, y0,z1), + stream.getDouble(x3, y0,z2), + stream.getDouble(x3, y0,z3), + + stream.getDouble(x0, y1, z0), + stream.getDouble(x0, y1,z1), + stream.getDouble(x0, y1,z2), + stream.getDouble(x0, y1,z3), + stream.getDouble(x1, y1,z0), + stream.getDouble(x1, y1,z1), + stream.getDouble(x1, y1,z2), + stream.getDouble(x1, y1,z3), + stream.getDouble(x2, y1,z0), + stream.getDouble(x2, y1,z1), + stream.getDouble(x2, y1,z2), + stream.getDouble(x2, y1,z3), + stream.getDouble(x3, y1,z0), + stream.getDouble(x3, y1,z1), + stream.getDouble(x3, y1,z2), + stream.getDouble(x3, y1,z3), + + stream.getDouble(x0, y2, z0), + stream.getDouble(x0, y2,z1), + stream.getDouble(x0, y2,z2), + stream.getDouble(x0, y2,z3), + stream.getDouble(x1, y2,z0), + stream.getDouble(x1, y2,z1), + stream.getDouble(x1, y2,z2), + stream.getDouble(x1, y2,z3), + stream.getDouble(x2, y2,z0), + stream.getDouble(x2, y2,z1), + stream.getDouble(x2, y2,z2), + stream.getDouble(x2, y2,z3), + stream.getDouble(x3, y2,z0), + stream.getDouble(x3, y2,z1), + stream.getDouble(x3, y2,z2), + stream.getDouble(x3, y2,z3), + + stream.getDouble(x0, y3, z0), + stream.getDouble(x0, y3,z1), + stream.getDouble(x0, y3,z2), + stream.getDouble(x0, y3,z3), + stream.getDouble(x1, y3,z0), + stream.getDouble(x1, y3,z1), + stream.getDouble(x1, y3,z2), + stream.getDouble(x1, y3,z3), + stream.getDouble(x2, y3,z0), + stream.getDouble(x2, y3,z1), + stream.getDouble(x2, y3,z2), + stream.getDouble(x2, y3,z3), + stream.getDouble(x3, y3,z0), + stream.getDouble(x3, y3,z1), + stream.getDouble(x3, y3,z2), + stream.getDouble(x3, y3,z3), + px, pz, py)); + //@done + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return interpolate(x, 0, z); + } + + @Override + public T get(double x, double y, double z) + { + return interpolate(x, y, z); + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TrilinearStream.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TrilinearStream.java new file mode 100644 index 000000000..39970cfc3 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/stream/TrilinearStream.java @@ -0,0 +1,74 @@ +package com.volmit.iris.gen.v2.scaffold.stream; + +import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer; +import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; +import com.volmit.iris.util.IrisInterpolation; + +public class TrilinearStream extends BasicLayer implements ProceduralStream, Interpolator +{ + private final ProceduralStream stream; + private final int rx; + private final int ry; + private final int rz; + + public TrilinearStream(ProceduralStream stream, int rx, int ry, int rz) + { + this.stream = stream; + this.rx = rx; + this.ry = ry; + this.rz = rz; + } + + public T interpolate(double x, double y, double z) + { + int fx = (int) Math.floor(x / rx); + int fy = (int) Math.floor(y / ry); + int fz = (int) Math.floor(z / rz); + int x1 = (int) Math.round(fx * rx); + int y1 = (int) Math.round(fy * ry); + int z1 = (int) Math.round(fz * rz); + int x2 = (int) Math.round((fx + 1) * rx); + int y2 = (int) Math.round((fy + 1) * ry); + int z2 = (int) Math.round((fz + 1) * rz); + double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x); + double py = IrisInterpolation.rangeScale(0, 1, y1, y2, y); + double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, z); + + //@builder + return stream.fromDouble(IrisInterpolation.trilerp( + stream.getDouble(x1, y1, z1), + stream.getDouble(x2, y1, z1), + stream.getDouble(x1, y1, z2), + stream.getDouble(x2, y1, z2), + stream.getDouble(x1, y2, z1), + stream.getDouble(x2, y2, z1), + stream.getDouble(x1, y2, z2), + stream.getDouble(x2, y2, z2), + px, pz, py)); + //@done + } + + @Override + public double toDouble(T t) + { + return stream.toDouble(t); + } + + @Override + public T fromDouble(double d) + { + return stream.fromDouble(d); + } + + @Override + public T get(double x, double z) + { + return interpolate(x, 0, z); + } + + @Override + public T get(double x, double y, double z) + { + return interpolate(x, y, z); + } +} diff --git a/src/main/java/com/volmit/iris/util/IrisInterpolation.java b/src/main/java/com/volmit/iris/util/IrisInterpolation.java index c21d8ce19..419e1bfa4 100644 --- a/src/main/java/com/volmit/iris/util/IrisInterpolation.java +++ b/src/main/java/com/volmit/iris/util/IrisInterpolation.java @@ -17,11 +17,6 @@ public class IrisInterpolation return sqt / (alpha * (sqt - Math.pow(t, alpha - 1)) + 1.0d); } - public static double lerp(double a, double b, double f) - { - return a + (f * (b - a)); - } - public static float lerpf(float a, float b, float f) { return a + (f * (b - a)); @@ -52,11 +47,6 @@ public class IrisInterpolation return a + (parametric(f, v) * (b - a)); } - public static double blerp(double a, double b, double c, double d, double tx, double ty) - { - return lerp(lerp(a, b, tx), lerp(c, d, tx), ty); - } - public static double blerp(double a, double b, double c, double d, double tx, double ty, InterpolationType type) { if(type.equals(InterpolationType.LINEAR)) @@ -107,76 +97,6 @@ public class IrisInterpolation return parametric(hermite(p0, p1, p2, p3, mu, tension, bias), a); } - public static double hermite(double p0, double p1, double p2, double p3, double mu, double tension, double bias) - { - double m0, m1, mu2, mu3; - double a0, a1, a2, a3; - - mu2 = mu * mu; - mu3 = mu2 * mu; - m0 = (p1 - p0) * (1 + bias) * (1 - tension) / 2; - m0 += (p2 - p1) * (1 - bias) * (1 - tension) / 2; - m1 = (p2 - p1) * (1 + bias) * (1 - tension) / 2; - m1 += (p3 - p2) * (1 - bias) * (1 - tension) / 2; - a0 = 2 * mu3 - 3 * mu2 + 1; - a1 = mu3 - 2 * mu2 + mu; - a2 = mu3 - mu2; - a3 = -2 * mu3 + 3 * mu2; - - return (a0 * p1 + a1 * m0 + a2 * m1 + a3 * p2); - } - - public static double bihermite(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias) - { - //@builder - return hermite( - hermite(p00, p01, p02, p03, muy, tension, bias), - hermite(p10, p11, p12, p13, muy, tension, bias), - hermite(p20, p21, p22, p23, muy, tension, bias), - hermite(p30, p31, p32, p33, muy, tension, bias), - mux, tension, bias); - //@done - } - - public static double trihermite(double p000, double p001, double p002, double p003, double p010, double p011, double p012, double p013, double p020, double p021, double p022, double p023, double p030, double p031, double p032, double p033, double p100, double p101, double p102, double p103, double p110, double p111, double p112, double p113, double p120, double p121, double p122, double p123, double p130, double p131, double p132, double p133, double p200, double p201, double p202, double p203, double p210, double p211, double p212, double p213, double p220, double p221, double p222, double p223, double p230, double p231, double p232, double p233, double p300, double p301, double p302, double p303, double p310, double p311, double p312, double p313, double p320, double p321, double p322, double p323, double p330, double p331, double p332, double p333, double mux, double muy, double muz, double tension, double bias) - { - //@builder - return hermite( - - hermite( - hermite(p000, p001, p002, p003, muy, tension, bias), - hermite(p010, p011, p012, p013, muy, tension, bias), - hermite(p020, p021, p022, p023, muy, tension, bias), - hermite(p030, p031, p032, p033, muy, tension, bias), - mux, tension, bias), - - hermite( - hermite(p100, p101, p102, p103, muy, tension, bias), - hermite(p110, p111, p112, p113, muy, tension, bias), - hermite(p120, p121, p122, p123, muy, tension, bias), - hermite(p130, p131, p132, p133, muy, tension, bias), - mux, tension, bias), - - hermite( - hermite(p200, p201, p202, p203, muy, tension, bias), - hermite(p210, p211, p212, p213, muy, tension, bias), - hermite(p220, p221, p222, p223, muy, tension, bias), - hermite(p230, p231, p232, p233, muy, tension, bias), - mux, tension, bias), - - hermite( - hermite(p300, p301, p302, p303, muy, tension, bias), - hermite(p310, p311, p312, p313, muy, tension, bias), - hermite(p320, p321, p322, p323, muy, tension, bias), - hermite(p330, p331, p332, p333, muy, tension, bias), - mux, tension, bias), - muz, - tension, - bias - ); - //@done - } - public static double bihermiteBezier(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias) { //@builder @@ -201,6 +121,35 @@ public class IrisInterpolation //@done } + public static double cubicBezier(double p0, double p1, double p2, double p3, double mu) + { + return bezier(cubic(p0, p1, p2, p3, mu)); + } + + public static double cubicParametric(double p0, double p1, double p2, double p3, double mu, double a) + { + return parametric(cubic(p0, p1, p2, p3, mu), a); + } + + public static double hermite(double p0, double p1, double p2, double p3, double mu, double tension, double bias) + { + double m0, m1, mu2, mu3; + double a0, a1, a2, a3; + + mu2 = mu * mu; + mu3 = mu2 * mu; + m0 = (p1 - p0) * (1 + bias) * (1 - tension) / 2; + m0 += (p2 - p1) * (1 - bias) * (1 - tension) / 2; + m1 = (p2 - p1) * (1 + bias) * (1 - tension) / 2; + m1 += (p3 - p2) * (1 - bias) * (1 - tension) / 2; + a0 = 2 * mu3 - 3 * mu2 + 1; + a1 = mu3 - 2 * mu2 + mu; + a2 = mu3 - mu2; + a3 = -2 * mu3 + 3 * mu2; + + return (a0 * p1 + a1 * m0 + a2 * m1 + a3 * p2); + } + public static double cubic(double p0, double p1, double p2, double p3, double mu) { double a0, a1, a2, a3, mu2; @@ -214,14 +163,9 @@ public class IrisInterpolation return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3; } - public static double cubicBezier(double p0, double p1, double p2, double p3, double mu) + public static double getTriStarcast(int x, int y, int z, double rad, double checks, NoiseProvider n) { - return bezier(cubic(p0, p1, p2, p3, mu)); - } - - public static double cubicParametric(double p0, double p1, double p2, double p3, double mu, double a) - { - return parametric(cubic(p0, p1, p2, p3, mu), a); + return (getStarcast(x, z, rad, checks, n) + getStarcast(x, y, rad, checks, n) + getStarcast(y, z, rad, checks, n)) / 3D; } public static double bicubic(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy) @@ -236,6 +180,89 @@ public class IrisInterpolation //@done } + public static double bihermite(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias) + { + //@builder + return hermite( + hermite(p00, p01, p02, p03, muy, tension, bias), + hermite(p10, p11, p12, p13, muy, tension, bias), + hermite(p20, p21, p22, p23, muy, tension, bias), + hermite(p30, p31, p32, p33, muy, tension, bias), + mux, tension, bias); + //@done + } + + public static double trihermite(double p000, double p001, double p002, double p003, double p010, double p011, double p012, double p013, double p020, double p021, double p022, double p023, double p030, double p031, double p032, double p033, double p100, double p101, double p102, double p103, double p110, double p111, double p112, double p113, double p120, double p121, double p122, double p123, double p130, double p131, double p132, double p133, double p200, double p201, double p202, double p203, double p210, double p211, double p212, double p213, double p220, double p221, double p222, double p223, double p230, double p231, double p232, double p233, double p300, double p301, double p302, double p303, double p310, double p311, double p312, double p313, double p320, double p321, double p322, double p323, double p330, double p331, double p332, double p333, double mux, double muy, double muz, double tension, double bias) + { + //@builder + return hermite( + bihermite(p000, p001, p002, p003, + p010, p011, p012, p013, + p020, p021, p022, p023, + p030, p031, p032, p033, + mux, muy, tension, bias), + bihermite(p100, p101, p102, p103, + p110, p111, p112, p113, + p120, p121, p122, p123, + p130, p131, p132, p133, + mux, muy, tension, bias), + bihermite(p200, p201, p202, p203, + p210, p211, p212, p213, + p220, p221, p222, p223, + p230, p231, p232, p233, + mux, muy, tension, bias), + bihermite(p300, p301, p302, p303, + p310, p311, p312, p313, + p320, p321, p322, p323, + p330, p331, p332, p333, + mux, muy, tension, bias), + muz, tension, bias); + //@done + } + + public static double tricubic(double p000, double p001, double p002, double p003, double p010, double p011, double p012, double p013, double p020, double p021, double p022, double p023, double p030, double p031, double p032, double p033, double p100, double p101, double p102, double p103, double p110, double p111, double p112, double p113, double p120, double p121, double p122, double p123, double p130, double p131, double p132, double p133, double p200, double p201, double p202, double p203, double p210, double p211, double p212, double p213, double p220, double p221, double p222, double p223, double p230, double p231, double p232, double p233, double p300, double p301, double p302, double p303, double p310, double p311, double p312, double p313, double p320, double p321, double p322, double p323, double p330, double p331, double p332, double p333, double mux, double muy, double muz) + { + //@builder + return cubic( + bicubic(p000, p001, p002, p003, + p010, p011, p012, p013, + p020, p021, p022, p023, + p030, p031, p032, p033, + mux, muy), + bicubic(p100, p101, p102, p103, + p110, p111, p112, p113, + p120, p121, p122, p123, + p130, p131, p132, p133, + mux, muy), + bicubic(p200, p201, p202, p203, + p210, p211, p212, p213, + p220, p221, p222, p223, + p230, p231, p232, p233, + mux, muy), + bicubic(p300, p301, p302, p303, + p310, p311, p312, p313, + p320, p321, p322, p323, + p330, p331, p332, p333, + mux, muy), + muz); + //@done + } + + public static double lerp(double a, double b, double f) + { + return a + (f * (b - a)); + } + + public static double blerp(double a, double b, double c, double d, double tx, double ty) + { + return lerp(lerp(a, b, tx), lerp(c, d, tx), ty); + } + + public static double trilerp(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double x, double y, double z) + { + return lerp(blerp(v1, v2, v3, v4, x, y), blerp(v5, v6, v7, v8, x, y), z); + } + public static double bicubicBezier(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy) { //@builder @@ -260,11 +287,6 @@ public class IrisInterpolation //@done } - public static double trilerp(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double x, double y, double z) - { - return lerp(blerp(v1, v2, v3, v4, x, y), blerp(v5, v6, v7, v8, x, y), z); - } - public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG()); public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n) @@ -275,7 +297,7 @@ public class IrisInterpolation int z1 = (int) Math.round(fz * rad); int x2 = (int) Math.round((fx + 1) * rad); int z2 = (int) Math.round((fz + 1) * rad); - + double px = rangeScale(0, 1, x1, x2, x); double pz = rangeScale(0, 1, z1, z2, z); //@builder diff --git a/src/main/java/com/volmit/iris/util/KList.java b/src/main/java/com/volmit/iris/util/KList.java index 3df3907e5..3647b2348 100644 --- a/src/main/java/com/volmit/iris/util/KList.java +++ b/src/main/java/com/volmit/iris/util/KList.java @@ -681,12 +681,15 @@ public class KList extends ArrayList implements List return m; } - public void addIfMissing(T t) + public boolean addIfMissing(T t) { if(!contains(t)) { add(t); + return true; } + + return false; } public void addAllIfMissing(KList t)