Blender  V2.93
gizmo_library_presets.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
25 #include "BLI_math.h"
26 
27 #include "DNA_object_types.h"
28 
29 #include "BKE_context.h"
30 
31 #include "GPU_matrix.h"
32 #include "GPU_select.h"
33 
34 #include "DEG_depsgraph.h"
35 
36 #include "WM_types.h"
37 
38 #include "ED_view3d.h"
39 
40 /* own includes */
41 #include "ED_gizmo_library.h" /* own include */
42 #include "gizmo_library_intern.h" /* own include */
43 
44 /* TODO, this is to be used by RNA. might move to ED_gizmo_library */
45 
49 static void single_axis_convert(int src_axis,
50  const float src_mat[4][4],
51  int dst_axis,
52  float dst_mat[4][4])
53 {
54  copy_m4_m4(dst_mat, src_mat);
55  if (src_axis == dst_axis) {
56  return;
57  }
58 
59  float rotmat[3][3];
60  mat3_from_axis_conversion_single(src_axis, dst_axis, rotmat);
61  transpose_m3(rotmat);
62  mul_m4_m4m3(dst_mat, src_mat, rotmat);
63 }
64 
68 static void ed_gizmo_draw_preset_geometry(const struct wmGizmo *gz,
69  const float mat[4][4],
70  int select_id,
71  const GizmoGeomInfo *info)
72 {
73  const bool is_select = (select_id != -1);
74  const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
75 
76  float color[4];
77  gizmo_color_get(gz, is_highlight, color);
78 
79  if (is_select) {
80  GPU_select_load_id(select_id);
81  }
82 
84  GPU_matrix_mul(mat);
85  wm_gizmo_geometryinfo_draw(info, is_select, color);
87 
88  if (is_select) {
90  }
91 }
92 
93 void ED_gizmo_draw_preset_box(const struct wmGizmo *gz, float mat[4][4], int select_id)
94 {
96 }
97 
98 void ED_gizmo_draw_preset_arrow(const struct wmGizmo *gz, float mat[4][4], int axis, int select_id)
99 {
100  float mat_rotate[4][4];
101  single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
102  ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_arrow);
103 }
104 
105 void ED_gizmo_draw_preset_circle(const struct wmGizmo *gz,
106  float mat[4][4],
107  int axis,
108  int select_id)
109 {
110  float mat_rotate[4][4];
111  single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
112  ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_dial);
113 }
114 
116  const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id)
117 {
118  /* Dependency graph is supposed to be evaluated prior to draw. */
120  const bool is_select = (select_id != -1);
121  const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
122 
123  float color[4];
124  gizmo_color_get(gz, is_highlight, color);
125 
126  if (is_select) {
127  GPU_select_load_id(select_id);
128  }
129 
130  GPU_matrix_push();
131  GPU_matrix_mul(ob->obmat);
133  GPU_matrix_pop();
134 
135  if (is_select) {
136  GPU_select_load_id(-1);
137  }
138 }
struct Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
Definition: context.c:1415
void mul_m4_m4m3(float R[4][4], const float A[4][4], const float B[3][3])
Definition: math_matrix.c:437
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
void transpose_m3(float R[3][3])
Definition: math_matrix.c:1312
bool mat3_from_axis_conversion_single(int src_axis, int dst_axis, float r_mat[3][3])
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
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], const int facemap)
Definition: drawobject.c:110
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:142
#define GPU_matrix_mul(x)
Definition: GPU_matrix.h:223
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:135
bool GPU_select_load_id(unsigned int id)
Definition: gpu_select.c:108
const int facemap[6][4]
Definition: Projections.cpp:57
#define C
Definition: RandGen.cpp:39
@ 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, const 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