Code cleanup: unused python vars & imports
[blender-staging.git] / release / scripts / startup / bl_ui / properties_particle.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 Panel
22 from rna_prop_ui import PropertyPanel
23 from bpy.app.translations import pgettext_iface as iface_
24
25 from bl_ui.properties_physics_common import (point_cache_ui,
26                                              effector_weights_ui,
27                                              basic_force_field_settings_ui,
28                                              basic_force_field_falloff_ui,
29                                              )
30
31
32 def particle_panel_enabled(context, psys):
33     if psys is None:
34         return True
35     phystype = psys.settings.physics_type
36     if psys.settings.type in {'EMITTER', 'REACTOR'} and phystype in {'NO', 'KEYED'}:
37         return True
38     else:
39         return (psys.point_cache.is_baked is False) and (not psys.is_edited) and (not context.particle_system_editable)
40
41
42 def particle_panel_poll(cls, context):
43     psys = context.particle_system
44     engine = context.scene.render.engine
45     settings = 0
46
47     if psys:
48         settings = psys.settings
49     elif isinstance(context.space_data.pin_id, bpy.types.ParticleSettings):
50         settings = context.space_data.pin_id
51
52     if not settings:
53         return False
54
55     return settings.is_fluid is False and (engine in cls.COMPAT_ENGINES)
56
57
58 def particle_get_settings(context):
59     if context.particle_system:
60         return context.particle_system.settings
61     elif isinstance(context.space_data.pin_id, bpy.types.ParticleSettings):
62         return context.space_data.pin_id
63     return None
64
65
66 class ParticleButtonsPanel():
67     bl_space_type = 'PROPERTIES'
68     bl_region_type = 'WINDOW'
69     bl_context = "particle"
70
71     @classmethod
72     def poll(cls, context):
73         return particle_panel_poll(cls, context)
74
75
76 class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
77     bl_label = ""
78     bl_options = {'HIDE_HEADER'}
79     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
80
81     @classmethod
82     def poll(cls, context):
83         engine = context.scene.render.engine
84         return (context.particle_system or context.object or context.space_data.pin_id) and (engine in cls.COMPAT_ENGINES)
85
86     def draw(self, context):
87         layout = self.layout
88
89         if context.scene.render.engine == 'BLENDER_GAME':
90             layout.label("Not available in the Game Engine")
91             return
92
93         ob = context.object
94         psys = context.particle_system
95         part = 0
96
97         if ob:
98             row = layout.row()
99
100             row.template_list("UI_UL_list", "particle_systems", ob, "particle_systems",
101                               ob.particle_systems, "active_index", rows=1)
102
103             col = row.column(align=True)
104             col.operator("object.particle_system_add", icon='ZOOMIN', text="")
105             col.operator("object.particle_system_remove", icon='ZOOMOUT', text="")
106
107         if psys is None:
108             part = particle_get_settings(context)
109
110             layout.operator("object.particle_system_add", icon='ZOOMIN', text="New")
111
112             if part is None:
113                 return
114
115             layout.template_ID(context.space_data, "pin_id")
116
117             if part.is_fluid:
118                 layout.label(text="Settings used for fluid")
119                 return
120
121             layout.prop(part, "type", text="Type")
122
123         elif not psys.settings:
124             split = layout.split(percentage=0.32)
125
126             col = split.column()
127             col.label(text="Settings:")
128
129             col = split.column()
130             col.template_ID(psys, "settings", new="particle.new")
131         else:
132             part = psys.settings
133
134             split = layout.split(percentage=0.32)
135             col = split.column()
136             if part.is_fluid is False:
137                 col.label(text="Settings:")
138                 col.label(text="Type:")
139
140             col = split.column()
141             if part.is_fluid is False:
142                 row = col.row()
143                 row.enabled = particle_panel_enabled(context, psys)
144                 row.template_ID(psys, "settings", new="particle.new")
145
146             if part.is_fluid:
147                 layout.label(text=iface_("%d fluid particles for this frame") % part.count, translate=False)
148                 return
149
150             row = col.row()
151             row.enabled = particle_panel_enabled(context, psys)
152             row.prop(part, "type", text="")
153             row.prop(psys, "seed")
154
155         if part:
156             split = layout.split(percentage=0.65)
157             if part.type == 'HAIR':
158                 if psys is not None and psys.is_edited:
159                     split.operator("particle.edited_clear", text="Free Edit")
160                 else:
161                     row = split.row()
162                     row.enabled = particle_panel_enabled(context, psys)
163                     row.prop(part, "regrow_hair")
164                     row.prop(part, "use_advanced_hair")
165                 row = split.row()
166                 row.enabled = particle_panel_enabled(context, psys)
167                 row.prop(part, "hair_step")
168                 if psys is not None and psys.is_edited:
169                     if psys.is_global_hair:
170                         layout.operator("particle.connect_hair")
171                     else:
172                         layout.operator("particle.disconnect_hair")
173             elif psys is not None and part.type == 'REACTOR':
174                 split.enabled = particle_panel_enabled(context, psys)
175                 split.prop(psys, "reactor_target_object")
176                 split.prop(psys, "reactor_target_particle_system", text="Particle System")
177
178
179 class PARTICLE_PT_emission(ParticleButtonsPanel, Panel):
180     bl_label = "Emission"
181     COMPAT_ENGINES = {'BLENDER_RENDER'}
182
183     @classmethod
184     def poll(cls, context):
185         psys = context.particle_system
186         settings = particle_get_settings(context)
187
188         if settings is None:
189             return False
190         if settings.is_fluid:
191             return False
192         if particle_panel_poll(PARTICLE_PT_emission, context):
193             return psys is None or not context.particle_system.point_cache.use_external
194         return False
195
196     def draw(self, context):
197         layout = self.layout
198
199         psys = context.particle_system
200         part = particle_get_settings(context)
201
202         layout.enabled = particle_panel_enabled(context, psys) and (psys is None or not psys.has_multiple_caches)
203
204         row = layout.row()
205         row.active = part.distribution != 'GRID'
206         row.prop(part, "count")
207
208         if part.type == 'HAIR':
209             row.prop(part, "hair_length")
210             if not part.use_advanced_hair:
211                 row = layout.row()
212                 row.prop(part, "use_modifier_stack")
213                 return
214
215         if part.type != 'HAIR':
216             split = layout.split()
217
218             col = split.column(align=True)
219             col.prop(part, "frame_start")
220             col.prop(part, "frame_end")
221
222             col = split.column(align=True)
223             col.prop(part, "lifetime")
224             col.prop(part, "lifetime_random", slider=True)
225
226         layout.label(text="Emit From:")
227         layout.prop(part, "emit_from", expand=True)
228
229         row = layout.row()
230         if part.emit_from == 'VERT':
231             row.prop(part, "use_emit_random")
232         elif part.distribution == 'GRID':
233             row.prop(part, "invert_grid")
234             row.prop(part, "hexagonal_grid")
235         else:
236             row.prop(part, "use_emit_random")
237             row.prop(part, "use_even_distribution")
238
239         if part.emit_from == 'FACE' or part.emit_from == 'VOLUME':
240             layout.prop(part, "distribution", expand=True)
241
242             row = layout.row()
243             if part.distribution == 'JIT':
244                 row.prop(part, "userjit", text="Particles/Face")
245                 row.prop(part, "jitter_factor", text="Jittering Amount", slider=True)
246             elif part.distribution == 'GRID':
247                 row.prop(part, "grid_resolution")
248                 row.prop(part, "grid_random", text="Random", slider=True)
249
250         row = layout.row()
251         row.prop(part, "use_modifier_stack")
252
253
254 class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
255     bl_label = "Hair dynamics"
256     bl_options = {'DEFAULT_CLOSED'}
257     COMPAT_ENGINES = {'BLENDER_RENDER'}
258
259     @classmethod
260     def poll(cls, context):
261         psys = context.particle_system
262         engine = context.scene.render.engine
263         if psys is None:
264             return False
265         if psys.settings is None:
266             return False
267         return psys.settings.type == 'HAIR' and (engine in cls.COMPAT_ENGINES)
268
269     def draw_header(self, context):
270         psys = context.particle_system
271         self.layout.prop(psys, "use_hair_dynamics", text="")
272
273     def draw(self, context):
274         layout = self.layout
275
276         psys = context.particle_system
277
278         if not psys.cloth:
279             return
280
281         cloth = psys.cloth.settings
282
283         layout.enabled = psys.use_hair_dynamics and psys.point_cache.is_baked is False
284
285         split = layout.split()
286
287         col = split.column()
288         col.label(text="Material:")
289         sub = col.column(align=True)
290         sub.prop(cloth, "pin_stiffness", text="Stiffness")
291         sub.prop(cloth, "mass")
292         sub.prop(cloth, "bending_stiffness", text="Bending")
293         sub.prop(cloth, "internal_friction", slider=True)
294         sub.prop(cloth, "collider_friction", slider=True)
295
296         col = split.column()
297         col.label(text="Damping:")
298         sub = col.column(align=True)
299         sub.prop(cloth, "spring_damping", text="Spring")
300         sub.prop(cloth, "air_damping", text="Air")
301
302         col.label(text="Quality:")
303         col.prop(cloth, "quality", text="Steps", slider=True)
304
305
306 class PARTICLE_PT_cache(ParticleButtonsPanel, Panel):
307     bl_label = "Cache"
308     bl_options = {'DEFAULT_CLOSED'}
309     COMPAT_ENGINES = {'BLENDER_RENDER'}
310
311     @classmethod
312     def poll(cls, context):
313         psys = context.particle_system
314         engine = context.scene.render.engine
315         if psys is None:
316             return False
317         if psys.settings is None:
318             return False
319         if psys.settings.is_fluid:
320             return False
321         phystype = psys.settings.physics_type
322         if phystype == 'NO' or phystype == 'KEYED':
323             return False
324         return (psys.settings.type in {'EMITTER', 'REACTOR'} or (psys.settings.type == 'HAIR' and (psys.use_hair_dynamics or psys.point_cache.is_baked))) and engine in cls.COMPAT_ENGINES
325
326     def draw(self, context):
327         psys = context.particle_system
328
329         point_cache_ui(self, context, psys.point_cache, True, 'HAIR' if (psys.settings.type == 'HAIR') else 'PSYS')
330
331
332 class PARTICLE_PT_velocity(ParticleButtonsPanel, Panel):
333     bl_label = "Velocity"
334     COMPAT_ENGINES = {'BLENDER_RENDER'}
335
336     @classmethod
337     def poll(cls, context):
338         if particle_panel_poll(PARTICLE_PT_velocity, context):
339             psys = context.particle_system
340             settings = particle_get_settings(context)
341
342             if settings.type == 'HAIR' and not settings.use_advanced_hair:
343                 return False
344             return settings.physics_type != 'BOIDS' and (psys is None or not psys.point_cache.use_external)
345         else:
346             return False
347
348     def draw(self, context):
349         layout = self.layout
350
351         psys = context.particle_system
352         part = particle_get_settings(context)
353
354         layout.enabled = particle_panel_enabled(context, psys)
355
356         split = layout.split()
357
358         col = split.column()
359         col.label(text="Emitter Geometry:")
360         col.prop(part, "normal_factor")
361         sub = col.column(align=True)
362         sub.prop(part, "tangent_factor")
363         sub.prop(part, "tangent_phase", slider=True)
364
365         col = split.column()
366         col.label(text="Emitter Object:")
367         col.prop(part, "object_align_factor", text="")
368
369         layout.label(text="Other:")
370         row = layout.row()
371         if part.emit_from == 'PARTICLE':
372             row.prop(part, "particle_factor")
373         else:
374             row.prop(part, "object_factor", slider=True)
375         row.prop(part, "factor_random")
376
377         #if part.type=='REACTOR':
378         #    sub.prop(part, "reactor_factor")
379         #    sub.prop(part, "reaction_shape", slider=True)
380
381
382 class PARTICLE_PT_rotation(ParticleButtonsPanel, Panel):
383     bl_label = "Rotation"
384     bl_options = {'DEFAULT_CLOSED'}
385     COMPAT_ENGINES = {'BLENDER_RENDER'}
386
387     @classmethod
388     def poll(cls, context):
389         if particle_panel_poll(PARTICLE_PT_rotation, context):
390             psys = context.particle_system
391             settings = particle_get_settings(context)
392
393             if settings.type == 'HAIR' and not settings.use_advanced_hair:
394                 return False
395             return settings.physics_type != 'BOIDS' and (psys is None or not psys.point_cache.use_external)
396         else:
397             return False
398
399     def draw_header(self, context):
400         psys = context.particle_system
401         if psys:
402             part = psys.settings
403         else:
404             part = context.space_data.pin_id
405
406         self.layout.prop(part, "use_rotations", text="")
407
408     def draw(self, context):
409         layout = self.layout
410
411         psys = context.particle_system
412         if psys:
413             part = psys.settings
414         else:
415             part = context.space_data.pin_id
416
417         layout.enabled = particle_panel_enabled(context, psys) and part.use_rotations
418
419         layout.label(text="Initial Orientation:")
420
421         split = layout.split()
422
423         col = split.column(align=True)
424         col.prop(part, "rotation_mode", text="")
425         col.prop(part, "rotation_factor_random", slider=True, text="Random")
426
427         col = split.column(align=True)
428         col.prop(part, "phase_factor", slider=True)
429         col.prop(part, "phase_factor_random", text="Random", slider=True)
430
431         if part.type != 'HAIR':
432             layout.label(text="Angular Velocity:")
433
434             split = layout.split()
435
436             col = split.column(align=True)
437             col.prop(part, "angular_velocity_mode", text="")
438             sub = col.column(align=True)
439             sub.active = part.angular_velocity_mode != 'NONE'
440             sub.prop(part, "angular_velocity_factor", text="")
441
442             col = split.column()
443             col.prop(part, "use_dynamic_rotation")
444
445
446 class PARTICLE_PT_physics(ParticleButtonsPanel, Panel):
447     bl_label = "Physics"
448     COMPAT_ENGINES = {'BLENDER_RENDER'}
449
450     @classmethod
451     def poll(cls, context):
452         if particle_panel_poll(PARTICLE_PT_physics, context):
453             psys = context.particle_system
454             settings = particle_get_settings(context)
455
456             if settings.type == 'HAIR' and not settings.use_advanced_hair:
457                 return False
458             return psys is None or not psys.point_cache.use_external
459         else:
460             return False
461
462     def draw(self, context):
463         layout = self.layout
464
465         psys = context.particle_system
466         part = particle_get_settings(context)
467
468         layout.enabled = particle_panel_enabled(context, psys)
469
470         layout.prop(part, "physics_type", expand=True)
471
472         row = layout.row()
473         col = row.column(align=True)
474         col.prop(part, "particle_size")
475         col.prop(part, "size_random", slider=True)
476
477         if part.physics_type != 'NO':
478             col = row.column(align=True)
479             col.prop(part, "mass")
480             col.prop(part, "use_multiply_size_mass", text="Multiply mass with size")
481
482         if part.physics_type in {'NEWTON', 'FLUID'}:
483             split = layout.split()
484
485             col = split.column()
486             col.label(text="Forces:")
487             col.prop(part, "brownian_factor")
488             col.prop(part, "drag_factor", slider=True)
489             col.prop(part, "damping", slider=True)
490
491             col = split.column()
492             col.label(text="Integration:")
493             col.prop(part, "integrator", text="")
494             col.prop(part, "timestep")
495             sub = col.row()
496             sub.prop(part, "subframes")
497             supports_courant = part.physics_type == 'FLUID'
498             subsub = sub.row()
499             subsub.enabled = supports_courant
500             subsub.prop(part, "use_adaptive_subframes", text="")
501             if supports_courant and part.use_adaptive_subframes:
502                 col.prop(part, "courant_target", text="Threshold")
503
504             row = layout.row()
505             row.prop(part, "use_size_deflect")
506             row.prop(part, "use_die_on_collision")
507
508             if part.physics_type == 'FLUID':
509                 fluid = part.fluid
510
511                 split = layout.split()
512                 sub = split.row()
513                 sub.prop(fluid, "solver", expand=True)
514
515                 split = layout.split()
516
517                 col = split.column()
518                 col.label(text="Fluid properties:")
519                 col.prop(fluid, "stiffness", text="Stiffness")
520                 col.prop(fluid, "linear_viscosity", text="Viscosity")
521                 col.prop(fluid, "buoyancy", text="Buoyancy", slider=True)
522
523                 col = split.column()
524                 col.label(text="Advanced:")
525
526                 if fluid.solver == 'DDR':
527                     sub = col.row()
528                     sub.prop(fluid, "repulsion", slider=fluid.factor_repulsion)
529                     sub.prop(fluid, "factor_repulsion", text="")
530
531                     sub = col.row()
532                     sub.prop(fluid, "stiff_viscosity", slider=fluid.factor_stiff_viscosity)
533                     sub.prop(fluid, "factor_stiff_viscosity", text="")
534
535                 sub = col.row()
536                 sub.prop(fluid, "fluid_radius", slider=fluid.factor_radius)
537                 sub.prop(fluid, "factor_radius", text="")
538
539                 sub = col.row()
540                 sub.prop(fluid, "rest_density", slider=fluid.use_factor_density)
541                 sub.prop(fluid, "use_factor_density", text="")
542
543                 if fluid.solver == 'CLASSICAL':
544                     # With the classical solver, it is possible to calculate the
545                     # spacing between particles when the fluid is at rest. This
546                     # makes it easier to set stable initial conditions.
547                     particle_volume = part.mass / fluid.rest_density
548                     spacing = pow(particle_volume, 1.0 / 3.0)
549                     sub = col.row()
550                     sub.label(text="Spacing: %g" % spacing)
551
552                 elif fluid.solver == 'DDR':
553                     split = layout.split()
554
555                     col = split.column()
556                     col.label(text="Springs:")
557                     col.prop(fluid, "spring_force", text="Force")
558                     col.prop(fluid, "use_viscoelastic_springs")
559                     sub = col.column(align=True)
560                     sub.active = fluid.use_viscoelastic_springs
561                     sub.prop(fluid, "yield_ratio", slider=True)
562                     sub.prop(fluid, "plasticity", slider=True)
563
564                     col = split.column()
565                     col.label(text="Advanced:")
566                     sub = col.row()
567                     sub.prop(fluid, "rest_length", slider=fluid.factor_rest_length)
568                     sub.prop(fluid, "factor_rest_length", text="")
569                     col.label(text="")
570                     sub = col.column()
571                     sub.active = fluid.use_viscoelastic_springs
572                     sub.prop(fluid, "use_initial_rest_length")
573                     sub.prop(fluid, "spring_frames", text="Frames")
574
575         elif part.physics_type == 'KEYED':
576             split = layout.split()
577             sub = split.column()
578
579             row = layout.row()
580             col = row.column()
581             col.active = not psys.use_keyed_timing
582             col.prop(part, "keyed_loops", text="Loops")
583             if psys:
584                 row.prop(psys, "use_keyed_timing", text="Use Timing")
585
586             layout.label(text="Keys:")
587         elif part.physics_type == 'BOIDS':
588             boids = part.boids
589
590             row = layout.row()
591             row.prop(boids, "use_flight")
592             row.prop(boids, "use_land")
593             row.prop(boids, "use_climb")
594
595             split = layout.split()
596
597             col = split.column(align=True)
598             col.active = boids.use_flight
599             col.prop(boids, "air_speed_max")
600             col.prop(boids, "air_speed_min", slider=True)
601             col.prop(boids, "air_acc_max", slider=True)
602             col.prop(boids, "air_ave_max", slider=True)
603             col.prop(boids, "air_personal_space")
604             row = col.row(align=True)
605             row.active = (boids.use_land or boids.use_climb) and boids.use_flight
606             row.prop(boids, "land_smooth")
607
608             col = split.column(align=True)
609             col.active = boids.use_land or boids.use_climb
610             col.prop(boids, "land_speed_max")
611             col.prop(boids, "land_jump_speed")
612             col.prop(boids, "land_acc_max", slider=True)
613             col.prop(boids, "land_ave_max", slider=True)
614             col.prop(boids, "land_personal_space")
615             col.prop(boids, "land_stick_force")
616
617             split = layout.split()
618
619             col = split.column(align=True)
620             col.label(text="Battle:")
621             col.prop(boids, "health")
622             col.prop(boids, "strength")
623             col.prop(boids, "aggression")
624             col.prop(boids, "accuracy")
625             col.prop(boids, "range")
626
627             col = split.column()
628             col.label(text="Misc:")
629             col.prop(boids, "bank", slider=True)
630             col.prop(boids, "pitch", slider=True)
631             col.prop(boids, "height", slider=True)
632
633         if psys and part.physics_type in {'KEYED', 'BOIDS', 'FLUID'}:
634             if part.physics_type == 'BOIDS':
635                 layout.label(text="Relations:")
636             elif part.physics_type == 'FLUID':
637                 layout.label(text="Fluid interaction:")
638
639             row = layout.row()
640             row.template_list("UI_UL_list", "particle_targets", psys, "targets", psys, "active_particle_target_index", rows=4)
641
642             col = row.column()
643             sub = col.row()
644             subsub = sub.column(align=True)
645             subsub.operator("particle.new_target", icon='ZOOMIN', text="")
646             subsub.operator("particle.target_remove", icon='ZOOMOUT', text="")
647             sub = col.row()
648             subsub = sub.column(align=True)
649             subsub.operator("particle.target_move_up", icon='MOVE_UP_VEC', text="")
650             subsub.operator("particle.target_move_down", icon='MOVE_DOWN_VEC', text="")
651
652             key = psys.active_particle_target
653             if key:
654                 row = layout.row()
655                 if part.physics_type == 'KEYED':
656                     col = row.column()
657                     #doesn't work yet
658                     #col.alert = key.valid
659                     col.prop(key, "object", text="")
660                     col.prop(key, "system", text="System")
661                     col = row.column()
662                     col.active = psys.use_keyed_timing
663                     col.prop(key, "time")
664                     col.prop(key, "duration")
665                 elif part.physics_type == 'BOIDS':
666                     sub = row.row()
667                     #doesn't work yet
668                     #sub.alert = key.valid
669                     sub.prop(key, "object", text="")
670                     sub.prop(key, "system", text="System")
671
672                     layout.prop(key, "alliance", expand=True)
673                 elif part.physics_type == 'FLUID':
674                     sub = row.row()
675                     #doesn't work yet
676                     #sub.alert = key.valid
677                     sub.prop(key, "object", text="")
678                     sub.prop(key, "system", text="System")
679
680
681 class PARTICLE_PT_boidbrain(ParticleButtonsPanel, Panel):
682     bl_label = "Boid Brain"
683     COMPAT_ENGINES = {'BLENDER_RENDER'}
684
685     @classmethod
686     def poll(cls, context):
687         psys = context.particle_system
688         settings = particle_get_settings(context)
689         engine = context.scene.render.engine
690
691         if settings is None:
692             return False
693         if psys is not None and psys.point_cache.use_external:
694             return False
695         return settings.physics_type == 'BOIDS' and engine in cls.COMPAT_ENGINES
696
697     def draw(self, context):
698         layout = self.layout
699
700         boids = particle_get_settings(context).boids
701
702         layout.enabled = particle_panel_enabled(context, context.particle_system)
703
704         # Currently boids can only use the first state so these are commented out for now.
705         #row = layout.row()
706         #row.template_list("UI_UL_list", "particle_boids", boids, "states",
707         #                  boids, "active_boid_state_index", compact="True")
708         #col = row.row()
709         #sub = col.row(align=True)
710         #sub.operator("boid.state_add", icon='ZOOMIN', text="")
711         #sub.operator("boid.state_del", icon='ZOOMOUT', text="")
712         #sub = row.row(align=True)
713         #sub.operator("boid.state_move_up", icon='MOVE_UP_VEC', text="")
714         #sub.operator("boid.state_move_down", icon='MOVE_DOWN_VEC', text="")
715
716         state = boids.active_boid_state
717
718         #layout.prop(state, "name", text="State name")
719
720         row = layout.row()
721         row.prop(state, "ruleset_type")
722         if state.ruleset_type == 'FUZZY':
723             row.prop(state, "rule_fuzzy", slider=True)
724         else:
725             row.label(text="")
726
727         row = layout.row()
728         row.template_list("UI_UL_list", "particle_boids_rules", state, "rules", state, "active_boid_rule_index", rows=4)
729
730         col = row.column()
731         sub = col.row()
732         subsub = sub.column(align=True)
733         subsub.operator_menu_enum("boid.rule_add", "type", icon='ZOOMIN', text="")
734         subsub.operator("boid.rule_del", icon='ZOOMOUT', text="")
735         sub = col.row()
736         subsub = sub.column(align=True)
737         subsub.operator("boid.rule_move_up", icon='MOVE_UP_VEC', text="")
738         subsub.operator("boid.rule_move_down", icon='MOVE_DOWN_VEC', text="")
739
740         rule = state.active_boid_rule
741
742         if rule:
743             row = layout.row()
744             row.prop(rule, "name", text="")
745             #somebody make nice icons for boids here please! -jahka
746             row.prop(rule, "use_in_air", icon='MOVE_UP_VEC', text="")
747             row.prop(rule, "use_on_land", icon='MOVE_DOWN_VEC', text="")
748
749             row = layout.row()
750
751             if rule.type == 'GOAL':
752                 row.prop(rule, "object")
753                 row = layout.row()
754                 row.prop(rule, "use_predict")
755             elif rule.type == 'AVOID':
756                 row.prop(rule, "object")
757                 row = layout.row()
758                 row.prop(rule, "use_predict")
759                 row.prop(rule, "fear_factor")
760             elif rule.type == 'FOLLOW_PATH':
761                 row.label(text="Not yet functional")
762             elif rule.type == 'AVOID_COLLISION':
763                 row.prop(rule, "use_avoid")
764                 row.prop(rule, "use_avoid_collision")
765                 row.prop(rule, "look_ahead")
766             elif rule.type == 'FOLLOW_LEADER':
767                 row.prop(rule, "object", text="")
768                 row.prop(rule, "distance")
769                 row = layout.row()
770                 row.prop(rule, "use_line")
771                 sub = row.row()
772                 sub.active = rule.line
773                 sub.prop(rule, "queue_count")
774             elif rule.type == 'AVERAGE_SPEED':
775                 row.prop(rule, "speed", slider=True)
776                 row.prop(rule, "wander", slider=True)
777                 row.prop(rule, "level", slider=True)
778             elif rule.type == 'FIGHT':
779                 row.prop(rule, "distance")
780                 row.prop(rule, "flee_distance")
781
782
783 class PARTICLE_PT_render(ParticleButtonsPanel, Panel):
784     bl_label = "Render"
785     COMPAT_ENGINES = {'BLENDER_RENDER'}
786
787     @classmethod
788     def poll(cls, context):
789         settings = particle_get_settings(context)
790         engine = context.scene.render.engine
791         if settings is None:
792             return False
793
794         return engine in cls.COMPAT_ENGINES
795
796     def draw(self, context):
797         layout = self.layout
798
799         psys = context.particle_system
800         part = particle_get_settings(context)
801
802         if psys:
803             row = layout.row()
804             if part.render_type in {'OBJECT', 'GROUP'}:
805                 row.enabled = False
806             row.prop(part, "material_slot", text="")
807             row.prop(psys, "parent")
808
809         split = layout.split()
810
811         col = split.column()
812         col.prop(part, "use_render_emitter")
813         col.prop(part, "use_parent_particles")
814
815         col = split.column()
816         col.prop(part, "show_unborn")
817         col.prop(part, "use_dead")
818
819         layout.prop(part, "render_type", expand=True)
820
821         split = layout.split()
822
823         col = split.column()
824
825         if part.render_type == 'LINE':
826             col.prop(part, "line_length_tail")
827             col.prop(part, "line_length_head")
828
829             split.prop(part, "use_velocity_length")
830         elif part.render_type == 'PATH':
831             col.prop(part, "use_strand_primitive")
832             sub = col.column()
833             sub.active = (part.use_strand_primitive is False)
834             sub.prop(part, "use_render_adaptive")
835             sub = col.column()
836             sub.active = part.use_render_adaptive or part.use_strand_primitive is True
837             sub.prop(part, "adaptive_angle")
838             sub = col.column()
839             sub.active = (part.use_render_adaptive is True and part.use_strand_primitive is False)
840             sub.prop(part, "adaptive_pixel")
841             col.prop(part, "use_hair_bspline")
842             col.prop(part, "render_step", text="Steps")
843
844             col = split.column()
845             col.label(text="Timing:")
846             col.prop(part, "use_absolute_path_time")
847
848             if part.type == 'HAIR' or psys.point_cache.is_baked:
849                 col.prop(part, "path_start", text="Start", slider=not part.use_absolute_path_time)
850             else:
851                 col.prop(part, "trail_count")
852
853             col.prop(part, "path_end", text="End", slider=not part.use_absolute_path_time)
854             col.prop(part, "length_random", text="Random", slider=True)
855
856             row = layout.row()
857             col = row.column()
858
859             if part.type == 'HAIR' and part.use_strand_primitive is True and part.child_type == 'INTERPOLATED':
860                 layout.prop(part, "use_simplify")
861                 if part.use_simplify is True:
862                     row = layout.row()
863                     row.prop(part, "simplify_refsize")
864                     row.prop(part, "simplify_rate")
865                     row.prop(part, "simplify_transition")
866                     row = layout.row()
867                     row.prop(part, "use_simplify_viewport")
868                     sub = row.row()
869                     sub.active = part.use_simplify_viewport is True
870                     sub.prop(part, "simplify_viewport")
871
872         elif part.render_type == 'OBJECT':
873             col.prop(part, "dupli_object")
874             sub = col.row()
875             sub.prop(part, "use_global_dupli")
876             sub.prop(part, "use_rotation_dupli")
877             sub.prop(part, "use_scale_dupli")
878         elif part.render_type == 'GROUP':
879             col.prop(part, "dupli_group")
880             split = layout.split()
881
882             col = split.column()
883             col.prop(part, "use_whole_group")
884             sub = col.column()
885             sub.active = (part.use_whole_group is False)
886             sub.prop(part, "use_group_pick_random")
887             sub.prop(part, "use_group_count")
888
889             col = split.column()
890             sub = col.column()
891             sub.active = (part.use_whole_group is False)
892             sub.prop(part, "use_global_dupli")
893             sub.prop(part, "use_rotation_dupli")
894             sub.prop(part, "use_scale_dupli")
895
896             if part.use_group_count and not part.use_whole_group:
897                 row = layout.row()
898                 row.template_list("UI_UL_list", "particle_dupli_weights", part, "dupli_weights",
899                                   part, "active_dupliweight_index")
900
901                 col = row.column()
902                 sub = col.row()
903                 subsub = sub.column(align=True)
904                 subsub.operator("particle.dupliob_copy", icon='ZOOMIN', text="")
905                 subsub.operator("particle.dupliob_remove", icon='ZOOMOUT', text="")
906                 subsub.operator("particle.dupliob_move_up", icon='MOVE_UP_VEC', text="")
907                 subsub.operator("particle.dupliob_move_down", icon='MOVE_DOWN_VEC', text="")
908
909                 weight = part.active_dupliweight
910                 if weight:
911                     row = layout.row()
912                     row.prop(weight, "count")
913
914         elif part.render_type == 'BILLBOARD':
915             ob = context.object
916
917             col.label(text="Align:")
918
919             row = layout.row()
920             row.prop(part, "billboard_align", expand=True)
921             row.prop(part, "lock_billboard", text="Lock")
922             row = layout.row()
923             row.prop(part, "billboard_object")
924
925             row = layout.row()
926             col = row.column(align=True)
927             col.label(text="Tilt:")
928             col.prop(part, "billboard_tilt", text="Angle", slider=True)
929             col.prop(part, "billboard_tilt_random", text="Random", slider=True)
930             col = row.column()
931             col.prop(part, "billboard_offset")
932
933             row = layout.row()
934             col = row.column()
935             col.prop(part, "billboard_size", text="Scale")
936             if part.billboard_align == 'VEL':
937                 col = row.column(align=True)
938                 col.label("Velocity Scale:")
939                 col.prop(part, "billboard_velocity_head", text="Head")
940                 col.prop(part, "billboard_velocity_tail", text="Tail")
941
942             if psys:
943                 col = layout.column()
944                 col.prop_search(psys, "billboard_normal_uv", ob.data, "uv_textures")
945                 col.prop_search(psys, "billboard_time_index_uv", ob.data, "uv_textures")
946
947             split = layout.split(percentage=0.33)
948             split.label(text="Split UVs:")
949             split.prop(part, "billboard_uv_split", text="Number of splits")
950
951             if psys:
952                 col = layout.column()
953                 col.active = part.billboard_uv_split > 1
954                 col.prop_search(psys, "billboard_split_uv", ob.data, "uv_textures")
955
956             row = col.row()
957             row.label(text="Animate:")
958             row.prop(part, "billboard_animation", text="")
959             row.label(text="Offset:")
960             row.prop(part, "billboard_offset_split", text="")
961
962         if part.render_type == 'HALO' or part.render_type == 'LINE' or part.render_type == 'BILLBOARD':
963             row = layout.row()
964             col = row.column()
965             col.prop(part, "trail_count")
966             if part.trail_count > 1:
967                 col.prop(part, "use_absolute_path_time", text="Length in frames")
968                 col = row.column()
969                 col.prop(part, "path_end", text="Length", slider=not part.use_absolute_path_time)
970                 col.prop(part, "length_random", text="Random", slider=True)
971             else:
972                 col = row.column()
973                 col.label(text="")
974
975         if part.render_type in {'OBJECT', 'GROUP'} and not part.use_advanced_hair:
976             row = layout.row(align=True)
977             row.prop(part, "particle_size")
978             row.prop(part, "size_random", slider=True)
979
980
981 class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
982     bl_label = "Display"
983     bl_options = {'DEFAULT_CLOSED'}
984     COMPAT_ENGINES = {'BLENDER_RENDER'}
985
986     @classmethod
987     def poll(cls, context):
988         settings = particle_get_settings(context)
989         engine = context.scene.render.engine
990         if settings is None:
991             return False
992         return engine in cls.COMPAT_ENGINES
993
994     def draw(self, context):
995         layout = self.layout
996
997         psys = context.particle_system
998         part = particle_get_settings(context)
999
1000         row = layout.row()
1001         row.prop(part, "draw_method", expand=True)
1002
1003         if part.draw_method == 'NONE' or (part.render_type == 'NONE' and part.draw_method == 'RENDER'):
1004             return
1005
1006         path = (part.render_type == 'PATH' and part.draw_method == 'RENDER') or part.draw_method == 'PATH'
1007
1008         row = layout.row()
1009         row.prop(part, "draw_percentage", slider=True)
1010         if part.draw_method != 'RENDER' or part.render_type == 'HALO':
1011             row.prop(part, "draw_size")
1012         else:
1013             row.label(text="")
1014
1015         if part.draw_percentage != 100 and psys is not None:
1016             if part.type == 'HAIR':
1017                 if psys.use_hair_dynamics and psys.point_cache.is_baked is False:
1018                     layout.row().label(text="Display percentage makes dynamics inaccurate without baking!")
1019             else:
1020                 phystype = part.physics_type
1021                 if phystype != 'NO' and phystype != 'KEYED' and psys.point_cache.is_baked is False:
1022                     layout.row().label(text="Display percentage makes dynamics inaccurate without baking!")
1023
1024         row = layout.row()
1025         col = row.column()
1026         col.prop(part, "show_size")
1027         col.prop(part, "show_velocity")
1028         col.prop(part, "show_number")
1029         if part.physics_type == 'BOIDS':
1030             col.prop(part, "show_health")
1031
1032         col = row.column(align=True)
1033         col.label(text="Color:")
1034         col.prop(part, "draw_color", text="")
1035         sub = col.row(align=True)
1036         sub.active = (part.draw_color in {'VELOCITY', 'ACCELERATION'})
1037         sub.prop(part, "color_maximum", text="Max")
1038
1039         if path:
1040             col.prop(part, "draw_step")
1041
1042
1043 class PARTICLE_PT_children(ParticleButtonsPanel, Panel):
1044     bl_label = "Children"
1045     bl_options = {'DEFAULT_CLOSED'}
1046     COMPAT_ENGINES = {'BLENDER_RENDER'}
1047
1048     @classmethod
1049     def poll(cls, context):
1050         return particle_panel_poll(cls, context)
1051
1052     def draw(self, context):
1053         layout = self.layout
1054
1055         psys = context.particle_system
1056         part = particle_get_settings(context)
1057
1058         layout.row().prop(part, "child_type", expand=True)
1059
1060         if part.child_type == 'NONE':
1061             return
1062
1063         row = layout.row()
1064
1065         col = row.column(align=True)
1066         col.prop(part, "child_nbr", text="Display")
1067         col.prop(part, "rendered_child_count", text="Render")
1068
1069         if part.child_type == 'INTERPOLATED':
1070             col = row.column()
1071             if psys:
1072                 col.prop(psys, "child_seed", text="Seed")
1073             col.prop(part, "virtual_parents", slider=True)
1074             col.prop(part, "create_long_hair_children")
1075         else:
1076             col = row.column(align=True)
1077             col.prop(part, "child_size", text="Size")
1078             col.prop(part, "child_size_random", text="Random")
1079
1080         split = layout.split()
1081
1082         col = split.column()
1083         col.label(text="Effects:")
1084
1085         sub = col.column(align=True)
1086         sub.prop(part, "clump_factor", slider=True)
1087         sub.prop(part, "clump_shape", slider=True)
1088
1089         sub = col.column(align=True)
1090         sub.prop(part, "child_length", slider=True)
1091         sub.prop(part, "child_length_threshold", slider=True)
1092
1093         if part.child_type == 'SIMPLE':
1094             sub = col.column(align=True)
1095             sub.prop(part, "child_radius", text="Radius")
1096             sub.prop(part, "child_roundness", text="Roundness", slider=True)
1097             if psys:
1098                 sub.prop(psys, "child_seed", text="Seed")
1099         elif part.virtual_parents > 0.0:
1100             sub = col.column(align=True)
1101             sub.label(text="Parting not")
1102             sub.label(text="available with")
1103             sub.label(text="virtual parents")
1104         else:
1105             sub = col.column(align=True)
1106             sub.prop(part, "child_parting_factor", text="Parting", slider=True)
1107             sub.prop(part, "child_parting_min", text="Min")
1108             sub.prop(part, "child_parting_max", text="Max")
1109
1110         col = split.column()
1111         col.label(text="Roughness:")
1112
1113         sub = col.column(align=True)
1114         sub.prop(part, "roughness_1", text="Uniform")
1115         sub.prop(part, "roughness_1_size", text="Size")
1116
1117         sub = col.column(align=True)
1118         sub.prop(part, "roughness_endpoint", "Endpoint")
1119         sub.prop(part, "roughness_end_shape")
1120
1121         sub = col.column(align=True)
1122         sub.prop(part, "roughness_2", text="Random")
1123         sub.prop(part, "roughness_2_size", text="Size")
1124         sub.prop(part, "roughness_2_threshold", slider=True)
1125
1126         layout.row().label(text="Kink:")
1127         layout.row().prop(part, "kink", expand=True)
1128
1129         split = layout.split()
1130         split.active = part.kink != 'NO'
1131
1132         col = split.column()
1133         sub = col.column(align=True)
1134         sub.prop(part, "kink_amplitude")
1135         sub.prop(part, "kink_amplitude_clump", text="Clump", slider=True)
1136         col.prop(part, "kink_flat", slider=True)
1137         col = split.column(align=True)
1138         col.prop(part, "kink_frequency")
1139         col.prop(part, "kink_shape", slider=True)
1140
1141
1142 class PARTICLE_PT_field_weights(ParticleButtonsPanel, Panel):
1143     bl_label = "Field Weights"
1144     bl_options = {'DEFAULT_CLOSED'}
1145     COMPAT_ENGINES = {'BLENDER_RENDER'}
1146
1147     @classmethod
1148     def poll(cls, context):
1149         return particle_panel_poll(cls, context)
1150
1151     def draw(self, context):
1152         part = particle_get_settings(context)
1153         effector_weights_ui(self, context, part.effector_weights, 'PSYS')
1154
1155         if part.type == 'HAIR':
1156             row = self.layout.row()
1157             row.prop(part.effector_weights, "apply_to_hair_growing")
1158             row.prop(part, "apply_effector_to_children")
1159             row = self.layout.row()
1160             row.prop(part, "effect_hair", slider=True)
1161
1162
1163 class PARTICLE_PT_force_fields(ParticleButtonsPanel, Panel):
1164     bl_label = "Force Field Settings"
1165     bl_options = {'DEFAULT_CLOSED'}
1166     COMPAT_ENGINES = {'BLENDER_RENDER'}
1167
1168     def draw(self, context):
1169         layout = self.layout
1170
1171         part = particle_get_settings(context)
1172
1173         row = layout.row()
1174         row.prop(part, "use_self_effect")
1175         row.prop(part, "effector_amount", text="Amount")
1176
1177         split = layout.split(percentage=0.2)
1178         split.label(text="Type 1:")
1179         split.prop(part.force_field_1, "type", text="")
1180         basic_force_field_settings_ui(self, context, part.force_field_1)
1181         if part.force_field_1.type != 'NONE':
1182             layout.label(text="Falloff:")
1183         basic_force_field_falloff_ui(self, context, part.force_field_1)
1184
1185         if part.force_field_1.type != 'NONE':
1186             layout.label(text="")
1187
1188         split = layout.split(percentage=0.2)
1189         split.label(text="Type 2:")
1190         split.prop(part.force_field_2, "type", text="")
1191         basic_force_field_settings_ui(self, context, part.force_field_2)
1192         if part.force_field_2.type != 'NONE':
1193             layout.label(text="Falloff:")
1194         basic_force_field_falloff_ui(self, context, part.force_field_2)
1195
1196
1197 class PARTICLE_PT_vertexgroups(ParticleButtonsPanel, Panel):
1198     bl_label = "Vertex Groups"
1199     bl_options = {'DEFAULT_CLOSED'}
1200     COMPAT_ENGINES = {'BLENDER_RENDER'}
1201
1202     @classmethod
1203     def poll(cls, context):
1204         if context.particle_system is None:
1205             return False
1206         return particle_panel_poll(cls, context)
1207
1208     def draw(self, context):
1209         layout = self.layout
1210
1211         ob = context.object
1212         psys = context.particle_system
1213
1214         col = layout.column()
1215         row = col.row(align=True)
1216         row.prop_search(psys, "vertex_group_density", ob, "vertex_groups", text="Density")
1217         row.prop(psys, "invert_vertex_group_density", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1218
1219         row = col.row(align=True)
1220         row.prop_search(psys, "vertex_group_length", ob, "vertex_groups", text="Length")
1221         row.prop(psys, "invert_vertex_group_length", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1222
1223         row = col.row(align=True)
1224         row.prop_search(psys, "vertex_group_clump", ob, "vertex_groups", text="Clump")
1225         row.prop(psys, "invert_vertex_group_clump", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1226
1227         row = col.row(align=True)
1228         row.prop_search(psys, "vertex_group_kink", ob, "vertex_groups", text="Kink")
1229         row.prop(psys, "invert_vertex_group_kink", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1230
1231         row = col.row(align=True)
1232         row.prop_search(psys, "vertex_group_roughness_1", ob, "vertex_groups", text="Roughness 1")
1233         row.prop(psys, "invert_vertex_group_roughness_1", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1234
1235         row = col.row(align=True)
1236         row.prop_search(psys, "vertex_group_roughness_2", ob, "vertex_groups", text="Roughness 2")
1237         row.prop(psys, "invert_vertex_group_roughness_2", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1238
1239         row = col.row(align=True)
1240         row.prop_search(psys, "vertex_group_roughness_end", ob, "vertex_groups", text="Roughness End")
1241         row.prop(psys, "invert_vertex_group_roughness_end", text="", toggle=True, icon='ARROW_LEFTRIGHT')
1242
1243         # Commented out vertex groups don't work and are still waiting for better implementation
1244         # row = layout.row()
1245         # row.prop_search(psys, "vertex_group_velocity", ob, "vertex_groups", text="Velocity")
1246         # row.prop(psys, "invert_vertex_group_velocity", text="")
1247
1248         # row = layout.row()
1249         # row.prop_search(psys, "vertex_group_size", ob, "vertex_groups", text="Size")
1250         # row.prop(psys, "invert_vertex_group_size", text="")
1251
1252         # row = layout.row()
1253         # row.prop_search(psys, "vertex_group_tangent", ob, "vertex_groups", text="Tangent")
1254         # row.prop(psys, "invert_vertex_group_tangent", text="")
1255
1256         # row = layout.row()
1257         # row.prop_search(psys, "vertex_group_rotation", ob, "vertex_groups", text="Rotation")
1258         # row.prop(psys, "invert_vertex_group_rotation", text="")
1259
1260         # row = layout.row()
1261         # row.prop_search(psys, "vertex_group_field", ob, "vertex_groups", text="Field")
1262         # row.prop(psys, "invert_vertex_group_field", text="")
1263
1264
1265 class PARTICLE_PT_custom_props(ParticleButtonsPanel, PropertyPanel, Panel):
1266     COMPAT_ENGINES = {'BLENDER_RENDER'}
1267     _context_path = "particle_system.settings"
1268     _property_type = bpy.types.ParticleSettings
1269
1270 if __name__ == "__main__":  # only for live edit.
1271     bpy.utils.register_module(__name__)