Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created July 16, 2015 10:22
Show Gist options
  • Save zeffii/41b588adb02d362a817a to your computer and use it in GitHub Desktop.
Save zeffii/41b588adb02d362a817a to your computer and use it in GitHub Desktop.
bl_info = {
"name": "TunnelGen",
"category": "Curve"
}
# /usr/share/blender/scripts
import bpy
import bpy.types
from bpy.utils import register_module, unregister_module
from bpy.props import StringProperty, FloatProperty, IntProperty, BoolProperty, PointerProperty
import math
class TunnelGenProps(bpy.types.PropertyGroup):
@classmethod
def register(cls):
Scn = bpy.types.Scene
Scn.tunnel_gen_props = PointerProperty(
name="tunnel_gen internal global properties",
description="uses these properties for shared properties between operators",
type=cls
)
cls.showPanel = BoolProperty()
cls.trackLength = FloatProperty(
name="Track length",
description="Track length in meters", default=1000.0, min=100.0)
cls.radius = FloatProperty(
name="Tunnel radius",
description="Radius of the tunnel in meters", default=16.0,
min=6.0, max=32.0)
cls.segments = IntProperty(
name="Circle segments",
min=6, max=64, default=32)
cls.bezierResolution = IntProperty(
name="Bezier resolution",
min=32, max=1024, default=256)
@classmethod
def unregister(cls):
del bpy.types.Scene.tunnel_gen_props
class SetShowPanelOperator(bpy.types.Operator):
'''Set Show Panel'''
bl_idname = "curve.set_show_panel_operator"
bl_label = "Set Show Panel"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
context.scene.tunnel_gen_props.showPanel = True
return {'FINISHED'}
class TunnelGen(bpy.types.Operator):
"""Tunnel Generator"""
bl_idname = "curve.tunnel_generator"
bl_label = "Tunnel Generator"
bl_options = {'REGISTER', 'UNDO'}
#sizeDesc = StringProperty(name="Size", default="x=0, y=0, z=0",
# description='Bounds of master line')
@classmethod
def poll(cls, context):
# obj = context.active_object
# return (obj and obj.type == 'CURVE')
return True
def debug(self, msg):
self.report({'INFO'}, msg)
def preInit(self):
props = bpy.context.scene.tunnel_gen_props
segmentAngle = 2 * math.pi / props.segments
self.circleSegmentSize = 2 * props.radius * math.sin(0.5 * segmentAngle)
pass
def execute(self, context):
scene = context.scene
curve = scene.objects.active
self.debug('obj is {}.'.format(type(curve)))
self.debug('splines: {}'.format(len(curve.data.splines)))
spline = curve.data.splines[0]
self.debug('bezier points: {}'.format(len(spline.bezier_points)))
# mathutils.geometry.interpolate_bezier(knot1, handle1, handle2, knot2, resolution)
# TODO do stuff
context.scene.tunnel_gen_props.showPanel = False
return {'FINISHED'}
class TunnelGenPanel(bpy.types.Panel):
bl_label = "Tunnel Generator"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOL_PROPS"
def debug(self, msg):
self.report({'INFO'}, msg)
@classmethod
def poll(cls, context):
obj = context.active_object
return obj and obj.type == 'CURVE' and context.scene.tunnel_gen_props.showPanel
def draw(self, context):
self.layout.operator("curve.tunnel_generator")
def menu_func(self, context):
self.layout.operator(SetShowPanelOperator.bl_idname)
def register():
bpy.utils.register_class(TunnelGenProps)
# bpy.types.VIEW3D_MT_edit_mesh_specials.append(menu_func)
register_module(__name__)
bpy.types.VIEW3D_MT_edit_curve_specials.append(menu_func)
def unregister():
bpy.types.VIEW3D_MT_edit_curve_specials.remove(menu_func)
unregister_module(__name__)
bpy.utils.unregister_class(TunnelGenProps)
if __name__ == '__main__':
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment