A Python application that converts 3D models (STL files) into buildable LEGO sculptures. The project currently supports converting 3D models into voxelized representations, with planned features to generate LEGO building instructions.
- User-friendly GUI for file selection and conversion
- STL file loading and processing
- Advanced voxelization with optimized resolution
- Exports both
.npy
(NumPy array) and voxelized STL files - Automatic resolution calculation based on model complexity
- Multi-threaded processing for responsive UI
- LEGO brick mapping algorithm
- Generation of building instructions
- LDraw file export for compatibility with LEGO CAD software
- Optimization for structural stability
- Color matching for colored STL models
The voxelization process converts a smooth 3D model into discrete cubic volumes
The current implementation uses a sophisticated voxelization technique:
-
Surface Sampling:
- The 3D model's surface is sampled using an optimized grid
- Sub-voxel sampling points ensure accurate surface representation
- Adaptive resolution based on model complexity
-
Volume Processing:
- Surface voxels are identified through triangle-point proximity tests
- Internal volumes are filled using flood-fill algorithms
- Floating voxels are removed for model integrity
-
Optimization:
- Binary morphological operations smooth the result
- Connected component analysis ensures model coherence
- Memory-efficient batch processing for large models
The planned LEGO conversion will:
-
Brick Mapping:
- Convert voxels into optimal LEGO brick combinations
- Consider standard LEGO brick sizes (1x1, 2x2, 2x4, etc.)
- Ensure structural stability through proper brick overlapping
-
Structure Optimization:
- Analyze structural integrity
- Optimize brick layout for stability
- Add support structures where necessary
-
Instruction Generation:
- Create layer-by-layer building instructions
- Generate LDraw format files for LEGO CAD compatibility
- Provide brick inventory and color matching
# Clone the repository
git clone https://github.com/yourusername/stl-to-lego-converter.git
# Install dependencies
pip install -r requirements.txt
- Run the application:
python main.py
- Use the GUI to:
- Upload your STL file
- Click "Convert to LEGO!" to process
- Find output files in the same directory as input
The converter currently generates two files:
{model_name}.npy
: NumPy array of voxel data{model_name}_voxelized.stl
: Voxelized 3D model for visualization
- Python 3.8+
- numpy
- scipy
- numpy-stl
- tkinter
Contributions are welcome! Please feel free to submit a Pull Request.