Chris Collins

Tools · bricks

LDraw viewer and brick builder

Open LDraw .ldr, .mpd and .dat models in the browser — LDraw colours, edge and conditional lines, step-by-step instructions with the new parts highlighted, submodels, a section plane, parts lists per step with BrickLink XML and CSV — and build simple LEGO-compatible models on the stud grid and save them as .ldr.

Added

Works with

How to use it

LDraw is the open file format and parts library that most LEGO-compatible CAD programs use (LDCad, LeoCAD, Bricksmith, Studio’s importers). A model is a text file: every line places a part — a colour, a position and a 3 × 3 rotation in LDraw units (LDU), and a part file — or draws a line, a triangle or a quad. This page reads those files and draws them, and has a small builder that writes them.

How to use it

  1. Open a model. Pick one of the examples (a little house with its roof as a submodel, a small car, and a Technic gearbox), drop an .ldr, .mpd or .dat file on the view, use Open file…, or paste a URL (the server has to allow cross-origin requests; otherwise download the file and open it). The last model you opened comes back next time.

  2. Look around. Drag to orbit, scroll or pinch to zoom, right-drag or two-finger drag to pan. Edges shows the black outline lines; Conditional lines adds the outlines of curved surfaces (studs, axles, round bricks), drawn only where the surface turns away from you. Section cuts the model with a plane along X, Y or Z — move the slider to slide through it. Screenshot saves a PNG of the view. ⛶ Full screen gives the view the whole window.

  3. Follow the steps. The step bar (or ← and →) moves through the model’s STEP commands. The parts added in this step glow orange; Fade earlier steps makes the rest translucent and This step only hides it. A submodel arrives whole in the step its parent places it; choose it in Model to see its own steps.

  4. Parts list. The table counts parts for this step or the whole model — part number, colour and quantity. BrickLink XML downloads a wanted list to upload on BrickLink (Want → Upload); CSV is the same list for a spreadsheet or Rebrickable.

  5. Build. In the Builder tab pick a part from the palette (bricks, plates, tiles, slopes, windows, wheels, Technic beams, axles, pins and gears) and a colour, then click the baseplate. Parts snap to the stud grid and stack on whatever is under them; R turns the part 90°, +1 plate (or ]) places it higher, Delete mode removes the part you click, and Undo / Redo (⌘/Ctrl Z) step back and forward. The model is kept in this browser. Save .ldr writes it (optionally with a STEP after every part, so the viewer replays the build in the order you placed it), Load .ldr reads one back and View steps opens it in the viewer.

How it works

  • The format. Line type 0 is a comment or meta command (STEP, BFC, FILE/NOFILE, Name:, Author:); 1 places a sub-file with colour, position x y z and the matrix a…i, so a point (u, v, w) of the sub-file lands at (a u + b v + c w + x, d u + e v + f w + y, g u + h v + i w + z); 2 is an edge line; 3 and 4 are triangles and quads; 5 is a conditional line, drawn only when its two control points fall on the same side of it on screen. Transforms are multiplied down the tree of parts, subparts and primitives (a 2 × 4 brick is about 30 files deep in places).

  • Colours come from LDConfig.ldr: code 16 means "the colour of the thing that placed me" and 24 "its edge colour", which is how one brick file can be every colour. Direct colours (0x2RRGGBB) work too. Transparent colours are drawn translucent; chrome and pearl are drawn as plain colours.

  • Winding. Files that declare BFC CERTIFY have consistent triangle winding; it is kept through mirrored matrices and INVERTNEXT. Faces are still drawn double-sided so uncertified parts and section cuts look right.

  • Units. 1 LDU = 0.4 mm. A stud is 20 LDU (8 mm), a plate 8 LDU (3.2 mm) and a brick 24 LDU (9.6 mm). LDraw’s Y axis points down, so "up" is negative Y. A part’s origin is the middle of the top of its body, which is what makes the builder’s snapping simple: a part with an odd number of studs across has its centre on a stud (10 mod 20 LDU), an even number on the line between two; a part resting on the ground has its origin at −height, and on another part at that part’s origin minus its own height. Parts whose body is not centred on the origin (slopes) are shifted by the centre of their bounding box.

  • Parts lists walk the model through its submodels and count each part file and colour once per placement. BrickLink colour numbers differ from LDraw’s; the common ones are mapped (red 4 → 5, light bluish grey 71 → 86 and so on) and anything else is exported with its LDraw code in the remarks. Part numbers are the LDraw file names, which match BrickLink for most plain parts but not all (some moulding variants and assemblies have different numbers there) — check the list before you order.

Where the parts come from

The LDraw library itself (library.ldraw.org) does not send cross-origin headers, so a page on another site cannot load parts from it directly. This tool therefore carries its own parts pack: about 200 common parts with the 685 subparts and primitives they use, packed into one 1.6 MB text file (about 250 KB as the browser downloads it, compressed), built by scripts/ldraw-pack.mjs from the official library. When a model uses a part that is not in the pack, the viewer fetches it — and everything it references — from a mirror of the LDraw library on GitHub (gkjohnson/ldraw-parts-library, a January 2023 snapshot made for three.js examples), served through jsDelivr and pinned to one commit so it cannot change underneath. Untick Fetch parts not in the pack to stay offline; missing parts are then listed and left out of the drawing (they still count in the parts list). Parts newer than the snapshot are not found.

The rendering is three.js (r147) with the parser, the geometry flattening and the conditional-line shader written for this page rather than three.js’s LDrawLoader, so the steps, the highlighting, the parts lists and the builder share one model of the file.

Credits and licence

The part geometry is from the LDraw Parts Library, © the LDraw contributors, used under the Creative Commons Attribution 2.0 licence — each file names its author, and the agreement and the licence text are at CAreadme.txt and CAlicense.txt. The colour table is LDConfig.ldr from LDraw.org. LDraw is a trademark of LDraw.org; see ldraw.org for the library, the file format specification and the programs that use it. The example models are original simple builds made for this page, not official set models.

LEGO® is a trademark of the LEGO Group, which does not sponsor, authorise or endorse this site. LDraw is an independent, community-made library of LEGO-compatible part models. This tool uses no LEGO logos; the studs are drawn plain.

Runs entirely in your browser; nothing you type leaves this page.