示例#1
0
    def execute(self, context):
        if g.light_index() > len(g.lights()) - 2:
            return {'CANCELLED'}

        lower = g.light_index() + 1
        g.lights().move(g.light_index(), lower)

        g.light_data.insert(g.light_index(), g.light_data[lower])
        g.light_data.pop(lower + 1)

        cpp().down(g.light_index())
        g.data().light_index += 1
        image.create_final()
        return {'FINISHED'}
示例#2
0
    def execute(self, context):
        if g.light_index() < 1:
            return {'CANCELLED'}

        upper = g.light_index() - 1
        g.lights().move(g.light_index(), upper)

        g.light_data.insert(upper, g.light_data[g.light_index()])
        g.light_data.pop(g.light_index() + 1)

        cpp().up(g.light_index())
        g.data().light_index -= 1
        image.create_final()
        return {'FINISHED'}
示例#3
0
    def execute(self, context):
        if g.no_lights():
            return {'CANCELLED'}

        g.lights().remove(g.light_index())
        cpp().removeLight(g.light_index())
        data = g.light_data[g.light_index()]

        g.textures().remove(data.texture())
        g.blender_lights().remove(data.light_flat())
        g.blender_lights().remove(data.light_image())

        g.light_data.remove(data)

        g.data().light_index -= 1
        if g.no_lights():
            if len(g.lights()):
                g.data().light_index = 0

        image.create_final()
        return {'FINISHED'}
示例#4
0
    def execute(self, context):
        item = g.lights().add()

        item.id = g.data().max_id
        g.data().max_id += 1

        item.name = 'light'
        g.data().light_index = len(g.lights()) - 1


        texture = g.textures().new(g.data_name(item), 'BLEND')
        texture.use_color_ramp = True
        texture.use_fake_user = True

        light_flat = g.blender_lights().new(
            g.data_name(item, 'flat'), 'POINT')
        light_flat.use_fake_user = True

        light_image = g.blender_lights().new(
            g.data_name(item, 'image'), 'POINT')
        light_image.use_fake_user = True
        curve = light_image.falloff_curve
        points = curve.curves[0].points
        points[0].location.y = 0
        points[1].location.y = 1
        curve.update()


        g.light_data.append(light.Data(
            texture.name,
            light_flat.name,
            light_image.name
        ))
        light.add(item, g.light_index())
        image.create_final()
        return {'FINISHED'}
def _update_name(l, context):
    name = l.name
    for light in g.lights():
        if light.name == l.name and light.id != l.id:
            splitted = l.name.split('.')

            if len(splitted) == 1:
                l.name += '.0'
                return

            ending = splitted[len(splitted) - 1]

            if not(ending.isdigit()):
                l.name += '.0'
                return

            name_new = ''
            for i in range(len(splitted) - 1):
                name_new += splitted[i] + '.'
            name_new += str(int(ending) + 1)
            l.name = name_new
def py_lightImage(index):
    return get_image_pointer(g.lights()[index].image).value
示例#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 _index_by_id(light):
    for li in range(len(g.lights())):
        if g.lights()[li].id == light.id:
            return li

    return -1