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

Create standard environment for scene optimization; Add SideCamera; Remove AntiOverviewCamera.

parent fb2716a1
......@@ -2,7 +2,7 @@
# animate_particles.py - Animate HEP events
#
# For console only rendering (example):
# $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera="BarrelCamera" \
# $ blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -cameras="BarrelCamera OverviewCamera" \
# -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"
#
......@@ -30,7 +30,7 @@ parser = ArgumentParserForBlender()
parser.add_argument('-radius','--r_part')
parser.add_argument('-duration','--duration')
parser.add_argument('-camera','--render_camera')
parser.add_argument('-cameras','--render_cameras')
parser.add_argument('-datafile','--datafile')
parser.add_argument('-simulated_t','--simulated_t')
parser.add_argument('-fps','--fps')
......@@ -68,11 +68,26 @@ blendersave = int(args.blendersave) # 1 (save Blender file) or 0 (don't)
picpct = int(args.picpct) # percentage of animation to take picture
tpc_blender_path = str(args.tpc_blender_path) # path to 'animate' directory, where .blend file for detailed TPC is saved
# Create array with cameras:
cams_string = str(args.render_cameras)
cams_list = []
j=0
last_space=0
for digit in range(0,len(cams_string)):
if cams_string[digit] == ' ':
cam = ""
for i in range(j,digit):
cam += cams_string[i]
cams_list.append(cam)
j=digit+1
cam = ""
for i in range(j,len(cams_string)):
cam += cams_string[i]
cams_list.append(cam)
#configure output
outputPath = "/tmp/alice_blender/"
fileIdentifier = "PhysicalTrajectories_"
## RenderCameras: ["ForwardCamera", "OverviewCamera", "AntiOverviewCamera", "BarrelCamera"]
renderCamera= args.render_camera
renderAnimation = True # True
saveBlenderFile = blendersave # False
......@@ -81,29 +96,28 @@ saveBlenderFile = blendersave # False
# Create and configure animation driver
n_particles = 100 # Event Multiplicity
driver = genDriver("GaussianGenerator",n_particles,3.0) # Simple genDriver takes two parameters: number of particles and Gaussian width
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
driver.configure(cams_list, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
"""
# Create and configure animation driver
driver = dataDriver("AlirootFileGenerator",n_event,datafile) # Simple dataDriver
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
driver.configure(cams_list, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
### Build scene
init(stamp_note,renderCamera,transp_par,detectors,tpc_blender_path) # Cleanup, addCameras, addALICE_TPC
init(stamp_note,transp_par,detectors,tpc_blender_path) # Cleanup, addCameras, addALICE_TPC
particles = driver.getParticles()
blender_particles, blender_tracks = createSceneParticles(particles,createTracks = True) # Create blender objects - one sphere per particle
#Animate scene using driver
animate(blender_particles,particles,driver)
animate_tracks(blender_tracks,particles,driver)
take_picture(picpct,driver)
bpy.context.scene.frame_current = 24
## Save blender file
if saveBlenderFile: bpy.ops.wm.save_as_mainfile(filepath=outputPath+fileIdentifier+"AlirootFileGenerator_"+datafile+"_Event_"+n_event+"_"+renderCamera+".blend")
if saveBlenderFile: bpy.ops.wm.save_as_mainfile(filepath=outputPath+fileIdentifier+"AlirootFileGenerator_"+datafile+"_Event_"+n_event+".blend")
# Render animation
if renderAnimation: driver.render()
if renderAnimation: driver.render(picpct)
#exit()
......@@ -11,8 +11,8 @@ exec(compile(open(filename).read(), filename, 'exec'))
class animationDriver:
def __init__(self,name):
self.name = name
def configure(self, renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent=100):
self.renderCamera=renderCamera
def configure(self, renderCameras, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent=100):
self.renderCameras=renderCameras # array with cameras to render animation with
self.duration=duration # total video duration in seconds
self.fps=fps
self.simulated_t=simulated_t # total simulated time in microseconds. (0.01 -> light travels ~ 3 m)
......@@ -26,9 +26,24 @@ class animationDriver:
bcs.frame_start = 0
bcs.frame_end = self.N_frames
def render(self):
bpy.context.scene.camera = bpy.data.objects[self.renderCamera]
bpy.ops.render.render(animation=True)
def render(self,pic_pct):
bcs = bpy.context.scene
self.output_prefix=[]
for c in range(0,len(self.renderCameras)):
# Set specific output info
self.output_prefix.append(self.fileIdentifier+str(self.xpixels)+"px_"+self.name+self.renderCameras[c])
bcs.render.filepath = "/tmp/alice_blender/"+self.output_prefix[c]
bcs.camera = bpy.data.objects[self.renderCameras[c]]
# Take picture of animation
bcs.frame_current = int(bcs.frame_end * pic_pct/100)
bpy.ops.render.render()
bpy.data.images['Render Result'].save_render(filepath=bcs.render.filepath+".png")
# Render actual animation
bpy.ops.render.render(animation=True)
def configureOutput(self):
# Configure Output
......@@ -45,9 +60,7 @@ class animationDriver:
bcsr.ffmpeg.buffersize = 224 * 8
bcsr.ffmpeg.packetsize = 2048
bcsr.ffmpeg.muxrate = 10080000
xpixels = int(bcsr.resolution_percentage * bcsr.resolution_x / 100)
output_prefix=self.fileIdentifier+str(xpixels)+"px_"+self.name+self.renderCamera
bcsr.filepath = "/tmp/alice_blender/"+output_prefix
self.xpixels = int(bcsr.resolution_percentage * bcsr.resolution_x / 100)
class genDriver(animationDriver): # A driver for particle generators
def __init__(self,name,N_particles, par1):
......
......@@ -2,7 +2,7 @@
filename = os.path.join(os.path.basename(bpy.data.filepath), "blender_functions.py")
exec(compile(open(filename).read(), filename, 'exec'))
def init(unique_id,camera_type,transp_par,detectors,blender_path):
def init(unique_id,transp_par,detectors,blender_path):
bcs = bpy.context.scene
# Configure Environment
......@@ -29,26 +29,16 @@ def init(unique_id,camera_type,transp_par,detectors,blender_path):
# Basic Objects
addCameras() # Add cameras
addLamps() # Add Lamps
if camera_type == "OverviewCamera":
addOverviewLamps()
else:
if camera_type == "AntiOverviewCamera":
addAntiOverviewLamps()
else:
addLamps() # Add Lamps
if camera_type == "ForwardCamera":
addALICE_Geometry(True,transp_par,detectors,blender_path) # ALICE TPC, EMCal, ITS, TRD
else:
addALICE_Geometry(False,transp_par,detectors,blender_path)
addALICE_Geometry(False,transp_par,detectors,blender_path)
def addALICE_Geometry(bright_colors=True, transp_par=1.0, detectors=[1,1,1,1,0], blender_path="/home/"):
def addALICE_Geometry(bright_colors=False, transp_par=1.0, detectors=[1,1,1,1,0], blender_path="/home/"):
if bright_colors: # Defining sequence of RGB values to fill 'createMaterial' functions below
rgb_v = [13,13,25,10] # Colors for "ForwardCamera"
rgb_v = [13,13,25,10] # Colors for brighter detector
else:
rgb_v = [0.5,0.9,1,0.2] # Colors for "OverviewCamera", "AntiOverviewCamera" and "BarrelCamera"
rgb_v = [0.5,0.9,1,0.2] # Colors for standard geometry
if detectors[0]:
......@@ -258,13 +248,7 @@ def addALICE_EMCal(transp_par,rgb_v):
def addLamps():
bpy.ops.object.lamp_add(type='POINT', location=(4,1,6))
bpy.ops.object.lamp_add(type='POINT', location=(-4,-1,-6))
def addOverviewLamps():
bpy.ops.object.lamp_add(type='POINT', location=(0,0,6))
def addAntiOverviewLamps():
bpy.ops.object.lamp_add(type='POINT', location=(0,0,-6))
bpy.ops.object.lamp_add(type='POINT', location=(0,0,-8))
def addCameras():
# ForwardCamera
......@@ -279,15 +263,15 @@ def addCameras():
bpy.context.object.name = "OverviewCamera"
bpy.context.object.data.lens = 66.78
# AntiOverviewCamera
bpy.ops.object.camera_add(location = (-24.1218, -10.7468, -22.754), rotation = (-0.10123, 2.27591, 3.44703))
bpy.context.object.name = "AntiOverviewCamera"
bpy.context.object.data.lens = 66.78
# Barrel Camera
bpy.ops.object.camera_add(location = (6, 0, 0), rotation = (0, 1.5708, 0))
bpy.context.object.name = "BarrelCamera"
# Side Camera
bpy.ops.object.camera_add(location = (6, 0, 0), rotation = (0, 1.5708, 0))
bpy.context.object.name = "SideCamera"
bpy.context.object.data.lens = 9
# Function that creates Blender Objects from input list of particles.
## Returns a list of blender objects
def createSceneParticles(particles, createTracks = False):
......@@ -405,11 +389,3 @@ def animate_tracks(tracks, particles, driver):
#point.keyframe_insert(data_path="co", frame = i)
# 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
fi
OPTIONS=c:hdau:m:n:t:r:
LONGOPTS=camera:,mosaic,resolution:,fps:,transparency:,duration:,maxparticles:,\
LONGOPTS=cameras:,mosaic,resolution:,fps:,transparency:,duration:,maxparticles:,\
minparticles:,numberofevents:,minavgpz:,minavgpt:,help,download,sample,url:,its,\
tpc,detailedtpc,trd,emcal,blendersave,picpct:
......@@ -54,7 +54,7 @@ eval set -- "$PARSED"
##############################
# Parse Parameters #
##############################
CAMERA=Overview
CAMERAS=Overview
MOSAIC=false
DURATION=10
RESOLUTION=100
......@@ -132,8 +132,8 @@ while true; do
TRANSPARENCY="$2"
shift 2
;;
-c|--camera)
CAMERA="$2"
-c|--cameras)
CAMERAS="$2"
shift 2
;;
--mosaic)
......@@ -222,10 +222,10 @@ Usage:
--transparency VALUE
Set detector transparency as a number greater than zero,
where zero is full transparency and 1 is standard transparency
-c | --camera VALUE
Which camera to use for the animation, where VALUE
-c | --cameras VALUE
Which cameras to use for the animation, where VALUE
is a comma-separated list (without spaces)
Options: Barrel,Forward,Overview,AntiOverview (defaults to Overview)
Options: Barrel,Side,Forward,Overview (defaults to Overview)
--mosaic
Make animations in all four available cameras and combine them into
a single 2x2 clip containing all perspectives, totalizing five generated
......@@ -259,12 +259,12 @@ END
}
# Fix CAMERA to be accepted by the for loop
if [[ $CAMERA != "" ]]; then
CAMERA=$(echo $CAMERA | sed -e 's#,#Camera #g' -e 's#$#Camera#')
if [[ $CAMERAS != "" ]]; then
CAMERAS=$(echo $CAMERAS | sed -e 's#,#Camera #g' -e 's#$#Camera#')
fi
if [[ $MOSAIC == "true" ]]; then
CAMERA=$(echo "OverviewCamera BarrelCamera AntiOverviewCamera ForwardCamera")
CAMERAS=$(echo "OverviewCamera BarrelCamera SideCamera ForwardCamera")
fi
if [[ $HELP = "true" ]]; then
......@@ -284,7 +284,7 @@ else
echo "Number of events: ${N_OF_EVENTS}"
echo "Min Average Z Momentum: ${MIN_AVG_PZ}"
echo "Min Average Transversal Momentum: ${MIN_AVG_PT}"
echo "Camera: $CAMERA"
echo "Cameras: $CAMERAS"
echo "Mosaic: $MOSAIC"
echo "Picture Percentage: ${PICPCT}%"
echo "-----------------------------------"
......@@ -352,15 +352,15 @@ if [ "$SAMPLE" = "true" ]; then
# Phase 1: Blender animate #
##############################
pushd ${BLENDER_SCRIPT_DIR}
for type in $CAMERA; do
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} -detailed_tpc=${DETAILED_TPC} \
-blendersave=${BLENDERSAVE} -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR}
done
echo "Preparing sample animation in Blender"
blender -noaudio --background -P animate_particles.py -- -radius=0.05 \
-duration=${DURATION} -cameras="${CAMERAS}" -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} -detailed_tpc=${DETAILED_TPC} \
-blendersave=${BLENDERSAVE} -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR}
popd
BLENDER_OUTPUT=.
mkdir --verbose -p ${BLENDER_OUTPUT}
......@@ -462,17 +462,17 @@ elif [ "$SAMPLE" = "false" ]; then
pushd ${BLENDER_SCRIPT_DIR}
for type in $CAMERA; do
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} -detailed_tpc=${DETAILED_TPC} \
-blendersave=${BLENDERSAVE} -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR}
echo "${type} for event ${EVENT_UNIQUE_ID} done."
done
echo "Processing ${EVENT_UNIQUE_ID} in Blender"
blender -noaudio --background -P animate_particles.py -- -radius=0.05 \
-duration=${DURATION} -cameras="${CAMERAS}" -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} -detailed_tpc=${DETAILED_TPC} \
-blendersave=${BLENDERSAVE} -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR}
echo "Event ${EVENT_UNIQUE_ID} done."
if [ "$MOSAIC" = "true" ]; then
......
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