def recalcSlice():
    global worldSlice, hmTrees, hmOceanFloor, heightmap

    worldSlice = WorldSlice(
        x1, z1, x2, z2,
        ["MOTION_BLOCKING_NO_LEAVES", "WORLD_SURFACE", "OCEAN_FLOOR"])

    hmTrees = worldSlice.heightmaps["WORLD_SURFACE"]
    hmOceanFloor = worldSlice.heightmaps["OCEAN_FLOOR"]

    heightmap = calcGoodHeightmap(worldSlice)
    heightmap = heightmap.astype(np.uint8)
    x2 = buildArea["xTo"]
    z2 = buildArea["zTo"]
    # print(buildArea)
    area = (x1, z1, x2 - x1, z2 - z1)

print("Build area is at position %s, %s with size %s, %s" % area)

# load the world data
# this uses the /chunks endpoint in the background
worldSlice = WorldSlice(area)
heightmap = worldSlice.heightmaps["MOTION_BLOCKING"]
heightmap = worldSlice.heightmaps["MOTION_BLOCKING_NO_LEAVES"]
heightmap = worldSlice.heightmaps["OCEAN_FLOOR"]
heightmap = worldSlice.heightmaps["WORLD_SURFACE"]
# caclulate a heightmap that ignores trees:
heightmap = mapUtils.calcGoodHeightmap(worldSlice)

# show the heightmap as an image
# mapUtils.visualize(heightmap, title="heightmap")

# define a function for easier heightmap access
# heightmap coordinates are not equal to world coordinates!


def heightAt(x, z):
    """Return the height at the appropriate location."""
    return heightmap[(x - area[0], z - area[1])]

# a wrapper function for setting blocks

)

# 2D build area
buildArea = interfaceUtils.requestBuildArea()
if buildArea != -1:
    x1 = buildArea["xFrom"]
    z1 = buildArea["zFrom"]
    x2 = buildArea["xTo"]
    z2 = buildArea["zTo"]
    # print(buildArea)
    area = (x1, z1, x2 - x1, z2 - z1)

ws = WorldSlice(area,
                ["MOTION_BLOCKING_NO_LEAVES", "OCEAN_FLOOR", "WORLD_SURFACE"])

heightmap = calcGoodHeightmap(ws).astype(np.uint8)

hmTrees = ws.heightmaps["WORLD_SURFACE"]
heightmapOcean = ws.heightmaps["OCEAN_FLOOR"].astype(np.uint8)

borderMap = np.ones(heightmap.shape, dtype=np.uint8)
borderMap[1:-1, 1:-1] = 0

landmapBorder = ((heightmapOcean > 62) & (borderMap == 0)).astype(np.uint8)
landmap = ((heightmapOcean > 62)).astype(np.uint8)

# visualize(landmapBorder)

dst, labels = cv2.distanceTransformWithLabels(landmapBorder,
                                              cv2.DIST_L2,
                                              5,
Esempio n. 4
0
from worldLoader import WorldSlice

######################## GLOBAL VARIABLES ########################

AREA            = buildUtils.BuildArea(buildUtils.getBuildArea())

if len(sys.argv) < 2:
    pass
elif len(sys.argv) == 4:
    AREA.x = int(sys.argv[1])
    AREA.z = int(sys.argv[2])
    AREA.size = int(sys.argv[3])

MAP_SIZE        = AREA.size
WORLD_SLICE     = WorldSlice(AREA.get())
HEIGHT_MAP      = mapUtils.calcGoodHeightmap(WORLD_SLICE)
USE_BATCHING    = True
BUILD_MAP       = buildUtils.BuildMap(MAP_SIZE, (AREA.x, AREA.z))
BUILDER         = buildUtils.Builder(HEIGHT_MAP, AREA.get(), USE_BATCHING)

##################################################################
########################### WORLD SETUP  #########################
##################################################################

# plot fence
perimeter_area  = (AREA.x-1, AREA.z-1, AREA.size + 2, AREA.size + 2)
perimeter_h_map = mapUtils.calcGoodHeightmap(WorldSlice(perimeter_area))
area_builder = buildUtils.Builder(perimeter_h_map, perimeter_area, USE_BATCHING)
area_builder.generatePlotFence()

# terraforming