Support Blender 4.0

This commit is contained in:
akaneyu 2024-03-11 22:26:26 +09:00
parent 995bf859b5
commit b990ec5e74
3 changed files with 51 additions and 50 deletions

View File

@ -1,5 +1,5 @@
'''
Copyright (C) 2021 - 2023 Akaneyu
Copyright (C) 2021 - 2024 Akaneyu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -18,8 +18,8 @@
bl_info = {
"name": "Symmetrize Texture",
"author": "akaneyu",
"version": (1, 1, 3),
"blender": (2, 93, 0),
"version": (1, 2, 0),
"blender": (3, 3, 0),
"location": "View3D",
"warning": "",
"description": "",

View File

@ -1,5 +1,5 @@
'''
Copyright (C) 2021 - 2023 Akaneyu
Copyright (C) 2021 - 2024 Akaneyu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,16 +15,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import sys
import os
import ctypes
import math
import bpy
import bpy.utils.previews
import blf
import numpy as np
from . ui_renderer import UIRenderer as UIRenderer
from . import utils
class Session:
def __init__(self):
@ -77,35 +74,31 @@ def draw_handler():
session.ui_renderer.render_arrow(center, arrow_angle)
info_text = "LMB: Perform\n" \
+ "RMB: Cancel"
info_text = "[LMB] Perform " \
+ "[RMB] Cancel"
# brush
if session.brush_active and session.brush_position:
session.ui_renderer.render_brush_frame(session.brush_position, session.brush_size)
info_text = "LMB: Perform\n" \
+ "RMB: Finish\n" \
+ "F: Change brush size"
info_text = "[LMB] Perform " \
+ "[RMB] Finish " \
+ "[F] Change brush size"
area_height = context.area.height
area_width, area_height = context.area.width, context.area.height
# info text
if info_text:
blf.enable(0, blf.WORD_WRAP)
blf.word_wrap(0, 200)
blf.color(0, 1.0, 1.0, 1.0, 1.0)
ui_scale = context.preferences.system.ui_scale
if bpy.context.area.type == 'VIEW_3D':
blf.position(0, 85, area_height - 150, 0)
else:
blf.position(0, 85, area_height - 70, 0)
session.ui_renderer.render_info_box((0, 0), (area_width, 20 * ui_scale))
blf.size(0, 14, 72)
blf.position(0, 8 * ui_scale, 6 * ui_scale, 0)
blf.size(0, 11 * ui_scale) if bpy.app.version >= (3, 6) \
else blf.size(0, 11 * ui_scale, 72)
blf.color(0, 0.7, 0.7, 0.7, 1.0)
blf.draw(0, info_text)
blf.disable(0, blf.WORD_WRAP)
def load_icons():
global session

View File

@ -1,5 +1,5 @@
'''
Copyright (C) 2020 Akaneyu
Copyright (C) 2020 - 2024 Akaneyu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,10 +15,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import time
import bpy
import bgl
import blf
import gpu
from gpu_extras.batch import batch_for_shader
from mathutils import Matrix
@ -94,9 +90,6 @@ class UIRenderer:
self.dotted_line_shader_u_color2 = self.dotted_line_shader.uniform_from_name("color2")
def render_border(self, pos1, pos2):
bgl.glEnable(bgl.GL_BLEND)
bgl.glLineWidth(1.0)
batch = batch_for_shader(self.default_shader, 'LINES',
{"pos": [pos1, pos2]})
@ -107,16 +100,9 @@ class UIRenderer:
batch.draw(self.default_shader)
err = bgl.glGetError()
if err != bgl.GL_NO_ERROR:
print('render_border')
print('OpenGL error:', err)
def render_arrow(self, center, angle):
bgl.glEnable(bgl.GL_BLEND)
bgl.glLineWidth(1.0)
gpu.matrix.load_identity()
prev_blend = gpu.state.blend_get()
gpu.state.blend_set('ALPHA')
with gpu.matrix.push_pop():
gpu.matrix.translate(center)
@ -151,14 +137,11 @@ class UIRenderer:
batch.draw(self.default_shader)
err = bgl.glGetError()
if err != bgl.GL_NO_ERROR:
print('render_arrow')
print('OpenGL error:', err)
gpu.state.blend_set(prev_blend)
def render_brush_frame(self, pos, radius):
bgl.glEnable(bgl.GL_BLEND)
bgl.glLineWidth(2.0)
prev_line_width = gpu.state.line_width_get()
gpu.state.line_width_set(2.0)
verts = self.create_brush_frame_vertices(pos, radius)
@ -180,10 +163,7 @@ class UIRenderer:
batch.draw(self.dotted_line_shader)
err = bgl.glGetError()
if err != bgl.GL_NO_ERROR:
print('render_brush_frame')
print('OpenGL error:', err)
gpu.state.line_width_set(prev_line_width)
def create_brush_frame_vertices(self, pos, radius):
segs = 32
@ -206,3 +186,31 @@ class UIRenderer:
verts.append(verts[0])
return np.array(verts, 'f')
def render_info_box(self, pos1, pos2):
prev_blend = gpu.state.blend_get()
gpu.state.blend_set('ALPHA')
verts = [
pos1,
(pos2[0], pos1[1]),
(pos1[0], pos2[1]),
pos2
]
indices = [
(0, 1, 2),
(2, 1, 3)
]
batch = batch_for_shader(self.default_shader, 'TRIS',
{"pos": verts}, indices=indices)
self.default_shader.bind()
self.default_shader.uniform_vector_float(self.default_shader_u_color,
np.array([0, 0, 0, 0.7], 'f'), 4)
batch.draw(self.default_shader)
gpu.state.blend_set(prev_blend)