1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/mesh/editmesh_extrude_spin_gizmo.c
* \ingroup edmesh
*/
#include "BLI_math.h"
#include "BKE_context.h"
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
#include "WM_message.h"
#include "ED_gizmo_utils.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "UI_resources.h"
#include "MEM_guardedalloc.h"
#include "mesh_intern.h" /* own include */
#include "ED_transform.h"
#include "ED_gizmo_library.h"
#include "ED_undo.h"
/* -------------------------------------------------------------------- */
/** \name Spin Tool Gizmo
* \{ */
typedef struct GizmoGroupData_SpinInit {
struct {
wmGizmo *xyz_view[4];
} gizmos;
/* Only for view orientation. */
struct {
float viewinv_m3[3][3];
} prev;
/* We could store more vars here! */
struct {
wmOperatorType *ot_spin;
} data;
} GizmoGroupData_SpinInit;
static void gizmo_mesh_spin_init_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
{
/* alpha values for normal/highlighted states */
const float alpha = 0.6f;
const float alpha_hi = 1.0f;
GizmoGroupData_SpinInit *ggd = MEM_callocN(sizeof(*ggd), __func__);
gzgroup->customdata = ggd;
const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true);
for (int i = 0; i < ARRAY_SIZE(ggd->gizmos.xyz_view); i++) {
wmGizmo *gz = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL);
UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color);
WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_VALUE, true);
ggd->gizmos.xyz_view[i] = gz;
}
for (int i = 0; i < 3; i++) {
wmGizmo *gz = ggd->gizmos.xyz_view[i];
RNA_enum_set(gz->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_CLIP);
WM_gizmo_set_line_width(gz, 3.0f);
float color[4];
UI_GetThemeColor3fv(TH_AXIS_X + i, color);
color[3] = alpha;
WM_gizmo_set_color(gz, color);
color[3] = alpha_hi;
WM_gizmo_set_color_highlight(gz, color);
}
{
wmGizmo *gz = ggd->gizmos.xyz_view[3];
WM_gizmo_set_line_width(gz, 2.0f);
float color[4];
copy_v3_fl(color, 1.0f);
color[3] = alpha;
WM_gizmo_set_color(gz, color);
color[3] = alpha_hi;
WM_gizmo_set_color_highlight(gz, color);
}
WM_gizmo_set_scale(ggd->gizmos.xyz_view[3], 1.2f);
ggd->data.ot_spin = WM_operatortype_find("MESH_OT_spin", true);
}
static void gizmo_mesh_spin_init_refresh(const bContext *C, wmGizmoGroup *gzgroup);
static void gizmo_mesh_spin_init_refresh_axis_orientation(
wmGizmoGroup *gzgroup,
int axis_index, const float axis_vec[3])
{
GizmoGroupData_SpinInit *ggd = gzgroup->customdata;
wmGizmo *gz = ggd->gizmos.xyz_view[axis_index];
WM_gizmo_set_matrix_rotation_from_z_axis(gz, axis_vec);
PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ggd->data.ot_spin, NULL);
RNA_float_set_array(ptr, "axis", axis_vec);
}
static void gizmo_mesh_spin_init_draw_prepare(
const bContext *C, wmGizmoGroup *gzgroup)
{
GizmoGroupData_SpinInit *ggd = gzgroup->customdata;
RegionView3D *rv3d = CTX_wm_region_view3d(C);
float viewinv_m3[3][3];
copy_m3_m4(viewinv_m3, rv3d->viewinv);
/* Avoid slowdown on view adjustments. */
if ((rv3d->rflag & RV3D_NAVIGATING) == 0) {
Scene *scene = CTX_data_scene(C);
switch (scene->orientation_type) {
case V3D_MANIP_VIEW:
{
if (!equals_m3m3(viewinv_m3, ggd->prev.viewinv_m3)) {
/* Take care calling refresh from draw_prepare,
* this should be OK because it's only adjusting the cage orientation. */
gizmo_mesh_spin_init_refresh(C, gzgroup);
}
break;
}
}
}
/* Refresh handled above when using view orientation. */
if (!equals_m3m3(viewinv_m3, ggd->prev.viewinv_m3)) {
gizmo_mesh_spin_init_refresh_axis_orientation(gzgroup, 3, rv3d->viewinv[2]);
copy_m3_m4(ggd->prev.viewinv_m3, rv3d->viewinv);
}
}
static void gizmo_mesh_spin_init_refresh(const bContext *C, wmGizmoGroup *gzgroup)
{
GizmoGroupData_SpinInit *ggd = gzgroup->customdata;
RegionView3D *rv3d = ED_view3d_context_rv3d((bContext *)C);
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
const View3DCursor *cursor = ED_view3d_cursor3d_get(scene, v3d);
for (int i = 0; i < ARRAY_SIZE(ggd->gizmos.xyz_view); i++) {
wmGizmo *gz = ggd->gizmos.xyz_view[i];
WM_gizmo_set_matrix_location(gz, cursor->location);
}
}
float mat[3][3];
ED_transform_calc_orientation_from_type(C, mat);
for (int i = 0; i < 3; i++) {
gizmo_mesh_spin_init_refresh_axis_orientation(gzgroup, i, mat[i]);
}
{
gizmo_mesh_spin_init_refresh_axis_orientation(gzgroup, 3, rv3d->viewinv[2]);
}
/* Needed to test view orientation changes. */
copy_m3_m4(ggd->prev.viewinv_m3, rv3d->viewinv);
}
static void gizmo_mesh_spin_init_message_subscribe(
const bContext *C, wmGizmoGroup *gzgroup, struct wmMsgBus *mbus)
{
Scene *scene = CTX_data_scene(C);
ARegion *ar = CTX_wm_region(C);
/* Subscribe to view properties */
wmMsgSubscribeValue msg_sub_value_gz_tag_refresh = {
.owner = ar,
.user_data = gzgroup->parent_gzmap,
.notify = WM_gizmo_do_msg_notify_tag_refresh,
};
PointerRNA scene_ptr;
RNA_id_pointer_create(&scene->id, &scene_ptr);
{
extern PropertyRNA rna_Scene_transform_orientation;
extern PropertyRNA rna_Scene_cursor_location;
const PropertyRNA *props[] = {
&rna_Scene_transform_orientation,
&rna_Scene_cursor_location,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
}
}
}
void MESH_GGT_spin(struct wmGizmoGroupType *gzgt)
{
gzgt->name = "Mesh Spin Init";
gzgt->idname = "MESH_GGT_spin";
gzgt->flag = WM_GIZMOGROUPTYPE_3D;
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
gzgt->setup = gizmo_mesh_spin_init_setup;
gzgt->refresh = gizmo_mesh_spin_init_refresh;
gzgt->message_subscribe = gizmo_mesh_spin_init_message_subscribe;
gzgt->draw_prepare = gizmo_mesh_spin_init_draw_prepare;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Spin Redo Gizmo
* \{ */
/**
* Don't show these for now, because they overlay the tools #MESH_GGT_spin_redo gizmos.
* this means we cant rotate the currently running gizmo.
*/
// #define USE_EXTRA_CONTROLS
typedef struct GizmoGroupData_SpinRedo {
/* Arrow to change plane depth. */
struct wmGizmo *translate_z;
/* Translate XYZ */
struct wmGizmo *translate_c;
/* For grabbing the gizmo and moving freely. */
struct wmGizmo *rotate_c;
/* Spin angle */
struct wmGizmo *angle_z;
/* We could store more vars here! */
struct {
bContext *context;
wmOperatorType *ot;
wmOperator *op;
PropertyRNA *prop_axis_co;
PropertyRNA *prop_axis_no;
PropertyRNA *prop_angle;
float rotate_axis[3];
float rotate_up[3];
} data;
} GizmoGroupData_SpinRedo;
/**
* XXX. calling redo from property updates is not great.
* This is needed because changing the RNA doesn't cause a redo
* and we're not using operator UI which does just this.
*/
static void gizmo_spin_exec(GizmoGroupData_SpinRedo *ggd)
{
wmOperator *op = ggd->data.op;
if (op == WM_operator_last_redo((bContext *)ggd->data.context)) {
ED_undo_operator_repeat((bContext *)ggd->data.context, op);
}
}
static void gizmo_mesh_spin_redo_update_from_op(GizmoGroupData_SpinRedo *ggd)
{
wmOperator *op = ggd->data.op;
float plane_co[3], plane_no[3];
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, plane_co);
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
WM_gizmo_set_matrix_location(ggd->translate_z, plane_co);
WM_gizmo_set_matrix_location(ggd->rotate_c, plane_co);
WM_gizmo_set_matrix_location(ggd->angle_z, plane_co);
/* translate_c location comes from the property. */
WM_gizmo_set_matrix_rotation_from_z_axis(ggd->translate_z, plane_no);
WM_gizmo_set_matrix_rotation_from_z_axis(ggd->angle_z, plane_no);
WM_gizmo_set_scale(ggd->translate_c, 0.2);
WM_gizmo_set_scale(ggd->angle_z, 1.5f);
WM_gizmo_set_line_width(ggd->angle_z, 2.0f);
RegionView3D *rv3d = ED_view3d_context_rv3d(ggd->data.context);
if (rv3d) {
normalize_v3_v3(ggd->data.rotate_axis, rv3d->viewinv[2]);
normalize_v3_v3(ggd->data.rotate_up, rv3d->viewinv[1]);
/* ensure its orthogonal */
project_plane_normalized_v3_v3v3(ggd->data.rotate_up, ggd->data.rotate_up, ggd->data.rotate_axis);
normalize_v3(ggd->data.rotate_up);
WM_gizmo_set_matrix_rotation_from_z_axis(ggd->translate_c, plane_no);
WM_gizmo_set_matrix_rotation_from_yz_axis(ggd->rotate_c, plane_no, ggd->data.rotate_axis);
/* show the axis instead of mouse cursor */
RNA_enum_set(ggd->rotate_c->ptr, "draw_options",
ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR |
ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y);
}
}
/* depth callbacks */
static void gizmo_spin_prop_depth_get(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
float *value = value_p;
BLI_assert(gz_prop->type->array_length == 1);
UNUSED_VARS_NDEBUG(gz_prop);
float plane_co[3], plane_no[3];
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, plane_co);
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
value[0] = dot_v3v3(plane_no, plane_co) - dot_v3v3(plane_no, gz->matrix_basis[3]);
}
static void gizmo_spin_prop_depth_set(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
const void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
const float *value = value_p;
BLI_assert(gz_prop->type->array_length == 1);
UNUSED_VARS_NDEBUG(gz_prop);
float plane_co[3], plane[4];
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, plane_co);
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane);
normalize_v3(plane);
plane[3] = -value[0] - dot_v3v3(plane, gz->matrix_basis[3]);
/* Keep our location, may be offset simply to be inside the viewport. */
closest_to_plane_normalized_v3(plane_co, plane, plane_co);
RNA_property_float_set_array(op->ptr, ggd->data.prop_axis_co, plane_co);
gizmo_spin_exec(ggd);
}
/* translate callbacks */
static void gizmo_spin_prop_translate_get(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
float *value = value_p;
BLI_assert(gz_prop->type->array_length == 3);
UNUSED_VARS_NDEBUG(gz_prop);
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, value);
}
static void gizmo_spin_prop_translate_set(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
const void *value)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
BLI_assert(gz_prop->type->array_length == 3);
UNUSED_VARS_NDEBUG(gz_prop);
RNA_property_float_set_array(op->ptr, ggd->data.prop_axis_co, value);
gizmo_spin_exec(ggd);
}
/* angle callbacks */
static void gizmo_spin_prop_axis_angle_get(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
float *value = value_p;
BLI_assert(gz_prop->type->array_length == 1);
UNUSED_VARS_NDEBUG(gz_prop);
float plane_no[4];
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
normalize_v3(plane_no);
float plane_no_proj[3];
project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, ggd->data.rotate_axis);
if (!is_zero_v3(plane_no_proj)) {
const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, ggd->data.rotate_up, ggd->data.rotate_axis);
value[0] = angle;
}
else {
value[0] = 0.0f;
}
}
static void gizmo_spin_prop_axis_angle_set(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
const void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
const float *value = value_p;
BLI_assert(gz_prop->type->array_length == 1);
UNUSED_VARS_NDEBUG(gz_prop);
float plane_no[4];
RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
normalize_v3(plane_no);
float plane_no_proj[3];
project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, ggd->data.rotate_axis);
if (!is_zero_v3(plane_no_proj)) {
const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, ggd->data.rotate_up, ggd->data.rotate_axis);
const float angle_delta = angle - angle_compat_rad(value[0], angle);
if (angle_delta != 0.0f) {
float mat[3][3];
axis_angle_normalized_to_mat3(mat, ggd->data.rotate_axis, angle_delta);
mul_m3_v3(mat, plane_no);
/* re-normalize - seems acceptable */
RNA_property_float_set_array(op->ptr, ggd->data.prop_axis_no, plane_no);
gizmo_spin_exec(ggd);
}
}
}
/* angle callbacks */
static void gizmo_spin_prop_angle_get(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
float *value = value_p;
BLI_assert(gz_prop->type->array_length == 1);
UNUSED_VARS_NDEBUG(gz_prop);
value[0] = RNA_property_float_get(op->ptr, ggd->data.prop_angle);
}
static void gizmo_spin_prop_angle_set(
const wmGizmo *gz, wmGizmoProperty *gz_prop,
const void *value_p)
{
GizmoGroupData_SpinRedo *ggd = gz->parent_gzgroup->customdata;
wmOperator *op = ggd->data.op;
BLI_assert(gz_prop->type->array_length == 1);
UNUSED_VARS_NDEBUG(gz_prop);
const float *value = value_p;
RNA_property_float_set(op->ptr, ggd->data.prop_angle, value[0]);
gizmo_spin_exec(ggd);
}
static bool gizmo_mesh_spin_redo_poll(const bContext *C, wmGizmoGroupType *gzgt)
{
return ED_gizmo_poll_or_unlink_delayed_from_operator(C, gzgt, "MESH_OT_spin");
}
static void gizmo_mesh_spin_redo_modal_from_setup(
const bContext *C, wmGizmoGroup *gzgroup)
{
/* Start off dragging. */
GizmoGroupData_SpinRedo *ggd = gzgroup->customdata;
wmWindow *win = CTX_wm_window(C);
wmGizmo *gz = ggd->angle_z;
wmGizmoMap *gzmap = gzgroup->parent_gzmap;
WM_gizmo_modal_set_from_setup(
gzmap, (bContext *)C, gz, 0, win->eventstate);
}
static void gizmo_mesh_spin_redo_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
wmOperatorType *ot = WM_operatortype_find("MESH_OT_spin", true);
wmOperator *op = WM_operator_last_redo(C);
if ((op == NULL) || (op->type != ot)) {
return;
}
GizmoGroupData_SpinRedo *ggd = MEM_callocN(sizeof(*ggd), __func__);
gzgroup->customdata = ggd;
const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true);
const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true);
ggd->translate_z = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL);
ggd->translate_c = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL);
ggd->rotate_c = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL);
ggd->angle_z = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL);
UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->translate_z->color);
UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->translate_c->color);
UI_GetThemeColor3fv(TH_GIZMO_SECONDARY, ggd->rotate_c->color);
UI_GetThemeColor3fv(TH_AXIS_Z, ggd->angle_z->color);
RNA_enum_set(ggd->translate_z->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_NORMAL);
RNA_enum_set(ggd->translate_c->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_RING_2D);
RNA_boolean_set(ggd->angle_z->ptr, "wrap_angle", false);
RNA_enum_set(ggd->angle_z->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE);
WM_gizmo_set_flag(ggd->translate_c, WM_GIZMO_DRAW_VALUE, true);
WM_gizmo_set_flag(ggd->rotate_c, WM_GIZMO_DRAW_VALUE, true);
WM_gizmo_set_flag(ggd->angle_z, WM_GIZMO_DRAW_VALUE, true);
WM_gizmo_set_scale(ggd->rotate_c, 0.8f);
{
ggd->data.context = (bContext *)C;
ggd->data.ot = ot;
ggd->data.op = op;
ggd->data.prop_axis_co = RNA_struct_type_find_property(ot->srna, "center");
ggd->data.prop_axis_no = RNA_struct_type_find_property(ot->srna, "axis");
ggd->data.prop_angle = RNA_struct_type_find_property(ot->srna, "angle");
}
gizmo_mesh_spin_redo_update_from_op(ggd);
/* Setup property callbacks */
{
WM_gizmo_target_property_def_func(
ggd->translate_z, "offset",
&(const struct wmGizmoPropertyFnParams) {
.value_get_fn = gizmo_spin_prop_depth_get,
.value_set_fn = gizmo_spin_prop_depth_set,
.range_get_fn = NULL,
.user_data = NULL,
});
WM_gizmo_target_property_def_func(
ggd->translate_c, "offset",
&(const struct wmGizmoPropertyFnParams) {
.value_get_fn = gizmo_spin_prop_translate_get,
.value_set_fn = gizmo_spin_prop_translate_set,
.range_get_fn = NULL,
.user_data = NULL,
});
WM_gizmo_target_property_def_func(
ggd->rotate_c, "offset",
&(const struct wmGizmoPropertyFnParams) {
.value_get_fn = gizmo_spin_prop_axis_angle_get,
.value_set_fn = gizmo_spin_prop_axis_angle_set,
.range_get_fn = NULL,
.user_data = NULL,
});
WM_gizmo_target_property_def_func(
ggd->angle_z, "offset",
&(const struct wmGizmoPropertyFnParams) {
.value_get_fn = gizmo_spin_prop_angle_get,
.value_set_fn = gizmo_spin_prop_angle_set,
.range_get_fn = NULL,
.user_data = NULL,
});
}
#ifndef USE_EXTRA_CONTROLS
/* Disable for now. */
WM_gizmo_set_flag(ggd->translate_z, WM_GIZMO_HIDDEN, true);
WM_gizmo_set_flag(ggd->translate_c, WM_GIZMO_HIDDEN, true);
WM_gizmo_set_flag(ggd->rotate_c, WM_GIZMO_HIDDEN, true);
#endif
/* Become modal as soon as it's started. */
gizmo_mesh_spin_redo_modal_from_setup(C, gzgroup);
}
static void gizmo_mesh_spin_redo_draw_prepare(
const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
{
GizmoGroupData_SpinRedo *ggd = gzgroup->customdata;
if (ggd->data.op->next) {
ggd->data.op = WM_operator_last_redo((bContext *)ggd->data.context);
}
gizmo_mesh_spin_redo_update_from_op(ggd);
}
void MESH_GGT_spin_redo(struct wmGizmoGroupType *gzgt)
{
gzgt->name = "Mesh Spin Redo";
gzgt->idname = "MESH_GGT_spin_redo";
gzgt->flag = WM_GIZMOGROUPTYPE_3D;
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
gzgt->poll = gizmo_mesh_spin_redo_poll;
gzgt->setup = gizmo_mesh_spin_redo_setup;
gzgt->draw_prepare = gizmo_mesh_spin_redo_draw_prepare;
}
/** \} */
|