A bunch of fun stuff now possible because of new pointcache code:
[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
358                         sub.itemL(text="Timing:")
359                         sub.itemR(part, "abs_path_time")
360                         sub.itemR(part, "path_start", text="Start", slider= not part.abs_path_time)
361                         sub.itemR(part, "path_end", text="End", slider= not part.abs_path_time)         
362                         sub.itemR(part, "random_length", text="Random", slider=True)
363                         
364                         row = layout.row()
365                         col = row.column()
366                         
367                         if part.type=='HAIR' and part.render_strand==True and part.child_type=='FACES':
368                                 layout.itemR(part, "enable_simplify")
369                                 if part.enable_simplify==True:
370                                         row = layout.row()
371                                         row.itemR(part, "simplify_refsize")
372                                         row.itemR(part, "simplify_rate")
373                                         row.itemR(part, "simplify_transition")
374                                         row = layout.row()
375                                         row.itemR(part, "viewport")
376                                         subrow = row.row()
377                                         subrow.active = part.viewport==True
378                                         subrow.itemR(part, "simplify_viewport")
379                         
380
381                 elif part.ren_as == 'OBJECT':
382                         sub.itemR(part, "dupli_object")
383                 elif part.ren_as == 'GROUP':
384                         sub.itemR(part, "dupli_group")
385                         split = layout.split()
386                         sub = split.column()
387                         sub.itemR(part, "whole_group")
388                         sub = split.column()
389                         colsub = sub.column()
390                         colsub.active = part.whole_group == False
391                         colsub.itemR(part, "rand_group")
392                         
393                 elif part.ren_as == 'BILLBOARD':
394                         sub.itemL(text="Align:")
395                         
396                         row = layout.row()
397                         row.itemR(part, "billboard_align", expand=True)
398                         row.itemR(part, "billboard_lock", text="Lock")
399                         row = layout.row()
400                         row.itemR(part, "billboard_object")
401                 
402                         row = layout.row()
403                         col = row.column(align=True)
404                         col.itemL(text="Tilt:")
405                         col.itemR(part, "billboard_tilt", text="Angle", slider=True)
406                         col.itemR(part, "billboard_random_tilt", slider=True)
407                         col = row.column()
408                         col.itemR(part, "billboard_offset")
409                         
410                         row = layout.row()
411                         row.itemR(psys, "billboard_normal_uv")
412                         row = layout.row()
413                         row.itemR(psys, "billboard_time_index_uv")
414                         
415                         row = layout.row()
416                         row.itemL(text="Split uv's:")
417                         row.itemR(part, "billboard_uv_split", text="Number of splits")
418                         row = layout.row()
419                         row.itemR(psys, "billboard_split_uv")
420                         row = layout.row()
421                         row.itemL(text="Animate:")
422                         row.itemR(part, "billboard_animation", expand=True)
423                         row.itemL(text="Offset:")
424                         row.itemR(part, "billboard_split_offset", expand=True)
425                 if part.ren_as == 'HALO' or part.ren_as == 'LINE' or part.ren_as=='BILLBOARD':
426                         row = layout.row()
427                         col = row.column()
428                         col.itemR(part, "trail_count")
429                         if part.trail_count > 1:
430                                 col.itemR(part, "abs_path_time", text="Length in frames")
431                                 col = row.column()
432                                 col.itemR(part, "path_end", text="Length", slider=not part.abs_path_time)
433                                 col.itemR(part, "random_length", text="Random", slider=True)
434                         else:
435                                 col = row.column()
436                                 col.itemL(text="")
437                                 
438 class PARTICLE_PT_draw(ParticleButtonsPanel):
439         __idname__= "PARTICLE_PT_draw"
440         __label__ = "Display"
441         __default_closed__ = True
442         
443         def poll(self, context):
444                 psys = context.particle_system
445                 if psys==None: return False
446                 if psys.settings==None: return False
447                 return True;
448         
449         def draw(self, context):
450                 layout = self.layout
451
452                 psys = context.particle_system
453                 part = psys.settings
454                 
455                 row = layout.row()
456                 row.itemR(part, "draw_as", expand=True)
457                 
458                 if part.draw_as=='NONE' or (part.ren_as=='NONE' and part.draw_as=='RENDER'):
459                         return
460                         
461                 path = (part.ren_as=='PATH' and part.draw_as=='RENDER') or part.draw_as=='PATH'
462                         
463                 if path and part.type!='HAIR' and psys.point_cache.baked==False:
464                         box = layout.box()
465                         box.itemL(text="Baked or keyed particles needed for correct drawing.")
466                         return
467                 
468                 row = layout.row()
469                 row.itemR(part, "display", slider=True)
470                 if part.draw_as!='RENDER' or part.ren_as=='HALO':
471                         row.itemR(part, "draw_size")
472                 else:
473                         row.itemL(text="")
474                 
475                 row = layout.row()
476                 col = row.column()
477                 col.itemR(part, "show_size")
478                 col.itemR(part, "velocity")
479                 col.itemR(part, "num")
480                 if part.physics_type == 'BOIDS':
481                         col.itemR(part, "draw_health")
482                 
483                 col = row.column()
484                 col.itemR(part, "material_color", text="Use material color")
485                 
486                 if (path):
487                         box = col.box()                         
488                         box.itemR(part, "draw_step")
489                 else:
490                         subcol = col.column()
491                         subcol.active = part.material_color==False
492                         #subcol.itemL(text="color")
493                         #subcol.itemL(text="Override material color")
494
495 class PARTICLE_PT_children(ParticleButtonsPanel):
496         __idname__= "PARTICLE_PT_children"
497         __label__ = "Children"
498         __default_closed__ = True
499
500         def draw(self, context):
501                 layout = self.layout
502
503                 psys = context.particle_system
504                 part = psys.settings
505                 
506                 layout.row().itemR(part, "child_type", expand=True)
507                 
508                 if part.child_type=='NONE':
509                         return
510                 
511                 row = layout.row()
512                 
513                 col = row.column(align=True)
514                 col.itemR(part, "child_nbr", text="Display")
515                 col.itemR(part, "rendered_child_nbr", text="Render")
516                 
517                 col = row.column(align=True)
518                 
519                 if part.child_type=='FACES':
520                         col.itemR(part, "virtual_parents", slider=True)
521                 else:
522                         col.itemR(part, "child_radius", text="Radius")
523                         col.itemR(part, "child_roundness", text="Roundness", slider=True)
524                 
525                         col = row.column(align=True)
526                         col.itemR(part, "child_size", text="Size")
527                         col.itemR(part, "child_random_size", text="Random")
528                 
529                 layout.row().itemL(text="Effects:")
530                 
531                 row = layout.row()
532                 
533                 col = row.column(align=True)
534                 col.itemR(part, "clump_factor", slider=True)
535                 col.itemR(part, "clumppow", slider=True)
536                 
537                 col = row.column(align=True)
538                 col.itemR(part, "rough_endpoint")
539                 col.itemR(part, "rough_end_shape")
540
541                 row = layout.row()
542                 
543                 col = row.column(align=True)
544                 col.itemR(part, "rough1")
545                 col.itemR(part, "rough1_size")
546
547                 col = row.column(align=True)
548                 col.itemR(part, "rough2")
549                 col.itemR(part, "rough2_size")
550                 col.itemR(part, "rough2_thres", slider=True)
551                 
552                 layout.row().itemL(text="Kink:")
553                 layout.row().itemR(part, "kink", expand=True)
554                 
555                 split = layout.split()
556                 
557                 sub = split.column()
558                 sub.itemR(part, "kink_amplitude")
559                 sub.itemR(part, "kink_frequency")
560                 sub = split.column()
561                 sub.itemR(part, "kink_shape", slider=True)
562
563 class PARTICLE_PT_vertexgroups(ParticleButtonsPanel):
564         __idname__= "PARTICLE_PT_vertexgroups"
565         __label__ = "Vertexgroups"
566         __default_closed__ = True
567
568         def draw(self, context):
569                 layout = self.layout
570
571                 psys = context.particle_system
572                 part = psys.settings
573                 
574                 layout.itemL(text="Nothing here yet.")
575
576                 #row = layout.row()
577                 #row.itemL(text="Vertex Group")
578                 #row.itemL(text="Negate")
579
580                 
581                 #row = layout.row()
582                 #row.itemR(psys, "vertex_group_density")
583                 #row.itemR(psys, "vertex_group_density_negate", text="")
584                 
585                 #row = layout.row()
586                 #row.itemR(psys, "vertex_group_velocity")
587                 #row.itemR(psys, "vertex_group_velocity_negate", text="")
588                 
589                 #row = layout.row()
590                 #row.itemR(psys, "vertex_group_length")
591                 #row.itemR(psys, "vertex_group_length_negate", text="")
592                 
593                 #row = layout.row()
594                 #row.itemR(psys, "vertex_group_clump")
595                 #row.itemR(psys, "vertex_group_clump_negate", text="")
596                 
597                 #row = layout.row()
598                 #row.itemR(psys, "vertex_group_kink")
599                 #row.itemR(psys, "vertex_group_kink_negate", text="")
600                 
601                 #row = layout.row()
602                 #row.itemR(psys, "vertex_group_roughness1")
603                 #row.itemR(psys, "vertex_group_roughness1_negate", text="")
604                 
605                 #row = layout.row()
606                 #row.itemR(psys, "vertex_group_roughness2")
607                 #row.itemR(psys, "vertex_group_roughness2_negate", text="")
608                 
609                 #row = layout.row()
610                 #row.itemR(psys, "vertex_group_roughness_end")
611                 #row.itemR(psys, "vertex_group_roughness_end_negate", text="")
612
613                 #row = layout.row()
614                 #row.itemR(psys, "vertex_group_size")
615                 #row.itemR(psys, "vertex_group_size_negate", text="")
616                 
617                 #row = layout.row()
618                 #row.itemR(psys, "vertex_group_tangent")
619                 #row.itemR(psys, "vertex_group_tangent_negate", text="")
620                 
621                 #row = layout.row()
622                 #row.itemR(psys, "vertex_group_rotation")
623                 #row.itemR(psys, "vertex_group_rotation_negate", text="")
624                 
625                 #row = layout.row()
626                 #row.itemR(psys, "vertex_group_field")
627                 #row.itemR(psys, "vertex_group_field_negate", text="")
628                 
629 bpy.types.register(PARTICLE_PT_particles)
630 bpy.types.register(PARTICLE_PT_cache)
631 bpy.types.register(PARTICLE_PT_emission)
632 bpy.types.register(PARTICLE_PT_initial)
633 bpy.types.register(PARTICLE_PT_physics)
634 bpy.types.register(PARTICLE_PT_render)
635 bpy.types.register(PARTICLE_PT_draw)
636 bpy.types.register(PARTICLE_PT_children)
637 bpy.types.register(PARTICLE_PT_vertexgroups)