Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Blackbourn <chrisbblend@gmail.com>2022-08-03 00:38:51 +0300
committerChris Blackbourn <chrisbblend@gmail.com>2022-08-03 00:44:06 +0300
commit18377c4f5e4727f6f0b58bd0bae7a5a5686ea0a0 (patch)
tree1313bb852a3ab49f596d271cde4dee87c3e57a6c /release
parent8081a05015f620db1d5759f80d9724699bbcd289 (diff)
UI: Improve circle drawing of cursor for uv sculpting
Calculate segments based on radius. Differential Revision: https://developer.blender.org/D15591
Diffstat (limited to 'release')
-rw-r--r--release/scripts/modules/gpu_extras/presets.py15
-rw-r--r--release/scripts/startup/bl_ui/space_toolsystem_toolbar.py2
2 files changed, 12 insertions, 5 deletions
diff --git a/release/scripts/modules/gpu_extras/presets.py b/release/scripts/modules/gpu_extras/presets.py
index ac9fd3cc1ff..222d9032cfd 100644
--- a/release/scripts/modules/gpu_extras/presets.py
+++ b/release/scripts/modules/gpu_extras/presets.py
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
-def draw_circle_2d(position, color, radius, *, segments=32):
+def draw_circle_2d(position, color, radius, *, segments=None):
"""
Draw a circle.
@@ -11,10 +11,11 @@ def draw_circle_2d(position, color, radius, *, segments=32):
:arg radius: Radius of the circle.
:type radius: float
:arg segments: How many segments will be used to draw the circle.
- Higher values give besser results but the drawing will take longer.
- :type segments: int
+ Higher values give better results but the drawing will take longer.
+ If None or not specified, an automatic value will be calculated.
+ :type segments: int or None
"""
- from math import sin, cos, pi
+ from math import sin, cos, pi, ceil, acos
import gpu
from gpu.types import (
GPUBatch,
@@ -22,6 +23,12 @@ def draw_circle_2d(position, color, radius, *, segments=32):
GPUVertFormat,
)
+ if segments is None:
+ max_pixel_error = 0.25 # TODO: multiply 0.5 by display dpi
+ segments = int(ceil(pi / acos(1.0 - max_pixel_error / radius)))
+ segments = max(segments, 8)
+ segments = min(segments, 1000)
+
if segments <= 0:
raise ValueError("Amount of segments must be greater than 0.")
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 470b78ae558..2e4c0e69e61 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1889,7 +1889,7 @@ class _defs_image_uv_sculpt:
if brush is None:
return
radius = brush.size
- draw_circle_2d(xy, (1.0,) * 4, radius, segments=32)
+ draw_circle_2d(xy, (1.0,) * 4, radius)
return generate_from_enum_ex(
context,