SDF, Noise, Blocks Helper, Spline Helper, Translation Helper

This commit is contained in:
paulevsGitch 2021-05-22 23:54:39 +03:00
parent 6a5584deae
commit 017d663af6
37 changed files with 4315 additions and 0 deletions

View file

@ -0,0 +1,39 @@
package ru.bclib.sdf.primitive;
import net.minecraft.util.Mth;
import ru.bclib.util.MHelper;
public class SDFCappedCone extends SDFPrimitive {
private float radius1;
private float radius2;
private float height;
public SDFCappedCone setRadius1(float radius) {
this.radius1 = radius;
return this;
}
public SDFCappedCone setRadius2(float radius) {
this.radius2 = radius;
return this;
}
public SDFCappedCone setHeight(float height) {
this.height = height;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float qx = MHelper.length(x, z);
float k2x = radius2 - radius1;
float k2y = 2 * height;
float cax = qx - MHelper.min(qx, (y < 0F) ? radius1 : radius2);
float cay = Math.abs(y) - height;
float mlt = Mth.clamp(MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y), 0F, 1F);
float cbx = qx - radius2 + k2x * mlt;
float cby = y - height + k2y * mlt;
float s = (cbx < 0F && cay < 0F) ? -1F : 1F;
return s * (float) Math.sqrt(MHelper.min(MHelper.dot(cax, cay, cax, cay), MHelper.dot(cbx, cby, cbx, cby)));
}
}

View file

@ -0,0 +1,24 @@
package ru.bclib.sdf.primitive;
import net.minecraft.util.Mth;
import ru.bclib.util.MHelper;
public class SDFCapsule extends SDFPrimitive {
private float radius;
private float height;
public SDFCapsule setRadius(float radius) {
this.radius = radius;
return this;
}
public SDFCapsule setHeight(float height) {
this.height = height;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
return MHelper.length(x, y - Mth.clamp(y, 0, height), z) - radius;
}
}

View file

@ -0,0 +1,8 @@
package ru.bclib.sdf.primitive;
public class SDFFlatland extends SDFPrimitive {
@Override
public float getDistance(float x, float y, float z) {
return y;
}
}

View file

@ -0,0 +1,26 @@
package ru.bclib.sdf.primitive;
import ru.bclib.util.MHelper;
public class SDFHexPrism extends SDFPrimitive {
private float radius;
private float height;
public SDFHexPrism setRadius(float radius) {
this.radius = radius;
return this;
}
public SDFHexPrism setHeight(float height) {
this.height = height;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float px = Math.abs(x);
float py = Math.abs(y);
float pz = Math.abs(z);
return MHelper.max(py - height, MHelper.max((px * 0.866025F + pz * 0.5F), pz) - radius);
}
}

View file

@ -0,0 +1,49 @@
package ru.bclib.sdf.primitive;
import net.minecraft.util.Mth;
import ru.bclib.util.MHelper;
public class SDFLine extends SDFPrimitive {
private float radius;
private float x1;
private float y1;
private float z1;
private float x2;
private float y2;
private float z2;
public SDFLine setRadius(float radius) {
this.radius = radius;
return this;
}
public SDFLine setStart(float x, float y, float z) {
this.x1 = x;
this.y1 = y;
this.z1 = z;
return this;
}
public SDFLine setEnd(float x, float y, float z) {
this.x2 = x;
this.y2 = y;
this.z2 = z;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float pax = x - x1;
float pay = y - y1;
float paz = z - z1;
float bax = x2 - x1;
float bay = y2 - y1;
float baz = z2 - z1;
float dpb = MHelper.dot(pax, pay, paz, bax, bay, baz);
float dbb = MHelper.dot(bax, bay, baz, bax, bay, baz);
float h = Mth.clamp(dpb / dbb, 0F, 1F);
return MHelper.length(pax - bax * h, pay - bay * h, paz - baz * h) - radius;
}
}

View file

@ -0,0 +1,31 @@
package ru.bclib.sdf.primitive;
import net.minecraft.util.Mth;
import ru.bclib.util.MHelper;
public class SDFPie extends SDFPrimitive {
private float sin;
private float cos;
private float radius;
public SDFPie setAngle(float angle) {
this.sin = (float) Math.sin(angle);
this.cos = (float) Math.cos(angle);
return this;
}
public SDFPie setRadius(float radius) {
this.radius = radius;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
float px = Math.abs(x);
float l = MHelper.length(px, y, z) - radius;
float m = MHelper.dot(px, z, sin, cos);
m = Mth.clamp(m, 0, radius);
m = MHelper.length(px - sin * m, z - cos * m);
return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z));
}
}

View file

@ -0,0 +1,39 @@
package ru.bclib.sdf.primitive;
import java.util.function.Function;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.sdf.SDF;
public abstract class SDFPrimitive extends SDF {
protected Function<BlockPos, BlockState> placerFunction;
public SDFPrimitive setBlock(Function<BlockPos, BlockState> placerFunction) {
this.placerFunction = placerFunction;
return this;
}
public SDFPrimitive setBlock(BlockState state) {
this.placerFunction = (pos) -> {
return state;
};
return this;
}
public SDFPrimitive setBlock(Block block) {
this.placerFunction = (pos) -> {
return block.defaultBlockState();
};
return this;
}
public BlockState getBlockState(BlockPos pos) {
return placerFunction.apply(pos);
}
/*public abstract CompoundTag toNBT(CompoundTag root) {
}*/
}

View file

@ -0,0 +1,17 @@
package ru.bclib.sdf.primitive;
import ru.bclib.util.MHelper;
public class SDFSphere extends SDFPrimitive {
private float radius;
public SDFSphere setRadius(float radius) {
this.radius = radius;
return this;
}
@Override
public float getDistance(float x, float y, float z) {
return MHelper.length(x, y, z) - radius;
}
}