… | |
… | |
20 | for ($1..$2) { push @{$cfg->{dir}}, $_ } |
20 | for ($1..$2) { push @{$cfg->{dir}}, $_ } |
21 | |
21 | |
22 | } elsif (m/dir\s*=\s*(\d+)/) { |
22 | } elsif (m/dir\s*=\s*(\d+)/) { |
23 | push @{$cfg->{dir}}, $1; |
23 | push @{$cfg->{dir}}, $1; |
24 | |
24 | |
|
|
25 | } elsif (m/replace\s+(\S+)\s+(\S+)/) { |
|
|
26 | push @{$cfg->{replace}}, [$1, $2]; |
|
|
27 | |
25 | } elsif (m/(\S+)\s*=\s*(.*)/) { |
28 | } elsif (m/(\S+)\s*=\s*(.*)/) { |
26 | $cfg->{$1} = $2; |
29 | $cfg->{$1} = $2; |
|
|
30 | |
27 | } |
31 | } |
28 | } |
32 | } |
29 | }; |
33 | }; |
30 | if ($@) { warn "Couldn't read $file\n" } |
34 | if ($@) { warn "Couldn't read $file\n" } |
31 | |
35 | |
… | |
… | |
41 | my ($x, $y, $z, $up, $r, $move_vec) = @_; |
45 | my ($x, $y, $z, $up, $r, $move_vec) = @_; |
42 | |
46 | |
43 | $move_vec ||= vector (0, 0, 0); |
47 | $move_vec ||= vector (0, 0, 0); |
44 | |
48 | |
45 | my $v = vector ($x, $y, $z); |
49 | my $v = vector ($x, $y, $z); |
46 | $v = $v + (0.5 * $z * $up); |
50 | $v = $v + (0.5 * $z * $up); |
47 | $v = $v + (0.25 * $z * $r); |
51 | $v = $v + (0.25 * $z * $r); |
48 | $v = $v + $move_vec; |
52 | $v = $v + $move_vec; |
49 | |
53 | |
50 | "p $v" |
54 | "p $v" |
51 | } |
55 | } |
… | |
… | |
55 | my ($x, $y) = ($cfg->{height} / 2, $cfg->{height} / 2); |
59 | my ($x, $y) = ($cfg->{height} / 2, $cfg->{height} / 2); |
56 | |
60 | |
57 | my ($w, $h) = ($cfg->{w}, $cfg->{h} || $cfg->{w}); |
61 | my ($w, $h) = ($cfg->{w}, $cfg->{h} || $cfg->{w}); |
58 | |
62 | |
59 | my $to = vector (0, 0, 0); |
63 | my $to = vector (0, 0, 0); |
60 | my $from = vector (0, 0, $cfg->{height}); |
64 | my $from = 1 ? vector (0, $cfg->{height}, 0) : vector (0, 0, $cfg->{height}); |
61 | |
65 | |
62 | my $dir = ($from - $to)->norm; |
66 | my $dir = ($from - $to)->norm; |
63 | |
67 | |
64 | my $up; |
68 | my $up; |
65 | my $r; |
69 | my $r; |
… | |
… | |
94 | $m = ($cfg->{xoffs} || 0) * $r + ($cfg->{yoffs} || 0) * $upv; |
98 | $m = ($cfg->{xoffs} || 0) * $r + ($cfg->{yoffs} || 0) * $upv; |
95 | } |
99 | } |
96 | |
100 | |
97 | $cont =~ s/p\s*x="([^"]+)"\s*y="([^"]+)"\s*z="([^"]+)"/add ($1, $2, $3, $upv, $r, $m)/egs; |
101 | $cont =~ s/p\s*x="([^"]+)"\s*y="([^"]+)"\s*z="([^"]+)"/add ($1, $2, $3, $upv, $r, $m)/egs; |
98 | |
102 | |
|
|
103 | |
99 | my $light = ($r + vector (0, 0, 0.7) + -$upv)->norm; # x="0" y="1" z="0.5"/> |
104 | my $light = ($r + vector (0, 0, 0.7) + -$upv)->norm; # x="0" y="1" z="0.5"/> |
100 | my $backlight = (-$r + vector (0, 0, 0.7) + $upv)->norm; |
105 | my $backlight = (-$r + vector (0, 0, 0.7) + $upv)->norm; |
101 | |
106 | |
102 | my $cam = <<CAM; |
107 | my $cam = <<CAM; |
103 | <light type="sunlight" name="w_Infinite2" power="0.3" cast_shadows="off"> |
108 | <light type="sunlight" name="w_Infinite2" power="0.5" cast_shadows="off"> |
104 | <from $backlight/> |
109 | <from $backlight/> |
105 | <color r="1.0" g="1.0" b="1.0"/> |
110 | <color r="1.0" g="1.0" b="1.0"/> |
106 | </light> |
111 | </light> |
107 | |
112 | |
108 | <light type="sunlight" name="w_Infinite" power="1" cast_shadows="off"> |
113 | <light type="sunlight" name="w_Infinite" power="1" cast_shadows="off"> |
109 | <from $light/> |
114 | <from $light/> |
110 | <color r="0.7" g="0.7" b="0.7"/> |
115 | <color r="1" g="1" b="1"/> |
111 | </light> |
116 | </light> |
112 | |
117 | |
113 | <!-- Section Background, Camera, Filter and Render --> |
118 | <!-- Section Background, Camera, Filter and Render --> |
114 | |
119 | |
115 | <camera name="x_Camera" resx="$w" resy="$h" focal="10" type="ortho"> |
120 | <camera name="x_Camera" resx="$w" resy="$h" focal="10" type="ortho"> |
… | |
… | |
136 | my ($cont, $dir, $cfg, $outfile) = @_; |
141 | my ($cont, $dir, $cfg, $outfile) = @_; |
137 | |
142 | |
138 | my $cam; |
143 | my $cam; |
139 | ($cont, $cam) = new_cam ($cont, $dir, $cfg, $outfile); |
144 | ($cont, $cam) = new_cam ($cont, $dir, $cfg, $outfile); |
140 | |
145 | |
|
|
146 | for (@{$cfg->{replace}}) { |
|
|
147 | $cont =~ s/\Q$_->[0]\E/$_->[1]/egs; |
|
|
148 | } |
|
|
149 | |
141 | $cont =~ s#<light.*<\/scene>#$cam."<\/scene>"#es; |
150 | $cont =~ s#<light.*<\/scene>#$cam."<\/scene>"#es; |
|
|
151 | $cont =~ s#<camera.*<\/scene>#<!--CAM-->#gs; |
|
|
152 | $cont =~ s#<render.*<\/scene>#<!--CAM-->#gs; |
|
|
153 | $cont =~ s#<!--CAM-->#$cam."<\/scene>"#es; |
142 | |
154 | |
143 | $cont |
155 | $cont |
144 | } |
156 | } |
145 | |
157 | |
146 | my $xml = $ARGV[0] or die "render <xml>\n"; |
158 | my $xml = $ARGV[0] or die "render <xml>\n"; |
… | |
… | |
154 | my ($vol, $dir, $file) = File::Spec->splitpath($xml); |
166 | my ($vol, $dir, $file) = File::Spec->splitpath($xml); |
155 | |
167 | |
156 | $file =~ m/^(.*?)\.xml/; |
168 | $file =~ m/^(.*?)\.xml/; |
157 | my $filebase = $1 || $file; |
169 | my $filebase = $1 || $file; |
158 | |
170 | |
159 | for (@{$cfg->{dir}}) { |
171 | for my $d (@{$cfg->{dir}}) { |
160 | my $ofile = File::Spec->catpath ($vol, $dir, "${filebase}_dir_${_}.tga"); |
172 | my $ofile = File::Spec->catpath ($vol, $dir, "${filebase}_dir_${d}.tga"); |
161 | my $oxfile = File::Spec->catpath ($vol, $dir, "${filebase}_rend_${_}.xml"); |
173 | my $oxfile = File::Spec->catpath ($vol, $dir, "${filebase}_rend_${d}.xml"); |
162 | |
174 | |
163 | my $nc = render_dir ($xmlcont, $_, $cfg, "${filebase}_dir_${_}.tga"); |
175 | my $nc = render_dir ($xmlcont, $d, $cfg, "${filebase}_dir_${d}.tga"); |
|
|
176 | |
164 | open OUT, ">$oxfile" |
177 | open OUT, ">$oxfile" |
165 | or die "Couldn't write '$nc': $!"; |
178 | or die "Couldn't write '$nc': $!"; |
166 | print OUT $nc; |
179 | print OUT $nc; |
167 | close OUT; |
180 | close OUT; |
|
|
181 | |
168 | my $cwd = getcwd; |
182 | my $cwd = getcwd; |
|
|
183 | |
169 | if ($dir) { |
184 | if ($dir) { |
170 | system ("cd $dir; yafray ${filebase}_rend_${_}.xml > yafray_out.log"); |
185 | system ("cd $dir; yafray ${filebase}_rend_${d}.xml > yafray_out.log 2> yafray_out.log"); |
171 | } else { |
186 | } else { |
172 | system ("yafray ${filebase}_rend_${_}.xml > yafray_out.log"); |
187 | system ("yafray ${filebase}_rend_${d}.xml > yafray_out.log 2> yafray_out.log"); |
173 | } |
188 | } |
|
|
189 | |
174 | unlink $oxfile; |
190 | unlink $oxfile; |
|
|
191 | |
|
|
192 | if ($cfg->{archname}) { |
|
|
193 | if (@{$cfg->{dir}} > 1) { |
|
|
194 | system ("convert ${filebase}_dir_${d}.tga $cfg->{archname}$d.png"); |
|
|
195 | print "saved arch png to: $cfg->{archname}$d.png\n"; |
|
|
196 | } else { |
|
|
197 | system ("convert ${filebase}_dir_${d}.tga $cfg->{archname}.png"); |
|
|
198 | print "saved arch png to: $cfg->{archname}.png\n"; |
|
|
199 | } |
|
|
200 | } else { |
|
|
201 | system ("convert ${filebase}_dir_${d}.tga ${filebase}_dir_${d}.png"); |
|
|
202 | print "saved arch png to: ${filebase}_dir_${d}.png\n"; |
|
|
203 | } |
|
|
204 | |
175 | print "rendered $ofile\n"; |
205 | print "rendered $ofile\n"; |
176 | } |
206 | } |