mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 22:31:52 +00:00
Change Java whitespace handling in .editorconfig (#425)
* Change whitespace handling in .editorconfig * Reformat code * fix format error * Reformat code --------- Co-authored-by: Zoë Gidiere <duplexsys@protonmail.com>
This commit is contained in:
+41
-41
@@ -31,54 +31,54 @@ import com.dfsek.terra.api.world.chunk.generation.util.provider.ChunkGeneratorPr
|
||||
public class NoiseChunkGenerator3DAddon implements AddonInitializer {
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
|
||||
@Inject
|
||||
private BaseAddon addon;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
PropertyKey<BiomePaletteInfo> paletteInfoPropertyKey = Context.create(BiomePaletteInfo.class);
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesPropertyKey = Context.create(BiomeNoiseProperties.class);
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.priority(1000)
|
||||
.then(event -> {
|
||||
|
||||
event.getPack().applyLoader(SlantHolder.CalculationMethod.class,
|
||||
(type, o, loader, depthTracker) -> SlantHolder.CalculationMethod.valueOf((String) o));
|
||||
|
||||
NoiseChunkGeneratorPackConfigTemplate config = event.loadTemplate(new NoiseChunkGeneratorPackConfigTemplate());
|
||||
event.getPack().getContext().put(config);
|
||||
|
||||
event.getPack()
|
||||
.getOrCreateRegistry(ChunkGeneratorProvider.class)
|
||||
.register(addon.key("NOISE_3D"),
|
||||
pack -> new NoiseChunkGenerator3D(pack, platform, config.getElevationBlend(),
|
||||
config.getHorizontalRes(),
|
||||
config.getVerticalRes(), noisePropertiesPropertyKey,
|
||||
paletteInfoPropertyKey));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.Layer.class, SlantLayerTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.priority(1000)
|
||||
.then(event -> {
|
||||
|
||||
event.getPack().applyLoader(SlantHolder.CalculationMethod.class,
|
||||
(type, o, loader, depthTracker) -> SlantHolder.CalculationMethod.valueOf((String) o));
|
||||
|
||||
NoiseChunkGeneratorPackConfigTemplate config = event.loadTemplate(new NoiseChunkGeneratorPackConfigTemplate());
|
||||
event.getPack().getContext().put(config);
|
||||
|
||||
event.getPack()
|
||||
.getOrCreateRegistry(ChunkGeneratorProvider.class)
|
||||
.register(addon.key("NOISE_3D"),
|
||||
pack -> new NoiseChunkGenerator3D(pack, platform, config.getElevationBlend(),
|
||||
config.getHorizontalRes(),
|
||||
config.getVerticalRes(), noisePropertiesPropertyKey,
|
||||
paletteInfoPropertyKey));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.Layer.class, SlantLayerTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
NoiseChunkGeneratorPackConfigTemplate config = event.getPack().getContext().get(
|
||||
NoiseChunkGeneratorPackConfigTemplate.class);
|
||||
|
||||
event.getLoadedObject(Biome.class).getContext().put(paletteInfoPropertyKey,
|
||||
event.load(new BiomePaletteTemplate(platform,
|
||||
config.getSlantCalculationMethod()))
|
||||
.get());
|
||||
event.getLoadedObject(Biome.class).getContext().put(noisePropertiesPropertyKey,
|
||||
event.load(new BiomeNoiseConfigTemplate()).get());
|
||||
}
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
NoiseChunkGeneratorPackConfigTemplate config = event.getPack().getContext().get(
|
||||
NoiseChunkGeneratorPackConfigTemplate.class);
|
||||
|
||||
event.getLoadedObject(Biome.class).getContext().put(paletteInfoPropertyKey,
|
||||
event.load(new BiomePaletteTemplate(platform,
|
||||
config.getSlantCalculationMethod()))
|
||||
.get());
|
||||
event.getLoadedObject(Biome.class).getContext().put(noisePropertiesPropertyKey,
|
||||
event.load(new BiomeNoiseConfigTemplate()).get());
|
||||
}
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -13,31 +13,31 @@ public class NoiseChunkGeneratorPackConfigTemplate implements ConfigTemplate, Pr
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
private @Meta int elevationBlend = 4;
|
||||
|
||||
|
||||
@Value("carving.resolution.horizontal")
|
||||
@Default
|
||||
private @Meta int horizontalRes = 4;
|
||||
|
||||
|
||||
@Value("carving.resolution.vertical")
|
||||
@Default
|
||||
private @Meta int verticalRes = 2;
|
||||
|
||||
|
||||
@Value("slant.calculation-method")
|
||||
@Default
|
||||
private SlantHolder.@Meta CalculationMethod slantCalculationMethod = SlantHolder.CalculationMethod.Derivative;
|
||||
|
||||
|
||||
public int getElevationBlend() {
|
||||
return elevationBlend;
|
||||
}
|
||||
|
||||
|
||||
public int getHorizontalRes() {
|
||||
return horizontalRes;
|
||||
}
|
||||
|
||||
|
||||
public int getVerticalRes() {
|
||||
return verticalRes;
|
||||
}
|
||||
|
||||
|
||||
public SlantHolder.CalculationMethod getSlantCalculationMethod() {
|
||||
return slantCalculationMethod;
|
||||
}
|
||||
|
||||
+8
-8
@@ -11,34 +11,34 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
public class BiomeNoiseConfigTemplate implements ObjectTemplate<BiomeNoiseProperties> {
|
||||
@Value("terrain.sampler")
|
||||
private @Meta NoiseSampler baseSampler;
|
||||
|
||||
|
||||
@Value("terrain.sampler-2d")
|
||||
@Default
|
||||
private @Meta NoiseSampler elevationSampler = NoiseSampler.zero();
|
||||
|
||||
|
||||
@Value("carving.sampler")
|
||||
@Default
|
||||
private @Meta NoiseSampler carvingSampler = NoiseSampler.zero();
|
||||
|
||||
|
||||
@Value("terrain.blend.distance")
|
||||
@Default
|
||||
private @Meta int blendDistance = 3;
|
||||
|
||||
|
||||
@Value("terrain.blend.weight")
|
||||
@Default
|
||||
private @Meta double blendWeight = 1;
|
||||
|
||||
|
||||
@Value("terrain.blend.step")
|
||||
@Default
|
||||
private @Meta int blendStep = 4;
|
||||
|
||||
|
||||
@Value("terrain.blend.weight-2d")
|
||||
@Default
|
||||
private @Meta double elevationWeight = 1;
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeNoiseProperties get() {
|
||||
return new BiomeNoiseProperties(baseSampler, elevationSampler, carvingSampler, blendDistance, blendStep, blendWeight,
|
||||
elevationWeight, new ThreadLocalNoiseHolder());
|
||||
elevationWeight, new ThreadLocalNoiseHolder());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -5,14 +5,14 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
public class ThreadLocalNoiseHolder {
|
||||
private final ThreadLocal<Holder> holder = ThreadLocal.withInitial(Holder::new);
|
||||
|
||||
|
||||
public double getNoise(NoiseSampler sampler, int x, int y, int z, long seed) {
|
||||
Holder holder = this.holder.get();
|
||||
|
||||
|
||||
if(holder.init && holder.y == y && holder.z == z && holder.x == x && holder.seed == seed) {
|
||||
return holder.noise;
|
||||
}
|
||||
|
||||
|
||||
double noise = sampler.noise(seed, x, y, z);
|
||||
holder.noise = noise;
|
||||
holder.x = x;
|
||||
@@ -22,7 +22,7 @@ public class ThreadLocalNoiseHolder {
|
||||
holder.init = true;
|
||||
return noise;
|
||||
}
|
||||
|
||||
|
||||
private static final class Holder {
|
||||
int x, y, z;
|
||||
boolean init = false;
|
||||
|
||||
+7
-7
@@ -12,6 +12,10 @@ import com.dfsek.tectonic.api.config.template.annotations.Description;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.BiomePaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.slant.SlantHolder;
|
||||
@@ -20,10 +24,6 @@ import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class BiomePaletteTemplate implements ObjectTemplate<BiomePaletteInfo> {
|
||||
private final Platform platform;
|
||||
@@ -55,15 +55,15 @@ public class BiomePaletteTemplate implements ObjectTemplate<BiomePaletteInfo> {
|
||||
@Value("carving.update-palette")
|
||||
@Default
|
||||
private @Meta boolean updatePalette = false;
|
||||
|
||||
|
||||
public BiomePaletteTemplate(Platform platform, SlantHolder.CalculationMethod slantCalculationMethod) {
|
||||
this.platform = platform;
|
||||
this.slantCalculationMethod = slantCalculationMethod;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomePaletteInfo get() {
|
||||
return new BiomePaletteInfo(PaletteHolder.of(palettes), SlantHolder.of(slantLayers, slantDepth, slantCalculationMethod),
|
||||
oceanPalette, seaLevel, updatePalette);
|
||||
oceanPalette, seaLevel, updatePalette);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,13 +13,13 @@ import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
|
||||
public class SlantLayerTemplate implements ObjectTemplate<SlantHolder.Layer> {
|
||||
|
||||
|
||||
@Value("threshold")
|
||||
private @Meta double threshold;
|
||||
|
||||
|
||||
@Value("palette")
|
||||
private @Meta List<@Meta Map<@Meta Palette, @Meta Integer>> palettes;
|
||||
|
||||
|
||||
@Override
|
||||
public SlantHolder.Layer get() {
|
||||
return new SlantHolder.Layer(PaletteHolder.of(palettes), threshold);
|
||||
|
||||
+41
-41
@@ -31,17 +31,17 @@ import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
private final Platform platform;
|
||||
|
||||
|
||||
private final SamplerProvider samplerCache;
|
||||
|
||||
|
||||
private final BlockState air;
|
||||
|
||||
|
||||
private final int carverHorizontalResolution;
|
||||
private final int carverVerticalResolution;
|
||||
|
||||
|
||||
private final PropertyKey<BiomePaletteInfo> paletteInfoPropertyKey;
|
||||
private final PropertyKey<BiomeNoiseProperties> noisePropertiesKey;
|
||||
|
||||
|
||||
public NoiseChunkGenerator3D(ConfigPack pack, Platform platform, int elevationBlend, int carverHorizontalResolution,
|
||||
int carverVerticalResolution,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey,
|
||||
@@ -53,16 +53,16 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
this.paletteInfoPropertyKey = paletteInfoPropertyKey;
|
||||
this.noisePropertiesKey = noisePropertiesKey;
|
||||
int maxBlend = pack
|
||||
.getBiomeProvider()
|
||||
.stream()
|
||||
.map(biome -> biome.getContext().get(noisePropertiesKey))
|
||||
.mapToInt(properties -> properties.blendDistance() * properties.blendStep())
|
||||
.max()
|
||||
.orElse(0);
|
||||
|
||||
.getBiomeProvider()
|
||||
.stream()
|
||||
.map(biome -> biome.getContext().get(noisePropertiesKey))
|
||||
.mapToInt(properties -> properties.blendDistance() * properties.blendStep())
|
||||
.max()
|
||||
.orElse(0);
|
||||
|
||||
this.samplerCache = new SamplerProvider(platform, elevationBlend, noisePropertiesKey, maxBlend);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public void generateChunkData(@NotNull ProtoChunk chunk, @NotNull WorldProperties world,
|
||||
@@ -71,41 +71,41 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
platform.getProfiler().push("chunk_base_3d");
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
|
||||
|
||||
Sampler3D sampler = samplerCache.getChunk(chunkX, chunkZ, world, biomeProvider);
|
||||
|
||||
|
||||
long seed = world.getSeed();
|
||||
|
||||
|
||||
LazilyEvaluatedInterpolator carver = new LazilyEvaluatedInterpolator(biomeProvider,
|
||||
chunkX,
|
||||
chunkZ,
|
||||
world.getMaxHeight(),
|
||||
noisePropertiesKey, world.getMinHeight(),
|
||||
carverHorizontalResolution,
|
||||
carverVerticalResolution,
|
||||
seed);
|
||||
chunkX,
|
||||
chunkZ,
|
||||
world.getMaxHeight(),
|
||||
noisePropertiesKey, world.getMinHeight(),
|
||||
carverHorizontalResolution,
|
||||
carverVerticalResolution,
|
||||
seed);
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
int paletteLevel = 0;
|
||||
|
||||
|
||||
int cx = xOrig + x;
|
||||
int cz = zOrig + z;
|
||||
|
||||
|
||||
BlockState data;
|
||||
Column<Biome> biomeColumn = biomeProvider.getColumn(cx, cz, world);
|
||||
for(int y = world.getMaxHeight() - 1; y >= world.getMinHeight(); y--) {
|
||||
Biome biome = biomeColumn.get(y);
|
||||
|
||||
|
||||
BiomePaletteInfo paletteInfo = biome.getContext().get(paletteInfoPropertyKey);
|
||||
|
||||
|
||||
int sea = paletteInfo.seaLevel();
|
||||
Palette seaPalette = paletteInfo.ocean();
|
||||
|
||||
|
||||
if(sampler.sample(x, y, z) > 0) {
|
||||
if(carver.sample(x, y, z) <= 0) {
|
||||
data = PaletteUtil
|
||||
.getPalette(x, y, z, sampler, paletteInfo, paletteLevel)
|
||||
.get(paletteLevel, cx, y, cz, seed);
|
||||
.getPalette(x, y, z, sampler, paletteInfo, paletteLevel)
|
||||
.get(paletteLevel, cx, y, cz, seed);
|
||||
chunk.setBlock(x, y, z, data);
|
||||
paletteLevel++;
|
||||
} else if(paletteInfo.updatePaletteWhenCarving()) {
|
||||
@@ -124,17 +124,17 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
}
|
||||
platform.getProfiler().pop("chunk_base_3d");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(WorldProperties world, int x, int y, int z, BiomeProvider biomeProvider) {
|
||||
Biome biome = biomeProvider.getBiome(x, y, z, world.getSeed());
|
||||
Sampler3D sampler = samplerCache.get(x, z, world, biomeProvider);
|
||||
|
||||
|
||||
BiomePaletteInfo paletteInfo = biome.getContext().get(paletteInfoPropertyKey);
|
||||
|
||||
|
||||
int fdX = Math.floorMod(x, 16);
|
||||
int fdZ = Math.floorMod(z, 16);
|
||||
|
||||
|
||||
Palette palette = PaletteUtil.getPalette(fdX, y, fdZ, sampler, paletteInfo, 0);
|
||||
double noise = sampler.sample(fdX, y, fdZ);
|
||||
if(noise > 0) {
|
||||
@@ -148,22 +148,22 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
return paletteInfo.ocean().get(paletteInfo.seaLevel() - y, x, y, z, world.getSeed());
|
||||
} else return air;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Palette getPalette(int x, int y, int z, WorldProperties world, BiomeProvider biomeProvider) {
|
||||
return biomeProvider.getBiome(x, y, z, world.getSeed()).getContext().get(paletteInfoPropertyKey).paletteHolder().getPalette(y);
|
||||
}
|
||||
|
||||
|
||||
public double getSlant(int x, int y, int z, WorldProperties world, BiomeProvider biomeProvider) {
|
||||
int fdX = Math.floorMod(x, 16);
|
||||
int fdZ = Math.floorMod(z, 16);
|
||||
return biomeProvider.getBiome(x, y, z, world.getSeed())
|
||||
.getContext()
|
||||
.get(paletteInfoPropertyKey)
|
||||
.slantHolder()
|
||||
.calculateSlant(samplerCache.get(x, z, world, biomeProvider), fdX, y, fdZ);
|
||||
.getContext()
|
||||
.get(paletteInfoPropertyKey)
|
||||
.slantHolder()
|
||||
.calculateSlant(samplerCache.get(x, z, world, biomeProvider), fdX, y, fdZ);
|
||||
}
|
||||
|
||||
|
||||
public SamplerProvider samplerProvider() {
|
||||
return samplerCache;
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
|
||||
public final class PaletteUtil {
|
||||
|
||||
|
||||
public static Palette getPalette(int x, int y, int z, Sampler3D sampler, BiomePaletteInfo paletteInfo, int depth) {
|
||||
SlantHolder slantHolder = paletteInfo.slantHolder();
|
||||
if(slantHolder.isAboveDepth(depth)) {
|
||||
@@ -23,7 +23,7 @@ public final class PaletteUtil {
|
||||
return slantHolder.getPalette(slant).getPalette(y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return paletteInfo.paletteHolder().getPalette(y);
|
||||
}
|
||||
}
|
||||
+44
-44
@@ -20,10 +20,10 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
*/
|
||||
public class ChunkInterpolator {
|
||||
private final Interpolator3[][][] interpGrid;
|
||||
|
||||
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates.
|
||||
*
|
||||
@@ -37,75 +37,75 @@ public class ChunkInterpolator {
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
||||
|
||||
int xOrigin = chunkX << 4;
|
||||
int zOrigin = chunkZ << 4;
|
||||
|
||||
|
||||
int range = this.max - this.min + 1;
|
||||
|
||||
|
||||
int size = range >> 2;
|
||||
|
||||
|
||||
interpGrid = new Interpolator3[4][size][4];
|
||||
|
||||
|
||||
double[][][] noiseStorage = new double[5][5][size + 1];
|
||||
|
||||
|
||||
int maxBlendAndChunk = 17 + 2 * maxBlend;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Column<Biome>[] columns = new Column[maxBlendAndChunk * maxBlendAndChunk];
|
||||
|
||||
|
||||
for(int x = 0; x < 5; x++) {
|
||||
int scaledX = x << 2;
|
||||
int absoluteX = xOrigin + scaledX;
|
||||
for(int z = 0; z < 5; z++) {
|
||||
int scaledZ = z << 2;
|
||||
int absoluteZ = zOrigin + scaledZ;
|
||||
|
||||
|
||||
int index = (scaledX + maxBlend) + maxBlendAndChunk * (scaledZ + maxBlend);
|
||||
Column<Biome> biomeColumn = columns[index];
|
||||
|
||||
|
||||
if(biomeColumn == null) {
|
||||
biomeColumn = provider.getColumn(absoluteX, absoluteZ, seed, min, max);
|
||||
columns[index] = biomeColumn;
|
||||
}
|
||||
|
||||
|
||||
for(int y = 0; y < size; y++) {
|
||||
int scaledY = (y << 2) + min;
|
||||
BiomeNoiseProperties generationSettings = biomeColumn.get(scaledY)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
|
||||
int step = generationSettings.blendStep();
|
||||
int blend = generationSettings.blendDistance();
|
||||
|
||||
|
||||
double runningNoise = 0;
|
||||
double runningDiv = 0;
|
||||
|
||||
|
||||
for(int xi = -blend; xi <= blend; xi++) {
|
||||
for(int zi = -blend; zi <= blend; zi++) {
|
||||
int blendX = (xi * step);
|
||||
int blendZ = (zi * step);
|
||||
|
||||
|
||||
int localIndex = (scaledX + maxBlend + blendX) + maxBlendAndChunk * (scaledZ + maxBlend + blendZ);
|
||||
Column<Biome> column = columns[localIndex];
|
||||
|
||||
|
||||
if(column == null) {
|
||||
column = provider.getColumn(absoluteX + blendX, absoluteZ + blendZ, seed, min, max);
|
||||
columns[localIndex] = column;
|
||||
}
|
||||
|
||||
|
||||
BiomeNoiseProperties properties = column
|
||||
.get(scaledY)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
.get(scaledY)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
double sample = properties.noiseHolder().getNoise(properties.base(), absoluteX, scaledY, absoluteZ, seed);
|
||||
runningNoise += sample * properties.blendWeight();
|
||||
runningDiv += properties.blendWeight();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double noise = runningNoise / runningDiv;
|
||||
|
||||
|
||||
noiseStorage[x][z][y] = noise;
|
||||
if(y == size - 1) {
|
||||
noiseStorage[x][z][size] = noise;
|
||||
@@ -113,28 +113,28 @@ public class ChunkInterpolator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int x = 0; x < 4; x++) {
|
||||
for(int z = 0; z < 4; z++) {
|
||||
for(int y = 0; y < size; y++) {
|
||||
interpGrid[x][y][z] = new Interpolator3(
|
||||
noiseStorage[x][z][y],
|
||||
noiseStorage[x + 1][z][y],
|
||||
noiseStorage[x][z][y + 1],
|
||||
noiseStorage[x + 1][z][y + 1],
|
||||
noiseStorage[x][z + 1][y],
|
||||
noiseStorage[x + 1][z + 1][y],
|
||||
noiseStorage[x][z + 1][y + 1],
|
||||
noiseStorage[x + 1][z + 1][y + 1]);
|
||||
noiseStorage[x][z][y],
|
||||
noiseStorage[x + 1][z][y],
|
||||
noiseStorage[x][z][y + 1],
|
||||
noiseStorage[x + 1][z][y + 1],
|
||||
noiseStorage[x][z + 1][y],
|
||||
noiseStorage[x + 1][z + 1][y],
|
||||
noiseStorage[x][z + 1][y + 1],
|
||||
noiseStorage[x + 1][z + 1][y + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int reRange(int value, int high) {
|
||||
return Math.max(Math.min(value, high), 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the noise at a pair of internal chunk coordinates.
|
||||
*
|
||||
@@ -145,15 +145,15 @@ public class ChunkInterpolator {
|
||||
*/
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][(Math.max(Math.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4,
|
||||
3)].trilerp(
|
||||
(x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
3)].trilerp(
|
||||
(x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
}
|
||||
|
||||
|
||||
public double getNoise(int x, int y, int z) {
|
||||
return interpGrid[x / 4][(y - min) / 4][z / 4].trilerp(
|
||||
(double) (x & 3) / 4, // x & 3 == x % 4
|
||||
(double) (y & 3) / 4, // x & 3 == x % 4
|
||||
(double) (z & 3) / 4 // x & 3 == x % 4
|
||||
);
|
||||
(double) (x & 3) / 4, // x & 3 == x % 4
|
||||
(double) (y & 3) / 4, // x & 3 == x % 4
|
||||
(double) (z & 3) / 4 // x & 3 == x % 4
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -14,36 +14,36 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
public class ElevationInterpolator {
|
||||
private final double[][] values = new double[18][18];
|
||||
|
||||
|
||||
public ElevationInterpolator(long seed, int chunkX, int chunkZ, BiomeProvider provider, int smooth,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey) {
|
||||
int xOrigin = chunkX << 4;
|
||||
int zOrigin = chunkZ << 4;
|
||||
|
||||
|
||||
BiomeNoiseProperties[][] gens = new BiomeNoiseProperties[18 + 2 * smooth][18 + 2 * smooth];
|
||||
|
||||
|
||||
// Precompute generators.
|
||||
for(int x = -1 - smooth; x <= 16 + smooth; x++) {
|
||||
for(int z = -1 - smooth; z <= 16 + smooth; z++) {
|
||||
int bx = xOrigin + x;
|
||||
int bz = zOrigin + z;
|
||||
gens[x + 1 + smooth][z + 1 + smooth] =
|
||||
provider
|
||||
.getBaseBiome(bx, bz, seed)
|
||||
.orElseGet(() -> provider.getBiome(bx, 0, bz, seed)) // kind of a hack
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
provider
|
||||
.getBaseBiome(bx, bz, seed)
|
||||
.orElseGet(() -> provider.getBiome(bx, 0, bz, seed)) // kind of a hack
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int x = -1; x <= 16; x++) {
|
||||
for(int z = -1; z <= 16; z++) {
|
||||
double noise = 0;
|
||||
double div = 0;
|
||||
|
||||
|
||||
BiomeNoiseProperties center = gens[x + 1 + smooth][z + 1 + smooth];
|
||||
boolean same = true;
|
||||
|
||||
|
||||
for(int xi = -smooth; xi <= smooth; xi++) {
|
||||
for(int zi = -smooth; zi <= smooth; zi++) {
|
||||
if(gens[x + 1 + smooth + xi][z + 1 + smooth + zi] !=
|
||||
@@ -53,7 +53,7 @@ public class ElevationInterpolator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(same) {
|
||||
values[x + 1][z + 1] = center.elevation().noise(seed, xOrigin + x, zOrigin + z); // no weighting needed!
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ public class ElevationInterpolator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double getElevation(int x, int z) {
|
||||
return values[x + 1][z + 1];
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import com.dfsek.terra.api.util.MathUtil;
|
||||
*/
|
||||
public class Interpolator {
|
||||
private final double v0, v1, v2, v3;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an interpolator with given values as vertices of a unit square.
|
||||
*
|
||||
@@ -30,7 +30,7 @@ public class Interpolator {
|
||||
this.v2 = v2;
|
||||
this.v3 = v3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 2D Bilinear interpolation between 4 points on a unit square.
|
||||
*
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ import com.dfsek.terra.api.util.MathUtil;
|
||||
public class Interpolator3 {
|
||||
private final Interpolator bottom;
|
||||
private final Interpolator top;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an interpolator with given values as vertices of a unit cube.
|
||||
* * @param _000 The value at <code>(t, u, v) = (0, 0, 0)</code>.
|
||||
@@ -35,7 +35,7 @@ public class Interpolator3 {
|
||||
this.top = new Interpolator(_000, _010, _001, _011);
|
||||
this.bottom = new Interpolator(_100, _110, _101, _111);
|
||||
}
|
||||
|
||||
|
||||
public double trilerp(double x, double y, double z) {
|
||||
return MathUtil.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
|
||||
}
|
||||
|
||||
+31
-30
@@ -5,23 +5,24 @@ import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class LazilyEvaluatedInterpolator {
|
||||
private final Double[] samples; //
|
||||
|
||||
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
|
||||
|
||||
private final int horizontalRes;
|
||||
private final int verticalRes;
|
||||
|
||||
|
||||
private final BiomeProvider biomeProvider;
|
||||
private final PropertyKey<BiomeNoiseProperties> noisePropertiesKey;
|
||||
|
||||
|
||||
private final long seed;
|
||||
private final int min, max;
|
||||
|
||||
|
||||
private final int zMul, yMul;
|
||||
|
||||
|
||||
public LazilyEvaluatedInterpolator(BiomeProvider biomeProvider, int cx, int cz, int max,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int min, int horizontalRes, int verticalRes,
|
||||
long seed) {
|
||||
@@ -40,70 +41,70 @@ public class LazilyEvaluatedInterpolator {
|
||||
this.min = min;
|
||||
this.max = max - 1;
|
||||
}
|
||||
|
||||
|
||||
private double sample(int xIndex, int yIndex, int zIndex, int ox, int oy, int oz) {
|
||||
int index = xIndex + (zIndex * zMul) + (yIndex * yMul);
|
||||
Double sample = samples[index];
|
||||
if(sample == null) {
|
||||
int xi = ox + chunkX;
|
||||
int zi = oz + chunkZ;
|
||||
|
||||
|
||||
int y = Math.min(max, oy);
|
||||
|
||||
|
||||
sample = biomeProvider
|
||||
.getBiome(xi, y, zi, seed)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey)
|
||||
.carving()
|
||||
.noise(seed, xi, y, zi);
|
||||
.getBiome(xi, y, zi, seed)
|
||||
.getContext()
|
||||
.get(noisePropertiesKey)
|
||||
.carving()
|
||||
.noise(seed, xi, y, zi);
|
||||
samples[index] = sample;
|
||||
}
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
public double sample(int x, int y, int z) {
|
||||
int xIndex = x / horizontalRes;
|
||||
int yIndex = (y - min) / verticalRes;
|
||||
int zIndex = z / horizontalRes;
|
||||
|
||||
|
||||
double sample_0_0_0 = sample(xIndex, yIndex, zIndex, x, y, z);
|
||||
|
||||
|
||||
boolean yRange = y % verticalRes == 0;
|
||||
if(x % horizontalRes == 0 && yRange && z % horizontalRes == 0) { // we're at the sampling point
|
||||
return sample_0_0_0;
|
||||
}
|
||||
|
||||
|
||||
double sample_0_0_1 = sample(xIndex, yIndex, zIndex + 1, x, y, z + horizontalRes);
|
||||
|
||||
|
||||
double sample_1_0_0 = sample(xIndex + 1, yIndex, zIndex, x + horizontalRes, y, z);
|
||||
double sample_1_0_1 = sample(xIndex + 1, yIndex, zIndex + 1, x + horizontalRes, y, z + horizontalRes);
|
||||
|
||||
|
||||
double xFrac = (double) (x % horizontalRes) / horizontalRes;
|
||||
double zFrac = (double) (z % horizontalRes) / horizontalRes;
|
||||
double lerp_bottom_0 = MathUtil.lerp(zFrac, sample_0_0_0, sample_0_0_1);
|
||||
double lerp_bottom_1 = MathUtil.lerp(zFrac, sample_1_0_0, sample_1_0_1);
|
||||
|
||||
|
||||
double lerp_bottom = MathUtil.lerp(xFrac, lerp_bottom_0, lerp_bottom_1);
|
||||
|
||||
|
||||
if(yRange) { // we can do bilerp
|
||||
return lerp_bottom;
|
||||
}
|
||||
|
||||
|
||||
double yFrac = (double) Math.floorMod(y, verticalRes) / verticalRes;
|
||||
|
||||
|
||||
|
||||
|
||||
double sample_0_1_0 = sample(xIndex, yIndex + 1, zIndex, x, y + verticalRes, z);
|
||||
double sample_0_1_1 = sample(xIndex, yIndex + 1, zIndex + 1, x, y + verticalRes, z + horizontalRes);
|
||||
|
||||
|
||||
|
||||
|
||||
double sample_1_1_0 = sample(xIndex + 1, yIndex + 1, zIndex, x + horizontalRes, y + verticalRes, z);
|
||||
double sample_1_1_1 = sample(xIndex + 1, yIndex + 1, zIndex + 1, x + horizontalRes, y + verticalRes, z + horizontalRes);
|
||||
|
||||
|
||||
double lerp_top_0 = MathUtil.lerp(zFrac, sample_0_1_0, sample_0_1_1);
|
||||
double lerp_top_1 = MathUtil.lerp(zFrac, sample_1_1_0, sample_1_1_1);
|
||||
|
||||
|
||||
double lerp_top = MathUtil.lerp(xFrac, lerp_top_0, lerp_top_1);
|
||||
|
||||
|
||||
return MathUtil.lerp(yFrac, lerp_bottom, lerp_top);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,18 +17,18 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
public class Sampler3D {
|
||||
private final ChunkInterpolator interpolator;
|
||||
private final ElevationInterpolator elevationInterpolator;
|
||||
|
||||
|
||||
public Sampler3D(int x, int z, long seed, int minHeight, int maxHeight, BiomeProvider provider, int elevationSmooth,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||
this.interpolator = new ChunkInterpolator(seed, x, z, provider,
|
||||
minHeight, maxHeight, noisePropertiesKey, maxBlend);
|
||||
minHeight, maxHeight, noisePropertiesKey, maxBlend);
|
||||
this.elevationInterpolator = new ElevationInterpolator(seed, x, z, provider, elevationSmooth, noisePropertiesKey);
|
||||
}
|
||||
|
||||
|
||||
public double sample(double x, double y, double z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation((int) Math.round(x), (int) Math.round(z));
|
||||
}
|
||||
|
||||
|
||||
public double sample(int x, int y, int z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(x, z);
|
||||
}
|
||||
|
||||
+8
-8
@@ -32,29 +32,29 @@ public class SamplerProvider {
|
||||
private final int elevationSmooth;
|
||||
private final PropertyKey<BiomeNoiseProperties> noisePropertiesKey;
|
||||
private final int maxBlend;
|
||||
|
||||
|
||||
public SamplerProvider(Platform platform, int elevationSmooth, PropertyKey<BiomeNoiseProperties> noisePropertiesKey, int maxBlend) {
|
||||
cache = Caffeine
|
||||
.newBuilder()
|
||||
.maximumSize(platform.getTerraConfig().getSamplerCache())
|
||||
.build();
|
||||
.newBuilder()
|
||||
.maximumSize(platform.getTerraConfig().getSamplerCache())
|
||||
.build();
|
||||
this.elevationSmooth = elevationSmooth;
|
||||
this.noisePropertiesKey = noisePropertiesKey;
|
||||
this.maxBlend = maxBlend;
|
||||
}
|
||||
|
||||
|
||||
public Sampler3D get(int x, int z, WorldProperties world, BiomeProvider provider) {
|
||||
int cx = Math.floorDiv(x, 16);
|
||||
int cz = Math.floorDiv(z, 16);
|
||||
return getChunk(cx, cz, world, provider);
|
||||
}
|
||||
|
||||
|
||||
public Sampler3D getChunk(int cx, int cz, WorldProperties world, BiomeProvider provider) {
|
||||
WorldContext context = new WorldContext(cx, cz, world.getSeed(), world.getMinHeight(), world.getMaxHeight());
|
||||
return cache.get(context, c -> new Sampler3D(c.cx, c.cz, c.seed, c.minHeight, c.maxHeight, provider,
|
||||
elevationSmooth, noisePropertiesKey, maxBlend));
|
||||
elevationSmooth, noisePropertiesKey, maxBlend));
|
||||
}
|
||||
|
||||
|
||||
private record WorldContext(int cx, int cz, long seed, int minHeight, int maxHeight) {
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -18,12 +18,12 @@ import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
public class PaletteHolder {
|
||||
private final Palette[] palettes;
|
||||
private final int offset;
|
||||
|
||||
|
||||
protected PaletteHolder(Palette[] palettes, int offset) {
|
||||
this.palettes = palettes;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
|
||||
public static PaletteHolder of(List<Map<Palette, Integer>> palettes) {
|
||||
PaletteHolderBuilder builder = new PaletteHolderBuilder();
|
||||
for(Map<Palette, Integer> layer : palettes) {
|
||||
@@ -33,7 +33,7 @@ public class PaletteHolder {
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
public Palette getPalette(int y) {
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
@@ -42,21 +42,21 @@ public class PaletteHolder {
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
|
||||
|
||||
|
||||
public PaletteHolderBuilder add(int y, Palette palette) {
|
||||
paletteMap.put(y, palette);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PaletteHolder build() {
|
||||
|
||||
|
||||
int min = Math.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = Math.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
|
||||
Palette[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= Math.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette d = null;
|
||||
|
||||
+4
-4
@@ -20,11 +20,11 @@ import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
public class MultipleSlantHolder extends SlantHolderImpl {
|
||||
private final NavigableMap<Double, PaletteHolder> layers;
|
||||
private final double slantThreshold;
|
||||
|
||||
|
||||
MultipleSlantHolder(List<SlantHolder.Layer> slant, int slantDepth, CalculationMethod calculationMethod) {
|
||||
super(slantDepth, calculationMethod);
|
||||
NavigableMap<Double, PaletteHolder> layers = new TreeMap<>(
|
||||
slant.stream().collect(Collectors.toMap(SlantHolder.Layer::threshold, SlantHolder.Layer::palette)));
|
||||
slant.stream().collect(Collectors.toMap(SlantHolder.Layer::threshold, SlantHolder.Layer::palette)));
|
||||
Stream<Double> thresholds = layers.keySet().stream();
|
||||
double slantThreshold = floorToThreshold ?
|
||||
thresholds.min(Double::compare).orElseThrow() :
|
||||
@@ -32,12 +32,12 @@ public class MultipleSlantHolder extends SlantHolderImpl {
|
||||
this.layers = layers;
|
||||
this.slantThreshold = slantThreshold;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected double getSlantThreshold() {
|
||||
return slantThreshold;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaletteHolder getPalette(double slant) {
|
||||
return (floorToThreshold ?
|
||||
|
||||
+4
-4
@@ -4,19 +4,19 @@ import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
|
||||
|
||||
final class SingleSlantHolder extends SlantHolderImpl {
|
||||
|
||||
|
||||
private final SlantHolder.Layer layer;
|
||||
|
||||
|
||||
public SingleSlantHolder(SlantHolder.Layer layer, int slantDepth, CalculationMethod calculationMethod) {
|
||||
super(slantDepth, calculationMethod);
|
||||
this.layer = layer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaletteHolder getPalette(double slant) {
|
||||
return layer.palette();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected double getSlantThreshold() {
|
||||
return layer.threshold();
|
||||
|
||||
+30
-30
@@ -8,29 +8,29 @@ import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
|
||||
public interface SlantHolder {
|
||||
|
||||
|
||||
SlantHolder EMPTY = new SlantHolder() {
|
||||
@Override
|
||||
public double calculateSlant(Sampler3D sampler, double x, double y, double z) {
|
||||
throw new UnsupportedOperationException("Empty holder should not calculate slant");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAboveDepth(int depth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInSlantThreshold(double slant) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaletteHolder getPalette(double slant) {
|
||||
throw new UnsupportedOperationException("Empty holder cannot return a palette");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static SlantHolder of(List<SlantHolder.Layer> layers, int slantDepth, CalculationMethod calculationMethod) {
|
||||
if(layers.isEmpty()) {
|
||||
return EMPTY;
|
||||
@@ -39,29 +39,29 @@ public interface SlantHolder {
|
||||
}
|
||||
return new MultipleSlantHolder(layers, slantDepth, calculationMethod);
|
||||
}
|
||||
|
||||
|
||||
double calculateSlant(Sampler3D sampler, double x, double y, double z);
|
||||
|
||||
|
||||
boolean isAboveDepth(int depth);
|
||||
|
||||
|
||||
boolean isInSlantThreshold(double slant);
|
||||
|
||||
|
||||
PaletteHolder getPalette(double slant);
|
||||
|
||||
|
||||
|
||||
|
||||
enum CalculationMethod {
|
||||
DotProduct {
|
||||
private static final Vector3 DOT_PRODUCT_DIRECTION = Vector3.of(0, 1, 0);
|
||||
|
||||
|
||||
private static final Vector3[] DOT_PRODUCT_SAMPLE_POINTS = {
|
||||
Vector3.of(0, 0, -DERIVATIVE_DIST),
|
||||
Vector3.of(0, 0, DERIVATIVE_DIST),
|
||||
Vector3.of(0, -DERIVATIVE_DIST, 0),
|
||||
Vector3.of(0, DERIVATIVE_DIST, 0),
|
||||
Vector3.of(-DERIVATIVE_DIST, 0, 0),
|
||||
Vector3.of(DERIVATIVE_DIST, 0, 0)
|
||||
Vector3.of(0, 0, -DERIVATIVE_DIST),
|
||||
Vector3.of(0, 0, DERIVATIVE_DIST),
|
||||
Vector3.of(0, -DERIVATIVE_DIST, 0),
|
||||
Vector3.of(0, DERIVATIVE_DIST, 0),
|
||||
Vector3.of(-DERIVATIVE_DIST, 0, 0),
|
||||
Vector3.of(DERIVATIVE_DIST, 0, 0)
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public double slant(Sampler3D sampler, double x, double y, double z) {
|
||||
Vector3.Mutable normalApproximation = Vector3.Mutable.of(0, 0, 0);
|
||||
@@ -71,39 +71,39 @@ public interface SlantHolder {
|
||||
}
|
||||
return DOT_PRODUCT_DIRECTION.dot(normalApproximation.normalize());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean floorToThreshold() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Derivative {
|
||||
@Override
|
||||
public double slant(Sampler3D sampler, double x, double y, double z) {
|
||||
double baseSample = sampler.sample(x, y, z);
|
||||
|
||||
|
||||
double xVal1 = (sampler.sample(x + DERIVATIVE_DIST, y, z) - baseSample) / DERIVATIVE_DIST;
|
||||
double xVal2 = (sampler.sample(x - DERIVATIVE_DIST, y, z) - baseSample) / DERIVATIVE_DIST;
|
||||
double zVal1 = (sampler.sample(x, y, z + DERIVATIVE_DIST) - baseSample) / DERIVATIVE_DIST;
|
||||
double zVal2 = (sampler.sample(x, y, z - DERIVATIVE_DIST) - baseSample) / DERIVATIVE_DIST;
|
||||
double yVal1 = (sampler.sample(x, y + DERIVATIVE_DIST, z) - baseSample) / DERIVATIVE_DIST;
|
||||
double yVal2 = (sampler.sample(x, y - DERIVATIVE_DIST, z) - baseSample) / DERIVATIVE_DIST;
|
||||
|
||||
|
||||
return Math.sqrt(
|
||||
((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1)));
|
||||
((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean floorToThreshold() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private static final double DERIVATIVE_DIST = 0.55;
|
||||
|
||||
|
||||
public abstract double slant(Sampler3D sampler, double x, double y, double z);
|
||||
|
||||
|
||||
/*
|
||||
* Controls whether palettes should be applied before or after their respective thresholds.
|
||||
*
|
||||
@@ -112,8 +112,8 @@ public interface SlantHolder {
|
||||
*/
|
||||
public abstract boolean floorToThreshold();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
record Layer(PaletteHolder palette, double threshold) {
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -7,25 +7,25 @@ public abstract class SlantHolderImpl implements SlantHolder {
|
||||
protected final boolean floorToThreshold;
|
||||
private final SlantHolder.CalculationMethod calculationMethod;
|
||||
private final int slantDepth;
|
||||
|
||||
|
||||
protected SlantHolderImpl(int slantDepth, CalculationMethod calculationMethod) {
|
||||
this.floorToThreshold = calculationMethod.floorToThreshold();
|
||||
this.calculationMethod = calculationMethod;
|
||||
this.slantDepth = slantDepth;
|
||||
}
|
||||
|
||||
|
||||
protected abstract double getSlantThreshold();
|
||||
|
||||
|
||||
@Override
|
||||
public final double calculateSlant(Sampler3D sampler, double x, double y, double z) {
|
||||
return calculationMethod.slant(sampler, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean isAboveDepth(int depth) {
|
||||
return depth <= slantDepth;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean isInSlantThreshold(double slant) {
|
||||
return (floorToThreshold ?
|
||||
|
||||
Reference in New Issue
Block a user