BrickEngineer: LEGO Design

LEGO Engineering for LEGO NXT and Robot Enthusiasts

LEGO Rendering Tutorial: The Basics


This is the first in a series of installments that describe how to render high-quality 3D images of your LEGO creations.  You will need the following free software:

  • LDraw
  • MLCad
  • L3P
  • POV-Ray v3.6

which can be downloaded with the LDraw All In One Installer

In this tutorial, we will be aiming for a nice simple still image of three bricks.  In later tutorials, we will animate them.  That will require extra software to put a series of inages together to form a video or an animated gif.  I use Adobe ImageReady to make animated gifs, but there are cheaper solutions.

You can also download all the files we will create here
BE_render_tutorial_1.zip
and follow along.

STEP 1: Create an MLCad file of the scene to be rendered

Open MLCad and prepare to place a few LEGO pieces in the scene.

Step 1.1: Set up a 1×1 brick
On the upper left-hand side, click on Brick.
Drag the 1×1 brick into one of the three viewing panels.
With the brick selected click the RED color button to color it red.
Right-click on the brick and select Enter Pos. + Rot…
Use Position Values
should be checked
Set the X and Z values all to zero and Y to -100 (negative 100)

Step 1.2: Add a 2×4 brick
Following the steps above, find the 2×4 brick in the Brick list (+ will expand the list) and add it to the scene.  Set its color to YELLOW and its position to X=100, Y=-100,  Z=50.

Step 1.3: Add a 2×6 plate
Following the steps above, find the 2×6 plate in the Plate list (you will have to scroll down to the Plate tab) and add it to the scene.  Set its color to BLUE and its position to X=100, Y=-100,  Z=-100.

Be sure that these pieces are all at Y=-100.  The -y direction points upward and this will place them above the Y=0 plane.

Step 1.4: Save your work as part-zoo-1.ldr

The screenshot below shows what you should see at this point on your MLCad screen.

MLCad Screenshot

MLCad Screenshot


STEP 2: Create a POVRay file using L3PAO

Open LP3AO (L3P-Add-on) keeping in mind where you stored your MLCad files.  This figure shows you the basic L3PAO window.

L3PAO Screenshot

L3PAO Screenshot

Step 2.1: In the L3P-Add-on window set the Model File to point to your MLCad file.  To browse, you may need to click on the button labeled …

Step 2.2: In the L3P-Add-on window set the POV-Ray Output File to point to the folder where you want your POV-Ray file to go.  To browse, you may need to click on the button labeled …

Step 2.3: In the middle of the right-hand column is the Quality Level setting.  Set this to 2.  IF you select 3 it prints the LEGO logo on every stud.  If you want this, you may leave it.  But I prefer to remove them.

Step 2.4: At the bottom of the middle column is the Render upon Completion option.  This will launch POV-Ray automatically.  However, if you have problems with the automatic launch, turn this option off and load it manually.  In later tutorials, we will edit the POV-Ray file manually anyway.

Step: 2.5: To start L3PAdd-on click on the Run L3P button in the lower right.  This will create the POV-Ray part-zoo-1.pov file in the directory you specified, and possibly launch POV-Ray depending on the settings you used in Step 2.4 above.

STEP 3: Render the Image with POV-Ray

If you launched POV-Ray automatically, you will already have your image.  Here we assume that you will render it manually.

POV-Ray Screenshot

POV-Ray Screenshot

Step 3.1: Open POV-Ray and in the File Menu, use Open File to open the .pov file that was created by L3pAO.

Step 3.2: Once the file is open, you can simply press the Run button on the upper bar.  This will create a default image, which is a 640×480 .bmp bitmap image.  This is saved automatically in the same folder as your .pov file.  Here it is:

Part-Zoo-1 Default image

Part-Zoo-1 Default image

Note that the LEGO pieces are lifted up above the floor.  This is because we set their y-coordinates to be -100, which is above the floor at zero.  Remember that negative y is up.  We now look to change a few features of our render.

Step 3.3: If you click on the Ini button (to the left of Run above), you will go to a screen that enables you to change the size of the output image.  The Section field on the right has many options that include the resolution of the final image as well as whether Anti-Aliasing (AA) is used.  Try changing the resolution and look at the differences between anti-aliased images and non-anti-aliased images.

Note however, that the output images will always be saved in either .bmp or .png format.  You will have to use another program to convert them to other formats if you are interested.

Step 3.4: You can try playing with the commands in the .pov file.  POV-Ray acts like an editor and you can manually edit your files.  For example, there is a section near the bottom that reads:

// Floor:
object {
plane { y, 24 hollow }
texture {
pigment { color rgb <0.8,0.8,0.8> }
finish { ambient 0.4 diffuse 0.4 }
}
}

This code controls the floor of the image.  If you delete it completely, the floor will disappear as you can see here in this image:

Part-Zoo-1 with No Floor

Part-Zoo-1 with No Floor

Step 3.4: IF you don’t like the black background, look in the .pov file for the Background section:

// Background:
background { color rgb <0,0,0>}

Changing the rgb (red, green, and blue) colors to <0.7, 0.7, 1.0>:

// Background:
background { color rgb <0.7, 0.7, 1.0>}

Will give you an image with no floor and a light blue background:

Part-Zoo-1 with a blue blackground

Part-Zoo-1 with a blue blackground

We have explored making simple cad images in MLCad, generating a .pov file using L3PAO, and rendering a high-quality bitmap image using POV-Ray.   You should read through the .pov file and try to figure out what the different parts do.  You can change their values and re-render the image to see what impact your changes have.  Just remember that POV-Ray saves the changes on top of the original file,  so you may want to make a backup first.

Happy Rendering!

Center of Mass of LEGO NXT Motors

I am working on designing a walking machine, but I needed to know the Center of Mass of the LEGO NXT Motors.  When using Newton’s Laws to compute the forces on the system, we can treat the motor as if all of its mass is located at a single point.  The Center of Mass is the location of this point.

Hanging an NXT motor to find its center of mass.

There are several ways to find the Center of Mass of the motor.  The most straightforward way is to hang the motor from an axle placed in one of the holes.  The motor will orient itself so that the Center of Mass lies directly below the axle.  By hanging a mass on a string from the axle, the Center of Mass must lie somewhere along the line defined by the string. 

The Center of Mass Lies along the line defined by the vertical string

After performing this experiment, I placed a small piece of Scotch tape over the string so that I can keep track of where that line is.  I then cut the string off of the axle.

A piece of Scotch tape holds the string in place

Now to find the precise point, we simply perform the experiment again, but place the axle through a different hole.  This gives us a second line.  Since the Center of Mass must be on both the first line and the second line, it is located at the intersection of these two lines.

The intersection of the two strings indicates the position of the Center of Mass

The Center of Mass is very close to being aligned with the holes on the motor.  Below is an MLCAD image of the NXT motor (from Philo).  I have overlayed a Cartesian coordinate system that corresponds to that used to define the 3-D image file.  The origin of this system is at the center of the axle hole on the motors drive axis.  This is perfect for me since I will be rotating the motor and trying to compute the position of the Center of Mass after the motor has rotated through some arbitrary angle.

The dimesions of the LEGO NXT Motor

This image not only helps with identifying the Center of Mass of the NXT motor, but also in understanding the dimensions of the NXT motor overall.

Kevin Knuth
Albany NY

Matlab Package for LEGO Mindstorms

I recently received a comment on my post on controlling NXT robots with Matlab that pointed me to the RWTH – Mindstorms NXT Toolbox for MATLAB®, which is a public domain Matlab package that enables one to interface with and control LEGO mindstorms.

The RWTH – Mindstorms NXT Toolbox for MATLAB® was developed as a student project in the Institute of Imaging and Computer Vision at RWTH Aachen University in Aachen Germany. It provides a Matlab interface with the NXT brick that includes Bluetooth communication, sensor interface and motor interface. It requires a working Matlab license, of course.

The package is very easy to set up. It took me less than ten minutes to successfully test the example programs over Bluetooth.

There are some very nice motor features, such as motor synchronization and speed ramp-up and ramp-down.

I have yet to explore how easy it is to modify or extend the code, but it ought to be a straightforward matter.

The package can be downloaded from
http://www.mindstorms.rwth-aachen.de

Kevin Knuth
Albany NY

Content Protected Using Blog Protector By: PcDrome.