Three official language extensions are written as meta commands: several files in one (MPD), back-face culling (BFC) and texture mapping.
Multi-part documents
An MPD file holds a model and the files it needs, one block after another.
| Line | Meaning |
|---|---|
0 FILE name | Begins an ordinary LDraw file that other lines refer to by name. |
0 !DATA name | Begins a block of embedded binary data, such as a texture picture. |
0 !: base64 | A line of that data. Only these lines of the block count. |
0 NOFILE | Ends a block. Needed only when something other than LDraw content follows; everything is then ignored up to the next FILE or !DATA. |
- Text before the first
FILEor!DATAis discarded; LDraw code there other than comments is an error. - The first block is the main model, and the first line is recommended to be a
FILEline. Other blocks are drawn only if referenced. - There are no rules of scope or name spaces: an embedded
stud.datoverrides the library’s. - A data line holds at most 80 base64 characters (60 bytes). All lines but the last have the same length, a multiple of 4. The
=padding at the end of the last line is optional.
0 FILE main.ldr
1 7 0 0 0 1 0 0 0 1 0 0 0 1 house.ldr
0 FILE house.ldr
1 16 0 0 0 1 0 0 0 1 0 0 0 1 3001.dat
0 NOFILE
0 !DATA sticker.png
0 !: (80 characters of base64)
0 !: (the remainder)
Back-face culling (BFC)
The extension states which way polygons are wound, so a renderer can skip the faces turned away from the viewer. The words are in capitals and case matters.
0 BFC (NOCERTIFY | CERTIFY [CW | CCW])
0 BFC (CW | CCW | CLIP [CW | CCW] | NOCLIP | INVERTNEXT)
CW CLIP and CCW CLIP are also accepted. CERTIFY alone means counter-clockwise.| Option | Meaning |
|---|---|
CERTIFY | The file follows the rules; winding defaults to CCW. |
NOCERTIFY | The file does not follow them; its other BFC lines are ignored. |
CW, CCW | Winding, seen from the front, of the following polygons of this file only. |
CLIP | Culling allowed from here; this is the default. |
NOCLIP | Culling off from here, including in files referenced while it is off. |
INVERTNEXT | Inverts the sub-file on the next line. It must come immediately before a type 1 line (blank lines are permitted but discouraged) and never before a part. |
Certification
- A
BFCline must come before the first operational line, or the file counts asNOCERTIFY. - There is at most one
CERTIFYorNOCERTIFY, ahead of every otherBFCand operational line. Another option before the first operational line also certifies, butCERTIFYis preferred and library files must say it. - A file counts as compliant only if it and every file above it are; parts are the exception on the second point, since they are never inverted.
- Polygons are culled only if the file and every file above it are certified and none of those above turned culling off.
Rendering
- Inversion accumulates down the tree as an on-off value, and is applied by swapping the winding.
- A matrix with a negative determinant mirrors the sub-file, so the expected winding is switched too.
INVERTNEXTacts in addition: on a mirrored reference the two cancel. - The determinant must not be used to guess that a sub-file was meant to be inverted.
- With a degenerate matrix culling is not possible for that sub-file.
- Uncertified models that use polygons or primitives directly must not be assumed correct. Whether culling starts allowed or off is the program’s choice.
- Codes
16and24resolve as usual; aNOCERTIFYor uncertified sub-file is drawn with culling off.
Parts library guidelines
New parts need a BFC line saying whether they comply; new primitives must be
certified. Counter-clockwise winding is preferred, and primitives always use it, with
polygons generally facing outward or upward.
Texture mapping (!TEXMAP)
0 !TEXMAP START method parameters pngfile [GLOSSMAP pngfile]
0 !: geometry shown only with the texture
geometry that is textured
0 !TEXMAP FALLBACK
geometry for programs without texture support
0 !TEXMAP END
0 !: lines as comments and draws what remains.| Line | Meaning |
|---|---|
START | Pushes the current texture and starts a new one. It lasts to END in the same file, the end of the file or a STEP, and stays active in referenced files unless they replace it. |
NEXT | Applies the texture to the next line only, which must be of type 1 to 5. If the next non-blank line is type 0, the NEXT is an error and ignored. |
0 !: line | An LDraw line seen only by programs that support textures. These are not nested. |
FALLBACK | Optional. A supporting program textures everything between START and here and ignores the lines from here to END. |
END | Pops back to the previous texture. It has no effect in a sub-file that had no START of its own. |
Projection methods
| Method and parameters | Geometry of the projection |
|---|---|
PLANAR x1 y1 z1 x2 y2 z2 x3 y3 z3 | Three corners of the picture. U is the distance of a point from the plane through p1 whose normal runs from p1 to p2, divided by the length p1–p2; V is the same with p1 and p3. |
CYLINDRICAL x1 y1 z1 x2 y2 z2 x3 y3 z3 a | p1 is the centre of the bottom, p2 the centre of the top, p3 the point on the bottom edge where the middle of the picture’s lower side touches. The picture spans the angle a, from −a/2 to a/2. U is the angle between p1–p3 and the line from p1 to the point projected on the base plane, divided by a; V is the distance from the base plane divided by the length p1–p2. |
SPHERICAL x1 y1 z1 x2 y2 z2 x3 y3 z3 a b | p1 is the centre, p2 where the middle of the picture touches the sphere, and p3 fixes the plane P1 that halves the picture horizontally; a second plane P2 is perpendicular to P1 and to the picture. The picture spans a horizontally and b vertically, each centred on zero. U is the angle in P1 divided by a, V the angle in P2 divided by b. |
Pictures
- Textures are PNG files; transparency in them lets the colour of the part show through.
- In a gloss map the alpha channel gives the gloss; the colour channels are reserved and ignored.
- A name with spaces goes in double quotes; a quote inside is escaped with
\and a backslash is doubled./is the recommended folder separator, and\and/are interchangeable. - A name is looked for as
textures/nameand thennameon the usual search path, or as an!DATAblock.