[37] | 1 | #!/usr/bin/perl |
---|
| 2 | # |
---|
| 3 | # plysets2conf: This program takes a bunch of ply sets, and then |
---|
| 4 | # generates a conf file, which grabs the first listed ply file |
---|
| 5 | # for each set, and the matrix transform. |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | if (($#ARGV == -1) || ($ARGV[0] eq "-h")) { |
---|
| 9 | print STDERR "\n"; |
---|
| 10 | print STDERR "Usage: plysets2conf [-l n] <1.set> <2.set> ... > all.conf\n"; |
---|
| 11 | print STDERR "\n"; |
---|
| 12 | print STDERR "The program will add the first-listed ply file for\n"; |
---|
| 13 | print STDERR "Each set to the conf file, as well as the xf.\n"; |
---|
| 14 | print STDERR "\n"; |
---|
| 15 | print STDERR " -l Use the nth level mesh. E.g. if n is 1,\n"; |
---|
| 16 | print STDERR " use the first mesh listed in each set file.\n"; |
---|
| 17 | print STDERR "\n"; |
---|
| 18 | print STDERR "Ex: plysets2conf -l 4 a.set b.set\n"; |
---|
| 19 | print STDERR " Will generate a .conf file with level 4 of each set.\n"; |
---|
| 20 | print STDERR "\n"; |
---|
| 21 | exit(-1); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | # Set a resolution level. 1 is highest, 4 is lowest |
---|
| 25 | $reslev = 1; |
---|
| 26 | if ($ARGV[0] eq "-l") { |
---|
| 27 | $reslev = int($ARGV[1]); |
---|
| 28 | ($reslev > 0) || die "Error: res level must be greater than 0.\n"; |
---|
| 29 | # Cut first 2 arguments off the list so we ignore the number... :-) |
---|
| 30 | splice(@ARGV, 0,2); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | for ($argc=0; $argc <= $#ARGV; $argc++) { |
---|
| 35 | $set = $ARGV[$argc]; |
---|
| 36 | open(SET, $set); |
---|
| 37 | print STDERR "Using mesh $reslev of set $set...\n"; |
---|
| 38 | # skip first two lines, then skip to the right reslev... |
---|
| 39 | for ($i=1; $i < 2+$reslev; $i++) { |
---|
| 40 | <SET>; |
---|
| 41 | } |
---|
| 42 | $line = <SET>; |
---|
| 43 | @words = split(' ', $line); |
---|
| 44 | # Assertion check |
---|
| 45 | if ($#words != 2) { |
---|
| 46 | print STDERR "Error: $set does not contain a mesh number $reslev.\n"; |
---|
| 47 | exit(-1); |
---|
| 48 | } |
---|
| 49 | # Get directory, too |
---|
| 50 | $plydir = $set; |
---|
| 51 | while (length($plydir) > 0 && substr($plydir, -1, 1) ne "/") { |
---|
| 52 | chop $plydir; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | $plyname = $words[2]; |
---|
| 56 | $xf = $set; |
---|
| 57 | $xf =~ s/.set/.xf/g; |
---|
| 58 | $quat = `matrix2quat < $xf`; |
---|
| 59 | $outline = "bmesh $plydir$plyname $quat"; |
---|
| 60 | print $outline; |
---|
| 61 | close(SET); |
---|
| 62 | } |
---|
| 63 | |
---|