def add(item, index): cpp().addLight( item.enabled, item.solo, _bm_enum(item.blend_mode), item.brightness_color, item.brightness_opacity, item.curve_x, item.curve_y, item.x, item.y, item.width, item.height, item.angle, item.is_ellipse, item.sides, item.corner_radius, _ct_enum(item.content_type), _to_float_pointer(item.color), _ft_enum(item.falloff_type), item.gradient_angle, item.radial_x, item.radial_y, item.radial_width, item.radial_height, )
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 update_x(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightX(index, l.x) global change_both_coordinates if change_both_coordinates: change_both_coordinates = False else: image.create_final()
def _update_color(l, context): global _skip_update_color _skip_update_color = not(_skip_update_color) if not(_skip_update_color): return index = _index_by_id(l) if index != -1: cpp().changeLightColor(index, _to_float_pointer(l.color)) image.create_final()
def main(): args = sys.argv[1:] if not args or '-h' in args: usage() cpp_opts, args = cpp.getopt(sys.argv[1:]) if not args: usage() plan_path = args[0] print cpp.cpp(plan_path, cpp_opts)
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.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 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): scene.clear() bpy.app.handlers.depsgraph_update_pre.remove(_check_curve_update) bpy.app.handlers.depsgraph_update_pre.remove(_check_ramp_update) for area in g.areas(): if area.type == 'IMAGE_EDITOR': area.tag_redraw() _set_started(context, False) g.light_data.clear() for image_name in image.env_for_mesh: im = g.images()[image_name] im.user_clear() g.images().remove(im) image.env_for_mesh.clear() cpp().clear() image.update() g.set_image(None) _set_hotkeys(True) return {'FINISHED'}
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 _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 _parse_plan_file(path, cpp_opts=[]): """process plan through cpp, then parse it and add packages to plan """ processed_plan = cpp.cpp(path, cpp_opts) packages = set() for expr in processed_plan.splitlines(): expr = re.sub(r'#.*', '', expr) expr = expr.strip() if not expr: continue if expr.startswith("!"): package = expr[1:] if package in packages: packages.remove(package) else: package = expr packages.add(package) return packages
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_gradient_angle(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightGradientAngle(index, l.gradient_angle) image.create_final()
def _update_solo(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightSolo(index, l.solo) image.create_final()
def _update_sides(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightSides(index, l.sides) image.create_final()
def create_final(): cpp().createFinalImage() update()
def _update_image(l, context): index = _index_by_id(l) if index != -1: cpp().updateLightImage(index) image.create_final()
def _update_falloff_type(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightFalloffType(index, _ft_enum(l.falloff_type)) image.create_final()
def _update_radial_height(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightRadialHeight(index, l.radial_height) image.create_final()
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'}
def _update_is_ellipse(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightIsEllipse(index, l.is_ellipse) image.create_final()
def _update_brightness_color(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightBrightnessColor(index, l.brightness_color) image.create_final()
def _update_blend_mode(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightBlendMode(index, _bm_enum(l.blend_mode)) image.create_final()
def _update_corner_radius(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightCornerRadius(index, l.corner_radius) image.create_final()
def _update_content_type(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightContentType(index, _ct_enum(l.content_type)) image.create_final()
def update_image_editor(): pixels = g.image().pixels pixels[0] = pixels[0] cpp().cleanImage()
def _update_curve_x(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightCurveX(index, l.curve_x) image.create_final()
def _update_radial_width(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightRadialWidth(index, l.radial_width) image.create_final()
def _update_brightness_opacity(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightBrightnessOpacity(index, l.brightness_opacity) image.create_final()
def _update_enabled(l, context): index = _index_by_id(l) if index != -1: cpp().changeLightEnabled(index, l.enabled) image.create_final()