Exemplo n.º 1
0
def get_all_ground_texture_paths(pytho_c_id):
    """Returns a dictionary with all available detail ground texture paths
    for the phytocoenosis at the requested ID.

    Format:
    {
        texture_name: path_to_texture
    }
    """

    phytocoenosis = get_object_or_404(Phytocoenosis, id=pytho_c_id)

    albedo_path, normal_path, displacement_path = None, None, None
    if phytocoenosis.albedo_path:
        albedo_path = utils.get_full_texture_path(phytocoenosis.albedo_path)
    if phytocoenosis.normal_path:
        normal_path = utils.get_full_texture_path(phytocoenosis.normal_path)
    if phytocoenosis.displacement_path:
        displacement_path = utils.get_full_texture_path(
            phytocoenosis.displacement_path)

    tex_dict = {
        "albedo_path": utils.replace_path_prefix(albedo_path),
        "normal_path": utils.replace_path_prefix(normal_path),
        "displacement_path": utils.replace_path_prefix(displacement_path),
    }

    # Remove None values
    # TODO: why do we need to do this? The client should check for this..
    tex_dict = {k: v for k, v in tex_dict.items() if v}

    return tex_dict
Exemplo n.º 2
0
def get_vegetation_splatmap(request, meter_x, meter_y, zoom):
    """Returns a JsonResponse with the path to the splatmap PNG for the given location"""

    zoom = int(zoom)
    splat_path, ids = splatmap.get_splatmap_path_and_ids_for_coordinates(
        float(meter_x), float(meter_y), zoom)

    res = {
        'path_to_splatmap': utils.replace_path_prefix(splat_path),
        'ids': ids
    }

    return JsonResponse(res)
Exemplo n.º 3
0
def get_ortho_dhm(request, meter_x: str, meter_y: str, zoom: str):

    # fetch the related filenames
    zoom = int(zoom)
    meter_x = float(meter_x)
    meter_y = float(meter_y)

    # TODO: maybe we add callbacks later to generate the files if they could not be found
    filename_ortho = tiles.get_tile(meter_x, meter_y, zoom,
                                    utils.get_full_texture_path(ORTHO_BASE),
                                    False, "jpg")
    filename_map = tiles.get_tile(meter_x, meter_y, zoom,
                                  utils.get_full_texture_path(MAP_BASE), False)
    filename_dhm = tiles.get_tile(meter_x, meter_y, zoom,
                                  utils.get_full_texture_path(DHM_BASE))

    # answer with a json
    ret = {
        'ortho': utils.replace_path_prefix(filename_ortho),
        'map': utils.replace_path_prefix(filename_map),
        'dhm': utils.replace_path_prefix(filename_dhm)
    }
    return JsonResponse(ret)
Exemplo n.º 4
0
def get_phytocoenosis_data(request, phyto_c_id, layer_name):
    """Returns a JsonResponse with the path to the distribution graphic and the path to the
    spritesheet for a given phytocoenosis at a given layer.

    All available detail ground texture paths (albedo_path, bumpmap_path, heightmap_detail_path)
    are included as well."""

    spritesheet, count = vegetation_spritesheet.get_spritesheet_and_count_for_id_and_layer(
        phyto_c_id, layer_name)
    path_to_distribution = generate_distribution.get_distribution_for_id_and_layer(
        phyto_c_id, layer_name)

    res = {
        'path_to_distribution':
        utils.replace_path_prefix(path_to_distribution),
        'path_to_spritesheet': utils.replace_path_prefix(spritesheet),
        'number_of_sprites': count,
        'distribution_pixels_per_meter': generate_distribution.PIXELS_PER_METER
    }

    # Add available detail ground textures to the dictionary
    res.update(phytocoenosis_textures.get_all_ground_texture_paths(phyto_c_id))

    return JsonResponse(res)
Exemplo n.º 5
0
def get_distribution_for_id_and_layer(pid, layer):
    """Returns the path to the spritesheet containing all plant images for a given phytocoenosis ID and layer.
    If the file does not exist yet, it is generated.
    """

    # FIXME solve circular dependency
    import vegetation.generate_distribution

    filename = utils.get_full_texture_path(DISTRIBUTION_PATH.format(
        pid, layer))

    if not os.path.isfile(filename):
        logging.info("Generating distribution for {}...".format(filename))
        vegetation.generate_distribution.generate_distribution_for_phytocoenosis_and_layer(
            pid, layer)

    # If the file now exists, return it
    if os.path.isfile(filename):
        return utils.replace_path_prefix(filename)