A Blender script to procedurally generate 3D spaceships

Last month I submitted an entry for Reddit’s /r/proceduralgeneration monthly challenge, which was to make an infinite number of spaceships using procedural generation. I figured generating spaceships in a 3D modelling package would be the most useful, so I decided to throw together a Blender Python addon.

I used Blender’s BMesh module to manipulate a box into a final spaceship. Here’s the basic algorithm:

  • Start with a box.
  • Build the hull: Extrude the front/rear faces several times, adding random translation/scaling/rotation along the way.
  • Add asymmetry to the hull: Pick random faces and extrude them out in a similar manner, reducing in scale each time.
  • Add detail to the hull: Categorize each face by its orientation and generate details on it such as engines, antenna, weapon turrets, lights etc.
  • Sometimes apply horizontal symmetry.
  • Add a Bevel modifier to angularize the shape a bit.
  • Apply materials to the final result.
  • Take over the universe with your new infinite fleet of spaceships.

I won the monthly challenge, and put the code up on GitHub. Since then a bunch of people have been making improvements, I made the top of HackerNews, and the /r/ mods gave me the flair “Starfleet Commander”. A good month.

Author: Michael Davies

Senior software engineer with 15 years of commercial video games experience.