Used Reparameterized Interpolation

Dieser Commit ist enthalten in:
Hazel Trinity 2020-08-16 01:11:12 -07:00
Ursprung e5f092c3ef
Commit 5c32cc17a2

Datei anzeigen

@ -18,6 +18,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.interpolation.Interpolation; import com.sk89q.worldedit.math.interpolation.Interpolation;
import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation; import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.math.interpolation.Node; import com.sk89q.worldedit.math.interpolation.Node;
import com.sk89q.worldedit.math.interpolation.ReparametrisingInterpolation;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
@ -41,22 +42,6 @@ public class SweepBrush implements Brush, ResettableTool {
this.copies = copies > 0 ? copies : -1; this.copies = copies > 0 ? copies : -1;
} }
private Vector3 getSidePos(Interpolation interpol, double position, Clipboard clipboard, boolean rightHand) {
Vector3 pos = interpol.getPosition(position);
Vector3 deriv = interpol.get1stDerivative(position);
double length = (rightHand ? 1 : -1) * Math.abs(
clipboard.getOrigin().getBlockZ() - clipboard.getRegion().getMinimumPoint().getBlockZ()
);
Vector3 cross = deriv.cross(Vector3.UNIT_Y);
if (cross.equals(Vector3.ZERO)) {
return null;
}
Vector3 perpendicular = cross.normalize().multiply(length);
return pos.add(perpendicular);
}
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
boolean visualization = editSession.getExtent() instanceof VisualExtent; boolean visualization = editSession.getExtent() instanceof VisualExtent;
@ -82,7 +67,7 @@ public class SweepBrush implements Brush, ResettableTool {
return; return;
} }
Interpolation interpol = new KochanekBartelsInterpolation(); Interpolation interpol = new ReparametrisingInterpolation(new KochanekBartelsInterpolation());
List<Node> nodes = positions.stream().map(v -> { List<Node> nodes = positions.stream().map(v -> {
Node n = new Node(v.toVector3()); Node n = new Node(v.toVector3());
n.setTension(tension); n.setTension(tension);
@ -114,30 +99,11 @@ public class SweepBrush implements Brush, ResettableTool {
break; break;
} }
case -1: { case -1: {
double splineLength = interpol.arcLength(0D, 1D); double length = interpol.arcLength(0, 1);
double blockDistance = 1d / splineLength; double step = 1 / (length * quality);
double step = blockDistance / quality; for (double pos = 0; pos <= 1; pos += step) {
MutableVector3 lastLHS = new MutableVector3(getSidePos(interpol, 0, clipboard, false).round());
MutableVector3 lastRHS = new MutableVector3(getSidePos(interpol, 0, clipboard, true).round());
for (double pos = 0D; pos <= 1D; pos += step) {
Vector3 lhs = getSidePos(interpol, pos, clipboard, false);
boolean doLeft = lhs == null || !lhs.round().equals(lastLHS);
if (doLeft && lhs != null) {
lastLHS.setComponents(lhs.round());
}
Vector3 rhs = getSidePos(interpol, pos, clipboard, true);
boolean doRight = rhs == null || !rhs.round().equals(lastRHS);
if (doRight && rhs != null) {
lastRHS.setComponents(rhs.round());
}
// Only paste if the edges have passed the previous edges
if (doLeft || doRight) {
spline.pastePosition(pos); spline.pastePosition(pos);
} }
}
break; break;
} }
default: { default: {