ee8c74a2cb60022c37ad554d533b97f2bfa8f9a0
[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 (point_cache_ui,
25                                              effector_weights_ui,
26                                              basic_force_field_settings_ui,
27                                              basic_force_field_falloff_ui,
28                                              )
29
30
31 def particle_panel_enabled(context, psys):
32     if psys is None:
33         return True
34     phystype = psys.settings.physics_type
35     if psys.settings.type in {'EMITTER', 'REACTOR'} and phystype in {'NO', 'KEYED'}:
36         return True
37     else:
38         return (psys.point_cache.is_baked is False) and (not psys.is_edited) and (not context.particle_system_editable)
39
40
41 def particle_panel_poll(cls, context):
42     psys = context.particle_system
43     engine = context.scene.render.engine
44     settings = 0
45
46     if psys:
47         settings = psys.settings
48     elif isinstance(context.space_data.pin_id, bpy.types.ParticleSettings):
49         settings = context.space_data.pin_id
50
51     if not settings:
52         return False
53
54     return settings.is_fluid is False and (engine in cls.COMPAT_ENGINES)
55
56
57 def particle_get_settings(context):
58     if context.particle_system:
59         return context.particle_system.settings
60     elif isinstance(context.space_data.pin_id, bpy.types.ParticleSettings):
61         return context.space_data.pin_id
62     return None
63
64
65 class ParticleButtonsPanel():
66     bl_space_type = 'PROPERTIES'
67     bl_region_type = 'WINDOW'
68     bl_context = "particle"
69
70     @classmethod
71     def poll(cls, context):
72         return particle_panel_poll(cls, context)
73
74
75 class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
76     bl_label = ""
77     bl_options = {'HIDE_HEADER'}
78     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
79
80     @classmethod
81     def poll(cls, context):
82         engine = context.scene.render.engine
83         return (context.particle_system or context.object or context.space_data.pin_id) and (engine in cls.COMPAT_ENGINES)
84
85     def draw(self, context):
86         layout = self.layout
87
88         if context.scene.render.engine == 'BLENDER_GAME':
89             layout.label("Not available in the Game Engine")
90             return
91
92         ob = context.object
93         psys = context.particle_system
94         part = 0
95
96         if ob:
97             row = layout.row()
98
99             row.template_list("UI_UL_list", "", ob, "particle_systems", ob.particle_systems, "active_index", rows=2)
100
101             col = row.column(align=True)
102             col.operator("object.particle_system_add", icon='ZOOMIN', text="")
103             col.operator("object.particle_system_remove", icon='ZOOMOUT', text="")
104
105         if psys is None:
106             part = particle_get_settings(context)
107
108             if part is None:
109                 return
110
111             layout.template_ID(context.space_data, "pin_id")
112
113             if part.is_fluid:
114                 layout.label(text="Settings used for fluid")
115                 return
116
117             layout.prop(part, "type", text="Type")
118
119         elif not psys.settings:
120             split = layout.split(percentage=0.32)
121
122             col = split.column()
123             col.label(text="Name:")
124             col.label(text="Settings:")
125
126             col = split.column()
127             col.prop(psys, "name", text="")
128             col.template_ID(psys, "settings", new="particle.new")
129         else:
130             part = psys.settings
131
132             split = layout.split(percentage=0.32)
133             col = split.column()
134             col.label(text="Name:")
135             if part.is_fluid is False:
136                 col.label(text="Settings:")
137                 col.label(text="Type:")
138
139             col = split.column()
140             col.prop(psys, "name", text="")
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             #row = layout.row()
147             #row.label(text="Viewport")
148             #row.label(text="Render")
149
150             if part.is_fluid:
151                 pgettext = bpy.app.translations.pgettext
152                 layout.label(text=pgettext("%d fluid particles for this frame") % part.count, translate=False)
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 is 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             sub.prop(part, "subframes")
495             supports_courant = part.physics_type == 'FLUID'
496             subsub = sub.row()
497             subsub.enabled = supports_courant
498             subsub.prop(part, "adaptive_subframes", text="")
499             if supports_courant and part.adaptive_subframes:
500                 col.prop(part, "courant_target", text="Threshold")
501
502             row = layout.row()
503             row.prop(part, "use_size_deflect")
504             row.prop(part, "use_die_on_collision")
505
506             if part.physics_type == 'FLUID':
507                 fluid = part.fluid
508
509                 split = layout.split()
510                 sub = split.row()
511                 sub.prop(fluid, "solver", expand=True)
512
513                 split = layout.split()
514
515                 col = split.column()
516                 col.label(text="Fluid properties:")
517                 col.prop(fluid, "stiffness", text="Stiffness")
518                 col.prop(fluid, "linear_viscosity", text="Viscosity")
519                 col.prop(fluid, "buoyancy", text="Buoyancy", slider=True)
520
521                 col = split.column()
522                 col.label(text="Advanced:")
523
524                 if fluid.solver == 'DDR':
525                     sub = col.row()
526                     sub.prop(fluid, "repulsion", slider=fluid.factor_repulsion)
527                     sub.prop(fluid, "factor_repulsion", text="")
528
529                     sub = col.row()
530                     sub.prop(fluid, "stiff_viscosity", slider=fluid.factor_stiff_viscosity)
531                     sub.prop(fluid, "factor_stiff_viscosity", text="")
532
533                 sub = col.row()
534                 sub.prop(fluid, "fluid_radius", slider=fluid.factor_radius)
535                 sub.prop(fluid, "factor_radius", text="")
536
537                 sub = col.row()
538                 sub.prop(fluid, "rest_density", slider=fluid.factor_density)
539                 sub.prop(fluid, "factor_density", text="")
540
541                 if fluid.solver == 'CLASSICAL':
542                     # With the classical solver, it is possible to calculate the
543                     # spacing between particles when the fluid is at rest. This
544                     # makes it easier to set stable initial conditions.
545                     particle_volume = part.mass / fluid.rest_density
546                     spacing = pow(particle_volume, 1.0 / 3.0)
547                     sub = col.row()
548                     sub.label(text="Spacing: %g" % spacing)
549
550                 elif fluid.solver == 'DDR':
551                     split = layout.split()
552
553                     col = split.column()
554                     col.label(text="Springs:")
555                     col.prop(fluid, "spring_force", text="Force")
556                     col.prop(fluid, "use_viscoelastic_springs")
557                     sub = col.column(align=True)
558                     sub.active = fluid.use_viscoelastic_springs
559                     sub.prop(fluid, "yield_ratio", slider=True)
560                     sub.prop(fluid, "plasticity", slider=True)
561
562                     col = split.column()
563                     col.label(text="Advanced:")
564                     sub = col.row()
565                     sub.prop(fluid, "rest_length", slider=fluid.factor_rest_length)
566                     sub.prop(fluid, "factor_rest_length", text="")
567                     col.label(text="")
568                     sub = col.column()
569                     sub.active = fluid.use_viscoelastic_springs
570                     sub.prop(fluid, "use_initial_rest_length")
571                     sub.prop(fluid, "spring_frames", text="Frames")
572
573         elif part.physics_type == 'KEYED':
574             split = layout.split()
575             sub = split.column()
576
577             row = layout.row()
578             col = row.column()
579             col.active = not psys.use_keyed_timing
580             col.prop(part, "keyed_loops", text="Loops")
581             if psys:
582                 row.prop(psys, "use_keyed_timing", text="Use Timing")
583
584             layout.label(text="Keys:")
585         elif part.physics_type == 'BOIDS':
586             boids = part.boids
587
588             row = layout.row()
589             row.prop(boids, "use_flight")
590             row.prop(boids, "use_land")
591             row.prop(boids, "use_climb")
592
593             split = layout.split()
594
595             sub = split.column()
596             col = sub.column(align=True)
597             col.active = boids.use_flight
598             col.prop(boids, "air_speed_max")
599             col.prop(boids, "air_speed_min", slider=True)
600             col.prop(boids, "air_acc_max", slider=True)
601             col.prop(boids, "air_ave_max", slider=True)
602             col.prop(boids, "air_personal_space")
603             row = col.row()
604             row.active = (boids.use_land or boids.use_climb) and boids.use_flight
605             row.prop(boids, "land_smooth")
606
607             sub = split.column()
608             col = sub.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             row = layout.row()
618
619             col = row.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 = row.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", "", psys, "targets", psys, "active_particle_target_index")
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", "", boids, "states", boids, "active_boid_state_index", compact="True")
707         #col = row.row()
708         #sub = col.row(align=True)
709         #sub.operator("boid.state_add", icon='ZOOMIN', text="")
710         #sub.operator("boid.state_del", icon='ZOOMOUT', text="")
711         #sub = row.row(align=True)
712         #sub.operator("boid.state_move_up", icon='MOVE_UP_VEC', text="")
713         #sub.operator("boid.state_move_down", icon='MOVE_DOWN_VEC', text="")
714
715         state = boids.active_boid_state
716
717         #layout.prop(state, "name", text="State name")
718
719         row = layout.row()
720         row.prop(state, "ruleset_type")
721         if state.ruleset_type == 'FUZZY':
722             row.prop(state, "rule_fuzzy", slider=True)
723         else:
724             row.label(text="")
725
726         row = layout.row()
727         row.template_list("UI_UL_list", "", state, "rules", state, "active_boid_rule_index")
728
729         col = row.column()
730         sub = col.row()
731         subsub = sub.column(align=True)
732         subsub.operator_menu_enum("boid.rule_add", "type", icon='ZOOMIN', text="")
733         subsub.operator("boid.rule_del", icon='ZOOMOUT', text="")
734         sub = col.row()
735         subsub = sub.column(align=True)
736         subsub.operator("boid.rule_move_up", icon='MOVE_UP_VEC', text="")
737         subsub.operator("boid.rule_move_down", icon='MOVE_DOWN_VEC', text="")
738
739         rule = state.active_boid_rule
740
741         if rule:
742             row = layout.row()
743             row.prop(rule, "name", text="")
744             #somebody make nice icons for boids here please! -jahka
745             row.prop(rule, "use_in_air", icon='MOVE_UP_VEC', text="")
746             row.prop(rule, "use_on_land", icon='MOVE_DOWN_VEC', text="")
747
748             row = layout.row()
749
750             if rule.type == 'GOAL':
751                 row.prop(rule, "object")
752                 row = layout.row()
753                 row.prop(rule, "use_predict")
754             elif rule.type == 'AVOID':
755                 row.prop(rule, "object")
756                 row = layout.row()
757                 row.prop(rule, "use_predict")
758                 row.prop(rule, "fear_factor")
759             elif rule.type == 'FOLLOW_PATH':
760                 row.label(text="Not yet functional")
761             elif rule.type == 'AVOID_COLLISION':
762                 row.prop(rule, "use_avoid")
763                 row.prop(rule, "use_avoid_collision")
764                 row.prop(rule, "look_ahead")
765             elif rule.type == 'FOLLOW_LEADER':
766                 row.prop(rule, "object", text="")
767                 row.prop(rule, "distance")
768                 row = layout.row()
769                 row.prop(rule, "use_line")
770                 sub = row.row()
771                 sub.active = rule.line
772                 sub.prop(rule, "queue_count")
773             elif rule.type == 'AVERAGE_SPEED':
774                 row.prop(rule, "speed", slider=True)
775                 row.prop(rule, "wander", slider=True)
776                 row.prop(rule, "level", slider=True)
777             elif rule.type == 'FIGHT':
778                 row.prop(rule, "distance")
779                 row.prop(rule, "flee_distance")
780
781
782 class PARTICLE_PT_render(ParticleButtonsPanel, Panel):
783     bl_label = "Render"
784     COMPAT_ENGINES = {'BLENDER_RENDER'}
785
786     @classmethod
787     def poll(cls, context):
788         settings = particle_get_settings(context)
789         engine = context.scene.render.engine
790         if settings is None:
791             return False
792
793         return engine in cls.COMPAT_ENGINES
794
795     def draw(self, context):
796         layout = self.layout
797
798         psys = context.particle_system
799         part = particle_get_settings(context)
800
801         row = layout.row()
802         row.prop(part, "material")
803         if psys:
804             row.prop(psys, "parent")
805
806         split = layout.split()
807
808         col = split.column()
809         col.prop(part, "use_render_emitter")
810         col.prop(part, "use_parent_particles")
811
812         col = split.column()
813         col.prop(part, "show_unborn")
814         col.prop(part, "use_dead")
815
816         layout.prop(part, "render_type", expand=True)
817
818         split = layout.split()
819
820         col = split.column()
821
822         if part.render_type == 'LINE':
823             col.prop(part, "line_length_tail")
824             col.prop(part, "line_length_head")
825
826             split.prop(part, "use_velocity_length")
827         elif part.render_type == 'PATH':
828             col.prop(part, "use_strand_primitive")
829             sub = col.column()
830             sub.active = (part.use_strand_primitive is False)
831             sub.prop(part, "use_render_adaptive")
832             sub = col.column()
833             sub.active = part.use_render_adaptive or part.use_strand_primitive is True
834             sub.prop(part, "adaptive_angle")
835             sub = col.column()
836             sub.active = (part.use_render_adaptive is True and part.use_strand_primitive is False)
837             sub.prop(part, "adaptive_pixel")
838             col.prop(part, "use_hair_bspline")
839             col.prop(part, "render_step", text="Steps")
840
841             col = split.column()
842             col.label(text="Timing:")
843             col.prop(part, "use_absolute_path_time")
844             col.prop(part, "path_start", text="Start", slider=not part.use_absolute_path_time)
845             col.prop(part, "path_end", text="End", slider=not part.use_absolute_path_time)
846             col.prop(part, "length_random", text="Random", slider=True)
847
848             row = layout.row()
849             col = row.column()
850
851             if part.type == 'HAIR' and part.use_strand_primitive is True and part.child_type == 'INTERPOLATED':
852                 layout.prop(part, "use_simplify")
853                 if part.use_simplify is True:
854                     row = layout.row()
855                     row.prop(part, "simplify_refsize")
856                     row.prop(part, "simplify_rate")
857                     row.prop(part, "simplify_transition")
858                     row = layout.row()
859                     row.prop(part, "use_simplify_viewport")
860                     sub = row.row()
861                     sub.active = part.use_simplify_viewport is True
862                     sub.prop(part, "simplify_viewport")
863
864         elif part.render_type == 'OBJECT':
865             col.prop(part, "dupli_object")
866             sub = col.row()
867             sub.prop(part, "use_global_dupli")
868             sub.prop(part, "use_rotation_dupli")
869             sub.prop(part, "use_scale_dupli")
870         elif part.render_type == 'GROUP':
871             col.prop(part, "dupli_group")
872             split = layout.split()
873
874             col = split.column()
875             col.prop(part, "use_whole_group")
876             sub = col.column()
877             sub.active = (part.use_whole_group is False)
878             sub.prop(part, "use_group_pick_random")
879             sub.prop(part, "use_group_count")
880
881             col = split.column()
882             sub = col.column()
883             sub.active = (part.use_whole_group is False)
884             sub.prop(part, "use_global_dupli")
885             sub.prop(part, "use_rotation_dupli")
886             sub.prop(part, "use_scale_dupli")
887
888             if part.use_group_count and not part.use_whole_group:
889                 row = layout.row()
890                 row.template_list("UI_UL_list", "", part, "dupli_weights", part, "active_dupliweight_index")
891
892                 col = row.column()
893                 sub = col.row()
894                 subsub = sub.column(align=True)
895                 subsub.operator("particle.dupliob_copy", icon='ZOOMIN', text="")
896                 subsub.operator("particle.dupliob_remove", icon='ZOOMOUT', text="")
897                 subsub.operator("particle.dupliob_move_up", icon='MOVE_UP_VEC', text="")
898                 subsub.operator("particle.dupliob_move_down", icon='MOVE_DOWN_VEC', text="")
899
900                 weight = part.active_dupliweight
901                 if weight:
902                     row = layout.row()
903                     row.prop(weight, "count")
904
905         elif part.render_type == 'BILLBOARD':
906             ob = context.object
907
908             col.label(text="Align:")
909
910             row = layout.row()
911             row.prop(part, "billboard_align", expand=True)
912             row.prop(part, "lock_billboard", text="Lock")
913             row = layout.row()
914             row.prop(part, "billboard_object")
915
916             row = layout.row()
917             col = row.column(align=True)
918             col.label(text="Tilt:")
919             col.prop(part, "billboard_tilt", text="Angle", slider=True)
920             col.prop(part, "billboard_tilt_random", text="Random", slider=True)
921             col = row.column()
922             col.prop(part, "billboard_offset")
923
924             row = layout.row()
925             col = row.column()
926             col.prop(part, "billboard_size", text="Scale")
927             if part.billboard_align == 'VEL':
928                 col = row.column(align=True)
929                 col.label("Velocity Scale:")
930                 col.prop(part, "billboard_velocity_head", text="Head")
931                 col.prop(part, "billboard_velocity_tail", text="Tail")
932
933             if psys:
934                 col = layout.column()
935                 col.prop_search(psys, "billboard_normal_uv", ob.data, "uv_textures")
936                 col.prop_search(psys, "billboard_time_index_uv", ob.data, "uv_textures")
937
938             split = layout.split(percentage=0.33)
939             split.label(text="Split UVs:")
940             split.prop(part, "billboard_uv_split", text="Number of splits")
941
942             if psys:
943                 col = layout.column()
944                 col.active = part.billboard_uv_split > 1
945                 col.prop_search(psys, "billboard_split_uv", ob.data, "uv_textures")
946
947             row = col.row()
948             row.label(text="Animate:")
949             row.prop(part, "billboard_animation", text="")
950             row.label(text="Offset:")
951             row.prop(part, "billboard_offset_split", text="")
952
953         if part.render_type == 'HALO' or part.render_type == 'LINE' or part.render_type == 'BILLBOARD':
954             row = layout.row()
955             col = row.column()
956             col.prop(part, "trail_count")
957             if part.trail_count > 1:
958                 col.prop(part, "use_absolute_path_time", text="Length in frames")
959                 col = row.column()
960                 col.prop(part, "path_end", text="Length", slider=not part.use_absolute_path_time)
961                 col.prop(part, "length_random", text="Random", slider=True)
962             else:
963                 col = row.column()
964                 col.label(text="")
965
966         if part.render_type in {'OBJECT', 'GROUP'} and not part.use_advanced_hair:
967             row = layout.row(align=True)
968             row.prop(part, "particle_size")
969             row.prop(part, "size_random", slider=True)
970
971
972 class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
973     bl_label = "Display"
974     bl_options = {'DEFAULT_CLOSED'}
975     COMPAT_ENGINES = {'BLENDER_RENDER'}
976
977     @classmethod
978     def poll(cls, context):
979         settings = particle_get_settings(context)
980         engine = context.scene.render.engine
981         if settings is None:
982             return False
983         return engine in cls.COMPAT_ENGINES
984
985     def draw(self, context):
986         layout = self.layout
987
988         psys = context.particle_system
989         part = particle_get_settings(context)
990
991         row = layout.row()
992         row.prop(part, "draw_method", expand=True)
993
994         if part.draw_method == 'NONE' or (part.render_type == 'NONE' and part.draw_method == 'RENDER'):
995             return
996
997         path = (part.render_type == 'PATH' and part.draw_method == 'RENDER') or part.draw_method == 'PATH'
998
999         row = layout.row()
1000         row.prop(part, "draw_percentage", slider=True)
1001         if part.draw_method != 'RENDER' or part.render_type == 'HALO':
1002             row.prop(part, "draw_size")
1003         else:
1004             row.label(text="")
1005
1006         if part.draw_percentage != 100 and psys is not None:
1007             if part.type == 'HAIR':
1008                 if psys.use_hair_dynamics and psys.point_cache.is_baked is False:
1009                     layout.row().label(text="Display percentage makes dynamics inaccurate without baking!")
1010             else:
1011                 phystype = part.physics_type
1012                 if phystype != 'NO' and phystype != 'KEYED' and psys.point_cache.is_baked is False:
1013                     layout.row().label(text="Display percentage makes dynamics inaccurate without baking!")
1014
1015         row = layout.row()
1016         col = row.column()
1017         col.prop(part, "show_size")
1018         col.prop(part, "show_velocity")
1019         col.prop(part, "show_number")
1020         if part.physics_type == 'BOIDS':
1021             col.prop(part, "show_health")
1022
1023         col = row.column(align=True)
1024         col.label(text="Color:")
1025         col.prop(part, "draw_color", text="")
1026         sub = col.row()
1027         sub.active = (part.draw_color in {'VELOCITY', 'ACCELERATION'})
1028         sub.prop(part, "color_maximum", text="Max")
1029
1030         if path:
1031             col.prop(part, "draw_step")
1032
1033
1034 class PARTICLE_PT_children(ParticleButtonsPanel, Panel):
1035     bl_label = "Children"
1036     bl_options = {'DEFAULT_CLOSED'}
1037     COMPAT_ENGINES = {'BLENDER_RENDER'}
1038
1039     @classmethod
1040     def poll(cls, context):
1041         return particle_panel_poll(cls, context)
1042
1043     def draw(self, context):
1044         layout = self.layout
1045
1046         psys = context.particle_system
1047         part = particle_get_settings(context)
1048
1049         layout.row().prop(part, "child_type", expand=True)
1050
1051         if part.child_type == 'NONE':
1052             return
1053
1054         row = layout.row()
1055
1056         col = row.column(align=True)
1057         col.prop(part, "child_nbr", text="Display")
1058         col.prop(part, "rendered_child_count", text="Render")
1059
1060         if part.child_type == 'INTERPOLATED':
1061             col = row.column()
1062             if psys:
1063                 col.prop(psys, "child_seed", text="Seed")
1064             col.prop(part, "virtual_parents", slider=True)
1065             col.prop(part, "create_long_hair_children")
1066         else:
1067             col = row.column(align=True)
1068             col.prop(part, "child_size", text="Size")
1069             col.prop(part, "child_size_random", text="Random")
1070
1071         split = layout.split()
1072
1073         col = split.column()
1074         col.label(text="Effects:")
1075
1076         sub = col.column(align=True)
1077         sub.prop(part, "clump_factor", slider=True)
1078         sub.prop(part, "clump_shape", slider=True)
1079
1080         sub = col.column(align=True)
1081         sub.prop(part, "child_length", slider=True)
1082         sub.prop(part, "child_length_threshold", slider=True)
1083
1084         if part.child_type == 'SIMPLE':
1085             sub = col.column(align=True)
1086             sub.prop(part, "child_radius", text="Radius")
1087             sub.prop(part, "child_roundness", text="Roundness", slider=True)
1088             if psys:
1089                 sub.prop(psys, "child_seed", text="Seed")
1090         elif part.virtual_parents > 0.0:
1091             sub = col.column(align=True)
1092             sub.label(text="Parting not")
1093             sub.label(text="available with")
1094             sub.label(text="virtual parents")
1095         else:
1096             sub = col.column(align=True)
1097             sub.prop(part, "child_parting_factor", text="Parting", slider=True)
1098             sub.prop(part, "child_parting_min", text="Min")
1099             sub.prop(part, "child_parting_max", text="Max")
1100
1101         col = split.column()
1102         col.label(text="Roughness:")
1103
1104         sub = col.column(align=True)
1105         sub.prop(part, "roughness_1", text="Uniform")
1106         sub.prop(part, "roughness_1_size", text="Size")
1107
1108         sub = col.column(align=True)
1109         sub.prop(part, "roughness_endpoint", "Endpoint")
1110         sub.prop(part, "roughness_end_shape")
1111
1112         sub = col.column(align=True)
1113         sub.prop(part, "roughness_2", text="Random")
1114         sub.prop(part, "roughness_2_size", text="Size")
1115         sub.prop(part, "roughness_2_threshold", slider=True)
1116
1117         layout.row().label(text="Kink:")
1118         layout.row().prop(part, "kink", expand=True)
1119
1120         split = layout.split()
1121         split.active = part.kink != 'NO'
1122
1123         col = split.column()
1124         sub = col.column(align=True)
1125         sub.prop(part, "kink_amplitude")
1126         sub.prop(part, "kink_amplitude_clump", text="Clump", slider=True)
1127         col.prop(part, "kink_flat", slider=True)
1128         col = split.column()
1129         sub = col.column(align=True)
1130         sub.prop(part, "kink_frequency")
1131         sub.prop(part, "kink_shape", slider=True)
1132
1133
1134 class PARTICLE_PT_field_weights(ParticleButtonsPanel, Panel):
1135     bl_label = "Field Weights"
1136     bl_options = {'DEFAULT_CLOSED'}
1137     COMPAT_ENGINES = {'BLENDER_RENDER'}
1138
1139     @classmethod
1140     def poll(cls, context):
1141         return particle_panel_poll(cls, context)
1142
1143     def draw(self, context):
1144         part = particle_get_settings(context)
1145         effector_weights_ui(self, context, part.effector_weights, 'PSYS')
1146
1147         if part.type == 'HAIR':
1148             row = self.layout.row()
1149             row.prop(part.effector_weights, "apply_to_hair_growing")
1150             row.prop(part, "apply_effector_to_children")
1151             row = self.layout.row()
1152             row.prop(part, "effect_hair", slider=True)
1153
1154
1155 class PARTICLE_PT_force_fields(ParticleButtonsPanel, Panel):
1156     bl_label = "Force Field Settings"
1157     bl_options = {'DEFAULT_CLOSED'}
1158     COMPAT_ENGINES = {'BLENDER_RENDER'}
1159
1160     def draw(self, context):
1161         layout = self.layout
1162
1163         part = particle_get_settings(context)
1164
1165         row = layout.row()
1166         row.prop(part, "use_self_effect")
1167         row.prop(part, "effector_amount", text="Amount")
1168
1169         split = layout.split(percentage=0.2)
1170         split.label(text="Type 1:")
1171         split.prop(part.force_field_1, "type", text="")
1172         basic_force_field_settings_ui(self, context, part.force_field_1)
1173         if part.force_field_1.type != 'NONE':
1174             layout.label(text="Falloff:")
1175         basic_force_field_falloff_ui(self, context, part.force_field_1)
1176
1177         if part.force_field_1.type != 'NONE':
1178             layout.label(text="")
1179
1180         split = layout.split(percentage=0.2)
1181         split.label(text="Type 2:")
1182         split.prop(part.force_field_2, "type", text="")
1183         basic_force_field_settings_ui(self, context, part.force_field_2)
1184         if part.force_field_2.type != 'NONE':
1185             layout.label(text="Falloff:")
1186         basic_force_field_falloff_ui(self, context, part.force_field_2)
1187
1188
1189 class PARTICLE_PT_vertexgroups(ParticleButtonsPanel, Panel):
1190     bl_label = "Vertex Groups"
1191     bl_options = {'DEFAULT_CLOSED'}
1192     COMPAT_ENGINES = {'BLENDER_RENDER'}
1193
1194     @classmethod
1195     def poll(cls, context):
1196         if context.particle_system is None:
1197             return False
1198         return particle_panel_poll(cls, context)
1199
1200     def draw(self, context):
1201         layout = self.layout
1202
1203         ob = context.object
1204         psys = context.particle_system
1205
1206         split = layout.split(percentage=0.85)
1207
1208         col = split.column()
1209         col.label(text="Vertex Group:")
1210         col.prop_search(psys, "vertex_group_density", ob, "vertex_groups", text="Density")
1211         col.prop_search(psys, "vertex_group_length", ob, "vertex_groups", text="Length")
1212         col.prop_search(psys, "vertex_group_clump", ob, "vertex_groups", text="Clump")
1213         col.prop_search(psys, "vertex_group_kink", ob, "vertex_groups", text="Kink")
1214         col.prop_search(psys, "vertex_group_roughness_1", ob, "vertex_groups", text="Roughness 1")
1215         col.prop_search(psys, "vertex_group_roughness_2", ob, "vertex_groups", text="Roughness 2")
1216         col.prop_search(psys, "vertex_group_roughness_end", ob, "vertex_groups", text="Roughness End")
1217
1218         col = split.column()
1219         col.label(text="Negate:")
1220         col.alignment = 'RIGHT'
1221         col.prop(psys, "invert_vertex_group_density", text="")
1222         col.prop(psys, "invert_vertex_group_length", text="")
1223         col.prop(psys, "invert_vertex_group_clump", text="")
1224         col.prop(psys, "invert_vertex_group_kink", text="")
1225         col.prop(psys, "invert_vertex_group_roughness_1", text="")
1226         col.prop(psys, "invert_vertex_group_roughness_2", text="")
1227         col.prop(psys, "invert_vertex_group_roughness_end", text="")
1228
1229         # Commented out vertex groups don't work and are still waiting for better implementation
1230         # row = layout.row()
1231         # row.prop_search(psys, "vertex_group_velocity", ob, "vertex_groups", text="Velocity")
1232         # row.prop(psys, "invert_vertex_group_velocity", text="")
1233
1234         # row = layout.row()
1235         # row.prop_search(psys, "vertex_group_size", ob, "vertex_groups", text="Size")
1236         # row.prop(psys, "invert_vertex_group_size", text="")
1237
1238         # row = layout.row()
1239         # row.prop_search(psys, "vertex_group_tangent", ob, "vertex_groups", text="Tangent")
1240         # row.prop(psys, "invert_vertex_group_tangent", text="")
1241
1242         # row = layout.row()
1243         # row.prop_search(psys, "vertex_group_rotation", ob, "vertex_groups", text="Rotation")
1244         # row.prop(psys, "invert_vertex_group_rotation", text="")
1245
1246         # row = layout.row()
1247         # row.prop_search(psys, "vertex_group_field", ob, "vertex_groups", text="Field")
1248         # row.prop(psys, "invert_vertex_group_field", text="")
1249
1250
1251 class PARTICLE_PT_custom_props(ParticleButtonsPanel, PropertyPanel, Panel):
1252     COMPAT_ENGINES = {'BLENDER_RENDER'}
1253     _context_path = "particle_system.settings"
1254     _property_type = bpy.types.ParticleSettings
1255
1256 if __name__ == "__main__":  # only for live edit.
1257     bpy.utils.register_module(__name__)