-
Notifications
You must be signed in to change notification settings - Fork 27
/
functions_tools.py
1816 lines (1346 loc) · 54.2 KB
/
functions_tools.py
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import bpy
from mathutils import Vector, Euler
from mathutils.geometry import intersect_line_plane
from bpy_extras import view3d_utils
from .functions_modal import *
from .classes_tool import *
def setup_tools(modal):
modal.tools = GEN_Modal_Container()
modal.tools.set_cancel_keys(['Cancel Tool 1', 'Cancel Tool 2'])
modal.tools.set_confirm_keys(['Confirm Tool 1', 'Confirm Tool 2'])
modal.tools.set_pass_through_events(modal.nav_list)
# BASIC TOOL
if True:
tool = modal.tools.add_tool(
inherit_cancel=False, inherit_confirm=False)
tool.set_mouse_function(mouse)
tool.add_cancel_key('Cancel Modal')
tool.set_cancel_function(cancel_modal)
tool.add_confirm_key('Confirm Modal')
tool.set_confirm_function(confirm_modal)
tool.add_keymap_argument('History Undo', hist_undo)
tool.add_keymap_argument('History Redo', hist_redo)
tool.set_always_function(click_hold_release)
# tool.set_pre_pass_through_function(gizmo_pre_navigate)
# tool.set_post_pass_through_function(gizmo_post_navigate)
tool.add_keymap_argument(
'Box Select Start', box_select_start)
tool.add_keymap_argument(
'Circle Select Start', circle_select_start)
tool.add_keymap_argument(
'Lasso Select Start', lasso_select_start)
tool.add_keymap_argument('Toggle Gizmo', toggle_gizmo)
tool.add_keymap_argument('Hide Selected', hide_selected)
tool.add_keymap_argument('Hide Unselected', hide_unselected)
tool.add_keymap_argument('Unhide', unhide)
tool.add_keymap_argument('Reset Gizmo Rotation', reset_gizmo)
tool.add_keymap_argument('Rotate Normals', rotate_start)
tool.add_keymap_argument('Toggle X-Ray', toggle_xray)
tool.add_keymap_argument('Mirror Normals Start', mirror_start)
tool.add_keymap_argument('Smooth Normals', smooth_norms)
tool.add_keymap_argument('Flatten Normals Start', flatten_norms)
tool.add_keymap_argument('Align Normals Start', align_norms)
tool.add_keymap_argument('Copy Active Normal', copy_active)
tool.add_keymap_argument('Paste Stored Normal', paste_stored)
tool.add_keymap_argument(
'Paste Active Normal to Selected', paste_active_to_selected)
tool.add_keymap_argument('Set Normals Outside', set_outside)
tool.add_keymap_argument('Set Normals Inside', set_inside)
tool.add_keymap_argument('Flip Normals', flip_norms)
tool.add_keymap_argument('Reset Vectors', reset_vectors)
tool.add_keymap_argument(
'Average Individual Normals', average_individual)
tool.add_keymap_argument('Average Selected Normals', average_selected)
tool.add_keymap_argument('Set Normals From Faces', normals_from_faces)
#
tool.add_keymap_argument('Select All', select_all)
tool.add_keymap_argument('Deselect All', deselect_all)
tool.add_keymap_argument('Select Linked', select_linked)
tool.add_keymap_argument('Select Hover Linked', select_hover_linked)
tool.add_keymap_argument('Invert Selection', invert_selection)
tool.add_keymap_argument('New Click Selection', new_click_select)
tool.add_keymap_argument('Add Click Selection', add_click_select)
tool.add_keymap_argument('New Loop Selection', new_loop_select)
tool.add_keymap_argument('Add Loop Selection', add_loop_select)
tool.add_keymap_argument(
'New Shortest Path Selection', new_shortest_select)
tool.add_keymap_argument(
'Add Shortest Path Selection', add_shortest_select)
tool.add_keymap_argument(
'Filter Mask From Selected', filter_from_sel)
tool.add_keymap_argument(
'Clear Filter Mask', filter_clear)
modal._basic_tool = tool
modal._current_tool = modal._basic_tool
#
#
#
# SELECTION TOOLS
if True:
# BOX SEL
tool = modal.tools.add_tool(inherit_confirm=False)
tool.set_use_start(True)
tool.add_start_argument('Box Select Start Selection', box_sel_start)
tool.set_mouse_function(box_sel_mouse)
tool.set_cancel_function(box_sel_cancel)
tool.set_confirm_function(box_sel_confirm)
tool.add_confirm_key('Box New Selection')
tool.add_confirm_key('Box Add Selection')
tool.add_confirm_key('Box Remove Selection')
# tool.set_pre_pass_through_function(clear_draw_pre_navigate)
# tool.set_post_pass_through_function(clear_draw_post_navigate)
modal._box_sel_tool = tool
# LASSO SEL
tool = modal.tools.add_tool(inherit_confirm=False)
tool.set_use_start(True)
tool.add_start_argument(
'Lasso Select Start Selection', lasso_sel_start)
tool.set_mouse_function(lasso_sel_mouse)
tool.set_cancel_function(lasso_sel_cancel)
tool.set_confirm_function(lasso_sel_confirm)
tool.add_confirm_key('Lasso New Selection')
tool.add_confirm_key('Lasso Add Selection')
tool.add_confirm_key('Lasso Remove Selection')
# tool.set_pre_pass_through_function(clear_draw_pre_navigate)
# tool.set_post_pass_through_function(clear_draw_post_navigate)
modal._lasso_sel_tool = tool
# CIRCLE SEL
tool = modal.tools.add_tool(inherit_confirm=False)
tool.set_use_start(True)
tool.add_start_argument(
'Circle Select Start Selection', circle_sel_start)
tool.add_keymap_argument('Circle Increase Size 1',
circle_sel_inc, pre_start=True)
tool.add_keymap_argument('Circle Increase Size 2',
circle_sel_inc, pre_start=True)
tool.add_keymap_argument('Circle Decrease Size 1',
circle_sel_dec, pre_start=True)
tool.add_keymap_argument('Circle Decrease Size 2',
circle_sel_dec, pre_start=True)
tool.add_keymap_argument('Circle Resize Mode Start',
circle_sel_start_resize, pre_start=True)
tool.set_mouse_function(circle_sel_mouse)
tool.set_cancel_function(circle_sel_cancel)
tool.set_confirm_function(circle_sel_confirm)
tool.add_confirm_key('Circle End Selection')
tool.add_confirm_key('Circle Add Selection')
tool.add_confirm_key('Circle Remove Selection')
# tool.set_pre_pass_through_function(clear_draw_pre_navigate)
# tool.set_post_pass_through_function(clear_draw_post_navigate)
modal._circle_sel_tool = tool
# CIRCLE SEL RESIZE
tool = modal.tools.add_tool()
tool.set_mouse_function(circle_resize_mouse)
tool.set_cancel_function(circle_resize_cancel)
tool.set_confirm_function(circle_resize_confirm)
tool.add_confirm_key('Circle Resize Confirm')
modal._circle_resize_tool = tool
# NORMAL TOOLS
if True:
# ROTATE NORMALS
tool = modal.tools.add_tool()
tool.set_mouse_function(rotate_norms_mouse)
tool.set_cancel_function(rotate_norms_cancel)
tool.set_confirm_function(rotate_norms_confirm)
tool.add_keymap_argument('Rotate X Axis', rotate_set_x)
tool.add_keymap_argument('Rotate Y Axis', rotate_set_y)
tool.add_keymap_argument('Rotate Z Axis', rotate_set_z)
tool.set_pre_pass_through_function(rotate_pre_navigate)
tool.set_post_pass_through_function(rotate_post_navigate)
modal._rotate_norms_tool = tool
# SPHEREIZE
tool = modal.tools.add_tool(
inherit_confirm=False, inherit_cancel=False)
tool.set_mouse_function(sphereize_mouse)
tool.set_mouse_pass(True)
tool.add_keymap_argument('Target Move Start', sphereize_start_move)
tool.add_keymap_argument('Target Center Reset', sphereize_reset)
tool.add_keymap_argument('Toggle X-Ray', toggle_x_ray)
tool.add_cancel_key('Cancel Tool 1')
modal._sphereize_tool = tool
# SPHEREIZE MOVE
tool = modal.tools.add_tool()
tool.set_mouse_function(sphereize_move_mouse)
tool.set_cancel_function(sphereize_move_cancel)
tool.set_confirm_function(sphereize_move_confirm)
tool.add_keymap_argument('Target Move X Axis', sphereize_move_set_x)
tool.add_keymap_argument('Target Move Y Axis', sphereize_move_set_y)
tool.add_keymap_argument('Target Move Z Axis', sphereize_move_set_z)
tool.add_keymap_argument('Toggle X-Ray', toggle_x_ray)
modal._sphereize_move_tool = tool
# POINT
tool = modal.tools.add_tool(
inherit_confirm=False, inherit_cancel=False)
tool.set_mouse_function(point_mouse)
tool.set_mouse_pass(True)
tool.add_keymap_argument('Target Move Start', point_start_move)
tool.add_keymap_argument('Target Center Reset', point_reset)
tool.add_keymap_argument('Toggle X-Ray', toggle_x_ray)
tool.add_cancel_key('Cancel Tool 1')
modal._point_tool = tool
# POINT MOVE
tool = modal.tools.add_tool()
tool.set_mouse_function(point_move_mouse)
tool.set_cancel_function(point_move_cancel)
tool.set_confirm_function(point_move_confirm)
tool.add_keymap_argument('Target Move X Axis', point_move_set_x)
tool.add_keymap_argument('Target Move Y Axis', point_move_set_y)
tool.add_keymap_argument('Target Move Z Axis', point_move_set_z)
tool.add_keymap_argument('Toggle X-Ray', toggle_x_ray)
modal._point_move_tool = tool
# GIZMO CLICK
tool = modal.tools.add_tool()
tool.set_mouse_function(gizmo_mouse)
tool.set_confirm_function(gizmo_confirm)
tool.set_cancel_function(gizmo_cancel)
tool.add_confirm_key('Confirm Tool 3')
modal._gizmo_tool = tool
# MIRROR
tool = modal.tools.add_tool(inherit_confirm=False)
tool.set_cancel_function(mirror_cancel)
tool.add_keymap_argument('Mirror Normals X', mirror_x)
tool.add_keymap_argument('Mirror Normals Y', mirror_y)
tool.add_keymap_argument('Mirror Normals Z', mirror_z)
modal._mirror_tool = tool
# FLATTEN
tool = modal.tools.add_tool(inherit_confirm=False)
tool.set_cancel_function(flatten_cancel)
tool.add_keymap_argument('Flatten Normals X', flatten_x)
tool.add_keymap_argument('Flatten Normals Y', flatten_y)
tool.add_keymap_argument('Flatten Normals Z', flatten_z)
modal._flatten_tool = tool
# ALIGN
tool = modal.tools.add_tool(inherit_confirm=False)
tool.set_cancel_function(align_cancel)
tool.add_keymap_argument('Align Normals Pos X', align_pos_x)
tool.add_keymap_argument('Align Normals Pos Y', align_pos_y)
tool.add_keymap_argument('Align Normals Pos Z', align_pos_z)
tool.add_keymap_argument('Align Normals Neg X', align_neg_x)
tool.add_keymap_argument('Align Normals Neg Y', align_neg_y)
tool.add_keymap_argument('Align Normals Neg Z', align_neg_z)
modal._align_tool = tool
# UI TOOLS
if True:
tool = modal.tools.add_tool(
inherit_cancel=False, inherit_confirm=False, inherit_pass_thru=False)
tool.add_cancel_key('Cancel Modal')
tool.set_cancel_function(cancel_modal)
tool.add_confirm_key('Confirm Modal')
tool.set_confirm_function(confirm_modal)
tool.add_keymap_argument('Select All', ui_select_all)
tool.add_keymap_argument('Deselect All', ui_deselect_all)
# tool.add_keymap_argument('Invert Selection', ui_invert_selection)
tool.add_keymap_argument('Toggle Cyclic Status', ui_toggle_cyclic)
tool.add_keymap_argument('Reset Point Rotate', ui_reset_rot)
tool.add_keymap_argument('Point Rotate Start', ui_rot_start)
tool.add_keymap_argument('Reset Point Sharpness', ui_reset_sharp)
tool.add_keymap_argument('Point Sharpness Start', ui_sharp_start)
tool.add_keymap_argument('Delete Selected Points', ui_delete_selected)
tool.add_keymap_argument('Toggle Gizmo', toggle_gizmo)
tool.add_keymap_argument('UI Panel Scroll Up 1', ui_scroll_up)
tool.add_keymap_argument('UI Panel Scroll Up 2', ui_scroll_up)
tool.add_keymap_argument('UI Panel Scroll Down 1', ui_scroll_down)
tool.add_keymap_argument('UI Panel Scroll Down 2', ui_scroll_down)
tool.add_keymap_argument('UI Click', ui_click)
tool.set_timer_function(ui_timer)
tool.add_cancel_key('Cancel Modal')
tool.add_keymap_argument('History Undo', hist_undo)
tool.add_keymap_argument('History Redo', hist_redo)
tool.set_mouse_function(ui_tool)
modal._ui_tool = tool
#
tool = modal.tools.add_tool(
inherit_cancel=False, inherit_confirm=False, inherit_pass_thru=False)
tool.add_keymap_argument('Select All', ui_select_all)
tool.add_keymap_argument('Deselect All', ui_deselect_all)
# tool.add_keymap_argument('Invert Selection', ui_invert_selection)
tool.add_keymap_argument('Toggle Cyclic Status', ui_toggle_cyclic)
tool.add_keymap_argument('Reset Point Rotate', ui_reset_rot)
tool.add_keymap_argument('Point Rotate Start', ui_rot_start)
tool.add_keymap_argument('Reset Point Sharpness', ui_reset_sharp)
tool.add_keymap_argument('Point Sharpness Start', ui_sharp_start)
tool.add_keymap_argument('Delete Selected Points', ui_delete_selected)
tool.add_keymap_argument('Toggle Gizmo', toggle_gizmo)
tool.add_keymap_argument('UI Panel Scroll Up 1', ui_scroll_up)
tool.add_keymap_argument('UI Panel Scroll Up 2', ui_scroll_up)
tool.add_keymap_argument('UI Panel Scroll Down 1', ui_scroll_down)
tool.add_keymap_argument('UI Panel Scroll Down 2', ui_scroll_down)
tool.add_keymap_argument('UI Click', ui_click)
tool.set_timer_function(ui_timer)
tool.set_mouse_function(popup_tool)
modal._popup_tool = tool
#
tool = modal.tools.add_tool(
inherit_cancel=False, inherit_confirm=False, inherit_pass_thru=False)
tool.set_always_function(typing_tool)
modal._typing_tool = tool
return
def tool_end(modal):
modal._mouse_init = None
modal._mode_cache.clear()
keymap_refresh(modal)
modal._current_tool = modal._basic_tool
return
def sel_tool_end(modal):
bpy.context.window.cursor_modal_set('DEFAULT')
update_orbit_empty(modal)
end_selection_drawing(modal)
tool_end(modal)
return
#
def ui_tool(modal, context, event, func_data):
ended = ui_mouse(modal, context, event, func_data)
if ended:
if modal._point_panel.visible:
modal._current_tool = modal._point_tool
elif modal._sphere_panel.visible:
modal._current_tool = modal._sphereize_tool
else:
modal._current_tool = modal._basic_tool
return {'RUNNING_MODAL'}
return
def popup_tool(modal, context, event, func_data):
ended = popup_mouse(modal, context, event, func_data)
if ended:
modal._current_tool = modal._basic_tool
return {'RUNNING_MODAL'}
return
def typing_tool(modal, context, event, func_data):
ended = typing_keys(modal, context, event, func_data)
if ended:
if modal._window.popup_mode:
modal._current_tool = modal._popup_tool
else:
modal._current_tool = modal._ui_tool
return {'RUNNING_MODAL'}
return
#
def ui_mouse(modal, context, event, func_data):
if modal.click_hold == False:
hov_status = modal._window.test_hover(modal._mouse_reg_loc)
modal.ui_hover = hov_status is not None
if modal.ui_hover == False:
ui_hover_timer_end(modal)
return True
else:
modal._window.click_down_move(
modal._mouse_reg_loc, event.shift, arguments=[event])
return False
def popup_mouse(modal, context, event, func_data):
if modal.click_hold == False:
hov_status = modal._window.test_hover(modal._mouse_reg_loc)
modal.ui_hover = hov_status is not None
if hov_status == 'CLOSED':
modal._window.set_popup_mode(False)
modal._popup_panel = None
modal._current_tool = modal._ui_tool
if modal.ui_hover == False:
ui_hover_timer_end(modal)
return True
# if event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
# modal.click_hold = False
else:
modal._window.click_down_move(
modal._mouse_reg_loc, event.shift, arguments=[event])
return False
def ui_select_all(modal, context, event, keys, func_data):
modal._window.curve_box_select_points(True)
return
def ui_deselect_all(modal, context, event, keys, func_data):
modal._window.curve_box_select_points(False)
return
def ui_invert_selection(modal, context, event, keys, func_data):
return
def ui_toggle_cyclic(modal, context, event, keys, func_data):
bezier_hover = modal._window.curve_box_toggle_cyclic()
return
def ui_reset_rot(modal, context, event, keys, func_data):
bezier_hover = modal._window.curve_box_clear_rotation(arguments=[
modal, event])
return
def ui_rot_start(modal, context, event, keys, func_data):
bezier_hover, bezier_id, changing, mid_co = modal._window.curve_box_rotate_points(
0.0, arguments=[event])
if changing:
modal._mode_cache.append(np.array([mid_co[0], mid_co[1], 0.0]))
modal._mouse_init = modal._mouse_reg_loc.copy()
modal.rotating = True
modal.active_drawing = True
modal._window.curve_box_store_data(rotations=True)
modal._current_tool = modal._bez_rotate_tool
keymap_rotating(modal)
return
def ui_reset_sharp(modal, context, event, keys, func_data):
bezier_hover = modal._window.curve_box_clear_sharpness(arguments=[
modal, event])
return
def ui_sharp_start(modal, context, event, keys, func_data):
bezier_hover, bezier_id, changing = modal._window.curve_box_sharpen_points(
0.0, arguments=[event])
if changing:
modal._mouse_init = modal._mouse_reg_loc.copy()
modal._window.curve_box_store_data(sharpness=True)
modal._current_tool = modal._bez_sharpness_tool
# keymap_sharpness_changing(modal)
return
def ui_delete_selected(modal, context, event, keys, func_data):
bez_hover = modal._window.curve_box_delete_points(
arguments=[event])
return
def ui_scroll_up(modal, context, event, keys, func_data):
modal._window.scroll_panel(10)
return
def ui_scroll_down(modal, context, event, keys, func_data):
modal._window.scroll_panel(-10)
return
def ui_click(modal, context, event, keys, func_data):
status = {'RUNNING_MODAL'}
if event.value == 'PRESS':
panel_status = modal._window.test_click_down(
modal._mouse_reg_loc, event.shift, arguments=[event])
modal.click_hold = True
if panel_status:
if panel_status[0] == 'GIZMO':
gizmo_click_init(modal, event, panel_status[1])
modal.ui_hover = False
else:
if panel_status[0] == {'CANCELLED'}:
status = panel_status[0]
if panel_status[0] == {'FINISHED'}:
status = panel_status[0]
elif event.value == 'RELEASE':
panel_status = modal._window.test_click_up(
modal._mouse_reg_loc, event.shift, arguments=[event])
modal.click_hold = False
if panel_status:
rco = view3d_utils.location_3d_to_region_2d(
modal.act_reg, modal.act_rv3d, modal._orbit_ob.location)
if rco != None:
modal.gizmo_reposition_offset = [
modal._gizmo_panel.position[0]-rco[0], modal._gizmo_panel.position[1]-rco[1]]
if panel_status[0] == 'NUMBER_BAR_TYPE':
modal._current_tool = modal._typing_tool
if panel_status[0] == {'CANCELLED'}:
status = panel_status[0]
if panel_status[0] == {'FINISHED'}:
status = panel_status[0]
return status
def ui_timer(modal, context, event, func_data):
if event.type != 'TIMER':
modal._hover_stop_time = modal._hover_timer.time_duration
if modal._hover_delay_passed:
modal._window.tooltip_hide()
modal._hover_delay_passed = False
else:
if modal._hover_delay_passed == False and (modal._hover_timer.time_duration-modal._hover_stop_time) > modal._hover_delay:
modal._window.tooltip_show(modal._mouse_reg_loc)
modal._hover_delay_passed = True
return
def ui_hover_timer_start(modal):
if modal._hover_timer is None:
modal._hover_timer = bpy.context.window_manager.event_timer_add(
0.25, window=bpy.context.window)
return
def ui_hover_timer_end(modal):
if modal._hover_timer is not None:
bpy.context.window_manager.event_timer_remove(
modal._hover_timer)
modal._hover_timer = None
return
def click_hold_release(modal, context, event, func_data):
if event.value == 'RELEASE':
modal.click_hold = False
return
def typing_keys(modal, context, event, func_data):
# typing keys
if event.type == 'RET' and event.value == 'PRESS':
modal._window.type_confirm(arguments=[event])
return True
elif event.type == 'NUMPAD_ENTER' and event.value == 'RELEASE':
modal._window.type_confirm(arguments=[event])
return True
elif event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
modal._window.type_confirm(arguments=[event])
return True
elif event.type == 'ESC' and event.value == 'PRESS':
modal._window.type_cancel()
return True
elif event.type == 'RIGHTMOUSE' and event.value == 'PRESS':
modal._window.type_cancel()
return True
elif event.type == 'LEFT_ARROW' and event.value == 'PRESS':
modal._window.type_move_pos(-1)
return False
elif event.type == 'RIGHT_ARROW' and event.value == 'PRESS':
modal._window.type_move_pos(1)
return False
elif event.type == 'BACK_SPACE' and event.value == 'PRESS':
modal._window.type_backspace_key()
return False
elif event.type == 'DEL' and event.value == 'PRESS':
modal._window.type_delete_key()
return False
else:
modal._window.type_add_key(event.ascii)
return False
return
#
#
# BASIC FUNCS
def mouse(modal, context, event, func_data):
if modal.click_hold == False:
hov_status = modal._window.test_hover(modal._mouse_reg_loc)
modal.ui_hover = hov_status is not None
if modal.ui_hover:
ui_hover_timer_start(modal)
modal._current_tool = modal._ui_tool
return {'RUNNING_MODAL'}
# view moved so update gizmo
if modal._use_gizmo and context.region_data.view_matrix != modal.prev_view:
modal._window.update_gizmo_pos(modal._orbit_ob.matrix_world)
relocate_gizmo_panel(modal)
modal.prev_view = context.region_data.view_matrix.copy()
if modal._container.sel_status.any():
gizmo_update_hide(modal, True)
else:
gizmo_update_hide(modal, False)
#
#
#
return
def gizmo_pre_navigate(modal, context, event, func_data):
gizmo_update_hide(modal, False)
modal._window.set_key('Navigation')
return
def gizmo_post_navigate(modal, context, event, func_data):
gizmo_update_hide(modal, True)
return
def toggle_gizmo(modal, context, event, keys, func_data):
modal._use_gizmo = not modal._use_gizmo
modal._gizmo_bool.toggle_bool()
update_orbit_empty(modal)
if modal._container.sel_status.any():
gizmo_update_hide(modal, True)
else:
gizmo_update_hide(modal, False)
modal._window.set_key('Toggle Gizmo')
return
def cancel_modal(modal, context, event, keys, func_data):
finish_modal(modal, True)
return {'CANCELLED'}
def confirm_modal(modal, context, event, keys, func_data):
finish_modal(modal, False)
return {'FINISHED'}
def hist_undo(modal, context, event, keys, func_data):
move_undostack(modal, 1)
modal._window.set_key('Undo')
return
def hist_redo(modal, context, event, keys, func_data):
move_undostack(modal, -1)
modal._window.set_key('Redo')
return
def hide_unselected(modal, context, event, keys, func_data):
if modal._container.sel_status.all() == False:
modal._container.hide_status[~modal._container.sel_status] = True
modal._window.set_key('Hide Unselected')
add_to_undostack(modal, 0)
return
def hide_selected(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
modal._container.hide_status[modal._container.sel_status] = True
modal._container.sel_status[:] = False
modal._container.act_status[:] = False
modal._window.set_key('Hide Selected')
add_to_undostack(modal, 0)
return
def unhide(modal, context, event, keys, func_data):
if modal._container.hide_status.any():
modal._container.sel_status[modal._container.hide_status] = True
modal._container.hide_status[:] = False
modal._window.set_key('Unhide')
add_to_undostack(modal, 0)
return
def reset_gizmo(modal, context, event, keys, func_data):
if modal._use_gizmo:
loc = modal._orbit_ob.location.copy()
modal._orbit_ob.matrix_world = modal._object.matrix_world
modal._orbit_ob.matrix_world.translation = loc
modal._window.update_gizmo_orientation(
modal._orbit_ob.matrix_world)
modal._window.set_key('Reset Gizmo')
return
def rotate_start(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
avg_loc = np.mean(
modal._container.loop_coords[modal._container.sel_status], axis=0)
modal._window.set_status('VIEW ROTATION')
modal._container.cache_norms[:] = modal._container.new_norms
modal._mode_cache.append(avg_loc)
modal._mode_cache.append(0)
modal._mode_cache.append(1)
modal._mouse_init = modal._mouse_reg_loc.copy()
modal.rotating = True
modal._current_tool = modal._rotate_norms_tool
keymap_rotating(modal)
gizmo_update_hide(modal, False)
modal.selection_drawing = True
start_active_drawing(modal)
modal._window.set_key('Rotation')
return
def toggle_xray(modal, context, event, keys, func_data):
modal._x_ray_mode = not modal._x_ray_mode
modal._xray_bool.toggle_bool()
modal._window.set_key('Toggle X-Ray')
return
def mirror_start(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
modal._current_tool = modal._mirror_tool
keymap_mirror(modal)
modal._window.set_key('Mirror Normals')
return
def smooth_norms(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
smooth_normals(modal, 0.5)
modal._window.set_key('Smooth Normals')
add_to_undostack(modal, 0)
return
def flatten_norms(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
modal._current_tool = modal._flatten_tool
keymap_flatten(modal)
modal._window.set_key('Flatten Normals')
return
def align_norms(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
modal._current_tool = modal._align_tool
keymap_align(modal)
modal._window.set_key('Align Normals')
return
def copy_active(modal, context, event, keys, func_data):
if modal._container.act_status.any():
store_active_normal(modal)
modal._window.set_key('Copy Active Normal')
return
def paste_stored(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
paste_normal(modal)
modal._window.set_key('Paste Stored Normal')
add_to_undostack(modal, 0)
return
def paste_active_to_selected(modal, context, event, keys, func_data):
if modal._container.act_status.any():
copy_active_to_selected(modal)
modal._window.set_key('Paste Active Normal to Selected')
add_to_undostack(modal, 0)
return
def set_outside(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
set_outside_inside(modal, 1)
modal._window.set_key('Set Normals Outside')
add_to_undostack(modal, 0)
return
def set_inside(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
set_outside_inside(modal, -1)
modal._window.set_key('Set Normals Inside')
add_to_undostack(modal, 0)
return
def flip_norms(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
flip_normals(modal)
modal._window.set_key('Flip Normals')
add_to_undostack(modal, 0)
return
def reset_vectors(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
reset_normals(modal)
modal._window.set_key('Reset Vectors')
add_to_undostack(modal, 0)
return
def average_individual(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
average_vertex_normals(modal)
modal._window.set_key('Average Individual Normals')
add_to_undostack(modal, 0)
return
def average_selected(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
average_selected_normals(modal)
modal._window.set_key('Average Selected Normals')
add_to_undostack(modal, 0)
return
def normals_from_faces(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
set_normals_from_faces(modal)
modal._window.set_key('Normals From Faces')
add_to_undostack(modal, 0)
return
#
def invert_selection(modal, context, event, keys, func_data):
if modal._container.hide_status.all() == False:
modal._container.act_status[:] = False
modal._container.sel_status[~modal._container.hide_status] = ~modal._container.sel_status[~modal._container.hide_status]
modal._active_face = None
modal._window.set_key('Invert Selection')
add_to_undostack(modal, 0)
return
def box_select_start(modal, context, event, keys, func_data):
bpy.context.window.cursor_modal_set('CROSSHAIR')
modal._current_tool = modal._box_sel_tool
modal.selection_drawing = True
keymap_box_selecting(modal)
gizmo_update_hide(modal, False)
modal._window.set_key('Box Select Start')
return
def circle_select_start(modal, context, event, keys, func_data):
bpy.context.window.cursor_modal_set('CROSSHAIR')
modal._current_tool = modal._circle_sel_tool
modal.selection_drawing = True
modal.circle_selecting = True
keymap_circle_selecting(modal)
modal._window.set_key('Circle Select Start')
return
def lasso_select_start(modal, context, event, keys, func_data):
bpy.context.window.cursor_modal_set('CROSSHAIR')
modal._current_tool = modal._lasso_sel_tool
modal.selection_drawing = True
keymap_lasso_selecting(modal)
gizmo_update_hide(modal, False)
modal._window.set_key('Lasso Select Start')
return
def select_all(modal, context, event, keys, func_data):
change = not modal._container.sel_status.all()
if change:
modal._container.sel_status[:] = True
modal._active_face = None
modal._window.set_key('Select All')
add_to_undostack(modal, 0)
return
def deselect_all(modal, context, event, keys, func_data):
change = modal._container.sel_status.any()
if change:
modal._container.sel_status[:] = False
modal._container.act_status[:] = False
modal._active_point = None
modal._active_face = None
modal._window.set_key('Deselect All')
add_to_undostack(modal, 0)
return
def select_linked(modal, context, event, keys, func_data):
if modal._container.sel_status.any():
vis_pos = get_visible_points(modal)
sel_inds = get_selected_points(modal, any_selected=True)
new_sel = get_linked_geo(
modal._object_bm, list(sel_inds), vis=list(vis_pos))
if len(new_sel) > 0:
modal._container.sel_status[get_vert_ls(
modal, new_sel)] = True
modal._window.set_key('Select Linked')
add_to_undostack(modal, 0)
return