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 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 it under the terms of the GNU General Public License as published by
@ -18,8 +18,8 @@
bl_info = { bl_info = {
"name": "Symmetrize Texture", "name": "Symmetrize Texture",
"author": "akaneyu", "author": "akaneyu",
"version": (1, 1, 3), "version": (1, 2, 0),
"blender": (2, 93, 0), "blender": (3, 3, 0),
"location": "View3D", "location": "View3D",
"warning": "", "warning": "",
"description": "", "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 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 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
''' '''
import sys
import os import os
import ctypes import ctypes
import math
import bpy import bpy
import bpy.utils.previews import bpy.utils.previews
import blf import blf
import numpy as np import numpy as np
from . ui_renderer import UIRenderer as UIRenderer from . ui_renderer import UIRenderer as UIRenderer
from . import utils
class Session: class Session:
def __init__(self): def __init__(self):
@ -77,35 +74,31 @@ def draw_handler():
session.ui_renderer.render_arrow(center, arrow_angle) session.ui_renderer.render_arrow(center, arrow_angle)
info_text = "LMB: Perform\n" \ info_text = "[LMB] Perform " \
+ "RMB: Cancel" + "[RMB] Cancel"
# brush # brush
if session.brush_active and session.brush_position: if session.brush_active and session.brush_position:
session.ui_renderer.render_brush_frame(session.brush_position, session.brush_size) session.ui_renderer.render_brush_frame(session.brush_position, session.brush_size)
info_text = "LMB: Perform\n" \ info_text = "[LMB] Perform " \
+ "RMB: Finish\n" \ + "[RMB] Finish " \
+ "F: Change brush size" + "[F] Change brush size"
area_height = context.area.height area_width, area_height = context.area.width, context.area.height
# info text # info text
if info_text: if info_text:
blf.enable(0, blf.WORD_WRAP) ui_scale = context.preferences.system.ui_scale
blf.word_wrap(0, 200)
blf.color(0, 1.0, 1.0, 1.0, 1.0)
if bpy.context.area.type == 'VIEW_3D': session.ui_renderer.render_info_box((0, 0), (area_width, 20 * ui_scale))
blf.position(0, 85, area_height - 150, 0)
else:
blf.position(0, 85, area_height - 70, 0)
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.draw(0, info_text)
blf.disable(0, blf.WORD_WRAP)
def load_icons(): def load_icons():
global session 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 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 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
''' '''
import time
import bpy
import bgl
import blf
import gpu import gpu
from gpu_extras.batch import batch_for_shader from gpu_extras.batch import batch_for_shader
from mathutils import Matrix from mathutils import Matrix
@ -94,9 +90,6 @@ class UIRenderer:
self.dotted_line_shader_u_color2 = self.dotted_line_shader.uniform_from_name("color2") self.dotted_line_shader_u_color2 = self.dotted_line_shader.uniform_from_name("color2")
def render_border(self, pos1, pos2): def render_border(self, pos1, pos2):
bgl.glEnable(bgl.GL_BLEND)
bgl.glLineWidth(1.0)
batch = batch_for_shader(self.default_shader, 'LINES', batch = batch_for_shader(self.default_shader, 'LINES',
{"pos": [pos1, pos2]}) {"pos": [pos1, pos2]})
@ -107,16 +100,9 @@ class UIRenderer:
batch.draw(self.default_shader) 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): def render_arrow(self, center, angle):
bgl.glEnable(bgl.GL_BLEND) prev_blend = gpu.state.blend_get()
bgl.glLineWidth(1.0) gpu.state.blend_set('ALPHA')
gpu.matrix.load_identity()
with gpu.matrix.push_pop(): with gpu.matrix.push_pop():
gpu.matrix.translate(center) gpu.matrix.translate(center)
@ -151,14 +137,11 @@ class UIRenderer:
batch.draw(self.default_shader) batch.draw(self.default_shader)
err = bgl.glGetError() gpu.state.blend_set(prev_blend)
if err != bgl.GL_NO_ERROR:
print('render_arrow')
print('OpenGL error:', err)
def render_brush_frame(self, pos, radius): def render_brush_frame(self, pos, radius):
bgl.glEnable(bgl.GL_BLEND) prev_line_width = gpu.state.line_width_get()
bgl.glLineWidth(2.0) gpu.state.line_width_set(2.0)
verts = self.create_brush_frame_vertices(pos, radius) verts = self.create_brush_frame_vertices(pos, radius)
@ -180,10 +163,7 @@ class UIRenderer:
batch.draw(self.dotted_line_shader) batch.draw(self.dotted_line_shader)
err = bgl.glGetError() gpu.state.line_width_set(prev_line_width)
if err != bgl.GL_NO_ERROR:
print('render_brush_frame')
print('OpenGL error:', err)
def create_brush_frame_vertices(self, pos, radius): def create_brush_frame_vertices(self, pos, radius):
segs = 32 segs = 32
@ -206,3 +186,31 @@ class UIRenderer:
verts.append(verts[0]) verts.append(verts[0])
return np.array(verts, 'f') 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)