1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
22 "name": "Vertex Chamfer",
23 "author": "Andrew Hale (TrumanBlending)",
26 "location": "Spacebar Menu",
27 "description": "Chamfer vertex",
37 class VertexChamfer(bpy.types.Operator):
38 bl_idname = "mesh.vertex_chamfer"
39 bl_label = "Chamfer Vertex"
40 bl_options = {'REGISTER', 'UNDO'}
42 factor = bpy.props.FloatProperty(name="Factor",
46 relative = bpy.props.BoolProperty(name="Relative", default=True)
47 dissolve = bpy.props.BoolProperty(name="Remove", default=True)
48 displace = bpy.props.FloatProperty(name="Displace",
53 def poll(self, context):
54 return (context.active_object.type == 'MESH' and
55 context.mode == 'EDIT_MESH')
57 def draw(self, context):
59 layout.prop(self, "factor", text="Fac" if self.relative else "Dist")
61 sub.prop(self, "relative")
62 sub.prop(self, "dissolve")
64 layout.prop(self, "displace")
66 def execute(self, context):
67 ob = context.active_object
69 bm = bmesh.from_edit_mesh(me)
75 dissolve = self.dissolve
76 displace = self.displace
81 # Loop over edges to find those with both verts selected
86 elen = e.calc_length()
87 val = fac if rel else fac / elen
89 # Loop over the verts of the edge to split
91 #if val == 0.5 and e.other_vert(v).tag:
93 en, vn = bmesh.utils.edge_split(e, v, val)
94 en.tag = vn.tag = True
95 val = 1.0 if val == 1.0 else val / (1.0 - val)
97 # Get all verts which are selected but not created previously
98 verts = [v for v in bm.verts if v.select and not v.tag]
100 # Loop over all verts to split their linked edges
102 for e in v.link_edges[:]:
105 elen = e.calc_length()
106 val = fac if rel else fac / elen
107 bmesh.utils.edge_split(e, v, val)
109 # Loop over all the loops of the vert
110 for l in v.link_loops:
112 bmesh.utils.face_split(l.face,
113 l.link_loop_next.vert,
114 l.link_loop_prev.vert)
116 # Remove the vert or displace otherwise
118 bmesh.utils.vert_dissolve(v)
120 v.co += displace * v.normal
128 bpy.utils.register_module(__name__)
132 bpy.utils.unregister_module(__name__)
135 if __name__ == "__main__":