LDraw file format
From Brickwiki
The LDraw file format (usually with extension .ldr or .dat) is a file format designed by the late James Jessiman with the idea of building virtual LEGO models. It is the standard format for all LDraw based projects and all parts in the LDraw parts library are designed in this format.
Contents |
Basics
The LDraw format follows a very basic format, with a handful of basic commands from which everything is built. All commands are terminated by a newline. These are as follows:
Comments (type 0)
Comments are indicated by a 0 at the start of a line, followed by the rest of the text or other information. They are terminated by a newline.
- 0This is a comment
- 0LPUB ASSEM PLACEMENT BOTTOM_RIGHT
Parts (type 1)
To place a part or submodel in an LDraw environment, you must enter a line like the following
- 1cxyzRxxRxyRxzRyxRyyRyzRzxRzyRzzFILENAME.DAT/LDR
Lines (type 2)
Lines are specified by
- 2cx1y1z1x2y2z2
Triangles (type 3)
Triangles are specified by
- 3cx1y1z1x2y2z2x3y3z3
Quads (type 4)
Quadrilaterals are specified by
- 4cx1y1z1x2y2z2x3y3z3x4y4z4
Optional lines (type 5)
Optional lines are lines that will only be drawn under certain circumstances. They are specified by
- 5cx1y1z1x2y2z2x3y3z3x4y4z4
All LDraw format models use only these basic commands.
Note the coolness of types 2, 3 and 4! They correspond to the number of defining points used (so does type 1, since there is a placement at a point... but you also need to specify a rotation matrix in that case)!
LDraw Colors
LDraw colors are specified by a number. Examples:
| #0: Black | #16: Main Color | #1: Blue |
A somewhat-complete list of colors can be found at the color table.
MPD extension
The Multi-Part Dat (MPD) extension to the LDraw file format allows a single file to contain multiple dats. The internal files are called in the same way as external files but come first in the order of preference. Each new internal file begins with the line
- 0FILE filename.ldr
This submodel can then be referenced as a type 1 element throught
- 1cXYZRxxRxyRxzRyxRyyRyzRzxRzyRzzfilename.ldr
The MPD file format is very useful for designing models featuring lots of SNOT techniques or sections which are repeated. Most experienced LDraw users use the MPD extension.
Format conversion
As you can see from this article, the LDraw format follows a logical 3d format. So what does this mean to you? If you happen to be a 3d author, for example, you use Bryce to render pictures from 3d models and such. There is one problem, Bryce doesn't and will never support LDraw's format LDR or it's older extension, DAT format. There are quite a few options you can use in order to convert those to other formats that can be used outside LDraw or programs that support LDR format. Anton Raves has created an online converter [1] that makes POV files that's usable in POV-Ray, a free 3d renderer. There are quite a few other formats you can use, however. You could convert them to DXF or OBJ formats using programs LdrDat2Dxf or LdrDat2Obj [2] by Rolf Redford. Or to RIB using l2rib [3]. There are several others at the LDraw homepage.
So, you can have fun rendering your LDraw models in photo realistic rendering programs! Rendered by Pov-Ray, Rendered by Bryce both by Rolf Redford, are just samples on what you can do!
External links
- ldraw.org the central site for ldraw. Responsible for maintenence and storage of the parts library and official extensions and updates for the LDraw format.
- Official LDraw file format hosted at LDraw.org

