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