[Extract from AVRIL.doc] Appendix C - PLG FILE FORMAT I originally designed PLG files for use with REND386; for better or worse, they seem to have become something of a standard. REND386, AVRIL, VR386 and Jon Blossom's Gossamer all use them for object geometry description; there are also translators that turn other formats into PLG, and the NorthCAD-3D program can generate PLG files as output. The PLG in the name stands for "polygon". There will soon be a file format for the interchange of virtual objects and virtual worlds between VR systems; at that point, support for the PLG file format will diminish. Conversion programs will be made available to convert PLG files to the new format. A PLG file basically has three parts: a header line, a list of vertices and a list of facets. The header line has the object name, the number of vertices, and the number of facets; for example: kitchen_table 100 35 which would mean that the object "kitchen_table" has 100 vertices and 35 facets. Anything after the facet count should be ignored, since it may be used for future expansion. Following this line are the vertices, one x,y,z triplet per line (each value is a floating-point number, and they're separated by spaces). For example: 18027 23025 98703 Only the first three values on the line should be used; anything following these values should be ignored. This allows future support for such things as vertex normals. This is followed by the facet information, one line per facet; each of these lines is of the form surfacedesc n v1 v2 v3 ... The surfacedesc is described below. The n is the number of vertices in the facet. The v1, v2, v3 and so on are indices into the array of vertices; the vertices are listed in a counter- clockwise order as seen from the "front" (i.e. visible side) of the facet. Note that the vertices are counted "origin zero", i.e. the first vertex is vertex number 0, not vertex number 1. 66 For example: 0x8002 4 8 27 5 12 would mean a four-sided facet bounded by vertices 8, 27, 5 and 12. This facet has a surface descriptor of 0x8002. Anything after the list of vertex indices should be ignored. The PLG format supports comments. Anything after a # should be ignored by any program that parses PLG files. In addition, lines beginning with a '*' should be ignored. PLG files can have multiple copies of an object at different resolutions. PLG files containing such multiple-resolution versions of objects must have "#MULTI" as their first line. For each object defined in such a file, the object name includes a number specifying the pixel size of the object on the screen. The object names for each representation must be _#### where #### is the smallest pixel width to use this representation for. For example, TABLE_15 would be a valid name. If the smallest rep size is zero, then that represenation will be used no matter how small the object gets. If the smallest rep size is 1 or greater, then the object will vanish if it gets too small. The surface descriptor can either be a decimal integer or a 0x or 0X followed by a hexadecimal integer value. The surface descriptor is a 16-bit value which is interpreted as follows: H R SS CCCC BBBBBBBB The R bit is reserved, and should be set to zero. If the H bit is set, it indicates that this is a "mapped" surface descriptor; the bottom 14 bits are taken to be an index into a surface map. If the H bit is clear, the SS bits are interpreted as follows: 00 -- This facet is "solid shaded"; i.e. it should be drawn in a fixed color, with no special effects. If the CCCC bits are zero, then the BBBBBBBB bits directly specify one of the 256 available colors; if the CCCC bits are non-zero, then they specify one of sixteen hues and the top four bits of BBBBBBBB specify which shade of that hue to use. 67 01 -- This facet is "flat shaded"; i.e. it should be drawn with a constant shading that is determined by the angle at which light is striking it; thus, as the facet moves around, its apparent brightness will change. The CCCC bits specify one of sixteen hues, and the bottom 8 bits BBBBBBBB represent the "brightness" of the color. This brightness value is multiplied by the cosine of the angle between the facet's normal vector and the vector from the facet to the light source; the result is used to specify an offset into the given color's array of shades. Note that if the CCCC value is 0, the color will always be black. 10 -- This facet should be treated as being "metallic"; the CCCC bits (which should be non-zero) specify one of the 16 hues, and the top 5 bits of the BBBBBBBB value are used as an offset into a range of shades to cycle through to give the metallic effect, i.e. a starting offset into the color cycle. 11 -- This facet should be treated as being "transparent"; it is just like surface type 10, except that alternating rows of dots are used instead of solid colors, allowing you to "see through" the facet.