Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Name: 'step_pyramid'
- Blender: 250
- Group: 'AddMesh'
- Tip: 'Add Step Pyramid Object...'
- """
- __author__= [ "Phil Cote", "BlenderPythonTutorials.com" ]
- __version__ = '.01'
- import bpy
- from bpy.props import IntProperty, FloatProperty
- def makePyramid( initialSize, stepHeight, stepWidth, numberSteps ):
- extrude = bpy.ops.mesh.extrude
- translate = bpy.ops.tfm.translate
- resize = bpy.ops.tfm.resize
- # establish the initial base.
- bpy.ops.mesh.primitive_plane_add( enter_editmode=True )
- ob = bpy.context.object
- ob.name = 'pyramid'
- resize( value=( initialSize, initialSize, 0 ) )
- extrude()
- translate( value=(0,0, stepHeight ) )
- # iterate to create the steps to extrude out from the base
- currentSize = initialSize
- while numberSteps > 0:
- currentSize = currentSize - stepWidth
- extrude()
- resize(value=(currentSize, currentSize, 0 ) )
- extrude()
- translate( value=(0, 0, -stepHeight ) )
- numberSteps = numberSteps - 1
- mesh = ob.data
- bpy.ops.object.editmode_toggle()
- bpy.context.scene.objects.unlink( ob )
- return mesh
- class OBJECT_OT_PyramidOp( bpy.types.Operator ):
- initialSize = FloatProperty( name="initialSize", default=1.0, min=0.0, max=5.0 )
- stepHeight= FloatProperty( name="stepHeight", default=0.3, min=0.0, max=5.0 )
- stepWidth= FloatProperty( name="stepWidth", default=0.1, min=0.0, max=5.0 )
- numberSteps= IntProperty( name="numberSteps", default=5, min=1, max=10 )
- bl_undo = True
- bl_register = True
- bl_idname="pyramid_op"
- def execute( self, context ):
- initSize = self.properties.initialSize
- sHeight = self.properties.stepHeight
- sWidth = self.properties.stepWidth
- nSteps = self.properties.numberSteps
- mesh = makePyramid( initSize, sHeight, sWidth, nSteps )
- scene = context.scene
- for ob in scene.objects:
- ob.selected = False
- mesh.update()
- ob_new = bpy.data.add_object( 'MESH', "Pyramid" )
- ob_new.data = mesh
- scene.objects.link( ob_new )
- scene.objects.active = ob_new
- ob_new.selected = True
- return( 'FINISHED', )
- bpy.ops.add( OBJECT_OT_PyramidOp )
- import dynamic_menu
- menuFunc = ( lambda self, context: self.layout.operator( OBJECT_OT_PyramidOp.bl_idname, text="Pyramid" ) )
- menu_item = dynamic_menu.add( bpy.types.INFO_MT_mesh_add, menuFunc )
- # DEBUGGING SECION...
- def deleteMeshes():
- obs = bpy.context.scene.objects
- for ob in obs:
- if ob.type == 'MESH':
- obs.unlink( ob )
- # test method to verify that the function that generates the pyramid actually works.
- def testPyramidGeneration():
- mesh = makePyramid( initialSize=1.0, stepHeight=0.3, stepWidth=0.1, numberSteps=5 )
- scene = bpy.context.scene
- for ob in scene.objects:
- ob.selected = False
- mesh.update()
- ob_new = bpy.data.add_object( 'MESH', "Pyramid" )
- ob_new.data = mesh
- scene.objects.link( ob_new )
- # leave these 2 lines commented out when not validating the makePyramid method.
- deleteMeshes()
- testPyramidGeneration()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement