Introduction
WorldToolKit, Sense8’s library for real-time 3D applications, had its own text
format for polygonal geometry, also called the Neutral File Format. It is unrelated
to Eric Haines’s NFF. The current version is 3.0,
which takes its colours from external material tables; version 2.x wrote a
hexadecimal colour on each polygon. WorldToolKit also had a binary form, BFF
(.bff), described as identical to NFF except that 12-bit colours are
not supported; its byte layout is a separate matter from this text format.
Structure
The file begins with a line holding the token nff, followed by an
optional header and any number of objects. // starts a comment that
runs to the end of the line. Any number of spaces or tabs may surround words.
Lines end with a line feed; CR LF is also read.
nff
[version n.nn]
[viewpos x y z]
[viewdir x y z]
object
…
| Line | Meaning |
|---|---|
version | Format version. Optional, but it ensures correct reading if the format changes |
viewpos | Viewpoint position |
viewdir | View direction |
Objects
name [shading=on|off]
[mtable table]
number of vertices
vertex
…
number of polygons
polygon
…
The first line is the object’s symbolic name. shading=on and
shading=off are the form of this option since version 1.7 (earlier
=flat and =none); the 3.0 description does not mention
it. In version 3.0 the next line names the object’s
material table. Several objects may share a table.
Vertices
x y z [norm nx ny nz] [rgb 0xrrggbb] [matid n] [uv u v] [N]
| Part | Since | Meaning |
|---|---|---|
x y z | 1.6 | Coordinates, real numbers, one vertex per line |
norm nx ny nz | 2.0 | Vertex normal; the polygon is then Gouraud-shaded |
N | 2.0 | At the end of the line: WorldToolKit calculates a normal from the surrounding polygons and puts it in place of the N |
rgb 0xrrggbb | 2.09 | Vertex colour, 8 bits each for red, green and blue. Used instead of the polygon colour if every vertex of the polygon has one. Not accepted in version 3.0 and later |
matid n | 3.0 | Vertex colour as an index into the material table |
uv u v | 2.09 | Texture coordinate. If every vertex of a polygon has one, these define the mapping and the polygon’s rot, scale and trans are ignored |
Polygons
count index… colour [both] [texture [attributes]] [tint] [id=n] [-universe]
The line gives the number of vertices in the polygon and then that many vertex indices, counting from 0 within the object. The front face is the one from which the vertices run counterclockwise.
| Part | Meaning |
|---|---|
matid n | Colour in version 3.0: an index into the material table, counting from 0 |
0xrgb | Colour before 3.0: 12 bits, red in the high four, 0x000 black to 0xfff white |
0xrrggbb | Colour from 2.0 to before 3.0: 24 bits. WorldToolKit 2.0 reduced it to 12 bits on reading |
both | Both sides are visible; otherwise only the front is drawn |
tint | Blend the material colour with the texture. May stand anywhere after matid; no effect without a texture |
id=n | Integer identifier by which an application can find the polygon |
-universe | Portal: the name of the universe loaded when the viewpoint crosses the polygon. Ignored in version 3.0 and later |
Textures
A texture word begins with _, a type letter and another
_; the rest names the bitmap file. _v_rug is the file
rug unshaded. Sense8’s examples write the type letter in either
case. A textured polygon takes its surface from the texture, not its colour
(except with tint).
| Prefix | Texture type |
|---|---|
_v_ | Plain: no shading |
_s_ | Shaded by the model’s lights |
_t_ | Transparent: black pixels of the bitmap are not drawn |
_u_ | Shaded and transparent (from 2.09) |
Optional attributes follow the texture name, in any order:
| Attribute | Meaning |
|---|---|
rot a | Rotation in radians |
scale s | Scale |
trans u v | Translation |
mirror | Mirroring |
All act in u,v texture space and are applied as mirroring, rotation, scaling, then translation, whatever their order in the file. A full polygon line from the manual:
5 0 1 2 3 4 0xffff00 both _s_rug rot 1.0 scale 0.5 trans 1.0 1.0 id=5
Material tables (.mat)
mtable mt1 refers to a material table, kept as a text file. If no file
of the given name is found, WorldToolKit adds .mat and looks again in
the current directory.
mat
version 3.00
valid ambient diffuse specular shininess
matdef // id 0
ambient 0.345098 0.325490 0.254902
diffuse 0.376471 0.345098 0.227451
specular 0.597882 0.538353 0.225176
shininess 58.879997
matdef // id 1
ambient 0.650980 0.000000 0.000000
diffuse 0.650980 0.000000 0.000000
specular 0.890000 0.890000 0.890000
shininess 89.599998
valid lists the properties the table defines. Each
matdef starts the next material; materials are numbered from 0 in
file order. A property a material leaves out acts as 0.
| Property | Values | Meaning |
|---|---|---|
ambient | 3 | Colour reflected regardless of light direction |
diffuse | 3 | Colour reflected according to light direction |
ambientdiffuse | 3 | Sets both; not defined together with ambient or diffuse |
specular | 3 | Highlight colour |
emission | 3 | Light the material gives off itself |
shininess | 1 | Sharpness of highlights, 0 to 128 |
opacity | 1 | 0 transparent to 1 opaque |
The spellings ambientdiffuse, emission and
opacity in the file are those Assimp reads; the manual names these
properties but its sample file does not use them.
Versions
| Version | Change |
|---|---|
| 1.6 | First numbered version |
| 1.7 | Object shading options became =on and =off |
| 1.9 | No changes |
| 2.0 | norm added; 24-bit polygon colours; the distinct keyword removed |
| 2.09 | Binary NFF introduced; rgb, uv and _u_ added |
| 2.1 | No changes |
| 3.0 | Material tables and matid replace hexadecimal colours; portals ignored |
Loading a 2.1 or earlier file in a later WorldToolKit builds a material table with
one ambientdiffuse entry for each colour in the object.
Worked example
A square pyramid in version 3.0, using entries 0 and 1 of
mt1.mat:
nff
version 3.0
viewpos 0.0 0.0 -40.0
viewdir 0.0 0.0 1.0
Pyramid
mtable mt1
5
9.0 9.0 -9.0
9.0 -9.0 -9.0
-9.0 -9.0 -9.0
-9.0 9.0 -9.0
0.0 0.0 9.0
5
4 0 1 2 3 matid 0 both
3 0 1 4 matid 1 both
3 1 2 4 matid 1 both
3 2 3 4 matid 1 both
3 3 0 4 matid 1 both
Divergence from the specification
- The manual’s own version 3.0 sample has a second object with no
mtableline, hexadecimal polygon colours andrgbvertex colours, and a portal on one polygon, although its text rules these out or ignores them in 3.0. - Assimp reads a vertex colour written as a bare
0xrrggbband does not recognise thergbkeyword. - Assimp divides each digit of a 12-bit colour by 16, so
0xfis slightly below full intensity. - Assimp does not apply
rot,scale,transormirror, and warns that_t_and_u_are unsupported. - Assimp means to append
.matto a table name, but its test skips the suffix for any name containing a dot or the letter m, a or t, such asmt1. It resolves a name without a directory against the directory of the NFF file.
In the explorer
A dropped .nff file whose first word is nff shows every
line in the byte tree, and every polygon of every object is drawn in 3D with the
colours and vertex normals the file gives. WorldToolKit’s axes are x to the right,
y downwards and z ahead; the picture is turned so that y points up. A very large
model is drawn in parts of three million triangles.
Tables list the objects, vertices, polygons, texture files, material tables and
portals. Texture files, .mat tables and the universes behind portals
are separate files: their names are shown, and a material number is drawn in a
stand-in colour. Files up to 256 MB are read.
Links
Software
- Assimp – 3D import library with a reader for these files (C++)
Reference
- WorldToolKit Reference Manual, Release 9 – appendix F, NFF 3.0; chapter 8, material tables
- Neutral ASCII File Format – Sense8’s 1993 description of version 2.0
- NFFLoader.cpp – Assimp’s reader