•  Back 
  •  %Main 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help page 
  •  Show info about hypertext 
  •  View a new file 
Topic       : ATARI ST Picture formats
Author      : David Baggett/Jan K⌐upka
Version     : atari_gf.hyp 0.01 (17/09/96)
Subject     : Documentation/File formats
Nodes       : 52
Index Size  : 1328
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : 
@help       : 
@options    : -i -s +y +z
@width      : 75CAD-3D Three-Dimensional Object File     *.3D2

  CAD-3D 2.0 stores its 3D objects in a file which can hold up to 40
objects, and contains all the information about the objects, including
the lighting and color palette used by the objects.

  The file is similar to the older file format, but no longer relies on
the Motorola Fast Floating Point library (LIBF) for the storage of vertex
coordinates. The new version stores each coordinate in a two-byte wordword = 2 bytes

instead of a four-byte floating-point value, saving a considerable amount
of storage, as well as making the file usable more easily by programs
written with different floating-point formats.

  The CAD-3D 2.0 3D object file uses an extension of .3D2, and is composed
of two parts.  The first section is a 256-byte header, which tells how many
objects are included in the file, the light settings and the color
information. The second section of the file contains a repeating structure
of data which defines the 3D objects in the file.

  The header is structured as follows:


1 wordword = 2 bytes
    File ID    $3D02

1 wordword = 2 bytes
    Count of objects in file (1-40)

1 wordword = 2 bytes
    Light source A on/off indicator (0=off, 1=on)
1 wordword = 2 bytes
    Light source B on/off indicator (0=off, 1=on)
1 wordword = 2 bytes
    Light source C on/off indicator (0=off, 1=on)

1 wordword = 2 bytes
    Light source A brightness (0-7)
1 wordword = 2 bytes
    Light source B brightness (0-7)
1 wordword = 2 bytes
    Light source C brightness (0-7)
1 wordword = 2 bytes
    Ambient light brightness (0-7)

1 wordword = 2 bytes
    Light source A Z position (-50 through +50)
1 wordword = 2 bytes
    Light source B Z position (-50 through +50)
1 wordword = 2 bytes
    Light source C Z position (-50 through +50)

1 wordword = 2 bytes
    Light source A Y position (-50 through +50)
1 wordword = 2 bytes
    Light source B Y position (-50 through +50)
1 wordword = 2 bytes
    Light source C Y position (-50 through +50)

1 wordword = 2 bytes
    Light source A X position (-50 through +50)
1 wordword = 2 bytes
    Light source B X position (-50 through +50)
1 wordword = 2 bytes
    Light source C X position (-50 through +50)

32 words  Object color palette (BIOS format)
32 words  Color group base array

  In order for the palette to be useful, it must be accompanied by the
color group base array.  This array indicates the index of the first color
in the group to which that color belongs. In the following example palette,
which contains a background color of black, followed by five reds, five
greens and five blues, you can see how the palette base array is used to
group the colors together.  The reds start at color index 1, the greens at
color index 6, and the blues at color index 11.

INDEX    COLOR     BASE
-----    -----     ----
   0      000        0
   1      100        1
   2      200        1
   3      300        1
   4      400        1
   5      500        1
   6      010        6
   7      020        6
   8      030        6
   9      040        6
  10      050        6
  11      001       11
  12      002       11
  13      003       11
  14      004       11
  15      005       11


  The base value is used when performing shading operations, and if
incorrectly set will result in odd-looking images.


1 wordword = 2 bytes
    Color palette type (0=Seven-shade, 1=Fourteen shade, 2=Custom)

1 wordword = 2 bytes
    Wireframe line color (1-15)


1 wordword = 2 bytes
    Outline line color (0-15)

150 bytes    Filler for future expansion



  The object data is a variable-sized section which depends on the
complexity of the object.  The section repeats for each object in the file,
and is structured as follows:


9 bytes   Object name (8 characters max) with null terminator.

1 wordword = 2 bytes
    Number of vertices in object (15000 maximum)

  The following structure defines the X, Y and Z coordinates for each
vertex of the object.  It is made up of three words and repeats the number
of times specified by the vertex count wordword = 2 bytes
 above.

1 wordword = 2 bytes
    X coordinate of vertex, stored in the standard CAD-3D fixed-point
          format.  For example, an X coordinate of 23.69 is stored as an
          integer value of 2369.  When reading this value, simply convert
          it to a floating-point variable and divide by 100.

1 wordword = 2 bytes
    Y coordinate of vertex, also in fixed-point format. See above for
          description of format.

1 wordword = 2 bytes
    Z coordinate of vertex, also in fixed-point format. See above for
          description of the format.


  After all the vertices' coordinates have been read in, the next part of
the file describes the triangular faces which make up the object.

1 wordword = 2 bytes
    Number of triangular faces in the object (30000 maximum)

  The following structure tells the face structure of the object. It is
made up of four words and is repeated once for every face in the object,
specified by the face count above. Each face is triangular, and defined by
three vertices, or points, referred to as A, B and C.  When looking at the
face of the triangle facing outward, the A-B-C order of the vertices is
counterclockwise.  This allows for quick calculation of whether or not a
face is visible.  Each face, in addition to having the three vertices of
the triangle defined, has a color and edge-flag wordword = 2 bytes
.  This word tells the
color of the face and whether or not the line of one of the three edges
(A-B, B-C, C-A) is to be drawn in edges-only mode.

1 wordword = 2 bytes
    Number of first vertex in the face, termed point A. This value
          can range from zero to the number of vertices in the object, and
          corresponds to the vertices read from the file earlier.

1 wordword = 2 bytes
    Number of second vertex in the face, termed point B. This value
          can range from zero to the number of vertices in the object, and
          corresponds to the vertices read from the file earlier.

1 wordword = 2 bytes
    Number of third vertex in the face, termed point C. This value
          can range from zero to the number of vertices in the object, and
          corresponds to the vertices read from the file earlier.

1 wordword = 2 bytes
    Color/edge flag indicator. The low byte of this value is a number
          from 1 to 15 and tells the color used for that face when drawing.
          This value is used by the object shading routine to determine the
          color group within the palette used by this face. The upper byte
          is used to tell the program which edges are to be shown by a line
          segment when drawing in "edges only" mode.  The three low-order
          bits in this byte are used as flags for this purpose; a zero in
          the bit indicates that no line is to be drawn, a one in the bit
          indicates that the edge is to be drawn. The bitassignments are:


                   Bit 2: Line segment A-B
                   Bit 1: Line segment B-C
                   Bit 0: Line segment C-A

  The face data repeats until all faces have been defined. This is the end
of the file.