-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkeymap.py
207 lines (170 loc) · 4.2 KB
/
keymap.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
from __future__ import annotations
import bpy
PREFIX = 'LIGHT_PAINTER_'
UNIVERSAL_KEYMAP = (
{
'name': 'PAINT',
'type': 'LEFTMOUSE',
'value': 'ANY',
'ctrl': 0,
},
{
'name': 'ERASE',
'type': 'LEFTMOUSE',
'value': 'ANY',
'ctrl': 1,
},
{
'name': 'ERASER_DECREASE',
'type': 'LEFT_BRACKET',
'value': 'PRESS',
},
{
'name': 'ERASER_INCREASE',
'type': 'RIGHT_BRACKET',
'value': 'PRESS',
},
{
'name': 'END_STROKE',
'type': 'RIGHTMOUSE',
'value': 'PRESS',
},
{
'name': 'CANCEL',
'type': 'ESC',
'value': 'PRESS',
},
{
'name': 'FINISH',
'type': 'RET',
'value': 'PRESS',
},
# MODES
{
'name': 'OFFSET_MODE',
'type': 'G',
'value': 'RELEASE',
},
{
'name': 'SIZE_MODE',
'type': 'F',
'shift': 0,
'value': 'RELEASE',
},
{
'name': 'POWER_MODE',
'type': 'F',
'shift': 1,
'value': 'RELEASE',
},
# TOGGLES
{
'name': 'RELATIVE_POWER_TOGGLE',
'type': 'R',
'value': 'PRESS',
},
{
'name': 'TYPE_TOGGLE',
'type': 'T',
'value': 'PRESS',
},
# MESH
{
'name': 'FLATTEN_TOGGLE',
'type': 'F',
'value': 'PRESS',
'shift': 0,
},
# AXIS
{
'name': 'AXIS_X',
'type': 'X',
'value': 'PRESS',
},
{
'name': 'AXIS_Y',
'type': 'Y',
'value': 'PRESS',
},
{
'name': 'AXIS_Z',
'type': 'Z',
'value': 'PRESS',
},
{
'name': 'AXIS_REFLECT',
'type': 'C',
'value': 'PRESS',
},
# Visibility
{
'name': 'VISIBILITY_TOGGLE_CAMERA',
'type': 'ONE',
'value': 'PRESS',
},
{
'name': 'VISIBILITY_TOGGLE_DIFFUSE',
'type': 'TWO',
'value': 'PRESS',
},
{
'name': 'VISIBILITY_TOGGLE_SPECULAR',
'type': 'THREE',
'value': 'PRESS',
},
{
'name': 'VISIBILITY_TOGGLE_VOLUME',
'type': 'FOUR',
'value': 'PRESS',
},
)
"""Contains default keymap for all Light Painter tools."""
for kmi in UNIVERSAL_KEYMAP:
kmi['name'] = PREFIX + kmi['name']
UNIVERSAL_KEYMAP_NAMES = tuple(kmi['name'] for kmi in UNIVERSAL_KEYMAP)
AXIS_KEYMAP = tuple(name for name in UNIVERSAL_KEYMAP_NAMES if '_AXIS_' in name)
VISIBILITY_KEYMAP = tuple(name for name in UNIVERSAL_KEYMAP_NAMES if '_VISIBILITY_' in name)
def compare_kmi_to_event(item, event):
data = item.type
event_data = event.type
if item.value != 'ANY':
data += item.value
event_data += event.value
data += str(item.shift * 1 | item.ctrl * 2 | item.alt * 4 | item.oskey * 8)
event_data += str(event.shift * 1 | event.ctrl * 2 | event.alt * 4 | event.oskey * 8)
return data == event_data
def get_matching_event(event) -> str | None:
"""Checks if Blender event matches our UNIVERSAL_KEYMAP,
returns the matching command name (if none match, return None).
"""
from .preferences import get_lightpainter_kmi
return next(
(
item.properties.name.replace(PREFIX, '')
for item in get_lightpainter_kmi(bpy.context)
if compare_kmi_to_event(item, event)
),
None,
)
def is_event_command(event, command_name) -> bool:
from .preferences import get_lightpainter_kmi
if not command_name.startswith(PREFIX):
command_name = PREFIX + command_name
item = next(
(item for item in get_lightpainter_kmi(bpy.context) if item.properties.name == command_name),
None,
)
if item is None:
return False
return compare_kmi_to_event(item, event)
def get_kmi_str(command_name):
from .preferences import get_lightpainter_kmi
if not command_name.startswith(PREFIX):
command_name = PREFIX + command_name
item = next(
(item for item in get_lightpainter_kmi(bpy.context) if item.properties.name == command_name),
None,
)
if item is None:
return ''
return item.to_string()