The long and short of AutoCAD’s PolyFace Mesh

AutoCAD has a polyface mesh entity (PFACE comand) which is capable of describing a mesh object, something that other CAD systems usually call “polygon mesh”. Basically a collection of triangle and/or quad faces connected to each other by common vertices. Meshes are used in a variety of applications such as terrain modelling, rapid prototyping, reverse engineering, finite element analysis, etc.

There is a little dark secret about AutoCAD’s polyface mesh which needs to be told. The polyface mesh entity cannot have more than 32,767 vertices. Why? Because the polyface mesh data structure is designed that way. Why? I don’t know. However, I do know that there are other CAD systems out there with far less features and much less expensive that do not have this limitation.

Let me explain. This may get a bit technical. In programming an integer can be stored as a char (1 byte), short (2 bytes), int (4 bytes) and long (8 bytes). I have left the “unsigned” types out of this to keep it simple. A short can store a maximum value of 32,767, whereas an int and long can store a maximum value of 2,147,483,647.

The data structure of a polyface mesh is stored as a list of vertices (x,y,z coordinates) followed by a list of faces, wherein each face is defined by the vertices which create that face. For example, a triangular face maybe defined by vertices 304, 306 and 312. Similarly a quad face may be defined by vertices 424, 434, 302 and 211. There is nothing wrong with this method of storing mesh information, In fact, this is the most commonly used method. The problem is that the polyface mesh data structure stores vertex numbers as shorts, not ints or longs, thereby limiting it to have not more than 32,767 vertices.

So what? You may ask. Well, this may have made sense in the good old days when disk space was a luxury. To save 2 or 4 bytes per face they may have said, “What the hell? Who needs large meshes anyways? Lets store vertex numbers as shorts”. Not any more. Nowadays it is not uncommon to have meshes containing a million vertices. A decent dental scan will easily cross that number. Reverse engineering involves millions of points which need to be later meshed. Terrain modeling requires meshes equally large.

I came across this issue years ago when I was writing a STL (Stereolithography) file import plug-in for AutoCAD. At that time I didn’t notice this limitation and wrote the plug-in to recreate the mesh in the STL file as a polyface mesh in AutoCAD. It worked for small meshes but began acting weird for large meshes. My plug-in reported that it had successfully created a polyface mesh but I could not find it anywhere in the drawing (although I could delete it using the ERASE command). Surprisingly, AutoCAD did not report any error or warning. That was AutoCAD 2000. Over the years, this limitation has carried itself through the newer versions of AutoCAD, even the latest version – 2007. I have done my tests on AutoCAD Spago Beta 2 (the future AutoCAD 2008), but I dont think I am allowed to say anything on that yet.

The irony of all this is that over the years Autodesk has revised the DWG file format a number of times, more recently to make it more difficult for people like ODA to reverse engineer it. I only wish they had changed the short to a long and added real value to it. There are supposedly billions of DWG files out there. Too bad not a single one can store a mesh with more than 32,767 vertices.

  • Ralph Grabowski

    The PFace command came out in AutoCAD Release 11 (released Sept, 1990), when the memory constraints of DOS were still a problem.

    I suspect Autodesk used integers for PFace parameters to save memory. Since 1990, Autodesk has not updated PFace.

  • Ralph Grabowski

    The PFace command came out in AutoCAD Release 11 (released Sept, 1990), when the memory constraints of DOS were still a problem. I suspect Autodesk used integers for PFace parameters to save memory. Since 1990, Autodesk has not updated PFace.