Subject:
|
autoFAQpost /cad/dat_file_format.en.faq
|
Newsgroups:
|
lugnet.faq
|
Date:
|
Mon, 12 Jul 1999 23:27:32 GMT
|
Viewed:
|
1315 times
|
| |
| |
Subject: What is the .DAT file format?
Content-Language: en
Topic-Level: 1
Revision: Jacob Sparre Andersen, 1999-05-14
Location: /cad/dev/,/cad/ldraw/file_format/
Comment: Unedited cut from the LDraw FAQ.
<P>
.DAT files are text (yes, you can edit them in EDIT or Notepad or your
favourite text editor). Each line is a single command, and each line is
independent. The commands are (mostly) very simple, there are only a few
different commands. Specific commands are identified by the first number on
the line, which is called the line-type. The contents and format of the
rest of the line depend on the line-type. I do not know of any length-limit
on command lines.</P>
<H3>Line types</H3>
<P>
Each line in the .DAT file is a single command. The first number on each
line is the line type, valid values are 0 through 5, with the following
meanings:
<DL Compact>
<DT>0: <DD>comment or meta-command
<DT>1: <DD>Part-file reference
<DT>2: <DD>Line
<DT>3: <DD>Triangle
<DT>4: <DD>Quadrilateral
<DT>5: <DD>Draw a line between the last two points, if both points are on
the same side of the line between the first two points.
</DL>
If the line type for a line is not a valid value, the line is ignored.
</P>
<P>
Meta-commands require a keyword to follow the line-type. These keywords
must be in all-caps, and you should assume that if the meta-command doesn't
require more information, you shouldn't give it any additional information.
</P>
<H3>Commands</H3>
<P>
Here is a complete (as far as I know) list of LDraw drawing- and
meta-commands:
<UL>
<LI>Model Title
<LI>Step
<LI>Write
<LI>Clear
<LI>Pause
<LI>Save
<LI>Comment
<LI>Part
<LI>Line
<LI>Triangle
<LI>Quadrilateral
<LI>Optional-Line
</UL>
</P>
<P>
And here are the details of each command. Meta-commands are listed first,
with the "real" commands after. The command-names are wholly made up by me,
I don't have any "official" names for these things.
</P>
<DL>
<DT>Model Title.
<DD>The descriptive name of the model- or part-file.
<DL Compact>
<DT>Line format: <DD><Code>0</Code> title-text
</DL>
where title-text is whatever you want to name your model.
<DD>This is a meta-command, sort of. If the first line in a .DAT file has
line-type 0, the remainder of that line will be considered the title
for the file (at least for parts files). This overrides any
meta-commands on the line.
<DT>Step meta-command.
<DD>Marks the end of a building step.
<DL Compact>
<DT>Line format: <DD><Code>0 STEP</Code>
</DL>
<DD>This command will cause LDraw to stop until you press <enter>,
and it will cause LDraw to save the current image into a bitmap file
in the <Code>ldraw\bitmap</Code> directory. These two effects are
controlled by the <Code>-M</Code> command line option (see
<Code>ldraw.doc</Code> for info on <Code>-M</Code>).
<DT>Write meta-command.
<DD>Displays a message at the top of the screen.
<DL Compact>
<DT>Line format: <DD><Code>0 WRITE</Code> message-text
<DT>or: <DD><Code>0 PRINT</Code> message-text
</DL>
where message-text is whatever you want displayed on the screen.
<DD>The displayed message is not saved in the image-bitmap files.
<DT>Clear meta-command.
<DD>Clears the screen.
<DL Compact>
<DT>Line format: <DD><Code>0 CLEAR</Code>
</DL>
<DD>Useful for advanced model files. Don't forget to redraw all the parts
you just erased by using this command.
<DT>Pause meta-command.
<DD>Causes LDraw to stop until you press <enter>.
<DL Compact>
<DT>Line format: <DD><Code>0 PAUSE</Code>
</DL>
<DD>This is like the Step command, but it does not save bitmaps, and it is
not affected by the <Code>-M</Code> command line option.
<DT>Save meta-command.
<DD>Causes LDraw to save the current image in a bitmap.
<DL Compact>
<DT>Line format: <DD><Code>0 SAVE</Code>
</DL>
<DD>This is also like the Step command, but it does not cause LDraw to
pause, and it is not affected by the <Code>-M</Code> command line
option.
<DT>Part command.
<DD>Inserts a part defined in another .DAT file.
<DL Compact>
<DT>Line format: <DD><Code>1</Code> colour x y z a b c d e f g h i part.dat
</DL>
where
<UL>
<LI>colour is a colour code: 0-15, 16, 24, 32-47, 256-511
<LI>x, y, z is the position of the part
<LI>a - i are orientation & scaling parameters (see below for
more on this)
<LI>part.dat is the filename of the included file
</UL>
<DD>Parts may located in the <Code>p\</Code>, <Code>parts\</Code>, or
<Code>models\</Code> subdirectories (under the <Code>ldraw\</Code>
directory). They may also be located in the current directory. James
has arranged the directories so that <Code>p\</Code> contains elements
that are intended to be used as part of elements (such as
<Code>stud.dat</Code>). The <Code>parts\</Code> directory contains
finished parts, ready to be used in construction models. And the
<Code>models\</Code> directory contains construction models.
<DD>Part files can also include Part commands. There don't seem to be a
specific limit to how deep these references can go.
<DT>Line command.
<DD>Draws a line between two points.
<DL Compact>
<DT>Line format: <DD><Code>2</Code> colour x1 y1 z1 x2 y2 z2
</DL>
where
<UL>
<LI>colour is a colour code: 0-15, 16, 24, 32-47, 256-511
<LI>x1, y1, z1 is the position of the first point
<LI>x2, y2, z2 is the position of the second point
</UL>
<DT>Triangle command.
<DD>Draws a filled triangle between three points.
<DL Compact>
<DT>Line format: <DD><Code>3</Code> colour x1 y1 z1 x2 y2 z2 x3 y3 z3
</DL>
where
<UL>
<LI>colour is a colour code: 0-15, 16, 24, 32-47, 256-511
<LI>x1, y1, z1 is the position of the first point
<LI>x2, y2, z2 is the position of the second point
<LI>x3, y3, z3 is the position of the third point
</UL>
<DT>Quadrilateral command.
<DD>Draws a four-sided, filled shape between four points.
<DL Compact>
<DT>Line format: <DD><Code>4</Code> colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
</DL>
where
<UL>
<LI>colour is a colour code: 0-15, 16, 24, 32-47, 256-511
<LI>x1, y1, z1 is the position of the first point
<LI>x2, y2, z2 is the position of the second point
<LI>x3, y3, z3 is the position of the third point
<LI>x4, y4, z4 is the position of the fourth point
</UL>
<DT>Optional-Line command.
<DD>Draws a line between the first two points, if the projections of both
points onto the screen are on the same side of an imaginary line
between the projections of the last two points onto the screen.
<DL Compact>
<DT>Line format: <DD><Code>5</Code> colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
</DL>
where
<UL>
<LI>colour is a colour code: 0-15, 16, 24, 32-47, 256-511
<LI>x1, y1, z1 is the position of the first point
<LI>x2, y2, z2 is the position of the second point
<LI>x3, y3, z3 is the position of the third point
<LI>x4, y4, z4 is the position of the fourth point
</UL>
Here is an example using the optional line command. If we try to
approximate a (cylindrical) stud with a hexagonal prism we have
something like this:
<Pre>
1___________2
/ \
/ \
6/ \3
|\ /|
| \ / |
| \5___________4/ |
\ | | /
\ | | /
\|___________|/
</Pre>
<UL>
<LI>The line below 1 should <Span Class=Negative>not</Span> be drawn because 6 and 2 are on <Span Class=Negative>different</Span> sides.
<LI>The line below 2 should <Span Class=Negative>not</Span> be drawn because 1 and 3 are on <Span Class=Negative>different</Span> sides.
<LI>The line below 3 <Span Class=Positive>should</Span> be drawn because 2 and 4 are on <Span Class=Positive>the same</Span> side.
<LI>The line below 4 should <Span Class=Negative>not</Span> be drawn because 3 and 5 are on <Span Class=Negative>different</Span> sides.
<LI>The line below 5 should <Span Class=Negative>not</Span> be drawn because 4 and 6 are on <Span Class=Negative>different</Span> sides.
<LI>The line below 6 <Span Class=Positive>should</Span> be drawn because 5 and 1 are on <Span Class=Positive>the same</Span> side.
</UL>
resulting in the following drawing:
<Pre>
1___________2
/ \
/ \
6/ \3
|\ /|
| \ / |
| \5___________4/ |
\ /
\ /
\_____________/
</Pre>
</DL>
<H3>Colours</H3>
<P>
Colours are outlined in LEDIT.DOC. Two special values are 16 and 24. 16 is
the 'current colour', i.e., whatever colour was specified on the type 1 line
which caused the current line to be executed. Colour 24 is a complementary
colour to the current colour, usually the bright/dark complementary shade.
So if the current colour is dark blue, colour 24 would give bright blue.
</P>
<P>
Also, colours 256 through 511 are dithered. So if you want to combine
colours J and K, figure your colour value as
</P>
<P Align=Center>
colour = (J * 16) + K + 256
</P>
<P>
The complementary colour of J is used as the complementary colour of the
dithered value. So you can control the edge colour (somewhat) by switching J
and K.
</P>
<H3></H3>
<P>
Line type 1's format is:
<DL Compact>
<DT>Line Format: <DD><Code>1</Code> colour x y z a b c d e f g h i part.dat
</DL>
</P>
<P>
Fields a through i are orientation & scaling parameters, which can be used
in 'standard' 3D transformation matrices. Fields x, y and z also fit into
this matrix:
</P>
<P Align=Center>
<Pre>
| a d g 0 |
| b e h 0 |
| c f i 0 |
| x y z 1 |
</Pre>
</P>
<P>
so that every point (x, y ,z) gets transformed to (x', y', z') :
</P>
<P Align=Center>
<Pre>
x' = a*x + b*y + c*z + x
y' = d*x + e*y + f*z + y
z' = g*x + h*y + i*z + z
</Pre>
</P>
<P>
or, in matrix-math style:
</P>
<P Align=Center>
<Pre>
| a d g 0 |
| X' Y' Z' 1 | = | X Y Z 1 | x | b e h 0 |
| c f i 0 |
| x y z 1 |
</Pre>
</P>
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|