Search in sources :

Example 1 with NoiseHeightMap

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

the class NoiseTileFactory method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    // Legacy support
    if (!beachesMigrated) {
        setBeaches(beaches);
        setRandomise(true);
        beachesMigrated = true;
    }
    if (range == 0) {
        baseHeight++;
        range = 20;
        scale = 1.0;
    }
    if (getHeightMap() == null) {
        setHeightMap(new SumHeightMap(new ConstantHeightMap(baseHeight), new NoiseHeightMap(range, scale, 1)));
    }
    perlinNoise = null;
}
Also used : SumHeightMap(org.pepsoft.worldpainter.heightMaps.SumHeightMap) NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) ConstantHeightMap(org.pepsoft.worldpainter.heightMaps.ConstantHeightMap)

Example 2 with NoiseHeightMap

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

the class TileFactoryFactory method createFancyTileFactory.

public static HeightMapTileFactory createFancyTileFactory(long seed, Terrain terrain, int maxHeight, int baseHeight, int waterLevel, boolean floodWithLava, float range, double scale) {
    // final HeightMapTileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(Terrain.GRASS, World2.DEFAULT_MAX_HEIGHT, 58, 62, false, true, 20.0f, 1.0);
    HeightMap oceanFloor = new ConstantHeightMap("Ocean Floor", waterLevel - 22);
    HeightMap continent;
    // continent = new NinePatchHeightMap(200, 100, 50, 58f);
    continent = new NinePatchHeightMap("Continent", 0, 500, 50, baseHeight - (waterLevel - 22));
    Random random = new Random(seed);
    HeightMap hills = new ProductHeightMap("Hills", new NoiseHeightMap(1.0f, 10f, 1, random.nextLong()), new NoiseHeightMap(range, scale, 2, random.nextLong()));
    // new SumHeightMap(
    // new NoiseHeightMap(range, scale, 2),
    // new ConstantHeightMap(-5f)));
    continent = new SumHeightMap(new SumHeightMap(oceanFloor, continent), hills);
    HeightMap mountainsLimit = new NinePatchHeightMap(0, 500, 200, 1f);
    HeightMap mountainsHeight = new ProductHeightMap(new ProductHeightMap(new NoiseHeightMap(1.0f, 10f, 1, random.nextLong()), mountainsLimit), new NoiseHeightMap(256f, 5f, 5, random.nextLong()));
    HeightMap mountainsAngleMap = new NoiseHeightMap((float) (Math.PI * 2), 2.5, 1, random.nextLong());
    HeightMap mountainsDistanceMap = new NoiseHeightMap(25f, 2.5, 1, random.nextLong());
    HeightMap mountains = new DisplacementHeightMap("Mountains", mountainsHeight, mountainsAngleMap, mountainsDistanceMap);
    HeightMap heightMap = new MaximisingHeightMap(continent, mountains);
    return new HeightMapTileFactory(seed, heightMap, 256, false, new FancyTheme(maxHeight, 62, heightMap, terrain));
}
Also used : SumHeightMap(org.pepsoft.worldpainter.heightMaps.SumHeightMap) NinePatchHeightMap(org.pepsoft.worldpainter.heightMaps.NinePatchHeightMap) ConstantHeightMap(org.pepsoft.worldpainter.heightMaps.ConstantHeightMap) NinePatchHeightMap(org.pepsoft.worldpainter.heightMaps.NinePatchHeightMap) ProductHeightMap(org.pepsoft.worldpainter.heightMaps.ProductHeightMap) SumHeightMap(org.pepsoft.worldpainter.heightMaps.SumHeightMap) NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) MaximisingHeightMap(org.pepsoft.worldpainter.heightMaps.MaximisingHeightMap) DisplacementHeightMap(org.pepsoft.worldpainter.heightMaps.DisplacementHeightMap) Random(java.util.Random) ProductHeightMap(org.pepsoft.worldpainter.heightMaps.ProductHeightMap) DisplacementHeightMap(org.pepsoft.worldpainter.heightMaps.DisplacementHeightMap) NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) FancyTheme(org.pepsoft.worldpainter.themes.impl.fancy.FancyTheme) MaximisingHeightMap(org.pepsoft.worldpainter.heightMaps.MaximisingHeightMap) ConstantHeightMap(org.pepsoft.worldpainter.heightMaps.ConstantHeightMap)

Example 3 with NoiseHeightMap

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

the class MixedMaterial method init.

private void init() {
    switch(mode) {
        case SIMPLE:
            if (rows.length != 1) {
                throw new IllegalArgumentException("Only one row allowed for SIMPLE mode");
            }
            simpleMaterial = rows[0].material;
            break;
        case NOISE:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for NOISE mode");
            }
            materials = new Material[1000];
            int index = 0;
            for (Row row : rows) {
                for (int i = 0; i < row.occurrence; i++) {
                    materials[index++] = row.material;
                }
            }
            random = new Random();
            break;
        case BLOBS:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for BLOBS mode");
            }
            sortedRows = Arrays.copyOf(rows, rows.length);
            Arrays.sort(sortedRows, (r1, r2) -> r1.occurrence - r2.occurrence);
            noiseGenerators = new PerlinNoise[rows.length - 1];
            int cumulativePermillage = 0;
            for (int i = 0; i < noiseGenerators.length; i++) {
                noiseGenerators[i] = new PerlinNoise(0);
                cumulativePermillage += sortedRows[i].occurrence * (1000 - cumulativePermillage) / 1000;
                sortedRows[i].chance = PerlinNoise.getLevelForPromillage(cumulativePermillage);
            }
            break;
        case LAYERED:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for LAYERED mode");
            }
            if ((!repeat) && ((layerXSlope != 0) || (layerYSlope != 0))) {
                throw new IllegalArgumentException("Angle may not be non-zero if repeat is false");
            }
            List<Material> tmpMaterials = new ArrayList<>(org.pepsoft.minecraft.Constants.DEFAULT_MAX_HEIGHT_2);
            for (int i = rows.length - 1; i >= 0; i--) {
                for (int j = 0; j < rows[i].occurrence; j++) {
                    tmpMaterials.add(rows[i].material);
                }
            }
            materials = tmpMaterials.toArray(new Material[tmpMaterials.size()]);
            if (variation != null) {
                layerNoiseheightMap = new NoiseHeightMap(variation, NOISE_SEED_OFFSET);
                layerNoiseOffset = variation.getRange();
            } else {
                layerNoiseheightMap = null;
                layerNoiseOffset = 0;
            }
            break;
    }
}
Also used : NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) PerlinNoise(org.pepsoft.util.PerlinNoise) Material(org.pepsoft.minecraft.Material)

Example 4 with NoiseHeightMap

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

the class TunnelLayerExporter method render.

@Override
public List<Fixup> render(Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld world) {
    final TunnelLayer.Mode floorMode = layer.getFloorMode(), roofMode = layer.getRoofMode();
    final int floorWallDepth = layer.getFloorWallDepth(), roofWallDepth = layer.getRoofWallDepth(), floorLevel = layer.getFloorLevel(), roofLevel = layer.getRoofLevel(), maxWallDepth = Math.max(floorWallDepth, roofWallDepth) + 1, floorMin = layer.getFloorMin(), floorMax = layer.getFloorMax(), roofMin = layer.getRoofMin(), roofMax = layer.getRoofMax(), floodLevel = layer.getFloodLevel();
    final int minZ = dimension.isBottomless() ? 0 : 1, maxZ = dimension.getMaxHeight() - 1;
    final boolean removeWater = layer.isRemoveWater(), floodWithLava = layer.isFloodWithLava();
    final MixedMaterial floorMaterial = layer.getFloorMaterial(), wallMaterial = layer.getWallMaterial(), roofMaterial = layer.getRoofMaterial();
    if (floorNoise != null) {
        floorNoise.setSeed(dimension.getSeed());
    }
    if (roofNoise != null) {
        roofNoise.setSeed(dimension.getSeed());
    }
    if ((floorMaterial == null) && (wallMaterial == null) && (roofMaterial == null)) {
        // One pass: just remove blocks
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    final int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final int waterLevel = dimension.getWaterLevelAt(x, y);
                    for (int z = Math.min(removeWater ? Math.max(terrainHeight, waterLevel) : terrainHeight, actualRoofLevel); z > actualFloorLevel; z--) {
                        if (removeWater || (z <= terrainHeight) || (z > waterLevel)) {
                            if (z <= floodLevel) {
                                world.setMaterialAt(x, y, z, floodWithLava ? Material.LAVA : Material.WATER);
                            } else {
                                world.setMaterialAt(x, y, z, Material.AIR);
                            }
                        }
                    }
                    if (actualFloorLevel == 0) {
                        // probably what the user wants
                        if ((floodLevel > 0) && (0 <= floodLevel)) {
                            world.setMaterialAt(x, y, 0, floodWithLava ? Material.STATIONARY_LAVA : Material.STATIONARY_WATER);
                        } else {
                            world.setMaterialAt(x, y, 0, Material.AIR);
                        }
                    }
                }
            }
        }
    } else {
        // excavate the interior
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    int waterLevel = dimension.getWaterLevelAt(x, y);
                    boolean flooded = waterLevel > terrainHeight;
                    final int startZ = Math.min(removeWater ? Math.max(terrainHeight, waterLevel) : terrainHeight, actualRoofLevel);
                    for (int z = startZ; z > actualFloorLevel; z--) {
                        if ((floorLedgeHeight == 0) && (floorMaterial != null)) {
                            setIfSolid(world, x, y, z - 1, minZ, maxZ, floorMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        if (wallMaterial != null) {
                            if (floorLedgeHeight > 0) {
                                setIfSolid(world, x, y, z - 1, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                            }
                            if (roofLedgeHeight > 0) {
                                setIfSolid(world, x, y, z + 1, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                            }
                        }
                        if ((roofLedgeHeight == 0) && (roofMaterial != null)) {
                            setIfSolid(world, x, y, z + 1, minZ, maxZ, roofMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                    }
                    if (wallMaterial != null) {
                        terrainHeight = dimension.getIntHeightAt(x - 1, y);
                        waterLevel = dimension.getWaterLevelAt(x - 1, y);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x - 1, y, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        terrainHeight = dimension.getIntHeightAt(x, y - 1);
                        waterLevel = dimension.getWaterLevelAt(x, y - 1);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x, y - 1, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        terrainHeight = dimension.getIntHeightAt(x + 1, y);
                        waterLevel = dimension.getWaterLevelAt(x + 1, y);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x + 1, y, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        terrainHeight = dimension.getIntHeightAt(x, y + 1);
                        waterLevel = dimension.getWaterLevelAt(x, y + 1);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x, y + 1, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                    }
                }
            }
        }
        // Second pass: excavate interior
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    final int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final int waterLevel = dimension.getWaterLevelAt(x, y);
                    for (int z = actualRoofLevel; z > actualFloorLevel; z--) {
                        if (removeWater || (z <= terrainHeight) || (z > waterLevel)) {
                            if (z <= floodLevel) {
                                world.setMaterialAt(x, y, z, floodWithLava ? Material.LAVA : Material.WATER);
                            } else {
                                world.setMaterialAt(x, y, z, Material.AIR);
                            }
                        }
                    }
                    if (actualFloorLevel == 0) {
                        // probably what the user wants
                        if ((floodLevel > 0) && (0 <= floodLevel)) {
                            world.setMaterialAt(x, y, 0, floodWithLava ? Material.LAVA : Material.WATER);
                        } else {
                            world.setMaterialAt(x, y, 0, Material.AIR);
                        }
                    }
                }
            }
        }
    }
    // Second/third pass: render floor layers
    List<Fixup> fixups = new ArrayList<>();
    final Map<Layer, TunnelLayer.LayerSettings> floorLayers = layer.getFloorLayers();
    if ((floorLayers != null) && (!floorLayers.isEmpty())) {
        final IncidentalLayerExporter[] floorExporters = new IncidentalLayerExporter[floorLayers.size()];
        final TunnelLayer.LayerSettings[] floorLayerSettings = new TunnelLayer.LayerSettings[floorLayers.size()];
        final NoiseHeightMap[] floorLayerNoise = new NoiseHeightMap[floorLayers.size()];
        int index = 0;
        for (Layer floorLayer : floorLayers.keySet()) {
            floorExporters[index] = (IncidentalLayerExporter) floorLayer.getExporter();
            TunnelLayer.LayerSettings layerSettings = floorLayers.get(floorLayer);
            floorLayerSettings[index] = layerSettings;
            if (layerSettings.getVariation() != null) {
                floorLayerNoise[index] = new NoiseHeightMap(layerSettings.getVariation(), index);
                floorLayerNoise[index].setSeed(dimension.getSeed());
            }
            index++;
        }
        final TunnelFloorDimension floorDimension = new TunnelFloorDimension(dimension, layer);
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    final int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if ((actualRoofLevel <= actualFloorLevel) || (actualFloorLevel == 0)) {
                        continue;
                    }
                    final int z = actualFloorLevel + 1;
                    final Point3i location = new Point3i(x, y, z);
                    for (int i = 0; i < floorExporters.length; i++) {
                        if ((z >= floorLayerSettings[i].getMinLevel()) && (z <= floorLayerSettings[i].getMaxLevel())) {
                            final int intensity = floorLayerNoise[i] != null ? MathUtils.clamp(0, (int) (floorLayerSettings[i].getIntensity() + floorLayerNoise[i].getValue(x, y, z) + 0.5f), 100) : floorLayerSettings[i].getIntensity();
                            if (intensity > 0) {
                                Fixup fixup = floorExporters[i].apply(floorDimension, location, intensity, exportedArea, world);
                                if (fixup != null) {
                                    fixups.add(fixup);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return fixups.isEmpty() ? null : fixups;
}
Also used : ArrayList(java.util.ArrayList) Layer(org.pepsoft.worldpainter.layers.Layer) Point3i(javax.vecmath.Point3i) NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Aggregations

NoiseHeightMap (org.pepsoft.worldpainter.heightMaps.NoiseHeightMap)4 ConstantHeightMap (org.pepsoft.worldpainter.heightMaps.ConstantHeightMap)2 SumHeightMap (org.pepsoft.worldpainter.heightMaps.SumHeightMap)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Point3i (javax.vecmath.Point3i)1 Material (org.pepsoft.minecraft.Material)1 PerlinNoise (org.pepsoft.util.PerlinNoise)1 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)1 DisplacementHeightMap (org.pepsoft.worldpainter.heightMaps.DisplacementHeightMap)1 MaximisingHeightMap (org.pepsoft.worldpainter.heightMaps.MaximisingHeightMap)1 NinePatchHeightMap (org.pepsoft.worldpainter.heightMaps.NinePatchHeightMap)1 ProductHeightMap (org.pepsoft.worldpainter.heightMaps.ProductHeightMap)1 Layer (org.pepsoft.worldpainter.layers.Layer)1 FancyTheme (org.pepsoft.worldpainter.themes.impl.fancy.FancyTheme)1