Skip to content

Open ended exploration of 3d rendering and motion graphics using Blender and Python.

Notifications You must be signed in to change notification settings

jordanblakey/blender-scripting

Repository files navigation

blender-scripting

Experiments in automating Blender with Python.

Table of Contents

Setup Project for VSCode

Installation

brew install poetry
poetry completions fish > ~/.config/fish/completions/poetry.fish
# run this once to create venv and install poe
poetry install
# run to (re)install everything--this is the main install command
poe install

The Big Idea: run Python scripts in Blender from the CLI

# run with UI to work visually
blender -P headless_mode.py # `poe blend`
# run without UI to debug (fast)
blender -P headless_mode.py -b # `poe bblend`

butils module

butils abstracts common Blender scripting code and provides CLI commands.

# General help
python -m butils --help

# Install dependencies into Blender's Python environment and symlink `butils`
# Run this when new dependencies are added to `butils`.
python -m butils install
# (Alias: poe install-butils)

# Create a new Blender starter script
python -m butils create -i my_new_script.py
# (Alias: poe create)
# The -i/--input-file flag specifies the name for the new script.

# Compress output images and videos
# Supported image formats: .png, .jpg, .jpeg
# Supported video formats: .mkv, .mp4
python -m butils compress -i path/to/your/file.png
python -m butils compress -i path/to/your/file.mkv --crf 23
# (Alias: poe compress)

# Options for 'compress':
# -i, --input-file: (Required) Path to the image or video file to compress.
# --analyze: (For images only) Get image attrs and metadata. Skips compression.
# --crf: Constant Rate Factor. Sets bitrate (e.g., 18-28). Lower is better.

# profile GPU performance
pipx run nvitop

# module structure
butils/
├── animation/
│   ├── fcurve.py  # Utilities for F-Curves
│   └── keyframe.py  # Utilities for keyframes
├── blend_file.py  # Work with .blend files
├── btyping/
│   ├── animation.py  # Type hints for animation module
│   └── render.py  # Type hints for render module
├── commands/  # CLI commands
│   ├── compress/
│   │   ├── image.py  # Image compression commands
│   │   └── video.py  # Video compression commands
│   ├── install/
│   │   ├── pythonpath.py  # Command to set up Python path for Blender
│   │   └── requirements.py  # Command to install deps in Blender's Python
│   └── starter/
│       ├── create.py  # Command to create a new starter script
│       └── starter_script.py  # Boilerplate for scripting a Blender scene
├── mesh.py  # Simplify working with meshes
├── render/
│   ├── config.py  # Rendering configuration utilities
│   ├── optimize.py  # Utilities for optimizing render performance
│   ├── render.py  # Core rendering utilities
│   └── update_mask.py  # Utilities for updating render masks
├── scene.py  # Clean scenes, work with collections
└── ui.py  # Work with the Blender UI: get contexts, control viewport

Pre-commit Hooks & Code Quality

This project uses the pre-commit python module to ensure code quality and consistency. These hooks are automatically installed when you run poe install, and can be run on demand withnormal maps and texture painting poe pre-commit.

  • lint and format using ruff, shfmt, shellcheck, and markdownlint, yamllint, actionlint.
  • check spelling, trim trailing spaces, add final newline to files.
  • validate links, scan for large files, warn about any added secrets.
  • validate json, yaml and toml files.

Unit tests

This project uses Python's built-in unittest module for testing. Tests are executed within a Docker container that includes Blender, ensuring a consistent testing environment. This setup is defined in the GitHub Actions workflow file (.github/workflows/blender_tests.yml).

Running Tests

There are several ways to run the tests:

  • Locally with act: You can simulate the GitHub Actions environment locally using act. The pyproject.toml defines a poe task for this:

    poe act
    poe act --input="testcase=tests.test_module.TestCase.test_function"

    Refer to the tool.poe.tasks.act section in pyproject.toml and the workflow_dispatch inputs in .github/workflows/blender_tests.yml for more details on available parameters.

  • GitHub Actions: Tests are automatically executed in GitHub Actions on every push and pull_request to the main branch. You can also manually trigger the "Blender Tests" workflow from the Actions tab in your GitHub repository, providing inputs for specific test cases, verbosity, etc.

    gh workflow run "Blender Tests" --input testcase=your_test_case --input verbosity=2

Visual Notes and Renders

after_effects_1
Geometry nodes aftereffects like effect
glass_cell_division
Geometry nodes glass metaball exercise - Blender 5.0 beta
particles_turbulence
Particle system using turbulence force field
particles_test1
Learning about particle emitters
cloth_pinning_tests
Cloth pinning tests using hook mod and vertex weight mix mod
cloth_sim_hires_solidify
Testing subdiv -> cloth -> solidify -> subdiv mod stack
cloth_sim_hires_presets
Cloth sim preset testing
cloth_sim_1_png
Cloth sim + Hair particle system
distribute_points_in_volume
Experiments with Distribute Points in Volume
led_matrix
LED matrix using ray casting to calc text collisions
geo_nodes_proximity2
Proximity based geo nodes exercise
metaball_geo_nodes
Metaball effect using geometry nodes
product_design_phone
Learning product design motion graphics
manitou_topography ny_orbit_viewport
Shuttle Radar Topography Mission data Open Street Map data via BlenderGIS
fracture_effect
Proximity plus fracture modifier
geo_nodes_proximity_1
Geometry proximity node
laptop_animation
Emissive image textures for screen and keyboard backlight
laptop_modeling
Started product design exercise - Laptop
low_poly_pc_process
Sourcing low res/poly textures from ebay photos.
low_poly_pc_anim
Finished animation with pixelate compositor node.
brick_wall_render
Learning more about displacement maps and vertex painting.
scifi_crate
Learning more about procedural texture creation.
anvil_normal_map
Learning more about normal maps and texture painting.
nikon_metashape
Exploring alternative photogrammetry workflow with Metashape.
nikon_photogrammetry
Improving Meshroom results: low ISO, small aperature, tripod, remote.
realistic_earth
Rendering Earth using NASA satellite imagery.
photogrammetry_experiment
Photogrammetry experiment in Meshroom.
hdri_transform_test_2
Hyperspace effect w/ HDRI scaling.
geo_nodes_cube_grid
Animating instance scale with a noise texture.
simple_lighting_experiments
Exploring basic lighting concepts.
geo_node_drivers
Using a driver to control a value with a named attribute.
geo_node_random_value
Getting collection instances by random index with geometry nodes.
read_variables
Reading variables with geometry nodes.
lego_geometry_nodes
meshes from scratch using geometry nodes.
soborg_chair_anim
Finished chair modeling series.
profiling_gpu_performance
Profiling GPU performance to identify bottlenecks in render pipeline.
chair_uv_unwrap
UV unwrap to prepare for texturing.
chair_model_complete
Chair model complete.
sphere_boolean_anim
brew install gifski && gifski -ogeo_nodes_proximity2 file.gif img0*.png
ui_manipulation
Manipulating the UI with Python
blender_beginner_tutorial
Tradition
rendering_compositing
Practicing rendering and combining images in the compositor
basic_interior
Composing an interior scene with 3rd party models
glitter_waves_viewport
Animating geometry nodes
modifier exploration
Exploring modifiers
reference modeling
Learning to create clean, precise topology
reference modeling
Learning to model with reference images
Rock texture
Creating rock textures from procedural shaders
Writing Shaders in OSL
Writing Shaders in Open Shader Language (OSL)
Parametric Modeling with Geometry Nodes
Parametric Modeling with Geometry Nodes
Hard Surface Modeling
Learning Hard Surface Modeling
Geometry Nodes
Working with node based geometry modifiers
Iterative Material Experiments
Iterative Material Experiments

iew | Exploring Fresnel and adding bloom with compositor | | :-----------------------------------------------------------------------: | | Exploring Fresnel node and adding bloom with the compositor |

Wave -> Voronoi -> Displace
Wave Texture -> Voronoi Texture -> Displacement
Screen1 Screen2
Experimenting with iteration Iterating using trigonometric functions
Defining Materials with Python
Defining Materials with Python
Node Based Material Experiments
Node Based Material Experiments
Using graph editor and camera view to proof an animation
Using graph editor and camera view to proof an animation
Mesh from scratch, composing and repetition
Mesh from scratch, composing and repetition
Procedural Animation Example
Procedural Animation Example

About

Open ended exploration of 3d rendering and motion graphics using Blender and Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5