Search in sources :

Example 1 with Void

use of org.pepsoft.worldpainter.layers.Void in project WorldPainter by Captain-Chaos.

the class ImportHeightMapDialog method exportToDimension.

private void exportToDimension() {
    if (currentDimension == null) {
        throw new IllegalStateException();
    }
    final HeightMapImporter importer = new HeightMapImporter();
    HeightMap heightMap = new BitmapHeightMap(selectedFile.getName(), image, 0, selectedFile, false, false);
    int scale = (Integer) spinnerScale.getValue();
    int offsetX = (Integer) spinnerOffsetX.getValue();
    int offsetY = (Integer) spinnerOffsetY.getValue();
    if ((scale != 100) || (offsetX != 0) || (offsetY != 0)) {
        ((BitmapHeightMap) heightMap).setSmoothScaling(true);
        heightMap = new TransformingHeightMap(heightMap.getName() + " transformed", heightMap, scale, scale, offsetX, offsetY, 0);
    }
    if (checkBoxInvert.isSelected()) {
        if (image.getSampleModel().getSampleSize(0) == 16) {
            heightMap = new DifferenceHeightMap(new ConstantHeightMap(65535f), heightMap);
        } else {
            heightMap = new DifferenceHeightMap(new ConstantHeightMap(255f), heightMap);
        }
    }
    importer.setHeightMap(heightMap);
    importer.setImageFile(selectedFile);
    String name = selectedFile.getName();
    int p = name.lastIndexOf('.');
    if (p != -1) {
        name = name.substring(0, p);
    }
    importer.setName(name);
    importer.setTileFactory(tileFactory);
    importer.setMaxHeight(Integer.parseInt((String) comboBoxHeight.getSelectedItem()));
    importer.setImageLowLevel((Integer) spinnerImageLow.getValue());
    importer.setImageHighLevel((Integer) spinnerImageHigh.getValue());
    importer.setWorldLowLevel((Integer) spinnerWorldLow.getValue());
    importer.setWorldWaterLevel((Integer) spinnerWorldMiddle.getValue());
    importer.setWorldHighLevel((Integer) spinnerWorldHigh.getValue());
    importer.setVoidBelowLevel(checkBoxVoid.isSelected() ? ((Integer) spinnerVoidBelow.getValue()) : 0);
    importer.setOnlyRaise(checkBoxOnlyRaise.isSelected());
    ProgressDialog.executeTask(this, new ProgressTask<Void>() {

        @Override
        public String getName() {
            return "Importing height map";
        }

        @Override
        public Void execute(ProgressReceiver progressReceiver) throws OperationCancelled {
            importer.importToDimension(currentDimension, checkBoxCreateTiles.isSelected(), progressReceiver);
            return null;
        }
    }, false);
    Configuration.getInstance().setHeightMapsDirectory(selectedFile.getParentFile());
    currentDimension.clearUndo();
    currentDimension.armSavePoint();
}
Also used : HeightMapImporter(org.pepsoft.worldpainter.importing.HeightMapImporter) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) ProgressReceiver(org.pepsoft.util.ProgressReceiver) Void(org.pepsoft.worldpainter.layers.Void)

Aggregations

ProgressReceiver (org.pepsoft.util.ProgressReceiver)1 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)1 HeightMapImporter (org.pepsoft.worldpainter.importing.HeightMapImporter)1 Void (org.pepsoft.worldpainter.layers.Void)1