def _check_ramp_update(scene): if g.light_index() == -1: return if cpp().colorRampChanged(g.light_index()): cpp().updateLightColor(g.light_index()) image.create_final()
def _check_curve_update(scene): if g.light_index() == -1: return if cpp().curveFlatChanged(g.light_index()): cpp().updateLightLuminosity(g.light_index()) image.create_final() if g.light().content_type == 'IMAGE': if cpp().curveImageChanged(g.light_index()): cpp().changeLightImageBrightness(g.light_index()) image.create_final()
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'}
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'}
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'}
def draw(self, context): if _skip_drawing_panel(context): return layout = self.layout content_type = g.light().content_type data = g.light_data[g.light_index()] layout.template_curve_mapping(data.light_flat(), 'falloff_curve') layout.prop(g.light(), 'brightness_color', text='intensity', slider=True) layout.prop(g.light(), 'brightness_opacity', slider=True) layout.prop(g.light(), 'curve_x', slider=True) layout.prop(g.light(), 'curve_y', slider=True) if g.light().content_type == 'IMAGE': layout.template_curve_mapping(data.light_image(), 'falloff_curve')
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)
def draw(self, context): if _skip_drawing_panel(context): return layout = self.layout s1 = layout.split() s1.label(text='blend mode:') s1.prop(g.light(), 'blend_mode', text='') s2 = layout.split() s2.label(text='content type:') s2.prop(g.light(), 'content_type', text='') content_type = g.light().content_type if content_type == 'FLAT': layout.prop(g.light(), 'color') if content_type == 'GRADIENT': layout.template_color_ramp(g.light_data[g.light_index()].texture(), 'color_ramp') layout.prop(g.light(), 'falloff_type', text='falloff') if g.light().falloff_type != 'RADIAL': layout.prop(g.light(), 'gradient_angle', text='angle', slider=True) else: layout.prop(g.light(), 'radial_x', slider=True) layout.prop(g.light(), 'radial_y', slider=True) layout.prop(g.light(), 'radial_width', slider=True) layout.prop(g.light(), 'radial_height', slider=True) if content_type == 'IMAGE': layout.prop_search(g.light(), 'image', bpy.data, 'images')
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 modal(self, context, event): if not (editor.started): if _handler: remove_handler() self.delay = True return {'PASS_THROUGH'} if self.delay: self.delay = False return {'PASS_THROUGH'} return {'FINISHED'} if g.wrong_workspace(context): return {'PASS_THROUGH'} if g.no_lights(): return {'PASS_THROUGH'} if g.light().locked: return {'PASS_THROUGH'} if event.type == 'LEFTMOUSE' and event.value == 'PRESS': def inside(event, x, y, width, height): if event.mouse_x < x: return False if event.mouse_x > x + width: return False if event.mouse_y < y: return False if event.mouse_y > y + height: return False return True self.image_editor = None self.region = None if not (bpy.context.screen == g.workspace().screens[0]): return {'PASS_THROUGH'} for area in g.areas(): if area.type != 'IMAGE_EDITOR': continue if not (inside(event, area.x, area.y, area.width, area.height)): continue self.image_editor = area for region in area.regions: if region.type == 'WINDOW': self.region = region break if not (self.image_editor): return {'PASS_THROUGH'} if g.wrong_image(self.image_editor): return {'PASS_THROUGH'} for region in self.image_editor.regions: if region.type == 'HEADER': header = region if region.type == 'UI': ui = region if region.type == 'TOOLS': tools = region x = tools.x + tools.width if not (inside(event, x + 10, self.image_editor.y, ui.x - x - 20, self.image_editor.height - header.height)): return {'PASS_THROUGH'} if not (self.mouse_event_common(event)): return {'PASS_THROUGH'} self.pressed = True return {'RUNNING_MODAL'} if event.type == 'MOUSEMOVE': if not (self.pressed): return {'PASS_THROUGH'} self.mouse_event_common(event) return {'RUNNING_MODAL'} if event.type == 'LEFTMOUSE' and event.value == 'RELEASE': if not (self.pressed): return {'PASS_THROUGH'} self.pressed = False light.change_both_coordinates = True cpp().changeBothCoordinates(g.light_index()) g.light().x, g.light().y = self.img_x, self.img_y return {'PASS_THROUGH'} if event.type == 'RIGHTMOUSE' and event.value == 'PRESS': if self.pressed: self.pressed = False self.image_editor.tag_redraw() return {'PASS_THROUGH'} return {'PASS_THROUGH'}