Aug 29 2008

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.

My LDraw viewer showing a Lego (LDraw) Forestman

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:

My LDraw viewer showing a sample of bricks, including some that are transparent.

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:

  1. get edge colors working
  2. get optional lines working
  3. count each primitive (line, tri, quad, optline) as a basis before optimizing
  4. examine possibility of using Back Face Culling as defined in the LDraw specs for doing less work in each draw cycle
  5. use one of the Processing camera libraries for moving the view around

We'll see how it progresses...

Comments

Jim

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?
Andy

Andy wrote on 01/11/10 7:32 PM

I know that it is possible to compile Processing code into an applet, but the issue, I think is that there are so many parts and sub-parts files that you need to display a single LDraw model. All of those files would need to be pulled off of a webserver somewhere, I think, which would be huge.

In any case, I have made the source files available for download in a new posting. Enjoy.
-Andy
Jim

Jim wrote on 01/11/10 9:53 PM

Thanks for sharing the code. I just wrote an <a href="http://anoved.net/2010/01/beginning-processing/">enthusiastic post</a> about discovering Processing, so I will certainly check it out.

You're right that the number of part files needed would make a web version impractical. It is possible to "inline" an LDraw file (e.g. using LDraw Designpad), though, thus reducing it to one file made up only of [many] graphics primitives. A renderer could hypothetically display that without access to a part library. Perhaps I'll have to experiment!
BLANKENSHIPLIZZIE31

BLANKENSHIPLIZZIE31 wrote on 03/10/10 1:02 AM

People deserve very good life and <a href="http://lowest-rate-loans.com">loans</a>; or just term loan would make it much better. Because freedom relies on money.

Write your comment



(it will not be displayed)