]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/polycount.pl
find the original shaderlist properly
[xonotic/xonotic.git] / misc / tools / polycount.pl
1 #!/usr/bin/perl
2
3 for(@ARGV)
4 {
5         my $data = do {
6                 open my $fh, "<", $_;
7                 undef local $/;
8                 <$fh>;
9         };
10
11         my $vertex = undef;
12         my $poly = undef;
13         my $type = undef;
14
15         if("IDP3" eq substr $data, 0, 4)
16         {
17                 # MD3 model
18                 my $num_meshes = unpack "V", substr $data, 4+4+64+4+4+4, 4;
19                 my $ofs_meshes = unpack "V", substr $data, 4+4+64+4+4+4+4+4+4+4, 4;
20                 $vertex = $poly = 0;
21                 for(1..$num_meshes)
22                 {
23                         $vertex     += unpack "V", substr $data, $ofs_meshes+4+64+4+4+4, 4;
24                         $poly       += unpack "V", substr $data, $ofs_meshes+4+64+4+4+4+4, 4;
25                         $ofs_meshes += unpack "V", substr $data, $ofs_meshes+4+64+4+4+4+4+4+4+4+4+4, 4;
26                 }
27                 $type = "md3";
28         }
29         elsif("ZYMOTICMODEL" eq substr $data, 0, 12)
30         {
31                 # ZYM model
32                 $vertex = unpack "N", substr $data, 12+4+4+4*3+4*3+4, 4;
33                 $poly   = unpack "N", substr $data, 12+4+4+4*3+4*3+4+4, 4;
34                 $type = "zym";
35         }
36
37         if(defined $type)
38         {
39                 printf "%8d %8d %-3s %s\n", $vertex, $poly, $type, $_;
40         }
41         else
42         {
43                 printf "%8s %8s %-3s %s\n", "-", "-", "-", $_;
44         }
45 }