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-09-10 00:28:12 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-09-10 00:30:44 +0300
commit6feb9c532d7b0850579be084ddce5016ce5b7e08 (patch)
tree6f6b54e876635e8c25c6dd2576fbccccdf514723
parent0cd92169d40ae1c7e103ff269e850eaf1b901646 (diff)
Magic UV: replace deprecated bgl module
Part of T80730
-rw-r--r--magic_uv/__init__.py4
-rw-r--r--magic_uv/lib/__init__.py14
-rw-r--r--magic_uv/lib/bglx.py288
-rw-r--r--magic_uv/op/__init__.py2
-rw-r--r--magic_uv/op/texture_projection.py49
-rw-r--r--magic_uv/op/uv_bounding_box.py50
-rw-r--r--magic_uv/op/uv_inspection.py102
-rw-r--r--magic_uv/op/uv_sculpt.py24
8 files changed, 96 insertions, 437 deletions
diff --git a/magic_uv/__init__.py b/magic_uv/__init__.py
index fe2fe0ae..c79f09ff 100644
--- a/magic_uv/__init__.py
+++ b/magic_uv/__init__.py
@@ -12,8 +12,8 @@ bl_info = {
"Keith (Wahooney) Boshoff, McBuff, MaxRobinot, "
"Alexander Milovsky, Dusan Stevanovic, MatthiasThDs, "
"theCryingMan, PratikBorhade302",
- "version": (6, 6, 0),
- "blender": (2, 80, 0),
+ "version": (6, 7, 0),
+ "blender": (3, 4, 0),
"location": "See Add-ons Preferences",
"description": "UV Toolset. See Add-ons Preferences for details",
"warning": "",
diff --git a/magic_uv/lib/__init__.py b/magic_uv/lib/__init__.py
deleted file mode 100644
index 12838e0d..00000000
--- a/magic_uv/lib/__init__.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-__author__ = "Nutti <nutti.metro@gmail.com>"
-__status__ = "production"
-__version__ = "6.6"
-__date__ = "22 Apr 2022"
-
-if "bpy" in locals():
- import importlib
- importlib.reload(bglx)
-else:
- from . import bglx
-
-import bpy
diff --git a/magic_uv/lib/bglx.py b/magic_uv/lib/bglx.py
deleted file mode 100644
index c1f696ab..00000000
--- a/magic_uv/lib/bglx.py
+++ /dev/null
@@ -1,288 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-from threading import Lock
-
-import bgl
-from bgl import Buffer as Buffer
-import gpu
-from gpu_extras.batch import batch_for_shader
-
-GL_LINES = 0
-GL_LINE_STRIP = 1
-GL_LINE_LOOP = 2
-GL_TRIANGLES = 5
-GL_TRIANGLE_FAN = 6
-GL_QUADS = 4
-
-class InternalData:
- __inst = None
- __lock = Lock()
-
- def __init__(self):
- raise NotImplementedError("Not allowed to call constructor")
-
- @classmethod
- def __internal_new(cls):
- inst = super().__new__(cls)
- inst.color = [1.0, 1.0, 1.0, 1.0]
- inst.line_width = 1.0
-
- return inst
-
- @classmethod
- def get_instance(cls):
- if not cls.__inst:
- with cls.__lock:
- if not cls.__inst:
- cls.__inst = cls.__internal_new()
-
- return cls.__inst
-
- def init(self):
- self.clear()
-
- def set_prim_mode(self, mode):
- self.prim_mode = mode
-
- def set_dims(self, dims):
- self.dims = dims
-
- def add_vert(self, v):
- self.verts.append(v)
-
- def add_tex_coord(self, uv):
- self.tex_coords.append(uv)
-
- def set_color(self, c):
- self.color = c
-
- def set_line_width(self, width):
- self.line_width = width
-
- def clear(self):
- self.prim_mode = None
- self.verts = []
- self.dims = None
- self.tex_coords = []
-
- def get_verts(self):
- return self.verts
-
- def get_dims(self):
- return self.dims
-
- def get_prim_mode(self):
- return self.prim_mode
-
- def get_color(self):
- return self.color
-
- def get_line_width(self):
- return self.line_width
-
- def get_tex_coords(self):
- return self.tex_coords
-
-
-def glLineWidth(width):
- inst = InternalData.get_instance()
- inst.set_line_width(width)
-
-
-def glColor3f(r, g, b):
- inst = InternalData.get_instance()
- inst.set_color([r, g, b, 1.0])
-
-
-def glColor4f(r, g, b, a):
- inst = InternalData.get_instance()
- inst.set_color([r, g, b, a])
-
-
-def glRecti(x0, y0, x1, y1):
- glBegin(GL_QUADS)
- glVertex2f(x0, y0)
- glVertex2f(x0, y1)
- glVertex2f(x1, y1)
- glVertex2f(x1, y0)
- glEnd()
-
-
-def glBegin(mode):
- inst = InternalData.get_instance()
- inst.init()
- inst.set_prim_mode(mode)
-
-
-def _get_transparency_shader():
- vertex_shader = '''
- uniform mat4 modelViewMatrix;
- uniform mat4 projectionMatrix;
-
- in vec2 pos;
- in vec2 texCoord;
- out vec2 uvInterp;
-
- void main()
- {
- uvInterp = texCoord;
- gl_Position = projectionMatrix * modelViewMatrix * vec4(pos.xy, 0.0, 1.0);
- gl_Position.z = 1.0;
- }
- '''
-
- fragment_shader = '''
- uniform sampler2D image;
- uniform vec4 color;
-
- in vec2 uvInterp;
- out vec4 fragColor;
-
- void main()
- {
- fragColor = texture(image, uvInterp);
- fragColor.a = color.a;
- }
- '''
-
- return vertex_shader, fragment_shader
-
-
-def glEnd():
- inst = InternalData.get_instance()
-
- color = inst.get_color()
- coords = inst.get_verts()
- tex_coords = inst.get_tex_coords()
- if inst.get_dims() == 2:
- if len(tex_coords) == 0:
- shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
- else:
- #shader = gpu.shader.from_builtin('2D_IMAGE')
- vert_shader, frag_shader = _get_transparency_shader()
- shader = gpu.types.GPUShader(vert_shader, frag_shader)
- elif inst.get_dims() == 3:
- if len(tex_coords) == 0:
- shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
- else:
- raise NotImplemented("Texture is not supported in get_dims() == 3")
- else:
- raise NotImplemented("get_dims() != 2")
-
- if len(tex_coords) == 0:
- data = {
- "pos": coords,
- }
- else:
- data = {
- "pos": coords,
- "texCoord": tex_coords
- }
-
- if inst.get_prim_mode() == GL_LINES:
- indices = []
- for i in range(0, len(coords), 2):
- indices.append([i, i + 1])
- batch = batch_for_shader(shader, 'LINES', data, indices=indices)
-
- elif inst.get_prim_mode() == GL_LINE_STRIP:
- batch = batch_for_shader(shader, 'LINE_STRIP', data)
-
-
- elif inst.get_prim_mode() == GL_LINE_LOOP:
- data["pos"].append(data["pos"][0])
- batch = batch_for_shader(shader, 'LINE_STRIP', data)
-
- elif inst.get_prim_mode() == GL_TRIANGLES:
- indices = []
- for i in range(0, len(coords), 3):
- indices.append([i, i + 1, i + 2])
- batch = batch_for_shader(shader, 'TRIS', data, indices=indices)
-
- elif inst.get_prim_mode() == GL_TRIANGLE_FAN:
- indices = []
- for i in range(1, len(coords) - 1):
- indices.append([0, i, i + 1])
- batch = batch_for_shader(shader, 'TRIS', data, indices=indices)
-
- elif inst.get_prim_mode() == GL_QUADS:
- indices = []
- for i in range(0, len(coords), 4):
- indices.extend([[i, i + 1, i + 2], [i + 2, i + 3, i]])
- batch = batch_for_shader(shader, 'TRIS', data, indices=indices)
- else:
- raise NotImplemented("get_prim_mode() != (GL_LINES|GL_TRIANGLES|GL_QUADS)")
-
- shader.bind()
- if len(tex_coords) != 0:
- shader.uniform_float("modelViewMatrix", gpu.matrix.get_model_view_matrix())
- shader.uniform_float("projectionMatrix", gpu.matrix.get_projection_matrix())
- shader.uniform_int("image", 0)
- shader.uniform_float("color", color)
- batch.draw(shader)
-
- inst.clear()
-
-
-def glVertex2f(x, y):
- inst = InternalData.get_instance()
- inst.add_vert([x, y])
- inst.set_dims(2)
-
-
-def glVertex3f(x, y, z):
- inst = InternalData.get_instance()
- inst.add_vert([x, y, z])
- inst.set_dims(3)
-
-
-def glTexCoord2f(u, v):
- inst = InternalData.get_instance()
- inst.add_tex_coord([u, v])
-
-
-GL_BLEND = bgl.GL_BLEND
-GL_LINE_SMOOTH = bgl.GL_LINE_SMOOTH
-GL_INT = bgl.GL_INT
-GL_SCISSOR_BOX = bgl.GL_SCISSOR_BOX
-GL_TEXTURE_2D = bgl.GL_TEXTURE_2D
-GL_TEXTURE0 = bgl.GL_TEXTURE0
-GL_DEPTH_TEST = bgl.GL_DEPTH_TEST
-
-GL_TEXTURE_MIN_FILTER = 0
-GL_TEXTURE_MAG_FILTER = 0
-GL_LINEAR = 0
-GL_TEXTURE_ENV = 0
-GL_TEXTURE_ENV_MODE = 0
-GL_MODULATE = 0
-
-def glEnable(cap):
- bgl.glEnable(cap)
-
-
-def glDisable(cap):
- bgl.glDisable(cap)
-
-
-def glScissor(x, y, width, height):
- bgl.glScissor(x, y, width, height)
-
-
-def glGetIntegerv(pname, params):
- bgl.glGetIntegerv(pname, params)
-
-
-def glActiveTexture(texture):
- bgl.glActiveTexture(texture)
-
-
-def glBindTexture(target, texture):
- bgl.glBindTexture(target, texture)
-
-
-def glTexParameteri(target, pname, param):
- pass
-
-
-def glTexEnvi(target, pname, param):
- pass
diff --git a/magic_uv/op/__init__.py b/magic_uv/op/__init__.py
index 0c6d91e2..e2104743 100644
--- a/magic_uv/op/__init__.py
+++ b/magic_uv/op/__init__.py
@@ -2,7 +2,7 @@
__author__ = "Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "6.6"
+__version__ = "6.7"
__date__ = "22 Apr 2022"
if "bpy" in locals():
diff --git a/magic_uv/op/texture_projection.py b/magic_uv/op/texture_projection.py
index 92566981..721d8261 100644
--- a/magic_uv/op/texture_projection.py
+++ b/magic_uv/op/texture_projection.py
@@ -2,7 +2,7 @@
__author__ = "Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "6.6"
+__version__ = "6.7"
__date__ = "22 Apr 2022"
from collections import namedtuple
@@ -24,11 +24,8 @@ from ..utils.bl_class_registry import BlClassRegistry
from ..utils.property_class_registry import PropertyClassRegistry
from ..utils import compatibility as compat
-if compat.check_version(2, 80, 0) >= 0:
- from ..lib import bglx as bgl
-else:
- import bgl
-
+import gpu
+from gpu_extras.batch import batch_for_shader
_Rect = namedtuple('Rect', 'x0 y0 x1 y1')
_Rect2 = namedtuple('Rect2', 'x y width height')
@@ -334,35 +331,19 @@ class MUV_OT_TextureProjection(bpy.types.Operator):
]
# OpenGL configuration
- if compat.check_version(2, 80, 0) >= 0:
- bgl.glEnable(bgl.GL_BLEND)
- bgl.glEnable(bgl.GL_TEXTURE_2D)
- bgl.glActiveTexture(bgl.GL_TEXTURE0)
- if img.bindcode:
- bind = img.bindcode
- bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
- else:
- bgl.glEnable(bgl.GL_BLEND)
- bgl.glEnable(bgl.GL_TEXTURE_2D)
- if img.bindcode:
- bind = img.bindcode[0]
- bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
- bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
- bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
- bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
- bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
- bgl.glTexEnvi(
- bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
- bgl.GL_MODULATE)
-
# render texture
- bgl.glBegin(bgl.GL_QUADS)
- bgl.glColor4f(1.0, 1.0, 1.0,
- sc.muv_texture_projection_tex_transparency)
- for (v1, v2), (u, v) in zip(positions, tex_coords):
- bgl.glTexCoord2f(u, v)
- bgl.glVertex2f(v1, v2)
- bgl.glEnd()
+ shader = gpu.shader.from_builtin('IMAGE_COLOR')
+ batch = batch_for_shader(
+ shader, 'TRI_FAN',
+ {"pos": positions, "texCoord": tex_coords},
+ )
+
+ gpu.state.blend_set('ALPHA')
+ shader.bind()
+ shader.uniform_sampler("image", gpu.texture.from_image(img))
+ shader.uniform_float("color", (1.0, 1.0, 1.0, sc.muv_texture_projection_tex_transparency))
+ batch.draw(shader)
+ del batch
def invoke(self, context, _):
if not MUV_OT_TextureProjection.is_running(context):
diff --git a/magic_uv/op/uv_bounding_box.py b/magic_uv/op/uv_bounding_box.py
index 90e65f2f..4ea9a500 100644
--- a/magic_uv/op/uv_bounding_box.py
+++ b/magic_uv/op/uv_bounding_box.py
@@ -2,7 +2,7 @@
__author__ = "Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "6.6"
+__version__ = "6.7"
__date__ = "22 Apr 2022"
from enum import IntEnum
@@ -18,10 +18,8 @@ from ..utils.bl_class_registry import BlClassRegistry
from ..utils.property_class_registry import PropertyClassRegistry
from ..utils import compatibility as compat
-if compat.check_version(2, 80, 0) >= 0:
- from ..lib import bglx as bgl
-else:
- import bgl
+import gpu
+from gpu_extras.batch import batch_for_shader
MAX_VALUE = 100000.0
@@ -635,28 +633,6 @@ class MUV_OT_UVBoundingBox(bpy.types.Operator):
cls.__timer = None
@classmethod
- def __draw_ctrl_point(cls, context, pos):
- """
- Draw control point
- """
- user_prefs = compat.get_user_preferences(context)
- prefs = user_prefs.addons["magic_uv"].preferences
- cp_size = prefs.uv_bounding_box_cp_size
- offset = cp_size / 2
- verts = [
- [pos.x - offset, pos.y - offset],
- [pos.x - offset, pos.y + offset],
- [pos.x + offset, pos.y + offset],
- [pos.x + offset, pos.y - offset]
- ]
- bgl.glEnable(bgl.GL_BLEND)
- bgl.glBegin(bgl.GL_QUADS)
- bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
- for (x, y) in verts:
- bgl.glVertex2f(x, y)
- bgl.glEnd()
-
- @classmethod
def draw_bb(cls, _, context):
"""
Draw bounding box
@@ -669,10 +645,22 @@ class MUV_OT_UVBoundingBox(bpy.types.Operator):
if not _is_valid_context(context):
return
- for cp in props.ctrl_points:
- cls.__draw_ctrl_point(
- context, mathutils.Vector(
- context.region.view2d.view_to_region(cp.x, cp.y)))
+ user_prefs = compat.get_user_preferences(context)
+ prefs = user_prefs.addons["magic_uv"].preferences
+ cp_size = prefs.uv_bounding_box_cp_size
+
+ gpu.state.program_point_size_set(False)
+ gpu.state.point_size_set(cp_size)
+ gpu.state.blend_set('ALPHA')
+
+ shader = gpu.shader.from_builtin("UNIFORM_COLOR")
+ shader.bind()
+ shader.uniform_float("color", (1.0, 1.0, 1.0, 1.0))
+
+ points = [mathutils.Vector(context.region.view2d.view_to_region(cp.x, cp.y)) for cp in props.ctrl_points]
+ batch = batch_for_shader(shader, 'POINTS', {"pos": points})
+ batch.draw(shader)
+ del batch
def __get_uv_info(self, context):
"""
diff --git a/magic_uv/op/uv_inspection.py b/magic_uv/op/uv_inspection.py
index bcfe80be..4dab465a 100644
--- a/magic_uv/op/uv_inspection.py
+++ b/magic_uv/op/uv_inspection.py
@@ -2,7 +2,7 @@
__author__ = "Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "6.6"
+__version__ = "6.7"
__date__ = "22 Apr 2022"
import random
@@ -17,10 +17,8 @@ from ..utils.bl_class_registry import BlClassRegistry
from ..utils.property_class_registry import PropertyClassRegistry
from ..utils import compatibility as compat
-if compat.check_version(2, 80, 0) >= 0:
- from ..lib import bglx as bgl
-else:
- import bgl
+import gpu
+from gpu_extras.batch import batch_for_shader
def _is_valid_context(context):
@@ -234,41 +232,40 @@ class MUV_OT_UVInspection_Render(bpy.types.Operator):
return
# OpenGL configuration.
- bgl.glEnable(bgl.GL_BLEND)
- bgl.glEnable(bgl.GL_DEPTH_TEST)
+ gpu.state.blend_set('ALPHA')
+ gpu.state.depth_test_set('LESS_EQUAL')
+
+ shader = gpu.shader.from_builtin("UNIFORM_COLOR")
+ shader.bind()
# Render faces whose UV is overlapped.
if sc.muv_uv_inspection_show_overlapped:
- color = prefs.uv_inspection_overlapped_color_for_v3d
+ shader.uniform_float("color", prefs.uv_inspection_overlapped_color_for_v3d)
+
for obj, findices in props.overlapped_info_for_v3d.items():
world_mat = obj.matrix_world
bm = bmesh.from_edit_mesh(obj.data)
for fidx in findices:
- bgl.glBegin(bgl.GL_TRIANGLE_FAN)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
- for l in bm.faces[fidx].loops:
- co = compat.matmul(world_mat, l.vert.co)
- bgl.glVertex3f(co[0], co[1], co[2])
- bgl.glEnd()
+ coords = [compat.matmul(world_mat, l.vert.co) for l in bm.faces[fidx].loops]
+ batch = batch_for_shader(shader, 'TRI_FAN', {"pos": coords})
+ batch.draw(shader)
# Render faces whose UV is flipped.
if sc.muv_uv_inspection_show_flipped:
- color = prefs.uv_inspection_flipped_color_for_v3d
+ shader.uniform_float("color", prefs.uv_inspection_flipped_color_for_v3d)
+
for obj, findices in props.filpped_info_for_v3d.items():
world_mat = obj.matrix_world
bm = bmesh.from_edit_mesh(obj.data)
for fidx in findices:
- bgl.glBegin(bgl.GL_TRIANGLE_FAN)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
- for l in bm.faces[fidx].loops:
- co = compat.matmul(world_mat, l.vert.co)
- bgl.glVertex3f(co[0], co[1], co[2])
- bgl.glEnd()
+ coords = [compat.matmul(world_mat, l.vert.co) for l in bm.faces[fidx].loops]
+ batch = batch_for_shader(shader, 'TRI_FAN', {"pos": coords})
+ batch.draw(shader)
- bgl.glDisable(bgl.GL_DEPTH_TEST)
- bgl.glDisable(bgl.GL_BLEND)
+ gpu.state.depth_test_set('NONE')
+ gpu.state.blend_set('NONE')
@staticmethod
def draw(_, context):
@@ -281,53 +278,46 @@ class MUV_OT_UVInspection_Render(bpy.types.Operator):
return
# OpenGL configuration
- bgl.glEnable(bgl.GL_BLEND)
+ gpu.state.blend_set('ALPHA')
+
+ shader = gpu.shader.from_builtin("UNIFORM_COLOR")
+ shader.bind()
# render overlapped UV
if sc.muv_uv_inspection_show_overlapped:
- color = prefs.uv_inspection_overlapped_color
+ shader.uniform_float("color", prefs.uv_inspection_overlapped_color)
+
for info in props.overlapped_info:
if sc.muv_uv_inspection_show_mode == 'PART':
for poly in info["polygons"]:
- bgl.glBegin(bgl.GL_TRIANGLE_FAN)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
- for uv in poly:
- x, y = context.region.view2d.view_to_region(
- uv.x, uv.y, clip=False)
- bgl.glVertex2f(x, y)
- bgl.glEnd()
+ coords = [context.region.view2d.view_to_region(uv.x, uv.y, clip=False) for uv in poly]
+ batch = batch_for_shader(shader, 'TRI_FAN', {"pos": coords})
+ batch.draw(shader)
+
elif sc.muv_uv_inspection_show_mode == 'FACE':
- bgl.glBegin(bgl.GL_TRIANGLE_FAN)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
- for uv in info["subject_uvs"]:
- x, y = context.region.view2d.view_to_region(
- uv.x, uv.y, clip=False)
- bgl.glVertex2f(x, y)
- bgl.glEnd()
+ coords = [
+ context.region.view2d.view_to_region(
+ uv.x, uv.y, clip=False) for uv in info["subject_uvs"]]
+ batch = batch_for_shader(shader, 'TRI_FAN', {"pos": coords})
+ batch.draw(shader)
# render flipped UV
if sc.muv_uv_inspection_show_flipped:
- color = prefs.uv_inspection_flipped_color
+ shader.uniform_float("color", prefs.uv_inspection_flipped_color)
+
for info in props.flipped_info:
if sc.muv_uv_inspection_show_mode == 'PART':
for poly in info["polygons"]:
- bgl.glBegin(bgl.GL_TRIANGLE_FAN)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
- for uv in poly:
- x, y = context.region.view2d.view_to_region(
- uv.x, uv.y, clip=False)
- bgl.glVertex2f(x, y)
- bgl.glEnd()
+ coords = [context.region.view2d.view_to_region(uv.x, uv.y, clip=False) for uv in poly]
+ batch = batch_for_shader(shader, 'TRI_FAN', {"pos": coords})
+ batch.draw(shader)
+
elif sc.muv_uv_inspection_show_mode == 'FACE':
- bgl.glBegin(bgl.GL_TRIANGLE_FAN)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
- for uv in info["uvs"]:
- x, y = context.region.view2d.view_to_region(
- uv.x, uv.y, clip=False)
- bgl.glVertex2f(x, y)
- bgl.glEnd()
-
- bgl.glDisable(bgl.GL_BLEND)
+ coords = [context.region.view2d.view_to_region(uv.x, uv.y, clip=False) for uv in info["uvs"]]
+ batch = batch_for_shader(shader, 'TRI_FAN', {"pos": coords})
+ batch.draw(shader)
+
+ gpu.state.blend_set('NONE')
def invoke(self, context, _):
if not MUV_OT_UVInspection_Render.is_running(context):
diff --git a/magic_uv/op/uv_sculpt.py b/magic_uv/op/uv_sculpt.py
index dac8cff3..d0426751 100644
--- a/magic_uv/op/uv_sculpt.py
+++ b/magic_uv/op/uv_sculpt.py
@@ -2,7 +2,7 @@
__author__ = "Nutti <nutti.metro@gmail.com>"
__status__ = "production"
-__version__ = "6.6"
+__version__ = "6.7"
__date__ = "22 Apr 2022"
from math import pi, cos, tan, sin
@@ -25,11 +25,8 @@ from ..utils.bl_class_registry import BlClassRegistry
from ..utils.property_class_registry import PropertyClassRegistry
from ..utils import compatibility as compat
-
-if compat.check_version(2, 80, 0) >= 0:
- from ..lib import bglx as bgl
-else:
- import bgl
+import gpu
+from gpu_extras.batch import batch_for_shader
def _is_valid_context(context):
@@ -215,21 +212,26 @@ class MUV_OT_UVSculpt(bpy.types.Operator):
theta = 2 * pi / num_segment
fact_t = tan(theta)
fact_r = cos(theta)
- color = prefs.uv_sculpt_brush_color
- bgl.glBegin(bgl.GL_LINE_STRIP)
- bgl.glColor4f(color[0], color[1], color[2], color[3])
+ shader = gpu.shader.from_builtin("UNIFORM_COLOR")
+ shader.bind()
+ shader.uniform_float("color", prefs.uv_sculpt_brush_color)
+
x = sc.muv_uv_sculpt_radius * cos(0.0)
y = sc.muv_uv_sculpt_radius * sin(0.0)
+ coords = []
for _ in range(num_segment):
- bgl.glVertex2f(x + obj.current_mco.x, y + obj.current_mco.y)
+ coords.append([x + obj.current_mco.x, y + obj.current_mco.y])
tx = -y
ty = x
x = x + tx * fact_t
y = y + ty * fact_t
x = x * fact_r
y = y * fact_r
- bgl.glEnd()
+
+ batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": coords})
+ batch.draw(shader)
+ del batch
def __init__(self):
self.__loop_info = {} # { Object: loop_info }