animate_particles.py 1.73 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")
15
exec(compile(open(filename).read(), filename, 'exec'))
Rafael Pezzi's avatar
Rafael Pezzi committed
16

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
31
32
33
renderAnimation = True # True
saveBlenderFile = False # False

# Create and configure animation driver
34
35
n_particles = 100 # Event Multiplicity
driver = genDriver("GaussianGenerator",n_particles,3.0) # Simple genDriver takes two parameters: number of particles and Gaussian width
36
37
38
39
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)

### Build scene
init() # Cleanup, addCameras, addALICE_TPC
40
particles = driver.getParticles()
41
42
43
44
45
blender_particles = createSceneParticles(particles) # Create blender objects - one sphere per particle

#Animate scene using driver
animate(blender_particles,particles,driver)
bpy.context.scene.frame_current = 24
46
47

## Save blender file
48
if saveBlenderFile: bpy.ops.wm.save_as_mainfile(filepath=outputPath+fileIdentifier+".blend")
49
50

# Render animation
51
if renderAnimation: driver.render()
52
53

#exit()