/blender-clj

Scripting blender with clojure

Primary LanguageShell

Description

This project uses libpython-clj and a custom build of blender as a python module, to be able to load it in my clojure repl and script it with the GUI visible, all from clojure.

For an alternative approach, which doesn’t require a custom build of blender, see https://github.com/tristanstraub/clj-python-trampoline

Motivation

I want to script blender with clojure from cider/emacs, or CLI, etc. I want the GUI to be visible.

Screenshot

screenshot.png

Procedure

We need blender to be built as the python module “bpy.so”, but patched to run the GUI in the foreground.

The build has been tested on:

  • Fedora 31 (python 3.7.7, blender 2.83)

Building

“bpy.so” can be built from the patched blender source as follows:

./build-blender-fedora.sh

See https://wiki.blender.org/wiki/Building_Blender/Linux/Fedora for more details regarding dependencies.

Running

To get blender running on the main thread and nrepl in the background, run the following, after which you can jack-in with your favourite editor.

clj -A:nREPL

For emacs users, “.dir-locals.el” exists to make jacking in work as expected, along with cider middleware.

Demo

After building, open a clojure repl with the following command:

./build-blender-fedora.sh repl

Run the demo:

(require 'blender-clj.examples.cube)

(blender-clj.examples.cube/demo)

Alternatively, a repl can be loaded as follows, where BPY_BIN_PATH is the directory where bpy.so can be found.

BPY_BIN_PATH=vendor/blender-git/build_linux/bin clj -r