Skip to content

Commit

Permalink
Merge pull request #7 from p2or/Blender-3.5+
Browse files Browse the repository at this point in the history
Blender 3.5+
  • Loading branch information
p2or authored May 1, 2023
2 parents da36deb + a13fb03 commit 6d53753
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions dof-utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
bl_info = {
"name": "Depth of Field Utilities",
"author": "Christian Brinkmann (p2or)",
"description": "Displays depth of field in 3D view port.",
"version": (0, 1, 1),
"blender": (2, 80, 0),
"description": "Displays depth of field in 3D viewport.",
"version": (0, 1, 2),
"blender": (3, 5, 0),
"location": "3d View > Properties Panel (N) > Depth of Field Utilities",
"doc_url": "https://github.com/p2or/blender-dof-utils",
"tracker_url": "https://github.com/p2or/blender-dof-utils/issues",
"category": "Render"
}

import bpy
import bgl
import blf
import gpu
from gpu_extras.batch import batch_for_shader
Expand Down Expand Up @@ -225,25 +224,25 @@ def draw_callback_3d(operator, context):
dofu.limits = (d, near_limit, far_limit)

# 80% alpha, 2 pixel width line
bgl.glEnable(bgl.GL_BLEND)
bgl.glEnable(bgl.GL_LINE_SMOOTH)
bgl.glEnable(bgl.GL_DEPTH_TEST)
gpu.state.blend_set('ALPHA') # bgl.glEnable(bgl.GL_BLEND)
#bgl.glEnable(bgl.GL_LINE_SMOOTH) # -> No replacement gpu.shader.from_builtin('POLYLINE_SMOOTH_COLOR')
gpu.state.depth_test_set("LESS") # bgl.glEnable(bgl.GL_DEPTH_TEST)

# check overlay
if dofu.overlay:
bgl.glDisable(bgl.GL_DEPTH_TEST)
gpu.state.depth_test_set("NONE") # bgl.glDisable(bgl.GL_DEPTH_TEST)
else:
bgl.glEnable(bgl.GL_DEPTH_TEST)
gpu.state.depth_test_set("LESS") # bgl.glEnable(bgl.GL_DEPTH_TEST)

# set line width
bgl.glLineWidth(2)
gpu.state.line_width_set(2) # bgl.glLineWidth(2)

def line(color, start, end):
vertices = [start,end]
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
batch = batch_for_shader(shader,'LINE_STRIP', {"pos": vertices})
shader.bind()
shader.uniform_float("color",color)
shader.uniform_float("color", color)
batch.draw(shader)
#bgl.glColor4f(*color)
#bgl.glBegin(bgl.GL_LINES)
Expand Down Expand Up @@ -274,22 +273,18 @@ def line(color, start, end):
size=dofu.size_limits * 1.7,
color=(dofu.color_limits[0], dofu.color_limits[1], dofu.color_limits[2], dofu.opacity_limits))

# restore opengl defaults
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glDisable(bgl.GL_LINE_SMOOTH)
bgl.glEnable(bgl.GL_DEPTH_TEST)
#bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

# restore defaults
gpu.state.line_width_set(1.0)
gpu.state.blend_set('NONE')

def draw_string(x, y, packed_strings):
font_id = 0
blf.size(font_id, 17, 70)
blf.size(font_id, 17*(bpy.context.preferences.system.dpi/72))
x_offset = 0
for pstr, pcol in packed_strings:
#bgl.glColor4f(*pcol)
text_width, text_height = blf.dimensions(font_id, pstr)
blf.position(font_id, (x + x_offset), y, 0)
blf.color(font_id, *pcol)
blf.draw(font_id, pstr)
x_offset += text_width

Expand All @@ -314,7 +309,7 @@ def draw_poly(coords, color, width):
# Create batch process
batch = batch_for_shader(shader,'LINE_STRIP', {"pos": coords})
# Set the line width
bgl.glLineWidth(width)
gpu.state.line_width_set(width) # bgl.glLineWidth(width)
shader.bind()
# Set color
shader.uniform_float("color",color)
Expand Down

0 comments on commit 6d53753

Please # to comment.