Jump to content


Creating renders using LDraw and Blender


  • Please log in to reply
15 replies to this topic

#1 juraj3579

juraj3579

    Posts: 124
    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: 2586
    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: 124
    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: 2528
    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: 124
    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: 2528
    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: 184
    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...

#10 Dilvish

Dilvish

    Posts: 94
    Joined: 28-March 11
    Member: 16912

Posted 08 August 2015 - 12:03 PM

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, 09 August 2015 - 03:49 AM.


#11 TotalyWicked

TotalyWicked

    Posts: 136
    Joined: 07-February 12
    Member: 25823

Posted 11 August 2015 - 06:19 AM

Interesting.
thanks for your guide
I was going to mess around with LeoCad to .3ds to Blender, but then got lazy and never did it.




#12 juraj3579

juraj3579

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

Posted 20 August 2015 - 01:05 PM

View PostDilvish, on 08 August 2015 - 12:03 PM, said:

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

#13 roland

roland

    Posts: 156
    Joined: 19-November 09
    Member: 8251
    Country: Netherlands

Posted 20 August 2015 - 07:09 PM

View Postjuraj3579, on 20 August 2015 - 01:05 PM, said:

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.
My free LDraw editing software: LDCad

#14 kub0slaw

kub0slaw

    Posts: 2
    Joined: 15-March 16
    Member: 156552

Posted 15 March 2016 - 09:56 PM

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:


Posted Image

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:

#15 juraj3579

juraj3579

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

Posted 16 March 2016 - 11:57 AM

View Postkub0slaw, on 15 March 2016 - 09:56 PM, said:

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, 16 March 2016 - 11:59 AM.

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

#16 kub0slaw

kub0slaw

    Posts: 2
    Joined: 15-March 16
    Member: 156552

Posted 16 March 2016 - 08:37 PM

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:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users