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

Add Background Shade option

parent e0751f63
......@@ -4,7 +4,8 @@
# For console only rendering (example):
# $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 \
# -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 -detailed_tpc=1 -emcal=0 -blendersave=0 -picpct=5 -tpc_blender_path="/home/files/blender" -output_path="/tmp/blender"
# -its=1 -tpc=0 -trd=1 -detailed_tpc=1 -emcal=0 -blendersave=0 -tpc_blender_path="/home/files/blender"\
# -output_path="/tmp/blender" -bgshade=0.05
#
import os
......@@ -42,7 +43,7 @@ parser.add_argument('-tpc','--tpc')
parser.add_argument('-trd','--trd')
parser.add_argument('-emcal','--emcal')
parser.add_argument('-blendersave','--blendersave')
parser.add_argument('-picpct','--picpct')
parser.add_argument('-bgshade','--bgshade')
parser.add_argument('-tpc_blender_path','--tpc_blender_path')
parser.add_argument('-detailed_tpc','--detailed_tpc')
parser.add_argument('-output_path','--output_path')
......@@ -65,7 +66,7 @@ transp_par = float(args.transp_par)
datafile = str(args.datafile)
detectors = [int(args.its),int(args.tpc),int(args.trd),int(args.emcal),int(args.detailed_tpc)] # Array that stores which detectors to build
blendersave = int(args.blendersave) # 1 (save Blender file) or 0 (don't)
picpct = int(args.picpct) # percentage of animation to take picture
bgshade = float(args.bgshade)
tpc_blender_path = str(args.tpc_blender_path) # path to 'animate' directory, where .blend file for detailed TPC is saved
# Configure Output
......@@ -86,7 +87,7 @@ driver = dataDriver("AlirootFileGenerator",n_event,datafile) # Simple dataDriver
driver.configure(duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
### Build scene
init(stamp_note,transp_par,detectors,tpc_blender_path) # Cleanup, addCameras, addALICE_TPC
init(stamp_note,transp_par,detectors,tpc_blender_path,bgshade) # Cleanup, addCameras, addALICE_TPC, Set background
particles = driver.getParticles()
blender_particles, blender_tracks = createSceneParticles(particles,createTracks = True) # Create blender objects - one sphere per particle
......
......@@ -2,12 +2,13 @@
filename = os.path.join(os.path.basename(bpy.data.filepath), "blender_functions.py")
exec(compile(open(filename).read(), filename, 'exec'))
def init(unique_id,transp_par,detectors,blender_path):
def init(unique_id,transp_par,detectors,blender_path,bgshade):
bcs = bpy.context.scene
# Configure Environment
bcs.world.light_settings.use_environment_light = False
bcs.world.light_settings.environment_energy = 0.1
bpy.context.scene.world.horizon_color = (bgshade,bgshade,bgshade)
# Configure Stamp
bcsr = bpy.context.scene.render
......@@ -354,7 +355,7 @@ def animate(objects, particles, driver):
bcs = bpy.context.scene
#Animate particles
for f in range(1, bcs.frame_end+1):
for f in range(bcs.frame_end):
t = driver.delta_t*f
bcs.frame_current = f
print("Configuring particles in frame: "+str(f)+" of "+str(bcs.frame_end))
......@@ -368,8 +369,8 @@ def animate_tracks(tracks, particles, driver):
bcs = bpy.context.scene
#Animate tracks
for f in range(1, bcs.frame_end+1):
t = driver.delta_t*f
for f in range(bcs.frame_end):
t = driver.delta_t*(f+1) # choosing (f+1) instead of (f) removes gap between track and particle
bcs.frame_current = f
print("Configuring tracks in frame: "+ str(f) +" of "+ str(bcs.frame_end))
for point in range(f,bcs.frame_end+1):
......
......@@ -50,7 +50,7 @@ fi
OPTIONS=c:hdau:m:n:t:r:
LONGOPTS=cameras:,mosaic,resolution:,fps:,transparency:,duration:,maxparticles:,\
minparticles:,numberofevents:,minavgpz:,minavgpt:,help,download,sample,url:,its,\
tpc,detailedtpc,trd,emcal,blendersave,picpct:
tpc,detailedtpc,trd,emcal,blendersave,picpct:,bgshade:
# -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors
......@@ -90,6 +90,7 @@ TRD=1
EMCAL=1
BLENDERSAVE=0
PICPCT=80
BGSHADE=0.051
# now enjoy the options in order and nicely split until we see --
while true; do
case "$1" in
......@@ -158,6 +159,10 @@ while true; do
PICPCT="$2"
shift 2
;;
--bgshade)
BGSHADE="$2"
shift 2
;;
--its)
ITS=0
shift
......@@ -247,6 +252,9 @@ Usage:
--picpct VALUE
Percentage of animation to take HD picture, saved along with the clip,
where VALUE must be an integer
--bgshade VALUE
Set background shade of black to VALUE, where 0 is totally black
and 1 is totally white
-a | --sample
Creates a sample Blender animation of Event 2 from URL
http://opendata.cern.ch/record/1102/files/assets/alice/2010/LHC10h/000139\
......@@ -301,6 +309,7 @@ else
echo "Cameras: $CAMERAS"
echo "Mosaic: $MOSAIC"
echo "Picture Percentage: ${PICPCT}%"
echo "Background Shade: ${BGSHADE}"
echo "-----------------------------------"
echo "------------ Detectors ------------"
if [[ $ITS = 1 ]]; then
......@@ -386,7 +395,7 @@ if [ "$SAMPLE" = "true" ]; then
-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} -detailed_tpc=${DETAILED_TPC} \
-blendersave=1 -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-blendersave=1 -bgshade=${BGSHADE} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-output_path="${BLENDER_OUTPUT}"
popd
......@@ -610,7 +619,7 @@ elif [ "$SAMPLE" = "false" ]; then
# Create script so we can use GNU parallel #
# to create multiple Blender scenes #
################################################
if ! grep -q "${UNIQUEID}, PREPARED TO MAKE SCENES IN PARALLEL" $PROGRESS_LOG; then
if ! grep -q "${UNIQUEID}, PARALLEL, SCENES, STARTING" $PROGRESS_LOG; then
rm -f scene-making
rm -f make-event-*
......@@ -636,7 +645,7 @@ elif [ "$SAMPLE" = "false" ]; then
-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} -detailed_tpc=${DETAILED_TPC} \
-blendersave=1 -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-blendersave=1 -bgshade=${BGSHADE} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-output_path=\'${BLENDER_OUTPUT}\' >> make-event-${EVENT_ID}
echo timestamp \"${UNIQUEID}, ${EVENT_ID}, BLENDER SCENE, FINISHED, ${NUMBER_OF_PARTICLES}\" \>\> $PROGRESS_LOG >> make-event-${EVENT_ID}
......@@ -647,7 +656,7 @@ elif [ "$SAMPLE" = "false" ]; then
echo ./make-event-${EVENT_ID} >> scene-making
done
timestamp "${UNIQUEID}, PREPARED TO MAKE SCENES IN PARALLEL" >> $PROGRESS_LOG
timestamp "${UNIQUEID}, PARALLEL, SCENES, STARTING" >> $PROGRESS_LOG
fi
......
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