def update():
    g.image().update()
    update_image_editor()
    engine = g.scene().render.engine

    if engine == _EEVEE:
        _update_eevee()
    elif engine == _CYCLES:
        _update_cycles()
Пример #2
0
    def mouse_event_common(self, event):
        self.image_editor.tag_redraw()

        area_x = event.mouse_x - self.image_editor.x
        area_y = event.mouse_y - self.image_editor.y

        image_x, image_y = self.region.view2d.region_to_view(area_x, area_y)

        size = g.image().size

        self.img_x = int(image_x * size[0])
        self.img_y = int(image_y * size[1])

        inside = True

        if self.img_x < 0:
            self.img_x = 0
            inside = False
        if self.img_x > size[0] - 1:
            self.img_x = size[0] - 1
            inside = False
        if self.img_y < 0:
            self.img_y = 0
            inside = False
        if self.img_y > size[1] - 1:
            self.img_y = size[1] - 1
            inside = False

        return inside
Пример #3
0
def clear():
    for scene in g.scenes():
        if scene.name[0:len(_PREFIX)] == _PREFIX:
            g.scenes().remove(scene, do_unlink = True)

    g.scene().use_nodes = False
    image.set_as_env_map(g.scene(), g.image())
    image.create_final()
Пример #4
0
def _set_started(context, value):
    global started
    started = value

    if started:
        active_image(context).hdr_pro_studio_data.edited = True
    else:
        g.image().hdr_pro_studio_data.edited = False
Пример #5
0
def _draw_callback_px(op, context):
    if g.wrong(context):
        return

    if g.no_lights():
        return

    if not (cpp().lightIsVisible(g.light_index())):
        return

    if op.pressed:
        (x, y) = (op.img_x, op.img_y)
    else:
        (x, y) = (g.light().x, g.light().y)

    size = g.image().size
    uv_x, uv_y = x / size[0], y / size[1]
    reg_x, reg_y = context.region.view2d.view_to_region(uv_x, uv_y)

    gpu_extras.presets.draw_circle_2d((reg_x, reg_y), (0, 0, 0, 1), 9)
    gpu_extras.presets.draw_circle_2d((reg_x, reg_y), (1, 1, 1, 1), 10)
Пример #6
0
def py_image():
    return g.image().as_pointer()
Пример #7
0
    def execute(self, context):
        g.set_image(active_image(context))

        if not (g.image()):
            self.report({'ERROR'}, 'No image is selected in uv editor.')
            return {'CANCELLED'}

        image_pointer = blender.get_image_pointer(g.image().name)

        if not (image_pointer):
            self.report({'ERROR'}, 'No image cache is available. Try opening '
                        'image in uv editor.')
            g.set_image(None)
            return {'CANCELLED'}

        im_dna = blender.ImageDna.from_address(image_pointer.value)
        pool = im_dna.cache.contents.items_pool.contents
        item = blender.MovieCacheItem.from_address(pool.free - pool.esize)
        imbuf_pointer = item.ibuf

        if not (cast(imbuf_pointer, c_void_p).value):
            g.set_image(None)
            return {'CANCELLED'}

        rect_float_pointer = imbuf_pointer.contents.rect_float

        if not (cast(rect_float_pointer, c_void_p).value):
            g.set_image(None)
            self.report({'ERROR'}, 'This is not an hdr image.')
            return {'CANCELLED'}

        cpp().initImage(image_pointer)

        try:
            g.image().pack()
        except:
            cpp().clearImage()
            g.set_image(None)
            self.report({'ERROR'},
                        'Failed to pack image. Try again with image '
                        'without unsaved changes.')
            return {'CANCELLED'}

        if not (image.enable_renderer()):
            cpp().clearImage()
            g.set_image(None)
            self.report({'ERROR'},
                        'Eevee and Cycles render engines are unavailable.')
            return {'CANCELLED'}

        image.set_as_env_map(g.scene(), g.image())

        for l in g.lights():
            image_name = l.image

            if not (image_name):
                continue

            try:
                g.images()[image_name]
            except:
                cpp().clearImage()
                g.set_image(None)
                self.report({'ERROR'}, 'Image \'' + image_name + '\' is '
                            'unavailable.')
                return {'CANCELLED'}

        for area in g.areas():
            if area.type == 'VIEW_3D':
                for space in area.spaces:
                    if space.type == 'VIEW_3D':
                        space.shading.type = 'RENDERED'
                        break
                break

        light.Light.x = IntProperty(default=int(g.image().size[0] / 2),
                                    min=0,
                                    max=(g.image().size[0] - 1),
                                    update=light.update_x)
        light.Light.y = IntProperty(default=int(g.image().size[1] / 2),
                                    min=0,
                                    max=(g.image().size[1] - 1),
                                    update=light.update_y)

        for l in g.lights():
            g.light_data.append(
                light.Data(g.data_name(l), g.data_name(l, 'flat'),
                           g.data_name(l, 'image')))

        for data in g.light_data:
            data.light_flat().falloff_curve.initialize()
            data.light_image().falloff_curve.initialize()

        for im in g.images():
            if im.type == 'IMAGE' and im.has_data:
                im.update()

        for i in range(len(g.lights())):
            light.add(g.lights()[i], i)

        image.create_final()
        bpy.ops.hdr_pro_studio.move('INVOKE_DEFAULT')

        bpy.app.handlers.depsgraph_update_pre.append(_check_curve_update)
        bpy.app.handlers.depsgraph_update_pre.append(_check_ramp_update)

        _set_hotkeys(False)
        _set_started(context, True)
        return {'FINISHED'}
def update_image_editor():
    pixels = g.image().pixels
    pixels[0] = pixels[0]
    cpp().cleanImage()