home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / WebSites / Sites / Imagine / TDDD.lzx / TDDD.txt
Text File  |  1999-03-04  |  64KB  |  1,523 lines

  1.               FORM TDDD - Imagine 3D object file format
  2.               -----------------------------------------
  3.  
  4.     Date:     23 Feb 1998
  5.  
  6.     Imagine:  Covered through version 1.3.x for Windows
  7.               (includes previous versions for DOS PC and Amiga)
  8.  
  9.     Imagine object files are written in an "IFF standard" file format.
  10.     "FORM TDDD" refers to the particular type of data that it contains,
  11.     and the format it is presented in.
  12.  
  13.     The full IFF specification provides a wide variety of options for
  14.     formatting data. A "FORM" block is one of the options.  However, most,
  15.     if not all, IFF files contain one or more FORM blocks.  A FORM block
  16.     has a "type identifier" (TDDD, in this case), and data within a FORM
  17.     block is interpreted according to its type.
  18.  
  19.     FORM TDDD was originally used by FORM TDDD is used by Impulse's
  20.     "Turbo Silver 3.0".  At that time, it was used regurlarly, to store
  21.     multiple 3D object heirarchies, as well as camera and environment
  22.     information.  And the data for an animation consisted of a series
  23.     of TDDD files ... which sometimes included references to other files,
  24.     containing single objects or object heirarchies.  Currently, it is
  25.     used only to store only a single object heirarchy. As a result, the
  26.     file format may seem a little "over complicated".
  27.  
  28.     IFF details
  29.     -----------
  30.     
  31.     ** important -- byte ordering and even-size padding **
  32.  
  33.     The IFF specification was originally developed for machines running
  34.     on Motorola CPUs, where "multi-byte" numeric data (e.g. 32-bit integers)
  35.     is stored with the most significant byte appearing first.  When IFF
  36.     files are read and written on "PC compatible" machines, which store
  37.     the bytes in the opposite order, special care must be taken to reverse
  38.     the byte ordering for numberic data.  In this way, the files are kept
  39.     "binary compatible" across machine platforms.
  40.  
  41.     The layout of IFF files is defined with special care taken to ensure
  42.     that IFF file readers can skip over blocks of data that they don't
  43.     understand, or don't care about.  "Blocks" and "chunks" of data all
  44.     have 4-character identifiers followed by a 32-bit size field, followed
  45.     by a block of data of the given size.  When the 4-character identifier
  46.     is not recognized, the data can be skipped by using the number appearing
  47.     in the size field.  There is one important "special case" for size
  48.     fields.  When the size is odd, one extra byte (a zero) is written
  49.     following the data, to pad it to a 2-byte boundary.  That fact must
  50.     be kept in mind when reading and writing data, and when skipping over
  51.     unrecognized data.
  52.  
  53.     A FORM block has the following layout:
  54.  
  55.         +-------------------+----------------------------------------------
  56.     0   | 'F' 'O' 'R' 'M'   |  identifies block as a FORM block
  57.         |                   |  
  58.     4   | 32-bit size (N)   |  specifies size of data following size field
  59.         +-------------------+----------------------------------------------
  60.     8   | 'T' 'D' 'D' 'D'   |  FORM type identifier (TDDD in this case)
  61.         +-------------------+
  62.         |                   |
  63.         |   data chunk      |  data unique to TDDD
  64.         |                   |
  65.         +-------------------+
  66.         |                   |
  67.         |   data chunk      |  data unique to TDDD
  68.         |                   |
  69.         +-------------------+
  70.         |                   |
  71.         |     ... etc.      |
  72.         |                   |
  73.         +-------------------+
  74.         |                   |
  75.         |   data chunk      |
  76.         |                   |  (end of FORM block)
  77.         +-------------------+-----------------------------------------------
  78.     N+8
  79.  
  80.  
  81.     A data "chunk" has the following layout:
  82.  
  83.         +-------------------+----------------------------------------------
  84.     0   | 'S' 'I' 'Z' 'E'   |  chunk type identifier ('SIZE' in this case)
  85.         |                   |  
  86.     4   | 32-bit size (N)   |  specifies size of data following size field
  87.         +-------------------+----------------------------------------------
  88.         |                   |
  89.         |  N bytes of data  |  data for SIZE block
  90.         |                   |
  91.         +-------------------+----------------------------------------------
  92.     N+8 |  (trailing zero)  |  if required for even byte padding
  93.         +-------------------+----------------------------------------------
  94.     N+8 or N+9  (whichever is even)
  95.  
  96.  
  97.     TDDD chunk types
  98.     ----------------
  99.  
  100.     In current TDDD files, there is only one chunk type that is used.
  101.     Its identifier is 'OBJ ', and the data inside it describes a single
  102.     object heirarchy.  In older files, multiple 'OBJ ' chunks could appear,
  103.     as well as other chunk types.
  104.  
  105.     (An "object heirarchy" is a parent object, with nested ("grouped") child
  106.     objects ... where each child can have child objects of its own, and so
  107.     on.)
  108.  
  109.     In TDDD files, the general "IFF" structure has been extended to include
  110.     "chunks within chunks".  The data in an 'OBJ ' chunk, then, is composed
  111.     of a series of sub-chunks, each having the form of an IFF chunk -- with
  112.     a 4-character identifier followed by the data size, followed by the data
  113.     itself, followed by a (zero) pad byte if necessary, to align the data
  114.     with an even byte boundary.  Similarly, then, one of the chunks types
  115.     that appears in an 'OBJ ' chunk, is a 'DESC' chunk -- and it is composed
  116.     itself, of more sub-chunks.  It is the chunks appearing in a DESC chunk,
  117.     contain the "real data" for the objects.
  118.  
  119.     'OBJ ' chunk
  120.     ------------
  121.  
  122.     And 'OBJ ' chunk is composed of only two "sub-chunk" types.  A 'DESC'
  123.     chunk, and a 'TOBJ' chunk.  Multiple chunks of each type can appear,
  124.     and each DESC chunk is matched with a "closing" TOBJ chunk, appearing
  125.     after, somewhere, it in the data.  The main use of the two chunk types
  126.     is to describe the grouping structure of the object heirarchy.  The
  127.     'DESC' chunks contain data describing each object (parent or child).
  128.     Following the 'DESC' chunk for a given object, is data for each of its
  129.     child objects.  And following that is a 'TOBJ' chunk, that marks the
  130.     end of the child object data, and the end of the heirarchy introduced
  131.     by the 'DESC' chunk.  The child object data itself, is a series 'DESC'
  132.     and chunks with matching (closing) 'TOBJ' chunks.  So the data for a
  133.     parent object with two child objects would have the form:
  134.  
  135.     (DESC,(DESC,TOBJ),(DESC,TOBJ),TOBJ)    - parent with 2 child objects
  136.  
  137.     A 'TOBJ' chunk has no data (its size field is zero), and serves only
  138.     to mark the end of the child object data, for a given object.
  139.     A 'DESC' chunk is composed of smaller sub-chunks, that describe the
  140.     object's geometry and other properties.
  141.  
  142.     Summary of above
  143.     ----------------
  144.  
  145.     With the above facts in mind, the layout of a "current" FORM TDDD
  146.     file is as follows:
  147.  
  148.         +---------------------+------------------------------------------
  149.     0   | 'F' 'O' 'R' 'M'     |  identifies block as a FORM block
  150.         |                     |  
  151.     4   | 32-bit size (N+M+28)|  size of data following the size field
  152.         +---------------------+------------------------------------------
  153.     8   | 'T' 'D' 'D' 'D'     |  FORM type identifier
  154.         +---------------------+-----------------------------------
  155.     12  | 'O' 'B' 'J'         |
  156.         |                     |  'OBJ ' chunk header
  157.     16  | 32-bit size (N+M+16)|
  158.         +---------------------+-----------------------------------
  159.     20  |   'D' 'E' 'S' 'C'   |
  160.         |                     |  'DESC' sub-chunk header
  161.     24  |   32-bit size (N)   |
  162.         +---------------------+--------------------------
  163.     28  |                     |
  164.         |     data chunk      |  object data
  165.         |                     |
  166.         +---------------------+
  167.         |                     |
  168.         |     data chunk      |  object data
  169.         |                     |
  170.         +---------------------+
  171.         |                     |
  172.         |     ... etc.        |
  173.         |                     |
  174.         +---------------------+
  175.         |                     |
  176.         |     data chunk      |
  177.         |                     |  (end of DESC chunk)
  178.         +---------------------+--------------------------
  179.     N+28|                     |
  180.         |  child object data  |  matching 'DESC' and 'TOBJ' pairs
  181.         |      (M bytes)      |  (maybe with more nested pairs)
  182.         +---------------------+--------------------------
  183.     N+28|                     |
  184.     +M  |   'T' 'O' 'B' 'J'   |  'TOBJ' sub-chunk (header)
  185.         |                     |
  186.         |      0 (zero)       |  (end of 'TOBJ', 'OBJ ', and FORM block)
  187.         +---------------------+------------------------------------------
  188.     N+M+36
  189.  
  190.  
  191.     DESC data - chunks appearing within DESC chunks
  192.     -----------------------------------------------
  193.  
  194.     This is the "core" of the file format specificaton.
  195.  
  196.     The chunk types appearing in DESC chunks have changed over the years,
  197.     as more features have been added to Imagine.  Imagine continues to
  198.     read the older style data, but writes its output in the newer forms.
  199.     All of the types are described below.  The descriptions are broken
  200.     into sections describing geometry related data, attribute related
  201.     data, special object data, and object "state" data.
  202.  
  203.     Imagine version note:
  204.  
  205.       As of this writing (Feb, '98), Imagine 1.3 is available as part of
  206.       Impulse's "constant upgrade program".  It is the only version that
  207.       reads and writes the newer style chunks that support point edge and
  208.       face counts larger than 32K.  Up until that point, the parts of the
  209.       file format related to the "geometry" of objects, had remained largly
  210.       unchanged. As a result, older versions of the software have at least
  211.       been able to read the geometry correctly.  With the "> 32K" changes,
  212.       that is no longer the case.  If you want to write TDDD files readable
  213.       by "most" current Imagine users, you should stick to the "pre-1.3"
  214.       style chunks. The 1.3 style chunks will be readable in all future
  215.       versions of Imagine, however ... so you can certainly use them.
  216.       But, you should take care to inform users that Imagine 1.3 or higher
  217.       will be required.
  218.  
  219.     Other version notes:
  220.  
  221.       When Imagine was introduced for the Windows platform, the version
  222.       numbering was changed back to 1.0.  The text below, may refer to
  223.       versions 3.0, etc, for DOS PC, and Amiga.  These versions precede
  224.       the Windows version.
  225.  
  226.     There are some conventions that are always used, below:
  227.  
  228.     Floating point data is always converted to a "fixed point"
  229.     representation, and written as a 32-bit integer (byte reversed
  230.     as appropriate).  The conversion algorithm is as follows:
  231.  
  232.     to integer:
  233.     
  234.       if (f < 0)
  235.           n = -(int)(-65536.0 * f + 0.5);
  236.       else
  237.           n = (int)(65536.0 * f + 0.5);
  238.  
  239.     to floating point:
  240.  
  241.       f = n / 65536.0;
  242.  
  243.     The resulting data is independent of any particular floating point
  244.     representation, but has a limitation that it can only properly store
  245.     floating point numbers in the range of -32767.5 < f < 32767.5
  246.  
  247.     The data type 'FRACT' (below), is used to indicate floating point
  248.     numbers which have been converted to the fixed point integer
  249.     representation.
  250.  
  251.     Other data types:
  252.  
  253.     BYTE - unsigned character
  254.     WORD - unsigned 16-bit integer
  255.     DWORD - unsigned 32-bit integer
  256.     SHORT - signed 16-bit integer
  257.     LONG - signed 32-bit integer
  258.  
  259.     typedef LONG    FRACT;   // 4 bytes
  260.  
  261.     typedef struct {
  262.         FRACT X;             // 4 bytes
  263.         FRACT Y;             // 4 bytes
  264.         FRACT Z;             // 4 bytes
  265.     } VECTOR;                // 12 bytes total
  266.  
  267.     typedef struct {
  268.         VECTOR I;            // 12 bytes
  269.         VECTOR J;            // 12 bytes
  270.         VECTOR K;            // 12 bytes
  271.     } MATRIX;                // 36 bytes total
  272.  
  273.     typedef struct {
  274.         VECTOR r;            // 12 bytes - position
  275.         VECTOR a;            // 12 bytes - x axis direction (unit vector)
  276.         VECTOR b;            // 12 bytes - y axis direction (unit vector)
  277.         VECTOR c;            // 12 bytes - z axis direction (unit vector)
  278.         VECTOR s;            // 12 bytes - size (axis lengths)
  279.     } TFORM;                 // 60 bytes total
  280.  
  281.  
  282.     // #pragma pack(1)
  283.     typedef BYTE COLOR[3];   // 3 bytes - 1st byte = R, 2nd = G, 3rd = B
  284.     // #pragma pack()
  285.  
  286.     ** Note ** use of the COLOR type is not recommended, due to potential
  287.     problems with byte packing and data alignment in the compiler.
  288.     It is used only as a convention in this document.  [An older version
  289.     of one C compiler, produced a difficult bug to track down at Impulse.
  290.     It was eventually discovered that copying COLOR values using pointers
  291.     of type (COLOR *) resulted in 4 bytes (not 3) being copied -- yet
  292.     incrementing the pointers caused them to change by 3 bytes].
  293.  
  294.     DESC sub-sub-chunks - geometry related
  295.     --------------------------------------
  296.  
  297.     Some of these fields are optional, and defaults values are used.
  298.  
  299.     A SHAP or SHP2 chunk MUST be present.
  300.  
  301.     Defaults are:   illegal shape; positioned at (0,0,0); axes aligned
  302.     to the world axes; size fields all 32.0;
  303.  
  304.     SHAP - size 4
  305.  
  306.         Note: This has been superceded by 'SHP2', below, as of
  307.             Imagine version 3.0 for the DOS PC and Amiga
  308.             (includes Imagine for Windows version 1.0)
  309.  
  310.         WORD    Shape;          ; number indicating object type
  311.         WORD    Lamp;           ; number indicating lamp type
  312.  
  313.         Lamp numbers are composed of several bit fields:
  314.  
  315.         Bits 0-1:
  316.             0 - not a lamp
  317.             1 - like sunlight
  318.             2 - like a lamp - intensity falls off with distance.
  319.             3 - unused/reserved
  320.  
  321.         Bits 2:
  322.             0 - non-shadow-casting light
  323.             4 - shadow-casting light
  324.  
  325.         Bits 3-4:
  326.             0  - Spherical light source
  327.             8  - Cylindrical light source.
  328.             16 - Conical light source.
  329.             24 - unused/reserved
  330.  
  331.         Shape numbers are:
  332.  
  333.             0 - Sphere          ; "perfect sphere", not point based.
  334.             1 - Stencil         ; - obsolete
  335.             2 - Axis            ; "normal" objects with points/triangles
  336.             3 - Facets          ; illegal - for internal use only
  337.             4 - Surface         ; - obsolete
  338.             5 - Ground          ; "infinite plane", not point based.
  339.  
  340.         Spheres have thier radius set by the X size parameter.
  341.         Stencils and surfaces are plane-parallelograms, with one
  342.         point at the object's position vector; one side lying along
  343.         the object's X axis with a length set by the X size; and
  344.         another side starting from the position vector and going
  345.         "Y size" units in the Y direction and "Z size" units in
  346.         the X direction.  A ground object is an infinte plane
  347.         perpendicular to the world Z axis.  Its Z coordinate sets
  348.         its height, and the X and Y coordinates are only relevant
  349.         to the position of the "hot point" used in selecting the
  350.         object in the editor.  Custom objects have points, edges
  351.         and triangles associated with them.  The size fields are
  352.         relevant only for drawing the object axes in the editor.
  353.         Shape number 3 is used internally for triangles of custom
  354.         objects, and should never appear in a data file.
  355.  
  356.     SHP2 - size 4
  357.  
  358.         Note: Replaces SHAP, above, as of
  359.             Imagine version 3.0 for the Amiga and DOS PC
  360.  
  361.         WORD    Shape;          ; number indicating object type
  362.         WORD    Lamp;           ; number indicating lamp type
  363.  
  364.         Shape numbers are:
  365.  
  366.             0 - Sphere          ; perfect sphere object
  367.             2 - Axis            ; custom objects with points/triangles
  368.             5 - Ground          ; infinite horizontal plane
  369.  
  370.         Spheres have thier radius set by the X size parameter.
  371.         Grounds have thier graphical size set by the X and Y size parameters.
  372.  
  373.         Lamp numbers are composed of several bit fields:
  374.  
  375.         (note the bit definitions have changed - from the
  376.          definition of the bits in the (older) SHAP chunk)
  377.  
  378.         Bits 0-1:  (type bits)
  379.             0 - not a light source
  380.             1 - point light source
  381.             2 - parallel ray light source
  382.             3 - unused/reserved
  383.  
  384.         Bits 2-3:  (shape bits)
  385.             0 - no shape (spherical radiator)
  386.             4 - round light
  387.             8 - rectangular light
  388.             12 - unused/reserved
  389.  
  390.         Bit 4: (lens flare bit)
  391.             0  - normal
  392.             16 - "No lens flare" - for use by Lens Flare global F/X
  393.  
  394.         Bits 5-6: (falloff bits)
  395.             0  - no falloff
  396.             32 - (1/R) falloff
  397.             64 - "controlled" falloff
  398.             96 - (1/R**2) falloff
  399.  
  400.         Bit 7: (shadow bit)
  401.             0   - doesn't cast shadows
  402.             128 - casts shadows
  403.  
  404.         Bit 8: (soft shadows bit)
  405.             0   - normal
  406.             256 - casts "soft shadows" (if bit 7 set)
  407.  
  408.         Bit 15: (bright object bit)
  409.             0     - normal object
  410.             32768 - "bright object" (fully bright)
  411.  
  412.             Note:  variable brightness was added, and if the "bright" bit
  413.             is seen on input, Imagine sets the brightness value to 255,
  414.             and clears this bit ... it is no longer written by Imagine.
  415.  
  416.     POSI - size 12
  417.  
  418.         VECTOR  Position;       ; the object's position.
  419.  
  420.         Legal coordinates are in the range -32768 to 32767 and 65535/65536.
  421.         Currently, the ray-tracer only sees objects in the -1024 to 1024
  422.         range.  Light sources, and the camera may be placed outside that
  423.         range, however.
  424.  
  425.     AXIS - size 36
  426.  
  427.         VECTOR  XAxis;
  428.         VECTOR  YAxis;
  429.         VECTOR  ZAxis;
  430.  
  431.         These are direction vectors for the object coordinate system.
  432.         They must be "orthogonal unit vectors" - i.e. the sum of the
  433.         squares of the vevtor components must equal one (or close to it),
  434.         and the vectors must be perpendicular.
  435.  
  436.     SIZE - size 12
  437.  
  438.         VECTOR  Size;
  439.  
  440.         See SHAP chunk above.  The sizes are used in a variety of ways
  441.         depending on the object shape.  For custom objects, they are
  442.         the lengths of the coordinate axes drawn in the editor.  If the
  443.         object has its "Quickdraw" flag set, the axes lengths are also
  444.         used to set the size of a rectangular solid that is drawn rather
  445.         than drawing all the points and edges.
  446.  
  447.     PNTS - size 2 + 12 * point count
  448.     PNT2 - size 4 + 12 * point count - 32K limit removed
  449.  
  450.         (PNTS chunk)
  451.  
  452.         WORD    PCount;         ; point count
  453.         VECTOR  Points[];       ; points
  454.  
  455.         (PNT2 chunk) - DWORD count
  456.  
  457.         DWORD   PCount;         ; point count
  458.         VECTOR  Points[];       ; points
  459.  
  460.         This chunk has all the points for faceted objects.  They are
  461.         refered to by thier position in the array ... with the first
  462.         point being point number zero.
  463.  
  464.     EDGE - size 2 + 4 * edge count
  465.     EDG2 - size 4 + 8 * edge count - 32K limit removed
  466.  
  467.         (EDGE chunk)
  468.  
  469.         WORD    ECount;         ; edge count
  470.         WORD    Edges[][2];     ; edges
  471.  
  472.         (EDG2 chunk)
  473.  
  474.         DWORD   ECount;         ; edge count
  475.         DWORD   Edges[][2];     ; edges
  476.  
  477.         This chunk contins the edge list for faceted objects.
  478.         The Edges[][2] array is pairs of point numbers that
  479.         are connected by the edges.  Edges are refered to by thier
  480.         position in the Edges[] array ... with the first edge being
  481.         edge number zero.
  482.  
  483.     FACE - size 2 + 6 * face count
  484.     FAC2 - size 4 + 12 * face count - 32K limit removed
  485.  
  486.         (FACE chunk)
  487.  
  488.         WORD    TCount;         ; face count
  489.         WORD    Connects[][3];  ; faces
  490.  
  491.         (FAC2 chunk)
  492.  
  493.         DWORD   TCount;         ; face count
  494.         DWORD   Connects[][3];  ; faces
  495.  
  496.         This chunk contains the triangle (face) list for custom objects.
  497.         The Connects[][3] array is triples of edge numbers that are
  498.         connected by triangles.
  499.  
  500.         Note: See intro to "Attribute related" data -- to remain compatible
  501.         with older versions of Imagine, you should write "per face" data
  502.         for color/reflect/filter values, if you write this chunk.
  503.  
  504.     BBOX - size 24
  505.  
  506.         VECTOR  Mins;        ; minimum X,Y,Z values in local coordinates
  507.         VECTOR  Maxs;        ; maximum X,Y,Z values in local coordinates
  508.  
  509.         This chunk contains bounding box data for the object.
  510.         It is used in Imagine when the stage editor is set to "Quick Draw"
  511.         mode ... where in switching between frames, the point data for
  512.         objects is ignored, and they are treated as simple bounding boxes.
  513.  
  514.     DESC sub-sub-chunks - attribute related
  515.     ---------------------------------------
  516.  
  517.     Most of these fields are optional, and defaults are supplied.
  518.     However, if there is a FACE chunk, there must also be a CLST chunk,
  519.     an RLST chunk and a TLST chunk -- all with matching "count" fields.
  520.     (This restriction is relaxed in newer versions of Imagine, but to
  521.     remain compatible with older versions, Imagine always writes this
  522.     data ... is may not, in the future, though, since with the
  523.     introduction of the new chunk types supporting point edge and face
  524.     chunks larger than 32K, the older software shouldn't have trouble,
  525.     since it won't recognize the geometry chunks anyway).
  526.  
  527.     Defaults are:  Colors set to (255,255,255); reflection and
  528.     transmission coefficients set to zero; illegal shape; positioned at
  529.     (0,0,0); axes aligned to the world axes; size fields all 32.0;
  530.     light source intensity at (255.0,255.0,255.0); no name; no points/edges
  531.     or faces; refractive index 1.00; phong shaded; brightness, hardness
  532.     roughness, and shininess set to zero; not a light source; not brightly
  533.     lit;
  534.  
  535.     NAME - size 18
  536.  
  537.         BYTE    Name[18];       ; a name for the object (null terminated)
  538.  
  539.         Used for camera tracking, specifying path names, etc.
  540.  
  541.         You should always assign a name to the object in the file.
  542.         Imagine displays the name in its "Find" object dialog.
  543.         You don't need to specify a unique name for each object.
  544.         When Imagine loads the objects, it will alter the name,
  545.         if there is already an object with the same name.
  546.  
  547.     COLR - size 4
  548.     REFL - size 4
  549.     TRAN - size 4
  550.     SPC1 - size 4 - superceded by SPC2, below.
  551.  
  552.         BYTE    Pad;            ; pad byte - must be zero
  553.         COLOR   Color;          ; RGB color
  554.  
  555.         These are the main object RGB color, and reflection, transmission
  556.         and specularity coefficients.
  557.  
  558.     SPC2 - size 8
  559.  
  560.         Note: This supercedes by SPC2 as of Imagine version 1.3 for Windows.
  561.  
  562.         BYTE    Pad;            ; pad byte - must be zero
  563.         COLOR   Color;          ; RGB color
  564.         FRACT   Overdrive;      ; specular overdrive setting
  565.  
  566.     INT1 - size 12
  567.  
  568.         VECTOR  Intensity;      ; light source intensity
  569.  
  570.         Light source intensity.  The vector components hold the (separate)
  571.         R, G and B intensities.  The X component is the R intensity,
  572.         Y is G, and Z is B.
  573.  
  574.     CLST - size 2 + 3 * count
  575.     CLS2 - size 4 + 3 * count - 32K limit removed
  576.     RLST - size 2 + 3 * count
  577.     RLS2 - size 4 + 3 * count - 32K limit removed
  578.     TLST - size 2 + 3 * count
  579.     TLS2 - size 4 + 3 * count - 32K limit removed
  580.  
  581.         (CLST,RLST and TLST chunks)
  582.  
  583.         WORD    count;          ; count of colors (faces)
  584.         COLOR   colors[];       ; colors
  585.  
  586.         (CLS2,RLS2 and TLS2 chunks)
  587.  
  588.         DWORD   count;          ; count of colors (faces)
  589.         COLOR   colors[];       ; colors
  590.  
  591.         (note: odd chunk size is possible)
  592.  
  593.         These are the color, reflection and transmission coefficients
  594.         for each face in custom objects. The count should match the
  595.         face count in the FACE chunk. The ordering corresponds to the
  596.         face order.
  597.  
  598.         As always, when the chunk size is odd, it is followed
  599.         by a zero pad byte.
  600.  
  601.     EFLG - size 2 + count
  602.     EFL2 - size 4 + count - 32K limit removed
  603.  
  604.         (EFLG chunk)
  605.  
  606.         WORD   count;           ; count of flag bytes (edges)
  607.         BYTE   flags[];         ; flag bytes
  608.  
  609.         (EFL2 chunk)
  610.  
  611.         LONG   count;           ; count of flag bytes (edges)
  612.         BYTE   flags[];         ; flag bytes
  613.  
  614.         Edge attributes ("per edge" flags).
  615.  
  616.         The flag bits are defined as:
  617.  
  618.         bits 0-5    - reserved, set to zero.
  619.         bit 6       - "quick" edge - used with "quick edges" drawing mode
  620.         bit 7       - "sharp" edge - disables Phong shading across the edge
  621.  
  622.         Imagine writes this chunk only when at least one edge has at least
  623.         one flag bit set (when it would not be a block of zeros).
  624.  
  625.         As always, when the chunk size is odd, it is followed
  626.         by a zero pad byte.
  627.  
  628.     PRP1 - size 8 - superceded
  629.     PRP2 - size 8 - supercedes PRP1
  630.  
  631.         BYTE   IProps[8];       ; more object properties
  632.  
  633.         This chunk contains object properties that programs other
  634.         than Imagine might support.
  635.  
  636.         (for PRP1 chunk)
  637.         IProps[0] - IPRP_DITHER   ; blending factor (0-255) (obsolete)
  638.         IProps[1] - IPRP_HARD     ; hardness factor (0-255)
  639.         IProps[2] - IPRP_ROUGH    ; roughness factor (0-255)
  640.         IProps[3] - IPRP_SHINY    ; shinyness factor (0-255)
  641.         IProps[4] - IPRP_INDEX    ; index of refraction
  642.         IProps[5] - IPRP_QUICK    ; flag - Quickdraw on/off
  643.         IProps[6] - IPRP_PHONG    ; flag - Phong shading on/off
  644.         IProps[7] - IPRP_GENLOCK  ; flag - Genlock on/off (obsolete)
  645.  
  646.         (for PRP2 chunk)
  647.         IProps[0] - IPRP_BRIGHT   ; brightness factor (0-255)
  648.         IProps[1-7] - same as above.
  649.  
  650.         The hardness factor controls how tight the specular spot
  651.         should be - 0 is a big soft spot, 255 is a tight hot spot
  652.         The roughness factor controls how rough the object should
  653.         appear - 0 is smooth, 255 is max roughness.
  654.         The shiny factor in interaction with the object's filter
  655.         values controls how shiny the object appears.  Setting it
  656.         to anything but zero forces the object to be non-transparent
  657.         since then the filter values are used in the shiny (reflection)
  658.         calculations.  A value of 255 means maximum shininess.
  659.         The brightness factor refers controls how much lighting and light
  660.         sources affect the object's rendered "color".  When the brightness
  661.         is zero, the normal lighting algorithms are used.  When it is 255,
  662.         the lighting calculations are ignored, and the object appears
  663.         "bright" in the rendering, with the colors taken directly from
  664.         the object.  Intermediate values result in a blend of the "shaded"
  665.         and "bright" appearance.
  666.  
  667.     FOGL - size 4
  668.     FOG2 - size 14 - Imagine for Windows 1.2
  669.     FOG3 - size 18 - Imagine for Windows 1.3
  670.  
  671.         These chunks contain data for "fog objects".
  672.  
  673.         (FOGL chunk)
  674.  
  675.         FRACT   Length;         ; fog length attribute
  676.  
  677.         (FOG2 chunk)
  678.  
  679.         FRACT   Length;         ; fog length attribute
  680.         FRACT   Falloff;        ; falloff distance
  681.         FRACT   Hot;            ; fog "hotness" setting
  682.         WORD    Type;           ; fog type (bits)
  683.  
  684.         (FOG3 chunk)
  685.  
  686.         FRACT   Length;         ; fog length attribute
  687.         FRACT   Falloff;        ; falloff distance
  688.         FRACT   Hot;            ; fog "hotness" setting
  689.         FRACT   Overdrive;      ; fog "overdrive" setting
  690.         WORD    Type;           ; fog type (bits)
  691.  
  692.         Fog Type bits:
  693.  
  694.         bits 0-1: falloff type
  695.  
  696.         0 - no falloff
  697.         1 - radial falloff
  698.         2 - axial falloff
  699.         3 - planar falloff
  700.  
  701.         bits 2-3: falloff axis
  702.  
  703.         0 - X axis
  704.         4 - Y axis
  705.         8 - Z axis
  706.  
  707.         bit 7: "hot center" on/off
  708.  
  709.         0   - off
  710.         128 - on
  711.  
  712.     BLB2 - size 10
  713.  
  714.         "Blob" object attributes
  715.  
  716.         FRACT   Strength;       ; blob strength - default is 1.0
  717.         FRACT   Threshold;      ; unused - Imagine writes 0.6 in FRACT form.
  718.         WORD    MeshDensity;    ; mesh density
  719.  
  720.         The MeshDensity setting is ignored for all but the head object of
  721.         a group of blob objects.  The entire group (generally) gets
  722.         converted into a single faceted object, using the MeshDensity
  723.         setting from the head object.
  724.  
  725.     PART - size 6 - obsolete
  726.     PAR2 - size 8 - supercedes PART in Imagine 3.1 for DOS PC and Amiga
  727.  
  728.         (PART chunk)
  729.         WORD    Type;           ; type bits
  730.         FRACT   Size;           ; "particle size" setting
  731.  
  732.         (PAR2 chunk)
  733.         DWORD   Type;           ; type bits
  734.         FRACT   Size;           ; "particle size" setting
  735.  
  736.         Particle attributes.
  737.  
  738.         The exact reason for the two chunk types, is uncertain.
  739.         The new chunk type may have been added as part of a bug fix.
  740.         The Type bits have the same meaning in both cases.
  741.  
  742.         Type bits:
  743.  
  744.         bits 0-3    - particle type
  745.  
  746.         0   - no particles - normal object
  747.         1   - tetrahedrons
  748.         2   - pyramids
  749.         3   - octahedrons
  750.         4   - cubes
  751.         5   - blocks (rectangular solids)
  752.         6   - dodecahedrons
  753.         7   - spheres
  754.         8   - randomly chosen, per face, from the list above
  755.         9   - filename - a PTFN chunk should be present too.
  756.  
  757.         bits 4-7    - centering option
  758.  
  759.         0x00    - inscribed
  760.         0x10    - circumscribed
  761.         0x20    - interpolated
  762.         0x30    - barycentric
  763.  
  764.         bits 8-11   - sizing option
  765.  
  766.         0x000   - small
  767.         0x100   - large
  768.         0x200   - random
  769.         0x300   - specify (use size value)
  770.  
  771.         bits 12-15  - alignment option
  772.  
  773.         0x0000  - align to object
  774.         0x1000  - align to faces
  775.         0x2000  - random
  776.  
  777.     PTFN - variable size - (1 + strlen(particle_filename))
  778.  
  779.         BYTE    CharCount;      ; count of characters in filename
  780.         BYTE[]  FileName;       ; - not null terminated
  781.  
  782.         Particle file name. Specifies the name of a TDDD object file,
  783.         for use with particlization.
  784.  
  785.         The chunk size is one plus the length of the string.
  786.         As always, when the chunk size is odd, it is followed
  787.         by a zero pad byte.
  788.  
  789.     FGRP - size 20 + 2 * count
  790.     FGR2 - size 26 + 2 * count + variable size -- Imagine 3.0 (DOS,Amiga)
  791.     FGR3 - size 28 + 2 * count + variable size -- Imagine 3.1 (DOS,Amiga)
  792.     FGR4 - size 30 + 4 * count + variable size -- Imagine for Windows 1.3
  793.  
  794.         the 'variable size' is (1 + strlen(particle_filename))
  795.  
  796.         These chunks describe data for "face subgroups" ... i.e. named
  797.         lists of faces, by face number.  The change from FGRP to FGRP2
  798.         and higher, came when subgroups could have "particle attributes"
  799.         assigned to them.  The change to FGRP3 corresponts to the change
  800.         from PART to PAR2.  The change to FGRP4 allows for face numbers
  801.         greater than 32K, and for subgroups to have > 32K faces.  The
  802.         variable sized field at the end is for a user specified particle
  803.         file name (a TDDD file).  It consists of a byte count, followed
  804.         by the filename characters, with no null termination.
  805.  
  806.         (FGRP chunk)
  807.  
  808.         WORD    Count;          ; count of faces in subgroup
  809.         BYTE    Name[18];       ; null terminated name string
  810.         WORD    FaceList[];     ; list of face numbers (0 based)
  811.  
  812.         (FGR2 chunk)
  813.  
  814.         WORD    Count;          ; count of faces in subgroup
  815.         BYTE    Name[18];       ; null terminated name string
  816.         WORD    FaceList[];     ; list of face numbers (0 based)
  817.         WORD    PType;          ; particle type bits - see PART/PAR2
  818.         FRACT   PSize;          ; particle size
  819.         BYTE    Count;          ; filename length
  820.         BYTE    FileName[];     ; particle filename - not null terminated
  821.         (note: odd chunk size is possible)
  822.  
  823.         (FGR3 chunk)
  824.  
  825.         WORD    Count;          ; count of faces in subgroup
  826.         BYTE    Name[18];       ; null terminated name string
  827.         WORD    FaceList[];     ; list of face numbers (0 based)
  828.         DWORD   PType;          ; particle type bits - see PAR2
  829.         FRACT   PSize;          ; particle size
  830.         BYTE    Count;          ; filename length
  831.         BYTE    FileName[];     ; particle filename - not null terminated
  832.         (note: odd chunk size is possible)
  833.  
  834.         (FGR4 chunk)
  835.  
  836.         DWORD   Count;          ; count of faces in subgroup (32 bit)
  837.         BYTE    Name[18];       ; null terminated name string
  838.         DWORD   FaceList[];     ; list of face numbers (0 based, 32 bit)
  839.         DWORD   PType;          ; particle type bits - see PAR2
  840.         FRACT   PSize;          ; particle size - see PAR2
  841.         BYTE    Count;          ; filename length
  842.         BYTE    FileName[];     ; particle filename - not null terminated
  843.         (note: odd chunk size is possible)
  844.  
  845.         See the PART/PAR2 and PTFN descriptions for details on the
  846.         particlization data.
  847.  
  848.         As always, when the chunk size is odd, it is followed
  849.         by a zero pad byte.
  850.  
  851.     BBSG - size 18
  852.     SBSG - size 18
  853.  
  854.         BYTE    Subgroup[18]    ; null terminated subgroup name
  855.  
  856.         These chunks list the "big" and "small" bones subgroup names,
  857.         for use with Imagine's "bones" feature.
  858.  
  859.     TXT1 - size 142 + variable size - Imagine 1.0 for DOS PC and Amiga 
  860.     TXT2 - size 160 + variable size - Imagine 1.1 for DOS PC and Amiga
  861.     TXT3 - size 178 + variable size - Imagine 3.0 for DOS PC and Amiga
  862.     TXT4 - size 200 + variable size - Imagine 3.3 for DOS PC and Amiga
  863.  
  864.         the 'variable size' is (1 + strlen(module_filename))
  865.  
  866.         These chunks contain data for algorithmic textures.
  867.  
  868.         (TXT1 chunk)
  869.  
  870.         WORD    Flags;          ; texture flags
  871.         TFORM   TForm;          ; local coordinates of texture axes.
  872.         FRACT   Params[16];     ; texture parameters
  873.         BYTE    PFlags[16];     ; parameter flags (currently unused)
  874.  
  875.         BYTE    Length;         ; length of texture file name
  876.         BYTE    Name[Length];   ; texture file name (not NULL terminated)
  877.         (note: odd chunk size is possible)
  878.  
  879.         (TXT2 chunk)
  880.  
  881.         WORD    Flags;          ; texture flags
  882.         TFORM   TForm;          ; local coordinates of texture axes.
  883.         FRACT   Params[16];     ; texture parameters
  884.         BYTE    PFlags[16];     ; parameter flags (currently unused)
  885.  
  886.         BYTE    Subgrp[18];     ; subgroup name, for "restrict to subgroup"
  887.  
  888.         BYTE    Length;         ; length of texture file name
  889.         BYTE    Name[Length];   ; texture file name (not NULL terminated)
  890.         (note: odd chunk size is possible)
  891.  
  892.         (TXT3 chunk)
  893.  
  894.         WORD    Flags;          ; texture flags
  895.         TFORM   TForm;          ; local coordinates of texture axes.
  896.         FRACT   Params[16];     ; texture parameters
  897.         BYTE    PFlags[16];     ; parameter flags (currently unused)
  898.  
  899.         BYTE    Subgrp[18];     ; subgroup name, for "restrict to subgroup"
  900.         BYTE    Stname[18];     ; "tacking" state name - NULL terminated
  901.  
  902.         BYTE    Length;         ; length of texture file name
  903.         BYTE    Name[Length];   ; texture file name (not NULL terminated)
  904.         (note: odd chunk size is possible)
  905.  
  906.         (TXT4 chunk)
  907.  
  908.         WORD    Flags;          ; texture flags:
  909.         TFORM   TForm;          ; local coordinates of texture axes.
  910.         FRACT   Params[16];     ; texture parameters
  911.         BYTE    PFlags[16];     ; parameter flags (currently unused)
  912.  
  913.         BYTE    Subgrp[18];     ; subgroup name, for "restrict to subgroup"
  914.         BYTE    Stname[18];     ; "tacking" state name - NULL terminated
  915.         BYTE    Label[18];      ; User label - NULL terminated
  916.         FRACT   Mixing;         ; "mixing intensity" (0...1) - default 1.0
  917.  
  918.         BYTE    Length;         ; length of texture file name
  919.         BYTE    Name[Length];   ; texture file name (not NULL terminated)
  920.         (note: odd chunk size is possible)
  921.  
  922.         As always, when the chunk size is odd, it is followed
  923.         by a zero pad byte.
  924.  
  925.         The Flags bit are:
  926.  
  927.         1 (bit 0) - TXTR_CHILDREN - apply texture to child objects in group
  928.         2 (bit 1) - TXTR_LIGHTING - the texture is a "lighting texture"
  929.         4 (bit 2) - TXTR_DISABLE - the texture is disabled
  930.  
  931.         (ligting textures are used with objects that are light sources)
  932.  
  933.         The 'Params' block stores up to 16 "floating point" values, that
  934.         act as parameters for the texture.  Unused values should contain
  935.         zeros.
  936.         
  937.         The 'PFlags' bits, one for each parameter, are used by Imagine
  938.         for performing "special services" with texture parameters.
  939.  
  940.         1 (bit 0)   - TXTF_RED - indicates Red RGB value in 0.0-255.0 range
  941.         2 (bit 1)   - TXTF_GRN - indicates Green value in 0.0-255.0 range
  942.         4 (bit 2)   - TXTF_BLU - indicates Blue value in 0.0-255.0 range
  943.         8 (bit 3)   - TXTF_SCL - indicates a parameter that scales in
  944.                                  proportion to the object, when the object
  945.                                  is resized (in all 3 axes).
  946.         16 (bit 4)  - TXTF_UNUSED - for DOS/Amiga textures only (interface)
  947.         32 (bit 5)  - TXTF_LUNUSED - for DOS/Amiga textures only (interface)
  948.  
  949.         These flags are specified by the texture modules themselves, when
  950.         a texture is first placed on an object, and after that they never
  951.         change.  Originally, with the exception of the 'TXTF_SCL' flag,
  952.         the flags were used to control the dialog that Imagine set up for
  953.         the texture modules.  As of the Windows version, the texture modules
  954.         are largely responsible for thier own interface.  However, as of
  955.         the Imagine 1.2 for Windows, the TXTF_RED,GRN,BLU flags are also
  956.         used in rendering, to identify RGB values and apply an "inverse"
  957.         gamma correction to them, prior to rendering.  The texture modules
  958.         manage and store RGB values as set in the interface, in these
  959.         locations, and then Imagine may alter them prior to calling the
  960.         texture during rendering, depending on the users preferences.
  961.         (Note: for texture designers - failure to set the RGB flags for,
  962.         RGB color parameters will usually result in rendered colors
  963.         appearing hue shifted with respect to what the user sets up in
  964.         the interface - primary colors are an exception)
  965.  
  966.     BRS1 - 64 + variable size - Imagine version 1.0 for DOS PC and Amiga
  967.     BRS2 - 68 + variable size - Imagine version 1.1 for DOS PC and Amiga
  968.     BRS3 - 86 + variable size - Imagine version ??
  969.     BRS4 - 104 + variable size - Imagine 3.0 for DOS PC and Amiga
  970.     BRS5 - 134 + variable size - Imagine 3.3 for DOS PC and Amiga
  971.  
  972.         the 'variable size' is (1 + strlen(brush_filename))
  973.  
  974.         These chunks contain data for brush maps.
  975.  
  976.         (BRS1 chunk)
  977.  
  978.         WORD    Flags;          ; brush type:
  979.         WORD    WFlags;         ; brush wrapping flags:
  980.         TFORM   TForm;          ; local coordinates of brush axes.
  981.  
  982.         BYTE    Length;         ; length of brush file name
  983.         BYTE    FileName[];     ; brush file name (not null terminated)
  984.         (note: odd chunk size is possible)
  985.  
  986.         (BRS2 chunk)
  987.  
  988.         WORD    Type;           ; brush type
  989.         WORD    WFlags;         ; brush wrapping flags
  990.         TFORM   TForm;          ; local coordinates of brush axes.
  991.  
  992.         WORD    FullScale;      ; full scale value
  993.         WORD    MaxSeq;         ; highest number for sequenced brushes
  994.  
  995.         BYTE    Length;         ; length of brush file name
  996.         BYTE    FileName[];     ; brush file name (not null terminated)
  997.         (note: odd chunk size is possible)
  998.  
  999.         (BRS3 chunk)
  1000.  
  1001.         WORD    Type;           ; brush type:
  1002.         WORD    WFlags;         ; brush wrapping flags:
  1003.         TFORM   TForm;          ; local coordinates of brush axes.
  1004.  
  1005.         WORD    FullScale;      ; full scale value
  1006.         WORD    MaxSeq;         ; highest number for sequenced brushes
  1007.         BYTE    Subgrp[18];     ; subgroup name, for "restrict to subgroup"
  1008.  
  1009.         BYTE    Length;         ; length of brush file name
  1010.         BYTE    FileName[];     ; brush file name (not null terminated)
  1011.         (note: odd chunk size is possible)
  1012.  
  1013.         (BRS4 chunk)
  1014.  
  1015.         WORD    Type;           ; brush type:
  1016.         WORD    WFlags;         ; brush wrapping flags:
  1017.         TFORM   TForm;          ; local coordinates of brush axes.
  1018.  
  1019.         WORD    FullScale;      ; full scale value
  1020.         WORD    MaxSeq;         ; highest number for sequenced brushes
  1021.         BYTE    Subgrp[18];     ; subgroup name, for "restrict to subgroup"
  1022.         BYTE    Stname[18];     ; "tacking" state name - NULL terminated
  1023.  
  1024.         BYTE    Length;         ; length of brush file name
  1025.         BYTE    FileName[];     ; brush file name (not null terminated)
  1026.         (note: odd chunk size is possible)
  1027.  
  1028.         (BRS5 chunk)
  1029.  
  1030.         WORD    Type;           ; brush type:
  1031.         WORD    WFlags;         ; brush wrapping flags:
  1032.         TFORM   TForm;          ; local coordinates of brush axes.
  1033.  
  1034.         WORD    FullScale;      ; full scale value
  1035.         WORD    MaxSeq;         ; highest number for sequenced brushes
  1036.         BYTE    Subgrp[18];     ; subgroup name, for "restrict to subgroup"
  1037.         BYTE    Stname[18];     ; "tacking" state name - NULL terminated
  1038.         BYTE    Label[18];      ; User label - NULL terminated
  1039.         FRACT   Mixing;         ; "mixing intensity" (0...1) - default 1.0
  1040.         FRACT   FogLo;          ; minimum fog length - for fog brushes
  1041.         FRACT   FogHi;          ; maximum fog length - for fog brushes
  1042.  
  1043.         BYTE    Length;         ; length of brush file name
  1044.         BYTE    FileName[];     ; brush file name (not null terminated)
  1045.         (note: odd chunk size is possible)
  1046.  
  1047.         brush type values:
  1048.  
  1049.         0    Color map
  1050.         1    Reflectivity map
  1051.         2    Filter map
  1052.         3    Altitude map
  1053.         4    Reflection (Environment) map
  1054.         5    Specular map
  1055.         6    Hardness map
  1056.         7    Roughness map
  1057.         8    Fog length map
  1058.         9    Shininess map
  1059.         10   Brightness map
  1060.         11   Index of refraction map
  1061.         12   Light (ambient) map
  1062.  
  1063.         brush wrapping flags:
  1064.  
  1065.         1   WRAP_X          - wrap type
  1066.         2   WRAP_Z          - wrap type
  1067.         4   WRAP_CHILDREN   - apply to children
  1068.         8   WRAP_REPEAT     - repeating brush
  1069.         16  WRAP_FLIP       - flip with repeats
  1070.         32  WRAP_INVERT     - use "inverse video"
  1071.         64  WRAP_ZEROCOLOR  - don't apply brush in "color zero" area
  1072.         128 WRAP_DISABLE    - brush is disabled
  1073.  
  1074.     DESC sub-sub-chunks - specialized object data
  1075.     ---------------------------------------------
  1076.  
  1077.     DTOO - size 4
  1078.  
  1079.         BYTE    Type;       ; type of deform tool - always 1
  1080.         BYTE    NX;         ; # of points in X direction (>= 2)
  1081.         BYTE    NY;         ; # of points in Y direction (>= 2)
  1082.         BYTE    NZ;         ; # of points in Z direction (>= 2)
  1083.  
  1084.         This chunk appears when Imagine "deform tool" objects are written.
  1085.         The numbers, NX, etc, are one larger than the "section" counts
  1086.         that the user specifies in the deform tool creation dialog.
  1087.  
  1088.         It was introduced in the Windows 1.1 upgrade version.  The point
  1089.         count for the object is NX * NY * NZ (when the type is 1).
  1090.  
  1091.         Prior to the introduction of this chunk, when Imagine created
  1092.         a deform tool it have it a name like 'DTOOL_2_2_4', to describe
  1093.         a tool with NX=3,NY=3, and NZ=5, above.  As a result, it did not
  1094.         recognize such an object as a deform tool, if the user had changed
  1095.         the name of the object.
  1096.  
  1097.     PTHD - size 2 + 60 * axis count
  1098.     PTH2 - size 2 + 68 * axis count - (spline editor added)
  1099.     PTH3 - size 4 + 76 * axis count - Imagine 1.3 for Windows
  1100.  
  1101.         These chunks contain the data for Imagine "path" objects.
  1102.         PTH2 and PTH3 chunks are used for "spline editor" paths as well
  1103.         as "detail" and "stage editor" (axis based) paths.
  1104.  
  1105.         (PTHD chunk)
  1106.  
  1107.         WORD    ACount;         ; axis count
  1108.         TFORM   PData[];        ; axis data
  1109.  
  1110.         (PTH2 chunk)
  1111.  
  1112.         WORD      ACount;        ; axis count
  1113.         PTHD_OLD  PData[];       ; axis data
  1114.  
  1115.         (PTH3 chunk) - 32K limit removed
  1116.  
  1117.         DWORD   ACount;         ; axis count
  1118.         PTHD    PData[];        ; axis data
  1119.  
  1120.         The PTHD and PTHD_OLD structures are defined as:
  1121.  
  1122.         typedef struct {
  1123.             VECTOR  r;          ; position of axis (spline "knot")
  1124.             VECTOR  a;          ; direction 1
  1125.             VECTOR  b;          ; direction 2
  1126.             VECTOR  c;          ; direction 3
  1127.             VECTOR  s;          ; sizes
  1128.             LONG    infrom;     ; axis number for "from" connection
  1129.             LONG    outto;      ; axis number for "to" connection
  1130.             LONG    flags;      ; see below.
  1131.             LONG    extracnt;   ; reserved - must be set to zero.
  1132.         } PTHD;
  1133.  
  1134.         PTHD_OLD is identical, with 'LONG' replaced by 'WORD'
  1135.  
  1136.         'flags' bits:
  1137.  
  1138.         #define PTHF_NEWPATH    0x01    // flag - spline editor path
  1139.         #define PTHF_CONNECTIN  0x02    // flag - 'infrom' valid
  1140.         #define PTHF_CONNECTOUT 0x04    // flag - 'outto' valid
  1141.         #define PTHF_SHARP      0x80    // flag - discontinuous knot
  1142.  
  1143.         Prior to the introduction of Imagine's spline editor, the path
  1144.         objects were all "axis based", and a path was just a series of
  1145.         axis objects.  The axis position, the 3 direction vectors, and
  1146.         the axis lengths were stored in the 'TFORM' structures, and the
  1147.         Y axis length had/has a special significance.  For "open paths",
  1148.         the Y axis length of the last axis object is zero.  All other
  1149.         Y axis lengths are non-zero, and correspond to the length of the
  1150.         path as it runs from that axis, to the next.
  1151.  
  1152.         When the spline editor was added to Imagine, the path data was
  1153.         extended to allow for more options.  For detail and stage editor
  1154.         paths, the "axis" data remained unchanged (note: the first 5
  1155.         members of the PTHD structure are the same as a TFORM structure),
  1156.         and the information about the "connection order" was added to
  1157.         the data ... however, the connection order is always "first to
  1158.         last" (i.e. axis 0 connects to axis 1, then 1 to 2, etc.)
  1159.  
  1160.         PTHD structure:
  1161.  
  1162.         The PTHD structures are used to describe two types of paths.
  1163.         The first type is used for detail and stage editor "paths",
  1164.         where path "axes" appear in various places in the world, the
  1165.         the directions of the Y axes are used to establish a path.
  1166.         The second type is used to describe "spline paths" used by the
  1167.         "spline" editor.  The "spline editor" paths have the 'PTHF_NEWPATH'
  1168.         flag set in the 'flags' member.  Both types use the 'infrom'
  1169.         and 'outto' fields, along with the 'PTHF_CONNECTIN' and
  1170.         'PTHF_CONNECTOUT' flags to describe the "connection" order.
  1171.         When PTHF_CONNECTIN is set, for example, the 'infrom' field is
  1172.         considered as valid, and contains the axis (or spline knot) number
  1173.         of the axis (or knot) preceding the current one in the connection
  1174.         order.  Spline editor paths allow multiple loops in a single
  1175.         object's path data, and "work in progress" spline paths can have
  1176.         many knots which are connected only on one end.  Detail and Stage
  1177.         editor paths allow only a single loop in the path (Closed Path),
  1178.         or two endpoints (Open Path).  The 'r' vector in the PTHD structure
  1179.         is always the position of the axis or knot.  The use of the other
  1180.         VECTOR fields depends on the type of path.
  1181.  
  1182.         For Detail/Stage editor paths:
  1183.  
  1184.         'a' - is the X axis direction (a unit vector)
  1185.         'b' - is the Y axis direction (a unit vector)
  1186.         'c' - is the Z axis direction (a unit vector)
  1187.         's.X' - length of X axis
  1188.         's.Z' - length of Z axis
  1189.         's.Y' - path length on "outgoing path" to next axis
  1190.                 (note: if you are reading a file generated by Imagine,
  1191.                 this field will be valid.  If you are generating a file
  1192.                 yourself, then you will need more information.  For a
  1193.                 "quick hack", you can write any non-zero number in this
  1194.                 field, and load the path into the detail editor, and
  1195.                 "tweak" each axis, to get it calculated.  Also, it should
  1196.                 be possible to use such a path in the "Stage Editor".
  1197.                 For use in the Detail editor, though, it is important that
  1198.                 this value be set correctly.  At the time of this writing,
  1199.                 there is no existing document explaining the algorithm that
  1200.                 is used.  If it becomes important, contact Impulse.)
  1201.  
  1202.         For Spline editor paths:
  1203.  
  1204.         Each point (knot) on the path is associated with two "control
  1205.         points" ... the "bowtie" points in the editor ... one on each
  1206.         side of the knot.  The path is assumed to lie in the X-Z plane,
  1207.         with the Y components of every vector being zero.
  1208.  
  1209.         'a' - is the direction from the knot to the control point
  1210.               preceding it (a unit vector)
  1211.         'c' - is the direction from the knot to the control point
  1212.               following it (a unit vector)
  1213.         'b' - is the Y axis direction (0,1,0) (perpendicular to the
  1214.               plane containing the path)
  1215.         'c' - is the Z axis direction (a unit vector)
  1216.         's.X' - distance from the knot to the preceding control point
  1217.         's.Z' - distance from the knot to the following control point
  1218.         's.Y' - unused - set to zero.
  1219.  
  1220.         Note:  Zeros should be written for directions & distances at open
  1221.         ends of the path (where one of PTHF_CONNECTIN or PTHF_CONNECTOUT
  1222.         is not set).  If PTHF_SHARP is clear, the 'a' and 'c' vectors
  1223.         should point in opposing directions (continuous tangent vector
  1224.         at the knot) ... otherwise (if PTHF_SHARP is set), they can point
  1225.         in different directions, and the path will have a sharp change of
  1226.         direction at the point.
  1227.  
  1228.         Note 2: on path lengths and Y axis lengths for "axis based" paths.
  1229.          The actual path that is generated internally in Imagine, is a
  1230.          3rd order "b-spline path".  For b-spline pros, the two control
  1231.          points between a pair of axes, are displaced from the axes, in
  1232.          the direction of the Y-axis (unit) vectors, by a distance which
  1233.          is 1/3 of the Y axis length.  A recursive algorithm, and "initial
  1234.          guess" formula are used to adjust the Y axis length so that the
  1235.          path which is generated by the above procedure, in fact has a
  1236.          length equal to the Y axis length. When a point is to be placed
  1237.          at, say a 30% point along the path, the "s = .3, 1-s = .7" point
  1238.          of the b-spline is used.  It is an approximation to the point
  1239.          which is 30% along the actual path length, but it's a fairly
  1240.          good approximation, due to the fact that the "velocity vector"
  1241.          at the two endpoints has a length equal to the path length, via
  1242.          the fact that the control points are displaced by 1/3 the path
  1243.          length, and the fact that the average of the length of the
  1244.          velocity vector, over the range of 's' range is, by definition,
  1245.          the actual path length.
  1246.  
  1247.     FORD - size 56 + 12 * PC
  1248.     FOR2 - size 56 + 12 * PC + 2 * sections
  1249.     FOR3 - size 62 + 12 * PC + 4 * sections - 32K limit removed
  1250.  
  1251.         These chunks contain data for Imagine "forms editor" objects.
  1252.  
  1253.         (FORD chunk) - "two formers" style only
  1254.  
  1255.         WORD    NumC;           ; number of cross section points
  1256.         WORD    NumF;           ; number of slices
  1257.         WORD    Flags;          ; orientation flag
  1258.         WORD    pad;            ; reserved - set to zero
  1259.         MATRIX  TForm;          ; object rotation/scaling transformation
  1260.         VECTOR  Shift;          ; object translation
  1261.         VECTOR  Points[PC];     ; "Forms" editor points
  1262.  
  1263.         (FOR2 chunk) - more styles added, and multiple cross sections
  1264.  
  1265.         WORD    NumC;           ; number of cross section points
  1266.         WORD    NumF;           ; number of slices
  1267.         WORD    Flags;          ; orientation flag
  1268.         WORD    NumS;           ; cross section count
  1269.         MATRIX  TForm;          ; object rotation/scaling transformation
  1270.         VECTOR  Shift;          ; object translation
  1271.         VECTOR  Points[PC];     ; "Forms" editor points
  1272.  
  1273.         (FOR3 chunk) - 32K limit removed
  1274.  
  1275.         DWORD   NumC;           ; number of cross section points
  1276.         DWORD   NumF;           ; number of slices
  1277.         DWORD   NumS;           ; cross section count
  1278.         WORD    Flags;          ; orientation flag
  1279.         MATRIX  TForm;          ; object rotation/scaling transformation
  1280.         VECTOR  Shift;          ; object translation
  1281.         VECTOR  Points[PC];     ; "Forms" editor points
  1282.  
  1283.         Flags bits:
  1284.  
  1285.         bit 0: orientation flag
  1286.  
  1287.         #define FORM_VFORM  1   ; X-Y orientation for cross sections
  1288.  
  1289.         bits 1-2: type bits (FOR2 and FOR3 chunks only)
  1290.  
  1291.         #define FORM_TWOF   0   ; "Two formers" style (PPF = 4, below)
  1292.         #define FORM_ONEF   2   ; "One former" style (PPF = 2, below)
  1293.         #define FORM_ONES   4   ; "One spacer" style (PPF = 1, below)
  1294.         #define FORM_TYPE   6   ; - mask for above
  1295.  
  1296.         For Imagine's "Forms" objects, the "PNTS" chunk above is not
  1297.         written out, but this structure is written instead.  The point
  1298.         count is PC = NumS * NumC + PPF * NumF, where 'NumS' is set to
  1299.         1 for data in FORD chunks.
  1300.         The object's real points are then calculated from these using
  1301.         a proprietary algorithm. The tranformation parameters above
  1302.         allow the axes of the real object be moved around relative
  1303.         to the "Forms" points.
  1304.  
  1305.     ANID - size 64
  1306.  
  1307.         LONG    Cellno;         ; cell number
  1308.         TFORM   TForm;          ; object position/axes/size in that cell.
  1309.  
  1310.         For Imagine's "Cycle editor" objects, within EACH DESC chunk in
  1311.         the file - that is, for each object of the group, there will be
  1312.         a series of ANID chunks.  The cell number sequences of each child
  1313.         of a group must agree with the sequence for the head object, and
  1314.         the first cell number must be zero.
  1315.  
  1316.         Note: the "cycle editor" was removed in Imagine 1.0 for Windows.
  1317.  
  1318.     DESC sub-sub-chunks - object "state" data
  1319.     -----------------------------------------
  1320.  
  1321.     State data in DESC blocks is stored as multiple successive STND
  1322.     chunks, one for each state, each containing sub-chunks.  A STID
  1323.     sub-chunk names the state and specifies certain flag values, and then
  1324.     multiple STDT sub-chunks can appear, each containing a specific type
  1325.     of data.
  1326.  
  1327.     STND - variable size
  1328.  
  1329.         STID chunk              ; need not appear first
  1330.         STDT chunk
  1331.         STDT chunk
  1332.         ... etc.
  1333.  
  1334.     STID - size 20
  1335.  
  1336.         BYTE    Name[18];       ; state name - null terminated
  1337.         WORD    Flags;          ; state flags
  1338.  
  1339.         Flag bits:
  1340.  
  1341.         SNF_AXES    0x0001      ; contains axis data
  1342.         SNF_SHAPE   0x0002      ; contains point/path data
  1343.         SNF_COLOR   0x0004      ; contains face color data
  1344.         SNF_PROPS   0x0008      ; contains attributes data
  1345.         SNF_TXBR    0x0010      ; contains brush or texture data
  1346.  
  1347.         Imagine uses these flags to quickly determine which types of
  1348.         data are associated with a (named) state.
  1349.  
  1350.     STDT - variable size
  1351.  
  1352.         WORD    IdTag;          ; indicates the type of data
  1353.         WORD    Flags;          ; reserved, set to zero.
  1354.         BYTE    Data[]          ; specific data
  1355.  
  1356.         The IdTag values, and data types are listed below.
  1357.  
  1358.         The chunks can appear in any order, with the following
  1359.         exception:  a SDTAG_TXBRNAME chunk is always followed
  1360.         a chunk containing texture or brush data.
  1361.  
  1362.         Some of the types have been upgraded, to allow for the
  1363.         new features that have been added in Imagine.
  1364.  
  1365.         SDTAG_OBJAXES   101 // object axes, etc.  : TFORM structure
  1366.         SDTAG_POINTS    102 // point coords       : VECTOR list
  1367.         SDTAG_PAXES     103 // path axes          : PTHD_OLD list
  1368.         SDTAG_SIZES     104 // object axis sizes  : VECTOR
  1369.         SDTAG_DLIST     105 // diffuse colors     : BYTE[3] list
  1370.         SDTAG_TLIST     106 // filter colors      : BYTE[3] list
  1371.         SDTAG_RLIST     107 // reflection colors  : BYTE[3] list
  1372.         SDTAG_OPROPS    108 // object colors/props: OPROPS structure
  1373.         SDTAG_TXBRNAME  109 // name field for next brush or texture
  1374.         SDTAG_OBRSH     110 // brush data         : OBRSH structure
  1375.         SDTAG_OTXTR     111 // texture data       : OTXTR structure
  1376.         SDTAG_OBRSH2    112 // brush data         : OBRSH2 structure
  1377.         SDTAG_OTXTR2    113 // brush data         : OTXTR2 structure
  1378.         SDTAG_OPROPS2   114 // object colors/props: OPROPS2 structure
  1379.         SDTAG_OPROPS3   115 // object colors/props: OPROPS3 structure
  1380.         SDTAG_PAXES2    116 // path axes          : PTHD list
  1381.  
  1382.         upgrade replacements:
  1383.  
  1384.         SDTAG_OBRSH2 replaces SDTAG_OBRSH.
  1385.         SDTAG_OTXTR2 replaces SDTAG_OTXTR.
  1386.         SDTAG_OPROPS3 replaces SDTAG_OPROPS2 and SDTAG_OPROPS.
  1387.  
  1388.         The items containing "per face color lists" contain 3 bytes per
  1389.         object face.
  1390.  
  1391.         The SDTAG_POINTS chunk contains one 12 bytes per object point.
  1392.  
  1393.         The SDTAG_PAXES and SDTAG_PAXES2 chunks contain one structure
  1394.         (PTHD_OLD or PTHD) per path axis.  
  1395.  
  1396.         The SDTAG_TXBRNAME chunk contains a byte count followed by a
  1397.         the characters in the file or module name.  In general, the
  1398.         string is not null terminated.  However, the chunk size is
  1399.         forced to be even, by appending a zero pad byte - which is
  1400.         counted in the chunk size, in this case (contratictory to
  1401.         the normal way that filenames are handled above, in the
  1402.         non-state-based data).
  1403.  
  1404.         The OBRSH,OTXTR,OBRSH2 and OTXTR2 structure are defined below.
  1405.         For details on the items in the structures, refer to the
  1406.         descriptions for the TXT1 and BRS1 chunks (and  successors).
  1407.  
  1408.         typedef struct {
  1409.             TFORM    tform;         // 60 bytes
  1410.             WORD    type;           //  2 bytes
  1411.             WORD    wrap;           //  2 bytes
  1412.             WORD    fullscale;      //  2 bytes
  1413.             WORD    maxseq;         //  2 bytes
  1414.             BYTE    subgrp[18];     // 18 bytes
  1415.             BYTE    stname[18];     // 18 bytes
  1416.         } OBRSH;                // total size = 104
  1417.  
  1418.         typedef struct {
  1419.             TFORM   tform;          // 60 bytes
  1420.             WORD    type;           //  2 bytes
  1421.             WORD    wrap;           //  2 bytes
  1422.             WORD    fullscale;      //  2 bytes
  1423.             WORD    maxseq;         //  2 bytes
  1424.             BYTE    subgrp[18];     // 18 bytes
  1425.             BYTE    stname[18];     // 18 bytes
  1426.             BYTE    brusrid[18];    // 18 bytes
  1427.             FRACT   brshint;        //  4 bytes
  1428.             FRACT   brfog_low;      //  4 bytes
  1429.             FRACT   brfog_hi;       //  4 bytes
  1430.         } OBRSH2;               // total size = 134
  1431.  
  1432.         typedef struct {
  1433.             TFORM   tform;          // 60 bytes
  1434.             WORD    flags;          //  2 bytes
  1435.             WORD    pad;            //  2 bytes
  1436.             FRACT   params[16];     // 64 bytes
  1437.             BYTE    pflags[16];     // 16 bytes
  1438.             BYTE    subgrp[18];     // 18 bytes
  1439.             BYTE    stname[18];     // 18 bytes
  1440.         } OTXTR;                // total size = 180
  1441.  
  1442.         typedef struct {
  1443.             TFORM   tform;          // 60 bytes
  1444.             WORD    flags;          //  2 bytes
  1445.             WORD    pad;            //  2 bytes
  1446.             FRACT   params[16];     // 64 bytes
  1447.             BYTE    pflags[16];     // 16 bytes
  1448.             BYTE    subgrp[18];     // 18 bytes
  1449.             BYTE    stname[18];     // 18 bytes
  1450.             BYTE    txusrid[18];    // 18 bytes
  1451.             FRACT   txtrint;        //  4 bytes
  1452.         } OTXTR2;               // total size = 202
  1453.  
  1454.         // the OPROPS,OPROPS2 and OPROPS3 structures are defined
  1455.         // as follows:
  1456.  
  1457.         typedef struct {
  1458.             BYTE    props[NUM_IOBJ_PROPS];  //   8 bytes
  1459.             WORD    lamp;                   //   2 bytes
  1460.             WORD    flags; /* unused */     //   2 bytes
  1461.             VECTOR  intensity;              //  12 bytes
  1462.             FRACT   foglen;                 //   4 bytes
  1463.             BYTE    diffuse[4];             //   4 bytes (0,R,G,B)
  1464.             BYTE    reflect[4];             //   4 bytes (0,R,G,B)
  1465.             BYTE    transmit[4];            //   4 bytes (0,R,G,B)
  1466.             BYTE    specular[4];            //   4 bytes (0,R,G,B)
  1467.         } OPROPS;                           //  42 bytes total
  1468.  
  1469.         typedef struct {
  1470.             BYTE    props[NUM_IOBJ_PROPS];  //   8 bytes
  1471.             WORD    lamp;                   //   2 bytes
  1472.             WORD    flags; /* unused */     //   2 bytes
  1473.             VECTOR  intensity;              //  12 bytes
  1474.             FRACT   foglen;                 //   4 bytes
  1475.             BYTE    diffuse[4];             //   4 bytes (0,R,G,B)
  1476.             BYTE    reflect[4];             //   4 bytes (0,R,G,B)
  1477.             BYTE    transmit[4];            //   4 bytes (0,R,G,B)
  1478.             BYTE    specular[4];            //   4 bytes (0,R,G,B)
  1479.             FRACT   fogfoff;                //   4 bytes
  1480.             FRACT   foghot;                 //   4 bytes
  1481.             WORD    fogtype;                //   2 bytes
  1482.             WORD    fogpad;                 //   2 bytes
  1483.         } OPROPS2;                          //  50 bytes total
  1484.  
  1485.         typedef struct {
  1486.             BYTE    props[NUM_IOBJ_PROPS];  //   8 bytes
  1487.             WORD    lamp;                   //   2 bytes
  1488.             WORD    flags; /* unused */     //   2 bytes
  1489.             VECTOR  intensity;              //  12 bytes
  1490.             FRACT   foglen;                 //   4 bytes
  1491.             BYTE    diffuse[4];             //   4 bytes (0,R,G,B)
  1492.             BYTE    reflect[4];             //   4 bytes (0,R,G,B)
  1493.             BYTE    transmit[4];            //   4 bytes (0,R,G,B)
  1494.             BYTE    specular[4];            //   4 bytes (0,R,G,B)
  1495.             FRACT   fogfoff;                //   4 bytes
  1496.             FRACT   foghot;                 //   4 bytes
  1497.             WORD    fogtype;                //   2 bytes
  1498.             WORD    fogpad;                 //   2 bytes
  1499.             FRACT   overdfog;               //   4 bytes
  1500.             FRACT   overdspec;              //   4 bytes
  1501.         } OPROPS3;                          //  50 bytes total
  1502.  
  1503.         The data in these structures corresponds to "normal" data
  1504.         for objects (described elsewhere) as follows:
  1505.  
  1506.         props[NUM_IOBJ_PROPS];      - PRP2 chunk
  1507.         WORD    lamp;               - SHP2 chunk - Lamp
  1508.         VECTOR  intensity;          - INT1 chunk
  1509.         FRACT   foglen;             - FOGL/FOG2/FOG3 chunks - Foglen
  1510.         BYTE    diffuse[4];         - COLR chunk
  1511.         BYTE    reflect[4];         - REFL chunk
  1512.         BYTE    transmit[4];        - TRAN chunk
  1513.         BYTE    specular[4];        - SPC1/SPC2 chunks - Color
  1514.         FRACT   fogfoff;            - FOG2/FOG3 chunks - Falloff
  1515.         FRACT   foghot;             - FOG2/FOG3 chunks - Hotness
  1516.         WORD    fogtype;            - FOG2/FOG3 chunks - Type
  1517.         FRACT   overdfog;           - FOG3 chunk - Overdrive
  1518.         FRACT   overdspec;          - SPC2 chunk - Overdrive
  1519.  
  1520. End
  1521. ---
  1522.  
  1523.