Added simple smoothing brush.

Dieser Commit ist enthalten in:
sk89q 2011-02-18 23:48:27 -08:00
Ursprung 7f25262572
Commit d5e8f037c9
3 geänderte Dateien mit 87 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -14,6 +14,9 @@ commands:
description: Choose the clipboard brush
usage: /<command> [-a]
aliases: ['copy']
smooth:
description: Choose the terrain softener brush
usage: /<command> [size] [iterations]
chunkinfo:
description: Get information about the chunk that you are inside
usage: /<command>
@ -107,6 +110,9 @@ commands:
up:
description: Go upwards some distance
usage: /<command> <block>
/smooth:
description: Smooth the elevation in the selection
usage: /<command> [iterations]
/overlay:
description: Set a block on top of blocks in the region
usage: /<command> <block>
@ -117,9 +123,6 @@ commands:
description: Build the walls, ceiling, and roof of a selection
usage: /<command> <block>
aliases: ['/outline']
/smooth:
description: Smooth the elevation in the selection
usage: /<command> [iterations]
/replace:
description: Replace all blocks in the selection with another
usage: /<command> [from-block] <to-block>

Datei anzeigen

@ -36,6 +36,7 @@ import com.sk89q.worldedit.tools.brushes.ClipboardBrush;
import com.sk89q.worldedit.tools.brushes.CylinderBrush;
import com.sk89q.worldedit.tools.brushes.HollowCylinderBrush;
import com.sk89q.worldedit.tools.brushes.HollowSphereBrush;
import com.sk89q.worldedit.tools.brushes.SmoothBrush;
import com.sk89q.worldedit.tools.brushes.SphereBrush;
/**
@ -162,4 +163,35 @@ public class BrushCommands {
player.print("Clipboard brush shape equipped.");
}
@Command(
aliases = {"smooth"},
usage = "[size] [iterations]",
desc = "Choose the terrain softener brush",
min = 0,
max = 2
)
@CommandPermissions({"worldedit.brush.smooth"})
public static void smoothBrush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int radius = args.argsLength() > 0 ? args.getInteger(0) : 2;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
int iterations = args.argsLength() > 1 ? args.getInteger(1) : 4;
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius);
tool.setBrush(new SmoothBrush(iterations));
player.print(String.format("Smooth brush equipped (%d x %dx).",
radius, iterations));
}
}

Datei anzeigen

@ -0,0 +1,49 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.HeightMap;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.filtering.GaussianKernel;
import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
public class SmoothBrush implements Brush {
private int iterations;
public SmoothBrush(int iterations) {
this.iterations = iterations;
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException {
int rad = size;
Vector min = pos.subtract(rad, rad, rad);
Vector max = pos.add(rad, rad + 10, rad);
Region region = new CuboidRegion(min, max);
HeightMap heightMap = new HeightMap(editSession, region);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
heightMap.applyFilter(filter, iterations);
}
}