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