Cleanup: surround multiply by parenthesis, remove unused import
[blender-addons.git] / btrace / bTrace_panel.py
blobec092f46eae33776614b3afcad4e075e5cceb8cb
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 from bpy.types import Panel
8 # Draw Brush panel in Toolbar
9 class addTracerObjectPanel(Panel):
10 bl_idname = "BTRACE_PT_object_brush"
11 bl_label = "BTracer"
12 bl_space_type = "VIEW_3D"
13 bl_region_type = "UI"
14 bl_context = "objectmode"
15 bl_category = "Create"
16 bl_options = {'DEFAULT_CLOSED'}
18 def draw(self, context):
19 layout = self.layout
20 Btrace = context.window_manager.curve_tracer
21 addon_prefs = context.preferences.addons[__package__].preferences
22 switch_expand = addon_prefs.expand_enum
23 obj = context.object
25 # Color Blender Panel options
26 def color_blender():
27 # Buttons for Color Blender
28 row = box.row()
29 row.label(text="Color palette")
30 row.prop(Btrace, "mmColors", text="")
32 # Show Custom Colors if selected
33 if Btrace.mmColors == 'CUSTOM':
34 row = box.row(align=True)
35 for i in range(1, 9):
36 row.prop(Btrace, "mmColor" + str(i), text="")
37 # Show Earth Colors
38 elif Btrace.mmColors == 'BW':
39 row = box.row(align=True)
40 row.prop(Btrace, "bwColor1", text="")
41 row.prop(Btrace, "bwColor2", text="")
42 # Show Earth Colors
43 elif Btrace.mmColors == 'BRIGHT':
44 row = box.row(align=True)
45 for i in range(1, 5):
46 row.prop(Btrace, "brightColor" + str(i), text="")
47 # Show Earth Colors
48 elif Btrace.mmColors == 'EARTH':
49 row = box.row(align=True)
50 for i in range(1, 6):
51 row.prop(Btrace, "earthColor" + str(i), text="")
52 # Show Earth Colors
53 elif Btrace.mmColors == 'GREENBLUE':
54 row = box.row(align=True)
55 for i in range(1, 4):
56 row.prop(Btrace, "greenblueColor" + str(i), text="")
57 elif Btrace.mmColors == 'RANDOM':
58 row = box.row()
60 # Curve noise settings
61 def curve_noise():
62 row = box.row()
63 row.label(text="F-Curve Noise", icon='RNDCURVE')
64 row = box.row(align=True)
65 row.prop(Btrace, "fcnoise_rot", toggle=True)
66 row.prop(Btrace, "fcnoise_loc", toggle=True)
67 row.prop(Btrace, "fcnoise_scale", toggle=True)
69 col = box.column(align=True)
70 col.prop(Btrace, "fcnoise_amp")
71 col.prop(Btrace, "fcnoise_timescale")
72 box.prop(Btrace, "fcnoise_key")
74 # Curve Panel options
75 def curve_settings():
76 # Button for curve options
77 row = self.layout.row()
78 row = box.row(align=True)
80 row.prop(Btrace, "show_curve_settings",
81 icon='CURVE_BEZCURVE', text="Curve Settings")
82 row.prop(Btrace, "material_settings",
83 icon='MATERIAL_DATA', text="Material Settings")
85 if Btrace.material_settings:
86 row = box.row()
87 row.label(text="Material Settings", icon='COLOR')
88 row = box.row()
89 row.prop(Btrace, "trace_mat_random")
90 if not Btrace.trace_mat_random:
91 row = box.row()
92 row.prop(Btrace, "trace_mat_color", text="")
93 else:
94 row.prop(Btrace, "mat_run_color_blender")
95 if Btrace.mat_run_color_blender:
96 row = box.row()
97 row.operator("object.colorblenderclear",
98 text="Reset Material Keyframes",
99 icon="KEY_DEHLT")
100 row.prop(Btrace, "mmSkip", text="Keyframe every")
101 color_blender()
102 row = box.row()
104 if Btrace.show_curve_settings:
105 # selected curve options
106 if len(context.selected_objects) > 0 and obj.type == 'CURVE':
107 col = box.column(align=True)
108 col.label(text="Edit Curves for:", icon='IPO_BEZIER')
109 col.separator()
110 col.label(text="Selected Curve Bevel Options")
111 row = col.row(align=True)
112 row.prop(obj.data, "bevel_depth", text="Depth")
113 row.prop(obj.data, "bevel_resolution", text="Resolution")
114 row = col.row(align=True)
115 row.prop(obj.data, "resolution_u")
116 else: # For new curve
117 box.label(text="New Curve Settings", icon='CURVE_BEZCURVE')
118 box.prop(Btrace, "curve_spline")
119 box.prop(Btrace, "curve_handle")
120 box.label(text="Bevel Options")
121 col = box.column(align=True)
122 row = col.row(align=True)
123 row.prop(Btrace, "curve_depth", text="Depth")
124 row.prop(Btrace, "curve_resolution", text="Resolution")
125 row = col.row(align=True)
126 row.prop(Btrace, "curve_u")
128 # Grow Animation Panel options
129 def add_grow():
130 # Button for grow animation option
131 row = box.row()
132 row.label(text="Animate Final Curve", icon="NONE")
133 row = box.row()
134 row.prop(Btrace, "animate", text="Add Grow Curve Animation", icon="META_BALL")
135 box.separator()
136 if Btrace.animate:
137 box.label(text="Frame Animation Settings:", icon="META_BALL")
138 col = box.column(align=True)
139 col.prop(Btrace, "anim_auto")
140 if not Btrace.anim_auto:
141 row = col.row(align=True)
142 row.prop(Btrace, "anim_f_start")
143 row.prop(Btrace, "anim_length")
144 row = col.row(align=True)
145 row.prop(Btrace, "anim_delay")
146 row.prop(Btrace, "anim_f_fade")
148 box.label(text="Additional Settings")
149 row = box.row()
150 row.prop(Btrace, "anim_tails")
151 row.prop(Btrace, "anim_keepr")
153 # Start Btrace Panel
154 if switch_expand == 'list':
155 layout.label(text="Available Tools:", icon="COLLAPSEMENU")
156 col = layout.column(align=True)
157 col.prop(Btrace, "btrace_toolmenu", text="")
158 elif switch_expand == 'col':
159 col = layout.column(align=True)
160 col.prop(Btrace, "btrace_toolmenu", expand=True)
161 elif switch_expand == 'row':
162 row = layout.row(align=True)
163 row.alignment = 'CENTER'
164 row.prop(Btrace, "btrace_toolmenu", text="", expand=True)
166 # Start Object Tools
167 sel = context.selected_objects
169 # Default option (can be expanded into help)
170 if Btrace.btrace_toolmenu == 'tool_help':
171 row = layout.row()
172 row.label(text="Pick an option", icon="HELP")
174 # Object Trace
175 elif Btrace.btrace_toolmenu == 'tool_objectTrace':
176 row = layout.row()
177 row.label(text=" Trace Tool:", icon="FORCE_CURVE")
178 box = self.layout.box()
179 row = box.row()
180 row.label(text="Object Trace", icon="FORCE_MAGNETIC")
181 row.operator("object.btobjecttrace", text="Run!", icon="PLAY")
182 row = box.row()
183 row.prop(Btrace, "settings_toggle", icon="MODIFIER", text="Settings")
184 myselected = "Selected %d" % len(context.selected_objects)
185 row.label(text=myselected)
186 if Btrace.settings_toggle:
187 box.label(text="Edge Type for Curves:", icon="IPO_CONSTANT")
188 row = box.row(align=True)
189 row.prop(Btrace, "convert_edgetype", text="")
190 box.prop(Btrace, "object_duplicate")
191 if len(sel) > 1:
192 box.prop(Btrace, "convert_joinbefore")
193 else:
194 Btrace.convert_joinbefore = False
195 row = box.row()
196 row.prop(Btrace, "distort_curve")
197 if Btrace.distort_curve:
198 col = box.column(align=True)
199 col.prop(Btrace, "distort_modscale")
200 col.prop(Btrace, "distort_noise")
201 row = box.row()
202 curve_settings() # Show Curve/material settings
203 add_grow() # Grow settings here
205 # Objects Connect
206 elif Btrace.btrace_toolmenu == 'tool_objectsConnect':
207 row = layout.row()
208 row.label(text=" Trace Tool:", icon="FORCE_CURVE")
209 box = self.layout.box()
210 row = box.row()
211 row.label(text="Objects Connect", icon="OUTLINER_OB_EMPTY")
212 row.operator("object.btobjectsconnect", text="Run!", icon="PLAY")
213 row = box.row()
214 row.prop(Btrace, "settings_toggle", icon='MODIFIER', text='Settings')
215 row.label(text="")
216 if Btrace.settings_toggle:
217 row = box.row()
218 row.prop(Btrace, "respect_order", text="Selection Options")
219 if Btrace.respect_order:
220 box.operator("object.select_order",
221 text="Click to start order selection",
222 icon='UV_SYNC_SELECT')
223 row = box.row()
224 row.prop(Btrace, "connect_noise", text="Add F-Curve Noise")
225 if Btrace.connect_noise:
226 curve_noise() # Show Curve Noise settings
228 curve_settings() # Show Curve/material settings
229 add_grow() # Grow settings here
231 # Mesh Follow
232 elif Btrace.btrace_toolmenu == 'tool_meshFollow':
233 row = layout.row()
234 row.label(text=" Trace Tool:", icon="FORCE_CURVE")
235 box = self.layout.box()
236 row = box.row()
237 row.label(text="Mesh Follow", icon="DRIVER")
238 row.operator("object.btmeshfollow", text="Run!", icon="PLAY")
239 row = box.row()
240 if Btrace.fol_mesh_type == 'OBJECT':
241 a, b = "Trace Object", "SNAP_VOLUME"
242 if Btrace.fol_mesh_type == 'VERTS':
243 a, b = "Trace Verts", "SNAP_VERTEX"
244 if Btrace.fol_mesh_type == 'EDGES':
245 a, b = "Trace Edges", "SNAP_EDGE"
246 if Btrace.fol_mesh_type == 'FACES':
247 a, b = "Trace Faces", "SNAP_FACE"
248 row.prop(Btrace, "settings_toggle", icon='MODIFIER', text='Settings')
249 row.label(text=a, icon=b)
250 if Btrace.settings_toggle:
251 col = box.column(align=True)
252 row = col.row(align=True)
253 row.prop(Btrace, "fol_mesh_type", expand=True)
254 row = col.row(align=True)
255 if Btrace.fol_mesh_type != 'OBJECT':
256 row.prop(Btrace, "fol_sel_option", expand=True)
257 row = box.row()
258 if Btrace.fol_sel_option == 'RANDOM':
259 row.label(text="Random Select of Total")
260 row.prop(Btrace, "fol_perc_verts", text="%")
261 if Btrace.fol_sel_option == 'CUSTOM':
262 row.label(text="Choose selection in Edit Mode")
263 if Btrace.fol_sel_option == 'ALL':
264 row.label(text="Select All items")
265 col = box.column(align=True)
266 col.label(text="Time Options", icon="TIME")
267 col.prop(Btrace, "particle_step")
268 row = col.row(align=True)
269 row.prop(Btrace, "fol_start_frame")
270 row.prop(Btrace, "fol_end_frame")
271 curve_settings() # Show Curve/material settings
272 add_grow() # Grow settings here
274 # Handwriting Tools
275 elif Btrace.btrace_toolmenu == 'tool_handwrite':
276 row = layout.row()
277 row.label(text=" Trace Tool:", icon="FORCE_CURVE")
278 box = self.layout.box()
279 row = box.row()
280 row.label(text='Handwriting', icon='BRUSH_DATA')
281 row.operator("curve.btwriting", text="Run!", icon='PLAY')
282 row = box.row()
283 row = box.row()
284 row.label(text='Grease Pencil Writing Tools')
285 col = box.column(align=True)
286 row = col.row(align=True)
287 row.operator("gpencil.draw", text="Draw", icon='BRUSH_DATA').mode = 'DRAW'
288 row.operator("gpencil.draw", text="Poly", icon='VPAINT_HLT').mode = 'DRAW_POLY'
289 row = col.row(align=True)
290 row.operator("gpencil.draw", text="Line", icon='ZOOM_OUT').mode = 'DRAW_STRAIGHT'
291 row.operator("gpencil.draw", text="Erase", icon='TPAINT_HLT').mode = 'ERASER'
292 row = box.row()
293 row.operator("gpencil.data_unlink", text="Delete Grease Pencil Layer", icon="CANCEL")
294 row = box.row()
295 curve_settings() # Show Curve/material settings
296 add_grow() # Grow settings here
298 # Particle Trace
299 elif Btrace.btrace_toolmenu == 'tool_particleTrace':
300 row = layout.row()
301 row.label(text=" Trace Tool:", icon="FORCE_CURVE")
302 box = self.layout.box()
303 row = box.row()
304 row.label(text="Particle Trace", icon="PARTICLES")
305 row.operator("particles.particletrace", text="Run!", icon="PLAY")
306 row = box.row()
307 row.prop(Btrace, "settings_toggle", icon='MODIFIER', text='Settings')
308 row.label(text="")
309 if Btrace.settings_toggle:
310 box.prop(Btrace, "particle_step")
311 row = box.row()
312 row.prop(Btrace, "curve_join")
313 curve_settings() # Show Curve/material settings
314 add_grow() # Grow settings here
316 # Connect Particles
317 elif Btrace.btrace_toolmenu == 'tool_particleConnect':
318 row = layout.row()
319 row.label(text=" Trace Tool:", icon="FORCE_CURVE")
320 box = self.layout.box()
321 row = box.row()
322 row.label(text='Particle Connect', icon='MOD_PARTICLES')
323 row.operator("particles.connect", icon="PLAY", text='Run!')
324 row = box.row()
325 row.prop(Btrace, "settings_toggle", icon='MODIFIER', text='Settings')
326 row.label(text="")
327 if Btrace.settings_toggle:
328 box.prop(Btrace, "particle_step")
329 row = box.row()
330 row.prop(Btrace, 'particle_auto')
331 if not Btrace.particle_auto:
332 row = box.row(align=True)
333 row.prop(Btrace, 'particle_f_start')
334 row.prop(Btrace, 'particle_f_end')
335 curve_settings() # Show Curve/material settings
336 add_grow() # Grow settings here
338 # Grow Animation
339 elif Btrace.btrace_toolmenu == 'tool_growCurve':
340 row = layout.row()
341 row.label(text=" Curve Tool:", icon="OUTLINER_OB_CURVE")
342 box = self.layout.box()
343 row = box.row()
344 row.label(text="Grow Curve", icon="META_BALL")
345 row.operator("curve.btgrow", text="Run!", icon="PLAY")
346 row = box.row()
347 row.prop(Btrace, "settings_toggle", icon="MODIFIER", text="Settings")
348 row.operator("object.btreset", icon="KEY_DEHLT")
349 if Btrace.settings_toggle:
350 box.label(text="Frame Animation Settings:")
351 col = box.column(align=True)
352 col.prop(Btrace, "anim_auto")
353 if not Btrace.anim_auto:
354 row = col.row(align=True)
355 row.prop(Btrace, "anim_f_start")
356 row.prop(Btrace, "anim_length")
357 row = col.row(align=True)
358 row.prop(Btrace, "anim_delay")
359 row.prop(Btrace, "anim_f_fade")
361 box.label(text="Additional Settings")
362 row = box.row()
363 row.prop(Btrace, "anim_tails")
364 row.prop(Btrace, "anim_keepr")
366 # F-Curve Noise Curve
367 elif Btrace.btrace_toolmenu == 'tool_fcurve':
368 row = layout.row()
369 row.label(text=" Curve Tool:", icon="OUTLINER_OB_CURVE")
370 box = self.layout.box()
371 row = box.row()
372 row.label(text="F-Curve Noise", icon='RNDCURVE')
373 row.operator("object.btfcnoise", icon='PLAY', text="Run!")
374 row = box.row()
375 row.prop(Btrace, "settings_toggle", icon='MODIFIER', text='Settings')
376 row.operator("object.btreset", icon='KEY_DEHLT')
377 if Btrace.settings_toggle:
378 curve_noise()
380 # Color Blender
381 elif Btrace.btrace_toolmenu == 'tool_colorblender':
382 row = layout.row()
383 row.label(text=" Curve/Object Tool:", icon="OUTLINER_OB_CURVE")
384 box = self.layout.box()
385 row = box.row()
386 row.label(text="Color Blender", icon="COLOR")
387 row.operator("object.colorblender", icon='PLAY', text="Run!")
388 row = box.row()
389 row.operator("object.colorblenderclear", text="Reset Keyframes", icon="KEY_DEHLT")
390 row.prop(Btrace, "mmSkip", text="Keyframe every")
391 color_blender()