Jump to content


Creating renders using LDraw and Blender


  • Please log in to reply
8 replies to this topic

#1 juraj3579

juraj3579

    Posts: 117
    Joined: 10-July 12
    Member: 29634
    Country: Slovakia

Posted 07 May 2013 - 03:39 PM

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.


Posted Image


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


Posted Image      Posted Image  



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.


Posted Image


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


Posted Image


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)



Posted Image






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



Posted Image


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!



Posted Image


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.


Posted Image           Posted Image



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....rt_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, 29 May 2013 - 03:54 PM.

| Contest Winner:  Posted Image    | My Flickr: Posted Image

#2 Walter Kovacs

Walter Kovacs

  • Tooting his own horn


    Posts: 2034
    Joined: 05-May 08
    Member: 3106
    Country: USA

Posted 07 May 2013 - 03:59 PM

View Postjuraj3579, on 07 May 2013 - 03:39 PM, said:

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.
Mafia results - Won: Eurodina (Scum), Werewolf (Town), The Forest (Town), Eurobricks Mafia 2 (Town), Mafia Mafia (Town)
Lost: Dr Bloodbrick's Asylum (Town), Harriet Slutter and the Philosopher's Balls (Town), Party Lines (Town)
Hosted: Unrest in the Forest, won by the Maples (Scum) and the Serial Killer.

Currently Cosplaying as the Flash in def's Cosplay II - Pelly's Paradise Mafia

#3 legolijntje

legolijntje

    Posts: 2246
    Joined: 06-June 10
    Member: 11214
    Country: The Netherlands

Posted 07 May 2013 - 09:21 PM

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.

#4 juraj3579

juraj3579

    Posts: 117
    Joined: 10-July 12
    Member: 29634
    Country: Slovakia

Posted 08 May 2013 - 10:14 AM

View Postlegolijntje, on 07 May 2013 - 09:21 PM, said:

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, 08 May 2013 - 10:14 AM.

| Contest Winner:  Posted Image    | My Flickr: Posted Image

#5 Calabar

Calabar

    Posts: 2361
    Joined: 11-April 10
    Member: 10232
    Country: Italy

Posted 24 May 2013 - 04:02 PM

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.
"Official LEGO Sets made in LDD" topic: Read guidelines before posting!

#6 juraj3579

juraj3579

    Posts: 117
    Joined: 10-July 12
    Member: 29634
    Country: Slovakia

Posted 29 May 2013 - 03:58 PM

View PostCalabar, on 24 May 2013 - 04:02 PM, said:

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:
| Contest Winner:  Posted Image    | My Flickr: Posted Image

#7 Calabar

Calabar

    Posts: 2361
    Joined: 11-April 10
    Member: 10232
    Country: Italy

Posted 29 May 2013 - 04:40 PM

Indexed!
Thanks. :wink:
"Official LEGO Sets made in LDD" topic: Read guidelines before posting!

#8 lego2lego

lego2lego

    Posts: 172
    Joined: 07-February 13
    Member: 39242
    Country: Netherlands

Posted 29 May 2013 - 05:51 PM

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.
My Flickr

#9 Dadda-the-hutt

Dadda-the-hutt

    Posts: 2
    Joined: 22-June 13
    Member: 64369

Posted 24 June 2013 - 05:58 PM

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...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users