Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2022-07-21 19:03:25 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-07-21 20:04:12 +0300
commitb56a6acb9f4fe1041ed377202f05ed5a5dd09d91 (patch)
treecae230fdbab0cf79f71a6f8426c1d8f8a6ec6cf4
parent294e899bf73cf461eee98c89a8583503cdcf58f5 (diff)
UV Layout: replace deprecated bgl module
Part of T80730
-rw-r--r--io_mesh_uv_layout/__init__.py4
-rw-r--r--io_mesh_uv_layout/export_uv_png.py26
2 files changed, 12 insertions, 18 deletions
diff --git a/io_mesh_uv_layout/__init__.py b/io_mesh_uv_layout/__init__.py
index 324f2254..ceb5ddbc 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 958bac8e..74cd7b19 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