======================================================================= The following information is courtesy of Ken Pimental of Sense8 Corporation, maker of the World Tool Kit, one of the standard development environments for virtual reality applications. The NFF standard is can accomodate file formats that are indigenous to various platforms with a minimum of effort. Sense8 has a file conversion program to bring DXF files into NFF format. They are putting this specification into the public domain. =========================================================================== Neutral ASCII File Format Overview The Sense8 neutral ASCII file format is a generic representation for polygonal geometry. The Sense8 WorldTool system can at present read geometry in any of the following file formats: 1. AutoCAD .DXF (through Release 11) 2. Sculpt-3d 3. Caligari 4. Videoscape In order to import other geometry into WorldToolKit, users may write translators to transform their proprietary format into the neutral ASCII file format, which can then be read directly. Thus, the NFF format serves as in interface between modellers which cannot write geometry in any of the forms accepted by WorldToolKit. In the NFF file format, objects are represented as sets of polygons, and polygons are ordered collections of vertices. Polygons have colors and can optionally have other attributes specified. Objects can optionally be named. The file must begin with a line containing the string "nff". (This is used to WTK to determine the type of file.) There follows an optional viewpoint specification associated with the file, and a set of one or more object specifications. All lines must be terminated by a linefeed character, but the PC end-of-line convention CR-LF is also supported. (Note: the CR-LF will be read in, but it won't be written out. Only LFs are written out to an NFF file). The optional viewpoint is specified as two lines, of the form: viewpos x y z viewdir x y z specifying the viewpoint's location and view direction, respectively. By default, an NFF file containing more than one object will load as a single object, which contains all of the file's objects. To tell WorldToolKit to load each NFF object as a distinct WorldToolKit object, put the word "distinct" after the viewpoint information and before any object specifications. See the object_new function for an explanation of how to load multiple objects from a single NFF file. Each object specification start with a line of text giving the object's symbolic name. The next line contains the number of vertices in the object. Vertex x,y,z coordinates, as real numbers, follow one per line. The next line contains the number of polygons in the object. Polygon specification lines follow, one for each polygon. The Vertex coordinate lines should contain 3 real numbers (as could be read in C with a "%f %f %f" format string). One or more spaces or other whitespace must seperate the numbers. Each polygon specification line is of the form <# of vertices> [both] [ []] [id=n] [] The line starts with an integer giving the number of vertices in the polygon. The number of indices follow, each indexing a vertex coordinate. (Zero indicates the first vertex). After the vertex indices is a color designator given in hexadecimal as a number in the range 0x0 to 0xfff. The high order 4 bits represents the red intensity, the middle 4 bits the green, and the low order 4 bits the blue. The optional string "both" indicates that both sides of the polygon are to be visible. The default is only the front face, by the right hand rule. Optionally, a texture name and attributes can be specified for the polygon. (When texturing is on, color is ignored for the textured polys since the surface properties come from the texture.) Texture names give the file containing the bitmap to be used as a texture, and specify whether the texture is to be shaded or transparent. Shaded textures have their brightness affected by the lights present in the model. Transparent textures are rendered so that all black pixels in the source bitmap are transparent when the texture is applied to a polygon. Texture names begin with the character "_". The character following the "_" indicates the type of texture, according to the following: _v_ plain Vanilla texture (no shading) _s_ Shaded texture _t_ transparent texture For example, a texture named "_v_rug" causes a texture from a file named "rug" to be used. A texture named "_s_rug" would apply the same texture, but shaded based on lighting. At present, these three options are mutually exclusive. You may also specify texture attributes immediately after the texture name. These take the format: [rot ] [scale ] [trans ] and specify texture rotation, scaling and translation, respectively. Any or none of these attributes may appear, but they must be placed after the texture name. Regardless of the order of the attributes, at the time the polygon is loaded, they will always be applied in the following order: rotation, scaling, translation. Since the NFF file's description of these texture attributes does not uniquely specify every possible transformation, if you require that files saved by WTK retain their exact transformation when loaded back in, apply your attributes in the same order (rotation, scaling, translation) before saving. Using the optional polygon ID token "id=n", you can assign an integer value "n" to any polygon in your NFF file (example: id=567). Then, from within your WorldToolKit application, you can use the WTpoly_getid function to retreive the ID number for the polygon in question. You can use this feature to "link" polygons in your NFF file with polygons in your application. This is extremely useful for texture animations or other special tricks. Finally, a portal name can be specified for a polygon. Portal names begin with a "-" and contain the name of the Universe to be loaded when the portal is crossed. This is a sample polygon specification line, illustrating all possible options: 5 0 1 2 3 4 0xff0 both _s_rug rot 1.0 scale 0.5 trans 1.0 1.0 id=5 -rugworld This polygon has 5 vertices and is colored yellow, although the yellow will not appear unless you are rendering without textures. Both sides of the polygon are visible, and a shaded rug texture is applied. The rug texture is rotated 1 radian, scaled to half-size, and translated by (1.0,1.0) in (u,v) space. The polygon`s ID number is set to 5 and if the viewpoint crosses this polygon, the universe "rugworld" will be loaded. NFF files may have comments placed on any line. The characters "//" introduce a comment. All characters on the line following the "//" are ignored. The NFF reader is also very flexible with white space; any number of tabs or spaces are allowed before, between and after words in the file. Sample ASCII File The following is an example of a simple ASCII File containing a simple cube structure. Some polygons of the cube are textured and some are not. nff // This is the first word of any NFF file. // The following two lines are optional. viewpos 0.0 0.0 0.0 // Viewpoint is at the origin viewdir 0.0 0.0 1.0 // and looking straight forward. OutObject // Name of the object. 8 // Number of vertices. 3.0 3.0 -3.0 // Vertex info. 3.0 -3.0 -3.0 -3.0 -3.0 -3.0 -3.0 3.0 -3.0 3.0 3.0 3.0 3.0 -3.0 3.0 -3.0 -3.0 3.0 -3.0 3.0 3.0 6 // Number of polygons. 4 0 1 2 3 0xf00 both // 0xf00 is the color, in this case, Red 4 7 6 5 4 0x0f0 both // "both" sides of the cube's faces are visible 4 0 4 5 1 0x00f both // so it is visible even from inside the cube. 4 1 5 6 2 0xff0 both _S_wings // A shaded texture called "wings" 4 2 6 7 3 0xfff both _T_fish rot 1.0 // A rotated, transparent fish texture //a portal to universe "kproom" 4 3 7 4 0 0x000 both _V_kproom -kproom ============================================================================