1 # mesh_relax.py Copyright (C) 2010, Fabian Fricke
3 # Relaxes selected vertices while retaining the shape as much as possible
5 # ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
22 # ***** END GPL LICENCE BLOCK *****
26 "author": "Fabian Fricke",
28 "blender": (2, 57, 0),
29 "location": "View3D > Specials > Relax ",
30 "description": "Relax the selected verts while retaining the shape",
32 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"\
33 "Scripts/Modeling/Relax",
34 "tracker_url": "https://projects.blender.org/tracker/index.php?"\
35 "func=detail&aid=21421",
41 Launch from "W-menu" or from "Mesh -> Vertices -> Relax"
45 Author Site: http://frigi.designdevil.de
46 e-mail: frigi.f {at} gmail {dot} com
51 from bpy
.props
import IntProperty
53 def relax_mesh(context
):
55 # deselect everything that's not related
56 for obj
in context
.selected_objects
:
60 obj
= context
.active_object
62 # duplicate the object so it can be used for the shrinkwrap modifier
63 obj
.select
= True # make sure the object is selected!
64 bpy
.ops
.object.mode_set(mode
='OBJECT')
65 bpy
.ops
.object.duplicate()
66 target
= context
.active_object
68 # remove all other modifiers from the target
69 for m
in range(0, len(target
.modifiers
)):
70 target
.modifiers
.remove(target
.modifiers
[0])
72 context
.scene
.objects
.active
= obj
74 sw
= obj
.modifiers
.new(type='SHRINKWRAP', name
='relax_target')
77 # run smooth operator to relax the mesh
78 bpy
.ops
.object.mode_set(mode
='EDIT')
79 bpy
.ops
.mesh
.vertices_smooth()
80 bpy
.ops
.object.mode_set(mode
='OBJECT')
83 bpy
.ops
.object.modifier_apply(modifier
='relax_target')
85 # delete the target object
88 bpy
.ops
.object.delete()
90 # go back to initial state
92 bpy
.ops
.object.mode_set(mode
='EDIT')
94 class Relax(bpy
.types
.Operator
):
95 """Relaxes selected vertices while retaining the shape """ \
96 """as much as possible"""
97 bl_idname
= 'mesh.relax'
99 bl_options
= {'REGISTER', 'UNDO'}
101 iterations
= IntProperty(name
="Relax iterations",
102 default
=1, min=0, max=100, soft_min
=0, soft_max
=10)
105 def poll(cls
, context
):
106 obj
= context
.active_object
107 return (obj
and obj
.type == 'MESH')
109 def execute(self
, context
):
110 for i
in range(0,self
.iterations
):
115 def menu_func(self
, context
):
116 self
.layout
.operator(Relax
.bl_idname
, text
="Relax")
120 bpy
.utils
.register_module(__name__
)
122 bpy
.types
.VIEW3D_MT_edit_mesh_specials
.append(menu_func
)
123 bpy
.types
.VIEW3D_MT_edit_mesh_vertices
.append(menu_func
)
126 bpy
.utils
.unregister_module(__name__
)
128 bpy
.types
.VIEW3D_MT_edit_mesh_specials
.remove(menu_func
)
129 bpy
.types
.VIEW3D_MT_edit_mesh_vertices
.remove(menu_func
)
131 if __name__
== "__main__":