To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
To LUGNET News Traffic PageSign In (Members)
 Orion Pobursky / $3

LDraw File Specification 1.0.0

Describing Virtual LEGO® Bricks and Models

Note: This Document is a work in progress

Table of Contents

Purpose
LDraw Files
    Line Types
        Line Type 0
        Line Type 1
        Line Type 2
        Line Type 3
        Line Type 4
        Line Type 5
    Colors
    Meta Commands
        Step
        Write/Print
        Clear
        Pause
        Save
        File Type
        Category
        Keywords
        Other Meta Commands

Purpose

Describing LEGO® bricks and models in a virtual environment is a challenging prospect. In 1995 James Jessiman developed just such a system with is his LDraw program and file format. Since then the LDraw file format has grown to be the standard by which most create virtual LEGO® models.

The aim of this document is to compile and consolidate James’s original file specification with the additions made since.

LDraw Files

Text Based All LDraw files are plain text based.

Extension All LDraw files carry the LDR (default), DAT or MPD extension. All files in the LDraw Parts Library must carry the DAT extension.

Every line of the file contains one command. Every command is independent of other lines. There is no line length restriction. Every command starts with a number, called a line type. The function and format of the line is determined by the line type.

Line Types

The line type of a line is the first number on the line. The line types are: * 0: Comment or Meta Command * 1: Part file reference * 2: Line * 3: Triangle * 4: Quadrilateral * 5: Optional Line If the line type of the command is invalid, the line is ignored.

Line Type 0

Line type 0 has two uses. One use is a comment the other is as a Meta command.

If the first line of a file is a line type 0 the remainder of the line is considered the file title. This overrides any Meta commands on that line.

A comment line is formatted:

0 comment

Where comment is any string

Meta Commands

A Meta command is a statement used to tell an LDraw compatible program to do something. There are currently many official Meta commands and almost as many unofficial Meta commands. In a Meta command, a keyword follows the line type in the line. The keyword must be in all caps. The generic Meta line format is:

0 command parameters

Where: * command is any string in all caps * parameters is any string. Note that if a Meta command does not require any additional parameter, none should be given.

For a list of official Meta commands, see the Meta commands section





Line Type 1

Line type 1 is a file reference. The generic format is:

1 color x y z a b c d e g f h i file

Where: * color is a number representing the color of the part. See the Colors section for allowable color numbers * x y z is the x y z coordinate of the part * a through i is a standard 3D transformation matrix. This represents the rotation and scaling of the part. * file is the filename of the file referenced. Files can be located LDRAWPARTS, LDRAWP, LDRAWMODELS, or the current file’s directory. There is no limit on how far these files can be nested.

Line Type 2

Line type 2 is a line drawn between two points. The generic format is:

2 color x1 y1 z1 x2 y2 z2

Where: * color is a number representing the color of the line. See the Colors section for allowable color numbers * x1 y1 z1 is the coordinate of the first point * x2 y2 z2 is the coordinate of the second point


Line Type 3

Line type 3 is a filled triangle drawn between three points. The generic format is:

3 color x1 y1 z1 x2 y2 z2 x3 y3 z3

Where: * color is a number representing the color of the triangle. See the Colors section for allowable color numbers * x1 y1 z1 is the coordinate of the first point * x2 y2 z2 is the coordinate of the second point * x3 y3 z3 is the coordinate of the third point




Line Type 4

Line type 4 is a filled quadrilateral drawn between four points. The generic format is:

4 color x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4

Where: * color is a number representing the color of the quadrilateral. See the Colors section for allowable color numbers * x1 y1 z1 is the coordinate of the first point * x2 y2 z2 is the coordinate of the second point * x3 y3 z3 is the coordinate of the third point * x4 y4 z4 is the coordinate of the fourth point

Line Type 5

Line type 5 is a filled conditional or optional line. This draws a line between the first two points, if the projections of the last two points onto the screen are on the same side of an imaginary line through the projections of the first two points onto the screen. The generic format is:

5 color x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4


Where: * color is a number representing the color of the line. See the Colors section for allowable color numbers * x1 y1 z1 is the coordinate of the first point * x2 y2 z2 is the coordinate of the second point * x3 y3 z3 is the coordinate of the third point * x4 y4 z4 is the coordinate of the fourth point














The optional line can be a difficult concept to grasp. The best way to demonstrate how they work is through a series of pictures.


Say we have an optional line at the point below 2. The other points are 3 and 1. In this case the line would not be drawn since points 1 and 3 are not on the same side of the line below 2. Now say we have an optional line at the point below 3. The other points are 2 and 4. The line would be drawn since 2 and 4 are on the same side of the line below 3. In the case of the picture above the only lines that are drawn would be those below 3 and 7. This serves to “outline” the edges of the cylinder, which is the intent of optional lines.

Colors

Colors in LDraw are defined by a number. The allowable numbers are 1-16, 24, 32-47, 256-511. The numbers 1-15 are the core colors. They are: 0. Black 1. Blue 2. Green 3. Dark Cyan 4. Red 5. Magenta 6. Brown 7. Grey 8. Dark Grey 9. Light Blue 10. Light Green 11. Cyan 12. Light Red 13. Pink 14. Yellow 15. White

The number for transparent equivalent of the core colors is obtained by adding 32 to the core color’s number. For example the number for transparent blue is 1 + 32 = 33.

Colors 256-512 are dithered colors. Only line type 1 is allowed to use colors 256-512. Basically colors 256-512 are the combination of two of the core colors. The way this is accomplished is:

color = (color 1 * 16) + color 2 + 256

Example, if you want to combine Black (color 0) and Red (Color 4):

(0 * 16) + 4 + 256 = 260











Colors 16 and 24 are special colors. Color 16 is the ‘current color’, whatever color the type 1 was that reference the file. Color 24 is the complement color to the current color. Line type 2 is typically color 24. The combinations are:

Current Color Complement Color 0 8 1 9 2 10 3 11 4 12 5 13 6 0 7 8 8 0 9 1 10 2 11 3 12 4 13 5 14 8 15 8

The complement for the dithered colors is the complement for the first color of the two colors used to determine the dithered color number. For example:

260 = (0 * 16) + 4 + 256 the complement is the complement of color 0, color 8

Meta Commands

The Meta commands documented here explain the behavior exhibited in ldraw.exe. For other LDraw compatible viewers refer to the documentation of the program you are using.

Step

Marks the end of a building step

Format: 0 STEP

The Step command causes the program to stop until the Enter key is pressed. Additionally a bitmap of the currently displayed model will be save to the LDRAWBITMAP directory

Write/Print

Displays a message

Format: 0 WRITE message Or 0 PRINT message

message is a string of any length. This message is not saved on any bitmaps.

Clear

Clears the screen

Format: 0 CLEAR

This command causes all previous drawn files and line types to be cleared. Any following lines are drawn as normal.

Pause

Pauses the drawing of a file

Format: 0 PAUSE

This command stops the further parsing of lines until the Enter key is pressed. Save

Saves a bitmap of the current drawing

Format: 0 SAVE

Save a bitmap of the current drawing in the LDRAWBITMAP directory. This command does not cause the program to pause.

File Type

Indicates the type of file (model, part, etc), and if it is part of the LDraw.org Parts Library.

Format:      0 LDRAWORG type update-tag or: 0 Official LCAD type update-tag or: 0 Unofficial type or: 0 Un-official type

This meta-statement should appear as the last line of the primary file header. The first format (LDRAWORG) 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: * Part * * Element – * Subpart * * Sub-part – * Primitive * * Shortcut * * Alias * * Cross-reference + * Model – * Submodel – * File – * Hi-Res Primitive –
  • = values currently in use for official part files.
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 line type should be considered case-insensitive and free-format. Category

Classifies a file according to a category

Format: 0 CATEGORY categoryname

This command is used almost exclusively in part files. A file can have only one category statement. categoryname can only be one of the following values: * * Animal * Antenna * Arch * Arm * Bar * Baseplate * Belville * Boat * Bracket * Brick * Car * Cone * Container * Conveyor * Crane * Cylinder * Door * Electric * Exhaust * Fence * Flag * Forklift * Freestyle * Garage * Gate * Glass * Grab * Hinge * Homemaker * Hose * Jack * Ladder * Lever * Magnet * Minifig * Minifig Accessory * Panel * Plane * Plant * Plate * Platform * Propellor * Rack * Roadsign * Rock * Scala * Slope * Staircase * Support * Tail * Tap * Technic * Tile * Tipper * Tractor * Trailer * Train * Turntable * Tyre * Wedge * Wheel * Winch * Window * Windscreen * Wing


If a part file has no category command the category is assumed to be the first word in the file title.











Keywords

Adds additional classifying words to a file

Format 0 KEYWORDS keyword keywordkeyword

The keywords command is essentially a laundry list of words that further describe the file. Like the category command, this command is used almost exclusively in part files. The list of words after the KEYWORD command can be space or comma delimited. The words the list should not also occur in the file title.

Other Meta Commands

The following is a list of other Meta Commands. These commands are documented and maintained by the owner of their respective programs. The URLs listed are the last known good links to that product. This list is not intended as a limit but merely to prevent overlap.

The following will be documented in future version of this document   FILE name   NOFILE   BFC (CERTIFYNOCERTIFY)] [(CLIPNOCLIP) (CWCCW)] [INVERTNEXT]

MLCad (http://www.lm-software.com/mlcad/)

ROTSTEP (x-angle y-angle z-angle (RELADDABS) END) BACKGROUND <filename> BUFEXCHG (A-H) (STORE RETRIEVE) GHOST line GROUP n name MLCAD BGT name MLCAD SKIPBEGIN MLCAD SKIPEND ROTATION CENTER xyzname” ROTATION CONFIG ID Flag ROTATION AXLE MLCAD SPRING MLCAD FLEXHOSE MLCAD RUBBERBELT






LPub (http://www.users.qwest.net/~kclague/LPub/index.htm)

PLIST BEGIN SUB fname   PLIST BEGIN IGN     PLIST END   BI BEGIN GRAYED     BI END

LSynth (http://www.users.qwest.net/~kclague/lsynth/index.htm)

SYNTH BEGIN (RIBBEDTUBE                          FLEXIBLE_TUBE                          FLEXCABLE                               RIGID_TUBE                                 ELECTRICCABLE                          PNEUMATIC_TUBE                          FLEXIBLEAXLE                          FIBER_OPTIC_CABLE                          RUBBERBAND                          CHAIN                          PLASTICTREAD                        RUBBER_TREAD) SYNTH END SYNTH (INSIDE OUTSIDE CROSS SHOW HIDE) SYNTHESIZED BEGIN SYNTHESIZED END

L3P (http://www.hassings.dk/l3/l3p.html)

L3P IFPOV L3P IFNOTPOV L3P ELSEPOV L3P ENDPOV

LDLite (http://ldlite.sourceforge.net/)

COLOR TRANSLATE ROTATE SCALE TRANSFORM COLORNAME POINT MATRIX CMDLINE line
Primary content in this document is © Orion Pobursky. All other text, images, or trademarks in this document are the intellectual property of their respective owners.


©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR