Skip to main content

LEGO rendering tools using Blender

Project description

grid of parts

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.

grid of materials

Colors

Colors are specified with hex codes in sRGB. Included is a list of named colors from Rebrickable.

grid of colors

Rotation

Parts can be rotated to various angles. The parts are moved up/down to remain touching the ground.

grid of various rotations

Lighting

Lighting Styles: default, bright, hard

grid of lighting styles

Lighting angle around the part

grid of light angles

Camera

Camera height: degrees from 0-90

grid of various camera angles

Camera zoom

grid of various zoom levels

Instruction Look

By default they are rendered with a transparent background. Use PNG format (format=Format.PNG).

grid of various parts in line art style

Setup

  • Install Blender
  • Download ImportLDraw Plugin
  • LDraw parts library
    • download and extract
    • cp -R ~/Downloads/ldraw ./ldraw
  • LDraw unofficial parts
    • download and extract
    • cp -R ~/Downloads/ldrawunf/* ./ldraw/
  • Your terminal needs Full Disk Access (to install Pillow in Blender.app) :(
  • Run
    ./setup.sh
    
  • Run Blender -> Edit -> Preferences -> Adds Ons -> Import LDraw -> check it to enable (can we script this?)

Run

Build script:

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 lib/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

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

lego_rendering-0.1.1.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lego_rendering-0.1.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file lego_rendering-0.1.1.tar.gz.

File metadata

  • Download URL: lego_rendering-0.1.1.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for lego_rendering-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a253f3c286c8144409085c5071d16543d0c5f4393f4b91f2c88b8d0c741c5955
MD5 f1c0fd4c640a1ec1590dea88ec9e6843
BLAKE2b-256 68b414a499bc9e32bdd4c6e4379d7615353ee92423872ab3df7189ddd0bad6f9

See more details on using hashes here.

File details

Details for the file lego_rendering-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lego_rendering-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff347289002f096443d04db9eb77f758df4dec2470a98c10e7415311049e1ade
MD5 aa5672e43bb6a5cc35cbcf12434ea131
BLAKE2b-256 d7acb9abb89a86ca2f93838fb2e9039b8b6c5a7d61d02c2deb2b7229ac91a6d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page