Search in sources :

Example 1 with TransformingHeightMap

use of org.pepsoft.worldpainter.heightMaps.TransformingHeightMap in project WorldPainter by Captain-Chaos.

the class ImportHeightMapOp method go.

@Override
public World2 go() throws ScriptException {
    goCalled();
    if (heightMap == null) {
        throw new ScriptException("heightMap not set");
    }
    HeightMap adjustedHeightMap = heightMap;
    if ((scale != 100) || (offsetX != 0) || (offsetY != 0)) {
        heightMap.setSmoothScaling(true);
        adjustedHeightMap = new TransformingHeightMap(heightMap.getName() + " transformed", heightMap, scale, scale, offsetX, offsetY, 0);
    }
    importer.setHeightMap(adjustedHeightMap);
    importer.setImageFile(heightMap.getImageFile());
    HeightMapTileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(new Random().nextLong(), Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 58, 62, false, true, 20, 1.0);
    Theme defaults = Configuration.getInstance().getHeightMapDefaultTheme();
    if (defaults != null) {
        tileFactory.setTheme(defaults);
    }
    importer.setTileFactory(tileFactory);
    String name = heightMap.getName();
    int p = name.lastIndexOf('.');
    if (p != -1) {
        name = name.substring(0, p);
    }
    importer.setName(name);
    try {
        return importer.importToNewWorld(null);
    } catch (ProgressReceiver.OperationCancelled e) {
        // Can never happen since we don't pass a progress receiver in
        throw new InternalError();
    }
}
Also used : TransformingHeightMap(org.pepsoft.worldpainter.heightMaps.TransformingHeightMap) BitmapHeightMap(org.pepsoft.worldpainter.heightMaps.BitmapHeightMap) Random(java.util.Random) ProgressReceiver(org.pepsoft.util.ProgressReceiver) Theme(org.pepsoft.worldpainter.themes.Theme) TransformingHeightMap(org.pepsoft.worldpainter.heightMaps.TransformingHeightMap)

Aggregations

Random (java.util.Random)1 ProgressReceiver (org.pepsoft.util.ProgressReceiver)1 BitmapHeightMap (org.pepsoft.worldpainter.heightMaps.BitmapHeightMap)1 TransformingHeightMap (org.pepsoft.worldpainter.heightMaps.TransformingHeightMap)1 Theme (org.pepsoft.worldpainter.themes.Theme)1