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