Fix sspl with visual enabled

This commit is contained in:
Jesse Boyd 2017-03-13 04:07:54 +11:00
parent 147cfeed10
commit 6400505807
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
1 changed files with 41 additions and 38 deletions

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.brush; package com.boydti.fawe.object.brush;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.brush.visualization.VisualExtent;
import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
@ -28,55 +29,57 @@ public class SurfaceSpline implements Brush {
@Override @Override
public void build(EditSession editSession, Vector pos, Pattern pattern, double radius) throws MaxChangedBlocksException { public void build(EditSession editSession, Vector pos, Pattern pattern, double radius) throws MaxChangedBlocksException {
int maxY = editSession.getMaxY(); int maxY = editSession.getMaxY();
boolean vis = editSession.getExtent() instanceof VisualExtent;
if (path.isEmpty() || !pos.equals(path.get(path.size() - 1))) { if (path.isEmpty() || !pos.equals(path.get(path.size() - 1))) {
int max = editSession.getNearestSurfaceTerrainBlock(pos.getBlockX(), pos.getBlockZ(), pos.getBlockY(), 0, editSession.getMaxY()); int max = editSession.getNearestSurfaceTerrainBlock(pos.getBlockX(), pos.getBlockZ(), pos.getBlockY(), 0, editSession.getMaxY());
pos.mutY(max); pos.mutY(max);
path.add(pos); path.add(pos);
editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_PRIMARY_2.s()); editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_PRIMARY_2.s());
} else{ if (!vis) return;
LocalBlockVectorSet vset = new LocalBlockVectorSet(); }
final List<Node> nodes = new ArrayList<>(path.size()); LocalBlockVectorSet vset = new LocalBlockVectorSet();
final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation(); final List<Node> nodes = new ArrayList<>(path.size());
final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation();
for (final Vector nodevector : path) { for (final Vector nodevector : path) {
final Node n = new Node(nodevector); final Node n = new Node(nodevector);
n.setTension(tension); n.setTension(tension);
n.setBias(bias); n.setBias(bias);
n.setContinuity(continuity); n.setContinuity(continuity);
nodes.add(n); nodes.add(n);
}
interpol.setNodes(nodes);
final double splinelength = interpol.arcLength(0, 1);
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
final Vector tipv = interpol.getPosition(loop);
final int tipx = (int) Math.round(tipv.getX());
final int tipz = (int) tipv.getZ();
int tipy = (int) Math.round(tipv.getY());
tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY);
if (radius == 0) {
editSession.setBlock(tipx, tipy, tipz, pattern.next(tipx, tipy, tipz));
} else {
vset.add(tipx, tipy, tipz);
} }
interpol.setNodes(nodes); }
final double splinelength = interpol.arcLength(0, 1); if (radius != 0) {
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) { double radius2 = (radius * radius);
final Vector tipv = interpol.getPosition(loop); LocalBlockVectorSet newSet = new LocalBlockVectorSet();
final int tipx = (int) Math.round(tipv.getX()); final int ceilrad = (int) Math.ceil(radius);
final int tipz = (int) tipv.getZ(); for (final Vector v : vset) {
int tipy = (int) Math.round(tipv.getY()); final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ();
tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY); for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) {
if (radius == 0) { for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) {
editSession.setBlock(tipx, tipy, tipz, pattern.next(tipx, tipy, tipz)); if (MathMan.hypot2(loopx - tipx, 0, loopz - tipz) <= radius2) {
} else { int y = editSession.getNearestSurfaceTerrainBlock(loopx, loopz, v.getBlockY(), 0, maxY);
vset.add(tipx, tipy, tipz); newSet.add(loopx, y, loopz);
}
}
if (radius != 0) {
double radius2 = (radius * radius);
LocalBlockVectorSet newSet = new LocalBlockVectorSet();
final int ceilrad = (int) Math.ceil(radius);
for (final Vector v : vset) {
final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ();
for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) {
for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) {
if (MathMan.hypot2(loopx - tipx, 0, loopz - tipz) <= radius2) {
int y = editSession.getNearestSurfaceTerrainBlock(loopx, loopz, v.getBlockY(), 0, maxY);
newSet.add(loopx, y, loopz);
}
} }
} }
} }
editSession.setBlocks(newSet, pattern);
} }
editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_SECONDARY.s()); editSession.setBlocks(newSet, pattern);
if (!vis) path.clear();
} }
editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_SECONDARY.s());
} }
} }