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