1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
8 from mathutils
import geometry
11 def add_vertex_to_intersection():
13 obj
= bpy
.context
.object
15 bm
= bmesh
.from_edit_mesh(me
)
17 edges
= [e
for e
in bm
.edges
if e
.select
]
20 [[v1
, v2
], [v3
, v4
]] = [[v
.co
for v
in e
.verts
] for e
in edges
]
22 iv
= geometry
.intersect_line_line(v1
, v2
, v3
, v4
)
24 iv
= (iv
[0] + iv
[1]) / 2
27 bm
.verts
.ensure_lookup_table()
29 bm
.verts
[-1].select
= True
30 bmesh
.update_edit_mesh(me
)
33 class TCVert2Intersection(bpy
.types
.Operator
):
34 '''Add a vertex at the intersection (projected or real) of two selected edges'''
35 bl_idname
= 'tinycad.vertintersect'
36 bl_label
= 'V2X vertex to intersection'
37 bl_options
= {'REGISTER', 'UNDO'}
40 def poll(cls
, context
):
41 obj
= context
.active_object
42 return obj
is not None and obj
.type == 'MESH' and obj
.mode
== 'EDIT'
44 def execute(self
, context
):
45 add_vertex_to_intersection()