1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # -----------------------------------------------------------------------
4 # Author: Alan Odom (Clockmender), Rune Morling (ermo) Copyright (c) 2019
5 # -----------------------------------------------------------------------
9 from math
import sqrt
, floor
, asin
, sin
, cos
, pi
10 from mathutils
import Vector
11 from bpy
.types
import Operator
13 from .pdt_functions
import (
21 from .pdt_msg_strings
import (
32 from . import pdt_exception
34 PDT_ObjectModeError
= pdt_exception
.ObjectModeError
35 PDT_SelectionError
= pdt_exception
.SelectionError
38 def get_tangent_intersect_outer(hloc_0
, vloc_0
, hloc_1
, vloc_1
, radius_0
, radius_1
):
39 """Return Location in 2 Dimensions of the Intersect Point for Outer Tangents.
42 hloc_0: Horizontal Coordinate of Centre of First Arc
43 vloc_0: Vertical Coordinate of Centre of First Arc
44 hloc_1: Horizontal Coordinate of Centre of Second Arc
45 vloc_1: Vertical Coordinate of Centre of Second Arc
46 radius_0: Radius of First Arc
47 radius_1: Radius of Second Arc
50 hloc_p: Horizontal Coordinate of Centre of Intersection
51 vloc_p: Vertical Coordinate of Centre of Intersection.
54 hloc_p
= ((hloc_1
* radius_0
) - (hloc_0
* radius_1
)) / (radius_0
- radius_1
)
55 vloc_p
= ((vloc_1
* radius_0
) - (vloc_0
* radius_1
)) / (radius_0
- radius_1
)
60 def get_tangent_intersect_inner(hloc_0
, vloc_0
, hloc_1
, vloc_1
, radius_0
, radius_1
):
61 """Return Location in 2 Dimensions of the Intersect Point for Inner Tangents.
64 hloc_0: Horizontal Coordinate of Centre of First Arc
65 vloc_0: Vertical Coordinate of Centre of First Arc
66 hloc_1: Horizontal Coordinate of Centre of Second Arc
67 vloc_1: Vertical Coordinate of Centre of Second Arc
68 radius_0: Radius of First Arc
69 radius_1: Radius of Second Arc
72 hloc_p: Horizontal Coordinate of Centre of Intersection
73 vloc_p: Vertical Coordinate of Centre of Intersection.
76 hloc_p
= ((hloc_1
* radius_0
) + (hloc_0
* radius_1
)) / (radius_0
+ radius_1
)
77 vloc_p
= ((vloc_1
* radius_0
) + (vloc_0
* radius_1
)) / (radius_0
+ radius_1
)
82 def get_tangent_points(context
, hloc_0
, vloc_0
, radius_0
, hloc_p
, vloc_p
):
83 """Return Location in 2 Dimensions of the Tangent Points.
86 context: Blender bpy.context instance
87 hloc_0: Horizontal Coordinate of Centre of First Arc
88 vloc_0: Vertical Coordinate of Centre of First Arc
89 radius_0: Radius of First Arc
90 hloc_p: Horizontal Coordinate of Intersection
91 vloc_p: Vertical Coordinate of Intersection
94 hloc_t1: Horizontal Location of First Tangent Point
95 hloc_t2: Horizontal Location of Second Tangent Point
96 vloc_t1: Vertical Location of First Tangent Point
97 vloc_t2: Vertical Location of Second Tangent Point
100 # Uses basic Pythagorus' theorem to compute locations
102 numerator
= (radius_0
** 2 * (hloc_p
- hloc_0
)) + (
105 * sqrt((hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2 - radius_0
** 2)
107 denominator
= (hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2
108 hloc_t1
= round((numerator
/ denominator
) + hloc_0
, 5)
110 numerator
= (radius_0
** 2 * (hloc_p
- hloc_0
)) - (
113 * sqrt((hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2 - radius_0
** 2)
115 denominator
= (hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2
116 hloc_t2
= round((numerator
/ denominator
) + hloc_0
, 5)
119 numerator
= (radius_0
** 2 * (vloc_p
- vloc_0
)) - (
122 * sqrt((hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2 - radius_0
** 2)
124 denominator
= (hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2
125 vloc_t1
= round((numerator
/ denominator
) + vloc_0
, 5)
127 numerator
= (radius_0
** 2 * (vloc_p
- vloc_0
)) + (
130 * sqrt((hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2 - radius_0
** 2)
132 denominator
= (hloc_p
- hloc_0
) ** 2 + (vloc_p
- vloc_0
) ** 2
133 vloc_t2
= round((numerator
/ denominator
) + vloc_0
, 5)
135 return hloc_t1
, hloc_t2
, vloc_t1
, vloc_t2
138 def make_vectors(coords
, a1
, a2
, a3
, pg
):
139 """Return Vectors of the Tangent Points.
142 coords: A List of Coordinates in 2D space of the tangent points
143 & a third dimension for the vectors
144 a1: Index of horizontal axis
145 a2: Index of vertical axis
146 a3: Index of depth axis
147 pg: PDT Parameters Group - our variables
150 tangent_vector_o1: Location of First Tangent Point
151 tangent_vector_o2: Location of Second Tangent Point
152 tangent_vector_o3: Location of First Tangent Point
153 tangent_vector_o4: Location of Second Tangent Point
156 tangent_vector_o1
= Vector((0, 0, 0))
157 tangent_vector_o1
[a1
] = coords
[0]
158 tangent_vector_o1
[a2
] = coords
[1]
159 tangent_vector_o1
[a3
] = coords
[8]
160 tangent_vector_o2
= Vector((0, 0, 0))
161 tangent_vector_o2
[a1
] = coords
[2]
162 tangent_vector_o2
[a2
] = coords
[3]
163 tangent_vector_o2
[a3
] = coords
[8]
164 tangent_vector_o3
= Vector((0, 0, 0))
165 tangent_vector_o3
[a1
] = coords
[4]
166 tangent_vector_o3
[a2
] = coords
[5]
167 tangent_vector_o3
[a3
] = coords
[8]
168 tangent_vector_o4
= Vector((0, 0, 0))
169 tangent_vector_o4
[a1
] = coords
[6]
170 tangent_vector_o4
[a2
] = coords
[7]
171 tangent_vector_o4
[a3
] = coords
[8]
174 # Reset coordinates from view local (Horiz, Vert, depth) to World XYZ.
176 tangent_vector_o1
= view_coords(
177 tangent_vector_o1
[a1
], tangent_vector_o1
[a2
], tangent_vector_o1
[a3
]
179 tangent_vector_o2
= view_coords(
180 tangent_vector_o2
[a1
], tangent_vector_o2
[a2
], tangent_vector_o2
[a3
]
182 tangent_vector_o3
= view_coords(
183 tangent_vector_o3
[a1
], tangent_vector_o3
[a2
], tangent_vector_o3
[a3
]
185 tangent_vector_o4
= view_coords(
186 tangent_vector_o4
[a1
], tangent_vector_o4
[a2
], tangent_vector_o4
[a3
]
189 return (tangent_vector_o1
, tangent_vector_o2
, tangent_vector_o3
, tangent_vector_o4
)
192 def tangent_setup(context
, pg
, plane
, obj_data
, centre_0
, centre_1
, centre_2
, radius_0
, radius_1
):
193 """This section sets up all the variables required for the tangent functions.
196 context: Blender bpy.context instance
197 pg: PDT Parameter Group of variables
199 obj_data: All the data of the chosen object
200 centre_0: Centre coordinates of the first arc
201 centre_1: Centre coordinates of the second arc
202 centre_2: Coordinates of the point
203 radius_0: Radius of the first Arc
204 radius_1: Radius of the second Arc
210 a1
, a2
, a3
= set_mode(plane
)
211 mode
= pg
.tangent_mode
213 # Translate world coordinates into view local (horiz, vert, depth)
215 centre_0
= view_coords_i(centre_0
[a1
], centre_0
[a2
], centre_0
[a3
])
216 centre_1
= view_coords_i(centre_1
[a1
], centre_1
[a2
], centre_1
[a3
])
217 centre_2
= view_coords_i(centre_2
[a1
], centre_2
[a2
], centre_2
[a3
])
218 if pg
.tangent_mode
== "point":
219 vector_difference
= centre_2
- centre_0
220 distance
= sqrt(vector_difference
[a1
] ** 2 + vector_difference
[a2
] ** 2)
222 vector_difference
= centre_1
- centre_0
223 distance
= sqrt(vector_difference
[a1
] ** 2 + vector_difference
[a2
] ** 2)
226 (distance
<= radius_0
and mode
in {"point"}) or
227 (distance
<= (radius_0
+ radius_1
) and mode
in {"inner", "both"}) or
228 (distance
<= radius_0
or distance
<= radius_1
and mode
in {"outer", "both"})
230 # Cannot execute, centres are too close.
232 pg
.error
= f
"{PDT_ERR_BADDISTANCE}"
233 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
236 """This next section will draw Point based Tangents.
238 These are drawn from a point to an Arc
243 (centre_2
[a1
] - centre_0
[a1
]) ** 2 + (centre_2
[a2
] - centre_0
[a2
]) ** 2 - radius_0
** 2
245 hloc_to1
, hloc_to2
, vloc_to1
, vloc_to2
= get_tangent_points(
246 context
, centre_0
[a1
], centre_0
[a2
], radius_0
, centre_2
[a1
], centre_2
[a2
]
249 pg
.error
= PDT_ERR_MATHSERROR
250 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
254 tangent_vector_o1
= Vector((0, 0, 0))
255 tangent_vector_o1
[a1
] = hloc_to1
256 tangent_vector_o1
[a2
] = vloc_to1
257 tangent_vector_o1
[a3
] = centre_2
[a3
]
258 tangent_vector_o2
= Vector((0, 0, 0))
259 tangent_vector_o2
[a1
] = hloc_to2
260 tangent_vector_o2
[a2
] = vloc_to2
261 tangent_vector_o2
[a3
] = centre_2
[a3
]
263 # Translate view local coordinates (horiz, vert, depth) into World XYZ
265 centre_2
= view_coords(centre_2
[a1
], centre_2
[a2
], centre_2
[a3
])
266 tangent_vector_o1
= view_coords(
267 tangent_vector_o1
[a1
], tangent_vector_o1
[a2
], tangent_vector_o1
[a3
]
269 tangent_vector_o2
= view_coords(
270 tangent_vector_o2
[a1
], tangent_vector_o2
[a2
], tangent_vector_o2
[a3
]
272 tangent_vectors
= (centre_2
, tangent_vector_o1
, tangent_vector_o2
)
273 draw_tangents(tangent_vectors
, obj_data
)
277 """This next section will draw Arc based Outer Tangents.
279 These are drawn from an Arc to another Arc
282 if mode
in {"outer", "both"}:
283 # Uses basic trigonometry and Pythagorus' theorem to compute locations
285 if radius_0
== radius_1
:
286 # No intersection point for outer tangents
288 sin_angle
= (centre_1
[a2
] - centre_0
[a2
]) / distance
289 cos_angle
= (centre_1
[a1
] - centre_0
[a1
]) / distance
290 hloc_to1
= centre_0
[a1
] + (radius_0
* sin_angle
)
291 hloc_to2
= centre_0
[a1
] - (radius_0
* sin_angle
)
292 hloc_to3
= centre_1
[a1
] + (radius_0
* sin_angle
)
293 hloc_to4
= centre_1
[a1
] - (radius_0
* sin_angle
)
294 vloc_to1
= centre_0
[a2
] - (radius_0
* cos_angle
)
295 vloc_to2
= centre_0
[a2
] + (radius_0
* cos_angle
)
296 vloc_to3
= centre_1
[a2
] - (radius_0
* cos_angle
)
297 vloc_to4
= centre_1
[a2
] + (radius_0
* cos_angle
)
299 hloc_po
, vloc_po
= get_tangent_intersect_outer(
300 centre_0
[a1
], centre_0
[a2
], centre_1
[a1
], centre_1
[a2
], radius_0
, radius_1
303 if ((hloc_po
- centre_0
[a1
]) ** 2 + (vloc_po
- centre_0
[a2
]) ** 2 - radius_0
** 2) > 0:
304 hloc_to1
, hloc_to2
, vloc_to1
, vloc_to2
= get_tangent_points(
305 context
, centre_0
[a1
], centre_0
[a2
], radius_0
, hloc_po
, vloc_po
308 pg
.error
= PDT_ERR_MATHSERROR
309 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
311 if ((hloc_po
- centre_0
[a1
]) ** 2 + (vloc_po
- centre_0
[a2
]) ** 2 - radius_1
** 2) > 0:
312 hloc_to3
, hloc_to4
, vloc_to3
, vloc_to4
= get_tangent_points(
313 context
, centre_1
[a1
], centre_1
[a2
], radius_1
, hloc_po
, vloc_po
316 pg
.error
= PDT_ERR_MATHSERROR
317 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
320 dloc_p
= centre_0
[a3
]
332 tangent_vectors
= make_vectors(coords_in
, a1
, a2
, a3
, pg
)
333 draw_tangents(tangent_vectors
, obj_data
)
335 """This next section will draw Arc based Inner Tangents.
337 These are drawn from an Arc to another Arc
340 if mode
in {"inner", "both"}:
341 # Uses basic trigonometry and Pythagorus' theorem to compute locations
343 hloc_pi
, vloc_pi
= get_tangent_intersect_inner(
344 centre_0
[a1
], centre_0
[a2
], centre_1
[a1
], centre_1
[a2
], radius_0
, radius_1
346 if ((hloc_pi
- centre_0
[a1
]) ** 2 + (vloc_pi
- centre_0
[a2
]) ** 2 - radius_0
** 2) > 0:
347 hloc_to1
, hloc_to2
, vloc_to1
, vloc_to2
= get_tangent_points(
348 context
, centre_0
[a1
], centre_0
[a2
], radius_0
, hloc_pi
, vloc_pi
351 pg
.error
= PDT_ERR_MATHSERROR
352 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
354 if ((hloc_pi
- centre_0
[a1
]) ** 2 + (vloc_pi
- centre_0
[a2
]) ** 2 - radius_0
** 2) > 0:
355 hloc_to3
, hloc_to4
, vloc_to3
, vloc_to4
= get_tangent_points(
356 context
, centre_1
[a1
], centre_1
[a2
], radius_1
, hloc_pi
, vloc_pi
359 pg
.error
= PDT_ERR_MATHSERROR
360 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
363 dloc_p
= centre_0
[a3
]
375 tangent_vectors
= make_vectors(coords_in
, a1
, a2
, a3
, pg
)
376 draw_tangents(tangent_vectors
, obj_data
)
381 def draw_tangents(tangent_vectors
, obj_data
):
382 """Add Edges Representing the Tangents.
385 The length of the tanget_vectors determines which tangents will be
386 drawn, 3 gives Point Tangents, 4 gives Inner/Outer tangents
389 tangent_vectors: A list of vectors representing the tangents
390 obj_data: A list giving Object, Object Location and Object Bmesh
396 obj_loc
= obj_data
[1]
398 if len(tangent_vectors
) == 3:
399 point_vertex_outer
= bm
.verts
.new(tangent_vectors
[0] - obj_loc
)
400 tangent_vertex_o1
= bm
.verts
.new(tangent_vectors
[1] - obj_loc
)
401 tangent_vertex_o2
= bm
.verts
.new(tangent_vectors
[2] - obj_loc
)
402 bm
.edges
.new([tangent_vertex_o1
, point_vertex_outer
])
403 bm
.edges
.new([tangent_vertex_o2
, point_vertex_outer
])
405 tangent_vertex_o1
= bm
.verts
.new(tangent_vectors
[0] - obj_loc
)
406 tangent_vertex_o2
= bm
.verts
.new(tangent_vectors
[2] - obj_loc
)
407 tangent_vertex_o3
= bm
.verts
.new(tangent_vectors
[1] - obj_loc
)
408 tangent_vertex_o4
= bm
.verts
.new(tangent_vectors
[3] - obj_loc
)
409 bm
.edges
.new([tangent_vertex_o1
, tangent_vertex_o2
])
410 bm
.edges
.new([tangent_vertex_o3
, tangent_vertex_o4
])
411 bmesh
.update_edit_mesh(obj
.data
)
414 def analyse_arc(context
, pg
):
415 """Analyses an Arc inferred from Selected Vertices.
418 Will work if more than 3 vertices are selected, taking the
419 first, the nearest to the middle and the last.
422 context: Blender bpy.context instance
423 pg: PDT Parameters Group - our variables
426 vector_delta: Location of Arc Centre
427 radius: Radius of Arc.
429 obj
= context
.view_layer
.objects
.active
431 pg
.error
= PDT_ERR_NO_ACT_OBJ
432 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
433 raise PDT_ObjectModeError
434 if obj
.mode
== "EDIT":
435 obj_loc
= obj
.matrix_world
.decompose()[0]
436 bm
= bmesh
.from_edit_mesh(obj
.data
)
437 verts
= [v
for v
in bm
.verts
if v
.select
]
439 pg
.error
= f
"{PDT_ERR_SEL_3_VERTS} {len(verts)})"
440 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
441 raise PDT_SelectionError
442 vector_a
= verts
[0].co
443 # Get the nearest to middle vertex of the arc
445 vector_b
= verts
[int(floor(len(verts
) / 2))].co
446 vector_c
= verts
[-1].co
447 vector_delta
, radius
= arc_centre(vector_a
, vector_b
, vector_c
)
449 return vector_delta
, radius
452 class PDT_OT_TangentOperate(Operator
):
453 """Calculate Tangents from Inputs."""
455 bl_idname
= "pdt.tangentoperate"
456 bl_label
= "Calculate Tangents"
457 bl_options
= {"REGISTER", "UNDO"}
458 bl_description
= "Calculate Tangents to Arcs from Points or Other Arcs"
461 def poll(cls
, context
):
465 return all([bool(ob
), ob
.type == "MESH", ob
.mode
== "EDIT"])
467 def execute(self
, context
):
468 """Calculate Tangents from Inputs.
471 Uses pg.plane, pg.tangent_point0, pg.tangent_radius0, pg.tangent_point1
472 pg.tangent_radius1, pg.tangent_point2 to place tangents.
474 Analyses distance between arc centres, or arc centre and tangent point
475 to determine which mode is possible (Inner, Outer, or Point). If centres are
476 both contained within 1 inferred circle, Inner tangents are not possible.
478 Arcs of same radius will have no intersection for outer tangents so these
479 are calculated differently.
482 context: Blender bpy.context instance.
488 scene
= context
.scene
492 obj
= context
.view_layer
.objects
.active
494 if obj
.mode
not in {"EDIT"} or obj
.type != "MESH":
495 pg
.error
= PDT_OBJ_MODE_ERROR
496 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
499 pg
.error
= PDT_ERR_NO_ACT_OBJ
500 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
502 bm
= bmesh
.from_edit_mesh(obj
.data
)
503 obj_loc
= obj
.matrix_world
.decompose()[0]
504 obj_data
= (obj
, obj_loc
, bm
)
506 radius_0
= pg
.tangent_radius0
507 radius_1
= pg
.tangent_radius1
508 centre_0
= pg
.tangent_point0
509 centre_1
= pg
.tangent_point1
510 centre_2
= pg
.tangent_point2
513 context
, pg
, plane
, obj_data
, centre_0
, centre_1
, centre_2
, radius_0
, radius_1
519 class PDT_OT_TangentOperateSel(Operator
):
520 """Calculate Tangents from Selection."""
522 bl_idname
= "pdt.tangentoperatesel"
523 bl_label
= "Calculate Tangents"
524 bl_options
= {"REGISTER", "UNDO"}
525 bl_description
= "Calculate Tangents to Arcs from 2 Selected Vertices, or 1 & Point in Menu"
528 def poll(cls
, context
):
532 return all([bool(ob
), ob
.type == "MESH", ob
.mode
== "EDIT"])
534 def execute(self
, context
):
535 """Calculate Tangents from Selection.
538 Uses pg.plane & 2 or more selected Vertices to place tangents.
539 One vertex must be on each arc.
541 Analyses distance between arc centres, or arc centre and tangent point
542 to determine which mode is possible (Inner, Outer, or Point). If centres are
543 both contained within 1 inferred circle, Inner tangents are not possible.
545 Arcs of same radius will have no intersection for outer tangents so these
546 are calculated differently.
549 context: Blender bpy.context instance.
555 scene
= context
.scene
559 obj
= context
.view_layer
.objects
.active
561 if obj
.mode
not in {"EDIT"} or obj
.type != "MESH":
562 pg
.error
= PDT_OBJ_MODE_ERROR
563 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
566 pg
.error
= PDT_ERR_NO_ACT_OBJ
567 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
569 bm
= bmesh
.from_edit_mesh(obj
.data
)
570 obj_loc
= obj
.matrix_world
.decompose()[0]
571 obj_data
= (obj
, obj_loc
, bm
)
573 # Get All Values from Selected Vertices
574 verts
= [v
for v
in bm
.verts
if v
.select
]
576 pg
.error
= f
"{PDT_ERR_SEL_1_VERT} 0"
577 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
586 bpy
.ops
.mesh
.select_linked()
587 verts1
= [v
for v
in bm
.verts
if v
.select
].copy()
589 pg
.error
= f
"{PDT_ERR_VERT_MODE} or Less than 3 vertices in your Arc(s)"
590 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
597 bpy
.ops
.mesh
.select_linked()
598 vertsn
= [v
for v
in bm
.verts
if v
.select
].copy()
603 bmesh
.update_edit_mesh(obj
.data
)
604 bm
.select_history
.clear()
605 # Select the nearest to middle vertex in the arc
607 verts1
= [verts1
[0].co
, verts1
[int(floor(len(verts1
) / 2))].co
, verts1
[-1].co
]
608 vertsn
= [vertsn
[0].co
, vertsn
[int(floor(len(vertsn
) / 2))].co
, vertsn
[-1].co
]
609 centre_0
, radius_0
= arc_centre(verts1
[0], verts1
[1], verts1
[2])
610 centre_1
, radius_1
= arc_centre(vertsn
[0], vertsn
[1], vertsn
[2])
611 centre_2
= pg
.tangent_point2
614 context
, pg
, plane
, obj_data
, centre_0
, centre_1
, centre_2
, radius_0
, radius_1
620 class PDT_OT_TangentSet1(Operator
):
621 """Calculates Centres & Radii from 3 Vectors."""
623 bl_idname
= "pdt.tangentset1"
624 bl_label
= "Calculate Centres & Radii"
625 bl_options
= {"REGISTER", "UNDO"}
626 bl_description
= "Calculate Centres & Radii from Selected Vertices"
629 def poll(cls
, context
):
633 return all([bool(ob
), ob
.type == "MESH", ob
.mode
== "EDIT"])
635 def execute(self
, context
):
636 """Sets Input Tangent Point 1 to analysis of Arc.
639 context: Blender bpy.context instance.
644 scene
= context
.scene
646 vector_delta
, radius
= analyse_arc(context
, pg
)
647 pg
.tangent_point0
= vector_delta
648 pg
.tangent_radius0
= radius
652 class PDT_OT_TangentSet2(Operator
):
653 """Calculates Centres & Radii from 3 Vectors."""
655 bl_idname
= "pdt.tangentset2"
656 bl_label
= "Calculate Centres & Radii"
657 bl_options
= {"REGISTER", "UNDO"}
658 bl_description
= "Calculate Centres & Radii from Selected Vertices"
661 def poll(cls
, context
):
665 return all([bool(obj
), obj
.type == "MESH", obj
.mode
== "EDIT"])
667 def execute(self
, context
):
668 """Sets Input Tangent Point 2 to analysis of Arc.
671 context: Blender bpy.context instance.
676 scene
= context
.scene
678 vector_delta
, radius
= analyse_arc(context
, pg
)
679 pg
.tangent_point1
= vector_delta
680 pg
.tangent_radius1
= radius
684 class PDT_OT_TangentSet3(Operator
):
685 """Set Tangent Origin Point from Cursor."""
687 bl_idname
= "pdt.tangentset3"
688 bl_label
= "Set Tangent Origin Point from Cursor"
689 bl_options
= {"REGISTER", "UNDO"}
690 bl_description
= "Set Tangent Origin Point from Cursor"
693 def poll(cls
, context
):
697 return all([bool(obj
), obj
.type == "MESH", obj
.mode
== "EDIT"])
699 def execute(self
, context
):
700 """Sets Input Tangent Point 3 to analysis of Arc.
703 context: Blender bpy.context instance.
708 scene
= context
.scene
710 pg
.tangent_point2
= scene
.cursor
.location
714 class PDT_OT_TangentSet4(Operator
):
715 """Set Tangent Origin Point from Cursor."""
717 bl_idname
= "pdt.tangentset4"
718 bl_label
= "Set Tangent Origin Point from Vertex"
719 bl_options
= {"REGISTER", "UNDO"}
720 bl_description
= "Set Tangent Origin Point from Vertex"
723 def poll(cls
, context
):
727 return all([bool(obj
), obj
.type == "MESH", obj
.mode
== "EDIT"])
729 def execute(self
, context
):
730 """Sets Input Tangent Point 2 to selected Vertex.
733 context: Blender bpy.context instance.
738 scene
= context
.scene
741 bm
= bmesh
.from_edit_mesh(obj
.data
)
742 verts
= [v
for v
in bm
.verts
if v
.select
]
744 pg
.error
= f
"{PDT_ERR_SEL_1_VERT} {len(verts)})"
745 context
.window_manager
.popup_menu(oops
, title
="Error", icon
="ERROR")
746 raise PDT_SelectionError
747 pg
.tangent_point2
= verts
[0].co
751 class PDT_OT_TangentExpandMenu(Operator
):
752 """Expand/Collapse Tangent Menu."""
754 bl_idname
= "pdt.tangentexpandmenu"
755 bl_label
= "Expand/Collapse Tangent Menu"
756 bl_options
= {"REGISTER", "UNDO"}
757 bl_description
= "Expand/Collapse Tangent Menu to Show/Hide Input Options"
759 def execute(self
, context
):
760 """Expand/Collapse Tangent Menu.
763 This is used to add further options to the menu.
766 context: Blender bpy.context instance.
771 scene
= context
.scene
774 pg
.menu_expand
= False
776 pg
.menu_expand
= True