Washington, DC 2005

Basic Parts Authoring in LDraw
Washington, DC 2005
• Getting started
on the path to
create you own
parts for the
LDraw library
• By Orion
Pobursky
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Why Make Parts?
Washington, DC 2005
• Not all LEGO® parts are modeled in the
official library
• Custom part designs
• Basic CAD objects
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
What do you need?
Washington, DC 2005
• An LDraw compatible 3D viewer
– LDView
– L3Lab
• An LDraw code editor
– LDraw Design Pad (LDDP)
– LDraw Add On (LDAO)
– MLCad
– Notepad
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Part Dimensions
Washington, DC 2005
• LDraw part are
measured in LDraw
Units (LDU)
– 1 brick width/depth = 20
LDU
– 1 brick height = 24 LDU
– 1 stud width = 12 LDU
• Real Life Conversion
– 1 LDU = 1/64 in
– 1 LDU = .397 mm
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Plan Your Process
Washington, DC 2005
• Analyze the Part
– Graph paper helps
• Take Measurements
– Two Techniques
• Comparison to other parts
• Calipers or Ruler
– Generally speaking, features less than 1 LDU
need not be modeled
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
The LDraw File Format
Washington, DC 2005
• All LDraw files are text based
• Every line of the file is one command
• The type of command for each line is
determined by the first number the appears
on each line
• There are 5 different types of commands or
linetypes
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Linetype 0: The Comment
Washington, DC 2005
• Form:
– 0 // <comment>
– <comment> can be any length
• Additionally, Linetype 0 is used for any meta-commands.
These commands essentially tell the LDraw program to
do some non-drawing action. For those with a
programming background, these meta-commands are
essentially like pre-processor directives
• While there a few official meta-commands, there are
many unofficial ones as these are added by program
authors to suit their needs.
• For example, LPub uses many of these custom metacommands to allow the user to dictate page layout.
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Linetype 1: The Subfile
Washington, DC 2005
• Form:
– 1 <color> x y z a b c d e f g h i <file>
•
•
•
•
<color> is the LDraw color number
x y z is the part position
a … I is a standard 3D transformation matrix
<file> is the referenced file
• Most model are completely Linetype 1.
• Also used in part files for primitive and
subpart references
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Washington, DC 2005
Linetypes 2 and 3:
The Line and Triangle
• Linetype 2
x1 y1 z1
– Form:
• 2 <color> x1 y1 z1 x2 y2 z2
– Most linetype 2’s are color 24
(edge color)
x2 y2 z2
x1 y1 z1
• Linetype 3
– Form:
• 3 <color> x1 y1 z1 x2 y2 z2 x2 y2 z2
x2 y2 z2
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
x3 y3 z3
Linetype 4: The Quad
Washington, DC 2005
x1 y1 z1
• Form:
x2 y2 z2
– 4 <color> x1 y1 z1 x2 y2 z2 x2 y2 z2 x4 y4 z4
• Be aware of coordinate order
1
4
Good
2
1
3
3
2
4
Bad
This is what is called a bowtie quad
• Avoid concave quads:
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
x4 y4 z4
x3 y3 z3
Linetype 5: The Optional Line
Washington, DC 2005
• Form:
– 5 <color> x1 y1 z1 x2 y2 z2 x2 y2 z2 x4 y4 z4
•
•
•
•
•
<color> is the LDraw color number
x1 y1 z1 is the position of the 1st point of the line
x2 y2 z2 is the position of the 2nd point of the line
x3 y3 z3 is the position of the 1st control point
x4 y4 z4 is the position of the 2nd control point
• Used to ‘highlight’ the curvature of rounded aspects of the
part
• Since Lintype 5’s are used on surfaces that are rounded,
programs can use them to implement smooth curves.
• Linetype 5 is by far the least understood linetype and is
best explained with an example…
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Washington, DC 2005
•
•
•
Linetype 5: The Optional Line
(cont.)
The LDraw program defines a line
between the first two points. If the
projections of the two control points
onto the screen are on the same side of
the projection of the defined line then
the line is drawn, otherwise it is not
Say we have an optional line from 1 to
the bottom of the cylinder. In this case
the control points should be set at 8
and 2. Since points 8 and 2 are not on
the same side of the line below 1 the
line is not drawn
Now say we have an optional line from
2 to the bottom of the cylinder. In this
case the control points should be set at
1 and 2. Since 1 and 3 are on the same
side of the line below 2 the line is
drawn
8
7
1
2
6
3
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
5
4
Color Definition
Washington, DC 2005
• All colors are represented by a number
• The RGB values and other characteristics of
official colors are defined in a special file in the
LDRAW directory name ldconfig.dat
• Two color numbers (16,24) are reserved for
special functions
• This method of defining colors was recently
adopted and currently LDView is the only widely
used program to implement support
• The legacy method is still the most widely
supported format…
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Legacy Color Definition
Washington, DC 2005
• Color RGB values are hard coded and
defined by a number. There are 16 basic
official colors (0-15)
• Transparent colors are limited to
transparent versions of the solid colors.
(Original Color #) + 32
• Extended colors (256 – 511) are defined by
dithering two of the official colors.
– (Color 1) * 16 + (Color 2) + 256
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Colors 16 and 24
Washington, DC 2005
• Color 16 is defined as ‘Main Color’
– This mean that if the part file is referenced by another file, all the color 16
lines are displayed using the color of the line that referenced it.
– Example:
• 1 4 0 0 0 1 0 0 0 1 0 0 0 1 part.dat
• All the color 16 lines in part.dat will be displayed using color 4 (Red)
– This is what allows one part file to be represented in many different colors
in one model file
• Color 24 is defined as ‘Edge Color’
– This works exactly like color 16, only the display color is the complement
color.
– Using the example above, all the color 24 line will display using the
complement to color 4, color 12 (Light Red)
– The list of complement colors can be found on LDraw.org’s color chart
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Primitives
Washington, DC 2005
• LDraw primitives are shortcut files for commonly
used structures. These are found in the P folder
• Included in this are:
Cylinders
Rings
Disks
Negative Disks
Other specialized primitives such as
peg holes, axle holes, connect pins
are also found in the P folder.
Boxes
Torus
Studs
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Putting it all together
Washington, DC 2005
• Let’s examine the code for a
1x2 brick
• This file has 4 quads, 3 studs,
and 2 references to box5.dat
• Box5 is a primitive found in the
P folder:
• We’ll examine these lines one
group at a time.
1 16 0 4 0 1 0 0 0 -5 0 0 0 1 stud3.dat
1 16 0 24 0 16 0 0 0 -20 0 0 0 6 box5.dat
4 16 20 24 10 16 24 6 -16 24 6 -20 24 10
4 16 -20 24 10 -16 24 6 -16 24 -6 -20 24 -10
4 16 -20 24 -10 -16 24 -6 16 24 -6 20 24 -10
4 16 20 24 -10 16 24 -6 16 24 6 20 24 10
1 16 0 24 0 20 0 0 0 -24 0 0 0 10 box5.dat
1 16 10 0 0 1 0 0 0 1 0 0 0 1 stud.dat
1 16 -10 0 0 1 0 0 0 1 0 0 0 1 stud.dat
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Putting it all together (cont.)
Washington, DC 2005
• The four quads make the bottom:
4 16 20 24 10 16 24 6 -16 24 6 -20 24 10
4 16 -20 24 10 -16 24 6 -16 24 -6 -20 24 -10
4 16 -20 24 -10 -16 24 -6 16 24 -6 20 24 -10
4 16 20 24 -10 16 24 -6 16 24 6 20 24 10
• The first box 5 makes up the inside:
1 16 0 24 0 16 0 0 0 -20 0 0 0 6 box5.dat
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Putting it all together (cont.)
Washington, DC 2005
• The second box5 makes up the outside:
1 16 0 24 0 20 0 0 0 -24 0 0 0 10 box5.dat
• The 2 stud.dat add the top studs and the
stud3 adds the bottom stud:
1 16 10 0 0 1 0 0 0 1 0 0 0 1 stud.dat
1 16 -10 0 0 1 0 0 0 1 0 0 0 1 stud.dat
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
1 16 0 4 0 1 0 0 0 -5 0 0 0 1 stud3.dat
Additional Topics
Washington, DC 2005
• BFC (Back Face Culling) Winding Standard
– File specification originally did not define a
standard polygon winding.
– The BFC standard was introduced to uniformly
wind the polygons in a parts file. This allows
for culling of unseen faces and other functions
tied to winding
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
I’m Done. What Now?
Washington, DC 2005
• Create a model with you part
– Make sure it fits as it should
– Examine you part from all angles and ensure there are no gaps and the
lines are in the position
– Ensure the all the quads/triangle are color 16 and line are color 24 except
those that need to be hard coded a certain color (e.g. patterns)
– Run you part through L3P with the –check option set or use LDDP’s error
check function.
• Submit your work to LDraw.org
• The LDraw.org Contributor Agreement
– Agreement is required if you want to submit your work to LDraw.org for
inclusion in the Official Library
– Basically licenses your part under the Creative Commons Attribution
License
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Additional Topics
Washington, DC 2005
• Additional rules for Official Parts
– Essentially a more stringent set of rules
applied to parts in consideration for the Official
Library.
– Examples include:
•
•
•
•
Proper part file headings
Part numbering and pattern codes
Actions for L3P –check errors
Part Origin requirements
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
BFC
Washington, DC 2005
• BFC (Back Face Culling) Winding Standard
– Most standard 3D rendering engine require uniform
winding of polygons
– The LDraw file specification does not define a standard
polygon winding.
– The BFC standard was introduced to uniformly wind
the polygons in a parts file. This allows for, amongst
other functions, the culling of unseen polygon which
leads to faster rendering times
– While conforming to the BFC standard is not currently
required for Official Library parts, it is highly
encouraged.
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.
Resources and Conclusion
Washington, DC 2005
• Many resources can be found on
LDraw.org.
• These include a primitive reference, color
chart, the LDraw File Specification, and
download link for many utilities.
• Any questions?
BrickFest 2005 is a production of
AMH Events LLC, all rights reserved.