Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graphics: scripts for rendering the blender files
- Loading branch information
jason@long.name
committed
Mar 29, 2014
1 parent
f9a30f3
commit c6f090d
Showing
9 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%crop 16x16+0+0 | ||
|
||
301,304 => 0,0 | ||
497,304 => 16,16 | ||
400,373 => 0,16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%crop 32x32+0+0 | ||
|
||
301,304 => 0,0 | ||
497,304 => 32,32 | ||
400,373 => 0,32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%crop 48x48+0+0 | ||
|
||
104,304 => 0,0 | ||
694,304 => 48,48 | ||
400,513 => 0,48 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%crop 96x96+0+0 | ||
|
||
104,304 => 0,0 | ||
694,304 => 96,96 | ||
400,513 => 0,96 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%crop 64x64+0+0 | ||
|
||
6,304 => 0,0 | ||
794,304 => 64,64 | ||
400,583 => 0,64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%crop 128x128+0+0 | ||
|
||
6,304 => 0,0 | ||
794,304 => 128,128 | ||
400,583 => 0,128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use Getopt::Long; | ||
|
||
my $mapfile = "map"; | ||
my $outputfile = "out.png"; | ||
GetOptions( | ||
"map=s" => \$mapfile, | ||
"output=s" => \$outputfile, | ||
) or exit 2; | ||
|
||
my @u; | ||
my @v; | ||
my @x; | ||
my @y; | ||
my %args; | ||
open MAP, "<", $mapfile | ||
or die "$mapfile: $!\n"; | ||
while (<MAP>) | ||
{ | ||
chomp; | ||
if (/^\s*(\d+)\s*,\s*(\d+)\s*=>\s*(\d+)\s*,\s*(\d+)\s*$/) | ||
{ | ||
my ($u, $v, $x, $y) = ($1, $2, $3, $4); | ||
push @u, $u; | ||
push @v, $v; | ||
push @x, $x; | ||
push @y, $y; | ||
} | ||
elsif (/^\s*%(\S+)\s+(.*)$/) | ||
{ | ||
$args{$1} = $2; | ||
} | ||
elsif (!/^\s*$/) { | ||
die "$mapfile: invalid format\n"; | ||
} | ||
} | ||
close MAP | ||
or die "$mapfile: $!\n"; | ||
|
||
if ($v[0] == $v[1]) { | ||
push @u, (shift @u); | ||
push @v, (shift @v); | ||
push @x, (shift @x); | ||
push @y, (shift @y); | ||
} | ||
|
||
my $a = (($x[0]-$x[1])*($v[0]-$v[2])-($x[0]-$x[2])*($v[0]-$v[1])) | ||
/(($u[0]-$u[1])*($v[0]-$v[2])-($u[0]-$u[2])*($v[0]-$v[1])); | ||
my $b = (($x[0]-$x[1])-$a*($u[0]-$u[1]))/($v[0]-$v[1]); | ||
my $c = $x[0] - $a*$u[0] - $b*$v[0]; | ||
my $d = (($y[0]-$y[1])*($v[0]-$v[2])-($y[0]-$y[2])*($v[0]-$v[1])) | ||
/(($u[0]-$u[1])*($v[0]-$v[2])-($u[0]-$u[2])*($v[0]-$v[1])); | ||
my $e = (($y[0]-$y[1])-$d*($u[0]-$u[1]))/($v[0]-$v[1]); | ||
my $f = $y[0] - $d*$u[0] - $e*$v[0]; | ||
my $sx = $a; | ||
my $ry = $b; | ||
my $tx = $c; | ||
my $rx = $d; | ||
my $sy = $e; | ||
my $ty = $f; | ||
for (my $i = 0; $i < 3; $i++) { | ||
my $x = $u[$i]*$sx + $v[$i]*$ry + $tx; | ||
my $y = $u[$i]*$rx + $v[$i]*$sy + $ty; | ||
print "$u[$i],$v[$i] => $x,$y\n"; | ||
} | ||
foreach my $file (@ARGV) | ||
{ | ||
system "convert", $file, "-matte", "-virtual-pixel", "Transparent", | ||
"-affine", "$sx,$rx,$ry,$sy,$tx,$ty", | ||
"-transform", | ||
"-crop", $args{crop} || "96x96+0+0", | ||
$outputfile; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
|
||
w_blender_exe='c:\Program Files\Blender Foundation\Blender\Blender.exe' | ||
c_blender_exe=$(cygpath -u "$w_blender_exe") | ||
w_1=$(cygpath -a -w "$1") | ||
|
||
echo "$c_blender_exe" -b "$w_1" -o "$2" -f 0 | ||
"$c_blender_exe" -b "$w_1" -o "$2" -f 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my @zones = qw( | ||
house01 1x1 | ||
house02 1x1 | ||
house03 1x1 | ||
house04 1x1 | ||
house05 1x1 | ||
house06 1x1 | ||
house07 1x1 | ||
house08 1x1 | ||
house09 1x1 | ||
house10 1x1 | ||
house11 1x1 | ||
house12 1x1 | ||
firestation 3x3 | ||
police 3x3 | ||
coal 4x4 | ||
com01 3x3 | ||
com02 3x3 | ||
com03 3x3 | ||
com05 3x3 | ||
com06 3x3 | ||
com11 3x3 | ||
res2 3x3 | ||
res3 3x3 | ||
res4 3x3 | ||
); | ||
|
||
unless (-d "raw_renders") { | ||
mkdir "raw_renders"; | ||
} | ||
|
||
for (my $i = 0; $i < @zones; $i += 2) | ||
{ | ||
my $zone = $zones[$i]; | ||
my $zonetype = $zones[$i+1]; | ||
|
||
do_render("raw_renders/$zone.png", $zone); | ||
|
||
do_transform( | ||
"${zone}_16x16.png", | ||
"raw_renders/$zone.png", | ||
"${zonetype}_16x16.map" | ||
); | ||
do_transform( | ||
"${zone}_32x32.png", | ||
"raw_renders/$zone.png", | ||
"${zonetype}_32x32.map" | ||
); | ||
} | ||
|
||
sub do_transform | ||
{ | ||
my ($outfile, $infile, $mapfile) = @_; | ||
|
||
return if not newer_than($infile, $outfile); | ||
print "$outfile\n"; | ||
system "scripts/bend.pl","--map=scripts/$mapfile", | ||
"--output=$outfile", $infile; | ||
exit 1 if $? != 0; | ||
} | ||
|
||
sub do_render | ||
{ | ||
my ($outfile, $infile) = @_; | ||
|
||
# check if any of the input files are newer than the output | ||
# file | ||
my $any_newer; | ||
foreach my $f (all_files_in($infile)) { | ||
$any_newer ||= newer_than($f, $outfile); | ||
} | ||
return if not $any_newer; | ||
|
||
print "$outfile\n"; | ||
system "scripts/render.sh", "$infile/$infile.blend", "raw"; | ||
exit 1 if $? != 0; | ||
rename "raw0000.png", $outfile | ||
or die "$outfile: $!\n"; | ||
} | ||
|
||
sub all_files_in | ||
{ | ||
my ($path) = @_; | ||
|
||
my @rv; | ||
opendir my $dh, $path | ||
or die "$path: $!\n"; | ||
foreach my $f (readdir $dh) { | ||
next if $f =~ /^\./; | ||
if (-d "$path/$f") { | ||
push @rv, all_files_in("$path/$f"); | ||
} | ||
else { | ||
push @rv, "$path/$f"; | ||
} | ||
} | ||
closedir $dh | ||
or die "$path: $!\n"; | ||
|
||
return @rv; | ||
} | ||
|
||
sub newer_than | ||
{ | ||
my ($afile, $ref_file) = @_; | ||
|
||
use File::stat; | ||
my $a = stat($afile); | ||
my $b = stat($ref_file); | ||
|
||
if (!$a or !$b) { return 1; } | ||
return $a->mtime > $b->mtime; | ||
} |