Skip to content

Instantly share code, notes, and snippets.

@Rahix
Last active Sep 12, 2016
Embed
What would you like to do?
Blender Plugin for my Spacestation Generator
import random
# This seems to be a well working system for loading the
# generator script, however I don't know
# wether it is required to look like this
if "bpy" in locals():
import importlib
importlib.reload(spacestation)
else:
from . import spacestation
import bpy
# Info about this plugin
bl_info = {
"name": "Spacestation Generator",
"author": "Rahix",
"version": (0, 1, 0),
"blender": (2, 76, 0),
"location": "View3D > Add > Mesh",
"description": "Procedural Spacestation generator",
"category": "Add Mesh"
}
# The Operator is a class
class GenerateSpacestation(bpy.types.Operator):
# Id of this Operator
bl_idname = "mesh.generate_spacestation"
# Display name for the menu
bl_label = "Spacestation"
bl_options = {'REGISTER', 'UNDO'}
# Define all options for the generator
use_seed = bpy.props.BoolProperty(default=False, name="Use Seed")
seed = bpy.props.IntProperty(default=5, name="Seed (Requires 'Use Seed')")
parts_min = bpy.props.IntProperty(default=3, min=0, name="Min. Parts")
parts_max = bpy.props.IntProperty(default=8, min=3, name="Max. Parts")
# ...
storage_min = bpy.props.FloatProperty(default=0.5, min=0.1, name="Min. Storage height")
storage_max = bpy.props.FloatProperty(default=1.0, min=0.1, name="Max. Storage height")
def execute(self, context):
# The actual code to execute the generator
if not self.use_seed:
seed = random.randint(0, 100000)
else:
seed = self.seed
config = {
"min_parts": self.parts_min,
"max_parts": self.parts_max,
# ...
"storage_min": self.storage_min,
"storage_max": self.storage_max
}
spacestation.generate_station(seed, config)
return {'FINISHED'}
# Below is the code required for adding the Operator to Blender and the correct menu
def add_menu_entry(self, context):
self.layout.operator(GenerateSpacestation.bl_idname, "Spacestation")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_mesh_add.append(add_menu_entry)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_mesh_add.remove(add_menu_entry)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment