1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
20 from mathutils
import Vector
21 from math
import cos
, sin
, pi
24 def create_widget(name
):
25 """Create an empty widget object and return the object"""
26 prefs
= bpy
.context
.preferences
.addons
["add_camera_rigs"].preferences
27 widget_prefix
= prefs
.widget_prefix
28 obj_name
= widget_prefix
+ name
29 scene
= bpy
.context
.scene
31 obj
= bpy
.data
.objects
.get(obj_name
)
34 mesh
= bpy
.data
.meshes
.new(obj_name
)
35 obj
= bpy
.data
.objects
.new(obj_name
, mesh
)
37 # Create a new collection for the widgets
38 collection_name
= prefs
.camera_widget_collection_name
39 coll
= bpy
.data
.collections
.get(collection_name
)
41 coll
= bpy
.data
.collections
.new(collection_name
)
42 scene
.collection
.children
.link(coll
)
43 coll
.hide_viewport
= True
44 coll
.hide_render
= True
47 coll
.objects
.link(obj
)
52 def create_corner_widget(name
, reverse
=False):
53 """Create a wedge-shaped widget"""
54 obj
= create_widget(name
)
55 if not obj
.data
.vertices
:
56 reverse
= -1 if reverse
else 1
57 verts
= (Vector((reverse
* 0.0, 0.0, 0.0)),
58 Vector((reverse
* 0.0, 1.0, 0.0)),
59 Vector((reverse
* -0.1, 1.0, 0.0)),
60 Vector((reverse
* -0.1, 0.1, 0.0)),
61 Vector((reverse
* -1.0, 0.1, 0.0)),
62 Vector((reverse
* -1.0, 0.0, 0.0)),
64 edges
= [(n
, (n
+1) % len(verts
)) for n
in range(len(verts
))]
67 mesh
.from_pydata(verts
, edges
, ())
72 def create_circle_widget(name
, radius
=1.0):
73 """Create a circle-shaped widget"""
74 obj
= create_widget(name
)
75 if not obj
.data
.vertices
:
78 for n
in range(vert_n
):
79 angle
= n
/ vert_n
* 2*pi
80 verts
.append(Vector((cos(angle
) * radius
,
81 sin(angle
) * radius
, 0.0)))
82 edges
= [(n
, (n
+1) % len(verts
)) for n
in range(len(verts
))]
85 mesh
.from_pydata(verts
, edges
, ())
90 def create_root_widget(name
):
91 """Create a compass-shaped widget"""
92 obj
= create_widget(name
)
93 if not obj
.data
.vertices
:
94 verts
= [(0.6307649612426758, 0.6271349787712097, 0.0),
95 (0.3413670063018799, 0.8205029964447021, 0.0),
96 (0.0, 0.8884050250053406, 0.0),
97 (-0.3413670063018799, 0.8205029964447021, 0.0),
98 (-0.6307649612426758, 0.6271349787712097, 0.0),
99 (-0.8241360187530518, 0.3377370238304138, 0.0),
100 (-0.8920379877090454, -0.003631560131907463, 0.0),
101 (0.8920379877090454, -0.003631379920989275, 0.0),
102 (0.824133038520813, 0.3377370238304138, 0.0),
103 (0.21458700299263, 1.5175920724868774, 0.0),
104 (-0.21458669006824493, 1.5175920724868774, 0.0),
105 (-0.21458700299263, 1.1372729539871216, 0.0),
106 (0.21458700299263, 1.1372729539871216, 0.0),
107 (-0.3977609872817993, 1.5175920724868774, 0.0),
108 (0.3977609872817993, 1.5175920724868774, 0.0),
109 (0.0, 2.002802848815918, 0.0),
110 (-0.8241360187530518, -0.3449999988079071, 0.0),
111 (0.8241360187530518, -0.3449999988079071, 0.0),
112 (0.6307649612426758, -0.6343979835510254, 0.0),
113 (0.3413670063018799, -0.8277660012245178, 0.0),
114 (0.0, -0.8956680297851562, 0.0),
115 (-0.3413670063018799, -0.8277660012245178, 0.0),
116 (-0.6307649612426758, -0.6343979835510254, 0.0),
117 (-2.0064330101013184, -0.003630870021879673, 0.0),
118 (-1.5212249755859375, 0.39413100481033325, 0.0),
119 (-1.5212249755859375, -0.4013940095901489, 0.0),
120 (-1.1409029960632324, 0.21095609664916992, 0.0),
121 (-1.1409029960632324, -0.2182179093360901, 0.0),
122 (-1.5212249755859375, -0.2182179093360901, 0.0),
123 (-1.5212249755859375, 0.21095609664916992, 0.0),
124 (1.5212249755859375, -0.2182179093360901, 0.0),
125 (1.5212249755859375, 0.21095609664916992, 0.0),
126 (1.1409029960632324, 0.21095609664916992, 0.0),
127 (1.1409029960632324, -0.2182179093360901, 0.0),
128 (1.5212249755859375, 0.39413100481033325, 0.0),
129 (1.5212249755859375, -0.4013940095901489, 0.0),
130 (2.0064330101013184, -0.0036309000570327044, 0.0),
131 (0.0, -2.0100629329681396, 0.0),
132 (-0.3977609872817993, -1.5248548984527588, 0.0),
133 (0.3977609872817993, -1.5248548984527588, 0.0),
134 (-0.21458669006824493, -1.144536018371582, 0.0),
135 (0.21458730101585388, -1.144536018371582, 0.0),
136 (0.21458730101585388, -1.5248548984527588, 0.0),
137 (-0.21458669006824493, -1.5248548984527588, 0.0)]
139 edges
= [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (7, 8), (0, 8),
140 (10, 11), (9, 12), (11, 12), (10, 13), (9, 14), (13, 15), (14, 15),
141 (16, 22), (17, 18), (18, 19), (19, 20), (20, 21), (21, 22), (7, 17),
142 (6, 16), (23, 24), (23, 25), (24, 29), (25, 28), (26, 27), (26, 29),
143 (27, 28), (31, 32), (30, 33), (32, 33), (31, 34), (30, 35), (34, 36),
144 (35, 36), (37, 38), (37, 39), (38, 43), (39, 42), (40, 41), (40, 43),
148 mesh
.from_pydata(verts
, edges
, [])
153 def create_camera_widget(name
):
154 """Create a camera control widget"""
155 obj
= create_widget(name
)
156 if not obj
.data
.vertices
:
157 verts
= [(0.275136, 0, -0.275136), (0.359483, 0, -0.148903),
158 (0.389102, 0, 0), (0.359483, 0, 0.148903),
159 (0.275136, 0, 0.275136), (0.148903, 0, 0.359483),
160 (-1.94818e-07, 0, 0.389102), (-1.17505e-07, 0, -0.389102),
161 (0.148903, 0, -0.359483), (0.663549, 0, -0.0936016),
162 (0.663549, 0, 0.0936016), (0.497656, 0, 0.0936016),
163 (0.497656, 0, -0.0936017), (0.663549, 0, 0.173501),
164 (0.663549, 0, -0.173501), (0.875195, 0, 0),
165 (-0.148903, 0, 0.359483), (-0.148903, 0, -0.359483),
166 (-0.275136, 0, -0.275136), (-0.359483, 0, -0.148903),
167 (-0.389102, 0, 0), (-0.359483, 0, 0.148903),
168 (-0.275136, 0, 0.275136), (1.03426e-07, 0, 0.875195),
169 (0.173502, 0, 0.663549), (-0.173501, 0, 0.663549),
170 (0.0936017, 0, 0.497656), (-0.0936016, 0, 0.497656),
171 (-0.0936016, 0, 0.663549), (0.0936017, 0, 0.663549),
172 (-0.0936015, 0, -0.663549), (0.0936017, 0, -0.663549),
173 (0.0936017, 0, -0.497656), (-0.0936016, 0, -0.497656),
174 (0.173502, 0, -0.663549), (-0.173501, 0, -0.663549),
175 (9.42269e-08, 0, -0.875195), (-0.875195, 0, 0),
176 (-0.663549, 0, 0.173501), (-0.663549, 0, -0.173502),
177 (-0.497656, 0, 0.0936015), (-0.497656, 0, -0.0936018),
178 (-0.663549, 0, -0.0936018), (-0.663549, 0, 0.0936015),
180 edges
= [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (7, 8), (0, 8),
181 (10, 11), (9, 12), (11, 12), (10, 13), (9, 14), (13, 15), (14, 15),
182 (16, 22), (17, 18), (18, 19), (19, 20), (20, 21), (21, 22), (7, 17),
183 (6, 16), (23, 24), (23, 25), (24, 29), (25, 28), (26, 29), (27, 28),
184 (31, 32), (30, 33), (32, 33), (31, 34), (30, 35), (34, 36), (35, 36),
185 (37, 38), (37, 39), (38, 43), (39, 42), (40, 41), (40, 43), (41, 42),
189 mesh
.from_pydata(verts
, edges
, [])
194 def create_camera_offset_widget(name
):
195 """Create a camera offset control widget"""
196 obj
= create_widget(name
)
197 if not obj
.data
.vertices
:
198 verts
= [(0.23286, 0, 0), (0.215135, 0, 0.0891117),
199 (0.164657, 0, 0.164657), (0.0891117, 0, 0.215135),
200 (0, 0, 0.23286), (-0.0891117, 0, 0.215135),
201 (-0.164657, 0, 0.164657), (-0.215135, 0, 0.0891117),
202 (-0.23286, 0, 0), (-0.215135, 0, -0.0891117),
203 (-0.164657, 0, -0.164657), (-0.0891117, 0, -0.215135),
204 (0, 0, -0.23286), (0.0891117, 0, -0.215135),
205 (0.164657, 0, -0.164657), (0.215135, 0, -0.0891117),
207 edges
= [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8),
208 (8, 9), (9, 10), (10, 11), (11, 12), (12, 13), (13, 14), (14, 15),
212 mesh
.from_pydata(verts
, edges
, [])
217 def create_aim_widget(name
):
218 """Create a camera aim widget"""
219 obj
= create_widget(name
)
220 if not obj
.data
.vertices
:
221 verts
= [(0.31008288264274597, 0.0, 0.31008288264274597),
222 (0.40514281392097473, 0.0, 0.1678156554698944),
223 (0.43852344155311584, 0.0, 0.0),
224 (0.40514281392097473, 0.0, -0.1678156852722168),
225 (0.31008288264274597, 0.0, -0.31008288264274597),
226 (0.1678156703710556, 0.0, -0.40514281392097473),
227 (-2.1956294915526087e-07, 0.0, -0.43852344155311584),
228 (-1.3243040086763358e-07, 0.0, 0.43852344155311584),
229 (0.16781596839427948, 0.0, 0.4051426947116852),
230 (0.7993937134742737, 0.0, 0.10549049079418182),
231 (0.7993937134742737, 0.0, -0.10549048334360123),
232 (0.9863580465316772, 0.0, -0.10549048334360123),
233 (0.9863580465316772, 0.0, 0.105490542948246),
234 (0.7993937134742737, 0.0, -0.19553886353969574),
235 (0.7993937134742737, 0.0, 0.19553886353969574),
236 (0.5608659386634827, 0.0, 0.0),
237 (-0.1678159236907959, 0.0, -0.4051426947116852),
238 (-0.16781575977802277, 0.0, 0.40514281392097473),
239 (-0.31008294224739075, 0.0, 0.3100828230381012),
240 (-0.40514281392097473, 0.0, 0.16781564056873322),
241 (-0.43852344155311584, 0.0, 0.0),
242 (-0.40514281392097473, 0.0, -0.16781572997570038),
243 (-0.3100828230381012, 0.0, -0.31008294224739075),
244 (5.8281088399780856e-08, 0.0, 0.5608659982681274),
245 (-0.19553889334201813, 0.0, 0.7993938326835632),
246 (0.1955389529466629, 0.0, 0.7993938326835632),
247 (-0.10549052804708481, 0.0, 0.9863581657409668),
248 (0.10549058020114899, 0.0, 0.9863581657409668),
249 (0.10549052804708481, 0.0, 0.7993938326835632),
250 (-0.10549046844244003, 0.0, 0.7993938326835632),
251 (0.10549034923315048, 0.0, -0.7993939518928528),
252 (-0.10549066960811615, 0.0, -0.7993939518928528),
253 (-0.10549074411392212, 0.0, -0.9863584041595459),
254 (0.10549039393663406, 0.0, -0.9863584041595459),
255 (-0.19553910195827484, 0.0, -0.7993938326835632),
256 (0.19553880393505096, 0.0, -0.7993940711021423),
257 (-1.4296951178494055e-07, 0.0, -0.5608659982681274),
258 (-0.5608660578727722, 0.0, 0.0),
259 (-0.7993939518928528, 0.0, -0.19553877413272858),
260 (-0.7993937134742737, 0.0, 0.19553901255130768),
261 (-0.9863580465316772, 0.0, -0.10549040883779526),
262 (-0.9863580465316772, 0.0, 0.10549063980579376),
263 (-0.7993938326835632, 0.0, 0.10549062490463257),
264 (-0.7993938326835632, 0.0, -0.10549038648605347),
265 (-0.12803608179092407, 0.0, -0.12803612649440765),
266 (-0.167287215590477, 0.0, -0.06929267197847366),
267 (-0.18107034265995026, 0.0, 0.0),
268 (-0.167287215590477, 0.0, 0.06929262727499008),
269 (-0.12803612649440765, 0.0, 0.12803608179092407),
270 (-0.06929267197847366, 0.0, 0.167287215590477),
271 (-0.06929274648427963, 0.0, -0.1672871708869934),
272 (0.06929276883602142, 0.0, 0.1672871708869934),
273 (-5.468173824851874e-08, 0.0, 0.18107034265995026),
274 (-9.065958295195742e-08, 0.0, -0.18107034265995026),
275 (0.06929264962673187, 0.0, -0.167287215590477),
276 (0.12803609669208527, 0.0, -0.12803609669208527),
277 (0.167287215590477, 0.0, -0.06929264962673187),
278 (0.18107034265995026, 0.0, 0.0),
279 (0.167287215590477, 0.0, 0.06929264217615128),
280 (0.12803609669208527, 0.0, 0.12803609669208527),
281 (-6.667435314966497e-08, 0.0, 0.060356780886650085),
282 (-7.866697160352487e-08, 0.0, -0.060356780886650085),
283 (-0.060356780886650085, 0.0, 0.0),
284 (0.060356780886650085, 0.0, 0.0)]
286 edges
= [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (7, 8), (0, 8),
287 (10, 11), (9, 12), (11, 12), (10, 13), (9, 14), (13, 15), (14, 15),
288 (16, 22), (17, 18), (18, 19), (19, 20), (20, 21), (21, 22), (7, 17),
289 (6, 16), (23, 24), (23, 25), (24, 29), (25, 28), (26, 29), (27, 28),
290 (31, 32), (30, 33), (32, 33), (31, 34), (30, 35), (34, 36), (35, 36),
291 (37, 38), (37, 39), (38, 43), (39, 42), (40, 41), (40, 43), (41, 42),
292 (50, 53), (49, 52), (44, 45), (45, 46), (46, 47), (47, 48), (48, 49),
293 (44, 50), (51, 59), (51, 52), (53, 54), (54, 55), (55, 56), (56, 57),
294 (57, 58), (58, 59), (27, 26), (60, 61), (62, 63)]
297 mesh
.from_pydata(verts
, edges
, [])