Commit b08f74da authored by Breno Rilho Lemos's avatar Breno Rilho Lemos 💬
Browse files

Improve transperency settings and create transperency parameter

parent d9af104a
...@@ -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 -stamp_note="Texto no canto" # $ 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 -transperency=1.2 -stamp_note="Texto no canto"
# #
import os import os
...@@ -35,6 +35,7 @@ parser.add_argument('-fps','--fps') ...@@ -35,6 +35,7 @@ parser.add_argument('-fps','--fps')
parser.add_argument('-resolution','--resolution_percent') parser.add_argument('-resolution','--resolution_percent')
parser.add_argument('-stamp_note','--stamp_note') parser.add_argument('-stamp_note','--stamp_note')
parser.add_argument('-n_event','--n_event') parser.add_argument('-n_event','--n_event')
parser.add_argument('-transperency','--transp_par')
args = parser.parse_args() args = parser.parse_args()
bpy.context.user_preferences.view.show_splash = False bpy.context.user_preferences.view.show_splash = False
...@@ -49,6 +50,7 @@ simulated_t = float(args.simulated_t) # in microsseconds ...@@ -49,6 +50,7 @@ simulated_t = float(args.simulated_t) # in microsseconds
duration = int(args.duration) # in seconds duration = int(args.duration) # in seconds
fps = int(args.fps) fps = int(args.fps)
resolution_percent = int(args.resolution_percent) resolution_percent = int(args.resolution_percent)
transp_par = float(args.transp_par)
#configure output #configure output
outputPath = "/tmp/blender/" outputPath = "/tmp/blender/"
...@@ -71,7 +73,7 @@ driver = dataDriver("AlirootFileGenerator",n_event,args.datafile) # Simple dataD ...@@ -71,7 +73,7 @@ driver = dataDriver("AlirootFileGenerator",n_event,args.datafile) # Simple dataD
driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent) driver.configure(renderCamera, duration, fps, simulated_t, outputPath, fileIdentifier, resolution_percent)
### Build scene ### Build scene
init(args.stamp_note) # Cleanup, addCameras, addALICE_TPC init(args.stamp_note,renderCamera,transp_par) # Cleanup, addCameras, addALICE_TPC
particles = driver.getParticles() particles = driver.getParticles()
blender_particles, blender_tracks = createSceneParticles(particles,createTracks = True) # Create blender objects - one sphere per particle blender_particles, blender_tracks = createSceneParticles(particles,createTracks = True) # Create blender objects - one sphere per particle
......
...@@ -11,13 +11,14 @@ def subtract(that,fromThat): ...@@ -11,13 +11,14 @@ def subtract(that,fromThat):
bpy.data.objects[that.name].select = True bpy.data.objects[that.name].select = True
bpy.ops.object.delete() bpy.ops.object.delete()
def createMaterial(name,R,G,B,shadows,cast_shadows,transperency,alpha,specular_alpha,fresnel_factor,fresnel): def createMaterial(name,R,G,B,shadows,cast_shadows,transperency,alpha,emit,specular_alpha,fresnel_factor,fresnel):
bpy.data.materials.new(name=name) bpy.data.materials.new(name=name)
bpy.data.materials[name].diffuse_color = (R, G, B) # Blue bpy.data.materials[name].diffuse_color = (R, G, B)
bpy.data.materials[name].use_shadows = shadows bpy.data.materials[name].use_shadows = shadows
bpy.data.materials[name].use_cast_shadows = cast_shadows bpy.data.materials[name].use_cast_shadows = cast_shadows
bpy.data.materials[name].use_transparency = transperency bpy.data.materials[name].use_transparency = transperency
bpy.data.materials[name].alpha = alpha bpy.data.materials[name].alpha = alpha
bpy.data.materials[name].emit = emit
bpy.data.materials[name].specular_alpha = specular_alpha bpy.data.materials[name].specular_alpha = specular_alpha
bpy.data.materials[name].raytrace_transparency.fresnel_factor = fresnel_factor bpy.data.materials[name].raytrace_transparency.fresnel_factor = fresnel_factor
bpy.data.materials[name].raytrace_transparency.fresnel = fresnel bpy.data.materials[name].raytrace_transparency.fresnel = fresnel
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
filename = os.path.join(os.path.basename(bpy.data.filepath), "blender_functions.py") filename = os.path.join(os.path.basename(bpy.data.filepath), "blender_functions.py")
exec(compile(open(filename).read(), filename, 'exec')) exec(compile(open(filename).read(), filename, 'exec'))
def init(unique_id): def init(unique_id,camera_type,transp_par):
bcs = bpy.context.scene bcs = bpy.context.scene
# Configure Environment # Configure Environment
...@@ -29,71 +29,38 @@ def init(unique_id): ...@@ -29,71 +29,38 @@ def init(unique_id):
# Basic Objects # Basic Objects
addCameras() # Add cameras addCameras() # Add cameras
addALICE_Geometry() # ALICE TPC, EMCal,
def addALICE_Geometry(): if camera_type == "ForwardCamera":
addALICE_Geometry(True,transp_par) # ALICE TPC, EMCal, ITS, TRD
else:
addALICE_Geometry(False,transp_par)
# Add big cube to subtract from TPC def addALICE_Geometry(bright_colors=True, transp_par=1.0):
bpy.ops.mesh.primitive_cube_add(location=(5.1,-5.1,0), radius=5.1)
bpy.context.object.name = "BigCube"
# ADD OUTER TPC if bright_colors: # Defining sequence of RGB values to fill 'createMaterial' functions below
rgb_v = [13,13,25,10] # Colors for "ForwardCamera"
else:
rgb_v = [0.5,0.9,1,0.2] # Colors for "OverviewCamera" and "BarrelCamera"
# Material # ADD TPC
createMaterial("outerTPC",R=0,G=255,B=0,shadows=False,cast_shadows=False,transperency=True,alpha=0.1,specular_alpha=0,fresnel_factor=5,fresnel=0.3)
# Add "hole" to subtract from the middle
bpy.ops.mesh.primitive_cylinder_add(radius=1.346, depth=6, view_align=False, enter_editmode=False, location=(0, 0, 0)) #smaller cylinder
outer_TPC_hole = bpy.context.object
outer_TPC_hole.name = "Hole"
# Add actual Outer TPC part
bpy.ops.mesh.primitive_cylinder_add(radius=2.461, depth=5.1, view_align=False, enter_editmode=False, location=(0, 0, 0)) #bigger cylinder
outer_TPC = bpy.context.object
outer_TPC.name = "outerTPC"
# Subtract hole from main TPC part
subtract(outer_TPC_hole,outer_TPC)
# Set material
outer_TPC.data.materials.clear()
outer_TPC.data.materials.append(bpy.data.materials["outerTPC"])
# ADD INNER TPC
# Material # Material
createMaterial("innerTPC",R=0,G=102,B=255,shadows=False,cast_shadows=False,transperency=True,alpha=0.1,specular_alpha=0,fresnel_factor=5,fresnel=0.3) createMaterial("tpc",R=0,G=rgb_v[0],B=0,shadows=False,cast_shadows=False,transperency=True,alpha=transp_par*0.2,emit=0.3,specular_alpha=0,fresnel_factor=5,fresnel=0.3)
# Add Inner TPC # Add TPC
bpy.ops.mesh.primitive_cylinder_add(radius=1.321, depth=5.1, view_align=False, enter_editmode=False, location=(0, 0, 0)) bpy.ops.mesh.primitive_cylinder_add(radius=2.461, depth=5.1, view_align=False, enter_editmode=False, location=(0, 0, 0)) #bigger cylinder
inner_TPC = bpy.context.object
inner_TPC.name = "innerTPC"
# Set Material
inner_TPC.data.materials.clear()
inner_TPC.data.materials.append(bpy.data.materials["innerTPC"])
# Make TPC one single object = inner + outer
joinObjects([inner_TPC,outer_TPC])
TPC = bpy.context.object TPC = bpy.context.object
TPC.name = "TPC" TPC.name = "TPC"
# Make TPC active object again # Set material
bpy.context.scene.objects.active = TPC TPC.data.materials.clear()
TPC.data.materials.append(bpy.data.materials["tpc"])
# Delete Big Cube
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects["BigCube"].select = True
bpy.ops.object.delete()
# ADD EMCal # ADD EMCal
# Material # Material
createMaterial("emcal",R=255,G=255,B=0,shadows=False,cast_shadows=False,transperency=True,alpha=0.1,specular_alpha=0,fresnel_factor=5,fresnel=0.3) createMaterial("emcal",R=rgb_v[1],G=rgb_v[1],B=0,shadows=False,cast_shadows=False,transperency=True,alpha=transp_par*0.05,emit=1.5,specular_alpha=0,fresnel_factor=5,fresnel=0.3)
# Add cylinder for EMCal # Add cylinder for EMCal
bpy.ops.mesh.primitive_cylinder_add(radius=4.7, depth=5.1, vertices=19, view_align=False, enter_editmode=False, location=(0, 0, 0)) bpy.ops.mesh.primitive_cylinder_add(radius=4.7, depth=5.1, vertices=19, view_align=False, enter_editmode=False, location=(0, 0, 0))
...@@ -133,7 +100,7 @@ def addALICE_Geometry(): ...@@ -133,7 +100,7 @@ def addALICE_Geometry():
# ADD ITS INNER BARREL # ADD ITS INNER BARREL
# Material # Material
createMaterial("innerITS",R=139,G=0,B=139,shadows=False,cast_shadows=False,transperency=True,alpha=0.7,specular_alpha=0,fresnel_factor=5,fresnel=0.3) createMaterial("innerITS",R=rgb_v[2],G=0,B=rgb_v[2],shadows=False,cast_shadows=False,transperency=True,alpha=transp_par*0.7,emit=0,specular_alpha=0,fresnel_factor=5,fresnel=0.3)
# Add Inner ITS # Add Inner ITS
bpy.ops.mesh.primitive_cylinder_add(radius=0.0421, depth=0.271, view_align=False, enter_editmode=False, location=(0, 0, 0)) bpy.ops.mesh.primitive_cylinder_add(radius=0.0421, depth=0.271, view_align=False, enter_editmode=False, location=(0, 0, 0))
...@@ -148,7 +115,7 @@ def addALICE_Geometry(): ...@@ -148,7 +115,7 @@ def addALICE_Geometry():
# ADD ITS OUTER BARREL # ADD ITS OUTER BARREL
# Material # Material
createMaterial("outerITS",R=.200,G=0,B=.200,shadows=False,cast_shadows=False,transperency=True,alpha=0.7,specular_alpha=0,fresnel_factor=5,fresnel=0.3) createMaterial("outerITS",R=rgb_v[3],G=0,B=rgb_v[3],shadows=False,cast_shadows=False,transperency=True,alpha=transp_par*0.4,emit=0.8,specular_alpha=0,fresnel_factor=5,fresnel=0.3)
# ADD ITS MIDDLE LAYERS # ADD ITS MIDDLE LAYERS
...@@ -198,7 +165,7 @@ def addALICE_Geometry(): ...@@ -198,7 +165,7 @@ def addALICE_Geometry():
# ADD ALICE TRD # ADD ALICE TRD
# Material # Material
createMaterial("TRD",R=0.2,G=0,B=0.2,shadows=False,cast_shadows=False,transperency=True,alpha=0.5,specular_alpha=0,fresnel_factor=5,fresnel=0.3) createMaterial("TRD",R=rgb_v[3],G=0,B=rgb_v[3],shadows=False,cast_shadows=False,transperency=True,alpha=transp_par*0.15,emit=0.8,specular_alpha=0,fresnel_factor=5,fresnel=0.3)
# Add "hole" to subtract from the middle # Add "hole" to subtract from the middle
bpy.ops.mesh.primitive_cylinder_add(radius=2.9, depth=6, vertices=18, view_align=False, enter_editmode=False, location=(0, 0, 0)) #smaller cylinder bpy.ops.mesh.primitive_cylinder_add(radius=2.9, depth=6, vertices=18, view_align=False, enter_editmode=False, location=(0, 0, 0)) #smaller cylinder
...@@ -244,7 +211,6 @@ def addALICE_Geometry(): ...@@ -244,7 +211,6 @@ def addALICE_Geometry():
bpy.ops.mesh.primitive_cube_add(radius=1, location=(xn,yn,0)) bpy.ops.mesh.primitive_cube_add(radius=1, location=(xn,yn,0))
slice = bpy.context.object slice = bpy.context.object
slice.name = "slice" slice.name = "slice"
#bpy.context.object.name = "slice" + str(n)
bpy.ops.transform.resize(value=(1,0.03,4)) bpy.ops.transform.resize(value=(1,0.03,4))
bpy.context.object.rotation_euler[2] = rotat bpy.context.object.rotation_euler[2] = rotat
...@@ -253,14 +219,14 @@ def addALICE_Geometry(): ...@@ -253,14 +219,14 @@ def addALICE_Geometry():
def addCameras(): def addCameras():
# ForwardCamera # ForwardCamera
bpy.ops.object.camera_add(location = (0,1,20), rotation = (0, 0, 0)) bpy.ops.object.camera_add(location = (0,0.5,20), rotation = (0, 0, 0))
bpy.context.object.name = "ForwardCamera" bpy.context.object.name = "ForwardCamera"
camera_forward=bpy.data.objects['ForwardCamera'] camera_forward=bpy.data.objects['ForwardCamera']
camera_forward.data.type = 'ORTHO' camera_forward.data.type = 'ORTHO'
camera_forward.data.ortho_scale = 13 camera_forward.data.ortho_scale = 18
# OverviewCamera # OverviewCamera
bpy.ops.object.camera_add(location = (20.936, 9.8, 20.448), rotation = (-0.071558, 0.879645, 0.305433)) bpy.ops.object.camera_add(location = (23.27182, 10.3968, 22.754), rotation = (-0.071558, 0.879645, 0.305433))
bpy.context.object.name = "OverviewCamera" bpy.context.object.name = "OverviewCamera"
bpy.context.object.data.lens = 66.78 bpy.context.object.data.lens = 66.78
......
...@@ -33,8 +33,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then ...@@ -33,8 +33,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
exit 1 exit 1
fi fi
OPTIONS=c:hdau:m:t:r: OPTIONS=c:hdau:m:t:r:b:
LONGOPTS=camera:,resolution:,duration:,maxparticles:,help,download,default,url: LONGOPTS=camera:,resolution:,transperency:,duration:,maxparticles:,help,download,default,url:
# -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
...@@ -52,9 +52,10 @@ eval set -- "$PARSED" ...@@ -52,9 +52,10 @@ eval set -- "$PARSED"
############################## ##############################
# Parse Parameters # # Parse Parameters #
############################## ##############################
CAMERA=Barrel CAMERA=Overview
DURATION=10 DURATION=10
RESOLUTION=100 RESOLUTION=100
TRANSPERENCY=1
MAX_PARTICLES=0 MAX_PARTICLES=0
HELP=false HELP=false
DOWNLOAD=false DOWNLOAD=false
...@@ -92,10 +93,14 @@ while true; do ...@@ -92,10 +93,14 @@ while true; do
RESOLUTION="$2" RESOLUTION="$2"
shift 2 shift 2
;; ;;
-b|--transperency)
TRANSPERENCY="$2"
shift 2
;;
-c|--camera) -c|--camera)
CAMERA="$2" CAMERA="$2"
shift 2 shift 2
;; ;;
--) --)
shift shift
break break
...@@ -130,6 +135,9 @@ Usage: ...@@ -130,6 +135,9 @@ Usage:
Set the animation duration in seconds. Set the animation duration in seconds.
-r | --resolution VALUE -r | --resolution VALUE
Set the animation resolution percentage. Set the animation resolution percentage.
-b | --transperency VALUE
Set detector transperency as a number greater than zero,
where zero is full transperency and 1 is standard transperency
-c | --camera VALUE -c | --camera VALUE
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)
...@@ -157,6 +165,9 @@ else ...@@ -157,6 +165,9 @@ else
echo "URL: $URL" echo "URL: $URL"
echo "Download: $DOWNLOAD" echo "Download: $DOWNLOAD"
echo "Default: $DEFAULT" echo "Default: $DEFAULT"
echo "Transperency Parameter: $TRANSPERENCY"
echo "Duration: $DURATION"
echo "Resolution: $RESOLUTION"
echo "Max particles: ${MAX_PARTICLES}" echo "Max particles: ${MAX_PARTICLES}"
echo "Camera: $CAMERA" echo "Camera: $CAMERA"
echo "-----------------------------------" echo "-----------------------------------"
...@@ -207,7 +218,7 @@ if [ "$DEFAULT" = "true" ]; then ...@@ -207,7 +218,7 @@ if [ "$DEFAULT" = "true" ]; then
# Phase 1: blender animate # # Phase 1: blender animate #
############################## ##############################
pushd ${BLENDER_SCRIPT_DIR} pushd ${BLENDER_SCRIPT_DIR}
blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera="OverviewCamera" -datafile="d-esd-detail.dat" -simulated_t=0.03 -fps=24 -resolution=${RESOLUTION} -stamp_note="Default animation" blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=${DURATION} -camera=${CAMERA} -datafile="d-esd-detail.dat" -simulated_t=0.03 -fps=24 -resolution=${RESOLUTION} -transperency=${TRANSPERENCY} -stamp_note="Default animation"
popd popd
BLENDER_OUTPUT=. BLENDER_OUTPUT=.
mkdir --verbose -p ${BLENDER_OUTPUT} mkdir --verbose -p ${BLENDER_OUTPUT}
...@@ -280,7 +291,7 @@ elif [ "$DEFAULT" = "false" ]; then ...@@ -280,7 +291,7 @@ elif [ "$DEFAULT" = "false" ]; then
for type in $CAMERA; do for type in $CAMERA; do
echo "Processing ${EVENT_UNIQUE_ID} with $type Camera in blender" echo "Processing ${EVENT_UNIQUE_ID} with $type Camera 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=24 -resolution=${RESOLUTION} -stamp_note="${EVENT_UNIQUE_ID}" 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=24 -resolution=${RESOLUTION} -transperency=${TRANSPERENCY} -stamp_note="${EVENT_UNIQUE_ID}"
# 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