Sweep brush semi-fix

This commit is contained in:
Hazel Trinity 2020-08-15 14:20:47 -07:00
parent da9c4ad543
commit e51f6e562d
3 changed files with 37 additions and 14 deletions

View File

@ -129,7 +129,7 @@ public abstract class Spline {
// Calculate position from spline // Calculate position from spline
BlockVector3 target = interpolation.getPosition(position).toBlockPoint(); BlockVector3 target = interpolation.getPosition(position).toBlockPoint();
BlockVector3 offset = target.subtract(target.round()); BlockVector3 offset = target.subtract(target.round());
target = target.subtract(offset); target = target.subtract(offset).round();
// Calculate rotation from spline // Calculate rotation from spline

View File

@ -13,11 +13,13 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.math.Vector2;
import com.sk89q.worldedit.math.Vector3; 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.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
@ -39,6 +41,22 @@ 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;
@ -99,18 +117,24 @@ public class SweepBrush implements Brush, ResettableTool {
double splineLength = interpol.arcLength(0D, 1D); double splineLength = interpol.arcLength(0D, 1D);
double blockDistance = 1d / splineLength; double blockDistance = 1d / splineLength;
double step = blockDistance / quality; double step = blockDistance / quality;
double accumulation = 0; MutableVector3 lastLHS = new MutableVector3(getSidePos(interpol, 0, clipboard, false).round());
MutableVector3 last = new MutableVector3(0, 0, 0); MutableVector3 lastRHS = new MutableVector3(getSidePos(interpol, 0, clipboard, true).round());
for (double pos = 0D; pos <= 1D; pos += step) { for (double pos = 0D; pos <= 1D; pos += step) {
Vector3 gradient = interpol.get1stDerivative(pos); Vector3 lhs = getSidePos(interpol, pos, clipboard, false);
double dist = MathMan.sqrtApprox(last.distanceSq(gradient)); boolean doLeft = lhs == null || !lhs.round().equals(lastLHS);
last.mutX(gradient.getX()); if (doLeft && lhs != null) {
last.mutY(gradient.getY()); lastLHS.setComponents(lhs.round());
last.mutZ(gradient.getZ()); }
double change = dist * step;
// Accumulation is arbitrary, but much faster than calculation overlapping regions Vector3 rhs = getSidePos(interpol, pos, clipboard, true);
if ((accumulation += change + step * 2) > blockDistance) { boolean doRight = rhs == null || !rhs.round().equals(lastRHS);
accumulation -= blockDistance; 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);
} }
} }

View File

@ -17,8 +17,7 @@ public class RoundedTransform implements Transform {
@Override @Override
public Vector3 apply(Vector3 input) { public Vector3 apply(Vector3 input) {
Vector3 val = transform.apply(input); Vector3 val = transform.apply(input);
return Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math return val.round();
.floor(val.getY() + 0.5));
} }
@Override @Override