juraj3579

Creating renders using LDraw and Blender

Recommended Posts

Hello everybody,

so here is a short tutorial of creating renders in Blender using Cycles - be sure you switch to Cycles, when you one new file in Blender! I used a simple 6611 Town Set as example.

1. create model (SR 3D Builder, MLCad, etc.):

- I prefer SR 3D Builder. I like the connection function, which makes the aligning of the bricks easy and the workflow is really fun.

2. export the model to lwo (Lightwave object):

- This is where I struggled a lot. There are some scripts, which imports ldraw files direct in Blender, but none of them works for me really. Then, I tried import obj files, which works quite good, however the mesh topology was bad and the logo on the studs was missing. Later I discovered the Lightwave exporter, which is available for download on the LDraw Webpage (LDraw2Lws). It has the possibility to replace ldraw parts with pre-created ones (in Lightwave format), which is really good feature, especially for the studs (they are available by default).

If you want use this exporter, read the readme file and be sure, to set the library paths correct. It uses *.dat file format, but you can open .l3b file directly.

8878326723_80a951af99_z.jpg

3. import lwo objects to blender:

- The exporter creates a folder with all parts in lwo format in same directory as your model file. Blender can import them, however only one by one, which can be quite time consuming. So I modified the import script, that all the objects from the folder are imported at once.

- I use a simple studio setup in blender (there are a lot of tutorials, how to do it in Blender or just download some free blend files available) and import model to the separate layer in it.

A. modified import script

copy and overwrite the default lightwave import script in "your blender install path"\"blender version"\scripts\addons (Example: d:\Program Files\Blender Foundation\Blender\2.66\scripts\addons\) with the downloaded(See end of the post)

Usage:

1. enable replaced addon (make a backup of the old one :-) ) in the blender user preferences

2. use file->import-> Lightwave (lwo) then select the directory with the parts (created with lw2ldraw application), select one file and click import -> all files from the directory will be imported (it could take some time, depending on the count of the parts)

3. you should see your imported model in blender

Basically it just do the import of the parts in a loop for all the files in the directory

8878944578_3e79f948a9_z.jpg 8878944574_bde393bf69_z.jpg

4. working in blender:

A. lego tools script

A.1 download and save the Lego Tools script file on your pc. Also download the material library file.

A.2 open the script file with notepad or similar and on the line 23 set the correct path to the downloaded material library file (mine is "E:\Privat\Lego"). Save the file.

8878944962_13fc200668_z.jpg

A.3 add the script in blender as any other addon. Go to user preferences in blender select addons -> install from file. Then search for lego tools and enable it by clicking on the checkbox

8878326863_771fc08672_z.jpg

A.4 on the left panel (show/hide with T) in the main blender window you should see menu item "Lego Tools" with the operators (Mesh Tools, Material Tools)

8878944652_b718af8a91_z.jpg

B. mesh correction

- after import, the mesh looks not really pleasing. You need to recalculate the normals and also remove double vertices. Also, the 90 degree edges are too smooth now. The Edgesplit modifier solves this problem.

You can do the mesh operations only in edit mode, so this could be pretty time consuming again (selecting one object after another). So I wrote own add-on, which did the corrections on current selected objects with one click.

Mesh Tools:

you can select your imported model or portion of it and use the operators. Be carefull with selection. The script runs on all selected object with type of MESH.

I use the operators in the same sequence as the buttons order. It's again just batch operation over all of the selected objects

8878326921_3009fce3d1_z.jpg

C. materials

- imported model has just simple diffuse shader material. The materials are named "Surface xxx" where xxx is the number of lego color. Because of import, Blender creates always new instance for the same material (eg. "Surface 0.001, Surface 0.002" and so on).

My plan was to auto-replace the materials with one from the lego material library for cycles, which I found on web. So the scripting again. First merge the materials, so it's always just one instance of the same material assigned to objects and then replace the materials with the

better ones from the library. Again, works only on selected objects.

Material Tools:

to replace the materials which came with the import with the better ones from a library file (found on web) just select the objects, then click merge and then autoreplace.

The operator appends the library file (see A.1+A.2), and replaces the materials using a dictionary (in the script file from line 26). Not all colors are implemented yet!

8878326981_1af7dd1a90_z.jpg

5. finish

- after all, I play a little bit with the lightning, position of camera and so on. Then render the model. Actually, you can do a lot of stuff later with compositor. I didn't use it till now, but it's on my "blender study plan", as it allows you to bring more realism to the finished picture.

8878944860_07ecd5f2f3_z.jpg 8878774023_89530a1313_z.jpg

So that's it. Maybe it looks a little bit complex, but in Blender it's actually only selecting the model and then 5 clicks to finish it. So, not big deal. Maybe the more time consuming part is to finish light and camera setup and rendering.

Feel free to try it yourself. Feedback and ideas for improvement are most welcome.

Edit 29.05.2013:

Here are the links for the python scripts which I'm using in Blender. They were tested with the version 2.66

Import script:

https://www.dropbox.com/s/q3hapud497xvktv/io_import_scene_lwo.py

Lego Tools ver 1.0:

- EDIT: I just realized, that make seam operator doesn't work properly Temporarily removed from operators panel

https://www.dropbox....ools_ver_1_0.py

Material Library:

https://www.dropbox....ls_cycles.blend

Next plans:

my next topics (except building models) are to extend the color dictionary with more lego colors, try to create separate material for the slopes with the rough surface to push the renders more to reality and play with various ligthbox setups (I'll probably leave my space setup :-) and concentrate more on studio renders)

Known bugs:

LDraw2Lws can't export the space crater plate correct (which is bad, because I have 2 Space Classic sets build already)

Edited by juraj3579

Share this post


Link to post
Share on other sites

If somebody is interested, I can upload the scripts, so you can try it yourself and maybe give me a feedback, if something is missing or not working well or if somebody has more ideas.

Yes please. :grin: I can't wait to start playing around with it.

Also, a question. Assuming you already have the model done in MLCad, SR 3D, etc., how long does it take from import to completed render? On average, as there are a lot of mitigating factors, obviously.

I'm trying to get a feel for render times relative to POV-Ray, if that's possible.

Share this post


Link to post
Share on other sites

Thanks Juraj3579 :thumbup:

I've tried rendering LDraw models using Blender a long time ago.... It wasn't succesful at all, but probably because I had very few knowledge of LDraw and Blender :grin:

Btw, I've made a topic for this, since it's not very useful if it's somewhere in the LDraw models topic.

Share this post


Link to post
Share on other sites

Thanks Juraj3579 :thumbup:

I've tried rendering LDraw models using Blender a long time ago.... It wasn't succesful at all, but probably because I had very few knowledge of LDraw and Blender :grin:

Btw, I've made a topic for this, since it's not very useful if it's somewhere in the LDraw models topic.

Yes, the separate topic is much better :thumbup:, so we don't mix it with the models and can better follow the changes and ideas, which will hopefully come.

I'm still on cleaning the script to make it publishable :blush: and I also added new feature for creating the seam between the parts automatically. I'll publish it in the end of the week.

Edited by juraj3579

Share this post


Link to post
Share on other sites

Is the guide completed?

I see there are not images, some image could help, expecially inexperienced users.

Inform me if/when the guide is complete, so I'll index it.

Share this post


Link to post
Share on other sites

Is the guide completed?

I see there are not images, some image could help, expecially inexperienced users.

Inform me if/when the guide is complete, so I'll index it.

I've updated the whole guide and added some images. I think it's ready for indexing :wink:

Share this post


Link to post
Share on other sites

Very nice guide, hope I can get my hands on a windows machine so I can experiment. I tried some alternatives on my mac to import LDraw into Blender but they didn't work out.

Share this post


Link to post
Share on other sites

Brilliant work! Ive seen your Flickr page too... very nice. I personally love the 'glossy'ness of the brick surfaces.

I must learn blender a bit more i feel... all renders are coming out very noisy/spekled.

Been trying to replicate your simple studio setup (image above the fireman). Are the black boxes some type of lighting?

Keep up the good work...

Share this post


Link to post
Share on other sites

How does the converter handle the model hierarchy? For instance, a model that has multiple sub-models. Or an MPD file. Or in my case a model that has multiple sub-models that are themselves MPD files.

[edit]

Okay, I just tested ldraw2lws and it does not seem to support MPD files. :(

[edit]

LDR Importer doesn't support MPD files either. Are there any Blender importers that do?

Edited by Dilvish

Share this post


Link to post
Share on other sites

How does the converter handle the model hierarchy? For instance, a model that has multiple sub-models. Or an MPD file. Or in my case a model that has multiple sub-models that are themselves MPD files.

[edit]

Okay, I just tested ldraw2lws and it does not seem to support MPD files. :(

[edit]

LDR Importer doesn't support MPD files either. Are there any Blender importers that do?

Hi,

you can open your mpd in mlcad and export the submodels (file->export). It will export all submodels as separate files where the main file contains all the submodels. Then, you need import only this file to blender using ldr importer. This worked well for smaller models.

For bigger, complicated models:

Open the mpd (make a copy of original) in LDCad and in main model: select all->reorganize->inline submodel(s). If you have submodels with submodels, you have to do it also for submodels and then in main model. Save the model. Open in mlcad, go to Multipart->Export Models, then again, you need to import just main file to blender.

Share this post


Link to post
Share on other sites
Open the mpd (make a copy of original) in LDCad and in main model: select all->reorganize->inline submodel(s). If you have submodels with submodels, you have to do it also for submodels and then in main model. Save the model. Open in mlcad, go to Multipart->Export Models, then again, you need to import just main file to blender.

You could also open the top level file, put it in nested mode then select all and copy it to the clipboard (if asked don't let it move the main line or compensate for positional/rotational data etc).

After that you can paste it in e.g. notepad and it will be all flat resulting in a single ldr no matter how many files / levels the original uses. You need to do this in LDCad 1.4b though as it's kinda broken in the 1.5 alpha's.

Share this post


Link to post
Share on other sites

Hi Juraj, I really like you guide it saves a lot of work but by any chance have you updated your Lego Tool script or could you maybe tell me what to edit in the script? I am asking because I was using it successfully till blender ver. 2.69 but from 2.70 and upwards it dose not work, to be more precise the Auto Replace tab gives me this report error:

report%20error.png

I know that I can install blender 2.69, import the model, save and then install 2.76 (the version which I am using now) but it is kind of annoying.

Your help would be much appreciated :grin:

Share this post


Link to post
Share on other sites

Hi Juraj, I really like you guide it saves a lot of work but by any chance have you updated your Lego Tool script or could you maybe tell me what to edit in the script? I am asking because I was using it successfully till blender ver. 2.69 but from 2.70 and upwards it dose not work, to be more precise the Auto Replace tab gives me this report error:

I know that I can install blender 2.69, import the model, save and then install 2.76 (the version which I am using now) but it is kind of annoying.

Your help would be much appreciated :grin:

Hi, I'm glad you like it. However, this approach comes from "dark ages" of importing (trying to import) LDraw models to Blender and is pretty nasty :blush: . Nowdays, the ldr-importer is surely better choise as it works quite good and is also well supported.

If you really want, I can look at the script, but it will take some time, because a lot of things changed in Blender since 2.69.

Edited by juraj3579

Share this post


Link to post
Share on other sites

Thx for the quick replay :sweet: , I am using Ldr importer as well, the thing is it dose not have that neat feature of auto replacing materials so there is quite some work when you have big technic model.

Anyway for now I will stick with my method of switching between 2.69 and 2.76 - it is still faster then selecting parts and creating/ tweaking materials for them :laugh:.

Nowadays everyone is busy so please do not waste time for me :sweet:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.