1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 # ----------------------------------------------------------
8 # Modified by: Alan Odom (Clockmender) & Rune Morling (ermo)
9 # ----------------------------------------------------------
14 from . import pdt_cad_module
as cm
15 from .pdt_msg_strings
import (
20 from .pdt_functions
import debug
, oops
23 def add_line_to_bisection(context
):
24 """Computes Bisector of 2 Co-Planar Edges.
27 context: Blender bpy.context instance
34 if all([bool(obj
), obj
.type == "MESH", obj
.mode
== "EDIT"]):
35 pg
= context
.scene
.pdt_pg
37 bm
= bmesh
.from_edit_mesh(obj_data
)
39 bm
.verts
.ensure_lookup_table()
40 bm
.edges
.ensure_lookup_table()
42 edges
= [e
for e
in bm
.edges
if e
.select
and not e
.hide
]
44 if not len(edges
) == 2:
45 pg
.error
= f
"{PDT_ERR_2CPNPE}"
46 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
49 [[vector_a
, vector_b
], [vector_c
, vector_d
]] = [[v
.co
for v
in e
.verts
] for e
in edges
]
50 debug(f
"vectors found:\n {vector_a}\n {vector_b}\n {vector_c}\n {vector_d}")
52 dist1
= (vector_a
- vector_b
).length
53 dist2
= (vector_c
- vector_d
).length
54 bdist
= min([dist1
, dist2
])
55 edge1
= (vector_a
, vector_b
)
56 edge2
= (vector_c
, vector_d
)
58 if not cm
.test_coplanar(edge1
, edge2
):
59 pg
.error
= PDT_ERR_NCEDGES
60 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
63 # get intersect_point and pick farthest vertex from (projected) intersections
64 intersect_point
= cm
.get_intersection(edge1
, edge2
)
67 if (vector_a
- intersect_point
).length
< (vector_b
- intersect_point
).length
72 if (vector_c
- intersect_point
).length
< (vector_d
- intersect_point
).length
76 dex1
= far1
- intersect_point
77 dex2
= far2
- intersect_point
78 dex1
= dex1
* (bdist
/ dex1
.length
)
79 dex2
= dex2
* (bdist
/ dex2
.length
)
80 intersect_point2
= intersect_point
+ (dex1
).lerp(dex2
, 0.5)
81 intersect_point3
= intersect_point2
.lerp(intersect_point
, 2.0)
83 vec1
= bm
.verts
.new(intersect_point2
)
84 vec2
= bm
.verts
.new(intersect_point
)
85 vec3
= bm
.verts
.new(intersect_point3
)
86 bm
.edges
.new((vec1
, vec2
))
87 bm
.edges
.new((vec2
, vec3
))
88 bmesh
.ops
.remove_doubles(bm
, verts
=bm
.verts
, dist
=0.0001)
89 bmesh
.update_edit_mesh(obj_data
)
91 pg
.error
= f
"{PDT_ERR_EDOB_MODE},{obj.mode})"
92 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
96 class PDT_OT_LineOnBisection(bpy
.types
.Operator
):
97 """Create Bisector between 2 Selected Edges"""
99 bl_idname
= "pdt.linetobisect"
100 bl_label
= "Add Edges Bisector"
101 bl_options
= {"REGISTER", "UNDO"}
104 def poll(cls
, context
):
105 """Only allow operation on a mesh object in EDIT mode.
108 context: Blender bpy.context instance.
114 obj
= context
.active_object
117 return all([obj
is not None, obj
.type == "MESH", obj
.mode
== "EDIT"])
119 def execute(self
, context
):
120 """Computes Bisector of 2 Co-Planar Edges.
123 Requires an Active Object
124 Active Object must be Mesh type
125 Active Object must be in Edit Mode.
128 context: Blender bpy.context instance.
134 pg
= context
.scene
.pdt_pg