
                   WIRE TO REAL TIME GAMES FORMAT
                  ================================
                          RTG Version 1.75
                         ==================

                      FILE FORMAT SPECIFICATION
                     ===========================


Latest revision of document: March 27, 1996.

The following is a document describing the Alias|Wavefront Real Time Games
Format (v1.75). Running the RTG converter generates an ASCII text .rtg
file and possibly a .bin file (if textures have been assigned to polygonal
geometry in PowerAnimator). The .rtg file contains polygonal data with possible
hierarchy information and possible texture table data. The .bin file contains a
byte oriented RGBA pixel dump of all textures generated for it's corresponding
.rtg file. NEW to this version is the option to generate, instead of an RTG
binary (.bin) file, image files for the textures generated. The image formats
supported for output are ALIAS pix, SGI rgb, 8bit TIFF and 16bit TIFF. Note
that the RTG .bin file still contains all textures generated for a frame, as
before, but the new option to generate image files will create a file per
texture per frame.

The .rtg file contains various tags including title tags, to denote sections of
data, and descriptor tags, which are used for visual reference and can be
ignored when parsing the file.



THE POLYGONAL DATA FILE (.rtg)
------------------------------

* Header Info:
  ------------

  The polygonal data (hereafter referred to as P-data) file begins with a
  number of header lines (currently there are 3 header lines). These
  header lines contain general information for the file. So far only title,
  version and date information header lines are generated. All header lines
  will begin with tags starting with 'HEADER_'. Here is an example of what
  these lines look like:

HEADER_TITLE    Alias|Wavefront Real Time Games Output
HEADER_VERSION  v1.75
HEADER_DATE     Tue Aug 15 21:58:15 1995


* Counter Info:
  -------------

  After header lines in the P-data file are any counters for the file.
  Currently there is only one counter. This is for the number of objects
  that exist in the file. All counter info lines will begin with tags
  starting with 'NUMBER_OF_'. For example:

NUMBER_OF_OBJECTS 4


* Flags Info:
  -----------

  After the counter info in the P-data file are any flags for the file. These
  are for indicating whether or not a particular item(s) will be found in the
  file. For example the flag info line 'OUTPUT_HIERARCHY  on' indicates that a
  hierarchy tree will be found in the file. This version contains flags for:

  OUTPUT_VERT_NORMS - to indicate if a NORMAL list for vertex normals is
                      included in this file or not.

  OUTPUT_TEX_COORDS - to indicate if a TEXCOORD list for vertex texture
                      coordinates is included in this file or not.

  OUTPUT_POLY_NORMS - to indicate if Normals for each polygon will be output on
                      a polygon data line or not.

  OUTPUT_HIERARCHY - to indicate if a hierarchy tree is included in this file
                     or not.

  SHOW_INDEX_COUNTERS - to indicate if index counters (sort of like line
                        numbers for each list - starting at 0) are included
                        in this file or not.

  Here is an example of a Flags info section:

OUTPUT_VERT_NORMS    off
OUTPUT_POLY_NORMS    on
OUTPUT_TEX_COORDS    on
OUTPUT_HIERARCHY     on
SHOW_INDEX_COUNTERS  off


* Selections Info:
  ----------------

  Following the flags info section is the 'Selections Info' section. It
  contains various modes that had been selected when this file was generated.
  Currently there is only one selection line. It is for TEXTURE_MODE and the
  valid modes for it (that are currently supported) are 'color', 'per_shader',
  or 'per_polygon'. If 'color' mode is indicated then only RGB color assign-
  ments are made to polygons and no textures were generated for this file.
  If 'per_shader' is indicated then a texture for each used shader and assigned
  to polygons, with texture coordinates needed for proper texture mapping. For
  'per_polygon' a correctly pre-distorted texture swatch is generated for each
  polygon, with texture coordinates being pretty much meaningless as these
  textures effectively map directly to the corners of each polygon.


* Hierarchy List:
  ---------------

  A Hierarchy list will only exist in the file if the OUTPUT_HIERARCHY
  flag is 'on'. Otherwise parsing should continue with the OBJECT Data as
  described below.

  The first line of a hierarchy list begins with the tag 'HIERARCHY_LIST'.
  Following that tag and still on the first line are 3 tags ...

  NOTE: (NEW STUFF IN THIS VERSION!!)

  ... the first of these tags is the 'Hier. Xform Output' tag. The two
  possible values for this tag are:  HXP and MAT4x4  ... the HXP is carried
  over from the previous version of RTG where this tag could be 'H', 'HX', or
  'HXP' ... on a hierarchy the converter will always output the transforms
  and pivots at each node (unless the new option MAT4x4 is selected - this
  will be detailed below).

  Following the 'Hier. Xform Output' tag is a count for number of top level
  dag nodes in the hierarchy list and then a descriptor tag 'top_level' that
  can be read and ignored.

  After the first line the hierarchy is output with node lines, and possibly
  transform lines and pivot lines.

  node lines are of the format:

  [level] [node_type] [node_name]

  where level is an integer number indicating hierarchy level. A top dag node
  is at level 0. The node_type is either 'G' or 'P', for Group or Polygonal
  Data. The node_name is a string name to individually identify a node.

  Just below a node line specification is the node transformation data. This
  data is represented in two different ways.

  The first is by component transforms (each of translate, rotate, and scale
  in each of x, y, and z) along with rotate and scale pivots - this is the
  'HXP' method (which is the 'Xforms w/ Pivots' option for 'Hier. Xform
  Output'). See below for an example.

  The second output method is 'MAT4x4' (which is the 'Local/World Matrices'
  option for 'Hier. Xform Output'). This method outputs two 4 by 4 transform
  matrices for the node ... the first being the local transform matrix
  at that node and the second is the 'world' transform matrix (the cumulative
  matrix of the transform at that node along with all the transforms above it)
  for that node. Both matrices are output at each (and every) node. Note
  that these matrices can be applied directly to point data, to apply the
  transformations, by premultiplying the given matrix to vertex position data
  ... i.e. p' = M * p  where p is ( x, y, z, w=1.0 ) and M is one of the
  above matrices (either localTM or worldTM). Basically these matrices are
  your standard graphics textbook transormation matrices. See below for some
  example output of the 'MAT4x4' option.
  

  END MARKER:
  ...........
  In either case the hierarchy list ends with the tag 'END_HIERARCHY_LIST' to
  indicate the end of hierarchy processing.


  'HXP' (Xforms w/ Pivots) option for 'Hier. Xform Output':
  .........................................................

  Below is an example of a hierarchy list output generated with the 'HXP'
  (or 'Xforms w/ Pivots') option for the Hierarchy Output:

HIERARCHY_LIST HXP 2 top_level
0 G node#27
      tran: 0.0000 0.0000 0.0000
      rot:  0.0000 0.0000 0.0000
      scal: 1.0000 1.0000 1.0000
      sPiv: 0.0000 0.0000 0.0000
      rPiv: 0.0000 0.0000 0.0000
    1 G node#26
          tran: 0.0000 0.0000 0.0000
          rot:  0.0000 0.0000 0.0000
          scal: 1.0000 1.0000 1.0000
          sPiv: 0.0000 0.0000 0.0000
          rPiv: 0.0000 0.0000 0.0000
        2 G node#25
              tran: 0.0000 0.0000 0.0000
              rot:  0.0000 0.0000 0.0000
              scal: 1.0000 1.0000 1.0000
              sPiv: 0.0000 0.0000 0.0000
              rPiv: 0.0000 0.0000 0.0000
            3 P x16y16end
                  tran: 0.0000 0.0000 0.0000
                  rot:  0.0000 0.0000 0.0000
                  scal: 1.0000 1.0000 1.0000
                  sPiv: 0.0000 0.0000 0.0000
                  rPiv: 0.0000 0.0000 0.0000
            3 P x24y32box
                  tran: 0.0000 0.0000 0.0000
                  rot:  0.0000 0.0000 0.0000
                  scal: 1.0000 1.0000 1.0000
                  sPiv: 0.0000 0.0000 0.0000
                  rPiv: 0.0000 0.0000 0.0000
0 G node#4
      tran: -5.9248 -0.2723 0.0000
      rot:  0.0000 0.0000 0.0000
      scal: 1.0000 1.0000 1.0000
      sPiv: -5.9248 -0.2723 0.0000
      rPiv: -5.9248 -0.2723 0.0000
    1 P x8y8sphere3
          tran: 9.6807 0.0000 0.0000
          rot:  0.0000 0.0000 0.0000
          scal: 0.6858 0.6858 0.6858
          sPiv: 3.7558 -0.2723 0.0000
          rPiv: 3.7558 -0.2723 0.0000
    1 P x22y18sphere2
          tran: 0.0000 0.0000 0.0000
          rot:  0.0000 0.0000 0.0000
          scal: 1.0000 1.0000 1.0000
          sPiv: -5.9248 -0.2723 0.0000
          rPiv: -5.9248 -0.2723 0.0000
END_HIERARCHY_LIST


  'MAT4x4' (Local/World Matrices) option for 'Hier. Xform Output':
  ................................................................

  Below is an example of a hierarchy list output generated with the 'MAT4x4'
  (or 'Local/World Matrices') option for the Hierarchy Output:

HIERARCHY_LIST MAT4x4 1 top_level
0 G node#4
    localTM:
      0.8445 0.7640 0.7168 -3.0819
      0.5484 0.4961 -1.1038 0.0000
      -1.0070 0.9110 0.0000 -0.9172
      0.0000 0.0000 0.0000 1.0000
    worldTM:
      0.8445 0.7640 0.7168 -3.0819
      0.5484 0.4961 -1.1038 0.0000
      -1.0070 0.9110 0.0000 -0.9172
      0.0000 0.0000 0.0000 1.0000
    1 G node#5
        localTM:
          0.6896 -0.6365 0.0188 0.0000
          0.5321 0.7348 0.2109 0.0000
          -0.2050 -0.2340 0.6109 0.0000
          0.0000 0.0000 0.0000 1.0000
        worldTM:
          0.8420 -0.1439 0.6150 -3.0819
          0.8686 0.2738 -0.5593 0.0000
          -0.2097 1.3105 0.1731 -0.9172
          0.0000 0.0000 0.0000 1.0000
        2 P sphere#3
            localTM:
              7.4667 -1.3735 2.2310 -4.7104
              2.1692 7.0198 -2.9382 0.0000
              -1.4691 3.3841 7.0004 -2.1973
              0.0000 0.0000 0.0000 1.0000
            worldTM:
              5.0714 -0.0852 6.6073 -8.3999
              7.9019 -1.1634 -2.7822 -2.8627
              1.0222 10.0736 -3.1062 -0.3097
              0.0000 0.0000 0.0000 1.0000
        2 P polyset#2
            localTM:
              1.0000 0.0000 0.0000 0.0000
              0.0000 1.0000 0.0000 0.7010
              0.0000 0.0000 1.0000 -1.5023
              0.0000 0.0000 0.0000 1.0000
            worldTM:
              0.8420 -0.1439 0.6150 -4.1069
              0.8686 0.2738 -0.5593 1.0323
              -0.2097 1.3105 0.1731 -0.2586
              0.0000 0.0000 0.0000 1.0000
    1 P sphere#2
        localTM:
          6.7623 0.0000 0.0000 4.1419
          0.0000 6.7623 0.0000 0.0000
          0.0000 0.0000 6.7623 2.7822
          0.0000 0.0000 0.0000 1.0000
        worldTM:
          5.7111 5.1668 4.8474 2.4105
          3.7088 3.3553 -7.4643 -0.7993
          -6.8097 6.1607 0.0000 -5.0883
          0.0000 0.0000 0.0000 1.0000
END_HIERARCHY_LIST



* Object Data:
  ------------

  There will be a number of Object sections, one for each object in the file,
  as indicated by the 'NUMBER_OF_OBJECTS' info line mentioned above.

  An Object section begins with an object start line. This line starts with an
  'OBJECT_START' tag and is followed by the name of the object, and counter
  tags. Each counter tag has a letter prefix (to denote what the counter is
  for) with a number (how many items of that type there are) appended to it.

  The letter 'v' is for vertices, 'n' for vertex normals, 't' for texture
  coordinates, and 'p' for polygons. These counters will be in the order of
  vertex count, normal count, texture count then polygon count regardless of
  whether or not some the counters are omitted. For example:

OBJECT_START sphere v26 n45 t45 p32

  ... indicates that the object 'sphere' contains a VERTEX list of 26 vertex
  positions, a NORMAL list of 45 vertex normal values, a TEXCOORD list of 45
  texture (u,v) coordinate values, and a POLYGON list of 32 polygon data
  entries.

  NOTE: if the OUTPUT_VERT_NORMS flag is off (meaning the output of vertex
        normals has been omitted) then the 'n' counter, n45 in the above
        example, is omitted from the object start line.

        Also if the OUTPUT_TEX_COORDS flag is off (meaning the output of
        texture coordinates has been omitted) then the 't' counter, t45 in
        the above example, is omitted from the object start line.

  VERTEX list:

  Following the object start line is the vertex list. This begins with a line
  containing the 'VERTEX' tag along with a coordinate space tag. This
  second tag is either 'local' or 'world' to indicate whether the position of
  the vertex is output in local (object) space or in world space. A list then
  follows of vertex positions specified in X Y Z order (one vertex position per
  line). If the 'SHOW_INDEX_COUNTERS' flag is on, then each vertex line is
  prefixed with an index number starting at 0 and incrementing by one for each
  vertex line in the list.

  NORMAL list:

  Following the vertex list is the vertex normal list. This begins with a line
  containing the 'NORMAL' tag. A list then follows of vertex normal values
  specified in X Y Z order (one vertex normal per line). If the
  'SHOW_INDEX_COUNTERS' flag is on, then each vertex normal line is prefixed
  with an index number starting at 0 and incrementing by one for each vertex
  normal in the list.

  NOTE: if the OUTPUT_VERT_NORMS flag is off (meaning the output of vertex
        normals has been omitted) then a NORMAL list will not be found after
        the VERTEX list.

  TEXCOORD list:

  Next is the texture coordinate list. This begins with a line containing the
  'TEXCOORD' tag. A list then follows of vertex texture coordinate (u,v)
  values specified in U V order (one texture coordinate pair per line). If the
  'SHOW_INDEX_COUNTERS' flag is on, then each line is prefixed with an index
  number starting at 0 and incrementing by one for each line in the list.

  NOTE: if the OUTPUT_TEX_COORDS flag is off (meaning the output of vertex
        texture coordinates has been omitted) then a TEXCOORD list will not be
        found here.

  POLYGON list:

  The next list within an object section is the polygon list for that object.
  This begins with a line containing only the 'POLYGON' list tag. A list then
  follows of polygon data lines (one line/entry for each polygon in the object)
  containing the following data:

  [index] -- omitted if SHOW_INDEX_COUNTERS is off
  [num_verts]
  v [vert_indices]
  n [norm_indices] -- omitted if OUTPUT_VERT_NORMS is off
  t [texcrd_indices] -- omitted if OUTPUT_TEX_COORDS is off
  N [polygon_normal] -- omitted if OUTPUT_POLY_NORMS is off
  T [texture_index] (or) C [rgb_color]

  ... where:

      index is the polygon i.d. in the list beginning at 0 for the first
            polygon and incrementing for each entry in the list. NOTE: this
            index counter is omitted if the SHOW_INDEX_COUNTERS flag is off.

      num_verts is the number of vertices in the polygon.

      vert_indices is a list of vertex indices that reference into the object's
                   VERTEX list. There should be a number of indices in this
                   list equal to num_verts.

      norm_indices is a list of vertex normal indices that reference into the
                   object's vertex NORMAL list. There should be a number of
                   indices in this list equal to num_verts. NOTE: these indices
                   are omitted from output if the OUTPUT_VERT_NORMS flag is off.

      texcrd_indices is a list of vertex indices that reference into the
                   object's TEXCOORD list. There should be a number of indices
                   in this list equal to num_verts. NOTE: these indices are
                   omitted from output if the OUTPUT_TEX_COORDS flag is off.

      poly_normal is the polygon's normal vector in X, Y and Z. NOTE: this
                   entry is omitted if the OUTPUT_POLY_NORMS flag is off.

      texture_index is an index into a texture table (that can be found at the
                    end of the file provided textures were generated).

      rgb_color is the polygon's color in R, G and B.

  Currently a polygon will only have either the Texture index OR an RGB color
  assignment. The tags 'v', 'n', 't', 'N', 'T', and 'C' exist to identify the
  data that follows them. These are omitted from the output if their corres-
  ponding data is also omitted.

  The object data ends with a line containing the 'OBJECT_END' and the name
  of the object as it appeared on the object start line.


* Texture Table:
  --------------

  **** NEW: note there are some changes to the format from the previous
            version of RTG ... but only under a new option selected. If
            normal option selected the texture table format is the SAME
            as before.

  The texture table starts with a line containing the 'TEXTURE_TABLE' tag.

  The next tag after that is either the name of the associated RTG texture
  .bin file (for RTG bin texture output) OR if image file output is selected
  (Alias pix, SGI rgb, or TIFF) then this tag is just a label to identify the
  texture table as part of the current RTG file.

  After the above label there is an entry count, the number of textures
  in the texture table, followed by the 'entries' descriptor tag.

  For RTG bin texture output the last 3 tags of this first TEXTURE_TABLE line
  are the '(header: ' descriptor tag, the number of bytes in the header of the
  RTG .bin file, and finally the ' bytes)' descriptor tag.

  For image file output the last 3 tags of this first TEXTURE_TABLE line are
  '(', an image format tag, and ')'. This indicates image file output for
  each texture in the table was selected for texture output. the "image format
  tag" found between the brackets identifies the image format type, one of:
  ALIAS_PIX, SGI_RGB, TIFF_8BIT, or TIFF_16BIT.

  Following the first line are the texture entries. Each texture entry line
  is of the format:

  [index]  [pixel_format] [X_res] [Y_res]  [source_shader]  [extra_info]

  ... where:

      index is the texture i.d. in the table, beginning with 0 for the first
            texture in the table. This appears in the file only if the index
            counters option is set ON.

FOR RTG BIN OUTPUT:
      pixel_format indicates what how the pixel data is stored in the .bin
                   file for this texture. Currently only 'RGBA' is allowed,
                   meaning the texture in the .bin file is stored 4 bytes per
                   pixel - one each for r, g, b, and a.

FOR IMAGE FILE OUTPUT (NEW!!):
      pixel_format will identify the output file image type for that texture,
                   which, currently, is one of: PIX, RGB, or TIFF.

                   NOTE: the pixel_format field, right now, is not of much
                         use but has been left in for historical purposes
                         and backward compatibility.

      X_res is the resolution in x for the texture swatch created.

      Y_res is the resolution in y for the texture swatch created.

      source_shader is the name of the shader (within PowerAnimator) that this
                    texture was generated from.

NEW>> extra_info - this can be two different things depending on the Texture
                   Output option selected.

                   If RTG bin files are selected for texture output then this
                   field is an integer number for the number of total bytes
                   that the pixel data for this texture takes up in the .bin
                   file.

                   If an image format (like Alias pix, SGI rgb, or TIFF) is
                   selected for texture output then the 'extra_info' field is
                   a string containing the name of the image file generated
                   for this texture entry.

  The texture table ends with a line containing the 'END_TEXTURE_TABLE' and
  the name of the associated texture file (.bin) as it appeared on the texture
  table start line.

  NOTE: the index counter on each entry is omitted if the SHOW_INDEX_COUNTERS
        flag is off.

  Here is an example of the TEXTURE_TABLE format:

TEXTURE_TABLE wackyB1.bin 3 entries (header: 82 bytes)
0  RGBA 32 32  Shader#2  4096
1  RGBA 32 32  Shader  4096
2  RGBA 32 32  Shader#4  4096
END_TEXTURE_TABLE wackyB1.bin


  Here is an example of the TEXTURE_TABLE format utilizing the encoded texture
  resolutions option on shader names:

TEXTURE_TABLE wackyB1.bin 3 entries (header: 82 bytes)
0  RGBA 33 17  x33y17trees  2244
1  RGBA 32 32  x32y32ng  4096
2  RGBA 16 48  x16y48marble  3072
END_TEXTURE_TABLE wackyB1.bin

  For more info on encoded texture resolutions see the README file.


  Here are some examples of the TEXTURE_TABLE format with image file output
  selected for Texture Output:

TEXTURE_TABLE pix_example1 entries ( ALIAS_PIX )
0  PIX 32 32  Shader#2  pix_example1_T1.pix
END_TEXTURE_TABLE pix_example1

  and ...

TEXTURE_TABLE sgi_example1 1 entries ( SGI_RGB )
0  RGB 32 32  Shader#2  sgi_example1_T1.rgb
END_TEXTURE_TABLE sgi_example1 



THE RTG BINARY TEXTURE DATA FILE (.bin)
---------------------------------------

* the Header:
  -----------

  The header of the texture file contains a text title, a version tag, and
  time and date creation information. This header string is NOT null terminat-
  ed. Use the header byte count found in the texture table start line to
  determine how many bytes to read to clear the header. the version tag has
  a 'ver' descriptor tag just before it and the time and date info has a 'date'
  descriptor tag just before it.

  The header should be parsed to get the version tag and the date in order to
  verify the texture file against the P-data file.

* the Data:
  ---------

  After the header any textures generated for the corresponding polygonal data
  file is dumped pixel by pixel into this file. Each pixel is seperated into
  4 bytes one for each of R, G, B, and A and written out to this file in that
  order. Values for each of RGB and A range from 0 to 255. Pixel values are
  output starting from the bottom-left (texture coord 0,0) and are output
  moving left to right and bottom to top.


[END]
