Blender V4.5
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
12
13#include "BLI_listbase.h"
14#include "BLI_math_matrix.h"
15#include "BLI_math_vector.h"
16
17#include "BKE_context.hh"
18#include "BKE_scene.hh"
19
20#include "ED_gizmo_library.hh"
21#include "ED_gizmo_utils.hh"
22#include "ED_screen.hh"
23#include "WM_api.hh"
24
25#include "UI_resources.hh"
26
27#include "RNA_access.hh"
28
29/* Local module include. */
30#include "transform.hh"
31#include "transform_gizmo.hh"
32
33namespace blender::ed::transform {
34
35/* -------------------------------------------------------------------- */
38
40 wmGizmo *gizmo[3][2];
43
44 /* Only for view orientation. */
45 struct {
46 float viewinv_m3[3][3];
48};
49
51{
53 return false;
54 }
55 View3D *v3d = CTX_wm_view3d(C);
57 return false;
58 }
59 return true;
60}
61
62static void WIDGETGROUP_xform_shear_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
63{
65 const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
66 wmOperatorType *ot_shear = WM_operatortype_find("TRANSFORM_OT_shear", true);
67
68 float axis_color[3][3];
69 for (int i = 0; i < 3; i++) {
70 UI_GetThemeColor3fv(TH_AXIS_X + i, axis_color[i]);
71 }
72
73 for (int i = 0; i < 3; i++) {
74 for (int j = 0; j < 2; j++) {
75 wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr);
76 RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
77 const int i_ortho_a = (i + j + 1) % 3;
78 const int i_ortho_b = (i + (1 - j) + 1) % 3;
79 interp_v3_v3v3(gz->color, axis_color[i_ortho_a], axis_color[i_ortho_b], 0.75f);
80 gz->color[3] = 0.5f;
81 PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, nullptr);
82 RNA_boolean_set(ptr, "release_confirm", true);
83 xgzgroup->gizmo[i][j] = gz;
84 }
85 }
86
87 for (int i = 0; i < 4; i++) {
88 wmGizmo *gz = WM_gizmo_new_ptr(gzt_arrow, gzgroup, nullptr);
89 RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
90 RNA_enum_set(gz->ptr, "draw_options", 0); /* No stem. */
91 copy_v3_fl(gz->color, 1.0f);
92 gz->color[3] = 0.5f;
94 PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ot_shear, nullptr);
95 RNA_boolean_set(ptr, "release_confirm", true);
96 xgzgroup->gizmo_view[i] = gz;
97
98 /* Unlike the other gizmos, this never changes so can be set on setup. */
100 RNA_enum_set(&gzop->ptr, "orient_type", V3D_ORIENT_VIEW);
101
102 RNA_enum_set(&gzop->ptr, "orient_axis", 2);
103 RNA_enum_set(&gzop->ptr, "orient_axis_ortho", ((i % 2) ? 0 : 1));
104 }
105
106 gzgroup->customdata = xgzgroup;
107}
108
110{
111 Scene *scene = CTX_data_scene(C);
112 ARegion *region = CTX_wm_region(C);
113 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
114
115 XFormShearWidgetGroup *xgzgroup = static_cast<XFormShearWidgetGroup *>(gzgroup->customdata);
116 TransformBounds tbounds;
117
118 /* Needed to test view orientation changes. */
119 copy_m3_m4(xgzgroup->prev.viewinv_m3, rv3d->viewinv);
120
122 scene, SCE_ORIENT_ROTATE);
123 const int orient_index = BKE_scene_orientation_slot_get_index(orient_slot);
124
125 TransformCalcParams calc_params{};
126 calc_params.use_local_axis = false;
127 calc_params.orientation_index = orient_index + 1;
128 if (calc_gizmo_stats(C, &calc_params, &tbounds, rv3d) == 0) {
129 for (int i = 0; i < 3; i++) {
130 for (int j = 0; j < 2; j++) {
131 wmGizmo *gz = xgzgroup->gizmo[i][j];
133 }
134 }
135
136 for (int i = 0; i < 4; i++) {
137 wmGizmo *gz = xgzgroup->gizmo_view[i];
139 }
140 }
141 else {
142 gizmo_prepare_mat(C, rv3d, &tbounds);
143 for (int i = 0; i < 3; i++) {
144 for (int j = 0; j < 2; j++) {
145 wmGizmo *gz = xgzgroup->gizmo[i][j];
148
150 const int i_ortho_a = (i + j + 1) % 3;
151 const int i_ortho_b = (i + (1 - j) + 1) % 3;
152 WM_gizmo_set_matrix_rotation_from_yz_axis(gz, rv3d->twmat[i_ortho_a], rv3d->twmat[i]);
154
155 RNA_float_set_array(&gzop->ptr, "orient_matrix", &tbounds.axis[0][0]);
156 RNA_enum_set(&gzop->ptr, "orient_type", orient_slot->type);
157
158 RNA_enum_set(&gzop->ptr, "orient_axis", i_ortho_b);
159 RNA_enum_set(&gzop->ptr, "orient_axis_ortho", i_ortho_a);
160
161 mul_v3_fl(gz->matrix_basis[0], 0.5f);
162 mul_v3_fl(gz->matrix_basis[1], 6.0f);
163 }
164 }
165
166 for (int i = 0; i < 4; i++) {
167 wmGizmo *gz = xgzgroup->gizmo_view[i];
169 }
170 }
171}
172
174 wmGizmoGroup *gzgroup,
175 wmMsgBus *mbus)
176{
177 Scene *scene = CTX_data_scene(C);
178 bScreen *screen = CTX_wm_screen(C);
179 ScrArea *area = CTX_wm_area(C);
180 ARegion *region = CTX_wm_region(C);
182 gzgroup, mbus, scene, screen, area, region, VIEW3D_GGT_xform_shear);
183}
184
186{
187 XFormShearWidgetGroup *xgzgroup = static_cast<XFormShearWidgetGroup *>(gzgroup->customdata);
189 {
190 Scene *scene = CTX_data_scene(C);
191 /* Shear is like rotate, use the rotate setting. */
193 scene, SCE_ORIENT_ROTATE);
194 switch (orient_slot->type) {
195 case V3D_ORIENT_VIEW: {
196 float viewinv_m3[3][3];
197 copy_m3_m4(viewinv_m3, rv3d->viewinv);
198 if (!equals_m3m3(viewinv_m3, xgzgroup->prev.viewinv_m3)) {
199 /* Take care calling refresh from draw_prepare,
200 * this should be OK because it's only adjusting the cage orientation. */
202 }
203 break;
204 }
205 }
206 }
207
208 for (int i = 0; i < 4; i++) {
209 const float outer_thin = 0.3f;
210 const float outer_offset = 1.0f / 0.3f;
211 wmGizmo *gz = xgzgroup->gizmo_view[i];
213 gz, rv3d->viewinv[(i + 1) % 2], rv3d->viewinv[i % 2]);
214 if (i >= 2) {
215 negate_v3(gz->matrix_basis[1]);
216 negate_v3(gz->matrix_basis[2]);
217 }
218
219 /* No need for depth with view aligned gizmos. */
220 mul_v3_fl(gz->matrix_basis[0], 0.0f);
221 mul_v3_fl(gz->matrix_basis[1], 20.0f + ((1.0f / outer_thin) * 1.8f));
222 mul_v3_fl(gz->matrix_basis[2], outer_thin);
224 gz->matrix_offset[3][2] = outer_offset;
225 }
226
227 /* Basic ordering for drawing only. */
228 {
229 LISTBASE_FOREACH (wmGizmo *, gz, &gzgroup->gizmos) {
230 /* Since we have two pairs of each axis,
231 * bias the values so gizmos that are orthogonal to the view get priority.
232 * This means we never default to shearing along
233 * the view axis in the case of an overlap. */
234 float axis_order[3], axis_bias[3];
235 copy_v3_v3(axis_order, gz->matrix_basis[2]);
236 copy_v3_v3(axis_bias, gz->matrix_basis[1]);
237 if (dot_v3v3(axis_bias, rv3d->viewinv[2]) < 0.0f) {
238 negate_v3(axis_bias);
239 }
240 madd_v3_v3fl(axis_order, axis_bias, 0.01f);
241 gz->temp.f = dot_v3v3(rv3d->viewinv[2], axis_order);
242 }
244 }
245}
246
265
267
268} // namespace blender::ed::transform
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:2397
TransformOrientationSlot * BKE_scene_orientation_slot_get_from_flag(Scene *scene, int flag)
Definition scene.cc:2405
int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_slot)
Definition scene.cc:2429
#define LISTBASE_FOREACH(type, var, list)
void void BLI_listbase_sort(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)
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_ORIENT_VIEW
@ V3D_GIZMO_HIDE_TOOL
@ V3D_GIZMO_HIDE
@ ED_GIZMO_ARROW_STYLE_BOX
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const bContext *C, wmGizmoGroupType *gzgt)
#define C
Definition RandGen.cpp:29
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:128
void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup, wmMsgBus *mbus, Scene *scene, bScreen *screen, ScrArea *area, ARegion *region, void(*type_fn)(wmGizmoGroupType *))
static void WIDGETGROUP_xform_shear_setup(const bContext *, wmGizmoGroup *gzgroup)
void gizmo_prepare_mat(const bContext *C, RegionView3D *rv3d, const TransformBounds *tbounds)
void VIEW3D_GGT_xform_shear(wmGizmoGroupType *gzgt)
static void WIDGETGROUP_xform_shear_refresh(const bContext *C, 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)
int calc_gizmo_stats(const bContext *C, const TransformCalcParams *params, TransformBounds *tbounds, RegionView3D *rv3d)
static bool WIDGETGROUP_xform_shear_poll(const bContext *C, wmGizmoGroupType *gzgt)
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)
void * regiondata
float twmat[4][4]
float viewinv[4][4]
struct blender::ed::transform::XFormShearWidgetGroup::@232024057326300264072210144262144264151225012330 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
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4226
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:280
wmGizmo * WM_gizmo_new_ptr(const wmGizmoType *gzt, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:85
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition wm_gizmo.cc:286
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:306
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 StringRef idname, bool quiet)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)