r5477 - trunk/misc

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Jan 9 15:14:28 EST 2009


Author: div0
Date: 2009-01-09 15:14:28 -0500 (Fri, 09 Jan 2009)
New Revision: 5477

Added:
   trunk/misc/polycount.pl
Log:
new toy: polycount.pl


Added: trunk/misc/polycount.pl
===================================================================
--- trunk/misc/polycount.pl	                        (rev 0)
+++ trunk/misc/polycount.pl	2009-01-09 20:14:28 UTC (rev 5477)
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+for(@ARGV)
+{
+	my $data = do {
+		open my $fh, "<", $_;
+		undef local $/;
+		<$fh>;
+	};
+
+	my $vertex = undef;
+	my $poly = undef;
+	my $type = undef;
+
+	if("IDP3" eq substr $data, 0, 4)
+	{
+		# MD3 model
+		my $num_meshes = unpack "V", substr $data, 4+4+64+4+4+4, 4;
+		my $ofs_meshes = unpack "V", substr $data, 4+4+64+4+4+4+4+4+4+4, 4;
+		$vertex = $poly = 0;
+		for(1..$num_meshes)
+		{
+			$vertex     += unpack "V", substr $data, $ofs_meshes+4+64+4+4+4, 4;
+			$poly       += unpack "V", substr $data, $ofs_meshes+4+64+4+4+4+4, 4;
+			$ofs_meshes += unpack "V", substr $data, $ofs_meshes+4+64+4+4+4+4+4+4+4+4+4, 4;
+		}
+		$type = "md3";
+	}
+	elsif("ZYMOTICMODEL" eq substr $data, 0, 12)
+	{
+		# ZYM model
+		$vertex = unpack "N", substr $data, 12+4+4+4*3+4*3+4, 4;
+		$poly   = unpack "N", substr $data, 12+4+4+4*3+4*3+4+4, 4;
+		$type = "zym";
+	}
+
+	if(defined $type)
+	{
+		printf "%8d %8d %-3s %s\n", $vertex, $poly, $type, $_;
+	}
+	else
+	{
+		printf "%8s %8s %-3s %s\n", "-", "-", "-", $_;
+	}
+}




More information about the nexuiz-commits mailing list