LDraw viewer in Processing
Posted by Andy at 9:56 PM
4 comments - Categories:
Lego | Programming | Processing
One of the great things about the online Adult Lego community is that you can find such a large number of really talented individuals that like to "Play Well" and share their creations. One such sub-community is the people that work on LDraw .org.ᅠThese hard working individuals have built a huge library of 3D Lego part definitions and the software needed to build virtual Lego models in 3D.
The specifications for their part definitions are all online, and they have some great documentation explaining how to use them.
I have always been interested in working with 3D programming, but have never had the time to learn it properly. As it so happens, Processing has some nice simple syntax to allow OpenGL drawing, so I have taken it upon myself to see what I can do. As you can see below, have managed what I would consider a decent start.

In the basic LDraw part definitions, they have Lines, Triangles, Quads, Optional Lines, and SubParts.ᅠI have implemented all except Optional Lines at this point. Optional Lines are used to give correct colored borders to curved pieces only where they are needed.ᅠ As for Colors, I have implemented the basic LDraw colors, but not the complementary colors that are usually used for edging each colored piece, at this time, I'm still using just plain black. Still, I'm pleased that I have made such progress in such a short period of time (just a few days of actual coding).
Processing has also made it easy to put in the various transparent colors, as seen in this example:

Naturally, I didn't actually build the model files with my little program... I used MLCad, which is one of the best tools available for Lego CAD work, even though it hasn't been updated in a few years. I believe that the author started having a family of his own right around the same time that I did.
Where am I going with this tool?ᅠ I really don't know. I'd like to continue to play with it for a while, and see how far I can take it.ᅠ When it gets a little bit more complete,ᅠI would like to release the source code and allow other people to use it for their own projects...
In the meantime, my short to do list is:
- get edge colors working
- get optional lines working
- count each primitive (line, tri, quad, optline) as a basis before optimizing
- examine possibility of using Back Face Culling as defined in the LDraw specs for doing less work in each draw cycle
- use one of the Processing camera libraries for moving the view around
We'll see how it progresses...
Jim wrote on 01/10/10 10:38 PM
This is neat, and makes me want to experiment with Processing, too. I understand that Processing code can be exported as a Java applet. Could this be used to present an LDraw viewer in a web page?