49ceaf6aae1873ef67bfac4a20918f860abf1709
[blender.git] / release / ui / buttons_particle.py
1
2 import bpy
3
4 def particle_panel_enabled(psys):
5         return psys.point_cache.baked==False and psys.editable==False
6         
7 def particle_panel_poll(context):
8         psys = context.particle_system
9         if psys==None:  return False
10         if psys.settings==None:  return False
11         return psys.settings.type in ('EMITTER', 'REACTOR', 'HAIR')
12
13 class ParticleButtonsPanel(bpy.types.Panel):
14         __space_type__ = "BUTTONS_WINDOW"
15         __region_type__ = "WINDOW"
16         __context__ = "particle"
17
18         def poll(self, context):
19                 return particle_panel_poll(context)
20
21 class PARTICLE_PT_particles(ParticleButtonsPanel):
22         __idname__= "PARTICLE_PT_particles"
23         __label__ = "Particle System"
24
25         def poll(self, context):
26                 return (context.particle_system or context.object)
27
28         def draw(self, context):
29                 layout = self.layout
30                 ob = context.object
31                 psys = context.particle_system
32
33                 if ob:
34                         row = layout.row()
35
36                         row.template_list(ob, "particle_systems", ob, "active_particle_system_index")
37
38                         col = row.column(align=True)
39                         col.itemO("OBJECT_OT_particle_system_add", icon="ICON_ZOOMIN", text="")
40                         col.itemO("OBJECT_OT_particle_system_remove", icon="ICON_ZOOMOUT", text="")
41
42                 if psys:
43                         split = layout.split(percentage=0.65)
44                         
45                         split.template_ID(psys, "settings", new="PARTICLE_OT_new")
46                         
47                         #row = layout.row()
48                         #row.itemL(text="Viewport")
49                         #row.itemL(text="Render")
50                         
51                         part = psys.settings
52                         
53                         if part:
54                                 ptype = psys.settings.type
55                                 if ptype not in ('EMITTER', 'REACTOR', 'HAIR'):
56                                         layout.itemL(text="No settings for fluid particles")
57                                         return
58                                         
59                                 split = layout.split(percentage=0.65)
60                                 
61                                 split.enabled = particle_panel_enabled(psys)
62                                 split.itemR(part, "type")
63                                 split.itemR(psys, "seed")
64                                 
65                                 split = layout.split(percentage=0.65)
66                                 if part.type=='HAIR':
67                                         if psys.editable==True:
68                                                 split.itemO("PARTICLE_OT_editable_set", text="Free Edit")
69                                         else:
70                                                 split.itemO("PARTICLE_OT_editable_set", text="Make Editable")
71                                         row = split.row()
72                                         row.enabled = particle_panel_enabled(psys)
73                                         row.itemR(part, "hair_step")
74                                 elif part.type=='REACTOR':
75                                         split.enabled = particle_panel_enabled(psys)
76                                         split.itemR(psys, "reactor_target_object")
77                                         split.itemR(psys, "reactor_target_particle_system", text="Particle System")
78                 
79 class PARTICLE_PT_emission(ParticleButtonsPanel):
80         __idname__= "PARTICLE_PT_emission"
81         __label__ = "Emission"
82         
83         def draw(self, context):
84                 layout = self.layout
85
86                 psys = context.particle_system
87                 part = psys.settings
88                 
89                 layout.enabled = particle_panel_enabled(psys)
90                 
91                 row = layout.row()
92                 row.itemR(part, "amount")
93                 
94                 split = layout.split()
95                 
96                 col = split.column(align=True)
97                 col.itemR(part, "start")
98                 col.itemR(part, "end")
99
100                 col = split.column(align=True)
101                 col.itemR(part, "lifetime")
102                 col.itemR(part, "random_lifetime", slider=True)
103                 
104                 layout.row().itemL(text="Emit From:")
105                 
106                 row = layout.row()
107                 row.itemR(part, "emit_from", expand=True)
108                 row = layout.row()
109                 row.itemR(part, "trand")
110                 if part.distribution!='GRID':
111                         row.itemR(part, "even_distribution")
112                 
113                 if part.emit_from=='FACE' or part.emit_from=='VOLUME':
114                         row = layout.row()
115                         row.itemR(part, "distribution", expand=True)
116                         
117                         row = layout.row()
118
119                         if part.distribution=='JIT':
120                                 row.itemR(part, "userjit", text="Particles/Face")
121                                 row.itemR(part, "jitter_factor", text="Jittering Amount", slider=True)
122                         elif part.distribution=='GRID':
123                                 row.itemR(part, "grid_resolution")
124
125 class PARTICLE_PT_cache(ParticleButtonsPanel):
126         __idname__= "PARTICLE_PT_cache"
127         __label__ = "Cache"
128         __default_closed__ = True
129         
130         def poll(self, context):
131                 psys = context.particle_system
132                 if psys==None:  return False
133                 if psys.settings==None:  return False
134                 return psys.settings.type in ('EMITTER', 'REACTOR')
135
136         def draw(self, context):
137                 layout = self.layout
138
139                 psys = context.particle_system
140                 part = psys.settings
141                 cache = psys.point_cache
142                 
143                 row = layout.row()
144                 row.itemR(cache, "name")
145                 
146                 row = layout.row()
147                 
148                 if cache.baked == True:
149                         row.itemO("PTCACHE_OT_free_bake_particle_system", text="Free Bake")
150                 else:
151                         row.item_booleanO("PTCACHE_OT_cache_particle_system", "bake", True, text="Bake")
152                 
153                 subrow = row.row()
154                 subrow.enabled = (cache.frames_skipped or cache.outdated) and particle_panel_enabled(psys)
155                 subrow.itemO("PTCACHE_OT_cache_particle_system", text="Calculate to Current Frame")
156                 
157                 row = layout.row()
158                 row.enabled = particle_panel_enabled(psys)
159                 row.itemO("PTCACHE_OT_bake_from_particles_cache", text="Current Cache to Bake")
160                 row.itemR(cache, "step");
161         
162                 row = layout.row()
163                 row.enabled = particle_panel_enabled(psys)
164                 row.itemR(cache, "quick_cache")
165                 row.itemR(cache, "disk_cache")
166                 
167                 layout.itemL(text=cache.info)
168                 
169                 layout.itemS()
170                 
171                 row = layout.row()
172                 row.item_booleanO("PTCACHE_OT_bake_all", "bake", True, text="Bake All Dynamics")
173                 row.itemO("PTCACHE_OT_free_bake_all", text="Free All Bakes")
174                 layout.itemO("PTCACHE_OT_bake_all", text="Update All Dynamics to current frame")
175                 
176                 # for particles these are figured out automatically
177                 #row.itemR(cache, "start_frame")
178                 #row.itemR(cache, "end_frame")
179
180 class PARTICLE_PT_initial(ParticleButtonsPanel):
181         __idname__= "PARTICLE_PT_initial"
182         __label__ = "Velocity"
183
184         def draw(self, context):
185                 layout = self.layout
186
187                 psys = context.particle_system
188                 part = psys.settings
189                 
190                 layout.enabled = particle_panel_enabled(psys)
191                                 
192                 layout.row().itemL(text="Direction:")
193         
194                 split = layout.split()
195                         
196                 sub = split.column()
197                 sub.itemR(part, "normal_factor")
198                 if part.emit_from=='PARTICLE':
199                         sub.itemR(part, "particle_factor")
200                 else:
201                         sub.itemR(part, "object_factor", slider=True)
202                 sub.itemR(part, "random_factor")
203                 sub.itemR(part, "tangent_factor")
204                 sub.itemR(part, "tangent_phase", slider=True)
205                 
206                 sub = split.column()
207                 sub.itemL(text="TODO:")
208                 sub.itemL(text="Object aligned")
209                 sub.itemL(text="direction: X, Y, Z")
210                 
211                 if part.type=='REACTOR':
212                         sub.itemR(part, "reactor_factor")
213                         sub.itemR(part, "reaction_shape", slider=True)
214                 else:
215                         sub.itemL(text="")
216                 
217                 layout.row().itemL(text="Rotation:")
218                 split = layout.split()
219                         
220                 sub = split.column()
221                 
222                 sub.itemR(part, "rotation_mode", text="Axis")
223                 split = layout.split()
224                         
225                 sub = split.column()
226                 sub.itemR(part, "rotation_dynamic")
227                 sub.itemR(part, "random_rotation_factor", slider=True)
228                 sub = split.column()
229                 sub.itemR(part, "phase_factor", slider=True)
230                 sub.itemR(part, "random_phase_factor", text="Random", slider=True)
231
232                 layout.row().itemL(text="Angular velocity:")
233                 layout.row().itemR(part, "angular_velocity_mode", expand=True)
234                 split = layout.split()
235                         
236                 sub = split.column()
237                 
238                 sub.itemR(part, "angular_velocity_factor", text="")
239                 
240 class PARTICLE_PT_physics(ParticleButtonsPanel):
241         __idname__= "PARTICLE_PT_physics"
242         __label__ = "Physics"
243
244         def draw(self, context):
245                 layout = self.layout
246
247                 psys = context.particle_system
248                 part = psys.settings
249                 
250                 layout.enabled = layout.enabled = particle_panel_enabled(psys)
251
252                 row = layout.row()
253                 row.itemR(part, "physics_type", expand=True)
254                 if part.physics_type != 'NO':
255                         layout.itemR(part, "effector_group")
256                 
257                         row = layout.row()
258                         col = row.column(align=True)
259                         col.itemR(part, "particle_size")
260                         col.itemR(part, "random_size", slider=True)
261                         col = row.column(align=True)
262                         col.itemR(part, "mass")
263                         col.itemR(part, "sizemass", text="Multiply mass with size")
264                                                         
265                         split = layout.split()
266                         
267                         sub = split.column()
268                         
269                 if part.physics_type == 'NEWTON':
270                         
271                         sub.itemL(text="Forces:")
272                         sub.itemR(part, "brownian_factor")
273                         sub.itemR(part, "drag_factor", slider=True)
274                         sub.itemR(part, "damp_factor", slider=True)
275                         sub.itemR(part, "integrator")
276                         sub = split.column()
277                         sub.itemR(part, "acceleration")
278                         
279                 elif part.physics_type == 'KEYED':
280                         sub.itemR(psys, "keyed_first")
281                         if psys.keyed_first==True:
282                                 sub.itemR(psys, "timed_keys", text="Key timing")
283                         else:
284                                 sub.itemR(part, "keyed_time")
285                         sub = split.column()
286                         sub.itemL(text="Next key from object:")
287                         sub.itemR(psys, "keyed_object", text="")
288                         sub.itemR(psys, "keyed_particle_system")
289                 
290                 if part.physics_type=='NEWTON' or part.physics_type=='BOIDS':
291
292                         sub.itemR(part, "size_deflect")
293                         sub.itemR(part, "die_on_collision")
294                         sub.itemR(part, "sticky")
295
296 class PARTICLE_PT_render(ParticleButtonsPanel):
297         __idname__= "PARTICLE_PT_render"
298         __label__ = "Render"
299         
300         def poll(self, context):
301                 psys = context.particle_system
302                 if psys==None: return False
303                 if psys.settings==None: return False
304                 return True;
305                 
306         def draw(self, context):
307                 layout = self.layout
308
309                 psys = context.particle_system
310                 part = psys.settings
311                 
312                 row = layout.row()
313                 row.itemR(part, "material")
314                 row.itemR(psys, "parent");
315                 
316                 split = layout.split()
317                         
318                 sub = split.column()
319                 sub.itemR(part, "emitter");
320                 sub.itemR(part, "parent");
321                 sub = split.column()
322                 sub.itemR(part, "unborn");
323                 sub.itemR(part, "died");
324                 
325                 row = layout.row()
326                 row.itemR(part, "ren_as", expand=True)
327                 
328                 split = layout.split()
329                         
330                 sub = split.column()
331                 
332                 if part.ren_as == 'LINE':
333                         sub.itemR(part, "line_length_tail")
334                         sub.itemR(part, "line_length_head")
335                         sub = split.column()
336                         sub.itemR(part, "velocity_length")
337                 elif part.ren_as == 'PATH':
338                 
339                         if (part.type!='HAIR' and psys.point_cache.baked==False):
340                                 box = layout.box()
341                                 box.itemL(text="Baked or keyed particles needed for correct rendering.")
342                                 return
343                                 
344                         sub.itemR(part, "render_strand")
345                         colsub = sub.column()
346                         colsub.active = part.render_strand == False
347                         colsub.itemR(part, "render_adaptive")
348                         colsub = sub.column()
349                         colsub.active = part.render_adaptive or part.render_strand == True
350                         colsub.itemR(part, "adaptive_angle")
351                         colsub = sub.column()
352                         colsub.active = part.render_adaptive == True and part.render_strand == False
353                         colsub.itemR(part, "adaptive_pix")
354                         sub.itemR(part, "hair_bspline")
355                         sub.itemR(part, "render_step", text="Steps")
356                         sub = split.column()
357                         sub.itemL(text="Length:")
358                         sub.itemR(part, "abs_length", text="Absolute")
359                         sub.itemR(part, "absolute_length", text="Maximum")
360                         sub.itemR(part, "random_length", text="Random", slider=True)
361                         
362                         #row = layout.row()
363                         #row.itemR(part, "timed_path")
364                         #col = row.column(align=True)
365                         #col.active = part.timed_path == True
366                         #col.itemR(part, "line_length_tail", text="Start")
367                         #col.itemR(part, "line_length_head", text="End")
368                         
369                         row = layout.row()
370                         col = row.column()
371                         
372                         if part.type=='HAIR' and part.render_strand==True and part.child_type=='FACES':
373                                 layout.itemR(part, "enable_simplify")
374                                 if part.enable_simplify==True:
375                                         row = layout.row()
376                                         row.itemR(part, "simplify_refsize")
377                                         row.itemR(part, "simplify_rate")
378                                         row.itemR(part, "simplify_transition")
379                                         row = layout.row()
380                                         row.itemR(part, "viewport")
381                                         subrow = row.row()
382                                         subrow.active = part.viewport==True
383                                         subrow.itemR(part, "simplify_viewport")
384                         
385
386                 elif part.ren_as == 'OBJECT':
387                         #sub = split.column()
388                         sub.itemR(part, "dupli_object")
389                 elif part.ren_as == 'GROUP':
390                         sub.itemR(part, "dupli_group")
391                         split = layout.split()
392                         sub = split.column()
393                         sub.itemR(part, "whole_group")
394                         sub = split.column()
395                         colsub = sub.column()
396                         colsub.active = part.whole_group == False
397                         colsub.itemR(part, "rand_group")
398                         
399                 elif part.ren_as == 'BILLBOARD':
400                         sub.itemL(text="Align:")
401                         
402                         row = layout.row()
403                         row.itemR(part, "billboard_align", expand=True)
404                         row.itemR(part, "billboard_lock", text="Lock")
405                         row = layout.row()
406                         row.itemR(part, "billboard_object")
407                 
408                         row = layout.row()
409                         col = row.column(align=True)
410                         col.itemL(text="Tilt:")
411                         col.itemR(part, "billboard_tilt", text="Angle", slider=True)
412                         col.itemR(part, "billboard_random_tilt", slider=True)
413                         col = row.column()
414                         col.itemR(part, "billboard_offset")
415                         
416                         row = layout.row()
417                         row.itemR(psys, "billboard_normal_uv")
418                         row = layout.row()
419                         row.itemR(psys, "billboard_time_index_uv")
420                         
421                         row = layout.row()
422                         row.itemL(text="Split uv's:")
423                         row.itemR(part, "billboard_uv_split", text="Number of splits")
424                         row = layout.row()
425                         row.itemR(psys, "billboard_split_uv")
426                         row = layout.row()
427                         row.itemL(text="Animate:")
428                         row.itemR(part, "billboard_animation", expand=True)
429                         row.itemL(text="Offset:")
430                         row.itemR(part, "billboard_split_offset", expand=True)
431                 
432 class PARTICLE_PT_draw(ParticleButtonsPanel):
433         __idname__= "PARTICLE_PT_draw"
434         __label__ = "Display"
435         __default_closed__ = True
436         
437         def poll(self, context):
438                 psys = context.particle_system
439                 if psys==None: return False
440                 if psys.settings==None: return False
441                 return True;
442         
443         def draw(self, context):
444                 layout = self.layout
445
446                 psys = context.particle_system
447                 part = psys.settings
448                 
449                 row = layout.row()
450                 row.itemR(part, "draw_as", expand=True)
451                 
452                 if part.draw_as=='NONE' or (part.ren_as=='NONE' and part.draw_as=='RENDER'):
453                         return
454                         
455                 path = (part.ren_as=='PATH' and part.draw_as=='RENDER') or part.draw_as=='PATH'
456                         
457                 if path and part.type!='HAIR' and psys.point_cache.baked==False:
458                         box = layout.box()
459                         box.itemL(text="Baked or keyed particles needed for correct drawing.")
460                         return
461                 
462                 row = layout.row()
463                 row.itemR(part, "display", slider=True)
464                 if part.draw_as!='RENDER' or part.ren_as=='HALO':
465                         row.itemR(part, "draw_size")
466                 else:
467                         row.itemL(text="")
468                 
469                 row = layout.row()
470                 col = row.column()
471                 col.itemR(part, "show_size")
472                 col.itemR(part, "velocity")
473                 col.itemR(part, "num")
474                 if part.physics_type == 'BOIDS':
475                         col.itemR(part, "draw_health")
476                 
477                 col = row.column()
478                 if (path):
479                         box = col.box()                         
480                         box.itemR(part, "draw_step")
481                 else:
482                         col.itemR(part, "material_color", text="Use material color")
483                         subcol = col.column()
484                         subcol.active = part.material_color==False
485                         #subcol.itemL(text="color")
486                         #subcol.itemL(text="Override material color")
487
488 class PARTICLE_PT_children(ParticleButtonsPanel):
489         __idname__= "PARTICLE_PT_children"
490         __label__ = "Children"
491         __default_closed__ = True
492
493         def draw(self, context):
494                 layout = self.layout
495
496                 psys = context.particle_system
497                 part = psys.settings
498                 
499                 layout.row().itemR(part, "child_type", expand=True)
500                 
501                 if part.child_type=='NONE':
502                         return
503                 
504                 row = layout.row()
505                 
506                 col = row.column(align=True)
507                 col.itemR(part, "child_nbr", text="Display")
508                 col.itemR(part, "rendered_child_nbr", text="Render")
509                 
510                 col = row.column(align=True)
511                 
512                 if part.child_type=='FACES':
513                         col.itemR(part, "virtual_parents", slider=True)
514                 else:
515                         col.itemR(part, "child_radius", text="Radius")
516                         col.itemR(part, "child_roundness", text="Roundness", slider=True)
517                 
518                         col = row.column(align=True)
519                         col.itemR(part, "child_size", text="Size")
520                         col.itemR(part, "child_random_size", text="Random")
521                 
522                 layout.row().itemL(text="Effects:")
523                 
524                 row = layout.row()
525                 
526                 col = row.column(align=True)
527                 col.itemR(part, "clump_factor", slider=True)
528                 col.itemR(part, "clumppow", slider=True)
529                 
530                 col = row.column(align=True)
531                 col.itemR(part, "rough_endpoint")
532                 col.itemR(part, "rough_end_shape")
533
534                 row = layout.row()
535                 
536                 col = row.column(align=True)
537                 col.itemR(part, "rough1")
538                 col.itemR(part, "rough1_size")
539
540                 col = row.column(align=True)
541                 col.itemR(part, "rough2")
542                 col.itemR(part, "rough2_size")
543                 col.itemR(part, "rough2_thres", slider=True)
544                 
545                 layout.row().itemL(text="Kink:")
546                 layout.row().itemR(part, "kink", expand=True)
547                 
548                 split = layout.split()
549                 
550                 sub = split.column()
551                 sub.itemR(part, "kink_amplitude")
552                 sub.itemR(part, "kink_frequency")
553                 sub = split.column()
554                 sub.itemR(part, "kink_shape", slider=True)
555
556 class PARTICLE_PT_vertexgroups(ParticleButtonsPanel):
557         __idname__= "PARTICLE_PT_vertexgroups"
558         __label__ = "Vertexgroups"
559         __default_closed__ = True
560
561         def draw(self, context):
562                 layout = self.layout
563
564                 psys = context.particle_system
565                 part = psys.settings
566                 
567                 layout.itemL(text="Nothing here yet.")
568
569                 #row = layout.row()
570                 #row.itemL(text="Vertex Group")
571                 #row.itemL(text="Negate")
572
573                 
574                 #row = layout.row()
575                 #row.itemR(psys, "vertex_group_density")
576                 #row.itemR(psys, "vertex_group_density_negate", text="")
577                 
578                 #row = layout.row()
579                 #row.itemR(psys, "vertex_group_velocity")
580                 #row.itemR(psys, "vertex_group_velocity_negate", text="")
581                 
582                 #row = layout.row()
583                 #row.itemR(psys, "vertex_group_length")
584                 #row.itemR(psys, "vertex_group_length_negate", text="")
585                 
586                 #row = layout.row()
587                 #row.itemR(psys, "vertex_group_clump")
588                 #row.itemR(psys, "vertex_group_clump_negate", text="")
589                 
590                 #row = layout.row()
591                 #row.itemR(psys, "vertex_group_kink")
592                 #row.itemR(psys, "vertex_group_kink_negate", text="")
593                 
594                 #row = layout.row()
595                 #row.itemR(psys, "vertex_group_roughness1")
596                 #row.itemR(psys, "vertex_group_roughness1_negate", text="")
597                 
598                 #row = layout.row()
599                 #row.itemR(psys, "vertex_group_roughness2")
600                 #row.itemR(psys, "vertex_group_roughness2_negate", text="")
601                 
602                 #row = layout.row()
603                 #row.itemR(psys, "vertex_group_roughness_end")
604                 #row.itemR(psys, "vertex_group_roughness_end_negate", text="")
605
606                 #row = layout.row()
607                 #row.itemR(psys, "vertex_group_size")
608                 #row.itemR(psys, "vertex_group_size_negate", text="")
609                 
610                 #row = layout.row()
611                 #row.itemR(psys, "vertex_group_tangent")
612                 #row.itemR(psys, "vertex_group_tangent_negate", text="")
613                 
614                 #row = layout.row()
615                 #row.itemR(psys, "vertex_group_rotation")
616                 #row.itemR(psys, "vertex_group_rotation_negate", text="")
617                 
618                 #row = layout.row()
619                 #row.itemR(psys, "vertex_group_field")
620                 #row.itemR(psys, "vertex_group_field_negate", text="")
621                 
622 bpy.types.register(PARTICLE_PT_particles)
623 bpy.types.register(PARTICLE_PT_cache)
624 bpy.types.register(PARTICLE_PT_emission)
625 bpy.types.register(PARTICLE_PT_initial)
626 bpy.types.register(PARTICLE_PT_physics)
627 bpy.types.register(PARTICLE_PT_render)
628 bpy.types.register(PARTICLE_PT_draw)
629 bpy.types.register(PARTICLE_PT_children)
630 bpy.types.register(PARTICLE_PT_vertexgroups)