animate_particles.py 2.08 KB
Newer Older
Rafael Pezzi's avatar
Rafael Pezzi committed
1
# -*- coding: utf-8 -*-
2
# animate_particles.py - Animate HEP events
Rafael Pezzi's avatar
Rafael Pezzi committed
3
#
4
5
6
7
8
#   For console only rendering:
#   $ blender -noaudio --background -P animate_particles.py
#
# TODO: - Implement command line arguments
#         - https://blender.stackexchange.com/questions/6817/how-to-pass-command-line-arguments-to-a-blender-python-script
Rafael Pezzi's avatar
Rafael Pezzi committed
9

10
import os
Rafael Pezzi's avatar
Rafael Pezzi committed
11
12
import bpy
bpy.context.user_preferences.view.show_splash = False
13
14
# Import Drivers, partiles and scence functions:
filename = os.path.join(os.path.basename(bpy.data.filepath), "drivers.py")
Rafael Pezzi's avatar
Rafael Pezzi committed
15
16
exec(compile(open(filename).read(), filename, 'exec'))

17
18
# Set animation parameters
r_part = 0.05 # Particle radius
19
20
21
22
simulated_t = 0.015
duration = 15
fps = 24
resolution_percent = 100
23
24

#configure output
25
26
27
28
outputPath = "/tmp/blender/"
fileIdentifier = "PhysicalTrajectories_"
##  RenderCameras: ["ForwardCamera", "OverviewCamera", "BarrelCamera"]
renderCamera="ForwardCamera"
29

30
renderAnimation = False #True # True
31
32
saveBlenderFile = False # False

Breno Rilho Lemos's avatar
Breno Rilho Lemos committed
33
"""
34
# Create and configure animation driver
35
36
n_particles = 100 # Event Multiplicity
driver = genDriver("GaussianGenerator",n_particles,3.0) # Simple genDriver takes two parameters: number of particles and Gaussian width
37
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
Breno Rilho Lemos's avatar
Breno Rilho Lemos committed
38
39
40
41
42
"""

# Create and configure animation driver
driver = dataDriver("AlirootFileGenerator","esd-detail.dat") # Simple dataDriver takes one parameters: filename
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
43
44
45

### Build scene
init() # Cleanup, addCameras, addALICE_TPC
46
particles = driver.getParticles()
47
blender_particles, blender_tracks = createSceneParticles(particles,createTracks = True) # Create blender objects - one sphere per particle
48
49
50

#Animate scene using driver
animate(blender_particles,particles,driver)
51
52
animate_tracks(blender_tracks,particles,driver)

53
bpy.context.scene.frame_current = 24
54
55

## Save blender file
56
if saveBlenderFile: bpy.ops.wm.save_as_mainfile(filepath=outputPath+fileIdentifier+".blend")
57
58

# Render animation
59
if renderAnimation: driver.render()
60
61

#exit()