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:
authorCampbell Barton <ideasman42@gmail.com>2021-01-27 13:13:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-01-27 13:20:58 +0300
commit41658df313e1948484af81a5c035810a040f637d (patch)
tree838946cfe773214d8b4d54815f8c641e651a1dfe
parenta889c00fde6a4566d8d18c551921394ceaec7a31 (diff)
Fix T82562: Measureit line drawing doesn't work
This allows measureit to behave correctly with line thickness option. Initially based on D9519 by @NicksBest with various fixes/updates.
-rw-r--r--measureit/measureit_geometry.py30
-rw-r--r--measureit/measureit_main.py1
-rw-r--r--measureit/measureit_render.py2
3 files changed, 23 insertions, 10 deletions
diff --git a/measureit/measureit_geometry.py b/measureit/measureit_geometry.py
index 998bc038..dbb9edd7 100644
--- a/measureit/measureit_geometry.py
+++ b/measureit/measureit_geometry.py
@@ -39,7 +39,19 @@ import bgl
import gpu
from gpu_extras.batch import batch_for_shader
+
shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') if not bpy.app.background else None
+shader_line = gpu.shader.from_builtin('3D_POLYLINE_UNIFORM_COLOR') if not bpy.app.background else None
+
+imm_line_width = 1.0
+imm_viewport = (0, 0)
+
+def imm_set_line_width(width):
+ global imm_line_width, imm_viewport
+ region = bpy.context.region
+ imm_viewport = (region.width, region.height)
+
+ imm_line_width = width
# -------------------------------------------------------------
# Draw segments
@@ -327,9 +339,9 @@ def draw_segments(context, myobj, op, region, rv3d):
# colour + line setup
# ------------------------------------
if ovr is False:
- bgl.glLineWidth(ms.glwidth)
+ imm_set_line_width(ms.glwidth)
else:
- bgl.glLineWidth(ovrline)
+ imm_set_line_width(ovrline)
# ------------------------------------
# Text (distance)
@@ -877,15 +889,17 @@ def draw_text(myobj, pos2d, display_text, rgba, fsize, align='L', text_rot=0.0):
#
# -------------------------------------------------------------
def draw_line(v1, v2, rgba):
- coords = [(v1[0], v1[1]), (v2[0], v2[1])]
- batch = batch_for_shader(shader, 'LINES', {"pos": coords})
+ coords = [(v1[0], v1[1], 0), (v2[0], v2[1], 0)]
+ batch = batch_for_shader(shader_line, 'LINES', {"pos": coords})
# noinspection PyBroadException
try:
if v1 is not None and v2 is not None:
- shader.bind()
- shader.uniform_float("color", rgba)
- batch.draw(shader)
+ shader_line.bind()
+ shader_line.uniform_float("color", rgba)
+ shader_line.uniform_float("lineWidth", imm_line_width)
+ shader_line.uniform_float("viewportSize", imm_viewport)
+ batch.draw(shader_line)
except:
pass
@@ -1180,7 +1194,7 @@ def draw_faces(context, myobj, region, rv3d):
a_p2 = (a_p1[0] + normal[0] * ln, a_p1[1] + normal[1] * ln, a_p1[2] + normal[2] * ln)
# line setup
bgl.glEnable(bgl.GL_BLEND)
- bgl.glLineWidth(th)
+ imm_set_line_width(th)
# converting to screen coordinates
txtpoint2d = get_2d_point(region, rv3d, a_p1)
point2 = get_2d_point(region, rv3d, a_p2)
diff --git a/measureit/measureit_main.py b/measureit/measureit_main.py
index 1e236971..233501b6 100644
--- a/measureit/measureit_main.py
+++ b/measureit/measureit_main.py
@@ -1984,7 +1984,6 @@ def draw_main(context):
# -----------------------
# restore opengl defaults
# -----------------------
- bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
diff --git a/measureit/measureit_render.py b/measureit/measureit_render.py
index fb33289c..a298fbd1 100644
--- a/measureit/measureit_render.py
+++ b/measureit/measureit_render.py
@@ -112,7 +112,7 @@ def render_main(self, context, animation=False):
rfborder = scene.measureit_rf_border
rfline = scene.measureit_rf_line
- bgl.glLineWidth(rfline)
+ imm_set_line_width(rfline)
x1 = rfborder
x2 = width - rfborder
y1 = int(ceil(rfborder / (width / height)))