Why are triangle meshes in ASCII format?

### 9.2.7 Why are triangle meshes in ASCII format?

"Why are triangle meshes in ASCII format? They are huge! A binary format would be a lot smaller. If POV-Ray can read binary images, why couldn't it read binary mesh data?"

It's not as simple as you may think.

You can't compare binary mesh data with image files. Yes, images are binary data, but there is one big difference: Image files use integer numbers (usually bytes, in some cases 16-bit integers), which can be easily read in any system.

However, meshes use floating point numbers.

It might come as a bit of surprise that it's far from easy to represent them in binary format so that they can be read in every possible system.

It's very important to keep in mind that POV-Ray is intended to be a very portable program, which should be compilable in virtually any system with a decent C compiler. This is not just mumbo-jumbo; POV-Ray IS used in a wide variety of operating systems and computer architectures, including Windows, MacOS, Linux, (Sparc) Solaris, Digital Unix and so on.

The internal representation of floating point numbers may differ in number of bits and bits reserved for each part of the number inside the data type in different systems. There's also the infamous big-endian/low-endian problem (that is, although the floating point numbers were identical in two different systems, they may be written in different byte-order when writing to a file).

If you try to make carelessly a patch which reads and writes floating point numbers in binary format, you'll probably quickly find that your patch only works in a certain architecture only (eg. PC) and not others.

In order to store floating point numbers so that they can be read in any system, you have to store them in an universal format. ASCII is as good as any other.

However, you are not completely out of luck when dealing with compressing mesh data. This has been done before. For example check:

»http://www.geocities.com/ccolefax/pcm.html

POV-Ray 3.5 supports a new type of mesh (called mesh2) which stores the mesh data in a more compact format (similar to the one used in the PCM format described in the abovementioned link, but with a bit more 'syntax' around it).