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