I have decided to post the code as it is right now, it is not what i had working in blender 2.49.
To anybody who wants to help
I need help creating edges between those rounded corners, between first vertex of the path and first corner and last vertex of the path and last corner.
# -*- coding: utf-8 -*-
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****
# ------ ------
bl_info = {
'name': 'fillet',
'author': '',
'version': (0, 0, 1),
'blender': (2, 5, 8),
'api': 36812,
'location': '',
'description': '',
'warning': '',
'wiki_url': '',
'tracker_url': '',
'category': 'Mesh' }
# ------ ------
import bpy
from bpy.props import FloatProperty, IntProperty
from mathutils import Vector, Matrix
from math import degrees, radians, cos
# ------ ------
def edit_mode_out(): # edit mode out
bpy.ops.object.mode_set(mode = 'OBJECT')
def edit_mode_in(): # edit mode in
bpy.ops.object.mode_set(mode = 'EDIT')
def get_adj_v_(me): # get vert adj to sel vert
for e in me.edges:
try: f_buf.dict_0[e.key[0]].append(e.key[1])
except KeyError: f_buf.dict_0[e.key[0]] = [e.key[1]]
try: f_buf.dict_0[e.key[1]].append(e.key[0])
except KeyError: f_buf.dict_0[e.key[1]] = [e.key[0]]
# ------ ------ ------ ------
def list_clear_(l):
l[:] = []
return l
# ------ ------ ------ ------
class f_buf():
me_data = []
dict_0 = {}
def f_(me, adj, n):
me_t = f_buf.me_data
list_0 = [v.index for v in me_t.vertices if v.select] # selected vertices
list_1 = [] # list of vert indices of arcs
dict_1 = {} # dict of v index as key and index of first and last vert of arc as value
for vi in list_0:
p = me_t.vertices[vi].co
if len(f_buf.dict_0[vi]) != 2:
pass
else:
p1 = me_t.vertices[f_buf.dict_0[vi][0]].co
p2 = me_t.vertices[f_buf.dict_0[vi][1]].co
vec1 = p - p1
vec2 = p - p2
ang = vec1.angle(vec2)
if ang == radians(180):
dict_1[vi] = vi
else:
h = adj * (1 / cos(ang / 2))
p3 = p - (vec1.normalized() * adj)
p4 = p - (vec2.normalized() * adj)
rp = p - ((p - ((p3 + p4) * 0.5)).normalized() * h)
vec3 = rp - p3
vec4 = rp - p4
rot_ang = vec3.angle(vec4)
axis = vec1.cross(vec2)
for i in range(n + 1):
new_angle = rot_ang * i / n
mtrx = Matrix.Rotation(new_angle, 3, axis)
tmp = p4 - rp
tmp1 = tmp * mtrx
tmp2 = tmp1 + rp
me.vertices.add(1)
me.vertices[-1].co = tmp2
list_1.append(me.vertices[-1].index)
dict_1[vi] = [list_1[0], list_1[-1]]
# ------ make edges between points of arc ------
n1 = len(list_1)
for j in range(n1 - 1):
a = list_1[j]
b = list_1[(j + 1) % n1]
me.edges.add(1)
me.edges[-1].vertices = [a, b]
list_clear_(list_1)
'''
# ------ make edges between arcs ------
for k in list_0:
a = dict_1[k]
kn = f_buf.dict_0[k]
if kn[0] in list_0:
b = dict_1[kn[0]]
me.edges.add(1)
me.edges[-1].vertices = [a[1], b[0]]
elif kn[1] in list_0:
b = dict_1[kn[1]]
me.edges.add(1)
me.edges[-1].vertices = [a[0], b[1]]
else:
me.edges.add(2)
me.edges[-1].vertices = [a[0], kn[1]]
me.edges[-2].vertices = [a[1], kn[0]]
'''
# ------ panel 0 ------
class f_p0(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
#bl_idname = 'f_p0_id'
bl_label = 'Fillet'
bl_context = 'mesh_edit'
def draw(self, context):
layout = self.layout
layout.operator('f.op0_id', text = 'Fillet')
# ------ operator 0 ------
class f_op0(bpy.types.Operator):
bl_idname = 'f.op0_id'
bl_label = 'fillet'
bl_options = {'REGISTER', 'UNDO'}
adj = FloatProperty( default = 0.4, min = -100.0, max = 100.0, step = 10, precision = 3 )
n = IntProperty( name = '', default = 4, min = 1, max = 100, step = 1 )
def draw(self, context):
layout = self.layout
layout.label('distance')
layout.prop(self, 'adj')
layout.label('number of sides')
layout.prop(self, 'n')
def execute(self, context):
n = self.n
adj = self.adj
edit_mode_out()
ob_act = context.active_object
me = ob_act.data
# -- -- -- --
f_buf.dict_0.clear()
get_adj_v_(me)
f_buf.me_data = me.copy()
# -- -- -- --
edit_mode_in()
#bpy.ops.mesh.delete(type = 'EDGE')
edit_mode_out()
# -- -- -- --
f_(me, adj, n)
# -- -- -- --
edit_mode_in()
bpy.data.meshes.remove(f_buf.me_data)
return {'FINISHED'}
# ------ ------
class_list = [ f_p0,
f_op0 ]
# ------ register ------
def register():
for c in class_list:
bpy.utils.register_class(c)
# ------ unregister ------
def unregister():
for c in class_list:
bpy.utils.unregister_class(c)
# ------ ------
if __name__ == "__main__":
register()