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