Commit c0a09171 authored by Breno Rilho Lemos's avatar Breno Rilho Lemos 💬

Save HD picture of animation along with clip

parent 9cb9ca8e
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# animate_particles.py - Animate HEP events # animate_particles.py - Animate HEP events
# #
# For console only rendering (example): # For console only rendering (example):
# $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera="BarrelCamera" -datafile="esd-detail.dat" -n_event=0 -simulated_t=0.02 -fps=24 -resolution=100 -transparency=1.2 -stamp_note="Texto no canto" -its=1 -tpc=0 -trd=1 -emcal=0 -blendersave=0 # $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera="BarrelCamera" -datafile="esd-detail.dat" -n_event=0 -simulated_t=0.02 -fps=24 -resolution=100 -transparency=1.2 -stamp_note="Texto no canto" -its=1 -tpc=0 -trd=1 -emcal=0 -blendersave=0 -picpct=5
# #
import os import os
...@@ -41,6 +41,7 @@ parser.add_argument('-tpc','--tpc') ...@@ -41,6 +41,7 @@ parser.add_argument('-tpc','--tpc')
parser.add_argument('-trd','--trd') parser.add_argument('-trd','--trd')
parser.add_argument('-emcal','--emcal') parser.add_argument('-emcal','--emcal')
parser.add_argument('-blendersave','--blendersave') parser.add_argument('-blendersave','--blendersave')
parser.add_argument('-picpct','--picpct')
args = parser.parse_args() args = parser.parse_args()
bpy.context.user_preferences.view.show_splash = False bpy.context.user_preferences.view.show_splash = False
...@@ -60,6 +61,7 @@ transp_par = float(args.transp_par) ...@@ -60,6 +61,7 @@ transp_par = float(args.transp_par)
datafile = str(args.datafile) datafile = str(args.datafile)
detectors = [int(args.its),int(args.tpc),int(args.trd),int(args.emcal)] # Array that stores which detectors to build detectors = [int(args.its),int(args.tpc),int(args.trd),int(args.emcal)] # Array that stores which detectors to build
blendersave = int(args.blendersave) # 1 (save Blender file) or 0 (don't) blendersave = int(args.blendersave) # 1 (save Blender file) or 0 (don't)
picpct = int(args.picpct) # percentage of animation to take picture
#configure output #configure output
outputPath = "/tmp/blender/" outputPath = "/tmp/blender/"
...@@ -89,6 +91,7 @@ blender_particles, blender_tracks = createSceneParticles(particles,createTracks ...@@ -89,6 +91,7 @@ blender_particles, blender_tracks = createSceneParticles(particles,createTracks
#Animate scene using driver #Animate scene using driver
animate(blender_particles,particles,driver) animate(blender_particles,particles,driver)
animate_tracks(blender_tracks,particles,driver) animate_tracks(blender_tracks,particles,driver)
take_picture(picpct,driver)
bpy.context.scene.frame_current = 24 bpy.context.scene.frame_current = 24
......
...@@ -367,3 +367,11 @@ def animate_tracks(tracks, particles, driver): ...@@ -367,3 +367,11 @@ def animate_tracks(tracks, particles, driver):
#point.keyframe_insert(data_path="co", frame = i) #point.keyframe_insert(data_path="co", frame = i)
# https://blender.stackexchange.com/questions/73630/animate-curves-by-changing-spline-data-using-a-python-script # https://blender.stackexchange.com/questions/73630/animate-curves-by-changing-spline-data-using-a-python-script
def take_picture(pic_pct,driver):
bcs = bpy.context.scene
bcs.frame_current = int(bcs.frame_end * pic_pct/100)
bcs.camera = bpy.data.objects[driver.renderCamera]
bpy.ops.render.render()
bpy.data.images['Render Result'].save_render(filepath=bcs.render.filepath+".png")
...@@ -34,7 +34,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then ...@@ -34,7 +34,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
fi fi
OPTIONS=c:hdau:m:n:t:r: OPTIONS=c:hdau:m:n:t:r:
LONGOPTS=camera:,resolution:,fps:,transparency:,duration:,maxparticles:,minparticles:,numberofevents:,minavgpz:,minavgpt:,help,download,sample,url:,its,tpc,trd,emcal,blendersave LONGOPTS=camera:,resolution:,fps:,transparency:,duration:,maxparticles:,minparticles:,numberofevents:,minavgpz:,minavgpt:,help,download,sample,url:,its,tpc,trd,emcal,blendersave,picpct:
# -regarding ! and PIPESTATUS see above # -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors # -temporarily store output to be able to check for errors
...@@ -71,6 +71,7 @@ TPC=1 ...@@ -71,6 +71,7 @@ TPC=1
TRD=1 TRD=1
EMCAL=1 EMCAL=1
BLENDERSAVE=0 BLENDERSAVE=0
PICPCT=80
# now enjoy the options in order and nicely split until we see -- # now enjoy the options in order and nicely split until we see --
while true; do while true; do
case "$1" in case "$1" in
...@@ -131,6 +132,10 @@ while true; do ...@@ -131,6 +132,10 @@ while true; do
CAMERA="$2" CAMERA="$2"
shift 2 shift 2
;; ;;
--picpct)
PICPCT="$2"
shift 2
;;
--its) --its)
ITS=0 ITS=0
shift shift
...@@ -208,6 +213,8 @@ Usage: ...@@ -208,6 +213,8 @@ Usage:
Which camera to use for the animation, where VALUE Which camera to use for the animation, where VALUE
is a comma-separated list (without spaces) is a comma-separated list (without spaces)
Options: Barrel,Forward,Overview (defaults to Overview) Options: Barrel,Forward,Overview (defaults to Overview)
--picpct VALUE
Percentage of animation to take HD picture, saved along with the clip.
-a | --sample -a | --sample
Creates a sample Blender animation of Event 2 from URL Creates a sample Blender animation of Event 2 from URL
http://opendata.cern.ch/record/1102/files/assets/alice/2010/LHC10h/000139038/ESD/0001/AliESDs.root http://opendata.cern.ch/record/1102/files/assets/alice/2010/LHC10h/000139038/ESD/0001/AliESDs.root
...@@ -252,6 +259,7 @@ else ...@@ -252,6 +259,7 @@ else
echo "Min Average Z Momentum: ${MIN_AVG_PZ}" echo "Min Average Z Momentum: ${MIN_AVG_PZ}"
echo "Min Average Transversal Momentum: ${MIN_AVG_PT}" echo "Min Average Transversal Momentum: ${MIN_AVG_PT}"
echo "Camera: $CAMERA" echo "Camera: $CAMERA"
echo "Picture Percentage: ${PICPCT}%"
echo "-----------------------------------" echo "-----------------------------------"
echo "------------ Detectors ------------" echo "------------ Detectors ------------"
if [[ $ITS = 1 ]]; then if [[ $ITS = 1 ]]; then
...@@ -315,7 +323,7 @@ if [ "$SAMPLE" = "true" ]; then ...@@ -315,7 +323,7 @@ if [ "$SAMPLE" = "true" ]; then
pushd ${BLENDER_SCRIPT_DIR} pushd ${BLENDER_SCRIPT_DIR}
for type in $CAMERA; do for type in $CAMERA; do
echo "Preparing sample animation with $type in Blender" echo "Preparing sample animation with $type in Blender"
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="d-esd-detail.dat" -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="opendata.cern.ch_record_1102_alice_2010_LHC10h_000139038_ESD_0001_2" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -blendersave=${BLENDERSAVE} blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="d-esd-detail.dat" -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="opendata.cern.ch_record_1102_alice_2010_LHC10h_000139038_ESD_0001_2" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -blendersave=${BLENDERSAVE} -picpct=5
done done
popd popd
BLENDER_OUTPUT=. BLENDER_OUTPUT=.
...@@ -418,7 +426,7 @@ elif [ "$SAMPLE" = "false" ]; then ...@@ -418,7 +426,7 @@ elif [ "$SAMPLE" = "false" ]; then
for type in $CAMERA; do for type in $CAMERA; do
echo "Processing ${EVENT_UNIQUE_ID} with $type in Blender" echo "Processing ${EVENT_UNIQUE_ID} with $type in Blender"
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="${LOCAL_FILE_WITH_DATA}" -n_event=${EVENT_ID} -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="${EVENT_UNIQUE_ID}" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -blendersave=${BLENDERSAVE} blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${type} -datafile="${LOCAL_FILE_WITH_DATA}" -n_event=${EVENT_ID} -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} -stamp_note="${EVENT_UNIQUE_ID}" -its=${ITS} -tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -blendersave=${BLENDERSAVE} -picpct=${PICPCT}
# Move generated file to final location # Move generated file to final location
mv /tmp/blender/* ${BLENDER_OUTPUT} mv /tmp/blender/* ${BLENDER_OUTPUT}
echo "${type} for event ${EVENT_UNIQUE_ID} done." echo "${type} for event ${EVENT_UNIQUE_ID} done."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment