This will be the last release I will make with this code. Although this code was useful to understand the ldraw import and it's completly working (now), I dont like this addon code structure and I find the render part useless. Not only that, but since it has a "crop" utility, this makes the addon "difficult to install", since it needs to install pip dependencies. Plus you need to post-process the output images for ML, for creating variation in rotation and maybe convert to greyscale. So moving forward I will make my own "utility" that not only has a Blender add-on but also everything you need to post process.
I think the main script is quite self-explanatory but I will write the steps I used to generate the output example here
- Install the plugin in Blender (instructions below) and make sure you have CUDA installed and enable GPU rendering in Blender.
- Open Blender and Go to File -> Import - >Import and import an LDRAW part also check your preferences in the plugin import window. Doesnt' matter which part you import, just one. (this sets all options for the importer, without having to create all the Options via script.)
- Now open the script (in Blender) called check_camera_pos.py . Generate as many camera position/rotation as you like. Create the list of CameraPos following the example. And check one by one with adjustCamera(camera_props[0]), adjustCamera(camera_props[1]) and so on, just run the script and check.. Just to make sure every render has a camera position exactly how you like it. Finally copy the list from the editor.
-
Open the script called first_script_testing_addon.py and paste the list of camera positions, replacing the one in the example. Set all the directories path needed in the script. Adjust the plane positions if you want. Adjust the light positions and intensity if you want.
-
I suggest to open the Blender output console window Window->Toggle system console because during the rendering Blender will "freeze", at least you will read whats going on.
-
Just run the script for the lego part you want. In the example script here , it will generate 208 images 200x200. This is just an example.
The process is quite simple:
-
Download the latest release (or git clone and use the script "create_local_package_ready_for_blender.sh")(but dont forget the file background.exr, git for some reason doesn't allow the push, can be found on the release)
-
Open Blender, go to Edit->Preferences->Add-ons. Click install in the top right and locate the zip file with the lastest release. Select the file and click Install Add-ons.
-
Open a terminal and navigate (cd) to the Blender addons directory. This depends on the OS and user settings. In my case, on windows 10, it is: C:\Users\Username\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons
-
Here you should see a file called installBlenderAddons.py and to be completly safe, just check you have a file called ldraw_render_addons.zip inside the addons subdir. (addons/addons/)
-
Launch the script using Blender engine. This depends again on SO. The basic idea is the same launch blender passing this script as argument. In windows 10 in my case it was: C:\Users\Alessio\AppData\Roaming\Blender Foundation\Blender\3.2\scripts\addons> & 'C:\Program Files\Blender Foundation\Blender 3.2\blender.exe' --background --python .\installBlenderAddons.py (offcourse you need python and pip installed on your system.)
-
Congratulations, you did it! You should see the message INFO: LDraw Addons installed. Blender quit
-
Now open Blender, go back in Edit->Preferences->Add-ons, search for ldraw and activate (✔️) the 2 new add-ons (importer and renderer)
At this point you can check in menu File->Import and see, you should have as first (probably) option the LPUB3D Import LDraw where you need to set your ldraw directory and to save it, try to import an ldraw part. Everything should be fine. You also will have a new option under menu Render->LPUB3D Render LDraw.
-Guide on HOW-TO install
-Working example on how to script Blender for actually use this addons.
The original repo from trevorsandy is abandoned from 18 July 2020. This addons seems promising but it doesnt install on Blender 2.92+ (I'm using 3.2). I want to try to use this addon to create Syntethic data for Machine Learning training. It should have everything needed but without a single HOW-TO, I need to "reverse engineer" the code and figure it out. Will write the How-to and example Blender script once I understand how to actually do it.
A Blender™ add-on for importing and rendering LDraw™ file format models and parts.
LPub3D Import LDraw imports LEGO® models into Blender. This addon is intended to support direct Blender integration with LPub3D.
This addon was designed to provide LPub3D an autonomous module enabling the integrated import and render of LDraw LEGO® models using Blender™. However, it can be executed directly from the Blender GUI, CLI or your operating system command console.
It supports .mpd, .ldr, and .dat file formats.
The LDraw import module is adapted from Import LDraw by Toby Nelson (tobymnelson@gmail.com).
- Available for Blender 2.80 and later (2.79 backport in progress).
- Mac, Windows and Linux supported.
- MPD file compatible.
- Render settings configurable from LPub3D user interface.
- Monitor render progress from LPub3D user interface or launch Blender and directly invoke render routine from manu item.
- Render Portable Network Graphics (.png) image files.
- Crop images with transparent background to their opaque bounds
- Specify transparent background from render settings
- Specify blendfile to load additional settings
- Specify exr 'environment' file to load custom backdrop and ground plane
- Available for Blender 2.80 and later (2.79 backport in progress).
- Mac, Windows and Linux supported.
- MPD file compatible.
- Import settings configurable from LPub3D user interface.
- LeoCAD groups and cameras (both perspective and orthographic) supported.
- LSynth bendable parts supported (synthesized models).
- LDCad generated parts supported.
- Additional LDraw parts paths can be specified.
- LGEO colours, sloped bricks and lighted bricks can be custom configured via parameter (ini) file.
- Import and apply camera settings from LPub3D generated LDraw content
- Import and apply light settings from LPub3D generated LDraw content.
- Pointlignt, Sunlight, Spotlight and Arealight sources available.
- LDraw archive (.zip) or disc library supported. Archive libraries are auto detected when available at the specified LDraw directory path.
- Cycles and Blender Render engines supported. It renders either engine from a single scene.
- Import Photorealistic look, or Instructions look.
- Physically Based Realistic materials - standard brick material, transparent, rubber, chrome, metal, pearlescent, glow-in-the-dark, glitter and speckle.
- Principled Shader supported Uses Blender's 'Principled Shader' where available for optimal look (but still works well when unavailable).
- Accurate colour handling. Correct colour space management is used so that e.g. black parts look black.
- Direct colours supported.
- Back face culling - fully parses all BFC information, for accurate normals.
- Linked duplicates - Parts of the same type and colour can share the same mesh.
- Linked studs - studs can also share the same mesh.
- Studs can include the LEGO logo on them, adding extra geometry.
- Gaps between bricks - Optionally adds a small space between each brick, as in real life.
- Smart face smoothing - Uses Edge-Split Modifier and Sharp Edges derived from Ldraw lines, for smooth curved surfaces and sharp corners.
- Concave walls - Optionally look as if each brick has very slightly concave walls (with the photorealistic renderer), which affects the look of light reflections.
- Light bricks - Bricks that emit light are supported.
- Fast - even large models can be imported in seconds.
LPub3D Render LDraw is licensed under the GPLv2 or any later version.
LEGO® is a registered trademark of the Lego Group
Copyright (c) 2020 by Trevor SANDY

