This commit is contained in:
CocoTheOwner 2020-10-25 16:44:31 +01:00
commit 2b8e189966
26 changed files with 1500 additions and 311 deletions

View File

@ -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<T> implements Hunk<T>
{
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<T> src;
public HunkView(Hunk<T> src)
{
this(src, src.getWidth(), src.getHeight(), src.getDepth());
}
public HunkView(Hunk<T> src, int w, int h, int d)
{
this(src, w, h, d, 0, 0, 0);
}
public HunkView(Hunk<T> 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<T> croppedView(int x1, int y1, int z1, int x2, int y2, int z2)
{
return new HunkView<T>(this, x2 - x1, y2 - y1, z2 - z1, x1 + ox, y1 + oy, z1 + oz);
}
@Override
public ArrayHunk<T> crop(int x1, int y1, int z1, int x2, int y2, int z2)
{
ArrayHunk<T> h = new ArrayHunk<T>(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<T> 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<T> 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<T> getSource()
{
return src;
}
}

View File

@ -1,14 +1,19 @@
package com.volmit.iris.gen.v2; 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.Iris;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; 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.manager.IrisDataManager;
import com.volmit.iris.object.InferredType; import com.volmit.iris.object.InferredType;
import com.volmit.iris.object.IrisBiome; 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.IrisDimension;
import com.volmit.iris.object.IrisGenerator;
import com.volmit.iris.object.IrisRegion; 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.M;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
@ -18,14 +23,19 @@ import lombok.Data;
public class IrisComplex implements DataProvider public class IrisComplex implements DataProvider
{ {
private IrisDataManager data; private IrisDataManager data;
private KList<IrisGenerator> generators;
private static final BlockData AIR = Material.AIR.createBlockData();
private ProceduralStream<IrisRegion> regionStream; private ProceduralStream<IrisRegion> regionStream;
private ProceduralStream<InferredType> bridgeStream; private ProceduralStream<InferredType> bridgeStream;
private ProceduralStream<IrisBiome> landBiomeStream; private ProceduralStream<IrisBiome> landBiomeStream;
private ProceduralStream<IrisBiome> seaBiomeStream; private ProceduralStream<IrisBiome> seaBiomeStream;
private ProceduralStream<IrisBiome> shoreBiomeStream; private ProceduralStream<IrisBiome> shoreBiomeStream;
private ProceduralStream<IrisBiome> baseBiomeStream; private ProceduralStream<IrisBiome> baseBiomeStream;
private ProceduralStream<IrisBiome> trueBiomeStream;
private ProceduralStream<Double> heightStream; private ProceduralStream<Double> heightStream;
private ProceduralStream<Double> heightMinStream; private ProceduralStream<BlockData> terrainStream;
private ProceduralStream<BlockData> rockStream;
private ProceduralStream<BlockData> fluidStream;
public IrisComplex() public IrisComplex()
{ {
@ -60,53 +70,177 @@ public class IrisComplex implements DataProvider
public void flash(long seed, IrisDimension dimension, IrisDataManager data) public void flash(long seed, IrisDimension dimension, IrisDataManager data)
{ {
this.data = data; this.data = data;
double fluidHeight = dimension.getFluidHeight();
generators = new KList<>();
RNG rng = new RNG(seed); RNG rng = new RNG(seed);
//@builder //@builder
regionStream = NoiseStyle.CELLULAR.stream(rng.nextRNG()) dimension.getRegions().forEach((i) -> data.getRegionLoader().load(i)
.zoom(4) .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()) .select(dimension.getRegions())
.convertCached((s) -> data.getRegionLoader().load(s)); .convertCached((s) -> data.getRegionLoader().load(s))
.cache2D(1024);
landBiomeStream = regionStream.convertCached((r) landBiomeStream = regionStream.convertCached((r)
-> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 10000 * r.getLandBiomeZoom()))) -> dimension.getLandBiomeStyle().create(rng.nextRNG()).stream()
.zoom(r.getLandBiomeZoom()) .zoom(r.getLandBiomeZoom())
.select(r.getLandBiomes()) .select(r.getLandBiomes())
.convertCached((s) -> data.getBiomeLoader().load(s)) .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) seaBiomeStream = regionStream.convertCached((r)
-> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 20000 * r.getSeaBiomeZoom()))) -> dimension.getSeaBiomeStyle().create(rng.nextRNG()).stream()
.zoom(r.getSeaBiomeZoom()) .zoom(r.getSeaBiomeZoom())
.select(r.getSeaBiomes()) .select(r.getSeaBiomes())
.convertCached((s) -> data.getBiomeLoader().load(s)) .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) shoreBiomeStream = regionStream.convertCached((r)
-> NoiseStyle.CELLULAR.stream(new RNG((long) (seed + 30000 * r.getShoreBiomeZoom()))) -> dimension.getShoreBiomeStyle().create(rng.nextRNG()).stream()
.zoom(r.getShoreBiomeZoom()) .zoom(r.getShoreBiomeZoom())
.select(r.getShoreBiomes()) .select(r.getShoreBiomes())
.convertCached((s) -> data.getBiomeLoader().load(s)) .convertCached((s) -> data.getBiomeLoader().load(s))
).convertAware2D((str, x, z) -> str.get(x, z)); ).convertAware2D((str, x, z) -> str.get(x, z))
bridgeStream = NoiseStyle.CELLULAR.stream(new RNG(seed + 4000)) .cache2D(1024);
bridgeStream = dimension.getContinentalStyle().create(rng.nextRNG()).stream()
.convert((v) -> v >= dimension.getLandChance() ? InferredType.SEA : InferredType.LAND); .convert((v) -> v >= dimension.getLandChance() ? InferredType.SEA : InferredType.LAND);
baseBiomeStream = bridgeStream.convertAware2D((t, x, z) -> t.equals(InferredType.SEA) baseBiomeStream = bridgeStream.convertAware2D((t, x, z) -> t.equals(InferredType.SEA)
? seaBiomeStream.get(x, z) : landBiomeStream.get(x, z)); ? seaBiomeStream.get(x, z) : landBiomeStream.get(x, z))
heightStream = baseBiomeStream.convertAware2D((b, x, z) -> { .cache2D(1024);
double h = 0; heightStream = baseBiomeStream.convertAware2D((b, x, z) -> getHeight(b, x, z, seed))
for(IrisBiomeGeneratorLink i : b.getGenerators()) .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<BlockData>()
{
@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 try
{ {
h += i.getHeight(this, x, z, seed); IrisBiome bx = baseBiomeStream.get(xx, zz);
return bx.getGenLinkMax(gen.getLoadKey());
} }
catch(Throwable e) 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; generators.add(cachedGenerator);
}).forceDouble().interpolate().starcast9(12).into().bihermite(4, 0.01, 0);
//@done
} }
} }

View File

@ -35,7 +35,7 @@ public class IrisTerrainGenerator
public ProceduralStream<Double> height = NoiseStyle.CELLULAR public ProceduralStream<Double> height = NoiseStyle.CELLULAR
.stream(69) .stream(69)
.fit(1, 69) .fit(1, 69)
.interpolate().starcast9(4).into().bilinear(4) .interpolate().bistarcast9(4).into().bilinear(4)
; ;
public ProceduralStream<BlockData> rock = NoiseStyle.STATIC public ProceduralStream<BlockData> rock = NoiseStyle.STATIC
@ -46,6 +46,6 @@ public class IrisTerrainGenerator
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes) public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes)
{ {
RNG rng = new RNG((((long) x) << 32) | (z & 0xffffffffL)); 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());
} }
} }

View File

@ -2,8 +2,6 @@ package com.volmit.iris.gen.v2;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -14,8 +12,8 @@ import org.bukkit.generator.ChunkGenerator;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.gen.v2.scaffold.Hunk; import com.volmit.iris.gen.v2.scaffold.Hunk;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; import com.volmit.iris.util.Form;
import com.volmit.iris.object.NoiseStyle; import com.volmit.iris.util.PrecisionStopwatch;
public class TestGen public class TestGen
{ {
@ -24,12 +22,20 @@ public class TestGen
p.teleport(new WorldCreator("t/" + UUID.randomUUID().toString()).generator(new ChunkGenerator() p.teleport(new WorldCreator("t/" + UUID.randomUUID().toString()).generator(new ChunkGenerator()
{ {
IrisTerrainGenerator tg = new IrisTerrainGenerator(1337, Iris.globaldata.getDimensionLoader().load("overworld"), Iris.globaldata); IrisTerrainGenerator tg = new IrisTerrainGenerator(1337, Iris.globaldata.getDimensionLoader().load("overworld"), Iris.globaldata);
BlockData st = Material.STONE.createBlockData();
public boolean isParallelCapable()
{
return true;
}
@Override @Override
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
{ {
PrecisionStopwatch p = PrecisionStopwatch.start();
ChunkData c = createChunkData(world); ChunkData c = createChunkData(world);
tg.generate(x, z, Hunk.view(c), null); tg.generate(x, z, Hunk.view(c), null);
Iris.info("Generated " + x + " " + z + " in " + Form.duration(p.getMilliseconds(), 2));
return c; return c;
} }
}).createWorld().getSpawnLocation()); }).createWorld().getSpawnLocation());

View File

@ -0,0 +1,61 @@
package com.volmit.iris.gen.v2.scaffold;
import com.volmit.iris.util.KList;
public class ArraySignificance<T> implements Significance<T>
{
private final KList<T> types;
private final KList<Double> significance;
private final T significant;
public ArraySignificance(KList<T> types, KList<Double> significance, T significant)
{
this.types = types;
this.significance = significance;
this.significant = significant;
}
public ArraySignificance(KList<T> types, KList<Double> 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<T> 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;
}
}

View File

@ -0,0 +1,12 @@
package com.volmit.iris.gen.v2.scaffold;
import com.volmit.iris.util.KList;
public interface Significance<T>
{
public KList<T> getFactorTypes();
public double getSignificance(T t);
public T getMostSignificantType();
}

View File

@ -4,34 +4,160 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import com.volmit.iris.gen.v2.scaffold.Hunk; 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.AwareConversionStream2D;
import com.volmit.iris.gen.v2.scaffold.stream.AwareConversionStream3D; 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.CachedConversionStream;
import com.volmit.iris.gen.v2.scaffold.stream.CachedStream2D; 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.ClampedStream;
import com.volmit.iris.gen.v2.scaffold.stream.ConversionStream; 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.FittedStream;
import com.volmit.iris.gen.v2.scaffold.stream.ForceDoubleStream; 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.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.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.RoundingStream;
import com.volmit.iris.gen.v2.scaffold.stream.SelectionStream; 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.gen.v2.scaffold.stream.ZoomStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3; import com.volmit.iris.util.Function3;
import com.volmit.iris.util.Function4; import com.volmit.iris.util.Function4;
public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
{ {
public static ProceduralStream<Double> ofDouble(Function2<Double, Double, Double> f)
{
return of(f, Interpolated.DOUBLE);
}
public static ProceduralStream<Double> ofDouble(Function3<Double, Double, Double, Double> f)
{
return of(f, Interpolated.DOUBLE);
}
public static <T> ProceduralStream<T> of(Function2<Double, Double, T> f, Interpolated<T> helper)
{
return of(f, (x, y, z) -> f.apply(x, z), helper);
}
public static <T> ProceduralStream<T> of(Function3<Double, Double, Double, T> f, Interpolated<T> helper)
{
return of((x, z) -> f.apply(x, 0D, z), f, helper);
}
public static <T> ProceduralStream<T> of(Function2<Double, Double, T> f, Function3<Double, Double, Double, T> f2, Interpolated<T> helper)
{
return new FunctionStream<>(f, f2, helper);
}
default ProceduralStream<T> add(Function3<Double, Double, Double, Double> a)
{
return new AddingStream<>(this, a);
}
default ProceduralStream<T> add(Function2<Double, Double, Double> a)
{
return new AddingStream<>(this, a);
}
default ProceduralStream<T> add(double a)
{
return new AddingStream<>(this, a);
}
default ProceduralStream<T> subtract(Function3<Double, Double, Double, Double> a)
{
return new SubtractingStream<>(this, a);
}
default ProceduralStream<T> subtract(Function2<Double, Double, Double> a)
{
return new SubtractingStream<>(this, a);
}
default ProceduralStream<T> subtract(double a)
{
return new SubtractingStream<>(this, a);
}
default ProceduralStream<T> multiply(Function3<Double, Double, Double, Double> a)
{
return new MultiplyingStream<>(this, a);
}
default ProceduralStream<T> multiply(Function2<Double, Double, Double> a)
{
return new MultiplyingStream<>(this, a);
}
default ProceduralStream<T> multiply(double a)
{
return new MultiplyingStream<>(this, a);
}
default ProceduralStream<T> divide(Function3<Double, Double, Double, Double> a)
{
return new DividingStream<>(this, a);
}
default ProceduralStream<T> divide(Function2<Double, Double, Double> a)
{
return new DividingStream<>(this, a);
}
default ProceduralStream<T> divide(double a)
{
return new DividingStream<>(this, a);
}
default ProceduralStream<T> modulo(Function3<Double, Double, Double, Double> a)
{
return new ModuloStream<>(this, a);
}
default ProceduralStream<T> modulo(Function2<Double, Double, Double> a)
{
return new ModuloStream<>(this, a);
}
default ProceduralStream<T> modulo(double a)
{
return new ModuloStream<>(this, a);
}
default ProceduralStream<Integer> round() default ProceduralStream<Integer> round()
{ {
return new RoundingStream(this); return new RoundingStream(this);
} }
default ProceduralStream<Double> roundDouble()
{
return new RoundingDoubleStream(this);
}
default ProceduralStream<T> forceDouble() default ProceduralStream<T> forceDouble()
{ {
return new ForceDoubleStream<T>(this); return new ForceDoubleStream<T>(this);
} }
default ProceduralStream<Significance<T>> significance(double radius, int checks)
{
return new SignificanceStream<Significance<T>, T>(this, radius, checks);
}
default ProceduralStream<T> to3D()
{
return new To3DStream<T>(this);
}
default ProceduralStream<T> cache2D(int maxSize) default ProceduralStream<T> cache2D(int maxSize)
{ {
return new CachedStream2D<T>(this, maxSize); return new CachedStream2D<T>(this, maxSize);

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final Function3<Double, Double, Double, Double> add;
public AddingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add)
{
super();
this.stream = stream;
this.add = add;
}
public AddingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add)
{
this(stream, (x, y, z) -> add.apply(x, z));
}
public AddingStream(ProceduralStream<T> 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));
}
}

View File

@ -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.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class StarcastStream<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T> public class BiStarcastStream<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{ {
private ProceduralStream<T> stream; private ProceduralStream<T> stream;
private int rad; private int rad;
private int checks; private int checks;
public StarcastStream(ProceduralStream<T> stream, int rad, int checks) public BiStarcastStream(ProceduralStream<T> stream, int rad, int checks)
{ {
this.stream = stream; this.stream = stream;
this.rad = rad; this.rad = rad;

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final Function3<Double, Double, Double, Double> add;
public DividingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add)
{
super();
this.stream = stream;
this.add = add;
}
public DividingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add)
{
this(stream, (x, y, z) -> add.apply(x, z));
}
public DividingStream(ProceduralStream<T> 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));
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private Function2<Double, Double, T> f2;
private Function3<Double, Double, Double, T> f3;
private Interpolated<T> helper;
public FunctionStream(Function2<Double, Double, T> f2, Function3<Double, Double, Double, T> f3, Interpolated<T> 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);
}
}

View File

@ -1,9 +1,15 @@
package com.volmit.iris.gen.v2.scaffold.stream; package com.volmit.iris.gen.v2.scaffold.stream;
import java.util.function.Function;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public interface Interpolated<T> public interface Interpolated<T>
{ {
public static final Interpolated<Double> DOUBLE = of((t) -> t, (t) -> t);
public static final Interpolated<Integer> INT = of((t) -> Double.valueOf(t), (t) -> t.intValue());
public static final Interpolated<Long> LONG = of((t) -> Double.valueOf(t), (t) -> t.longValue());
public double toDouble(T t); public double toDouble(T t);
public T fromDouble(double d); public T fromDouble(double d);
@ -17,4 +23,22 @@ public interface Interpolated<T>
return null; return null;
} }
public static <T> Interpolated<T> of(Function<T, Double> a, Function<Double, T> b)
{
return new Interpolated<T>()
{
@Override
public double toDouble(T t)
{
return a.apply(t);
}
@Override
public T fromDouble(double d)
{
return b.apply(d);
}
};
}
} }

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final InterpolationMethod type;
private final NoiseProvider np;
private final int rx;
public InterpolatingStream(ProceduralStream<T> 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);
}
}

View File

@ -1,6 +1,7 @@
package com.volmit.iris.gen.v2.scaffold.stream; package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream; import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
import com.volmit.iris.object.InterpolationMethod;
public class InterpolatorFactory<T> public class InterpolatorFactory<T>
{ {
@ -11,6 +12,21 @@ public class InterpolatorFactory<T>
this.stream = stream; this.stream = stream;
} }
public InterpolatingStream<T> with(InterpolationMethod t, int rx)
{
return new InterpolatingStream<T>(stream, rx, t);
}
public TrilinearStream<T> trilinear(int rx, int ry, int rz)
{
return new TrilinearStream<>(stream, rx, ry, rz);
}
public TricubicStream<T> tricubic(int rx, int ry, int rz)
{
return new TricubicStream<>(stream, rx, ry, rz);
}
public BicubicStream<T> bicubic(int rx, int ry) public BicubicStream<T> bicubic(int rx, int ry)
{ {
return new BicubicStream<>(stream, rx, ry); return new BicubicStream<>(stream, rx, ry);
@ -31,24 +47,44 @@ public class InterpolatorFactory<T>
return bilinear(r, r); return bilinear(r, r);
} }
public StarcastStream<T> starcast(int radius, int checks) public TriStarcastStream<T> tristarcast(int radius, int checks)
{ {
return new StarcastStream<>(stream, radius, checks); return new TriStarcastStream<>(stream, radius, checks);
} }
public StarcastStream<T> starcast3(int radius) public TriStarcastStream<T> tristarcast3(int radius)
{ {
return starcast(radius, 3); return tristarcast(radius, 3);
} }
public StarcastStream<T> starcast6(int radius) public TriStarcastStream<T> tristarcast6(int radius)
{ {
return starcast(radius, 6); return tristarcast(radius, 6);
} }
public StarcastStream<T> starcast9(int radius) public TriStarcastStream<T> tristarcast9(int radius)
{ {
return starcast(radius, 9); return tristarcast(radius, 9);
}
public BiStarcastStream<T> bistarcast(int radius, int checks)
{
return new BiStarcastStream<>(stream, radius, checks);
}
public BiStarcastStream<T> bistarcast3(int radius)
{
return bistarcast(radius, 3);
}
public BiStarcastStream<T> bistarcast6(int radius)
{
return bistarcast(radius, 6);
}
public BiStarcastStream<T> bistarcast9(int radius)
{
return bistarcast(radius, 9);
} }
public BiHermiteStream<T> bihermite(int rx, int ry, double tension, double bias) public BiHermiteStream<T> bihermite(int rx, int ry, double tension, double bias)

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final Function3<Double, Double, Double, Double> add;
public ModuloStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add)
{
super();
this.stream = stream;
this.add = add;
}
public ModuloStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add)
{
this(stream, (x, y, z) -> add.apply(x, z));
}
public ModuloStream(ProceduralStream<T> 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));
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final Function3<Double, Double, Double, Double> add;
public MultiplyingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add)
{
super();
this.stream = stream;
this.add = add;
}
public MultiplyingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add)
{
this(stream, (x, y, z) -> add.apply(x, z));
}
public MultiplyingStream(ProceduralStream<T> 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));
}
}

View File

@ -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<Double>
{
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));
}
}

View File

@ -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<K extends Significance<T>, T> extends BasicLayer implements ProceduralStream<K>
{
private final ProceduralStream<T> stream;
private final double radius;
private final int checks;
public SignificanceStream(ProceduralStream<T> 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<T> ke = new KList<>(8);
KList<Double> va = new KList<Double>(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<T>(ke, va);
}
@Override
public K get(double x, double y, double z)
{
return get(x, z);
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final Function3<Double, Double, Double, Double> add;
public SubtractingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add)
{
super();
this.stream = stream;
this.add = add;
}
public SubtractingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add)
{
this(stream, (x, y, z) -> add.apply(x, z));
}
public SubtractingStream(ProceduralStream<T> 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));
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
public To3DStream(ProceduralStream<T> 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);
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final int rx;
private final int ry;
private final int rz;
private final double tension;
private final double bias;
public TriHermiteStream(ProceduralStream<T> 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);
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private ProceduralStream<T> stream;
private int rad;
private int checks;
public TriStarcastStream(ProceduralStream<T> 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);
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final int rx;
private final int ry;
private final int rz;
public TricubicStream(ProceduralStream<T> 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);
}
}

View File

@ -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<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final int rx;
private final int ry;
private final int rz;
public TrilinearStream(ProceduralStream<T> 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);
}
}

View File

@ -17,11 +17,6 @@ public class IrisInterpolation
return sqt / (alpha * (sqt - Math.pow(t, alpha - 1)) + 1.0d); 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) public static float lerpf(float a, float b, float f)
{ {
return a + (f * (b - a)); return a + (f * (b - a));
@ -52,11 +47,6 @@ public class IrisInterpolation
return a + (parametric(f, v) * (b - a)); 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) public static double blerp(double a, double b, double c, double d, double tx, double ty, InterpolationType type)
{ {
if(type.equals(InterpolationType.LINEAR)) if(type.equals(InterpolationType.LINEAR))
@ -107,76 +97,6 @@ public class IrisInterpolation
return parametric(hermite(p0, p1, p2, p3, mu, tension, bias), a); 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) 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 //@builder
@ -201,6 +121,35 @@ public class IrisInterpolation
//@done //@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) public static double cubic(double p0, double p1, double p2, double p3, double mu)
{ {
double a0, a1, a2, a3, mu2; double a0, a1, a2, a3, mu2;
@ -214,14 +163,9 @@ public class IrisInterpolation
return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3; 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)); return (getStarcast(x, z, rad, checks, n) + getStarcast(x, y, rad, checks, n) + getStarcast(y, z, rad, checks, n)) / 3D;
}
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 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) 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 //@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) 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 //@builder
@ -260,11 +287,6 @@ public class IrisInterpolation
//@done //@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 CNG cng = NoiseStyle.SIMPLEX.create(new RNG());
public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n) public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n)

View File

@ -681,12 +681,15 @@ public class KList<T> extends ArrayList<T> implements List<T>
return m; return m;
} }
public void addIfMissing(T t) public boolean addIfMissing(T t)
{ {
if(!contains(t)) if(!contains(t))
{ {
add(t); add(t);
return true;
} }
return false;
} }
public void addAllIfMissing(KList<T> t) public void addAllIfMissing(KList<T> t)