Topic: Ldraw and Blender Tips and Tricks

Seems there has been an emergence of CGI animators here in the brickfilming community.  Yay.  But it seems not everyone knows how to use Ldraw, Blender and other user-friendly 3D animation software effectively so here are some things I've come across in honing my skills in 3D animation using Ldraw and Blender.

Settings for modeling
MLCAD
Firstly, install Ldraw.  I set my Ldraw folder under the C drive.
For MLCAD, the parts folder should be under ...\Ldraw\

Be sure to update the Parts and P folder with the latest official and unofficial parts from Ldraw.org.  I usually just download the zip file.

Click on File>Scan Parts to update MLCAD's parts library.

LeoCAD
You should install the latest version of LeoCAD.  I believe it is in a google directory.

To update the parts, you will have to go to File>Pieces Library Manager.  In the Pieces Library Manager, go to File>Import Piece...  You can import multiple pieces at once with the latest verison of LeoCAD on Windows Vista and Windows 7.  Someone has to clarify if they can do the same thing with other OS.

Of these two CAD programs, LeoCAD is usefully for building in 3D but I would advise that you save the project as an ldr or mpd if you're going to import ldraw files into blender.

Also, take note the features and settings in these two programs.  I am more savvy to MLCAD so here are my notes:

You can change the Grid's increment for Coarse, Medium and Fine by going to Settings>General>Change... but I would advise that you only mess with the Fine settings.  Coarse and Medium have values that match what we usually experience with actual bricks, i.e. 10 units in Ldraw = 0.5 stud unit of a brick.

Also note the pivot point, or center of rotation for your piece.

Take advantage MLCAD's ability to handle multiple models in one project (Multipart>New Model...).

For example: if you were building an X-Wing and you need the Wings to rotate where the hinge piece is, build the wing separately from the body by building in a separate model within the same MLCAD project.  Make sure you position the wing model so the rotation point of the hinge piece is centered with the center of the model area you're in (switch to Fine Grid and compare the coordinates where you mouse is with the hinge's rotation point).  In your top Active model, just right click, Add>Part... and search for your wing's model name.  Note that having multiple models will mean that you have to save the project as an mpd.  Both LeoCAD and MLCAD supports Ldr and mpd extensions, but MLCAD cannot support LeoCAD's extension.

Make sure the first or top model listed in you MLCAD model is the combined complete model and not a submodel.

Also note that depending on the amount of pieces you have in your MLCAD model, Blender may or may not support mpd files that have model within a model (a submodel with a submodel in it).  I've had mixed results with some working and some not so just be aware.

Importing in Blender
Some of you have had trouble with Blender and the Ldraw importer plugin so let's clarify some things:

Be sure to have at least Python 2.5 installed.
So far, it works for Blender 2.49a.  With the recent changes in Blender 2.5x, it is unclear how the script can be added so someone will have to update me on that.  Essentially, the Ldraw importer plugin script seems to work with any stable version currently available.  That means 2.49a.

Lastly, if the Ldraw importer plugin script doesn't work for you, it's most likely because you have your Ldraw directory placed elsewhere other than directly under the C drive.  The reason is that the script hardcoded the parts directory to "C:\ldraw\".  You can change this with a text editor to wherever your Ldraw folder is or you can move your ldraw folder to C:\

The variable you're looking for is on line 91 of the code

LDrawPath="C:\Ldraw"

To refine or not to refine
If you want to jump straight to animation, not worrying about making the parts look realistic or you want to use scaling tricks or your 3D animator's modifiers to create some realism, then using LeoCAD to export is fine.  Just be aware of your 3D animation tool's limitations.  For example, for Carrara, modifiers can only be applied one mesh at a time, which is time consuming.  Also, the scaling trick may be simple and easy, but all it does is create gaps, it doesn't make the brick look realistic up close.

For those who wish to add more realism to the pieces like making the edges smoother, you'll need to use something like Blender.

Those of you who skipped making the parts look real should take notice how the folks at ldraw.org build their parts.  The studs are nothing but cylinders on top of a plane.  They're not actually connected to that plane.  And if you were to apply a modifier to an unrefined straight-out-of-Ldraw-parts-folder piece, you will notice problems with the stud part of the piece.

Here are just some examples of using modifiers on an unrefined 1x2 plate in Blender.
http://i52.tinypic.com/124akxj.png
http://i51.tinypic.com/b8kao0.png
http://i51.tinypic.com/15d6p77.png

I have noticed similar problems in Carrara.

Unfortunately, there is no easy method of refining your pieces.  Fortunately, Blender has an advantage over all other 3D animation software: it can access Ldraw's dat files directly, which also means it links copies of the same LEGO part together.

As far as I know, no other 3D animation tool can import ldraw files, forcing you to convert the Ldraw model into a format that your animation tool can support.  The conversion usually renders each piece into an individual mesh.  For example, if you have a model of 50 1x1 plates, the conversion creates 50 individual 1x1 lego plate meshes.

Refining Technique
There is no one definite way of refining your bricks to look realistic.  An actual plastic lego brick does not have sharp 90 degree edges on its side nor on its studs.  They're slightly rounded so our goal is to soften the edges and make the stud look realistic.
*****************************
Background
Before I get into the technique, I need to explain why other single-step techniques aren't used.

Note, the smoothing feature in your animation tool does not smooth the object, it smooths the way light bounces off it. *Someone correct me if I'm wrong*

Take the following set of cubes.  Each have unique settings or changes done to them.

http://i54.tinypic.com/ei4dhv.png
From left to right:
Cube set to smooth, Cube with Bevel modifier set to smooth, Cube with Bevel modifier set to solid, Cube with a modified version of Littlebrick's beveling technique set to smooth and Cube set to solid.

Here are some illustrations on how light interacts with these cubes.  The black square is the cube, the gray dots are the vertices of the cube and the red outline is the shape the light is treat the cube as when the cube is set to smooth. *Someone correct me if I'm wrong*

Smoothed Cube.  Light bounces off this cube as if it were a sphere.
http://i53.tinypic.com/2sb1z7b.png

Beveled and smoothed Cube.  Light bounces off it like a sphere.
http://i51.tinypic.com/4l155t.png

Littlebrick's beveling and smooth cube.  The corners are rounded, but not the sides so the light bounces of it as if it were a rounded cube, which is what real LEGO bricks look like.
http://i51.tinypic.com/mhttzd.png

Looking at the 10 cubes, I find Littlebrick's beveling technique works the best in creating the illusion of rounded edges while still looking solid compared to the beveled-and-smooth and beveled-and-solid cubes.

*****************************
So the technique that I developed derives from Littlebrick's original technique.  It involves a combination of extrusion and scaling of each face of your  LEGO piece.  The result is something like this.

http://i56.tinypic.com/2vjelua.png

You're creating a face within a face.  The edge of the cube and the edge of the "sub-face" make up the round edge when you smooth the object.

Take a 1x1 brick as an example.  Select one of the side faces, hit the extrusion hotkey and enter 0 as the extrusion distance.  Hit the scaling hotkey to scale the face and depending on the amount of "beveling" you want, you scale the face accordingly on its axes.

In Blender, 1 stud unit = 20 Blender units.  If you wanted to scale the width (let's say it's the X-axis) of the sub-face to, say, 1unit from the edge on both sides, 20 - 2 = 18, 18/20 = 0.9, so scale value for the X-axis of the face is 0.9.

The height of a plate (excluding stud) is 8 Blender units.  So a brick is 24 units.  Using the same 1 unit distant from the top and bottom, 24 -2 = 22, 22/24 = 0.916667.  Say the height is the Z-axis, scale the Z-axis of the face by 0.916667.

Reminder: The 1 unit space from the corner edges is just an example.  It's up to you to determine the best distance from the corner edges that make your bricks look realistic.

There's a different technique for the studs but the idea of spacing is the same.  There are ways to create those edges between the top and bottom and inside the top face of the stud such as loopcut.  But for me, I use the spin/lathe tool.  Like drawing the lathe profile of a wine glass and spinning  on its vertical axis to create the wine glass, I delete all but the two edges of the stud that will serve as the lathe profile.  I use Subdivide Multi (set the number of cuts to 2 for the side and 1 for the top) and move the new vertices around to where I want them.  For our 1 unit example, it would be 1 unit from the top and bottom and 1 unit from the side.  Select the entire lathe profile, make sure your center of rotation is where it's supposed to be, and spin it 360.

Ultimately, you're trying to make the stud be part of the brick instead of being just a cylinder on top of a plane so after you created the stud, you'll have to create faces between the bottom of the studs and the rest of the LEGO piece you're working on and that's the most time consuming part of this technique.  For someone who is savvy to Blender's many functions, this should be a breeze, others might get a headache out of it.

Benefit with Blender
As mentioned before, with the use of the Ldraw Importer plugin script, Blender can access Ldraw's dat files directly and, to use Blender's terminology, treats copies of the same piece as linked duplicates.  To make it more confusing, I would coin the term: duplicate inheritance.

For example, you build a model that includes ten 1x1 bricks (part is 3005.dat).  In Blender, via Ldraw Importer, the 3005.dat file is loaded ten times and positioned along with the other pieces in the model.  If you change something on the 1x1 brick, that change will appear on all of the ten 1x1 bricks you imported.  The changes also appear in other models you import later on within the same Blender project.  This means you only need to apply the LB-beveling technique once for all ten 1x1 bricks and future 1x1 bricks that get imported.

Problems with Blender
The Ldraw Importer loads the model in an odd way.  Odd as in it loads the model scaled up and rotated 90 degrees on its X-axis.  But once you try to change something on the piece you selected, it scales down and rotates back to its actual size and orientation.  So don't worry if you see a huge looking 1x1 brick or plate after importing.  Just select all and do anything (press a transformation hotkey, toggle between Edit and Object mode, etc) and it should correct itself.  Also, don't worry if you're loading an mpd file and your submodels end up in the center of the Blender grid.  It'll correct itself once you do anything to it.

Also, for mpd files, you may notice small gray circles with dotted lines protruding out of it.  When you select it, its name should be the submodel name you created in MLCAD.  For example, if you name the wing submodel of the X-Wing model "Portside-Wing", it should say Portside-Wing when you select.  I'm not 100% sure, but I believe this gray circle is the parent object of the submodel and if you delete it, all the parts linked to it get blown back up to the original size and rotation when it was imported.  To get rid of this problem, after you imported and gotten the pieces to scale down, rotated, and positioned to their proper places, select all and clear the parent, keeping its transformation, of course.  This should not affect the "duplicate inheritance" of the pieces you imported.

Exporting
It really depends on the 3D animation tool.  For me, I go with LWO because Carrara allows me to set the smooth angle value up to 180 degrees for Lightwave Objects which makes everything look as smooth as they did in Blender.  With 3ds, it only goes up to 90 degrees which doesn't smooth everything.  The reason for this is because if you don't set it high enough, you don't get the round edges that you toiled away for hours trying to make in Blender.

Of course, if you're animating in Blender, the last thing you might want to do is apply a Smooth modifier to all your pieces.  The smooth factor depends on the spacing you decided to use on the sub-face.


Hope that clears things up for you CGI brickfilming freshmen and to those who ask us to do CGI stuff for them: now you know the magnitude of what you're asking us to do.

FYI:  You just read a 10 page essay.

Last edited by Lechnology (January 24, 2011 (03:18pm))

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

I've used blender for a while, but when I downloaded 2.56 and opened it- well. Let me explain first.

Be sure to have at least Python 2.5 installed.
It doesn't matter which version of Blender you have installed as far as I know.  The Ldraw importer plugin script seems to work with any version currently available.

I've have python 2.7. This worked fine with my old blender (2.53) but now whenever I open up blender 2.56m this keeps popping up:

Blender Pop-up wrote:

This program can't start because python31.dll is missing from your computer. Try reinstalling the program to fix this problem

I'm not sure if it's the same as 2.7 (well obviously) but whenever I run the setup for blender, and at the end it say: Run blender now? And if I press yes, it works, but as soon as I click on the blender Icon, that message keeps popping up.
And Yes, I've searched google, but where can I find that python31.dll, and where would i place it on my computer?
Or should I just search around more for an old 2.5 version (Not 2.49, but I geuss I can get used to it).

Re: Ldraw and Blender Tips and Tricks

Nice tutorial Lech, but there are several things that you missed, such as scaling faces at an angle, or creating smooth faces. I could do that, if you're alright with it. Also, I think a lot more people are using Blender 2.5 now, and things have been moved around a bit.

And finally, on a side note, when bricks are put together, they usually have gaps between them, most notably between the sides, so pushing the vertical faces in .01 Blender units might be a good idea. For comparison, the bevels (with my original technique) were .03 Blender units wide/tall.

"[It] was the theme song for the movie 2010 first contact." ~ A YouTuber on Also Sprach Zarathustra
CGI LEGO! Updated occasionally...

Re: Ldraw and Blender Tips and Tricks

Mason wrote:

I've have python 2.7. This worked fine with my old blender (2.53) but now whenever I open up blender 2.56m this keeps popping up:

Blender Pop-up wrote:

This program can't start because python31.dll is missing from your computer. Try reinstalling the program to fix this problem

Not sure what's going on there as I'm currently using the stable 2.49 version of Blender but I would suggest installing an older version of Python.  I have 2.5 and 2.7 (which I just added) installed on mine computer and 2.49 works.

/me goes look at 2.56a...Son of a !@#$%!  Now I'm all turned around here.  Ooh, very Maya-esque camera moves, nice.

For angular faces, you'll have to switch over to normal axis.  As for the smooth faces, I'm not familiar so go for it, Littlebrick.

The scaling thing really depends on the person.  I feel it's unnecessary.


Go ahead and show them how to do things in 2.5, Littlebrick, because I am suddenly lost in this user-friendly version of Blender mini/eek .  Where's the script folder in this thing...

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

Sorry for bumping this topic, but how do you import bricks from the newest version of LeoCAD into Blender 2.57a?

EDIT: YES! I just figured it out! You have to export it from LeoCAD as a 3ds file, and then go to Blender and import it! That saves a TON of modeling time! WOOHOO!

Last edited by Rusty (July 27, 2011 (03:53pm))

"Doc seriously, do that one more time without warning me first and I'll flip this examination table and roundhouse kick you in the face." - Adam young

Re: Ldraw and Blender Tips and Tricks

EDIT: Sent as PM.

Re: Ldraw and Blender Tips and Tricks

Exporting a model as a .3ds, then importing it into 2.58 makes all the polygons are triangular, not  square.
This gives for a strange, saw-tooth look around the edges of the studs.

http://i.imgur.com/lZUQ9.pnghttp://i.imgur.com/9CQIM.pnghttp://i.imgur.com/YZLtR.pnghttp://i.imgur.com/ICcjc.png

Re: Ldraw and Blender Tips and Tricks

So how do you get a Lego Digital Designer file into Blender?

"Doc seriously, do that one more time without warning me first and I'll flip this examination table and roundhouse kick you in the face." - Adam young

Re: Ldraw and Blender Tips and Tricks

Ask an LDD expert.  This thread is about LDraw.

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

Export the model as an Ldraw file, then import it into Blender 2.49 with the Ldraw import script.

http://i.imgur.com/lZUQ9.pnghttp://i.imgur.com/9CQIM.pnghttp://i.imgur.com/YZLtR.pnghttp://i.imgur.com/ICcjc.png

Re: Ldraw and Blender Tips and Tricks

Where and how do I use the Ldraw import script?

http://www.usa.canon.com/assets/app/images/callouts/cameras/callout_hdvideo_091511.jpg    http://www.usa.canon.com/assets/app/images/callouts/cameras/cdlc_148_rt.jpg

Re: Ldraw and Blender Tips and Tricks

ZP wrote:

Export the model as an Ldraw file, then import it into Blender 2.49 with the Ldraw import script.

That works only for parts that both Ldraw and LDD have.  Certain hair pieces in LDD, for example, don't load into Blender because the folks at Ldraw haven't made one yet.

VanderFlame Studios wrote:

Where and how do I use the Ldraw import script?

http://wiki.blender.org/index.php/Exten … port/LDRAW

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

I downloaded the file...how do I use it?

http://www.usa.canon.com/assets/app/images/callouts/cameras/callout_hdvideo_091511.jpg    http://www.usa.canon.com/assets/app/images/callouts/cameras/cdlc_148_rt.jpg

Re: Ldraw and Blender Tips and Tricks

Add it to your blender script folder.  Where is it?  If you have to ask that, then you'll need to go back to Blender 101.  Note: my instructions are for 2.49a or older.  It currently doesn't work for the newer version of Blender.

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

This is good but how t=do you use it with actual stopmotion?
I just want to implement 3d models into my scene but dont know how

Re: Ldraw and Blender Tips and Tricks

Why do some of the faces on my models turn invisible when I turn on Textured and/or press Play?

"Doc seriously, do that one more time without warning me first and I'll flip this examination table and roundhouse kick you in the face." - Adam young

Re: Ldraw and Blender Tips and Tricks

Mutuceba wrote:

This is good but how t=do you use it with actual stopmotion?
I just want to implement 3d models into my scene but dont know how

That's unrelated to this topic but the idea is that you match your physical camera settings with your 3D camera.  That includes position, angle, and focal length.

Please refer to this thread.

Rusty wrote:

Why do some of the faces on my models turn invisible when I turn on Textured and/or press Play?

Unrelated to this topic.  Please refer to this thread for all CGI question.  Check where your camera is and check to see if your face's normals are facing the right way.

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

If anyone is still following this tutorial into Blender 2.6, some changes: There is an LDR importer script for 2.6 or higher.  Note that it doesn't link duplicate pieces so you'll have to manually do that (hotkey Alt+D).  Blender 2.6 and higher has the Inset Tool (hotkey I) that pretty much does what this tutorial is about in one step.  With that, my tutorial is obsolete and I'm unsticking it.

https://i.imgur.com/4b9NnS3.pnghttps://i.imgur.com/GUIl0qk.pnghttps://i.imgur.com/ox64uld.pnghttps://i.imgur.com/v3iyhE5.png

Re: Ldraw and Blender Tips and Tricks

http://www.creativecrash.com/maya/scrip … -generator

If I can put this in here for anyone who uses Maya, this is an (old) LEGO generator plugin for Maya. It's not the greatest, but it is the easiest way I have found to generate LEGO pieces. It needs an update on colours, and I find the tiles have too much of curve on it, but it has a good selection of basic pieces (no minifigures). A bit of bashing should fix it up for anyone who wants to use it mini/smile

http://www.cxpulp.com/attachment.php?attachmentid=874&d=1279678499
The new KB Videos coming soon.

Re: Ldraw and Blender Tips and Tricks

That works only for parts that both Ldraw and LDD have.  Certain hair pieces in LDD, for example, don't load into Blender because the folks at Ldraw haven't made one yet.
wiki.blender.org/wiki/Extensions:2.4/Py/Scripts/LDRAW/import/wiki/writemyessay

Any experience with this Blender LDraw importer - ImportLDraw  by TobyLobster? What Blender import tool could be the best? Thanks, and sorry for this bump, just looking for valid information from experienced users (no answer from LDraw community members so far).

Last edited by randybonnette (May 15, 2019 (02:53am))