LDraw file format

From Brickwiki
Jump to: navigation, search

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.

  1. 0This is a comment

They can also be used for meta commands for other programs, because any program can ignore type 0 lines. For example

  1. 0LPUB ASSEM PLACEMENT BOTTOM_RIGHT

tells the LPub program to render with assemblies in the bottom right corner of the page.

Parts (type 1)

To place a part or submodel in an LDraw environment, you must enter a line like the following

  1. 1cxyzRxxRxyRxzRyxRyyRyzRzxRzyRzzFILENAME.DAT/LDR

where (x,y,z) specifies the position of the parts/submodels centre and all of the Rab specify a SO(3) rotation matrix to be applied to the model. Basically, each point x in the model is transformed to x' as follows x'=(x,y,z)+R x. The colour c is passed to the part for use in special colours 16 and 24 (see colours section).

Lines (type 2)

Lines are specified by

  1. 2cx1y1z1x2y2z2

where the line runs from (x1,y1,z1) to (x2,y2,z2) and takes colour c.

Triangles (type 3)

Triangles are specified by

  1. 3cx1y1z1x2y2z2x3y3z3

where the edges of the triangle are (x1,y1,z1) to (x2,y2,z2), (x2,y2,z2) to (x3,y3,z3) and (x3,y3,z3) to (x1,y1,z2). They are filled in colour c.

Quads (type 4)

Quadrilaterals are specified by

  1. 4cx1y1z1x2y2z2x3y3z3x4y4z4

where the (xn,yn,zn) points specify the four corners of the quad. Like triangles they are filled in colour c

Optional lines (type 5)

Optional lines are lines that will only be drawn under certain circumstances. They are specified by

  1. 5cx1y1z1x2y2z2x3y3z3x4y4z4

and can be understood by looking here.

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

  1. 0FILE filename.ldr

which is usually preceded by at least one blank comment line.

This submodel can then be referenced as a type 1 element throught

  1. 1cXYZRxxRxyRxzRyxRyyRyzRzxRzyRzzfilename.ldr

and manipulated accordingally.

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 its 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


Personal tools