Blender V4.3
transform_gizmo_3d_shear.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13#include "BLI_math_matrix.h"
14#include "BLI_math_vector.h"
15
16#include "BKE_context.hh"
17#include "BKE_scene.hh"
18
19#include "ED_gizmo_library.hh"
20#include "ED_gizmo_utils.hh"
21#include "ED_screen.hh"
22#include "WM_api.hh"
23
24#include "UI_resources.hh"
25
26#include "RNA_access.hh"
27
28/* Local module include. */
29#include "transform.hh"
30#include "transform_gizmo.hh"
31
32/* -------------------------------------------------------------------- */
37 wmGizmo *gizmo[3][2];
40
41 /* Only for view orientation. */
42 struct {
43 float viewinv_m3[3][3];
45};
46
48{
50 return false;
51 }
52 View3D *v3d = CTX_wm_view3d(C);
54 return false;
55 }
56 return true;
57}
58
59static void WIDGETGROUP_xform_shear_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
60{
61 XFormShearWidgetGroup *xgzgroup = static_cast<XFormShearWidgetGroup *>(
62 MEM_mallocN(sizeof(XFormShearWidgetGroup), __func__));
63 const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
64 wmOperatorType *ot_shear = WM_operatortype_find("TRANSFORM_OT_shear", true);
65
66 float axis_color[3][3];
67 for (int i = 0; i < 3; i++) {
68 UI_GetThemeColor3fv(TH_AXIS_X + i, axis_color[i]);
69 }
70
71 for (int i = 0; i < 3; i++) {
72 for (int j = 0; j < 2; j++) {
73 wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr);
74 RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
75 const int i_ortho_a = (i + j + 1) % 3;
76 const int i_ortho_b = (i + (1 - j) + 1) % 3;
77 interp_v3_v3v3(gz->color, axis_color[i_ortho_a], axis_color[i_ortho_b], 0.75f);
78 gz->color[3] = 0.5f;
79 PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, nullptr);
80 RNA_boolean_set(ptr, "release_confirm", true);
81 xgzgroup->gizmo[i][j] = gz;
82 }
83 }
84
85 for (int i = 0; i < 4; i++) {
86 wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr);
87 RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
88 RNA_enum_set(gz->ptr, "draw_options", 0); /* No stem. */
89 copy_v3_fl(gz->color, 1.0f);
90 gz->color[3] = 0.5f;
92 PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, nullptr);
93 RNA_boolean_set(ptr, "release_confirm", true);
94 xgzgroup->gizmo_view[i] = gz;
95
96 /* Unlike the other gizmos, this never changes so can be set on setup. */
98 RNA_enum_set(&gzop->ptr, "orient_type", V3D_ORIENT_VIEW);
99
100 RNA_enum_set(&gzop->ptr, "orient_axis", 2);
101 RNA_enum_set(&gzop->ptr, "orient_axis_ortho", ((i % 2) ? 0 : 1));
102 }
103
104 gzgroup->customdata = xgzgroup;
105}
106
108{
109 Scene *scene = CTX_data_scene(C);
110 ARegion *region = CTX_wm_region(C);
111 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
112
113 XFormShearWidgetGroup *xgzgroup = static_cast<XFormShearWidgetGroup *>(gzgroup->customdata);
114 TransformBounds tbounds;
115
116 /* Needed to test view orientation changes. */
117 copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv);
118
120 scene, SCE_ORIENT_ROTATE);
121 const int orient_index = BKE_scene_orientation_slot_get_index(orient_slot);
122
123 TransformCalcParams calc_params{};
124 calc_params.use_local_axis = false;
125 calc_params.orientation_index = orient_index + 1;
126 if (ED_transform_calc_gizmo_stats(C, &calc_params, &tbounds, rv3d) == 0) {
127 for (int i = 0; i < 3; i++) {
128 for (int j = 0; j < 2; j++) {
129 wmGizmo *gz = xgzgroup->gizmo[i][j];
131 }
132 }
133
134 for (int i = 0; i < 4; i++) {
135 wmGizmo *gz = xgzgroup->gizmo_view[i];
137 }
138 }
139 else {
140 gizmo_prepare_mat(C, rv3d, &tbounds);
141 for (int i = 0; i < 3; i++) {
142 for (int j = 0; j < 2; j++) {
143 wmGizmo *gz = xgzgroup->gizmo[i][j];
146
148 const int i_ortho_a = (i + j + 1) % 3;
149 const int i_ortho_b = (i + (1 - j) + 1) % 3;
150 WM_gizmo_set_matrix_rotation_from_yz_axis(gz, rv3d->twmat[i_ortho_a], rv3d->twmat[i]);
152
153 RNA_float_set_array(&gzop->ptr, "orient_matrix", &tbounds.axis[0][0]);
154 RNA_enum_set(&gzop->ptr, "orient_type", orient_slot->type);
155
156 RNA_enum_set(&gzop->ptr, "orient_axis", i_ortho_b);
157 RNA_enum_set(&gzop->ptr, "orient_axis_ortho", i_ortho_a);
158
159 mul_v3_fl(gz->matrix_basis[0], 0.5f);
160 mul_v3_fl(gz->matrix_basis[1], 6.0f);
161 }
162 }
163
164 for (int i = 0; i < 4; i++) {
165 wmGizmo *gz = xgzgroup->gizmo_view[i];
167 }
168 }
169}
170
172 wmGizmoGroup *gzgroup,
173 wmMsgBus *mbus)
174{
175 Scene *scene = CTX_data_scene(C);
176 bScreen *screen = CTX_wm_screen(C);
177 ScrArea *area = CTX_wm_area(C);
178 ARegion *region = CTX_wm_region(C);
180 gzgroup, mbus, scene, screen, area, region, VIEW3D_GGT_xform_shear);
181}
182
184{
185 XFormShearWidgetGroup *xgzgroup = static_cast<XFormShearWidgetGroup *>(gzgroup->customdata);
187 {
188 Scene *scene = CTX_data_scene(C);
189 /* Shear is like rotate, use the rotate setting. */
191 scene, SCE_ORIENT_ROTATE);
192 switch (orient_slot->type) {
193 case V3D_ORIENT_VIEW: {
194 float viewinv_m3[3][3];
195 copy_m3_m4(viewinv_m3, rv3d->viewinv);
196 if (!equals_m3m3(viewinv_m3, xgzgroup->prev.viewinv_m3)) {
197 /* Take care calling refresh from draw_prepare,
198 * this should be OK because it's only adjusting the cage orientation. */
200 }
201 break;
202 }
203 }
204 }
205
206 for (int i = 0; i < 4; i++) {
207 const float outer_thin = 0.3f;
208 const float outer_offset = 1.0f / 0.3f;
209 wmGizmo *gz = xgzgroup->gizmo_view[i];
211 gz, rv3d->viewinv[(i + 1) % 2], rv3d->viewinv[i % 2]);
212 if (i >= 2) {
213 negate_v3(gz->matrix_basis[1]);
214 negate_v3(gz->matrix_basis[2]);
215 }
216
217 /* No need for depth with view aligned gizmos. */
218 mul_v3_fl(gz->matrix_basis[0], 0.0f);
219 mul_v3_fl(gz->matrix_basis[1], 20.0f + ((1.0f / outer_thin) * 1.8f));
220 mul_v3_fl(gz->matrix_basis[2], outer_thin);
222 gz->matrix_offset[3][2] = outer_offset;
223 }
224
225 /* Basic ordering for drawing only. */
226 {
227 LISTBASE_FOREACH (wmGizmo *, gz, &gzgroup->gizmos) {
228 /* Since we have two pairs of each axis,
229 * bias the values so gizmos that are orthogonal to the view get priority.
230 * This means we never default to shearing along
231 * the view axis in the case of an overlap. */
232 float axis_order[3], axis_bias[3];
233 copy_v3_v3(axis_order, gz->matrix_basis[2]);
234 copy_v3_v3(axis_bias, gz->matrix_basis[1]);
235 if (dot_v3v3(axis_bias, rv3d->viewinv[2]) < 0.0f) {
236 negate_v3(axis_bias);
237 }
238 madd_v3_v3fl(axis_order, axis_bias, 0.01f);
239 gz->temp.f = dot_v3v3(rv3d->viewinv[2], axis_order);
240 }
242 }
243}
244
263
bScreen * CTX_wm_screen(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
TransformOrientationSlot * BKE_scene_orientation_slot_get(Scene *scene, int slot_index)
Definition scene.cc:2347
TransformOrientationSlot * BKE_scene_orientation_slot_get_from_flag(Scene *scene, int flag)
Definition scene.cc:2355
int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_slot)
Definition scene.cc:2379
#define LISTBASE_FOREACH(type, var, list)
void void BLI_listbase_sort(struct ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool equals_m3m3(const float mat1[3][3], const float mat2[3][3])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
Definition math_vector.c:36
MINLINE void negate_v3(float r[3])
MINLINE void copy_v3_fl(float r[3], float f)
@ SCE_ORIENT_ROTATE
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
@ V3D_GIZMO_HIDE_TOOL
@ V3D_GIZMO_HIDE
@ V3D_ORIENT_VIEW
@ ED_GIZMO_ARROW_STYLE_BOX
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const bContext *C, wmGizmoGroupType *gzgt)
int ED_transform_calc_gizmo_stats(const bContext *C, const TransformCalcParams *params, TransformBounds *tbounds, RegionView3D *rv3d)
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_AXIS_X
@ WM_GIZMO_HIDDEN
@ WM_GIZMO_MOVE_CURSOR
@ WM_GIZMO_DRAW_OFFSET_SCALE
@ WM_GIZMOGROUPTYPE_DRAW_MODAL_EXCLUDE
@ WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP
@ WM_GIZMOGROUPTYPE_DELAY_REFRESH_FOR_TWEAK
@ WM_GIZMOGROUPTYPE_3D
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
float twmat[4][4]
float viewinv[4][4]
float axis[3][3]
struct XFormShearWidgetGroup::@580 prev
wmGizmoGroupFnSetupKeymap setup_keymap
wmGizmoGroupFnMsgBusSubscribe message_subscribe
wmGizmoGroupFnRefresh refresh
wmGizmoGroupFnInit setup
const char * idname
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupFnPoll poll
wmGizmoGroupFnDrawPrepare draw_prepare
float matrix_basis[4][4]
float matrix_offset[4][4]
float color[4]
PointerRNA * ptr
void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, wmMsgBus *mbus, Scene *scene, bScreen *screen, ScrArea *area, ARegion *region, void(*type_fn)(wmGizmoGroupType *))
void gizmo_prepare_mat(const bContext *C, RegionView3D *rv3d, const TransformBounds *tbounds)
void VIEW3D_GGT_xform_shear(wmGizmoGroupType *gzgt)
static void WIDGETGROUP_xform_shear_setup(const bContext *, wmGizmoGroup *gzgroup)
static void WIDGETGROUP_xform_shear_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
static void WIDGETGROUP_xform_shear_message_subscribe(const bContext *C, wmGizmoGroup *gzgroup, wmMsgBus *mbus)
static bool WIDGETGROUP_xform_shear_poll(const bContext *C, wmGizmoGroupType *gzgt)
static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzgroup)
PointerRNA * ptr
Definition wm_files.cc:4126
wmGizmoOpElem * WM_gizmo_operator_get(wmGizmo *gz, int part_index)
Definition wm_gizmo.cc:195
void WM_gizmo_set_matrix_rotation_from_yz_axis(wmGizmo *gz, const float y_axis[3], const float z_axis[3])
Definition wm_gizmo.cc:277
wmGizmo * WM_gizmo_new_ptr(const wmGizmoType *gzt, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:81
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition wm_gizmo.cc:283
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:303
PointerRNA * WM_gizmo_operator_set(wmGizmo *gz, int part_index, wmOperatorType *ot, IDProperty *properties)
Definition wm_gizmo.cc:203
int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_maybe_drag(const wmGizmoGroupType *, wmKeyConfig *kc)
const wmGizmoType * WM_gizmotype_find(const char *idname, bool quiet)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)