Blender  V3.3
gizmo_library_presets.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
11 #include "BLI_math.h"
12 
13 #include "DNA_object_types.h"
14 
15 #include "BKE_context.h"
16 
17 #include "GPU_matrix.h"
18 #include "GPU_select.h"
19 
20 #include "DEG_depsgraph.h"
21 
22 #include "WM_types.h"
23 
24 #include "ED_view3d.h"
25 
26 /* own includes */
27 #include "ED_gizmo_library.h" /* own include */
28 #include "gizmo_library_intern.h" /* own include */
29 
30 /* TODO: this is to be used by RNA. might move to ED_gizmo_library. */
31 
35 static void single_axis_convert(int src_axis,
36  const float src_mat[4][4],
37  int dst_axis,
38  float dst_mat[4][4])
39 {
40  copy_m4_m4(dst_mat, src_mat);
41  if (src_axis == dst_axis) {
42  return;
43  }
44 
45  float rotmat[3][3];
46  mat3_from_axis_conversion_single(src_axis, dst_axis, rotmat);
47  transpose_m3(rotmat);
48  mul_m4_m4m3(dst_mat, src_mat, rotmat);
49 }
50 
54 static void ed_gizmo_draw_preset_geometry(const struct wmGizmo *gz,
55  const float mat[4][4],
56  int select_id,
57  const GizmoGeomInfo *info)
58 {
59  const bool is_select = (select_id != -1);
60  const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
61 
62  float color[4];
63  gizmo_color_get(gz, is_highlight, color);
64 
65  if (is_select) {
66  GPU_select_load_id(select_id);
67  }
68 
70  GPU_matrix_mul(mat);
71  wm_gizmo_geometryinfo_draw(info, is_select, color);
73 
74  if (is_select) {
76  }
77 }
78 
79 void ED_gizmo_draw_preset_box(const struct wmGizmo *gz, float mat[4][4], int select_id)
80 {
82 }
83 
84 void ED_gizmo_draw_preset_arrow(const struct wmGizmo *gz, float mat[4][4], int axis, int select_id)
85 {
86  float mat_rotate[4][4];
87  single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
88  ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_arrow);
89 }
90 
91 void ED_gizmo_draw_preset_circle(const struct wmGizmo *gz,
92  float mat[4][4],
93  int axis,
94  int select_id)
95 {
96  float mat_rotate[4][4];
97  single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
98  ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_dial);
99 }
100 
102  const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id)
103 {
104  /* Dependency graph is supposed to be evaluated prior to draw. */
106  const bool is_select = (select_id != -1);
107  const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
108 
109  float color[4];
110  gizmo_color_get(gz, is_highlight, color);
111 
112  if (is_select) {
113  GPU_select_load_id(select_id);
114  }
115 
116  GPU_matrix_push();
117  GPU_matrix_mul(ob->obmat);
119  GPU_matrix_pop();
120 
121  if (is_select) {
122  GPU_select_load_id(-1);
123  }
124 }
struct Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
Definition: context.c:1519
void mul_m4_m4m3(float R[4][4], const float A[4][4], const float B[3][3])
Definition: math_matrix.c:434
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
void transpose_m3(float R[3][3])
Definition: math_matrix.c:1332
bool mat3_from_axis_conversion_single(int src_axis, int dst_axis, float r_mat[3][3])
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
Object is a sort of wrapper for general info.
@ OB_POSZ
void ED_draw_object_facemap(struct Depsgraph *depsgraph, struct Object *ob, const float col[4], int facemap)
Definition: drawobject.c:44
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:126
#define GPU_matrix_mul(x)
Definition: GPU_matrix.h:224
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:119
bool GPU_select_load_id(unsigned int id)
Definition: gpu_select.c:117
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
const int facemap[6][4]
Definition: Projections.cpp:43
#define C
Definition: RandGen.cpp:25
@ WM_GIZMO_STATE_HIGHLIGHT
const Depsgraph * depsgraph
GizmoGeomInfo wm_gizmo_geom_data_arrow
GizmoGeomInfo wm_gizmo_geom_data_cube
GizmoGeomInfo wm_gizmo_geom_data_dial
void wm_gizmo_geometryinfo_draw(const GizmoGeomInfo *info, const bool UNUSED(select), const float color[4])
void gizmo_color_get(const struct wmGizmo *gz, bool highlight, float r_color[4])
void ED_gizmo_draw_preset_circle(const struct wmGizmo *gz, float mat[4][4], int axis, int select_id)
void ED_gizmo_draw_preset_arrow(const struct wmGizmo *gz, float mat[4][4], int axis, int select_id)
static void ed_gizmo_draw_preset_geometry(const struct wmGizmo *gz, const float mat[4][4], int select_id, const GizmoGeomInfo *info)
void ED_gizmo_draw_preset_box(const struct wmGizmo *gz, float mat[4][4], int select_id)
static void single_axis_convert(int src_axis, const float src_mat[4][4], int dst_axis, float dst_mat[4][4])
void ED_gizmo_draw_preset_facemap(const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id)
float obmat[4][4]
eWM_GizmoFlagState state