/
beowulf_blend.pl
228 lines (199 loc) · 5.66 KB
/
beowulf_blend.pl
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/perl
##########################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This script was based on "blendbat.pl" by Stefano (S68) Selleri
# which can be obtained at http://www.selleri.org/Blender/
#
##########################################################################
##############################################################
# A Perl Batch to spawn blender renderings #
##############################################################
#### PARAMETERS TO CONFIGURE ####
@NodeNames = ("machine_1", "machine_2", "machine_3");
#### The above parameter specifies the names of the machines (nodes)
# onto which the rendering will be spawned. More machines
# can be added to suit your cluster.
#
$RootDir = "directory_name";
#### The directory where the .blend file is and where the images
# and logs will be store:
# A directory is shared on one node and visible
# by all other, in this directory a single copy of the .blend file
# is stored and output.
#
# The rendering will be produced independently, hence if you
# chosen AVI file you'll have as many AVIs as processes.
# rendering TARGAs or JPGs and then using the sequence
# editor can be better.
#
# Console Outputs by Blender are redirected on a file, in
# the RootDir directory, named dumpblend.N.M where N is the node
# number (0,1,...) and M is the process number in that node,
# usefull for debugging
#
$OutputDir = "directory_name";
#### Directory where the rendered images will be placed. If you are
# using an NFS to share rendered images make sure this directory
# exists on each node.
#### END OF CONFIG SECTION ####
$f = $ARGV[0] || die "Missing file name (try beowulf_blend.pl -h)\n";
if ($f=~/^-h/){
print "\n\n beowulf_blend.pl (C) Mar. 2008 Brandon (cdated) Fields\n\n";
print " based on blendbat.pl (C) Sept. 2002 Stefano (S68) Selleri\n\n";
print "usage:\n\n beowulf_blend.pl file.blend StartFrame EndFrame\n\n";
print " flile.blend - The blender file. it must be located in\n";
print " directory specified in the configuration parameters\n";
print " of this script.i\n\n";
print " StartFrame - First frame of the batch\n";
print " EndFrame - Last frame of the batch\n\n";
die;
}
$start = $ARGV[1] || die "Missing start frame (try beowulf_blend.pl -h)\n";
$end = $ARGV[2] || die "Missing end frame (try beowulf_blend.pl -h)\n";
# Cleanup directory for new render
#`rm ./output/*.jpg *dump*`;
#$nf is number of frames
$nf=$end-$start;
$finished = "false";
$i = $start;
for($start ... $end)
{
$frames[$i] = $i;
$rendered[$i] = "false";
$nodeArray[$i] = "";
$i++;
}
$i = $start;
foreach $node (@NodeNames)
{
&renderFrame($i, $node);
$nodeArray[$i] = $node;
$i++;
}
#print "starting the while loop\n";
while ($finished eq "false")
{
$frameNum = &nextRender();
&checkRendered($frameNum);
$i = $start;
for ($start ... $end)
{
#print "Frame $i is $rendered[$i], and on node $nodeArray[$i]\n";
$i++;
}
$finished = &allRendered();
}
sub checkNodes {
my($node) = @_;
$i = $start;
for($start ... $end)
{
if(($nodeArray[$i] = $node) && ($rendered[$i] eq "false"))
{
print "$node is currently busy\n";
return "false";
}
else
{
return $node;
}
$i++;
}
}
sub checkRendered {
my ($frameNum) = @_;
$i = $start;
for($start ... $end)
{
$before = $rendered[$i];
if ($i < 10)
{
$rendered[$i] = &fileCheck("000$i.jpg");
}
elsif ($i < 100)
{
$rendered[$i] = &fileCheck("00$i.jpg");
}
elsif ($i < 1000)
{
$rendered[$i] = &fileCheck("0$i.jpg");
}
else
{
$rendered[$i] = &fileCheck("$i.jpg");
}
#print "frame $i rendered is $rendered[$i]\n";
$after = $rendered[$i];
if (!($before eq $after))
{
print "frame $i has been rendered\n";
print "the next frame is $frameNum\n";
print "the node rendering it is $nodeArray[$i]\n";
$nodeArray[$frameNum] = $nodeArray[$i];
&renderFrame($frameNum, $nodeArray[$i]);
#@rendered[$frameNum] = "active";
return;
}
$i++;
}
}
sub nextRender {
$i = $start;
for($start ... $end)
{
if (($nodeArray[$i] eq "") && ($rendered[$i] eq "false"))
{
print "The next frame to be rendered is $i\n";
return $i;
}
$i++;
}
}
sub allRendered {
$i = $start;
for($start ... $end)
{
if ($rendered[$i] eq "false")
{
return "false";
}
$i++;
}
print "\nAll frames have been rendered!\n";
return "true";
}
sub renderFrame {
my($idx, $node) = @_;
if(($nodeArray[$idx] == $node) && ($rendered[$idx] eq "false"))
{
print "The frame $idx is $rendered[$idx]\n";
print "node $node is currently rendering frame $idx\n";
open RESULT, ">$node.txt";
print RESULT $idx;
close RESULT;
#`ssh -n $node "cd $RootDir ; blender -b $f -F JPEG -x 1 -s $idx -e $idx -a -x 1 > dumpblend.$idx; exit" &`;
}
}
sub fileCheck {
my ($file) = @_;
if (-e "$OutputDir/$file")
{
return "true";
}
else
{
return "false";
}
}