89024a52c252dd7ee8cff113d0cab6d75435f462
[blender-staging.git] / release / scripts / startup / bl_ui / properties_freestyle.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
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.
7 #
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.
12 #
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.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Menu, Panel, UIList
22
23
24 # Render properties
25
26 class RenderFreestyleButtonsPanel:
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "render"
30     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
31
32     @classmethod
33     def poll(cls, context):
34         scene = context.scene
35         with_freestyle = bpy.app.build_options.freestyle
36         return scene and with_freestyle and(scene.render.engine in cls.COMPAT_ENGINES)
37
38
39 class RENDER_PT_freestyle(RenderFreestyleButtonsPanel, Panel):
40     bl_label = "Freestyle"
41     bl_options = {'DEFAULT_CLOSED'}
42     COMPAT_ENGINES = {'BLENDER_RENDER'}
43
44     def draw_header(self, context):
45         rd = context.scene.render
46         self.layout.prop(rd, "use_freestyle", text="")
47
48     def draw(self, context):
49         layout = self.layout
50
51         rd = context.scene.render
52
53         layout.active = rd.use_freestyle
54
55         row = layout.row()
56         row.label(text="Line Thickness:")
57         row.prop(rd, "line_thickness_mode", expand=True)
58
59         if (rd.line_thickness_mode == 'ABSOLUTE'):
60             layout.prop(rd, "line_thickness")
61
62
63 # Render layer properties
64
65 class RenderLayerFreestyleButtonsPanel:
66     bl_space_type = 'PROPERTIES'
67     bl_region_type = 'WINDOW'
68     bl_context = "render_layer"
69     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
70
71     @classmethod
72     def poll(cls, context):
73         scene = context.scene
74         rd = context.scene.render
75         with_freestyle = bpy.app.build_options.freestyle
76
77         return (scene and with_freestyle and rd.use_freestyle and
78                 rd.layers.active and(scene.render.engine in cls.COMPAT_ENGINES))
79
80
81 class RenderLayerFreestyleEditorButtonsPanel(RenderLayerFreestyleButtonsPanel):
82     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
83
84     @classmethod
85     def poll(cls, context):
86         if not super().poll(context):
87             return False
88         rl = context.scene.render.layers.active
89         return rl and rl.freestyle_settings.mode == 'EDITOR'
90
91
92 class RENDERLAYER_UL_linesets(UIList):
93     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
94         lineset = item
95         if self.layout_type in {'DEFAULT', 'COMPACT'}:
96             layout.prop(lineset, "name", text="", emboss=False, icon_value=icon)
97             layout.prop(lineset, "show_render", text="", index=index)
98         elif self.layout_type == 'GRID':
99             layout.alignment = 'CENTER'
100             layout.label("", icon_value=icon)
101
102
103 class RENDER_MT_lineset_specials(Menu):
104     bl_label = "Lineset Specials"
105
106     def draw(self, context):
107         layout = self.layout
108         layout.operator("scene.freestyle_lineset_copy", icon='COPYDOWN')
109         layout.operator("scene.freestyle_lineset_paste", icon='PASTEDOWN')
110
111
112 class RENDERLAYER_PT_freestyle(RenderLayerFreestyleButtonsPanel, Panel):
113     bl_label = "Freestyle"
114     COMPAT_ENGINES = {'BLENDER_RENDER'}
115
116     def draw(self, context):
117         layout = self.layout
118
119         rd = context.scene.render
120         rl = rd.layers.active
121         freestyle = rl.freestyle_settings
122
123         layout.active = rl.use_freestyle
124
125         row = layout.row()
126         layout.prop(freestyle, "mode", text="Control mode")
127         layout.prop(freestyle, "use_view_map_cache", text="View Map Cache")
128         layout.label(text="Edge Detection Options:")
129
130         split = layout.split()
131
132         col = split.column()
133         col.prop(freestyle, "crease_angle")
134         col.prop(freestyle, "use_culling")
135         col.prop(freestyle, "use_advanced_options")
136
137         col = split.column()
138         col.prop(freestyle, "use_smoothness")
139         if freestyle.mode == 'SCRIPT':
140             col.prop(freestyle, "use_material_boundaries")
141
142         # Advanced options are hidden by default to warn new users
143         if freestyle.use_advanced_options:
144             if freestyle.mode == 'SCRIPT':
145                 row = layout.row()
146                 row.prop(freestyle, "use_ridges_and_valleys")
147                 row.prop(freestyle, "use_suggestive_contours")
148             row = layout.row()
149             row.prop(freestyle, "sphere_radius")
150             row.prop(freestyle, "kr_derivative_epsilon")
151
152         if freestyle.mode == 'SCRIPT':
153             row = layout.row()
154             row.label("Style modules:")
155             row.operator("scene.freestyle_module_add", text="Add")
156             for i, module in enumerate(freestyle.modules):
157                 box = layout.box()
158                 box.context_pointer_set("freestyle_module", module)
159                 row = box.row(align=True)
160                 row.prop(module, "use", text="")
161                 row.prop(module, "script", text="")
162                 row.operator("scene.freestyle_module_open", icon='FILESEL', text="")
163                 row.operator("scene.freestyle_module_remove", icon='X', text="")
164                 row.operator("scene.freestyle_module_move", icon='TRIA_UP', text="").direction = 'UP'
165                 row.operator("scene.freestyle_module_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
166
167
168 class RENDERLAYER_PT_freestyle_lineset(RenderLayerFreestyleEditorButtonsPanel, Panel):
169     bl_label = "Freestyle Line Set"
170     COMPAT_ENGINES = {'BLENDER_RENDER'}
171
172     def draw_edge_type_buttons(self, box, lineset, edge_type):
173         # property names
174         select_edge_type = "select_" + edge_type
175         exclude_edge_type = "exclude_" + edge_type
176         # draw edge type buttons
177         row = box.row(align=True)
178         row.prop(lineset, select_edge_type)
179         sub = row.column(align=True)
180         sub.prop(lineset, exclude_edge_type, text="")
181         sub.active = getattr(lineset, select_edge_type)
182
183     def draw(self, context):
184         layout = self.layout
185
186         rd = context.scene.render
187         rl = rd.layers.active
188         freestyle = rl.freestyle_settings
189         lineset = freestyle.linesets.active
190
191         layout.active = rl.use_freestyle
192
193         row = layout.row()
194         rows = 4 if lineset else 2
195         row.template_list("RENDERLAYER_UL_linesets", "", freestyle, "linesets", freestyle.linesets, "active_index", rows=rows)
196
197         sub = row.column(align=True)
198         sub.operator("scene.freestyle_lineset_add", icon='ZOOMIN', text="")
199         sub.operator("scene.freestyle_lineset_remove", icon='ZOOMOUT', text="")
200         sub.menu("RENDER_MT_lineset_specials", icon='DOWNARROW_HLT', text="")
201         if lineset:
202             sub.separator()
203             sub.separator()
204             sub.operator("scene.freestyle_lineset_move", icon='TRIA_UP', text="").direction = 'UP'
205             sub.operator("scene.freestyle_lineset_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
206
207             col = layout.column()
208             col.label(text="Selection By:")
209             row = col.row(align=True)
210             row.prop(lineset, "select_by_visibility", text="Visibility", toggle=True)
211             row.prop(lineset, "select_by_edge_types", text="Edge Types", toggle=True)
212             row.prop(lineset, "select_by_face_marks", text="Face Marks", toggle=True)
213             row.prop(lineset, "select_by_group", text="Group", toggle=True)
214             row.prop(lineset, "select_by_image_border", text="Image Border", toggle=True)
215
216             if lineset.select_by_visibility:
217                 col.label(text="Visibility:")
218                 row = col.row(align=True)
219                 row.prop(lineset, "visibility", expand=True)
220                 if lineset.visibility == 'RANGE':
221                     row = col.row(align=True)
222                     row.prop(lineset, "qi_start")
223                     row.prop(lineset, "qi_end")
224
225             if lineset.select_by_edge_types:
226                 col.label(text="Edge Types:")
227                 row = col.row()
228                 row.prop(lineset, "edge_type_negation", expand=True)
229                 row.prop(lineset, "edge_type_combination", expand=True)
230
231                 split = col.split()
232
233                 sub = split.column()
234                 self.draw_edge_type_buttons(sub, lineset, "silhouette")
235                 self.draw_edge_type_buttons(sub, lineset, "border")
236                 self.draw_edge_type_buttons(sub, lineset, "contour")
237                 self.draw_edge_type_buttons(sub, lineset, "suggestive_contour")
238                 self.draw_edge_type_buttons(sub, lineset, "ridge_valley")
239
240                 sub = split.column()
241                 self.draw_edge_type_buttons(sub, lineset, "crease")
242                 self.draw_edge_type_buttons(sub, lineset, "edge_mark")
243                 self.draw_edge_type_buttons(sub, lineset, "external_contour")
244                 self.draw_edge_type_buttons(sub, lineset, "material_boundary")
245
246             if lineset.select_by_face_marks:
247                 col.label(text="Face Marks:")
248                 row = col.row()
249                 row.prop(lineset, "face_mark_negation", expand=True)
250                 row.prop(lineset, "face_mark_condition", expand=True)
251
252             if lineset.select_by_group:
253                 col.label(text="Group:")
254                 row = col.row()
255                 row.prop(lineset, "group", text="")
256                 row.prop(lineset, "group_negation", expand=True)
257
258
259 class RENDERLAYER_PT_freestyle_linestyle(RenderLayerFreestyleEditorButtonsPanel, Panel):
260     bl_label = "Freestyle Line Style"
261     bl_options = {'DEFAULT_CLOSED'}
262     COMPAT_ENGINES = {'BLENDER_RENDER'}
263
264     def draw_modifier_box_header(self, box, modifier):
265         row = box.row()
266         row.context_pointer_set("modifier", modifier)
267         if modifier.expanded:
268             icon = 'TRIA_DOWN'
269         else:
270             icon = 'TRIA_RIGHT'
271         row.prop(modifier, "expanded", text="", icon=icon, emboss=False)
272         # TODO: Use icons rather than text label, would save some room!
273         row.label(text=modifier.rna_type.name)
274         row.prop(modifier, "name", text="")
275         if modifier.use:
276             icon = 'RESTRICT_RENDER_OFF'
277         else:
278             icon = 'RESTRICT_RENDER_ON'
279         row.prop(modifier, "use", text="", icon=icon)
280         sub = row.row(align=True)
281         sub.operator("scene.freestyle_modifier_copy", icon='NONE', text="Copy")
282         sub.operator("scene.freestyle_modifier_move", icon='TRIA_UP', text="").direction = 'UP'
283         sub.operator("scene.freestyle_modifier_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
284         sub.operator("scene.freestyle_modifier_remove", icon='X', text="")
285
286     def draw_modifier_box_error(self, box, modifier, message):
287         row = box.row()
288         row.label(text=message, icon="ERROR")
289
290     def draw_modifier_common(self, box, modifier):
291         row = box.row()
292         row.prop(modifier, "blend", text="")
293         row.prop(modifier, "influence")
294
295     def draw_modifier_color_ramp_common(self, box, modifier, has_range):
296         box.template_color_ramp(modifier, "color_ramp", expand=True)
297         if has_range:
298             row = box.row(align=True)
299             row.prop(modifier, "range_min")
300             row.prop(modifier, "range_max")
301
302     def draw_modifier_curve_common(self, box, modifier, has_range, has_value):
303         row = box.row()
304         row.prop(modifier, "mapping", text="")
305         sub = row.column()
306         sub.prop(modifier, "invert")
307         if modifier.mapping == 'CURVE':
308             sub.active = False
309             box.template_curve_mapping(modifier, "curve")
310         if has_range:
311             row = box.row(align=True)
312             row.prop(modifier, "range_min")
313             row.prop(modifier, "range_max")
314         if has_value:
315             row = box.row(align=True)
316             row.prop(modifier, "value_min")
317             row.prop(modifier, "value_max")
318
319     def draw_color_modifier(self, context, modifier):
320         layout = self.layout
321
322         col = layout.column(align=True)
323         self.draw_modifier_box_header(col.box(), modifier)
324         if modifier.expanded:
325             box = col.box()
326             self.draw_modifier_common(box, modifier)
327
328             if modifier.type == 'ALONG_STROKE':
329                 self.draw_modifier_color_ramp_common(box, modifier, False)
330
331             elif modifier.type == 'DISTANCE_FROM_OBJECT':
332                 box.prop(modifier, "target")
333                 self.draw_modifier_color_ramp_common(box, modifier, True)
334                 prop = box.operator("scene.freestyle_fill_range_by_selection")
335                 prop.type = 'COLOR'
336                 prop.name = modifier.name
337
338             elif modifier.type == 'DISTANCE_FROM_CAMERA':
339                 self.draw_modifier_color_ramp_common(box, modifier, True)
340                 prop = box.operator("scene.freestyle_fill_range_by_selection")
341                 prop.type = 'COLOR'
342                 prop.name = modifier.name
343
344             elif modifier.type == 'MATERIAL':
345                 row = box.row()
346                 row.prop(modifier, "material_attribute", text="")
347                 sub = row.column()
348                 sub.prop(modifier, "use_ramp")
349                 if modifier.material_attribute in {'LINE', 'DIFF', 'SPEC'}:
350                     sub.active = True
351                     show_ramp = modifier.use_ramp
352                 else:
353                     sub.active = False
354                     show_ramp = True
355                 if show_ramp:
356                     self.draw_modifier_color_ramp_common(box, modifier, False)
357
358             elif modifier.type == 'TANGENT':
359                 self.draw_modifier_color_ramp_common(box, modifier, False)
360
361             elif modifier.type == 'NOISE':
362                 self.draw_modifier_color_ramp_common(box, modifier, False)
363                 row = box.row(align=False)
364                 row.prop(modifier, "amplitude")
365                 row.prop(modifier, "period")
366                 row.prop(modifier, "seed")
367
368             elif modifier.type == 'CREASE_ANGLE':
369                 self.draw_modifier_color_ramp_common(box, modifier, False)
370                 row = box.row(align=True)
371                 row.prop(modifier, "angle_min")
372                 row.prop(modifier, "angle_max")
373
374             elif modifier.type == 'CURVATURE_3D':
375                 self.draw_modifier_color_ramp_common(box, modifier, False)
376                 row = box.row(align=True)
377                 row.prop(modifier, "curvature_min")
378                 row.prop(modifier, "curvature_max")
379                 freestyle = context.scene.render.layers.active.freestyle_settings
380                 if not freestyle.use_smoothness:
381                     message = "Enable Face Smoothness to use this modifier"
382                     self.draw_modifier_box_error(col.box(), modifier, message)
383
384     def draw_alpha_modifier(self, context, modifier):
385         layout = self.layout
386
387         col = layout.column(align=True)
388         self.draw_modifier_box_header(col.box(), modifier)
389         if modifier.expanded:
390             box = col.box()
391             self.draw_modifier_common(box, modifier)
392
393             if modifier.type == 'ALONG_STROKE':
394                 self.draw_modifier_curve_common(box, modifier, False, False)
395
396             elif modifier.type == 'DISTANCE_FROM_OBJECT':
397                 box.prop(modifier, "target")
398                 self.draw_modifier_curve_common(box, modifier, True, False)
399                 prop = box.operator("scene.freestyle_fill_range_by_selection")
400                 prop.type = 'ALPHA'
401                 prop.name = modifier.name
402
403             elif modifier.type == 'DISTANCE_FROM_CAMERA':
404                 self.draw_modifier_curve_common(box, modifier, True, False)
405                 prop = box.operator("scene.freestyle_fill_range_by_selection")
406                 prop.type = 'ALPHA'
407                 prop.name = modifier.name
408
409             elif modifier.type == 'MATERIAL':
410                 box.prop(modifier, "material_attribute", text="")
411                 self.draw_modifier_curve_common(box, modifier, False, False)
412
413             elif modifier.type == 'TANGENT':
414                 self.draw_modifier_curve_common(box, modifier, False, False)
415
416             elif modifier.type == 'NOISE':
417                 self.draw_modifier_curve_common(box, modifier, False, False)
418                 row = box.row(align=False)
419                 row.prop(modifier, "amplitude")
420                 row.prop(modifier, "period")
421                 row.prop(modifier, "seed")
422
423             elif modifier.type == 'CREASE_ANGLE':
424                 self.draw_modifier_curve_common(box, modifier, False, False)
425                 row = box.row(align=True)
426                 row.prop(modifier, "angle_min")
427                 row.prop(modifier, "angle_max")
428
429             elif modifier.type == 'CURVATURE_3D':
430                 self.draw_modifier_curve_common(box, modifier, False, False)
431                 row = box.row(align=True)
432                 row.prop(modifier, "curvature_min")
433                 row.prop(modifier, "curvature_max")
434                 freestyle = context.scene.render.layers.active.freestyle_settings
435                 if not freestyle.use_smoothness:
436                     message = "Enable Face Smoothness to use this modifier"
437                     self.draw_modifier_box_error(col.box(), modifier, message)
438
439     def draw_thickness_modifier(self, context, modifier):
440         layout = self.layout
441
442         col = layout.column(align=True)
443         self.draw_modifier_box_header(col.box(), modifier)
444         if modifier.expanded:
445             box = col.box()
446             self.draw_modifier_common(box, modifier)
447
448             if modifier.type == 'ALONG_STROKE':
449                 self.draw_modifier_curve_common(box, modifier, False, True)
450
451             elif modifier.type == 'DISTANCE_FROM_OBJECT':
452                 box.prop(modifier, "target")
453                 self.draw_modifier_curve_common(box, modifier, True, True)
454                 prop = box.operator("scene.freestyle_fill_range_by_selection")
455                 prop.type = 'THICKNESS'
456                 prop.name = modifier.name
457
458             elif modifier.type == 'DISTANCE_FROM_CAMERA':
459                 self.draw_modifier_curve_common(box, modifier, True, True)
460                 prop = box.operator("scene.freestyle_fill_range_by_selection")
461                 prop.type = 'THICKNESS'
462                 prop.name = modifier.name
463
464             elif modifier.type == 'MATERIAL':
465                 box.prop(modifier, "material_attribute", text="")
466                 self.draw_modifier_curve_common(box, modifier, False, True)
467
468             elif modifier.type == 'CALLIGRAPHY':
469                 box.prop(modifier, "orientation")
470                 row = box.row(align=True)
471                 row.prop(modifier, "thickness_min")
472                 row.prop(modifier, "thickness_max")
473
474             elif modifier.type == 'TANGENT':
475                 self.draw_modifier_curve_common(box, modifier, False, False)
476                 self.mapping = 'CURVE'
477                 row = box.row(align=True)
478                 row.prop(modifier, "thickness_min")
479                 row.prop(modifier, "thickness_max")
480
481             elif modifier.type == 'NOISE':
482                 row = box.row(align=False)
483                 row.prop(modifier, "amplitude")
484                 row.prop(modifier, "period")
485                 row = box.row(align=False)
486                 row.prop(modifier, "seed")
487                 row.prop(modifier, "use_asymmetric")
488
489             elif modifier.type == 'CREASE_ANGLE':
490                 self.draw_modifier_curve_common(box, modifier, False, False)
491                 row = box.row(align=True)
492                 row.prop(modifier, "thickness_min")
493                 row.prop(modifier, "thickness_max")
494                 row = box.row(align=True)
495                 row.prop(modifier, "angle_min")
496                 row.prop(modifier, "angle_max")
497
498             elif modifier.type == 'CURVATURE_3D':
499                 self.draw_modifier_curve_common(box, modifier, False, False)
500                 row = box.row(align=True)
501                 row.prop(modifier, "thickness_min")
502                 row.prop(modifier, "thickness_max")
503                 row = box.row(align=True)
504                 row.prop(modifier, "curvature_min")
505                 row.prop(modifier, "curvature_max")
506                 freestyle = context.scene.render.layers.active.freestyle_settings
507                 if not freestyle.use_smoothness:
508                     message = "Enable Face Smoothness to use this modifier"
509                     self.draw_modifier_box_error(col.box(), modifier, message)
510
511     def draw_geometry_modifier(self, context, modifier):
512         layout = self.layout
513
514         col = layout.column(align=True)
515         self.draw_modifier_box_header(col.box(), modifier)
516         if modifier.expanded:
517             box = col.box()
518
519             if modifier.type == 'SAMPLING':
520                 box.prop(modifier, "sampling")
521
522             elif modifier.type == 'BEZIER_CURVE':
523                 box.prop(modifier, "error")
524
525             elif modifier.type == 'SINUS_DISPLACEMENT':
526                 split = box.split()
527                 col = split.column()
528                 col.prop(modifier, "wavelength")
529                 col.prop(modifier, "amplitude")
530                 col = split.column()
531                 col.prop(modifier, "phase")
532
533             elif modifier.type == 'SPATIAL_NOISE':
534                 split = box.split()
535                 col = split.column()
536                 col.prop(modifier, "amplitude")
537                 col.prop(modifier, "scale")
538                 col.prop(modifier, "octaves")
539                 col = split.column()
540                 col.prop(modifier, "smooth")
541                 col.prop(modifier, "use_pure_random")
542
543             elif modifier.type == 'PERLIN_NOISE_1D':
544                 split = box.split()
545                 col = split.column()
546                 col.prop(modifier, "frequency")
547                 col.prop(modifier, "amplitude")
548                 col.prop(modifier, "seed")
549                 col = split.column()
550                 col.prop(modifier, "octaves")
551                 col.prop(modifier, "angle")
552
553             elif modifier.type == 'PERLIN_NOISE_2D':
554                 split = box.split()
555                 col = split.column()
556                 col.prop(modifier, "frequency")
557                 col.prop(modifier, "amplitude")
558                 col.prop(modifier, "seed")
559                 col = split.column()
560                 col.prop(modifier, "octaves")
561                 col.prop(modifier, "angle")
562
563             elif modifier.type == 'BACKBONE_STRETCHER':
564                 box.prop(modifier, "backbone_length")
565
566             elif modifier.type == 'TIP_REMOVER':
567                 box.prop(modifier, "tip_length")
568
569             elif modifier.type == 'POLYGONIZATION':
570                 box.prop(modifier, "error")
571
572             elif modifier.type == 'GUIDING_LINES':
573                 box.prop(modifier, "offset")
574
575             elif modifier.type == 'BLUEPRINT':
576                 row = box.row()
577                 row.prop(modifier, "shape", expand=True)
578                 box.prop(modifier, "rounds")
579                 row = box.row()
580                 if modifier.shape in {'CIRCLES', 'ELLIPSES'}:
581                     row.prop(modifier, "random_radius")
582                     row.prop(modifier, "random_center")
583                 elif modifier.shape == 'SQUARES':
584                     row.prop(modifier, "backbone_length")
585                     row.prop(modifier, "random_backbone")
586
587             elif modifier.type == '2D_OFFSET':
588                 row = box.row(align=True)
589                 row.prop(modifier, "start")
590                 row.prop(modifier, "end")
591                 row = box.row(align=True)
592                 row.prop(modifier, "x")
593                 row.prop(modifier, "y")
594
595             elif modifier.type == '2D_TRANSFORM':
596                 box.prop(modifier, "pivot")
597                 if modifier.pivot == 'PARAM':
598                     box.prop(modifier, "pivot_u")
599                 elif modifier.pivot == 'ABSOLUTE':
600                     row = box.row(align=True)
601                     row.prop(modifier, "pivot_x")
602                     row.prop(modifier, "pivot_y")
603                 row = box.row(align=True)
604                 row.prop(modifier, "scale_x")
605                 row.prop(modifier, "scale_y")
606                 box.prop(modifier, "angle")
607
608             elif modifier.type == 'SIMPLIFICATION':
609                 box.prop(modifier, "tolerance")
610
611     def draw(self, context):
612         layout = self.layout
613
614         rd = context.scene.render
615         rl = rd.layers.active
616         lineset = rl.freestyle_settings.linesets.active
617
618         layout.active = rl.use_freestyle
619
620         if lineset is None:
621             return
622         linestyle = lineset.linestyle
623
624         layout.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new")
625         if linestyle is None:
626             return
627         row = layout.row(align=True)
628         row.prop(linestyle, "panel", expand=True)
629         if linestyle.panel == 'STROKES':
630             ## Chaining
631             layout.prop(linestyle, "use_chaining", text="Chaining:")
632             split = layout.split(align=True)
633             split.active = linestyle.use_chaining
634             # First column
635             col = split.column()
636             col.active = linestyle.use_chaining
637             col.prop(linestyle, "chaining", text="")
638             if linestyle.chaining == 'SKETCHY':
639                 col.prop(linestyle, "rounds")
640             # Second column
641             col = split.column()
642             col.prop(linestyle, "use_same_object")
643
644             ## Splitting
645             layout.label(text="Splitting:")
646             split = layout.split(align=True)
647             # First column
648             col = split.column()
649             row = col.row(align=True)
650             row.prop(linestyle, "use_angle_min", text="")
651             sub = row.row()
652             sub.active = linestyle.use_angle_min
653             sub.prop(linestyle, "angle_min")
654             row = col.row(align=True)
655             row.prop(linestyle, "use_angle_max", text="")
656             sub = row.row()
657             sub.active = linestyle.use_angle_max
658             sub.prop(linestyle, "angle_max")
659             # Second column
660             col = split.column()
661             row = col.row(align=True)
662             row.prop(linestyle, "use_split_length", text="")
663             sub = row.row()
664             sub.active = linestyle.use_split_length
665             sub.prop(linestyle, "split_length", text="2D Length")
666             row = col.row(align=True)
667             row.prop(linestyle, "material_boundary")
668             # End of columns
669             row = layout.row(align=True)
670             row.prop(linestyle, "use_split_pattern", text="")
671             sub = row.row(align=True)
672             sub.active = linestyle.use_split_pattern
673             sub.prop(linestyle, "split_dash1", text="D1")
674             sub.prop(linestyle, "split_gap1", text="G1")
675             sub.prop(linestyle, "split_dash2", text="D2")
676             sub.prop(linestyle, "split_gap2", text="G2")
677             sub.prop(linestyle, "split_dash3", text="D3")
678             sub.prop(linestyle, "split_gap3", text="G3")
679
680             ## Sorting
681             layout.prop(linestyle, "use_sorting", text="Sorting:")
682             col = layout.column()
683             col.active = linestyle.use_sorting
684             row = col.row(align=True)
685             row.prop(linestyle, "sort_key", text="")
686             sub = row.row()
687             sub.active = linestyle.sort_key in {'DISTANCE_FROM_CAMERA',
688                                                 'PROJECTED_X',
689                                                 'PROJECTED_Y'}
690             sub.prop(linestyle, "integration_type", text="")
691             row = col.row(align=True)
692             row.prop(linestyle, "sort_order", expand=True)
693
694             ## Selection
695             layout.label(text="Selection:")
696             split = layout.split(align=True)
697             # First column
698             col = split.column()
699             row = col.row(align=True)
700             row.prop(linestyle, "use_length_min", text="")
701             sub = row.row()
702             sub.active = linestyle.use_length_min
703             sub.prop(linestyle, "length_min")
704             row = col.row(align=True)
705             row.prop(linestyle, "use_length_max", text="")
706             sub = row.row()
707             sub.active = linestyle.use_length_max
708             sub.prop(linestyle, "length_max")
709             # Second column
710             col = split.column()
711             row = col.row(align=True)
712             row.prop(linestyle, "use_chain_count", text="")
713             sub = row.row()
714             sub.active = linestyle.use_chain_count
715             sub.prop(linestyle, "chain_count")
716
717             ## Caps
718             layout.label(text="Caps:")
719             row = layout.row(align=True)
720             row.prop(linestyle, "caps", expand=True)
721
722             ## Dashed lines
723             layout.prop(linestyle, "use_dashed_line", text="Dashed Line:")
724             row = layout.row(align=True)
725             row.active = linestyle.use_dashed_line
726             row.prop(linestyle, "dash1", text="D1")
727             row.prop(linestyle, "gap1", text="G1")
728             row.prop(linestyle, "dash2", text="D2")
729             row.prop(linestyle, "gap2", text="G2")
730             row.prop(linestyle, "dash3", text="D3")
731             row.prop(linestyle, "gap3", text="G3")
732
733         elif linestyle.panel == 'COLOR':
734             col = layout.column()
735             row = col.row()
736             row.label(text="Base Color:")
737             row.prop(linestyle, "color", text="")
738             col.label(text="Modifiers:")
739             col.operator_menu_enum("scene.freestyle_color_modifier_add", "type", text="Add Modifier")
740             for modifier in linestyle.color_modifiers:
741                 self.draw_color_modifier(context, modifier)
742
743         elif linestyle.panel == 'ALPHA':
744             col = layout.column()
745             row = col.row()
746             row.label(text="Base Transparency:")
747             row.prop(linestyle, "alpha")
748             col.label(text="Modifiers:")
749             col.operator_menu_enum("scene.freestyle_alpha_modifier_add", "type", text="Add Modifier")
750             for modifier in linestyle.alpha_modifiers:
751                 self.draw_alpha_modifier(context, modifier)
752
753         elif linestyle.panel == 'THICKNESS':
754             col = layout.column()
755             row = col.row()
756             row.label(text="Base Thickness:")
757             row.prop(linestyle, "thickness")
758             subcol = col.column()
759             subcol.active = linestyle.chaining == 'PLAIN' and linestyle.use_same_object
760             row = subcol.row()
761             row.prop(linestyle, "thickness_position", expand=True)
762             row = subcol.row()
763             row.prop(linestyle, "thickness_ratio")
764             row.active = (linestyle.thickness_position == 'RELATIVE')
765             col = layout.column()
766             col.label(text="Modifiers:")
767             col.operator_menu_enum("scene.freestyle_thickness_modifier_add", "type", text="Add Modifier")
768             for modifier in linestyle.thickness_modifiers:
769                 self.draw_thickness_modifier(context, modifier)
770
771         elif linestyle.panel == 'GEOMETRY':
772             col = layout.column()
773             col.label(text="Modifiers:")
774             col.operator_menu_enum("scene.freestyle_geometry_modifier_add", "type", text="Add Modifier")
775             for modifier in linestyle.geometry_modifiers:
776                 self.draw_geometry_modifier(context, modifier)
777
778         elif linestyle.panel == 'TEXTURE':
779             layout.separator()
780
781             row = layout.row()
782             if rd.use_shading_nodes:
783                 row.prop(linestyle, "use_nodes")
784             else:
785                 row.prop(linestyle, "use_texture")
786             row.prop(linestyle, "texture_spacing", text="Spacing Along Stroke")
787
788             row = layout.row()
789             props = row.operator(
790                     "wm.properties_context_change",
791                     text="Go to Linestyle Textures Properties",
792                     icon='TEXTURE')
793             props.context = 'TEXTURE'
794
795         elif linestyle.panel == 'MISC':
796             pass
797
798
799 # Material properties
800
801 class MaterialFreestyleButtonsPanel:
802     bl_space_type = 'PROPERTIES'
803     bl_region_type = 'WINDOW'
804     bl_context = "material"
805     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
806
807     @classmethod
808     def poll(cls, context):
809         scene = context.scene
810         material = context.material
811         with_freestyle = bpy.app.build_options.freestyle
812         return with_freestyle and material and scene and scene.render.use_freestyle and \
813             (scene.render.engine in cls.COMPAT_ENGINES)
814
815
816 class MATERIAL_PT_freestyle_line(MaterialFreestyleButtonsPanel, Panel):
817     bl_label = "Freestyle Line"
818     bl_options = {'DEFAULT_CLOSED'}
819     COMPAT_ENGINES = {'BLENDER_RENDER'}
820
821     def draw(self, context):
822         layout = self.layout
823
824         mat = context.material
825
826         row = layout.row()
827         row.prop(mat, "line_color", text="")
828         row.prop(mat, "line_priority", text="Priority")
829
830
831 classes = (
832     MATERIAL_PT_freestyle_line,
833     RENDERLAYER_PT_freestyle,
834     RENDERLAYER_PT_freestyle_lineset,
835     RENDERLAYER_PT_freestyle_linestyle,
836     RENDERLAYER_UL_linesets,
837     RENDER_MT_lineset_specials,
838     RENDER_PT_freestyle,
839 )
840
841 if __name__ == "__main__":  # only for live edit.
842     from bpy.utils import register_class
843     for cls in classes:
844         register_class(cls)