def generate_bmesh_repr(p1, v1, axis, num_verts):
'''
p1: center of circle (local coordinates)
v1: first vertex of circle in (local coordinates)
axis: orientation matrix
origin: obj.location
'''
props = bpy.context.scene.tinycad_props
rescale = props.rescale
# generate geometry up front
chain = []
gamma = 2 * math.pi / num_verts
for i in range(num_verts + 1):
theta = gamma * i
mat_rot = mathutils.Matrix.Rotation(theta, 4, axis)
local_point = (mat_rot * ((v1 - p1) * rescale))
chain.append(local_point + p1)
obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
# add verts
v_refs = []
for p in chain:
v = bm.verts.new(p)
v.select = False # this might be a default.. redundant?
v_refs.append(v)
# join verts, daisy chain
num_verts = len(v_refs)
for i in range(num_verts):
idx1 = i
idx2 = (i + 1) % num_verts
bm.edges.new([v_refs[idx1], v_refs[idx2]])
bmesh.update_edit_mesh(me, True)
评论列表
文章目录