LDR, DAT and MPD files share one syntax: plain text with one command on each line. The first token of a line is a number, the line type, that says what the rest of it means.
Text rules
| Item | Rule |
|---|---|
| Encoding | UTF-8 without a byte order mark; software may reject a file that has one. A reader should check that the text is valid UTF-8 and otherwise fall back to the Windows code page of the user’s language, or 1252. |
| Line ends | CR LF; the last line end is optional. Readers are recommended to accept a bare LF. |
| Lines | One command per line, with no length limit. Leading white space is allowed. Empty lines have no effect. |
| Tokens | Separated by any run of spaces or tabs. Some trailing data, such as a file name or comment text, is not split into tokens. |
| Bad lines | A line with an invalid line type is ignored. |
| File names | At most 255 characters including the extension; &, #, | and ? should be avoided. The old eight-plus-three limit no longer applies. |
| Extensions | .ldr (the default for models), .dat (parts and primitives, and older models) and .mpd (multi-part documents). |
Coordinates and units
The coordinate system is right-handed with −Y pointing up. Lengths are in LDraw units (LDU); one LDU is about 1/64 inch or 0.4 mm.
| Brick measurement | LDU |
|---|---|
| Width and depth of a 1 × 1 brick | 20 |
| Height of a brick | 24 |
| Height of a plate | 8 |
| Stud diameter | 12 |
| Stud height | 4 |
Line types
| Type | Meaning | Line |
|---|---|---|
0 | Comment or meta command | 0 text |
1 | Sub-file reference | 1 colour x y z a b c d e f g h i file |
2 | Line | 2 colour x1 y1 z1 x2 y2 z2 |
3 | Triangle | 3 colour x1 y1 z1 x2 y2 z2 x3 y3 z3 |
4 | Quadrilateral | 4 colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 |
5 | Optional (conditional) line | 5 colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 |
Types 1 to 5 are the operational lines. The colour field is a code from the colour system.
Type 0: comments and meta commands
- The first line of a file is its title or description. This reading takes precedence over any meta command written there.
- A comment is best written
0 // text. The bare form0 textis deprecated. - A meta command is written
0 !KEYWORD parameterswith the keyword in capitals. Some old official commands have no!; new ones must have it. A command may take no parameters. - A new meta command should start with the name of the program that defines it, as in
0 !LDPARSER EXAMPLE.
| Command | Effect |
|---|---|
0 STEP | Ends a building step. In the original LDraw program it saved a picture, then paused. |
0 WRITE message | Shows a message. |
0 PRINT message | The same as WRITE. |
0 CLEAR | Clears the screen. |
0 PAUSE | Waits for the Enter key without saving a picture. |
0 SAVE | Saves a bitmap picture without pausing; the original program wrote it to LDRAW\BITMAP. |
The other defined commands belong to the file header, colour definitions and the language extensions.
Type 1: sub-file reference
Places another file in this one. x y z is a translation and a to i a 3 × 3 matrix given row by row. A point (u, v, w) of the referenced file lands at:
u' = a*u + b*v + c*w + x
v' = d*u + e*v + f*w + y
w' = g*u + h*v + i*w + z
| a b c x |
| d e f y |
| g h i z |
| 0 0 0 1 |
- The file name is the rest of the line. Leading and trailing white space is ignored; it is otherwise not split, so it may contain spaces.
- A reference should not use colour 24.
- No limit on the depth of nesting is specified.
Where referenced files are found
Parts are not stored in a model: they come from the LDraw parts library installed
beside it. A name is looked for in LDRAW\PARTS, LDRAW\P,
LDRAW\MODELS, the folder of the current file, as a path relative to one
of these, or as a full path. A block of an MPD file can
also supply a referenced name.
| Stored in | Referenced as | Holds |
|---|---|---|
parts | 3001.dat | Parts |
parts\s | s\name.dat | Sub-parts |
p | stud.dat | Primitives |
p\48 | 48\name.dat | High-resolution primitives |
Types 2 to 4: lines, triangles and quadrilaterals
- Type 2 is a line between two points. Parts draw their edges with it, using colour 24. Not every renderer shows types 2 and 5.
- Type 3 is a filled triangle.
- Type 4 is a filled quadrilateral. Its points run round it clockwise or counter-clockwise; a crossed (bow-tie) order is wrong. The points should lie in one plane, no three of them should be in a straight line, and the shape must not be concave.
- Polygons in the same plane should overlap only when they have the same colour, and then as little as possible. Intersections should be kept to a minimum, and polygons that touch should share vertices.
- Polygons are strongly recommended not to use colour 24; what happens is up to the program.
Winding order has a meaning only under the back-face culling extension.
Type 5: optional line
The first two points are the line; the last two are control points that are never drawn. The line is drawn only if, as seen on screen, both control points fall on the same side of it. It marks the outline of curved surfaces such as cylinders. Colour rules are those of type 2.
Example
0 Two bricks
0 Name: two.ldr
1 4 0 0 0 1 0 0 0 1 0 0 0 1 3001.dat
0 STEP
1 1 0 -24 0 0 0 1 0 1 0 -1 0 0 3001.dat