LEGO rendering tools using Blender
Project description
Lego Rendering Pipeline
Render semi-realistic, individual parts. Primarily used to train machine learning models for detection, part classification and color classification.
This uses LDraw's part models and Blender to produce a render.
A single render typically takes 10-15s on an M1 Pro. There is a draft mode that takes a few seconds.
Parts
In theory this can render any LDraw part. However I've only tested with typical plastic Lego parts. Parts are specified using their LDraw ID. In many cases this will be same as the mold number on the part but not always. Keep in mind there may be multiple molds over time.
Materials
Currently supports plastic, transparent and rubber. Not supported yet: pearlescent, glitter, neon colors, metal and cloth.
Colors
Colors are specified with hex codes in sRGB. Included is a list of named colors from Rebrickable.
Rotation
Parts can be rotated to various angles. The parts are moved up/down to remain touching the ground.
Lighting
Lighting Styles: default, bright, hard
Lighting angle around the part
Camera
Camera height: degrees from 0-90
Camera zoom
Instruction Look
By default they are rendered with a transparent background. Use PNG format (format=Format.PNG).
Setup
- Install Blender
- Install ImportLDraw Plugin
- In your own a folder:
- Download LDraw parts library
unzip complete.zip- Download LDraw unofficial parts
unzip -o ldrawunf.zip -d ldraw- At this point your current folder should look like
ldraw/ parts/ p/ ... - In Blender, open the Python Console:
import subprocess import sys subprocess.check_call([sys.executable, "-m", "pip", "install", "--user", "lego-rendering"])
Alternatively, clone this repo, follow the above steps and run
./setup.sh
Run
Build script:
sys.path.insert(0, site.getusersitepackages())
from lego_rendering import Renderer, RenderOptions, Quality, LightingStyle, Look, Material, RebrickableColors
renderer = Renderer(ldraw_path="./ldraw")
renderer.render_part("6126b", RenderOptions(
image_filename = "renders/test.jpg",
part_color = RebrickableColors.Blue.value.best_hex,
material = Material.PLASTIC,
lighting_style = LightingStyle.BRIGHT,
light_angle = 160,
part_rotation = (0, 0, 270),
camera_height = 45,
zoom = 0.1,
look = Look.NORMAL,
width = 244,
height = 244,
))
See lego_renderer/renderer/render_options.py for the full list of options. See docs-*.py to see how the images on this page were genereated.
Run in Blender's Python environment:
./run.sh test.py # renders to renders/test/png
./run-watch.sh test.py # run test.py each time a .py file is saved
Contributing
# Setup
uv sync
# Render without publishing a pacakge
./run.sh test-local.py
# Publish a new version
# - bump version in pyproject.toml
uv build
uv publish
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lego_rendering-0.1.4.tar.gz.
File metadata
- Download URL: lego_rendering-0.1.4.tar.gz
- Upload date:
- Size: 38.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9dab1bd4ed78e589d5f5960c4024d3bcf8344b8e6f0467de5e9f3c8e0ce755f
|
|
| MD5 |
82ee58ff51a3ea8bad2bc83541597a24
|
|
| BLAKE2b-256 |
d7f582a98e7f054d793f1e2fe6f905a2b7dab60a8c1c1033c3db5b419f57f002
|
File details
Details for the file lego_rendering-0.1.4-py3-none-any.whl.
File metadata
- Download URL: lego_rendering-0.1.4-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa69776e6d3de4f10437de6c06bc46e78c51c9ba0757fc010b2524c8233c470c
|
|
| MD5 |
955431153277b46c0bacfe555870a2fa
|
|
| BLAKE2b-256 |
3c43aeff8bc99f142d80f2f54042b0f9334d4437c5297908245ef8b94f388728
|