Generative Helper Methods for Blender 3.5

Example of generative art in Blender
Example of generative art in Blender

Wth is this?

Working with Python in Blender can be hard. There are a lot (and I mean a lot) of extra code to write that I felt could be abstracted away. So I wrote a couple classes with a few helper methods to simplify this.

Please note that these probably will change and be extended as I learn more generative techniques etc. But I think it’s a good starting point for now.

Please note that this library only works in newer versions of Blender (3.4+ I believe) that contains Python 3.10+.

Setup

There are two main elements that you most commonly work with when programming generative art in Blender:

  • Scene
  • Object

These are the two classes that this library is built around.

Scene

When starting a new generative project, there are stuff that I find myself doing over and over and over. Some examples:

  • Delete all objects / meshes by type everytime you run the script
  • Delete all materials everytime you run the script
  • Automatically render a PNG
  • etc.

Here’s an example of a basic setup.

# Example scene

scene = Scene()

scene.setup(
  ["cube", "sphere", "cone"], # object types to be deleted on script re-run
  ["toon"], # materials to be deleted on script re-run
  "#EBEBEB" # world color
)

Object

Working with objects / meshes in Python can also be difficult. That’s why I wrote the Object class. Some examples of what it can do:

  • Set the scale of an object
  • Set the position of an object
  • Set the rotation of an object
  • Set the material of an object
  • etc.

Here’s a basic example of creating a cube of a certain size, position and rotation.

# Example object creation

obj = Obj(
  "Cube", # object type
  "toon", # material name
  [1, 2.5, 2], # size x, y, z
  [2, 2, 0, 0], # position x, y, z, z-extra (z + n)
  [15, 12, 9]
)

Usage

This post is a work in progress. -insert examples here-