File Extensions
LDraw Model files carry either the extension LDR (default) or DAT. LDraw Part Files carry the extension DAT.
Text-Based
LDraw files are plain text. Each line is a single command, and each line is independent. Only a few commands are used in the file format. 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. No length-limit on command lines is known.
Line types
Each line in the 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:
If the line type for a line is not a valid value, the line is ignored.
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.
Commands
Here is a complete list of LDraw drawing- and meta-commands:
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.
0 title-text
0 STEP
ldraw\bitmap directory. These two
effects are controlled by the -M command line option (see
ldraw.doc for info on -M).
0 WRITE message-text
0 PRINT message-text
0 CLEAR
0 PAUSE
-M command line option.
0 SAVE
-M command line
option.
0 LDRAW_ORG type update-tag0 Official LCAD type update-tag0 Unofficial type0 Un-official typeThis meta-statement should appear as the last line of the primary file header (that is, the first lines in the file, with the Model Title, Name: and Author: lines). The first format (LDRAW_ORG) is the current standard for files in the official parts library. Older files still carry the second (Official LCAD) format. The valid values for the type field are:
Some older official files do not include a type code on their File Type line. Unofficial files may have a variety of values after the initial tag. In particular, the type values of Element, Model, and Submodel may be used.
The exact format of the File Type line has changed over time. In general, this linetype should be considered case-insensitive and free-format.
1 colour x y z a b c d e f g h i part.dat
p\, parts\, or
models\ subdirectories (under the ldraw\
directory). They may also be located in the current directory. James
has arranged the directories so that p\ contains elements
that are intended to be used as part of elements (such as
stud.dat). The parts\ directory contains
finished parts, ready to be used in construction models. And the
models\ directory contains construction models.
2 colour x1 y1 z1 x2 y2 z2
3 colour x1 y1 z1 x2 y2 z2 x3 y3 z3
4 colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
5 colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
Colours
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.
Also, colours 256 through 511 are dithered. So if you want to combine colours J and K, figure your colour value as
colour = (J * 16) + K + 256
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.
Format of Linetype 1
The Part command (linetype 1) has some unique features that require special
attention. This section makes more sense if you're familiar with matrix
math. It makes much more sense if you're familiar with using matrix math
in graphic modeling.
1 colour x y z a b c d e f g h i part.dat
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:
| a d g 0 |
| b e h 0 |
| c f i 0 |
| x y z 1 |
so that every point (x, y ,z) gets transformed to (x', y', z') :
x' = a*x + b*y + c*z + x
y' = d*x + e*y + f*z + y
z' = g*x + h*y + i*z + z
or, in matrix-math style:
| 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 |
Explanation of Conditional Lines (Linetype 5)
Here is an example using the conditional line command. If we try to approximate
a (cylindrical) stud with a hexagonal prism we have something like this:
1___________2
/ \
/ \
6/ \3
|\ /|
| \ / |
| \5___________4/ |
\ | | /
\ | | /
\|___________|/
resulting in the following drawing:
1___________2
/ \
/ \
6/ \3
|\ /|
| \ / |
| \5___________4/ |
\ /
\ /
\_____________/
For questions, contact Steve Bliss [5].
Note: This document is an offical LSC specification and/or lanaguage extension. Material changes can only be made after ratification by the LSC.