Search in sources :

Example 1 with Interpolation

use of com.sk89q.worldedit.math.interpolation.Interpolation in project FastAsyncWorldEdit by IntellectualSites.

the class EditSession method drawSpline.

/**
 * Draws a spline (out of blocks) between specified vectors.
 *
 * @param pattern     The block pattern used to draw the spline.
 * @param nodevectors The list of vectors to draw through.
 * @param tension     The tension of every node.
 * @param bias        The bias of every node.
 * @param continuity  The continuity of every node.
 * @param quality     The quality of the spline. Must be greater than 0.
 * @param radius      The radius (thickness) of the spline.
 * @param filled      If false, only a shell will be generated.
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int drawSpline(Pattern pattern, List<BlockVector3> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled) throws MaxChangedBlocksException {
    LocalBlockVectorSet vset = new LocalBlockVectorSet();
    List<Node> nodes = new ArrayList<>(nodevectors.size());
    Interpolation interpol = new KochanekBartelsInterpolation();
    for (BlockVector3 nodevector : nodevectors) {
        Node n = new Node(nodevector.toVector3());
        n.setTension(tension);
        n.setBias(bias);
        n.setContinuity(continuity);
        nodes.add(n);
    }
    interpol.setNodes(nodes);
    double splinelength = interpol.arcLength(0, 1);
    for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
        BlockVector3 tipv = interpol.getPosition(loop).toBlockPoint();
        if (radius == 0) {
            pattern.apply(this, tipv, tipv);
            changes++;
        } else {
            vset.add(tipv);
        }
    }
    Set<BlockVector3> newVset;
    if (radius != 0) {
        newVset = getBallooned(vset, radius);
        if (!filled) {
            newVset = this.getHollowed(newVset);
        }
        return this.changes += setBlocks(newVset, pattern);
    }
    return changes;
}
Also used : KochanekBartelsInterpolation(com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation) Interpolation(com.sk89q.worldedit.math.interpolation.Interpolation) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) Node(com.sk89q.worldedit.math.interpolation.Node) KochanekBartelsInterpolation(com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation) ArrayList(java.util.ArrayList) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Aggregations

LocalBlockVectorSet (com.fastasyncworldedit.core.math.LocalBlockVectorSet)1 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 Interpolation (com.sk89q.worldedit.math.interpolation.Interpolation)1 KochanekBartelsInterpolation (com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation)1 Node (com.sk89q.worldedit.math.interpolation.Node)1 ArrayList (java.util.ArrayList)1