fix for error in line 164
[blender-addons-contrib.git] / mesh_extra_tools / mesh_bump.py
1 # mesh_bump.py Copyright (C) 2011, Dolf Veenvliet
2 #
3 # Extrude a selection from a mesh multiple times
4 #
5 # ***** BEGIN GPL LICENSE BLOCK *****
6 #
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #
22 # ***** END GPL LICENCE BLOCK *****
23
24 bl_info = {
25         "name": "Bump",
26         "author": "Dolf Veenvliet",
27         "version": 1,
28         "blender": (2, 5, 6),
29         "api": 31847,
30         "location": "View3D > Specials > Bump",
31         "description": "Extrude and translate/rotate/scale multiple times",
32         "warning": "",
33         "wiki_url": "",
34         "tracker_url": "",
35         "category": "Mesh"}
36         
37         
38 """
39 Usage:
40
41 Launch from "W-menu"
42
43 Additional links:
44         Author Site: http://www.macouno.com
45         e-mail: dolf {at} macouno {dot} com
46 """
47
48 import bpy
49 from bpy.props import EnumProperty, FloatVectorProperty, FloatProperty, BoolProperty
50 from . import mesh_extras
51
52 # Bump stuff!
53 class Bump():
54
55         # Initialise the class
56         def __init__(self, context, type, scale, steps):
57         
58                 self.ob = context.active_object
59                 bpy.ops.object.mode_set(mode='OBJECT')
60                 
61                 translate = mesh_extras.get_average_outer_edge_length()
62                 #inset = mesh_extras.get_shortest_outer_edge_length() * 0.25
63                 
64                 translate *= scale
65                 
66                 bpy.ops.object.mode_set(mode='EDIT')
67                 
68                 stepped = 0
69         
70                 # Simple... we just do a bunch of steps... set in stone... easy!
71                 if type == 'BUM':
72                 
73                         self.extrude()
74                         
75                         bpy.ops.object.mode_set(mode='OBJECT')
76                         bpy.ops.object.mode_set(mode='EDIT')
77                         
78                         self.shrink(-translate)
79                         self.shrink(translate*0.3)
80                         
81                         stepped += 1
82                 
83                 # Spike!
84                 elif type == 'SPI':
85                 
86                         for i in range(3):
87                 
88                                 self.extrude()
89                                 
90                                 bpy.ops.object.mode_set(mode='OBJECT')
91                                 bpy.ops.object.mode_set(mode='EDIT')
92                                 
93                                 if not i:
94                                         f = 0.5
95                                 elif i == 1:
96                                         f = 0.3
97                                 elif i == 2:
98                                         f = 0.2
99                                 
100                                 t = translate * f
101                                 
102                                 self.shrink(-t)
103                                 self.shrink(t * (2 * f))
104                                 
105                                 stepped += 1
106                                 
107                 # Dimple!
108                 elif type == 'DIM' or type == 'PIM':
109                 
110                         self.extrude()
111                         bpy.ops.object.mode_set(mode='OBJECT')
112                         bpy.ops.object.mode_set(mode='EDIT')
113                         
114                         self.shrink(-translate * 0.2)
115                         
116                         self.extrude()
117                         bpy.ops.object.mode_set(mode='OBJECT')
118                         bpy.ops.object.mode_set(mode='EDIT')
119                         
120                         self.shrink(translate * 0.2)
121                         self.shrink(-translate * 0.2)
122                         
123                         if type == 'PIM':
124                                 self.extrude()
125                                 bpy.ops.object.mode_set(mode='OBJECT')
126                                 bpy.ops.object.mode_set(mode='EDIT')
127                         
128                                 self.shrink(-translate * 0.2)
129                                 stepped = 3
130                         else:
131                                 stepped = 2
132                         
133                         
134                         
135
136                 if steps:
137                         self.ob['growsteps'] = stepped
138                 
139         
140                 
141         # Extrude the selection (do not move it)
142         def extrude(self):
143                 bpy.ops.mesh.extrude_faces_move()
144                 
145         # SHrink!
146         def shrink(self,v):
147                 bpy.ops.transform.shrink_fatten(value=v, mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
148                 
149         
150
151 class Bump_init(bpy.types.Operator):
152         '''Bump by extruding and moving/rotating/scaling multiple times'''
153         bl_idname = 'mesh.bump'
154         bl_label = 'Inset Extrude Bump'
155         bl_options = {'REGISTER', 'UNDO'}
156         
157         # The falloffs we use
158         types=(
159                 ('BUM', 'Bump',''),
160                 ('SPI', 'Spike',''),
161                 ('DIM', 'Dimple',''),
162                 ('PIM', 'Pimple',''),
163                 )
164         
165         type = EnumProperty(items=types, name='Type', description='The type of bump', default='BUM')
166         
167         # Scale
168         scale = FloatProperty(name='Scale factor', description='Translation in Blender units', default=1.0, min=0.01, max=1000.0, soft_min=0.01, soft_max=1000.0, step=10, precision=2)
169         
170         steps = BoolProperty(name='Retain steps', description='Keep the step count in a property', default=False)
171
172         @classmethod
173         def poll(cls, context):
174                 obj = context.active_object
175                 return (obj and obj.type == 'MESH' and bpy.context.tool_settings.mesh_select_mode[0] == False and bpy.context.tool_settings.mesh_select_mode[1] == False and bpy.context.tool_settings.mesh_select_mode[2] == True)
176
177         def execute(self, context):
178                 BUMP = Bump(context, self.type, self.scale, self.steps) 
179                 return {'FINISHED'}
180
181 class bump_help(bpy.types.Operator):
182         bl_idname = 'help.bump'
183         bl_label = ''
184
185         def draw(self, context):
186                 layout = self.layout
187                 layout.label('To use:')
188                 layout.label('Make a selection or selection of Faces ')
189                 layout.label('Choose from the bump types in the menu.')
190                 layout.label('Keep extrusions small to prevent overlapping.')
191         
192         def execute(self, context):
193                 return {'FINISHED'}
194
195         def invoke(self, context, event):
196                 return context.window_manager.invoke_popup(self, width = 300)           
197 '''
198 def menu_func(self, context):
199         self.layout.operator(Bump_init.bl_idname, text="Bump")
200
201 def register():
202         bpy.utils.register_module(__name__)
203         bpy.types.VIEW3D_MT_edit_mesh_specials.append(menu_func)
204
205 def unregister():
206         bpy.utils.unregister_module(__name__)
207         bpy.types.VIEW3D_MT_edit_mesh_specials.remove(menu_func)
208
209 if __name__ == "__main__":
210         register()
211 '''