-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheager.sh
executable file
·94 lines (78 loc) · 2.67 KB
/
eager.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -e
# Configurable variables
SSH_HOSTS=(username@hostname username@another-hostname username@third-example-hostname)
CHUNK_SIZE=8
## You don't have to edit anything below this line
FILE=$1
BLENDER_OPTIONS=${@:2}
if [ -z "$BLENDER_OPTIONS" ]; then
BLENDER_OPTIONS="-E CYCLES -F PNG -t 0"
fi
tiles=($(seq 0 63))
declare -A MACHINES=( [local]=true )
for i in "${SSH_HOSTS[@]}"; do
MACHINES[$i]=true
done
# Check requirements
if [[ ! -e /usr/bin/sshfs || ! -e /usr/bin/convert ]]; then
echo "$(tput setaf 1)This script requires sshfs and ImageMagick$(tput sgr0)"
exit 1;
fi
# Prepare machines
rm -rf rendering rendering_local
mkdir rendering_local
for host in "${!MACHINES[@]}"; do
if [ $host = "local" ]; then
continue
fi
echo "$(tput setaf 2)$host: create rendering dir$(tput sgr0)"
ssh -qt $host "mkdir -p ~/rendering"
echo "$(tput setaf 2)$host: mount sshfs$(tput sgr0)"
mkdir -p rendering_$host
sshfs -o uid=$(id -u $USER) $host:rendering rendering_$host
echo "$(tput setaf 2)$host: copy necessary files$(tput sgr0)"
cp eager.py $FILE rendering_$host/
done
while [ -n "$tiles" ]; do
for host in "${!MACHINES[@]}"; do
if [ "${MACHINES[$host]}" = true ]; then
range=(${tiles[@]:0:$CHUNK_SIZE})
first=${range[0]}
last=${range[-1]}
last=$((last+1))
echo "$(tput setaf 4)$host: run blender with tiles range $first-$last $(tput sgr0)"
if [ "$host" = "local" ]; then
OUTPUT_DIR=$(realpath rendering_local) TILES_RANGE=$first:$last blender -b $FILE $BLENDER_OPTIONS -P eager.py 2>&1 > /dev/null &
else
ssh -qt -t $host "TILES_RANGE=$first:$last blender -b rendering/$FILE $BLENDER_OPTIONS -P rendering/eager.py" 2>&1 > /dev/null &
fi
MACHINES[$host]=$!
tiles=(${tiles[@]:$CHUNK_SIZE})
else
if [ ! -e /proc/${MACHINES[$host]} ]; then
echo "$(tput setaf 3)$host: finished chunk$(tput sgr0)"
MACHINES[$host]=true
fi
fi
done
sleep 0.1
done
wait
echo "$(tput setaf 2)Rendering finished. Get tiles from remote$(tput sgr0)"
for host in "${!MACHINES[@]}"; do
if [ $host = "local" ]; then
continue
fi
mv rendering_$host/rendered_tile_tmp_* rendering_local/
fusermount -u rendering_$host
rm -r rendering_$host
done
echo "$(tput setaf 2)Composing image$(tput sgr0)"
cd rendering_local
convert rendered_tile_tmp_* -flatten ../$(basename "$FILE" .blend)_rendered_final.png
rm rendered_tile_tmp_*
cd ..
if [ -e /usr/bin/feh ]; then
feh $(basename "$FILE" .blend)_rendered_final.png &
fi