Search in sources :

Example 6 with Border3D

use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.

the class BooleanFacetTest method setup.

@Before
public void setup() {
    Border3D border = new Border3D(0, 0, 0).extendBy(0, 15, 10);
    Vector3i min = new Vector3i(10, 20, 30);
    Vector3i size = new Vector3i(40, 50, 60);
    Region3i region = Region3i.createFromMinAndSize(min, size);
    facet = createFacet(region, border);
// facet = [worldMin=(0, 5, 20), relativeMin=(-10, -15, -10), size=(60, 65, 80)]
}
Also used : Border3D(org.terasology.world.generation.Border3D) Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i) Before(org.junit.Before)

Example 7 with Border3D

use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.

the class LayeredZoneRegionFunctionTest method setup.

@Before
public void setup() {
    parent.addZone(new Zone("Medium sky", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), MEDIUM_SKY))).addZone(new Zone("Low sky", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), LOW_SKY))).addZone(new Zone("Above ground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), ABOVE_GROUND))).addZone(new Zone("Ground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), GROUND))).addZone(new Zone("Shallow underground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), SHALLOW_UNDERGROUND))).addZone(new Zone("Medium underground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), MEDIUM_UNDERGROUND)));
    parent.setSeed(12345);
    parent.initialize();
    ListMultimap<Class<? extends WorldFacet>, FacetProvider> facetProviderChains = ArrayListMultimap.create();
    facetProviderChains.put(SurfaceHeightFacet.class, (generatingRegion) -> {
        SurfaceHeightFacet facet = new SurfaceHeightFacet(generatingRegion.getRegion(), generatingRegion.getBorderForFacet(SurfaceHeightFacet.class));
        for (BaseVector2i pos : facet.getRelativeRegion().contents()) {
            facet.set(pos, 100);
        }
        generatingRegion.setRegionFacet(SurfaceHeightFacet.class, facet);
    });
    Map<Class<? extends WorldFacet>, Border3D> borders = new HashMap<>();
    borders.put(SurfaceHeightFacet.class, new Border3D(0, 0, 0));
    region = new RegionImpl(Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), 4), facetProviderChains, borders);
}
Also used : HashMap(java.util.HashMap) Zone(org.terasology.world.zones.Zone) FacetProvider(org.terasology.world.generation.FacetProvider) Border3D(org.terasology.world.generation.Border3D) MinMaxLayerThickness(org.terasology.world.zones.MinMaxLayerThickness) LayeredZoneRegionFunction(org.terasology.world.zones.LayeredZoneRegionFunction) WorldFacet(org.terasology.world.generation.WorldFacet) SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i) Vector3i(org.terasology.math.geom.Vector3i) RegionImpl(org.terasology.world.generation.RegionImpl) Before(org.junit.Before)

Example 8 with Border3D

use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.

the class SurfaceProvider method process.

@Override
public void process(GeneratingRegion region) {
    // Create our surface height facet (we will get into borders later)
    Border3D border = region.getBorderForFacet(SurfaceHeightFacet.class);
    SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), border);
    // loop through every position on our 2d array
    Rect2i processRegion = facet.getWorldRegion();
    for (BaseVector2i position : processRegion.contents()) {
        facet.setWorld(position, surfaceNoise.noise(position.x(), position.y()) * 20);
    }
    // give our newly created and populated facet to the region
    region.setRegionFacet(SurfaceHeightFacet.class, facet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Rect2i(org.terasology.math.geom.Rect2i) Border3D(org.terasology.world.generation.Border3D) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 9 with Border3D

use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.

the class BiomeProvider method process.

@Override
public void process(GeneratingRegion region) {
    SeaLevelFacet seaLevelFacet = region.getRegionFacet(SeaLevelFacet.class);
    SurfaceHeightFacet heightFacet = region.getRegionFacet(SurfaceHeightFacet.class);
    SurfaceTemperatureFacet temperatureFacet = region.getRegionFacet(SurfaceTemperatureFacet.class);
    SurfaceHumidityFacet humidityFacet = region.getRegionFacet(SurfaceHumidityFacet.class);
    Border3D border = region.getBorderForFacet(BiomeFacet.class);
    BiomeFacet biomeFacet = new BiomeFacet(region.getRegion(), border);
    int seaLevel = seaLevelFacet.getSeaLevel();
    for (BaseVector2i pos : biomeFacet.getRelativeRegion().contents()) {
        float temp = temperatureFacet.get(pos);
        float hum = temp * humidityFacet.get(pos);
        float height = heightFacet.get(pos);
        if (height <= seaLevel) {
            biomeFacet.set(pos, CoreBiome.OCEAN);
        } else if (height <= seaLevel + 2) {
            biomeFacet.set(pos, CoreBiome.BEACH);
        } else if (temp >= 0.5f && hum < 0.3f) {
            biomeFacet.set(pos, CoreBiome.DESERT);
        } else if (hum >= 0.3f && hum <= 0.6f && temp >= 0.5f) {
            biomeFacet.set(pos, CoreBiome.PLAINS);
        } else if (temp <= 0.3f && hum > 0.5f) {
            biomeFacet.set(pos, CoreBiome.SNOW);
        } else if (hum >= 0.2f && hum <= 0.6f && temp < 0.5f) {
            biomeFacet.set(pos, CoreBiome.MOUNTAINS);
        } else {
            biomeFacet.set(pos, CoreBiome.FOREST);
        }
    }
    region.setRegionFacet(BiomeFacet.class, biomeFacet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) SurfaceHumidityFacet(org.terasology.world.generation.facets.SurfaceHumidityFacet) Border3D(org.terasology.world.generation.Border3D) BaseVector2i(org.terasology.math.geom.BaseVector2i) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) SurfaceTemperatureFacet(org.terasology.world.generation.facets.SurfaceTemperatureFacet)

Example 10 with Border3D

use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.

the class HeightMapSurfaceHeightProvider method process.

@Override
public void process(GeneratingRegion region) {
    Border3D border = region.getBorderForFacet(SurfaceHeightFacet.class);
    SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), border);
    for (BaseVector2i pos : facet.getWorldRegion().contents()) {
        int xzScale = configuration.terrainScale;
        int mapX0;
        int mapZ0;
        int mapX1;
        int mapZ1;
        switch(configuration.wrapMode) {
            case CLAMP:
                mapX0 = TeraMath.clamp(pos.getX(), 0, mapWidth * xzScale - 1) / xzScale;
                mapZ0 = TeraMath.clamp(pos.getY(), 0, mapHeight * xzScale - 1) / xzScale;
                mapX1 = TeraMath.clamp(mapX0 + 1, 0, mapWidth - 1);
                mapZ1 = TeraMath.clamp(mapZ0 + 1, 0, mapHeight - 1);
                break;
            case REPEAT:
                mapX0 = IntMath.mod(pos.getX(), mapWidth * xzScale) / xzScale;
                mapZ0 = IntMath.mod(pos.getY(), mapHeight * xzScale) / xzScale;
                mapX1 = IntMath.mod(mapX0 + 1, mapWidth);
                mapZ1 = IntMath.mod(mapZ0 + 1, mapHeight);
                break;
            default:
                throw new UnsupportedOperationException("Not supported: " + configuration.wrapMode);
        }
        double p00 = heightmap[mapX0][mapZ0];
        double p10 = heightmap[mapX1][mapZ0];
        double p11 = heightmap[mapX1][mapZ1];
        double p01 = heightmap[mapX0][mapZ1];
        float relX = IntMath.mod(pos.getX(), xzScale) / (float) xzScale;
        float relZ = IntMath.mod(pos.getY(), xzScale) / (float) xzScale;
        float interpolatedHeight = (float) lerp(relX, lerp(relZ, p00, p01), lerp(relZ, p10, p11));
        float height = configuration.heightOffset + configuration.heightScale * interpolatedHeight;
        facet.setWorld(pos, height);
    }
    region.setRegionFacet(SurfaceHeightFacet.class, facet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Border3D(org.terasology.world.generation.Border3D) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Aggregations

Border3D (org.terasology.world.generation.Border3D)11 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)6 Before (org.junit.Before)4 BaseVector2i (org.terasology.math.geom.BaseVector2i)4 Vector3i (org.terasology.math.geom.Vector3i)4 Region3i (org.terasology.math.Region3i)3 SeaLevelFacet (org.terasology.world.generation.facets.SeaLevelFacet)3 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)2 Rect2i (org.terasology.math.geom.Rect2i)2 SurfaceHumidityFacet (org.terasology.world.generation.facets.SurfaceHumidityFacet)2 Predicate (com.google.common.base.Predicate)1 HashMap (java.util.HashMap)1 TreeFacet (org.terasology.core.world.generator.facets.TreeFacet)1 FacetProvider (org.terasology.world.generation.FacetProvider)1 RegionImpl (org.terasology.world.generation.RegionImpl)1 WorldFacet (org.terasology.world.generation.WorldFacet)1 SurfaceTemperatureFacet (org.terasology.world.generation.facets.SurfaceTemperatureFacet)1 LayeredZoneRegionFunction (org.terasology.world.zones.LayeredZoneRegionFunction)1 MinMaxLayerThickness (org.terasology.world.zones.MinMaxLayerThickness)1 Zone (org.terasology.world.zones.Zone)1