I was asked to put together a tutorial on rendering LDraw-produced models in POV-Ray in as clear and simple a way as possible. Although the following might seem a bit lengthy, I have tried to keep it clear, which is what caused it require a lot of explanation. I plan on updating things and changing things as time goes on and as people give me their input, so as to create a useful guide for everyone here on Eurobricks.
NOTE: To give an idea of how long these images can take to render, I will be adding the render time of each image to the tutorial. As I don't rely on POV-Ray's anti-aliasing, I have rendered each image at 2880x1620 with AA set to off, and then crop and resize the image afterwards.
For computer spec comparisons, I use an Intel Core i5 running at 2.67 GHz, with 4GB of RAM running at 1333 MHz and an NVIDIA GeForce GTX 460 with 1GB of RAM. I'm also using POV-Ray 3.7, which can take advantage of more than one CPU core.
MLCad (including LSynth and SR 3D Builder)
Setting up POV-Ray
Rendering your model in POV-Ray (including lighting and effects)
Unlike LEGO’s own Digital Designer (LDD), which can currently only output an image of exactly what you can see within the LDD window, LEGO models created using LDraw can be turned into high-quality and, in some cases, photo-realistic images.
This brief tutorial covers some of the basics of converting files created in LDraw and other compatible programs into something that looks almost real.
As an example throughout this guide, I will be using a model I made in MLCad of the tipper from 4201 Loader and Tipper, which can be found here.
Regarding operating system, I currently use Windows 7, so this tutorial will be written to mainly accommodate Windows users, and I shall assume you are using a 32-bit version of Windows with the default installation path for LDraw.
For anyone using a 64-bit version, when referencing folder paths please use “C:\Program Files (x86)” instead of “C:\Program Files”.
Firstly, if you do not have it installed already, you need to install the LDraw All-In-One Installer, which contains the following programs required for this tutorial:
The LDraw parts library
MLCad, used for building the models
LSynth [optional], a system for building flexible parts within MLCad
LDView, used for converting models into a POV-Ray file
LGEO, a parts library built specifically for POV-Ray
POV-Ray, a ray-tracer that can render 3D models in high-quality
You can find the installer here: http://www.ldraw.org/
This will install everything within the "C:\Program Files\LDRAW" folder, although POV-Ray will get its own installation folder.
More information on this installer can be found at http://www.holly-woo...w/aioi1-en.html
At the moment, the installer seems to install POV-Ray 3.6, but if you're using a computer with multiple CPUs then it would be worth downloading and installing beta version 3.7, as this can make use of more than one CPU. This can be downloaded from http://www.povray.org/beta/ and is installed in the Program Files folder, but installs the "ini" and "include" files in your My Documents folder.
Although it's still in beta, I've had no issues when using this to render images.
MLCad is a user-interface for the LDraw system, and makes it easier to create virtual LEGO models than hand-coding the location of each piece. It’s not as straight-forward to use as LEGO Digital Designer, but the parts list contains a greater number of “older” pieces, you ultimately have complete control over brick placement as LDD-style collision is ignored, and (if you’re feeling adventurous) you can even recreate LEGO elements yourself, if they have not been created already, and submit them to the LDraw parts lists. It is missing a number of more recent parts, but new elements are always being submitted and can be downloaded and installed fairly easily.
There are many excellent tutorials on how to use MLCad, so I won’t cover that here. However, there are a few settings within MLCad that I use that you may find useful.
Firstly, under Settings → General → Change... and then on the Step, Grid, Snap tab, I set the values as below:
The coarse settings are left at MLCad’s default setting.
The medium settings are changed to 1 unit per step, and the rotation angle is set to mimic the rotation of the new-style locking hinge pieces, which can be set at angles of 22.5 degrees. 11.25 degrees gives you slightly more freedom when using the old-style hinge pieces, but the correct angle is easily set for the locking hinges, which can be reproduced in sets of two rotations.
Finally, the fine settings are set very low, so that I can accurately place items that have been rotated. Of course, if you find MLCad’s default settings enough, then they can be left as they are.
I then set up the parts tree to something more useable, under Settings → Parts Tree → Tree Configuration…, although this can be quite time-consuming and if you accidentally reset the tree you cannot easily get the settings back, as the information is stored in your computer's registry.
For ease of use, I have created a group file that automatically adds the values for you, an explanation of which is available in the “Downloads” section.
If this is installed alongside MLCad, it will allow you to render flexible elements, such as hoses, and store these within your LDR and MPD files. It has a bit of a learning curve (pun not intended), but once you’ve got the hang of it, it can really improve models that contain flexible parts.
A modest example of what it can do can be found here in a Technic model that I’ve rendered.
A good guide can also be found at http://www.holly-woo...utorial-en.html
3.2. SR 3D Builder
A lot of people use SR 3D Builder as an alternative to MLCad, as it uses a system that is a little more like LDD. It uses a file format called L3B, which is essentially the LDraw format but with a bit more functionality. These files can also be opened within LDView, but certain special elements created within SR 3D Builder (such as rubber hoses) cannot be displayed using LDView, and therefore cannot be exported to POV-Ray for rendering.
As far as I’m aware, SR 3D Builder does not recognise the LSynth library of parts.
4. Special files
There are a few special files that are installed with the All-In-One installer which need some adjusting before rendering your model in POV-Ray.
LGEO.xml This file contains all of the colour and element definitions for when LDView is exporting a model to the POV-Ray format. The default version is missing some colours, so I have created a more complete version, which can be found in 8. Downloads. Simply replace the default version with this one, and you will have more of LDraw’s colours available to render with. This needs to be saved to “C:\Program Files\LDRAW\LDView”
lg_color.inc This file is installed into LGEO's program folder, in the "lg" sub-folder. It contains definitions to all of the colours of the bricks that POV-Ray uses, as well as information on element finish (transparency, reflection, etc.). The default one does not render accurate LEGO colours, so a replacement for this one can be found in 8. Downloads. This needs to be saved to "C:\Program Files\LDRAW\LGEO\lg"
Once you have completed your model in MLCad, open LDView and locate the model file (either an LDR or MPD file, or L3B is you have used SR 3D Builder). Depending on how good your graphics card is, you should see a representation of your model that looks better than the one shown in MLCad. As LDView also displays the LEGO logo on element studs, you can use this to check to see if they are set to your desired rotation, as this will carry through to the POV-Ray render.
Settings-wise, there is little that needs tweaking here, as it is mainly just for visual effect. However, you can set a better default angle, as LDView’s default is more top-down than the default one in MLCad, and when you export the model to POV-Ray, it will use the angle you currently have your model rotated to.
Select View → Viewing Angles → Specify latitude/longitude, and enter your desired values. As I said, I like the default MLCad 3D angle, so I use latitude 23 and longitude 45, although latitude 30 works well with some long, low models, such as cars.
Click OK and then go back to View → Viewing Angles and then click Save Current as Default. Now, when you open any model within LDView, it will always be initially displayed at this angle.
The model I will be using as it appears within LDView:
Render time: N/A
5.1. Exporting to a .pov file
Now that you have your file open in LDView, click File → Export. This will bring up a dialog box which allows you to specify where you wish to save the exported file. It also has a button called Options..., which allows you to define various parameters. This is where you can set the aspect ratio for your render, and gives you some specific options: 5:4, 4:3, 3:2, 5:3, 16:9 and 2.35:1. I tend to go with 16:9, as that’s the ratio that modern widescreen TVs and monitors tend to use. It’s important that you remember which one you use, as you will need to set up another file in POV-Ray to account for this.
There are a few other options to choose from here, and I use the ones shown below:
Once you’ve chosen your settings, click OK and then from the Export window click Save. This will create a .pov file at your chosen location, using your chosen file name (by default this is the filename of the model you were looking at in LDView).
6. Setting up POV-Ray
6.1. Image resolution presets
The first thing to set up is the file that contains the default resolution presets. If you are using POV-Ray 3.6, this will be located within the “C:\Program Files (x86)\POV-Ray for Windows v3.6\renderer” folder and will be called “quickres.ini”, and this cannot be edited from here, so you may need to copy the file to your desktop first and then open it from there. If you’re using POV-Ray 3.7, this can be edited within the program itself, as it stores it in you user area, so you can just open POV-Ray and select Tools → Edit resolution INI file.
Open this file with a text editor and you should be able to see a list of screen resolutions, listed in this format:
[1280x1024, AA 0.3]
The first line is the name of the preset, and this is displayed in a drop-down box within POV-Ray. The following lines are the actual settings themselves. Copy and paste one of these settings to another location in this file, so we can create a new preset.
You can leave both Antialias and Antialias_Threshold alone, as these are best left at default. If you wish to create an image that matches the aspect ratio set within LDView, this is where you set it. As I prefer to render in 16:9, then I need to make a width and height that matches this. So, for example, an image that is 1280 pixels in width must be 720 pixels in height, so you need to change this for your new preset, resulting in something like this:
[1280x720 16:9, AA 0.3]
I add the 16:9 comment to the preset’s title, just to make it easier to see the ratio.
If you’ve had to edit this from your desktop, then just copy it back to the original location.
6.2. POV-Ray INI file (3.7 only)
This file is the one that contains the paths to the LGEO pieces that POV-Ray utilizes in rendering. If you’re using POV-Ray 3.6 it should already have the right paths in it. However, if you’ve manually installed the POV-Ray 3.7 beta, then it needs to be set up.
Open POV-Ray and go to Tools → Edit master POVRAY.INI, and this should open the file within a text editor. At the bottom of the file, you need to insert three lines to ensure that POV-Ray can locate the right files. These are:
Don’t forget that if you’re using a 64-bit operating system to make sure that the path uses "C:\Program Files (x86)".