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