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:
authorGaia Clary <gaia.clary@machinimatrix.org>2021-08-31 17:58:29 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2021-09-01 14:59:12 +0300
commit59c8409947c4174983a36ec28dfeda2be9e254d2 (patch)
tree5f78928b1bb1ed549000cbe80c17e2c123536a90
parent8750642fd56d7fec26b5b1280deabe1393314600 (diff)
MathVis: Mark the selected display item with an active color
When the number of items defined in MathVis grows, then finding a specific item in the ViewPort becomes more difficult. One way to "solve" this is by limiting the number of displayed items. This patch adds another way by color marking the selected item in the MathVis list widget with an 'active' color I have implemented this for matrix bounding boxes and vectors. Benefit: this way you can quickly step over the list and see which item highlights in the viewport. Example: {F10357951} Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D12360
-rw-r--r--space_view3d_math_vis/draw.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/space_view3d_math_vis/draw.py b/space_view3d_math_vis/draw.py
index fa03061d..0420044e 100644
--- a/space_view3d_math_vis/draw.py
+++ b/space_view3d_math_vis/draw.py
@@ -39,7 +39,9 @@ else:
COLOR_POINT = (1.0, 0.0, 1.0, 1)
COLOR_LINE = (0.5, 0.5, 1, 1)
+COLOR_LINE_ACTIVE = (1.0, 1.0, 0.5, 1)
COLOR_BOUNDING_BOX = (1.0, 1.0, 1.0, 1.0)
+COLOR_BOUNDING_BOX_ACTIVE = (1.0, 0.5, 0.0, 1.0)
def tag_redraw_areas():
@@ -136,6 +138,8 @@ def draw_callback_px():
def draw_callback_view():
settings = bpy.context.window_manager.MathVisProp
+ prop_states = bpy.context.window_manager.MathVisStatePropList
+
scale = settings.bbox_scale
with_bounding_box = not settings.bbox_hide
@@ -145,31 +149,36 @@ def draw_callback_view():
bgl.glDepthFunc(bgl.GL_LESS)
data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()
+ active_index = settings.index
+ active_key = prop_states[active_index].name if active_index >= 0 else None
if data_vector:
coords = [tuple(vec.to_3d()) for vec in data_vector.values()]
draw_points(coords)
if data_vector_array:
- for line in data_vector_array.values():
+ for key, line in data_vector_array.items():
coords = [tuple(vec.to_3d()) for vec in line]
- draw_line(coords)
+ if key == active_key:
+ draw_line(coords, COLOR_LINE_ACTIVE)
+ else:
+ draw_line(coords, COLOR_LINE)
if data_matrix:
- draw_matrices(list(data_matrix.values()), scale, with_bounding_box)
+ draw_matrices(data_matrix, scale, with_bounding_box, active_key)
if data_euler or data_quat:
cursor = bpy.context.scene.cursor.location.copy()
derived_matrices = []
- for quat in data_quat.values():
+ for key, quat in data_quat.values():
matrix = quat.to_matrix().to_4x4()
matrix.translation = cursor
- derived_matrices.append(matrix)
- for eul in data_euler.values():
+ derived_matrices[key] = matrix
+ for key, eul in data_euler.values():
matrix = eul.to_matrix().to_4x4()
matrix.translation = cursor
- derived_matrices.append(matrix)
- draw_matrices(derived_matrices, scale, with_bounding_box)
+ derived_matrices[key] = matrix
+ draw_matrices(derived_matrices, scale, with_bounding_box, active_key)
def draw_points(points):
@@ -179,10 +188,10 @@ def draw_points(points):
batch.draw(single_color_shader)
-def draw_line(points):
+def draw_line(points, color):
batch = batch_from_points(points, "LINE_STRIP")
single_color_shader.bind()
- single_color_shader.uniform_float("color", COLOR_LINE)
+ single_color_shader.uniform_float("color", color)
batch.draw(single_color_shader)
@@ -190,7 +199,7 @@ def batch_from_points(points, type):
return batch_for_shader(single_color_shader, type, {"pos": points})
-def draw_matrices(matrices, scale, with_bounding_box):
+def draw_matrices(matrices, scale, with_bounding_box, active_key):
x_p = Vector((scale, 0.0, 0.0))
x_n = Vector((-scale, 0.0, 0.0))
y_p = Vector((0.0, scale, 0.0))
@@ -207,7 +216,9 @@ def draw_matrices(matrices, scale, with_bounding_box):
coords = []
colors = []
- for matrix in matrices:
+ selected = []
+ active = []
+ for key, matrix in matrices.items():
coords.append(matrix @ x_n)
coords.append(matrix @ x_p)
colors.extend((red_dark, red_light))
@@ -217,6 +228,10 @@ def draw_matrices(matrices, scale, with_bounding_box):
coords.append(matrix @ z_n)
coords.append(matrix @ z_p)
colors.extend((blue_dark, blue_light))
+ if key == active_key:
+ active.append(matrix)
+ else:
+ selected.append(matrix)
batch = batch_for_shader(smooth_color_shader, "LINES", {
"pos": coords,
@@ -225,7 +240,10 @@ def draw_matrices(matrices, scale, with_bounding_box):
batch.draw(smooth_color_shader)
if with_bounding_box:
- draw_bounding_boxes(matrices, scale, COLOR_BOUNDING_BOX)
+ if selected:
+ draw_bounding_boxes(selected, scale, COLOR_BOUNDING_BOX)
+ if active:
+ draw_bounding_boxes(active, scale, COLOR_BOUNDING_BOX_ACTIVE)
def draw_bounding_boxes(matrices, scale, color):