Followup to r59434 : py UI scripts edits.
[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             col = split.column(align=True)
603             col.active = boids.use_flight
604             col.prop(boids, "air_speed_max")
605             col.prop(boids, "air_speed_min", slider=True)
606             col.prop(boids, "air_acc_max", slider=True)
607             col.prop(boids, "air_ave_max", slider=True)
608             col.prop(boids, "air_personal_space")
609             row = col.row(align=True)
610             row.active = (boids.use_land or boids.use_climb) and boids.use_flight
611             row.prop(boids, "land_smooth")
612
613             col = split.column(align=True)
614             col.active = boids.use_land or boids.use_climb
615             col.prop(boids, "land_speed_max")
616             col.prop(boids, "land_jump_speed")
617             col.prop(boids, "land_acc_max", slider=True)
618             col.prop(boids, "land_ave_max", slider=True)
619             col.prop(boids, "land_personal_space")
620             col.prop(boids, "land_stick_force")
621
622             split = layout.split()
623
624             col = split.column(align=True)
625             col.label(text="Battle:")
626             col.prop(boids, "health")
627             col.prop(boids, "strength")
628             col.prop(boids, "aggression")
629             col.prop(boids, "accuracy")
630             col.prop(boids, "range")
631
632             col = split.column()
633             col.label(text="Misc:")
634             col.prop(boids, "bank", slider=True)
635             col.prop(boids, "pitch", slider=True)
636             col.prop(boids, "height", slider=True)
637
638         if psys and part.physics_type in {'KEYED', 'BOIDS', 'FLUID'}:
639             if part.physics_type == 'BOIDS':
640                 layout.label(text="Relations:")
641             elif part.physics_type == 'FLUID':
642                 layout.label(text="Fluid interaction:")
643
644             row = layout.row()
645             row.template_list("UI_UL_list", "particle_targets", psys, "targets", psys, "active_particle_target_index")
646
647             col = row.column()
648             sub = col.row()
649             subsub = sub.column(align=True)
650             subsub.operator("particle.new_target", icon='ZOOMIN', text="")
651             subsub.operator("particle.target_remove", icon='ZOOMOUT', text="")
652             sub = col.row()
653             subsub = sub.column(align=True)
654             subsub.operator("particle.target_move_up", icon='MOVE_UP_VEC', text="")
655             subsub.operator("particle.target_move_down", icon='MOVE_DOWN_VEC', text="")
656
657             key = psys.active_particle_target
658             if key:
659                 row = layout.row()
660                 if part.physics_type == 'KEYED':
661                     col = row.column()
662                     #doesn't work yet
663                     #col.alert = key.valid
664                     col.prop(key, "object", text="")
665                     col.prop(key, "system", text="System")
666                     col = row.column()
667                     col.active = psys.use_keyed_timing
668                     col.prop(key, "time")
669                     col.prop(key, "duration")
670                 elif part.physics_type == 'BOIDS':
671                     sub = row.row()
672                     #doesn't work yet
673                     #sub.alert = key.valid
674                     sub.prop(key, "object", text="")
675                     sub.prop(key, "system", text="System")
676
677                     layout.prop(key, "alliance", expand=True)
678                 elif part.physics_type == 'FLUID':
679                     sub = row.row()
680                     #doesn't work yet
681                     #sub.alert = key.valid
682                     sub.prop(key, "object", text="")
683                     sub.prop(key, "system", text="System")
684
685
686 class PARTICLE_PT_boidbrain(ParticleButtonsPanel, Panel):
687     bl_label = "Boid Brain"
688     COMPAT_ENGINES = {'BLENDER_RENDER'}
689
690     @classmethod
691     def poll(cls, context):
692         psys = context.particle_system
693         settings = particle_get_settings(context)
694         engine = context.scene.render.engine
695
696         if settings is None:
697             return False
698         if psys is not None and psys.point_cache.use_external:
699             return False
700         return settings.physics_type == 'BOIDS' and engine in cls.COMPAT_ENGINES
701
702     def draw(self, context):
703         layout = self.layout
704
705         boids = particle_get_settings(context).boids
706
707         layout.enabled = particle_panel_enabled(context, context.particle_system)
708
709         # Currently boids can only use the first state so these are commented out for now.
710         #row = layout.row()
711         #row.template_list("UI_UL_list", "particle_boids", boids, "states",
712         #                  boids, "active_boid_state_index", compact="True")
713         #col = row.row()
714         #sub = col.row(align=True)
715         #sub.operator("boid.state_add", icon='ZOOMIN', text="")
716         #sub.operator("boid.state_del", icon='ZOOMOUT', text="")
717         #sub = row.row(align=True)
718         #sub.operator("boid.state_move_up", icon='MOVE_UP_VEC', text="")
719         #sub.operator("boid.state_move_down", icon='MOVE_DOWN_VEC', text="")
720
721         state = boids.active_boid_state
722
723         #layout.prop(state, "name", text="State name")
724
725         row = layout.row()
726         row.prop(state, "ruleset_type")
727         if state.ruleset_type == 'FUZZY':
728             row.prop(state, "rule_fuzzy", slider=True)
729         else:
730             row.label(text="")
731
732         row = layout.row()
733         row.template_list("UI_UL_list", "particle_boids_rules", state, "rules", state, "active_boid_rule_index")
734
735         col = row.column()
736         sub = col.row()
737         subsub = sub.column(align=True)
738         subsub.operator_menu_enum("boid.rule_add", "type", icon='ZOOMIN', text="")
739         subsub.operator("boid.rule_del", icon='ZOOMOUT', text="")
740         sub = col.row()
741         subsub = sub.column(align=True)
742         subsub.operator("boid.rule_move_up", icon='MOVE_UP_VEC', text="")
743         subsub.operator("boid.rule_move_down", icon='MOVE_DOWN_VEC', text="")
744
745         rule = state.active_boid_rule
746
747         if rule:
748             row = layout.row()
749             row.prop(rule, "name", text="")
750             #somebody make nice icons for boids here please! -jahka
751             row.prop(rule, "use_in_air", icon='MOVE_UP_VEC', text="")
752             row.prop(rule, "use_on_land", icon='MOVE_DOWN_VEC', text="")
753
754             row = layout.row()
755
756             if rule.type == 'GOAL':
757                 row.prop(rule, "object")
758                 row = layout.row()
759                 row.prop(rule, "use_predict")
760             elif rule.type == 'AVOID':
761                 row.prop(rule, "object")
762                 row = layout.row()
763                 row.prop(rule, "use_predict")
764                 row.prop(rule, "fear_factor")
765             elif rule.type == 'FOLLOW_PATH':
766                 row.label(text="Not yet functional")
767             elif rule.type == 'AVOID_COLLISION':
768                 row.prop(rule, "use_avoid")
769                 row.prop(rule, "use_avoid_collision")
770                 row.prop(rule, "look_ahead")
771             elif rule.type == 'FOLLOW_LEADER':
772                 row.prop(rule, "object", text="")
773                 row.prop(rule, "distance")
774                 row = layout.row()
775                 row.prop(rule, "use_line")
776                 sub = row.row()
777                 sub.active = rule.line
778                 sub.prop(rule, "queue_count")
779             elif rule.type == 'AVERAGE_SPEED':
780                 row.prop(rule, "speed", slider=True)
781                 row.prop(rule, "wander", slider=True)
782                 row.prop(rule, "level", slider=True)
783             elif rule.type == 'FIGHT':
784                 row.prop(rule, "distance")
785                 row.prop(rule, "flee_distance")
786
787
788 class PARTICLE_PT_render(ParticleButtonsPanel, Panel):
789     bl_label = "Render"
790     COMPAT_ENGINES = {'BLENDER_RENDER'}
791
792     @classmethod
793     def poll(cls, context):
794         settings = particle_get_settings(context)
795         engine = context.scene.render.engine
796         if settings is None:
797             return False
798
799         return engine in cls.COMPAT_ENGINES
800
801     def draw(self, context):
802         layout = self.layout
803
804         psys = context.particle_system
805         part = particle_get_settings(context)
806
807         row = layout.row()
808         row.prop(part, "material")
809         if psys:
810             row.prop(psys, "parent")
811
812         split = layout.split()
813
814         col = split.column()
815         col.prop(part, "use_render_emitter")
816         col.prop(part, "use_parent_particles")
817
818         col = split.column()
819         col.prop(part, "show_unborn")
820         col.prop(part, "use_dead")
821
822         layout.prop(part, "render_type", expand=True)
823
824         split = layout.split()
825
826         col = split.column()
827
828         if part.render_type == 'LINE':
829             col.prop(part, "line_length_tail")
830             col.prop(part, "line_length_head")
831
832             split.prop(part, "use_velocity_length")
833         elif part.render_type == 'PATH':
834             col.prop(part, "use_strand_primitive")
835             sub = col.column()
836             sub.active = (part.use_strand_primitive is False)
837             sub.prop(part, "use_render_adaptive")
838             sub = col.column()
839             sub.active = part.use_render_adaptive or part.use_strand_primitive is True
840             sub.prop(part, "adaptive_angle")
841             sub = col.column()
842             sub.active = (part.use_render_adaptive is True and part.use_strand_primitive is False)
843             sub.prop(part, "adaptive_pixel")
844             col.prop(part, "use_hair_bspline")
845             col.prop(part, "render_step", text="Steps")
846
847             col = split.column()
848             col.label(text="Timing:")
849             col.prop(part, "use_absolute_path_time")
850
851             if part.type == 'HAIR' or psys.point_cache.is_baked:
852                 col.prop(part, "path_start", text="Start", slider=not part.use_absolute_path_time)
853             else:
854                 col.prop(part, "trail_count")
855
856             col.prop(part, "path_end", text="End", slider=not part.use_absolute_path_time)
857             col.prop(part, "length_random", text="Random", slider=True)
858
859             row = layout.row()
860             col = row.column()
861
862             if part.type == 'HAIR' and part.use_strand_primitive is True and part.child_type == 'INTERPOLATED':
863                 layout.prop(part, "use_simplify")
864                 if part.use_simplify is True:
865                     row = layout.row()
866                     row.prop(part, "simplify_refsize")
867                     row.prop(part, "simplify_rate")
868                     row.prop(part, "simplify_transition")
869                     row = layout.row()
870                     row.prop(part, "use_simplify_viewport")
871                     sub = row.row()
872                     sub.active = part.use_simplify_viewport is True
873                     sub.prop(part, "simplify_viewport")
874
875         elif part.render_type == 'OBJECT':
876             col.prop(part, "dupli_object")
877             sub = col.row()
878             sub.prop(part, "use_global_dupli")
879             sub.prop(part, "use_rotation_dupli")
880             sub.prop(part, "use_scale_dupli")
881         elif part.render_type == 'GROUP':
882             col.prop(part, "dupli_group")
883             split = layout.split()
884
885             col = split.column()
886             col.prop(part, "use_whole_group")
887             sub = col.column()
888             sub.active = (part.use_whole_group is False)
889             sub.prop(part, "use_group_pick_random")
890             sub.prop(part, "use_group_count")
891
892             col = split.column()
893             sub = col.column()
894             sub.active = (part.use_whole_group is False)
895             sub.prop(part, "use_global_dupli")
896             sub.prop(part, "use_rotation_dupli")
897             sub.prop(part, "use_scale_dupli")
898
899             if part.use_group_count and not part.use_whole_group:
900                 row = layout.row()
901                 row.template_list("UI_UL_list", "particle_dupli_weights", part, "dupli_weights",
902                                   part, "active_dupliweight_index")
903
904                 col = row.column()
905                 sub = col.row()
906                 subsub = sub.column(align=True)
907                 subsub.operator("particle.dupliob_copy", icon='ZOOMIN', text="")
908                 subsub.operator("particle.dupliob_remove", icon='ZOOMOUT', text="")
909                 subsub.operator("particle.dupliob_move_up", icon='MOVE_UP_VEC', text="")
910                 subsub.operator("particle.dupliob_move_down", icon='MOVE_DOWN_VEC', text="")
911
912                 weight = part.active_dupliweight
913                 if weight:
914                     row = layout.row()
915                     row.prop(weight, "count")
916
917         elif part.render_type == 'BILLBOARD':
918             ob = context.object
919
920             col.label(text="Align:")
921
922             row = layout.row()
923             row.prop(part, "billboard_align", expand=True)
924             row.prop(part, "lock_billboard", text="Lock")
925             row = layout.row()
926             row.prop(part, "billboard_object")
927
928             row = layout.row()
929             col = row.column(align=True)
930             col.label(text="Tilt:")
931             col.prop(part, "billboard_tilt", text="Angle", slider=True)
932             col.prop(part, "billboard_tilt_random", text="Random", slider=True)
933             col = row.column()
934             col.prop(part, "billboard_offset")
935
936             row = layout.row()
937             col = row.column()
938             col.prop(part, "billboard_size", text="Scale")
939             if part.billboard_align == 'VEL':
940                 col = row.column(align=True)
941                 col.label("Velocity Scale:")
942                 col.prop(part, "billboard_velocity_head", text="Head")
943                 col.prop(part, "billboard_velocity_tail", text="Tail")
944
945             if psys:
946                 col = layout.column()
947                 col.prop_search(psys, "billboard_normal_uv", ob.data, "uv_textures")
948                 col.prop_search(psys, "billboard_time_index_uv", ob.data, "uv_textures")
949
950             split = layout.split(percentage=0.33)
951             split.label(text="Split UVs:")
952             split.prop(part, "billboard_uv_split", text="Number of splits")
953
954             if psys:
955                 col = layout.column()
956                 col.active = part.billboard_uv_split > 1
957                 col.prop_search(psys, "billboard_split_uv", ob.data, "uv_textures")
958
959             row = col.row()
960             row.label(text="Animate:")
961             row.prop(part, "billboard_animation", text="")
962             row.label(text="Offset:")
963             row.prop(part, "billboard_offset_split", text="")
964
965         if part.render_type == 'HALO' or part.render_type == 'LINE' or part.render_type == 'BILLBOARD':
966             row = layout.row()
967             col = row.column()
968             col.prop(part, "trail_count")
969             if part.trail_count > 1:
970                 col.prop(part, "use_absolute_path_time", text="Length in frames")
971                 col = row.column()
972                 col.prop(part, "path_end", text="Length", slider=not part.use_absolute_path_time)
973                 col.prop(part, "length_random", text="Random", slider=True)
974             else:
975                 col = row.column()
976                 col.label(text="")
977
978         if part.render_type in {'OBJECT', 'GROUP'} and not part.use_advanced_hair:
979             row = layout.row(align=True)
980             row.prop(part, "particle_size")
981             row.prop(part, "size_random", slider=True)
982
983
984 class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
985     bl_label = "Display"
986     bl_options = {'DEFAULT_CLOSED'}
987     COMPAT_ENGINES = {'BLENDER_RENDER'}
988
989     @classmethod
990     def poll(cls, context):
991         settings = particle_get_settings(context)
992         engine = context.scene.render.engine
993         if settings is None:
994             return False
995         return engine in cls.COMPAT_ENGINES
996
997     def draw(self, context):
998         layout = self.layout
999
1000         psys = context.particle_system
1001         part = particle_get_settings(context)
1002
1003         row = layout.row()
1004         row.prop(part, "draw_method", expand=True)
1005
1006         if part.draw_method == 'NONE' or (part.render_type == 'NONE' and part.draw_method == 'RENDER'):
1007             return
1008
1009         path = (part.render_type == 'PATH' and part.draw_method == 'RENDER') or part.draw_method == 'PATH'
1010
1011         row = layout.row()
1012         row.prop(part, "draw_percentage", slider=True)
1013         if part.draw_method != 'RENDER' or part.render_type == 'HALO':
1014             row.prop(part, "draw_size")
1015         else:
1016             row.label(text="")
1017
1018         if part.draw_percentage != 100 and psys is not None:
1019             if part.type == 'HAIR':
1020                 if psys.use_hair_dynamics and psys.point_cache.is_baked is False:
1021                     layout.row().label(text="Display percentage makes dynamics inaccurate without baking!")
1022             else:
1023                 phystype = part.physics_type
1024                 if phystype != 'NO' and phystype != 'KEYED' and psys.point_cache.is_baked is False:
1025                     layout.row().label(text="Display percentage makes dynamics inaccurate without baking!")
1026
1027         row = layout.row()
1028         col = row.column()
1029         col.prop(part, "show_size")
1030         col.prop(part, "show_velocity")
1031         col.prop(part, "show_number")
1032         if part.physics_type == 'BOIDS':
1033             col.prop(part, "show_health")
1034
1035         col = row.column(align=True)
1036         col.label(text="Color:")
1037         col.prop(part, "draw_color", text="")
1038         sub = col.row(align=True)
1039         sub.active = (part.draw_color in {'VELOCITY', 'ACCELERATION'})
1040         sub.prop(part, "color_maximum", text="Max")
1041
1042         if path:
1043             col.prop(part, "draw_step")
1044
1045
1046 class PARTICLE_PT_children(ParticleButtonsPanel, Panel):
1047     bl_label = "Children"
1048     bl_options = {'DEFAULT_CLOSED'}
1049     COMPAT_ENGINES = {'BLENDER_RENDER'}
1050
1051     @classmethod
1052     def poll(cls, context):
1053         return particle_panel_poll(cls, context)
1054
1055     def draw(self, context):
1056         layout = self.layout
1057
1058         psys = context.particle_system
1059         part = particle_get_settings(context)
1060
1061         layout.row().prop(part, "child_type", expand=True)
1062
1063         if part.child_type == 'NONE':
1064             return
1065
1066         row = layout.row()
1067
1068         col = row.column(align=True)
1069         col.prop(part, "child_nbr", text="Display")
1070         col.prop(part, "rendered_child_count", text="Render")
1071
1072         if part.child_type == 'INTERPOLATED':
1073             col = row.column()
1074             if psys:
1075                 col.prop(psys, "child_seed", text="Seed")
1076             col.prop(part, "virtual_parents", slider=True)
1077             col.prop(part, "create_long_hair_children")
1078         else:
1079             col = row.column(align=True)
1080             col.prop(part, "child_size", text="Size")
1081             col.prop(part, "child_size_random", text="Random")
1082
1083         split = layout.split()
1084
1085         col = split.column()
1086         col.label(text="Effects:")
1087
1088         sub = col.column(align=True)
1089         sub.prop(part, "clump_factor", slider=True)
1090         sub.prop(part, "clump_shape", slider=True)
1091
1092         sub = col.column(align=True)
1093         sub.prop(part, "child_length", slider=True)
1094         sub.prop(part, "child_length_threshold", slider=True)
1095
1096         if part.child_type == 'SIMPLE':
1097             sub = col.column(align=True)
1098             sub.prop(part, "child_radius", text="Radius")
1099             sub.prop(part, "child_roundness", text="Roundness", slider=True)
1100             if psys:
1101                 sub.prop(psys, "child_seed", text="Seed")
1102         elif part.virtual_parents > 0.0:
1103             sub = col.column(align=True)
1104             sub.label(text="Parting not")
1105             sub.label(text="available with")
1106             sub.label(text="virtual parents")
1107         else:
1108             sub = col.column(align=True)
1109             sub.prop(part, "child_parting_factor", text="Parting", slider=True)
1110             sub.prop(part, "child_parting_min", text="Min")
1111             sub.prop(part, "child_parting_max", text="Max")
1112
1113         col = split.column()
1114         col.label(text="Roughness:")
1115
1116         sub = col.column(align=True)
1117         sub.prop(part, "roughness_1", text="Uniform")
1118         sub.prop(part, "roughness_1_size", text="Size")
1119
1120         sub = col.column(align=True)
1121         sub.prop(part, "roughness_endpoint", "Endpoint")
1122         sub.prop(part, "roughness_end_shape")
1123
1124         sub = col.column(align=True)
1125         sub.prop(part, "roughness_2", text="Random")
1126         sub.prop(part, "roughness_2_size", text="Size")
1127         sub.prop(part, "roughness_2_threshold", slider=True)
1128
1129         layout.row().label(text="Kink:")
1130         layout.row().prop(part, "kink", expand=True)
1131
1132         split = layout.split()
1133         split.active = part.kink != 'NO'
1134
1135         col = split.column()
1136         sub = col.column(align=True)
1137         sub.prop(part, "kink_amplitude")
1138         sub.prop(part, "kink_amplitude_clump", text="Clump", slider=True)
1139         col.prop(part, "kink_flat", slider=True)
1140         col = split.column(align=True)
1141         col.prop(part, "kink_frequency")
1142         col.prop(part, "kink_shape", slider=True)
1143
1144
1145 class PARTICLE_PT_field_weights(ParticleButtonsPanel, Panel):
1146     bl_label = "Field Weights"
1147     bl_options = {'DEFAULT_CLOSED'}
1148     COMPAT_ENGINES = {'BLENDER_RENDER'}
1149
1150     @classmethod
1151     def poll(cls, context):
1152         return particle_panel_poll(cls, context)
1153
1154     def draw(self, context):
1155         part = particle_get_settings(context)
1156         effector_weights_ui(self, context, part.effector_weights, 'PSYS')
1157
1158         if part.type == 'HAIR':
1159             row = self.layout.row()
1160             row.prop(part.effector_weights, "apply_to_hair_growing")
1161             row.prop(part, "apply_effector_to_children")
1162             row = self.layout.row()
1163             row.prop(part, "effect_hair", slider=True)
1164
1165
1166 class PARTICLE_PT_force_fields(ParticleButtonsPanel, Panel):
1167     bl_label = "Force Field Settings"
1168     bl_options = {'DEFAULT_CLOSED'}
1169     COMPAT_ENGINES = {'BLENDER_RENDER'}
1170
1171     def draw(self, context):
1172         layout = self.layout
1173
1174         part = particle_get_settings(context)
1175
1176         row = layout.row()
1177         row.prop(part, "use_self_effect")
1178         row.prop(part, "effector_amount", text="Amount")
1179
1180         split = layout.split(percentage=0.2)
1181         split.label(text="Type 1:")
1182         split.prop(part.force_field_1, "type", text="")
1183         basic_force_field_settings_ui(self, context, part.force_field_1)
1184         if part.force_field_1.type != 'NONE':
1185             layout.label(text="Falloff:")
1186         basic_force_field_falloff_ui(self, context, part.force_field_1)
1187
1188         if part.force_field_1.type != 'NONE':
1189             layout.label(text="")
1190
1191         split = layout.split(percentage=0.2)
1192         split.label(text="Type 2:")
1193         split.prop(part.force_field_2, "type", text="")
1194         basic_force_field_settings_ui(self, context, part.force_field_2)
1195         if part.force_field_2.type != 'NONE':
1196             layout.label(text="Falloff:")
1197         basic_force_field_falloff_ui(self, context, part.force_field_2)
1198
1199
1200 class PARTICLE_PT_vertexgroups(ParticleButtonsPanel, Panel):
1201     bl_label = "Vertex Groups"
1202     bl_options = {'DEFAULT_CLOSED'}
1203     COMPAT_ENGINES = {'BLENDER_RENDER'}
1204
1205     @classmethod
1206     def poll(cls, context):
1207         if context.particle_system is None:
1208             return False
1209         return particle_panel_poll(cls, context)
1210
1211     def draw(self, context):
1212         layout = self.layout
1213
1214         ob = context.object
1215         psys = context.particle_system
1216
1217         split = layout.split(percentage=0.85)
1218
1219         col = split.column()
1220         col.label(text="Vertex Group:")
1221         col.prop_search(psys, "vertex_group_density", ob, "vertex_groups", text="Density")
1222         col.prop_search(psys, "vertex_group_length", ob, "vertex_groups", text="Length")
1223         col.prop_search(psys, "vertex_group_clump", ob, "vertex_groups", text="Clump")
1224         col.prop_search(psys, "vertex_group_kink", ob, "vertex_groups", text="Kink")
1225         col.prop_search(psys, "vertex_group_roughness_1", ob, "vertex_groups", text="Roughness 1")
1226         col.prop_search(psys, "vertex_group_roughness_2", ob, "vertex_groups", text="Roughness 2")
1227         col.prop_search(psys, "vertex_group_roughness_end", ob, "vertex_groups", text="Roughness End")
1228
1229         col = split.column()
1230         col.label(text="Negate:")
1231         col.alignment = 'RIGHT'
1232         col.prop(psys, "invert_vertex_group_density", text="")
1233         col.prop(psys, "invert_vertex_group_length", text="")
1234         col.prop(psys, "invert_vertex_group_clump", text="")
1235         col.prop(psys, "invert_vertex_group_kink", text="")
1236         col.prop(psys, "invert_vertex_group_roughness_1", text="")
1237         col.prop(psys, "invert_vertex_group_roughness_2", text="")
1238         col.prop(psys, "invert_vertex_group_roughness_end", text="")
1239
1240         # Commented out vertex groups don't work and are still waiting for better implementation
1241         # row = layout.row()
1242         # row.prop_search(psys, "vertex_group_velocity", ob, "vertex_groups", text="Velocity")
1243         # row.prop(psys, "invert_vertex_group_velocity", text="")
1244
1245         # row = layout.row()
1246         # row.prop_search(psys, "vertex_group_size", ob, "vertex_groups", text="Size")
1247         # row.prop(psys, "invert_vertex_group_size", text="")
1248
1249         # row = layout.row()
1250         # row.prop_search(psys, "vertex_group_tangent", ob, "vertex_groups", text="Tangent")
1251         # row.prop(psys, "invert_vertex_group_tangent", text="")
1252
1253         # row = layout.row()
1254         # row.prop_search(psys, "vertex_group_rotation", ob, "vertex_groups", text="Rotation")
1255         # row.prop(psys, "invert_vertex_group_rotation", text="")
1256
1257         # row = layout.row()
1258         # row.prop_search(psys, "vertex_group_field", ob, "vertex_groups", text="Field")
1259         # row.prop(psys, "invert_vertex_group_field", text="")
1260
1261
1262 class PARTICLE_PT_custom_props(ParticleButtonsPanel, PropertyPanel, Panel):
1263     COMPAT_ENGINES = {'BLENDER_RENDER'}
1264     _context_path = "particle_system.settings"
1265     _property_type = bpy.types.ParticleSettings
1266
1267 if __name__ == "__main__":  # only for live edit.
1268     bpy.utils.register_module(__name__)