Пример #1
0
    def __init__(self, image: bpy.types.Image):
        if image.size[0] * image.size[1] * image.channels == 0:
            raise ValueError("Image has no data", image)

        pixels = image.pixels
        if hasattr(pixels, 'foreach_get'):
            data = utils.get_prop_array_data(pixels)
        else:
            # loading image by pixels
            data = np.fromiter(pixels,
                               dtype=np.float32,
                               count=image.size[0] * image.size[1] *
                               image.channels)

        self.pixels = data.reshape(image.size[1], image.size[0],
                                   image.channels)

        self.name = image.name
        self.color_space = image.colorspace_settings.name
Пример #2
0
def sync(rpr_context, image: bpy.types.Image):
    """ Creates pyrpr.Image from bpy.types.Image """

    if image.size[0] * image.size[1] * image.channels == 0:
        log.warn("Image has no data", image)
        return None

    image_key = key(image)

    if image_key in rpr_context.images:
        return rpr_context.images[image_key]

    log("sync", image)

    pixels = image.pixels
    if hasattr(pixels, 'foreach_get'):
        data = utils.get_prop_array_data(pixels)
        data = np.flipud(data.reshape(image.size[1], image.size[0], image.channels))
        rpr_image = rpr_context.create_image_data(image_key, np.ascontiguousarray(data))

    elif image.source in ('FILE', 'GENERATED'):
        file_path = cache_image_file(image, rpr_context.blender_data['depsgraph'])
        rpr_image = rpr_context.create_image_file(image_key, file_path)

    else:
        # loading image by pixels
        data = np.fromiter(pixels, dtype=np.float32,
                           count=image.size[0] * image.size[1] * image.channels)
        data = np.flipud(data.reshape(image.size[1], image.size[0], image.channels))
        rpr_image = rpr_context.create_image_data(image_key, np.ascontiguousarray(data))

    rpr_image.set_name(image_key)

    # TODO: implement more correct support of image color space types
    if image.colorspace_settings.name in ('sRGB', 'BD16', 'Filmic Log'):
        rpr_image.set_gamma(2.2)
    else:
        if image.colorspace_settings.name not in ('Non-Color', 'Raw', 'Linear'):
            log.warn("Ignoring unsupported image color space type",
                     image.colorspace_settings.name, image)

    return rpr_image
Пример #3
0
def sync(rpr_context, obj: bpy.types.Object):
    """ sync any volume attached to the object.  
        Note that volumes don't currently use motion blur """

    # find the smoke modifier
    smoke_modifier = get_smoke_modifier(obj)
    if not smoke_modifier:
        return

    log("sync", smoke_modifier, obj)

    domain = smoke_modifier.domain_settings
    if len(domain.color_grid) == 0:
        # empty smoke.  warn and return
        log.warn("Empty smoke domain", domain, smoke_modifier, obj)
        return

    # getting volume material
    volume_material = None
    if obj.material_slots and obj.material_slots[0].material:
        volume_material = material.sync(rpr_context,
                                        obj.material_slots[0].material,
                                        'Volume')

    if not volume_material:
        log.warn("No volume material for smoke domain", obj)
        return

    data = volume_material.data

    # creating rpr_volume
    volume_key = key(obj, smoke_modifier)
    rpr_volume = rpr_context.create_hetero_volume(volume_key)
    rpr_volume.set_name(str(volume_key))

    # getting smoke resolution and color_grid
    if BLENDER_VERSION >= '2.82':
        x, y, z = domain.domain_resolution
    else:
        amplify = domain.amplify if domain.use_high_resolution else 0
        x, y, z = ((amplify + 1) * i for i in domain.domain_resolution)

    if domain.use_noise:
        # smoke noise upscale the basic domain resolution
        x, y, z = (domain.noise_scale * e for e in (x, y, z))

    color_grid = get_prop_array_data(domain.color_grid).reshape(x, y, z, -1)

    # set albedo grid
    albedo_data = np.average(color_grid[:, :, :, :3], axis=3)
    albedo_grid = rpr_context.create_grid_from_3d_array(
        np.ascontiguousarray(albedo_data))
    color = data['color']
    albedo_lookup = np.array([0.0, 0.0, 0.0, *color],
                             dtype=np.float32).reshape(-1, 3)
    rpr_volume.set_grid('albedo', albedo_grid)
    rpr_volume.set_lookup('albedo', albedo_lookup)

    # set density grid
    density_data = get_prop_array_data(domain.density_grid).reshape(x, y, z)
    density_grid = rpr_context.create_grid_from_3d_array(
        np.ascontiguousarray(density_data))
    density = data['density']
    density_lookup = np.array([0.0, 0.0, 0.0, density, density, density],
                              dtype=np.float32).reshape(-1, 3)
    rpr_volume.set_grid('density', density_grid)
    rpr_volume.set_lookup('density', density_lookup)

    emission_color = data['emission_color']
    if not is_zero(emission_color):
        # set emission grid
        emission_data = get_prop_array_data(domain.flame_grid).reshape(x, y, z)
        emission_grid = rpr_context.create_grid_from_3d_array(
            np.ascontiguousarray(emission_data))
        emission_lookup = np.array([0.0, 0.0, 0.0, *emission_color],
                                   dtype=np.float32).reshape(-1, 3)
        rpr_volume.set_grid('emission', emission_grid)
        rpr_volume.set_lookup('emission', emission_lookup)

    # set volume transform
    rpr_volume.set_transform(get_transform(obj))

    # attaching to scene and shape
    rpr_context.scene.attach(rpr_volume)
    rpr_obj = rpr_context.objects[object.key(obj)]
    rpr_obj.set_hetero_volume(rpr_volume)
Пример #4
0
def sync(rpr_context,
         image: bpy.types.Image,
         use_color_space=None,
         frame_number=None):
    """ Creates pyrpr.Image from bpy.types.Image """
    from rprblender.engine.export_engine import ExportEngine

    color_space = image.colorspace_settings.name
    if use_color_space:
        color_space = use_color_space

    if image.source == 'SEQUENCE':
        image_key = key(image, color_space, frame_number=frame_number)
    else:
        if image.size[0] * image.size[1] * image.channels == 0:
            log.warn("Image has no data", image)
            return None
        image_key = key(image, color_space)

    if image_key in rpr_context.images:
        return rpr_context.images[image_key]

    log("sync", image)

    if image.source == 'TILED':  # UDIM Tiles
        rpr_image = rpr_context.create_tiled_image(key=image_key)
        if rpr_image:  # if context doesn't support tiles - export as regular image
            udim_path_split = image.filepath_from_user().split('.')
            for tile in image.tiles:
                tile_path = '.'.join(udim_path_split[:-2] + [tile.label] +
                                     udim_path_split[-1:])
                tile_key = key(image, color_space, UDIM_tile=tile.label)

                tile_image = rpr_context.create_image_file(tile_key, tile_path)
                set_image_gamma(tile_image, image, color_space)
                tile_image.set_name(str(tile_key))

                rpr_image.set_udim_tile(tile.number, tile_image)

            rpr_image.set_name(str(image_key))

            return rpr_image

    pixels = image.pixels
    if image.source == 'SEQUENCE':
        file_path = get_sequence_frame_file_path(image.filepath_from_user(),
                                                 frame_number)
        if not file_path:
            return None
        rpr_image = rpr_context.create_image_file(image_key, file_path)

    elif rpr_context.engine_type != ExportEngine.TYPE and hasattr(
            pixels, 'foreach_get'):
        data = utils.get_prop_array_data(pixels)
        data = np.flipud(
            data.reshape(image.size[1], image.size[0], image.channels))
        rpr_image = rpr_context.create_image_data(image_key,
                                                  np.ascontiguousarray(data))

    elif image.source in ('FILE', 'GENERATED'):
        file_path = cache_image_file(image,
                                     rpr_context.blender_data['depsgraph'])
        rpr_image = rpr_context.create_image_file(image_key, file_path)

    else:
        # loading image by pixels
        data = utils.get_prop_array_data(pixels)
        data = np.flipud(
            data.reshape(image.size[1], image.size[0], image.channels))
        rpr_image = rpr_context.create_image_data(image_key,
                                                  np.ascontiguousarray(data))

    rpr_image.set_name(str(image_key))

    set_image_gamma(rpr_image, image, color_space)

    return rpr_image
Пример #5
0
def sync(rpr_context,
         image: bpy.types.Image,
         use_color_space=None,
         frame_number=None):
    """ Creates pyrpr.Image from bpy.types.Image """
    from rprblender.engine.export_engine import ExportEngine

    color_space = image.colorspace_settings.name
    if use_color_space:
        color_space = use_color_space

    if image.source == 'SEQUENCE':
        image_key = key(image, color_space, frame_number)
    else:
        if image.size[0] * image.size[1] * image.channels == 0:
            log.warn("Image has no data", image)
            return None
        image_key = key(image, color_space)

    if image_key in rpr_context.images:
        return rpr_context.images[image_key]

    log("sync", image)

    pixels = image.pixels
    if image.source == 'SEQUENCE':
        file_path = get_sequence_frame_file_path(image.filepath_from_user(),
                                                 frame_number)
        if not file_path:
            return None
        rpr_image = rpr_context.create_image_file(image_key, file_path)

    elif rpr_context.engine_type != ExportEngine.TYPE and hasattr(
            pixels, 'foreach_get'):
        data = utils.get_prop_array_data(pixels)
        data = np.flipud(
            data.reshape(image.size[1], image.size[0], image.channels))
        rpr_image = rpr_context.create_image_data(image_key,
                                                  np.ascontiguousarray(data))

    elif image.source in ('FILE', 'GENERATED'):
        file_path = cache_image_file(image,
                                     rpr_context.blender_data['depsgraph'])
        rpr_image = rpr_context.create_image_file(image_key, file_path)

    else:
        # loading image by pixels
        data = utils.get_prop_array_data(pixels)
        data = np.flipud(
            data.reshape(image.size[1], image.size[0], image.channels))
        rpr_image = rpr_context.create_image_data(image_key,
                                                  np.ascontiguousarray(data))

    rpr_image.set_name(str(image_key))

    # TODO: implement more correct support of image color space types
    # RPRImageTexture node color space names are in caps, unlike in Blender
    if color_space in ('sRGB', 'BD16', 'Filmic Log', 'SRGB'):
        rpr_image.set_gamma(2.2)
    elif color_space not in ('Non-Color', 'Raw', 'Linear', 'LINEAR'):
        log.warn("Ignoring unsupported image color space type", color_space,
                 image)

    return rpr_image