mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Cavern json objects
This commit is contained in:
parent
f682d7489f
commit
d826f968b5
@ -25,6 +25,8 @@ import com.volmit.iris.engine.object.annotations.Desc;
|
|||||||
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||||
import com.volmit.iris.engine.object.annotations.MinNumber;
|
import com.volmit.iris.engine.object.annotations.MinNumber;
|
||||||
import com.volmit.iris.engine.object.annotations.Required;
|
import com.volmit.iris.engine.object.annotations.Required;
|
||||||
|
import com.volmit.iris.engine.stream.ProceduralStream;
|
||||||
|
import com.volmit.iris.engine.stream.interpolation.Interpolated;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -62,6 +64,8 @@ public class IrisCarveLayer {
|
|||||||
@Desc("The threshold used as: \n\ncarved = noise(x,y,z) > threshold")
|
@Desc("The threshold used as: \n\ncarved = noise(x,y,z) > threshold")
|
||||||
private double threshold = 0.5;
|
private double threshold = 0.5;
|
||||||
|
|
||||||
|
private final transient AtomicCache<ProceduralStream<Boolean>> streamCache = new AtomicCache<>();
|
||||||
|
private final transient AtomicCache<ProceduralStream<Double>> rawStreamCache = new AtomicCache<>();
|
||||||
private final transient AtomicCache<CNG> cng = new AtomicCache<>();
|
private final transient AtomicCache<CNG> cng = new AtomicCache<>();
|
||||||
|
|
||||||
public boolean isCarved(RNG rng, double x, double y, double z) {
|
public boolean isCarved(RNG rng, double x, double y, double z) {
|
||||||
@ -70,7 +74,24 @@ public class IrisCarveLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double opacity = Math.pow(IrisInterpolation.sinCenter(M.lerpInverse(getMinHeight(), getMaxHeight(), y)), 4);
|
double opacity = Math.pow(IrisInterpolation.sinCenter(M.lerpInverse(getMinHeight(), getMaxHeight(), y)), 4);
|
||||||
return cng.aquire(() -> getStyle().create(rng.nextParallelRNG(-2340 * getMaxHeight() * getMinHeight()))).fitDouble(0D, 1D, x, y, z) * opacity > getThreshold();
|
return getCng(rng).fitDouble(0D, 1D, x, y, z) * opacity > getThreshold();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProceduralStream<Boolean> stream(RNG rng)
|
||||||
|
{
|
||||||
|
return streamCache.aquire(() -> ProceduralStream.of((x,y,z) -> isCarved(rng, x,y,z), Interpolated.BOOLEAN));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProceduralStream<Double> rawStream(RNG rng)
|
||||||
|
{
|
||||||
|
return rawStreamCache.aquire(() -> ProceduralStream.of((x,y,z) -> {
|
||||||
|
return getCng(rng).fitDouble(0D, 1D, x, y, z) * Math.pow(IrisInterpolation.sinCenter(M.lerpInverse(getMinHeight(), getMaxHeight(), y)), 4);
|
||||||
|
}, Interpolated.DOUBLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CNG getCng(RNG rng)
|
||||||
|
{
|
||||||
|
return cng.aquire(() -> getStyle().create(rng.nextParallelRNG(-2340 * getMaxHeight() * getMinHeight())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCarved2(RNG rng, double x, double y, double z) {
|
public boolean isCarved2(RNG rng, double x, double y, double z) {
|
||||||
|
@ -18,11 +18,13 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.object;
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.cache.AtomicCache;
|
||||||
import com.volmit.iris.engine.hunk.Hunk;
|
import com.volmit.iris.engine.hunk.Hunk;
|
||||||
import com.volmit.iris.engine.object.annotations.Desc;
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||||
import com.volmit.iris.engine.object.annotations.MinNumber;
|
import com.volmit.iris.engine.object.annotations.MinNumber;
|
||||||
import com.volmit.iris.engine.object.common.IRare;
|
import com.volmit.iris.engine.object.common.IRare;
|
||||||
|
import com.volmit.iris.engine.stream.ProceduralStream;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -48,6 +50,8 @@ public class IrisCavernZone implements IRare {
|
|||||||
@MaxNumber(100)
|
@MaxNumber(100)
|
||||||
private int rarity = 1;
|
private int rarity = 1;
|
||||||
|
|
||||||
|
private AtomicCache<ProceduralStream<Boolean>> carveCache = new AtomicCache<>();
|
||||||
|
|
||||||
public boolean isCarved(RNG rng, double xx, double yy, double zz) {
|
public boolean isCarved(RNG rng, double xx, double yy, double zz) {
|
||||||
if(carver != null)
|
if(carver != null)
|
||||||
{
|
{
|
||||||
@ -56,4 +60,13 @@ public class IrisCavernZone implements IRare {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getCarved(RNG rng, double xx, double yy, double zz) {
|
||||||
|
if(carver != null)
|
||||||
|
{
|
||||||
|
return carver.rawStream(rng).get(xx,yy,zz) / (carver.getThreshold() * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,9 @@ import com.volmit.iris.engine.cache.AtomicCache;
|
|||||||
import com.volmit.iris.engine.hunk.Hunk;
|
import com.volmit.iris.engine.hunk.Hunk;
|
||||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
import com.volmit.iris.engine.object.common.IRare;
|
|
||||||
import com.volmit.iris.engine.stream.ProceduralStream;
|
import com.volmit.iris.engine.stream.ProceduralStream;
|
||||||
|
import com.volmit.iris.engine.stream.interpolation.Interpolated;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.math.M;
|
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -54,7 +53,11 @@ public class IrisCaverns {
|
|||||||
@Desc("Threshold defined")
|
@Desc("Threshold defined")
|
||||||
private double topBleed = 16;
|
private double topBleed = 16;
|
||||||
|
|
||||||
|
@Desc("If set to true (default) iris will interpolate the noise before checking if it meets the threshold.")
|
||||||
|
private boolean preThresholdInterpolation = true;
|
||||||
|
|
||||||
private transient AtomicCache<ProceduralStream<IrisCavernZone>> zonesRarity = new AtomicCache<>();
|
private transient AtomicCache<ProceduralStream<IrisCavernZone>> zonesRarity = new AtomicCache<>();
|
||||||
|
private transient AtomicCache<ProceduralStream<Double>> streamCache = new AtomicCache<>();
|
||||||
|
|
||||||
public IrisCavernZone getZone(double x, double y, double z, RNG rng)
|
public IrisCavernZone getZone(double x, double y, double z, RNG rng)
|
||||||
{
|
{
|
||||||
@ -62,36 +65,34 @@ public class IrisCaverns {
|
|||||||
.stream().selectRarity(getZones())).get(x,y,z);
|
.stream().selectRarity(getZones())).get(x,y,z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double threshold(double y, double th)
|
private double threshold(double y)
|
||||||
{
|
{
|
||||||
double m = 0;
|
return 0.5;
|
||||||
double a = 0;
|
|
||||||
double top = th - topBleed;
|
|
||||||
double bot = 0 + bottomBleed;
|
|
||||||
|
|
||||||
if(y >= top && y <= th)
|
|
||||||
{
|
|
||||||
m++;
|
|
||||||
a+= IrisInterpolation.lerpBezier(1, 0, M.lerpInverse(top, th, y));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(y <= bottomBleed && y >= 0)
|
public ProceduralStream<Double> stream(RNG rng)
|
||||||
{
|
{
|
||||||
m++;
|
if(preThresholdInterpolation)
|
||||||
a+= IrisInterpolation.lerpBezier(1, 0, M.lerpInverse(top, th, y));
|
{
|
||||||
|
return streamCache.aquire(() -> ProceduralStream.of((xx,yy,zz)
|
||||||
|
-> (getZone(xx, yy, zz, rng)
|
||||||
|
.getCarved(rng, xx,yy,zz)), Interpolated.DOUBLE)
|
||||||
|
.cache3D(65535));
|
||||||
}
|
}
|
||||||
|
|
||||||
return m==0 ? 1 : (a/m);
|
return streamCache.aquire(() -> ProceduralStream.of((xx,yy,zz)
|
||||||
|
-> (getZone(xx, yy, zz, rng)
|
||||||
|
.isCarved(rng, xx,yy,zz) ? 1D : 0D), Interpolated.DOUBLE)
|
||||||
|
.cache3D(65535));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void apply(double ox, double oy, double oz, Hunk<T> hunk, T cave, RNG rng, ProceduralStream<Double> height)
|
public boolean isCavern(RNG rng, double x, double y, double z, double height) {
|
||||||
|
if(zones.isEmpty())
|
||||||
{
|
{
|
||||||
hunk.iterateSync((x,y,z) -> {
|
return false;
|
||||||
if(getInterpolator().interpolate(ox+x,oy+y,oz+z,(xx,yy,zz)
|
|
||||||
-> getZone(xx,yy,zz, rng).isCarved(rng, xx,yy,zz) ? 1 : 0) > threshold(y + oy, height.get(ox + x, oz + z)))
|
|
||||||
{
|
|
||||||
hunk.set(x,y,z,cave);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return getInterpolator().interpolate(x, y, z, (xx, yy, zz)
|
||||||
|
-> stream(rng).get(xx,yy,zz)) > threshold(height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user