animate_particles.py 2.16 KB
Newer Older
Rafael Pezzi's avatar
Rafael Pezzi committed
1
2
3
4
# -*- coding: utf-8 -*-
# particulas.py - Protótipo de animação de partículas
# Para utilizar este script chame o blender com a opção -P e o nome do arquivo
#
5
6
7
8
9
#   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
10
11
12

import bpy
bpy.context.user_preferences.view.show_splash = False
13
14
bcs = bpy.context.scene
bcsr = bcs.render
Rafael Pezzi's avatar
Rafael Pezzi committed
15
16
import math
import os
17
import random
Rafael Pezzi's avatar
Rafael Pezzi committed
18
19
20
# Import Particle class
filename = os.path.join(os.path.basename(bpy.data.filepath), "particle.py")
exec(compile(open(filename).read(), filename, 'exec'))
21
22
23
# Import scene functions
filename = os.path.join(os.path.basename(bpy.data.filepath), "scene_functions.py")
exec(compile(open(filename).read(), filename, 'exec'))
Rafael Pezzi's avatar
Rafael Pezzi committed
24

25
26
27
28
29

# Set animation parameters
renderCamera = "ForwardCamera" # Set rendering Camera: "ForwardCamera" "OverviewCamera" "BarrelCamera"
n_particles = 500 # Event Multiplicity
r_part = 0.05 # Particle radius
30
t_video=15 # total video duration in seconds
31
t_simulado=0.015 # tempo simulado em microssegundos. 0.01 é o tempo para percorrer 3m na velocidade da luz
32
33
34
fps = 24 # frames per second
N_frames=t_video*fps # Total number of frames
delta_t=t_simulado/N_frames # time elapsed per frame
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
bcs.frame_start = 0
bcs.frame_end = N_frames
init()

#configure output
fileIdentifier="_GaussianMomentum-PhysicalTrajectories_"
configureOutput(fileIdentifier,resolution_percent=100)
renderAnimation=False

addCameras() # Add cameras
addALICE_TPC() # ALICE TPC
particles = createNparticlesPropGaussian(n_particles) # Create particles
blender_particles = create(particles) # Create blender objects - one sphere per particle
animate(blender_particles,particles)  #Animate Scene using particle propagator
bpy.context.scene.frame_current = 24
50
51
52

## Todo:
##  - Add option to keep particle trails
53
54
55
56
57

## Save blender file
#bpy.ops.wm.save_as_mainfile(filepath="/home/pezzi/particles_"+str(n_particles)+".blend")

# Render animation
58
59
bpy.context.scene.camera = bpy.data.objects[renderCamera]
bpy.ops.render.render(animation=renderAnimation)
60
61

#exit()