home *** CD-ROM | disk | FTP | other *** search
/ Avalon - 3D Objects & Resources / Avalon.iso / frmtspcs / nff_wtk.txt < prev    next >
Text File  |  1995-01-01  |  12KB  |  323 lines

  1.  
  2. WorldToolKit Neutral File Format
  3. Version 2.1
  4.  
  5.  
  6. The NFF Format
  7.  
  8. The Sense8 neutral ASCII file format is a generic representation for
  9. polygonal geometry.  Objects are represented as sets of polygons, and
  10. polygons are ordered collections of vertices.  The format specifies
  11. polygon color and texture application, backface rejection, vertex
  12. normals, vertex colors, object names, polygon ids, and portals.
  13.  
  14.  
  15. Binary NFF (.bff)
  16.  
  17. The NFF format is now supported in binary.  The format layout and
  18. order is identical to the ASCII version, with the exception that
  19. 12-bit colors are not supported.  (All colors are 24-bit.)
  20.  
  21.  
  22. NFF Syntax
  23.  
  24. The following describes version 2.1 of the NFF format.  For changes
  25. from earlier versions, see the section below, "NFF Revision History".
  26.  
  27.  
  28. NFF Header
  29.  
  30. The file must begin with a line containing the string token "nff".
  31. The next line should state the version level of the NFF file.  Next
  32. follows an optional viewpoint specification associated with the file,
  33. and a set of one or more object specifications.  All lines must be
  34. terminated by a linefeed character, but the PC end-of-line convention
  35. CR-LF (carriage return - line feed) is also supported.
  36.  
  37. NFF files may have comments placed on any line.  The characters "//"
  38. introduce a comment.  All characters on the line following the "//"
  39. are ignored.  An NFF reader should also very flexible with white space;
  40. any number of tabs or spaces are allowed before, between and after
  41. words in the file.
  42.  
  43. The second line in the file should be the NFF version number.  The
  44. current version is 2.1.  Although the version number is optional,
  45. providing it ensures that the file will be read correctly even if the
  46. NFF format changes in the future.
  47.  
  48. The optional viewpoint is specified as two lines with the tokens
  49. "viewpos" and "viewdir".  These specify the viewpoint's location and
  50. view direction respectively.
  51.  
  52. Here is the entire header syntax:
  53.  
  54.   nff
  55.   version n.nn
  56.   [viewpos x y z]
  57.   [viewdir x y z]
  58.  
  59. Here is an example of a an NFF header:
  60.  
  61.   nff
  62.   version 2.1
  63.   viewpos 0.000 0.000 0.000
  64.   viewdir 0.000 0.000 1.000
  65.  
  66.  
  67. NFF Objects
  68.  
  69. Each object specification starts with a line of text giving the
  70. object's symbolic name, followed by the description of the geometry
  71. of the object.  The syntax is as follows:
  72.  
  73.   <objectname>
  74.   <number of vertices>
  75.   <first vertex>
  76.   ...
  77.   <last vertex>
  78.   <number of polygons>
  79.   <first polygon>
  80.   ...
  81.   <last polygon>
  82.  
  83. An NFF file can contain any number of objects, each described by its
  84. own name and geometry.  The file structure is:
  85.  
  86.   <NFF header>
  87.   <first NFF object>
  88.   ...
  89.   <last NFF object>
  90.  
  91.  
  92. NFF Vertices
  93.  
  94. After the NFF object name, the next line should be a single integer
  95. value defining the total number of vertices in the object.  Vertex x,
  96. y, z coordinates, as real numbers, follow one per line.  One or more
  97. spaces or other white space must separate the numbers.
  98.  
  99. You can optionally specify a normal vector for each vertex.  The
  100. vertex normal is introduced by the keyword "norm" and is defined as
  101. three real numbers.  Vertex normals are used for Gourand shading.
  102.  
  103. You can optionally specify a vertex color.  If vertex colors are
  104. provided for all the vertices of a polygon, the polygon is to be
  105. rendered with those colors instead of the polygon's color.  The
  106. vertex color is introduced by the keyword "rgb" and takes the form
  107. 0xrrggbb, a hexadecimal number in the range 0x000000 to 0xffffff,
  108. with 8 bits each for red, green, and blue.  For example, red is
  109. 0xff0000, black is 0x000000, white 0xffffff and yellow 0xffff00.
  110.  
  111. A vertex may also specify an explicit texture coordinate (u,v).  If
  112. present for all the vertices of a polygon, these (u,v) coordinates
  113. will precisely define the texture mapping.  The vertex (u,v) values
  114. are introduced by the keyword "uv" and take the form of two
  115. floating-point numbers.
  116.  
  117. Here is the vertex definition syntax:
  118.  
  119.   <x y z> [norm <x y z>] [rgb <0xrrggbb>] [uv <u v>]
  120.  
  121. Here is an example of defining three vertices with vertex normals:
  122.  
  123.   0.00 0.00 0.00  norm 0.707 0.707 0.00
  124.   -100.00 0.00 0.00  norm 1.00 0.00 0.00
  125.   0.00 100.00 0.00  norm -0.707 -0.707 0.00
  126.  
  127. This is an example of a vertex color:
  128.  
  129.   0.00 2.00 0.00 rgb 0x0000ff    // a blue vertex
  130.  
  131. This is an example of a vertex uv value:
  132.  
  133.   1.00 0.00 0.00 uv 0.5 0.5    // a uv coordinate
  134.  
  135.  
  136. NFF Polygons
  137.  
  138. After defining the vertices, the next line contains the number of
  139. polygons in the object.  Polygon specification lines follow, one for
  140. each polygon.
  141.  
  142. Each polygon specification line is of the form:
  143.  
  144. <#vertices><verticies><color>[both] [<texture>[<attributes>]] [id=n] [<portal>]
  145.  
  146. The polygon specification line starts with an integer giving the
  147. number of vertices in the polygon.  Following that is a list of vertex
  148. indices for the current polygon, with zero referring to the first
  149. vertex in the object's vertex list.  For backface rejection purposes
  150. it is important to note that the front face of a polygon is defined
  151. as the side of the polygon for which the vertices go around counter
  152. clockwise in a right-handed coordinate scheme.  Backface rejection is
  153. further discussed below where the "both" flag is described.
  154.  
  155. After the list of vertex indices is a color designator given in
  156. hexadecimal as a number in the range 0x0 to 0xffffff.  The high order
  157. (left-most) 8 bits represent the red intensity, the middle 8 bits the
  158. green, and the low order 8 bits the blue, so that black is 0x000000,
  159. white is 0xffffff, and red is 0xff0000.  If you wish, you may instead
  160. use a 12-bit color specification, in the form 0xrgb.
  161.  
  162. The optional string "both" indicates that both sides of the polygon
  163. are to be visible.  If "both" is not specified, then only front facing
  164. polygons, as defined above, are rendered.
  165.  
  166. Optionally, a texture name and attributes can be specified for the
  167. polygon.  When texturing is on, color is ignored for the textured
  168. polygons since the surface properties come from the texture.  The
  169. texture name specifies the file containing the bitmap to be used as a
  170. texture and also specifies whether the texture is to be plain,
  171. shaded, or transparent.  Shaded textures have their brightness
  172. affected by the lights present in the model.  Transparent textures are
  173. rendered so that all black pixels in the source bitmap are
  174. transparent when the texture is applied to a polygon.  Texture names
  175. begin with the character "_".  The character following the "_"
  176. indicates the type of texture, according to the following:
  177.  
  178.   _v_    plain vanilla texture (no shading)
  179.   _s_    shaded texture
  180.   _t_    transparent texture
  181.   _u_    shaded and transparent texture
  182.  
  183. For example, a texture named "_v_rug" causes a texture from a file
  184. named "rug" to be used.  A texture named "_s_rug" would apply the
  185. same texture, but shaded based on lighting.
  186.  
  187. You can specify texture attributes in two ways: (1) by providing
  188. explicit uv mapping coordinates for the vertices using the "uv"
  189. keyword as described above in the section "NFF Vertices", or (2) by
  190. using the following keywords in the polygon specification:
  191.  
  192.   [rot <value>] [scale <value>] [trans <value> <value>] [mirror]
  193.  
  194. for texture rotation, scaling, translation, and mirroring
  195. respectively.  Rotations are specified in radians, and all operations
  196. are performed in u,v texture coordinate space.  Any or none of these
  197. attributes may appear, but they must be placed after the texture name.
  198.  
  199. Note that if every vertex in the polygon has uv coordinates
  200. specified, then these uv values are used to determine the mapping of
  201. the texture onto the polygon, and any keywords which may be present
  202. (rot, scale, trans) are ignored.
  203.  
  204. Regardless of the order of the attributes, at the time the polygon is
  205. loaded, they are applied in the following order: mirroring, rotation,
  206. scaling, translation.  Since the NFF file's description of these
  207. texture attributes does not uniquely specify every possible
  208. transformation, if you require that files retain their exact
  209. transformation, use the vertex uv values.
  210.  
  211. Using the optional polygon ID token "id=n", you can assign an integer
  212. value "n" to any polygon in your NFF file (example: id=567).
  213.  
  214. Finally, a portal name can be specified for a polygon.  Portal names
  215. begin with a hyphen "- " and contain the name of the universe to be
  216. loaded when the portal is crossed.
  217.  
  218. This is a sample polygon specification, illustrating all possible options:
  219.  
  220. 5 0 1 2 3 4 0xffff00 both _s_rug rot 1.0 scale 0.5 trans 1.0 1.0 id=5 -rugworld
  221.  
  222. This polygon has 5 vertices and is colored yellow, although the
  223. yellow will not appear unless you are rendering without textures.
  224. Both sides of the polygon are visible, and a shaded rug texture is
  225. applied.  The rug texture is rotated 1 radian, scaled to half-size,
  226. and translated by (1.0,1.0) in (u,v) space.  The polygon`s ID number
  227. is set to 5 and if the viewpoint crosses this polygon, the universe
  228. "rugworld" will be loaded.
  229.  
  230.  
  231. WorldToolKit-Specific NFF Extensions
  232.  
  233. Automatic Normal Generation
  234.  
  235. Since adding vertex normals by hand can be difficult, WorldToolKit
  236. supports an automatic normal generation procedure for NFF files.  To
  237. use this feature, you would add an "N" at the end of any vertex line
  238. for which you wanted WorldToolKit to calculate the normals.  When the
  239. file is read into WorldToolKit, the "N" is replaced with an
  240. approximate vertex normal, based on the average of the polygons
  241. surrounding that vertex.  This approximation may lead to an incorrect
  242. normal if polygons are defined haphazardly.  You may also encounter
  243. problems if some vertices are shared by polygons you don't want
  244. Gouraud-shaded.  In this case, you will have to make duplicate
  245. vertices - one with a vertex normal and one without.  After reading in
  246. an object with automatic normals, you may want to write the object
  247. back out so that the next time it is read the normals are already
  248. calculated.
  249.  
  250.  
  251. NFF Version History and Backwards Compatibility
  252.  
  253. 2.1
  254.   no changes
  255. 2.09
  256.   binary nff file format introduced
  257.   added "rgb" keyword for vertex colors
  258.   added "uv" keyword for vertex texture mapping coordinates
  259.   added _u_ designation for textures which are both shaded and transparent
  260. 2.0
  261.   added "norm" keyword to introduce vertex normals
  262.   allow 24-bit color for polygons
  263. 1.9
  264.   no changes
  265. 1.7
  266.   changed object shading to  =on and =off instead of =flat and =none
  267. 1.6
  268.   first numbered version
  269.  
  270.  
  271. Sample NFF File
  272.  
  273. The following is an example of a simple ASCII NFF file containing
  274. simple cube structures.  Some polygons of the first cube are textured
  275. and some are not.
  276.  
  277. nff                  // This is the first word of any NFF file.
  278. version 2.1
  279.  
  280. // The following two lines are optional.
  281. viewpos 0.0 0.0 0.0  // Viewpoint is at the origin
  282. viewdir 0.0 0.0 1.0  // and looking straight forward.
  283.  
  284. SimpleCube           // Name of the object.
  285. 8                    // Number of vertices.
  286. 3.0 3.0 -3.0         // Vertex info.
  287. 3.0 -3.0 -3.0
  288. -3.0 -3.0 -3.0
  289. -3.0 3.0 -3.0
  290. 3.0 3.0 3.0
  291. 3.0 -3.0 3.0
  292. -3.0 -3.0 3.0
  293. -3.0 3.0 3.0
  294. 6                         // Number of polygons.
  295. 4 0 1 2 3 0xff0000 both   // 0xff0000 is the color, in this case, Red
  296. 4 7 6 5 4 0x00ff00 both   // "both" sides of the cube's faces are visible,
  297. 4 0 4 5 1 0x0000ff both   // so it is visible even from inside the cube.
  298. 4 1 5 6 2 0xffff00 both _S_wings         // A shaded texture called "wings"
  299. 4 2 6 7 3 0xffffff both _T_fish rot 1.0  // A rotated, transparent fish texture
  300. 4 3 7 4 0 0x000000 both _V_kproom -kproom
  301.                 // a portal to universe "kproom"
  302.                 // with a texture called "kproom"
  303.  
  304. SecondObject              // Name of the object.
  305. 8                         // Number of vertices.
  306. 9.0 9.0 -9.0 uv 0.0 0.0   // Vertex info, including texture uv.
  307. 9.0 -9.0 -9.0 uv 1.0 0.0
  308. -9.0 -9.0 -9.0 uv 1.0 0.5
  309. -9.0 9.0 -9.0 uv 0.0 0.5
  310. 9.0 9.0 9.0 rgb 0xff0000
  311. 9.0 -9.0 9.0 rgb 0xff8800   // orange
  312. -9.0 -9.0 9.0 rgb 0x0000ff
  313. -9.0 9.0 9.0 rgb 0xff0000
  314. 6                                 // Number of polygons.
  315. 4 0 1 2 3 0xff0000 both _T_fish   // Texture is applied using vertex uv's
  316.                                   // to apply bottom half of texture to polygon
  317. 4 7 6 5 4 0x00ff00 both   // Note that this polygon will use vertex colors
  318.                           // instead of the polygon color!
  319. 4 0 4 5 1 0x0000ff both
  320. 4 1 5 6 2 0xffff00 both
  321. 4 2 6 7 3 0xffffff both
  322. 4 3 7 4 0 0x000000 both
  323.