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.
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.
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.
Beveled and smoothed Cube. Light bounces off it like a sphere.
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.
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.
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))