LDraw is a system of freeware tools for modeling Lego creations in 3D on a computer. The LDraw file format and original program were written by James Jessiman, although the file format has since evolved and extended. He also modeled many of the original parts in the parts library, which is under continuous maintenance and extension by the LDraw community. Following Jessiman's death in 1997, a variety of programs have been written that use the LDraw parts library, and file format. LDraw models are frequently rendered in POV-Ray or Blender, free 3D ray tracers.
File format
The LDraw format can divide a model into steps so that the building instructions can be incorporated into the design, and also allows for steps that rotate the camera and even move parts around in an elementary fashion. It also allows for models to be incorporated in the construction of larger models to make design easier. This also makes the file format space efficient: instead of specifying the polygons of every single stud of a specific brick for example, a shared stud file is included multiple times with transformation applied. Parts, models, sub-models and polygons are all treated the same and are not specific to Lego models. The format could be used to store any type of 3D model. Some have created bricks of other building systems for use with LDraw. The following main three filename extensions are used by LDraw:
files implementing a part, subpart or primitive use .dat
a Lego model consisting of 1 or more bricks use .ldr
multiple .ldr files can be aggregated into files of type .mpd
The file format uses plain text data, and uses the charset UTF-8 without BOM.
Example File: 3003.dat, the Implementation of a 2 x 2 Brick
The above code defines the basic 2×2 brick. It consists of a five-sided box and an inverted five-sided box, the connection between those two, consisting of four quads, the four studs on top of it and the long hollow stud in the inside. All lines in an LDraw file are either empty or start with a command number, where 0 means no command. The command 1 for example includes a subfile. It specifies the file's path and a transformation matrix that should be applied to it, as well as its color. Command 4 specifies a four-sided polygon. There are also commands that define 2D lines. Such lines give the parts a clear contour even in non-shaded orthographic renderings.
Example File: pyramid.ldr, a Lego Model of a Pyramid
The Lego set and parts database hosted at the website peeron.com lists parts available as 3D CAD models in the LDraw parts library, with correctly colored images rendered from these models. The Peeron and LDraw teams work together to clarify unclear part numbers, colors and names, sometimes using information provided by The Lego Group.