$v) { $x = round(($v[0]/$max)*15)+15; $y = round(($v[1]/$max)*15)+15; $z = round(($v[2]/$max)*15)+15; // echo "Vertex $i => ($x, $y, $z)\n"; $packed .= pack('C', $x). pack('C', $y). pack('C', $z); } // Pack indices w. vertex index $a_last_index = 0; foreach ($indices as $i => $f) { $a_address_inc = $f[0] - $a_last_index; if ($a_address_inc > 3) { die("Face $i index a increment exceeds 2 bits ($a_address_inc)\n"); } $a_last_index = $f[0]; if ($f[1] > 127 || $f[2] > 127) { die("Face $i index exceeds 7 bits ({$f[1]}, {$f[1]}, {$f[2]})\n"); } // echo "Face $i => ({$f[1]}, {$f[1]}, {$f[2]})\n"; // $packed .= pack('v', ($a_address_inc << 14) | ($f[1] << 7) | $f[2]); $packed .= pack('C', $a_address_inc). pack('C', $f[1]). pack('C', $f[2]); } // Write $packedfile = $argv[count($argv)-1]; file_put_contents($packedfile, $packed); echo "Wrote $packedfile: ". count($infiles)." frame(s), ". count($verts)." verts, ". count($indices)." indices, ". strlen($packed)." bytes\n";