2.9 KiB
2.9 KiB
NodeSlicer
NodeSlicer is a high-performance Blender extension providing a custom node-based interface for mesh slicing and G-code generation. It leverages NumPy for vectorized geometry processing and Pyclipper for robust 2D polygon operations.
Project Overview
- Purpose: 3D printing slicing, CNC toolpathing, and procedural geometry tasks.
- Main Technologies: Python, Blender API (
bpy), NumPy, Pyclipper, Shapely. - Architecture: Separates Blender-specific UI and data capture (
infra/) from core geometric and slicing algorithms (core/).
Building and Running
Requirements
- Blender 4.2 or newer (required for the Extension platform).
uvfor Python dependency management.
Development Setup
- Clone the repository.
- Run
uv syncto install development dependencies (likefake-bpy-module).
Building the Extension
Run the build script to package the addon:
./build.sh
This generates a zip file in the release/ directory using Blender's extension build system.
Installation
- Open Blender.
- Go to
Edit > Preferences > Extensions. - Click the arrow in the top right and select
Install from Disk. - Select the generated zip from the
release/folder.
Project Structure
__init__.py: Main entry point. Defines theNodeSlicer Tree, custom Sockets, and all Nodes.registry.py: Utility for automatic registration of Blender classes using the@register_classdecorator.core/:slice.py: Core slicing engine (plane-mesh intersection), buffering (offsetting), and infill generation.geometry.py: Shared geometry utility functions.
infra/:blender_mesh_capture.py: Logic for extracting mesh data from Blender objects into NumPy arrays.blender_slice_nodes_generic.py: Base classes for the node system and the evaluation logic (resolve_input).
doc/: Comprehensive documentation on modules and nodes.
Development Conventions
- Registration: All Blender classes (Nodes, Sockets, Operators, Menus) must be decorated with
@register_classfromregistry.pyto ensure they are registered correctly during initialization. - Node Evaluation: Nodes follow a pull-based evaluation model. Use
resolve_input(self.inputs.get("SocketName"))within a node'sevaluate_outputmethod to trigger the evaluation of upstream nodes. - NumPy First: For any geometry processing, prioritize NumPy vectorized operations over standard Python loops to maintain high performance.
- Scaling & Integer Math: 2D polygon and geometric operations use a
SCALE = 1000factor (defined incore/slice.py) representing 1 micron (1\ \mu\text{m} = 0.001\text{ mm}) integer math units to eliminate floating-point precision issues. - Type Hinting: Use exhaustive type hints for all new functions and classes.
- Documentation: Update
doc/NODES.mdwhen adding new nodes anddoc/MODULES.mdwhen adding new modules.