|
|
|
Home :: Login :: Forgot Password :: Search :: FAQ
|
|
|
|
Published By OrionP on Wednesday, September 24, 2003 - 06:59 PM
Maintained by: The LDraw.org Standards Committee Table of Contents
Purpose Purpose Describing LEGO® bricks and models in a virtual environment is a challenging prospect. In 1995 James Jessiman developed just such a system with his LDraw program and file format. Since then the LDraw file format has grown to be the standard by which most create LEGO® models on the computer. The aim of this document is to compile and consolidate James's original file specification with selected additions made since. LDraw Files
Every line of the file contains one command. With few exceptions, every command is independent of other lines. The exceptions are the BFC meta-commands which modify the behaviour of one or more following command lines. There is no line length restriction. The whitespace characters allowed for keyword and parameter separation include spaces and tabs. Every command starts with a number, called a line type. The function and format of the line is determined by the line type.
The LDraw Co-ordinate System LDraw uses a right-handed co-ordinate system where -Y is "up".
The LDraw Unit (LDU) LDraw parts are measured in LDraw Units (LDU)1 brick width/depth = 20 LDU 1 brick height = 24 LDU 1 plate height = 8 LDU 1 stud diameter = 12 LDU 1 stud height = 4 LDU
Real World Approximations Line Types The line type of a line is the first number on the line. The line types are:
If the line type of the command is invalid, the line is ignored. Line Type 0 Line type 0 has two uses. One use is a comment the other is as a META command. If the first line of a file is a line type 0 the remainder of the line is considered the file title (see Library Header specification). This overrides any META commands on that line.
0 // <comment>0 <comment>Where:
The form
The form META Commands A META command is a statement used to tell an LDraw compatible program to do something. There are currently many official META commands and even more unofficial META commands. In a META command, a keyword follows the line type in the line. The keyword must be in all caps. The generic META line format is:
Where:
For a list of official META commands, see the META commands section. Line Type 1 Line type 1 is a sub-file reference. The generic format is:
Where:
Line type 1 should never use the colour 24. Sub-files can be located in the LDRAW\PARTS sub-directory, the LDRAW\P sub-directory, the LDRAW\MODELS sub-directory, the current file�s directory, a path relative to one of these directories, or a full path may be specified. Sub-parts are typically stored in the LDRAW\PARTS\S sub-directory and so are referenced as s\subpart.dat, while hi-res primitives are stored in the LDRAW\P\48 sub-directory and so referenced as 48\hires.dat While there is no specified limit on how deep sub-files may be nested, there are probably practical limitations imposed by individual software programs. There are many on-line references about transformation matrices, one such reference is The POV-RAY Matrix Page Line Type 2 Line type 2 is a line drawn between two points. The generic format is:
Where:
Line type 2 (and also 5) is typically used to edge parts. When used in this manner colour 24 must be used for the line. Line type 2 can also be used to represent fine detail in patterns (cf some torso patterns) and when used in this manner any colour may be used for the line. In either case it should be remembered that not all renderers display line types 2 and 5 Line Type 3 Line type 3 is a filled triangle drawn between three points. The generic format is:
Where:
See also the comments about polygons at the end of the Line Type 4 section. Line Type 4 Line type 4 is a filled quadrilateral (also known as a "quad") drawn between four points. The generic format is:
Where:
While no specific order (winding) is required, the points of the quadrilateral must be declared in either a clockwise (CW) or counter-clockwise (CCW) order (see BFC statements). The "good" example exhibits clockwise winding. If the points were given in the order 1, 4, 3, 2, they would exhibit counter-clockwise winding and also be considered as "good". The "bad" example illustrates a "bow-tie" or "hour-glass" quad.
The four points must lie within a plane. Quads should not contain three co-linear points (they should be reduced to a triangle). Quads must not be concave (two or more other polygons must be used instead). Co-planar polygons (line types 3 and 4) may overlap only if they are the same colour. Any such overlap must be kept to a minimum as it affects the render quality of transparent parts. Polygons may intersect, but any such intersection must be kept to a minimum as it affects the render quality of transparent parts.
Where possible, abutting polygons should share common verticies. That is, if polygons ABCD and EGF
abut along the line AEFB, A and E should be the same point and F and B should be the same point.
[If A and E are the same point but F and B are not the same point, the pixel approximations of
lines A'B' and A'F' (where A' represents the pixel point of A - which will be subject to integer
truncation) may not be the same along the length A'F'. This will result in holes being visible in the
part, especially at high magnification/resolution, and is the primary cause of "dot creep" when
rotating parts.]
Where practical, if A and E (and/or F and B) are not the same point, one or other or both of the polygons
should be decomposed into two or more smaller polygons such that they share common verticies.
In the diagram, ABCD has been decomposed into the quad AFCD and the tri FBC
It is strongly recommended that polygons do not use colour 24 (the complement colour).(The rendition of a colour 24 polygon in a main file is implementation dependant (and may not be rendered at all), while the rendition of a colour 24 polygon in a sub-file is configurable, and so may not give the expected results in all situations/renderers.) Line Type 5 Line type 5 is an optional line. The generic format is:
Where:
With an optional line, a line between the first two points will only be drawn if the projections of the last two points (the control points) onto the screen are on the same side of an imaginary line through the projections of the first two points onto the screen. The optional line can be a difficult concept to grasp. The best way to demonstrate how they work is through a picture.
5 24 Bx By Bz Ex Ey Ez Ax Ay Az Cx Cy Cz See also the colour comments at the end of the Line Type 2 section. Colours
The official colours are defined via Colour Definition statements in the ldconfig.ldr file The colour numbers 16 and 24 are reserved and must not be used in Colour Definition statements. Colour 16
Colour 16 is referred to as the "main colour" or "current colour". When a sub-file is referenced
by another file all the colour 16 command lines are displayed using the colour of the line that
referenced it. Colour 24
Colour 24 is referred to as the "complement colour" or "edge colour". Colour 24 is most commonly
used for line types 2 (line) and 5 (optional line). When a sub-file is referenced by another file
all the colour 24 command lines are displayed using the complement colour of the line that referenced
it. The complement colour of a given colour is defined in the Colour Definition for that colour. Use of colour 24 for line types other than 2 and 5 is strongly discouraged.
See the LDraw Colour Chart for a complete list of the LDraw
colour number equivalents to the official LEGO colours. Direct Colours Direct Colours are colour numbers that represent RGB values using the form 0x2RRGGBB, where RRGGBB is the exact RGB value in hexadecimal notation. For example, 0x2008000 would produce dark green with RGB of (0 red, 128 green, 0 blue). All letters (A-F) used in the specification of RGB values must be in upper case. LDraw compatible visualization applications shall be capable of displaying Direct RGB Values from Patterned Parts that contain these colours. For applications that support part authoring, it is recommended that the program provide a graphical aid for choosing a Direct RGB Value. The use of Direct RGB Values is discouraged in model authoring. Therefore, applications that support model authoring should favour colours from LDConfig.ldr. Blended Colours LDraw compatible visualization applications that once supported dithered colours should continue to do so in the display of parts and models that may contain a dithered colour code. However, dithered colours have been made obsolete and will not be contained within any new official parts. These colours should be removed from any graphical aids for choosing colours, and should not be added to any new graphical aids for choosing colours. New applications are not required to support these colours. These "dithered" colours are defined based on a modification of ldraw.exe's original behavior that uses RGB blending instead of dithering. The original ldraw.exe drew them as a 50/50 checkerboard dither of two of its standard 16 colours. Since modern computers all support true colour, they will instead be drawn as a blend of the two input colors, which is calculated as the average of two original ldraw.exe colours. The two input colour indexes are calculated as follows:
n1 = (nb - 256) / 16 where n1 is the index of input colour 1, nb is the index of the blended color, and n2 is the index of input colour 2. Once n1 and n2 are determined, the colour of the blended colour is calculated using the following equations:
Rb = (R1 + R2) / 2 where Rb, Gb, Bb are the red, green, and blue components of the blended colour; R1, G1, B1 are the red, green, and blue components of the first input colour; and R2, G2, B2 are the red, green, and blue components of the second input colour. The red, green, and blue components of the original 16 ldraw.exe colours are as follows:
0: 51, 51, 51 Going the other direction, the blended colour's colour code is calculated using the following equation: nb = n1 * 16 + n2 + 256 where nb is the index of the blended colour, n1 is the index of the first input colour, and n2 is the index of the second input colour. META Commands Meta commands (or meta statements) are a powerful way to extend the File Format Specification to enable the inclusion of meta data (such as author name, keywords, category, etc) and processing instructions (such as step, bfc, etc) within the data file. (See also List of Official META Commands) For historical reasons, the original meta commands are defined as part of the file format specification, while others are defined in seperate language extension documents. Header Statements See the Official Library Header Specification Step Marks the end of a building step
0 STEP
The Step command causes the original LDraw program to pause
until the Enter key is pressed.
Additionally a bitmap of the currently displayed parts in the model is saved to the
LDRAW\BITMAP directory. Therefore, for the original LDraw program, Other programs may interpret this META command differently. Write/Print Displays a message
0 WRITE <message>0 PRINT <message>
The Write or Print commands cause the original LDraw program to display a message to the screen. This message is not saved on any bitmaps. Other programs may interpret this META command differently. Clear Clears the screen
0 CLEARThis command causes all previous drawn sub-files and line types to be cleared (erased). Any following line types are drawn as normal. Pause Pauses the drawing of a file
0 PAUSEThis command stops the further parsing of lines until the Enter key is pressed. Unlike the Step command, Pause does not save a bitmap of the currently displayed model to the LDRAW\BITMAP directory. Save Saves a bitmap of the current drawing
0 SAVESaves a bitmap of the current drawing in the LDRAW\BITMAP directory. Unlike the Step command, this command does not cause the program to pause. File Type Indicates the type of file (model, part, etc), and if it is part of the LDraw.org Parts Library.
0 !LDRAW_ORG <type> (qualifier(s)) (update-tag)0 LDRAW_ORG <type> update-tag0 Official LCAD <type> update-tag0 Unofficial <type>0 Un-official <type>
The first format (
* = values currently in use for official part files. Some older official files do not include a type code on their File Type line. Unofficial files may have a variety of values after the initial tag. The exact format of the File Type line has changed over time. In general, parsers should consider this line to be case-insensitive and free-format. CATEGORY and KEYWORDS Statements See the CATEGORY and KEYWORDS Language Extension MPD Statements See the MPD Language Extension BFC Statements See the LDraw Language Extension for Back Face Culling (BFC) Unofficial META Commands See the list of known META commands and the programs that use themAdding New META Commands The following guidelines should be followed by developers when adding new META command functionality to their LDraw.org compatible programs:
Note: This document is an offical LSC specification and/or language extension. Material changes can only be made after ratification by the LSC. Ratified 2007-09-23
Updated 2011-03-30: Added text encoding. Updated 2011-07-26: Travis Cobbs fixed UTF-8 character set problems. Updated 2011-12-02: Removed discouragement of spaces in filenames. |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|



