Hunk grow interp

This commit is contained in:
Daniel Mills 2021-07-30 04:40:07 -04:00
parent 742fa27029
commit 394d653978
2 changed files with 63 additions and 0 deletions

View File

@ -19,14 +19,17 @@
package com.volmit.iris.engine.framework;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.documentation.BlockCoordinates;
public abstract class EngineAssignedModifier<T> extends EngineAssignedComponent implements EngineModifier<T> {
public EngineAssignedModifier(Engine engine, String name) {
super(engine, name);
}
@BlockCoordinates
public abstract void onModify(int x, int z, Hunk<T> output, boolean multicore);
@BlockCoordinates
@Override
public void modify(int x, int z, Hunk<T> output, boolean multicore) {
onModify(x, z, output, multicore);

View File

@ -21,8 +21,12 @@ package com.volmit.iris.engine.hunk;
import com.volmit.iris.engine.hunk.io.HunkIOAdapter;
import com.volmit.iris.engine.hunk.storage.*;
import com.volmit.iris.engine.hunk.view.*;
import com.volmit.iris.engine.interpolation.InterpolationMethod;
import com.volmit.iris.engine.interpolation.InterpolationMethod3D;
import com.volmit.iris.engine.interpolation.IrisInterpolation;
import com.volmit.iris.engine.parallel.BurstExecutor;
import com.volmit.iris.engine.parallel.MultiBurst;
import com.volmit.iris.engine.stream.interpolation.Interpolated;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.function.*;
import com.volmit.iris.util.oldnbt.ByteArrayTag;
@ -1182,4 +1186,60 @@ public interface Hunk<T> {
default void empty(T b) {
fill(b);
}
/**
* Take a hunk and scale it up using interpolation
* @param scale the scale
* @param d the interpolation method
* @param interpolated the interpolated value converter
* @return the new hunk
*/
default Hunk<T> interpolate3D(double scale, InterpolationMethod3D d, Interpolated<T> interpolated)
{
Hunk<T> t = Hunk.newArrayHunk((int)(getWidth() * scale), (int)(getHeight() * scale), (int)(getDepth() * scale));
NoiseProvider3 n3 = (x,y,z) -> interpolated.toDouble(
t.get((int)(x/scale),
(int)(y/scale),
(int)(z/scale)));
for(int i = 0; i < t.getWidth(); i++)
{
for(int j = 0; j < t.getHeight(); j++)
{
for(int k = 0; k < t.getDepth(); k++)
{
t.set(i, j, k, interpolated.fromDouble(IrisInterpolation.getNoise3D(d, i,j,k,scale, n3)));
}
}
}
return t;
}
/**
* Take a hunk and scale it up using interpolation
* 2D, (using only x and z) assumes the height is 1
* @param scale the scale
* @param d the interpolation method
* @param interpolated the interpolated value converter
* @return the new hunk
*/
default Hunk<T> interpolate2D(double scale, InterpolationMethod d, Interpolated<T> interpolated)
{
Hunk<T> t = Hunk.newArrayHunk((int)(getWidth() * scale), 1, (int)(getDepth() * scale));
NoiseProvider n2 = (x,z) -> interpolated.toDouble(
t.get((int)(x/scale),
0,
(int)(z/scale)));
for(int i = 0; i < t.getWidth(); i++)
{
for(int j = 0; j < t.getDepth(); j++)
{
t.set(i, 0, j, interpolated.fromDouble(IrisInterpolation.getNoise(d, i,j,scale, n2)));
}
}
return t;
}
}