1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
8 from mathutils
.geometry
import intersect_line_plane
11 def failure_message(self
):
12 self
.report({"WARNING"}, 'select 1 face and 1 detached edge')
14 def failure_message_on_plane(self
):
16 Edge2Face expects the edge to intersect at one point on the plane of the selected face. You're
17 seeing this warning because mathutils.geometry.intersect_line_plane is being called on an edge/face
18 combination that has no clear intersection point ( both points of the edge either touch the same
19 plane as the face or they lie in a plane that is offset along the face's normal )"""
20 lines
= msg2
.split('\n')
22 self
.report({'INFO'}, line
)
23 self
.report({"WARNING"}, 'No intersection found, see the info panel for details')
26 def extend_vertex(self
):
28 obj
= bpy
.context
.edit_object
30 bm
= bmesh
.from_edit_mesh(me
)
34 planes
= [f
for f
in faces
if f
.select
]
35 if not (len(planes
) == 1):
40 plane_vert_indices
= [v
for v
in plane
.verts
[:]]
41 all_selected_vert_indices
= [v
for v
in verts
if v
.select
]
43 M
= set(plane_vert_indices
)
44 N
= set(all_selected_vert_indices
)
52 (v1_ref
, v1
), (v2_ref
, v2
) = [(i
, i
.co
) for i
in O
]
54 plane_co
= plane
.calc_center_median()
55 plane_no
= plane
.normal
57 new_co
= intersect_line_plane(v1
, v2
, plane_co
, plane_no
, False)
60 new_vertex
= verts
.new(new_co
)
61 A_len
= (v1
- new_co
).length
62 B_len
= (v2
- new_co
).length
64 vertex_reference
= v1_ref
if (A_len
< B_len
) else v2_ref
65 bm
.edges
.new([vertex_reference
, new_vertex
])
66 bmesh
.update_edit_mesh(me
, loop_triangles
=True)
69 failure_message_on_plane(self
)
73 class TCEdgeToFace(bpy
.types
.Operator
):
74 '''Extend selected edge towards projected intersection with a selected face'''
75 bl_idname
= 'tinycad.edge_to_face'
76 bl_label
= 'E2F edge to face'
77 bl_options
= {'REGISTER', 'UNDO'}
80 def poll(cls
, context
):
82 return all([bool(ob
), ob
.type == 'MESH', ob
.mode
== 'EDIT'])
84 def execute(self
, context
):