diff --git a/io_mesh_uv_layout/__init__.py b/io_mesh_uv_layout/__init__.py index 324f2254e190db1b96a10652ad41f6c7723fc753..ceb5ddbcc17bf340c43db123bae245324b5f55b2 100644 --- a/io_mesh_uv_layout/__init__.py +++ b/io_mesh_uv_layout/__init__.py @@ -3,8 +3,8 @@ bl_info = { "name": "UV Layout", "author": "Campbell Barton, Matt Ebb", - "version": (1, 1, 1), - "blender": (2, 80, 0), + "version": (1, 1, 2), + "blender": (3, 0, 0), "location": "Image-Window > UVs > Export UV Layout", "description": "Export the UV layout as a 2D graphic", "warning": "", diff --git a/io_mesh_uv_layout/export_uv_png.py b/io_mesh_uv_layout/export_uv_png.py index 958bac8ea50579f54b737f330343e7230ac45485..74cd7b1939baf04c8e53fec427df87521f2b374b 100644 --- a/io_mesh_uv_layout/export_uv_png.py +++ b/io_mesh_uv_layout/export_uv_png.py @@ -2,7 +2,6 @@ import bpy import gpu -import bgl from mathutils import Vector, Matrix from mathutils.geometry import tessellate_polygon from gpu_extras.batch import batch_for_shader @@ -12,21 +11,23 @@ def export(filepath, face_data, colors, width, height, opacity): offscreen.bind() try: - bgl.glClearColor(0.0, 0.0, 0.0, 0.0) - bgl.glClear(bgl.GL_COLOR_BUFFER_BIT) + fb = gpu.state.active_framebuffer_get() + fb.clear(color=(0.0, 0.0, 0.0, 0.0)) draw_image(face_data, opacity) - pixel_data = get_pixel_data_from_current_back_buffer(width, height) + pixel_data = fb.read_color(0, 0, width, height, 4, 0, 'UBYTE') + pixel_data.dimensions = width * height * 4 save_pixels(filepath, pixel_data, width, height) finally: offscreen.unbind() offscreen.free() def draw_image(face_data, opacity): - bgl.glLineWidth(1) - bgl.glEnable(bgl.GL_BLEND) - bgl.glEnable(bgl.GL_LINE_SMOOTH) - bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST) + gpu.state.line_width_set(1.0) + gpu.state.blend_set('ALPHA_PREMULT') + # TODO: Use shader that draws a smooth line (Eg. '3D_POLYLINE_UNIFORM_COLOR') + # bgl.glEnable(bgl.GL_LINE_SMOOTH) + # bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST) with gpu.matrix.push_pop(): gpu.matrix.load_matrix(get_normalize_uvs_matrix()) @@ -35,8 +36,7 @@ def draw_image(face_data, opacity): draw_background_colors(face_data, opacity) draw_lines(face_data) - bgl.glDisable(bgl.GL_BLEND) - bgl.glDisable(bgl.GL_LINE_SMOOTH) + gpu.state.blend_set('NONE') def get_normalize_uvs_matrix(): '''matrix maps x and y coordinates from [0, 1] to [-1, 1]''' @@ -83,12 +83,6 @@ def draw_lines(face_data): shader.uniform_float("color", (0, 0, 0, 1)) batch.draw(shader) -def get_pixel_data_from_current_back_buffer(width, height): - buffer = bgl.Buffer(bgl.GL_BYTE, width * height * 4) - bgl.glReadBuffer(bgl.GL_BACK) - bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer) - return buffer - def save_pixels(filepath, pixel_data, width, height): image = bpy.data.images.new("temp", width, height, alpha=True) image.filepath = filepath