Search in sources :

Example 1 with HeightMap

use of com.sk89q.worldedit.math.convolution.HeightMap in project FastAsyncWorldEdit by IntellectualSites.

the class SmoothBrush method build.

@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
    Vector3 posDouble = position.toVector3();
    Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
    BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
    Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max);
    HeightMap heightMap = new HeightMap(editSession, region, mask);
    HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
    heightMap.applyFilter(filter, iterations);
}
Also used : HeightMapFilter(com.sk89q.worldedit.math.convolution.HeightMapFilter) HeightMap(com.sk89q.worldedit.math.convolution.HeightMap) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) GaussianKernel(com.sk89q.worldedit.math.convolution.GaussianKernel) Location(com.sk89q.worldedit.util.Location)

Example 2 with HeightMap

use of com.sk89q.worldedit.math.convolution.HeightMap in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method smooth.

@Command(name = "/smooth", desc = "Smooth the elevation in the selection", descFooter = "Example: '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain.")
@CommandPermissions("worldedit.region.smooth")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int smooth(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "# of iterations to perform", def = "1") int iterations, @Arg(desc = "The mask of blocks to use as the height map", def = "") Mask mask) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    int affected;
    try {
        HeightMap heightMap = new HeightMap(editSession, region, mask);
        HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
        affected = heightMap.applyFilter(filter, iterations);
        actor.print(Caption.of("worldedit.smooth.changed", TextComponent.of(affected)));
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return affected;
}
Also used : HeightMapFilter(com.sk89q.worldedit.math.convolution.HeightMapFilter) HeightMap(com.sk89q.worldedit.math.convolution.HeightMap) SnowHeightMap(com.sk89q.worldedit.math.convolution.SnowHeightMap) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) GaussianKernel(com.sk89q.worldedit.math.convolution.GaussianKernel) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 GaussianKernel (com.sk89q.worldedit.math.convolution.GaussianKernel)2 HeightMap (com.sk89q.worldedit.math.convolution.HeightMap)2 HeightMapFilter (com.sk89q.worldedit.math.convolution.HeightMapFilter)2 FaweLimit (com.fastasyncworldedit.core.limit.FaweLimit)1 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 Logging (com.sk89q.worldedit.command.util.Logging)1 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)1 Preload (com.sk89q.worldedit.command.util.annotation.Preload)1 Vector3 (com.sk89q.worldedit.math.Vector3)1 SnowHeightMap (com.sk89q.worldedit.math.convolution.SnowHeightMap)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Region (com.sk89q.worldedit.regions.Region)1 Location (com.sk89q.worldedit.util.Location)1 Command (org.enginehub.piston.annotation.Command)1