Skip to content
Snippets Groups Projects
add_mesh_archimedean_solids.py 36.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • class AddTruncatedOctahedron(bpy.types.Operator):
        '''Add a mesh for a truncated octahedron.'''
        bl_idname = 'mesh.primitive_truncated_octahedron_add'
        bl_label = 'Add Truncated Octahedron'
        bl_description = 'Create a mesh for a truncated octahedron.'
        bl_options = {'REGISTER', 'UNDO'}
    
        # edit - Whether to add or update.
        edit = BoolProperty(name='',
            description='',
            default=False,
            options={'HIDDEN'})
        hexagon_side = FloatProperty(name='Hexagon Side',
            description='One length of the hexagon side' \
                ' (on the original octahedron edge).',
            min=0.01,
            max=sqrt(2) - 0.1,
            default=sqrt(2) / 3.0)
        star_ngons = BoolProperty(name='Star N-Gon',
            description='Create star-shaped hexagons.',
            default=False)
    
        def execute(self, context):
            props = self.properties
    
            verts, faces = add_truncated_octahedron(
                props.hexagon_side,
                props.star_ngons)
    
            if not verts:
                return {'CANCELLED'}
    
            obj = create_mesh_object(context, verts, [], faces,
                'TrOctahedron', props.edit)
    
            # Store 'recall' properties in the object.
            recall_args_list = {
                'edit': True,
                'hexagon_side': props.hexagon_side,
                'star_ngons': props.star_ngons}
            store_recall_properties(obj, self, recall_args_list)
    
            return {'FINISHED'}
    
    
    
    class INFO_MT_mesh_archimedean_solids_add(bpy.types.Menu):
        # Define the "Archimedean Solids" menu
        bl_idname = "INFO_MT_mesh_archimedean_solids_add"
        bl_label = "Archimedean Solids"
    
        def draw(self, context):
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
            layout.operator("mesh.primitive_truncated_tetrahedron_add",
                text="Truncated Tetrahedron")
    
            layout.operator("mesh.primitive_cuboctahedron_add",
    
                text="Cuboctahedron or Truncated Cube")
            layout.operator("mesh.primitive_rhombicuboctahedron_add",
    
                text="Rhombicuboctahedron")
    
            layout.operator("mesh.primitive_truncated_octahedron_add",
                text="Truncated Octahedron")
    
    import space_info
    
    # Define "Archimedean Solids" menu
    menu_func = (lambda self, context: self.layout.menu(
        "INFO_MT_mesh_archimedean_solids_add", icon="PLUGIN"))
    
    
    def register():
        # Register the operators/menus.
        bpy.types.register(AddTruncatedTetrahedron)
    
        bpy.types.register(AddCuboctahedron)
        bpy.types.register(AddRhombicuboctahedron)
    
        bpy.types.register(AddTruncatedOctahedron)
    
        bpy.types.register(INFO_MT_mesh_archimedean_solids_add)
    
        # Add "Archimedean Solids" menu to the "Add Mesh" menu
        space_info.INFO_MT_mesh_add.append(menu_func)
    
    
    def unregister():
        # Unregister the operators/menus.
        bpy.types.unregister(AddTruncatedTetrahedron)
    
        bpy.types.unregister(AddCuboctahedron)
        bpy.types.unregister(AddRhombicuboctahedron)
    
        bpy.types.unregister(AddTruncatedOctahedron)
    
        bpy.types.unregister(INFO_MT_mesh_archimedean_solids_add)
    
        # Remove "Archimedean Solids" menu from the "Add Mesh" menu.
        space_info.INFO_MT_mesh_add.remove(menu_func)
    
    if __name__ == "__main__":
        register()