use of org.pepsoft.worldpainter.Terrain.GRASS in project WorldPainter by Captain-Chaos.
the class HeightMapEditor method createHeightMap.
private void createHeightMap() throws IOException {
rootHeightMap = TileFactoryFactory.createFancyTileFactory(new Random().nextLong(), GRASS, DEFAULT_MAX_HEIGHT_2, 62, 58, false, 20f, 1.0).getHeightMap();
// File bitmapFile = new File("/home/pepijn/Pictures/WorldPainter/test-image-8-bit-grayscale.png");
// BufferedImage bitmap = ImageIO.read(bitmapFile);
// BitmapHeightMap bitmapHeightMap = BitmapHeightMap.build().withImage(bitmap).withSmoothScaling(false).withRepeat(true).now();
// TransformingHeightMap scaledHeightMap = TransformingHeightMap.build().withHeightMap(bitmapHeightMap).withScale(300).now();
// NoiseHeightMap angleMap = new NoiseHeightMap("Angle", (float) (Math.PI * 2), 2.5f, 1);
// NoiseHeightMap distanceMap = new NoiseHeightMap("Distance", 25f, 2.5f, 1);
// heightMap = new DisplacementHeightMap(scaledHeightMap, angleMap, distanceMap);
focusOn(rootHeightMap);
installHeightMap(true);
jTree1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent event) {
if (event.isPopupTrigger()) {
showPopupMenu(event);
}
}
@Override
public void mouseReleased(MouseEvent event) {
if (event.isPopupTrigger()) {
showPopupMenu(event);
}
}
private void showPopupMenu(MouseEvent event) {
TreePath path = jTree1.getPathForLocation(event.getX(), event.getY());
if (path == null) {
return;
}
jTree1.setSelectionPath(path);
HeightMap heightMap = (HeightMap) path.getLastPathComponent();
TreePath parentPath = path.getParentPath();
DelegatingHeightMap parent;
if (parentPath != null) {
parent = (DelegatingHeightMap) parentPath.getLastPathComponent();
} else {
parent = null;
}
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Focus Here");
menuItem.addActionListener(actionEvent -> {
focusOn(heightMap);
installHeightMap(false);
});
menu.add(menuItem);
JMenu insertMenu = new JMenu("Insert");
menuItem = new JMenuItem("Product");
menuItem.addActionListener(actionEvent -> {
ProductHeightMap productHeightMap = new ProductHeightMap(heightMap, new ConstantHeightMap(1.0f));
replace(parent, heightMap, productHeightMap);
});
insertMenu.add(menuItem);
menuItem = new JMenuItem("Sum");
menuItem.addActionListener(actionEvent -> {
SumHeightMap sumHeightMap = new SumHeightMap(heightMap, new ConstantHeightMap(0.0f));
replace(parent, heightMap, sumHeightMap);
});
insertMenu.add(menuItem);
menuItem = new JMenuItem("Maximum");
menuItem.addActionListener(actionEvent -> {
MaximisingHeightMap maximisingHeightMap = new MaximisingHeightMap(heightMap, new ConstantHeightMap(0.0f));
replace(parent, heightMap, maximisingHeightMap);
});
insertMenu.add(menuItem);
menuItem = new JMenuItem("Slope");
menuItem.addActionListener(actionEvent -> {
SlopeHeightMap slopeHeightMap = new SlopeHeightMap(heightMap);
replace(parent, heightMap, slopeHeightMap);
});
insertMenu.add(menuItem);
menuItem = new JMenuItem("Displacement");
menuItem.addActionListener(actionEvent -> {
DisplacementHeightMap displacementHeightMap = new DisplacementHeightMap(heightMap, new ConstantHeightMap(0.0f), new ConstantHeightMap(0.0f));
replace(parent, heightMap, displacementHeightMap);
});
insertMenu.add(menuItem);
menuItem = new JMenuItem("Transformation");
menuItem.addActionListener(actionEvent -> {
TransformingHeightMap transformingHeightMap = new TransformingHeightMap(heightMap.getName(), heightMap, 100, 100, 0, 0, 0);
replace(parent, heightMap, transformingHeightMap);
});
insertMenu.add(menuItem);
menuItem = new JMenuItem("Shelves");
menuItem.addActionListener(actionEvent -> {
ShelvingHeightMap shelvingHeightMap = new ShelvingHeightMap(heightMap);
replace(parent, heightMap, shelvingHeightMap);
});
insertMenu.add(menuItem);
menu.add(insertMenu);
JMenu replaceMenu = new JMenu("Replace");
menuItem = new JMenuItem("Mandelbrot");
menuItem.addActionListener(actionEvent -> {
MandelbrotHeightMap mandelbrotHeightMap = new MandelbrotHeightMap();
replace(parent, heightMap, mandelbrotHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Nine Patch");
menuItem.addActionListener(actionEvent -> {
NinePatchHeightMap ninePatchHeightMap = new NinePatchHeightMap(100, 25, 1.0f);
replace(parent, heightMap, ninePatchHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Constant");
menuItem.addActionListener(actionEvent -> {
ConstantHeightMap constantHeightMap = new ConstantHeightMap(1.0f);
replace(parent, heightMap, constantHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Bitmap");
menuItem.addActionListener(actionEvent -> {
File myHeightMapDir = Configuration.getInstance().getHeightMapsDirectory();
final Set<String> extensions = new HashSet<>(Arrays.asList(ImageIO.getReaderFileSuffixes()));
StringBuilder sb = new StringBuilder("Supported image formats (");
boolean first = true;
for (String extension : extensions) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append("*.");
sb.append(extension);
}
sb.append(')');
final String description = sb.toString();
File file = FileUtils.selectFileForOpen(HeightMapEditor.this, "Select a height map image file", myHeightMapDir, new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String filename = f.getName();
int p = filename.lastIndexOf('.');
if (p != -1) {
String extension = filename.substring(p + 1).toLowerCase();
return extensions.contains(extension);
} else {
return false;
}
}
@Override
public String getDescription() {
return description;
}
});
if (file != null) {
try {
BufferedImage image = ImageIO.read(file);
BitmapHeightMap bitmapHeightMap = new BitmapHeightMap(file.getName(), image, 0, file, false, false);
replace(parent, heightMap, bitmapHeightMap);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Noise");
menuItem.addActionListener(actionEvent -> {
NoiseHeightMap noiseHeightMap = new NoiseHeightMap(1f, 1.0, 1);
replace(parent, heightMap, noiseHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Bands");
menuItem.addActionListener(actionEvent -> {
BandedHeightMap bandedHeightMap = new BandedHeightMap();
replace(parent, heightMap, bandedHeightMap);
});
replaceMenu.add(menuItem);
replaceMenu.addSeparator();
menuItem = new JMenuItem("Product");
menuItem.addActionListener(actionEvent -> {
ProductHeightMap productHeightMap = new ProductHeightMap(new ConstantHeightMap(1.0f), new ConstantHeightMap(1.0f));
replace(parent, heightMap, productHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Sum");
menuItem.addActionListener(actionEvent -> {
SumHeightMap sumHeightMap = new SumHeightMap(new ConstantHeightMap(0.5f), new ConstantHeightMap(0.5f));
replace(parent, heightMap, sumHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Maximum");
menuItem.addActionListener(actionEvent -> {
MaximisingHeightMap maximisingHeightMap = new MaximisingHeightMap(new ConstantHeightMap(1.0f), new ConstantHeightMap(1.0f));
replace(parent, heightMap, maximisingHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Slope");
menuItem.addActionListener(actionEvent -> {
SlopeHeightMap slopeHeightMap = new SlopeHeightMap(new ConstantHeightMap(1.0f));
replace(parent, heightMap, slopeHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Displacement");
menuItem.addActionListener(actionEvent -> {
DisplacementHeightMap displacementHeightMap = new DisplacementHeightMap(new ConstantHeightMap(1.0f), new ConstantHeightMap(0.0f), new ConstantHeightMap(0.0f));
replace(parent, heightMap, displacementHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Transformation");
menuItem.addActionListener(actionEvent -> {
TransformingHeightMap transformingHeightMap = new TransformingHeightMap(null, new ConstantHeightMap(1.0f), 100, 100, 0, 0, 0);
replace(parent, heightMap, transformingHeightMap);
});
replaceMenu.add(menuItem);
menuItem = new JMenuItem("Shelves");
menuItem.addActionListener(actionEvent -> {
ShelvingHeightMap shelvingHeightMap = new ShelvingHeightMap(new ConstantHeightMap(1.0f));
replace(parent, heightMap, shelvingHeightMap);
});
replaceMenu.add(menuItem);
menu.add(replaceMenu);
if (heightMap instanceof DelegatingHeightMap) {
menuItem = new JMenuItem("Delete");
menuItem.addActionListener(e -> {
replace(parent, heightMap, ((DelegatingHeightMap) heightMap).getHeightMap(0));
treeModel.notifyListeners();
});
menu.add(menuItem);
}
menu.show(jTree1, event.getX(), event.getY());
}
private void replace(DelegatingHeightMap parent, HeightMap oldHeightMap, HeightMap newHeightMap) {
if (parent == null) {
HeightMapEditor.this.rootHeightMap = newHeightMap;
focusOn(newHeightMap);
installHeightMap(true);
} else {
parent.replace(oldHeightMap, newHeightMap);
if (oldHeightMap == HeightMapEditor.this.focusHeightMap) {
focusOn(newHeightMap);
}
treeModel.notifyListeners();
synchronized (tileCache) {
tileCache.clear();
tileCache.notifyAll();
}
tiledImageViewer1.refresh(true);
}
}
});
}
Aggregations