1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # ----------------------------------------------------------
4 # support routines for OpenGL
5 # Author: Antonio Vazquez (antonioya)
7 # ----------------------------------------------------------
8 # noinspection PyUnresolvedReferences
10 # noinspection PyUnresolvedReferences
12 from blf
import ROTATION
13 from math
import fabs
, degrees
, radians
, sqrt
, cos
, sin
, pi
14 from mathutils
import Vector
, Matrix
15 from bmesh
import from_edit_mesh
16 from bpy_extras
import view3d_utils
, mesh_utils
17 import bpy_extras
.object_utils
as object_utils
18 from sys
import exc_info
21 from gpu_extras
.batch
import batch_for_shader
24 shader
= gpu
.shader
.from_builtin('UNIFORM_COLOR') if not bpy
.app
.background
else None
25 shader_line
= gpu
.shader
.from_builtin('POLYLINE_UNIFORM_COLOR') if not bpy
.app
.background
else None
30 def imm_set_line_width(width
):
31 global imm_line_width
, imm_viewport
32 region
= bpy
.context
.region
33 imm_viewport
= (region
.width
, region
.height
)
35 imm_line_width
= width
37 # -------------------------------------------------------------
40 # -------------------------------------------------------------
41 # noinspection PyUnresolvedReferences,PyUnboundLocalVariable
42 def draw_segments(context
, myobj
, op
, region
, rv3d
):
43 if op
.measureit_num
> 0:
44 a_code
= "\u00b0" # degree
45 scale
= bpy
.context
.scene
.unit_settings
.scale_length
46 scene
= bpy
.context
.scene
47 pr
= scene
.measureit_gl_precision
48 fmt
= "%1." + str(pr
) + "f"
49 ovr
= scene
.measureit_ovr
50 ovrcolor
= scene
.measureit_ovr_color
51 ovrfsize
= scene
.measureit_ovr_font
52 ovrfang
= get_angle_in_rad(scene
.measureit_ovr_font_rotation
)
53 ovrfaln
= scene
.measureit_ovr_font_align
54 ovrline
= scene
.measureit_ovr_width
55 units
= scene
.measureit_units
56 fang
= get_angle_in_rad(scene
.measureit_font_rotation
)
58 # --------------------
60 # --------------------
61 if scene
.measureit_scale
is True:
62 prs
= scene
.measureit_scale_precision
63 fmts
= "%1." + str(prs
) + "f"
64 pos_2d
= get_scale_txt_location(context
)
65 tx_dsp
= fmts
% scene
.measureit_scale_factor
66 tx_scale
= scene
.measureit_gl_scaletxt
+ " 1:" + tx_dsp
67 draw_text(myobj
, pos_2d
,
68 tx_scale
, scene
.measureit_scale_color
, scene
.measureit_scale_font
,
71 # --------------------
73 # --------------------
74 for idx
in range(op
.measureit_num
):
75 ms
= op
.measureit_segments
[idx
]
77 fsize
= ms
.glfont_size
78 fang
= get_angle_in_rad(ms
.glfont_rotat
)
79 faln
= ms
.glfont_align
84 # ------------------------------
85 # only active and visible
86 # ------------------------------
87 if ms
.glview
is True and ms
.glfree
is False:
92 # noinspection PyBroadException
99 # ----------------------
101 # ----------------------
102 if ms
.gltype
== 1 or ms
.gltype
== 2:
103 obverts
= get_mesh_vertices(myobj
)
105 if ms
.glpointa
<= len(obverts
) and ms
.glpointb
<= len(obverts
):
106 a_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
107 b_p1
= get_point(obverts
[ms
.glpointb
].co
, myobj
)
109 # ----------------------
111 # ----------------------
112 if ms
.gltype
== 12 or ms
.gltype
== 13 or ms
.gltype
== 14:
113 obverts
= get_mesh_vertices(myobj
)
114 if ms
.glpointa
<= len(obverts
):
115 a_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
116 if ms
.gltype
== 12: # X
117 b_p1
= get_point((0.0,
118 obverts
[ms
.glpointa
].co
[1],
119 obverts
[ms
.glpointa
].co
[2]), myobj
)
120 elif ms
.gltype
== 13: # Y
121 b_p1
= get_point((obverts
[ms
.glpointa
].co
[0],
123 obverts
[ms
.glpointa
].co
[2]), myobj
)
125 b_p1
= get_point((obverts
[ms
.glpointa
].co
[0],
126 obverts
[ms
.glpointa
].co
[1],
128 # ----------------------
129 # Vertex to Vertex (link)
130 # ----------------------
132 obverts
= get_mesh_vertices(myobj
)
133 linkverts
= bpy
.data
.objects
[ms
.gllink
].data
.vertices
134 a_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
135 b_p1
= get_point(linkverts
[ms
.glpointb
].co
, bpy
.data
.objects
[ms
.gllink
])
136 # ----------------------
137 # Vertex to Object (link)
138 # ----------------------
140 obverts
= get_mesh_vertices(myobj
)
141 a_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
142 b_p1
= get_location(bpy
.data
.objects
[ms
.gllink
])
143 # ----------------------
144 # Object to Vertex (link)
145 # ----------------------
147 linkverts
= bpy
.data
.objects
[ms
.gllink
].data
.vertices
148 a_p1
= get_location(myobj
)
149 b_p1
= get_point(linkverts
[ms
.glpointb
].co
, bpy
.data
.objects
[ms
.gllink
])
150 # ----------------------
151 # Object to Object (link)
152 # ----------------------
154 a_p1
= get_location(myobj
)
155 b_p1
= get_location(bpy
.data
.objects
[ms
.gllink
])
156 # ----------------------
158 # ----------------------
160 obverts
= get_mesh_vertices(myobj
)
162 b_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
163 # ----------------------
165 # ----------------------
168 b_p1
= get_location(myobj
)
169 # ----------------------
171 # ----------------------
173 obverts
= get_mesh_vertices(myobj
)
174 if ms
.glpointa
<= len(obverts
) and ms
.glpointb
<= len(obverts
) and ms
.glpointc
<= len(obverts
):
175 an_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
176 an_p2
= get_point(obverts
[ms
.glpointb
].co
, myobj
)
177 an_p3
= get_point(obverts
[ms
.glpointc
].co
, myobj
)
179 ang_1
= Vector((an_p1
[0] - an_p2
[0], an_p1
[1] - an_p2
[1], an_p1
[2] - an_p2
[2]))
180 ang_2
= Vector((an_p3
[0] - an_p2
[0], an_p3
[1] - an_p2
[1], an_p3
[2] - an_p2
[2]))
182 ang_3
= ang_1
+ ang_2
# Result vector
184 a_p1
= (an_p2
[0], an_p2
[1], an_p2
[2])
186 # ----------------------
188 # ----------------------
190 a_p1
= get_location(myobj
)
191 b_p1
= get_location(myobj
)
193 # ----------------------
195 # ----------------------
197 obverts
= get_mesh_vertices(myobj
)
198 if ms
.glpointa
<= len(obverts
) and ms
.glpointb
<= len(obverts
) and ms
.glpointc
<= len(obverts
):
199 an_p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
200 an_p2
= get_point(obverts
[ms
.glpointb
].co
, myobj
)
201 an_p3
= get_point(obverts
[ms
.glpointc
].co
, myobj
)
202 # reference for maths: http://en.wikipedia.org/wiki/Circumscribed_circle
203 an_p12
= Vector((an_p1
[0] - an_p2
[0], an_p1
[1] - an_p2
[1], an_p1
[2] - an_p2
[2]))
204 an_p13
= Vector((an_p1
[0] - an_p3
[0], an_p1
[1] - an_p3
[1], an_p1
[2] - an_p3
[2]))
205 an_p21
= Vector((an_p2
[0] - an_p1
[0], an_p2
[1] - an_p1
[1], an_p2
[2] - an_p1
[2]))
206 an_p23
= Vector((an_p2
[0] - an_p3
[0], an_p2
[1] - an_p3
[1], an_p2
[2] - an_p3
[2]))
207 an_p31
= Vector((an_p3
[0] - an_p1
[0], an_p3
[1] - an_p1
[1], an_p3
[2] - an_p1
[2]))
208 an_p32
= Vector((an_p3
[0] - an_p2
[0], an_p3
[1] - an_p2
[1], an_p3
[2] - an_p2
[2]))
209 an_p12xp23
= an_p12
.copy().cross(an_p23
)
211 # radius = an_p12.length * an_p23.length * an_p31.length / (2 * an_p12xp23.length)
213 alpha
= pow(an_p23
.length
, 2) * an_p12
.dot(an_p13
) / (2 * pow(an_p12xp23
.length
, 2))
214 beta
= pow(an_p13
.length
, 2) * an_p21
.dot(an_p23
) / (2 * pow(an_p12xp23
.length
, 2))
215 gamma
= pow(an_p12
.length
, 2) * an_p31
.dot(an_p32
) / (2 * pow(an_p12xp23
.length
, 2))
217 a_p1
= (alpha
* an_p1
[0] + beta
* an_p2
[0] + gamma
* an_p3
[0],
218 alpha
* an_p1
[1] + beta
* an_p2
[1] + gamma
* an_p3
[1],
219 alpha
* an_p1
[2] + beta
* an_p2
[2] + gamma
* an_p3
[2])
221 b_p1
= (an_p2
[0], an_p2
[1], an_p2
[2])
222 a_n
= an_p12
.cross(an_p23
)
223 a_n
.normalize() # normal vector
224 arc_angle
, arc_length
= get_arc_data(an_p1
, a_p1
, an_p2
, an_p3
)
225 # Apply scale to arc_length
226 arc_length
*= scene
.measureit_scale_factor
228 # ----------------------
230 # ----------------------
232 a_p1
= get_location(myobj
) # Not used
233 b_p1
= get_location(myobj
) # Not used
236 dist
, distloc
= distance(a_p1
, b_p1
, ms
.glocx
, ms
.glocy
, ms
.glocz
)
237 # ------------------------------------
239 # ------------------------------------
240 if ms
.gldefault
is True:
242 vn
= ang_3
# if angle, vector is angle position
243 elif ms
.gltype
== 11:
244 vn
= a_n
# if arc, vector is perpendicular to surface of the three vertices
246 loc
= get_location(myobj
)
247 midpoint3d
= interpolate3d(a_p1
, b_p1
, fabs(dist
/ 2))
248 vn
= Vector((midpoint3d
[0] - loc
[0],
249 midpoint3d
[1] - loc
[1],
250 midpoint3d
[2] - loc
[2]))
252 vn
= Vector((ms
.glnormalx
, ms
.glnormaly
, ms
.glnormalz
))
255 # ------------------------------------
257 # ------------------------------------
262 vi2
= vn
* (ms
.glspace
+ s
)
263 # ------------------------------------
265 # ------------------------------------
266 v1
= [a_p1
[0] + vi
[0], a_p1
[1] + vi
[1], a_p1
[2] + vi
[2]]
267 v2
= [b_p1
[0] + vi
[0], b_p1
[1] + vi
[1], b_p1
[2] + vi
[2]]
270 v11
= [a_p1
[0] + vi2
[0], a_p1
[1] + vi2
[1], a_p1
[2] + vi2
[2]]
271 v22
= [b_p1
[0] + vi2
[0], b_p1
[1] + vi2
[1], b_p1
[2] + vi2
[2]]
274 v11a
= (a_p1
[0] + vi2
[0], a_p1
[1] + vi2
[1], a_p1
[2] + vi2
[2] + s
/ 30)
275 v11b
= (a_p1
[0] + vi2
[0], a_p1
[1] + vi2
[1], a_p1
[2] + vi2
[2] - s
/ 40)
278 vn1
= (a_p1
[0], a_p1
[1], a_p1
[2])
280 # -------------------------------------------
282 # -------------------------------------------
283 if ms
.gltype
== 1 and ms
.glorto
!= "99":
284 if ms
.glorto
== "0": # A
285 if ms
.glorto_x
is True:
288 if ms
.glorto_y
is True:
291 if ms
.glorto_z
is True:
295 if ms
.glorto
== "1": # B
296 if ms
.glorto_x
is True:
299 if ms
.glorto_y
is True:
302 if ms
.glorto_z
is True:
306 # ------------------------------------
307 # converting to screen coordinates
308 # ------------------------------------
309 screen_point_ap1
= get_2d_point(region
, rv3d
, a_p1
)
310 screen_point_bp1
= get_2d_point(region
, rv3d
, b_p1
)
312 screen_point_v1
= get_2d_point(region
, rv3d
, v1
)
313 screen_point_v2
= get_2d_point(region
, rv3d
, v2
)
314 screen_point_v11
= get_2d_point(region
, rv3d
, v11
)
315 screen_point_v22
= get_2d_point(region
, rv3d
, v22
)
316 screen_point_v11a
= get_2d_point(region
, rv3d
, v11a
)
317 screen_point_v11b
= get_2d_point(region
, rv3d
, v11b
)
319 # ------------------------------------
320 # colour + line setup
321 # ------------------------------------
323 imm_set_line_width(ms
.glwidth
)
325 imm_set_line_width(ovrline
)
327 # ------------------------------------
329 # ------------------------------------
330 # noinspection PyBroadException
331 if ms
.gltype
!= 2 and ms
.gltype
!= 9 and ms
.gltype
!= 10 and ms
.gltype
!= 11 and ms
.gltype
!= 20:
332 # noinspection PyBroadException
334 midpoint3d
= interpolate3d(v1
, v2
, fabs(dist
/ 2))
335 gap3d
= (midpoint3d
[0], midpoint3d
[1], midpoint3d
[2] + s
/ 2)
336 tmp_point
= get_2d_point(region
, rv3d
, gap3d
)
337 if tmp_point
is None:
339 txtpoint2d
= tmp_point
[0] + ms
.glfontx
, tmp_point
[1] + ms
.glfonty
341 if scene
.measureit_scale
is True:
342 dist
= dist
* scene
.measureit_scale_factor
343 distloc
= distloc
* scene
.measureit_scale_factor
354 tx_dist
= str(format_distance(fmt
, units
, usedist
))
355 # -----------------------------------
357 # -----------------------------------
358 if scene
.measureit_gl_show_d
is True and ms
.gldist
is True:
362 if scene
.measureit_gl_show_n
is True and ms
.glnames
is True:
364 if scene
.measureit_gl_show_d
is True or scene
.measureit_gl_show_n
is True:
365 draw_text(myobj
, txtpoint2d
, msg
, rgba
, fsize
, faln
, fang
)
367 # ------------------------------
368 # if axis loc, show a indicator
369 # ------------------------------
370 if locflag
is True and ms
.glocwarning
is True:
371 txtpoint2d
= get_2d_point(region
, rv3d
, (v2
[0], v2
[1], v2
[2]))
380 draw_text(myobj
, txtpoint2d
, txt
, rgba
, fsize
- 1, text_rot
=fang
)
384 # ------------------------------------
385 # Text (label) and Angles
386 # ------------------------------------
387 # noinspection PyBroadException
388 if ms
.gltype
== 2 or ms
.gltype
== 9 or ms
.gltype
== 11:
390 # noinspection PyBroadException
394 if ms
.gltype
== 9: # Angles
395 ang
= ang_1
.angle(ang_2
)
396 if bpy
.context
.scene
.unit_settings
.system_rotation
== "DEGREES":
399 tx_dist
= " " + fmt
% ang
401 if bpy
.context
.scene
.unit_settings
.system_rotation
== "DEGREES":
404 if scene
.measureit_gl_show_n
is True:
405 tx_dist
+= " " + ms
.gltxt
406 if ms
.gltype
== 11: # arc
407 # print length or arc and angle
408 if ms
.glarc_len
is True:
409 tx_dist
= ms
.glarc_txlen
+ format_distance(fmt
, units
, arc_length
* scale
)
413 if bpy
.context
.scene
.unit_settings
.system_rotation
== "DEGREES":
414 arc_d
= degrees(arc_angle
)
418 if ms
.glarc_ang
is True:
419 tx_dist
+= " " + ms
.glarc_txang
+ format_distance(fmt
, 9, arc_d
)
421 if bpy
.context
.scene
.unit_settings
.system_rotation
== "DEGREES":
424 if scene
.measureit_gl_show_d
is True and ms
.gldist
is True:
429 if scene
.measureit_gl_show_n
is True and ms
.glnames
is True:
432 if scene
.measureit_gl_show_d
is True or scene
.measureit_gl_show_n
is True:
434 vna
= Vector((b_p1
[0] - a_p1
[0],
438 via
= vna
* ms
.glspace
440 gap3d
= (b_p1
[0] + via
[0], b_p1
[1] + via
[1], b_p1
[2] + via
[2])
441 tmp_point
= get_2d_point(region
, rv3d
, gap3d
)
442 if tmp_point
is not None:
443 txtpoint2d
= tmp_point
[0] + ms
.glfontx
, tmp_point
[1] + ms
.glfonty
444 draw_text(myobj
, txtpoint2d
, msg
, rgba
, fsize
, faln
, fang
)
446 if scene
.measureit_gl_show_d
is True and ms
.gldist
is True and \
447 ms
.glarc_rad
is True:
448 tx_dist
= ms
.glarc_txradio
+ format_distance(fmt
, units
,
449 dist
* scene
.measureit_scale_factor
* scale
)
453 gap3d
= (v11a
[0], v11a
[1], v11a
[2])
455 gap3d
= (a_p1
[0], a_p1
[1], a_p1
[2])
457 tmp_point
= get_2d_point(region
, rv3d
, gap3d
)
458 if tmp_point
is not None:
459 txtpoint2d
= tmp_point
[0] + ms
.glfontx
, tmp_point
[1] + ms
.glfonty
460 draw_text(myobj
, txtpoint2d
, tx_dist
, rgba
, fsize
, faln
, fang
)
463 # ------------------------------------
465 # ------------------------------------
466 # noinspection PyBroadException
468 # noinspection PyBroadException
470 gap3d
= (vn1
[0], vn1
[1], vn1
[2])
471 tmp_point
= get_2d_point(region
, rv3d
, gap3d
)
472 if tmp_point
is not None:
473 txtpoint2d
= tmp_point
[0] + ms
.glfontx
, tmp_point
[1] + ms
.glfonty
474 draw_text(myobj
, txtpoint2d
, tx_dist
, rgba
, fsize
, faln
, fang
)
476 # ------------------------------------
478 # ------------------------------------
479 gpu
.state
.blend_set('ALPHA')
481 if ms
.gltype
== 1: # Segment
482 draw_line(screen_point_ap1
, screen_point_v11
, rgba
)
483 draw_line(screen_point_bp1
, screen_point_v22
, rgba
)
484 draw_arrow(screen_point_v1
, screen_point_v2
, rgba
, a_size
, a_type
, b_type
)
486 if ms
.gltype
== 12 or ms
.gltype
== 13 or ms
.gltype
== 14: # Segment to origin
487 draw_line(screen_point_ap1
, screen_point_v11
, rgba
)
488 draw_line(screen_point_bp1
, screen_point_v22
, rgba
)
489 draw_arrow(screen_point_v1
, screen_point_v2
, rgba
, a_size
, a_type
, b_type
)
491 if ms
.gltype
== 2: # Label
492 draw_line(screen_point_v11a
, screen_point_v11b
, rgba
)
493 draw_arrow(screen_point_ap1
, screen_point_v11
, rgba
, a_size
, a_type
, b_type
)
495 if ms
.gltype
== 3 or ms
.gltype
== 4 or ms
.gltype
== 5 or ms
.gltype
== 8 \
496 or ms
.gltype
== 6 or ms
.gltype
== 7: # Origin and Links
497 draw_arrow(screen_point_ap1
, screen_point_bp1
, rgba
, a_size
, a_type
, b_type
)
499 if ms
.gltype
== 9: # Angle
500 dist
, distloc
= distance(an_p1
, an_p2
)
501 mp1
= interpolate3d(an_p1
, an_p2
, fabs(dist
/ 1.1))
503 dist
, distloc
= distance(an_p3
, an_p2
)
504 mp2
= interpolate3d(an_p3
, an_p2
, fabs(dist
/ 1.1))
506 screen_point_an_p1
= get_2d_point(region
, rv3d
, mp1
)
507 screen_point_an_p2
= get_2d_point(region
, rv3d
, an_p2
)
508 screen_point_an_p3
= get_2d_point(region
, rv3d
, mp2
)
510 draw_line(screen_point_an_p1
, screen_point_an_p2
, rgba
)
511 draw_line(screen_point_an_p2
, screen_point_an_p3
, rgba
)
512 draw_line(screen_point_an_p1
, screen_point_an_p3
, rgba
)
514 if ms
.gltype
== 11: # arc
515 # draw line from center of arc second point
517 if ms
.glarc_rad
is True:
518 if ms
.glarc_extrad
is False:
519 draw_arrow(screen_point_ap1
, screen_point_bp1
, rgba
, a_size
, a_type
, b_type
)
521 vne
= Vector((b_p1
[0] - a_p1
[0],
525 vie
= vne
* ms
.glspace
526 pe
= (b_p1
[0] + vie
[0], b_p1
[1] + vie
[1], b_p1
[2] + vie
[2])
527 screen_point_pe
= get_2d_point(region
, rv3d
, pe
)
528 draw_arrow(screen_point_ap1
, screen_point_pe
, rgba
, a_size
, a_type
, b_type
)
530 # create arc around the centerpoint
531 # rotation matrix around normal vector at center point
532 mat_trans1
= Matrix
.Translation(-c
)
535 if ms
.glarc_full
is False:
536 step
= arc_angle
/ n_step
538 step
= radians(360.0) / n_step
540 mat_rot1
= Matrix
.Rotation(step
, 4, vn
)
541 mat_trans2
= Matrix
.Translation(c
)
542 p1
= Vector(an_p1
) # first point of arc
544 vn
= Vector((p1
[0] - a_p1
[0],
555 for i
in range(int(n_step
)):
556 p2
= mat_trans2
@ mat_rot1
@ mat_trans1
@ p1
557 p1_
= (p1
[0] + vi
[0], p1
[1] + vi
[1], p1
[2] + vi
[2])
560 p_01a
= (p1_
[0], p1_
[1], p1_
[2])
561 p_01b
= (p1
[0], p1
[1], p1
[2])
564 vn
= Vector((p2
[0] - a_p1
[0],
570 p2_
= (p2
[0] + vi
[0], p2
[1] + vi
[1], p2
[2] + vi
[2])
571 # convert to screen coordinates
572 screen_point_p1
= get_2d_point(region
, rv3d
, p1_
)
573 screen_point_p2
= get_2d_point(region
, rv3d
, p2_
)
575 draw_arrow(screen_point_p1
, screen_point_p2
, rgba
, ms
.glarc_s
, ms
.glarc_a
, "99")
576 elif i
== int(n_step
) - 1:
577 draw_arrow(screen_point_p1
, screen_point_p2
, rgba
, ms
.glarc_s
, "99", ms
.glarc_b
)
579 draw_line(screen_point_p1
, screen_point_p2
, rgba
)
584 if i
== int(n_step
) - 1:
585 p_02a
= (p2_
[0], p2_
[1], p2_
[2])
586 p_02b
= (p2
[0], p2
[1], p2
[2])
589 if ms
.glarc_full
is False:
590 screen_point_p1a
= get_2d_point(region
, rv3d
, p_01a
)
591 screen_point_p1b
= get_2d_point(region
, rv3d
, p_01b
)
592 screen_point_p2a
= get_2d_point(region
, rv3d
, p_02a
)
593 screen_point_p2b
= get_2d_point(region
, rv3d
, p_02b
)
595 draw_line(screen_point_p1a
, screen_point_p1b
, rgba
)
596 draw_line(screen_point_p2a
, screen_point_p2b
, rgba
)
598 if ms
.gltype
== 20: # Area
599 obverts
= get_mesh_vertices(myobj
)
601 if scene
.measureit_scale
is True:
602 ms_scale
= scene
.measureit_scale_factor
606 for face
in ms
.measureit_faces
:
608 for v
in face
.measureit_index
:
609 myvertices
.append(v
.glidx
)
611 area
= get_area_and_paint(myvertices
, myobj
, obverts
, region
, rv3d
, rgba
, ms_scale
)
613 # Draw Area number over first face
614 if len(ms
.measureit_faces
) > 0:
615 face
= ms
.measureit_faces
[0]
616 a
= face
.measureit_index
[0].glidx
617 b
= face
.measureit_index
[2].glidx
619 p1
= get_point(obverts
[a
].co
, myobj
)
620 p2
= get_point(obverts
[b
].co
, myobj
)
622 d1
, dn
= distance(p1
, p2
)
623 midpoint3d
= interpolate3d(p1
, p2
, fabs(d1
/ 2))
625 # mult by world scale
627 tx_dist
= str(format_distance(fmt
, units
, tot
, 2))
628 # -----------------------------------
630 # -----------------------------------
631 if scene
.measureit_gl_show_d
is True and ms
.gldist
is True:
635 if scene
.measureit_gl_show_n
is True and ms
.glnames
is True:
637 if scene
.measureit_gl_show_d
is True or scene
.measureit_gl_show_n
is True:
638 tmp_point
= get_2d_point(region
, rv3d
, midpoint3d
)
639 if tmp_point
is not None:
640 txtpoint2d
= tmp_point
[0] + ms
.glfontx
, tmp_point
[1] + ms
.glfonty
641 # todo: swap ms.glcolorarea with ms.glcolor ?
642 draw_text(myobj
, txtpoint2d
, msg
, ms
.glcolorarea
, fsize
, faln
, fang
)
647 print("Unexpected error:" + str(exc_info()))
653 # ------------------------------------------
654 # Get polygon area and paint area
656 # ------------------------------------------
657 def get_area_and_paint(myvertices
, myobj
, obverts
, region
, rv3d
, rgba
, ms_scale
):
660 if len(myvertices
) > 3:
661 # Tessellate the polygon
662 if myobj
.mode
!= 'EDIT':
663 tris
= mesh_utils
.ngon_tessellate(mymesh
, myvertices
)
665 bm
= from_edit_mesh(myobj
.data
)
669 tris
= mesh_utils
.ngon_tessellate(myv
, myvertices
)
673 p1
= get_point(obverts
[myvertices
[v1
]].co
, myobj
)
674 p2
= get_point(obverts
[myvertices
[v2
]].co
, myobj
)
675 p3
= get_point(obverts
[myvertices
[v3
]].co
, myobj
)
677 screen_point_p1
= get_2d_point(region
, rv3d
, p1
)
678 screen_point_p2
= get_2d_point(region
, rv3d
, p2
)
679 screen_point_p3
= get_2d_point(region
, rv3d
, p3
)
681 draw_triangle(screen_point_p1
, screen_point_p2
, screen_point_p3
, rgba
)
685 area
= get_triangle_area(p1
, p2
, p3
, ms_scale
)
688 elif len(myvertices
) == 3:
689 v1
, v2
, v3
= myvertices
690 p1
= get_point(obverts
[v1
].co
, myobj
)
691 p2
= get_point(obverts
[v2
].co
, myobj
)
692 p3
= get_point(obverts
[v3
].co
, myobj
)
694 screen_point_p1
= get_2d_point(region
, rv3d
, p1
)
695 screen_point_p2
= get_2d_point(region
, rv3d
, p2
)
696 screen_point_p3
= get_2d_point(region
, rv3d
, p3
)
697 draw_triangle(screen_point_p1
, screen_point_p2
, screen_point_p3
, rgba
)
700 area
= get_triangle_area(p1
, p2
, p3
, ms_scale
)
706 totarea
*= bpy
.context
.scene
.unit_settings
.scale_length
711 # ------------------------------------------
712 # Get area using Heron formula
714 # ------------------------------------------
715 def get_triangle_area(p1
, p2
, p3
, scale
=1.0):
716 d1
, dn
= distance(p1
, p2
)
717 d2
, dn
= distance(p2
, p3
)
718 d3
, dn
= distance(p1
, p3
)
724 per
= (d1
+ d2
+ d3
) / 2.0
725 area
= sqrt(per
* (per
- d1
) * (per
- d2
) * (per
- d3
))
729 # ------------------------------------------
730 # Get point in 2d space
732 # ------------------------------------------
733 def get_2d_point(region
, rv3d
, point3d
):
734 if rv3d
is not None and region
is not None:
735 return view3d_utils
.location_3d_to_region_2d(region
, rv3d
, point3d
)
737 return get_render_location(point3d
)
740 # -------------------------------------------------------------
743 # myobj: Current object
745 # -------------------------------------------------------------
746 def get_group_sum(myobj
, tag
):
747 # noinspection PyBroadException
749 tx
= ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
750 "T", "U", "V", "W", "X", "Y", "Z"]
752 mp
= myobj
.MeasureGenerator
[0]
757 scale
= bpy
.context
.scene
.unit_settings
.scale_length
759 obverts
= get_mesh_vertices(myobj
)
760 for idx
in range(mp
.measureit_num
):
761 ms
= mp
.measureit_segments
[idx
]
762 if (ms
.gltype
== 1 or ms
.gltype
== 12 or
763 ms
.gltype
== 13 or ms
.gltype
== 14) and ms
.gltot
!= '99' \
764 and ms
.glfree
is False and g
== tx
[int(ms
.gltot
)]: # only segments
765 if ms
.glpointa
<= len(obverts
) and ms
.glpointb
<= len(obverts
):
766 p1
= get_point(obverts
[ms
.glpointa
].co
, myobj
)
768 p2
= get_point(obverts
[ms
.glpointb
].co
, myobj
)
769 elif ms
.gltype
== 12:
771 obverts
[ms
.glpointa
].co
[1],
772 obverts
[ms
.glpointa
].co
[2]), myobj
)
773 elif ms
.gltype
== 13:
774 p2
= get_point((obverts
[ms
.glpointa
].co
[0],
776 obverts
[ms
.glpointa
].co
[2]), myobj
)
778 p2
= get_point((obverts
[ms
.glpointa
].co
[0],
779 obverts
[ms
.glpointa
].co
[1],
782 dist
, distloc
= distance(p1
, p2
, ms
.glocx
, ms
.glocy
, ms
.glocz
)
793 pr
= bpy
.context
.scene
.measureit_gl_precision
794 fmt
= "%1." + str(pr
) + "f"
795 units
= bpy
.context
.scene
.measureit_units
797 return format_distance(fmt
, units
, tot
)
804 # -------------------------------------------------------------
807 # -------------------------------------------------------------
808 def draw_text(myobj
, pos2d
, display_text
, rgba
, fsize
, align
='L', text_rot
=0.0):
812 # dpi = bpy.context.preferences.system.dpi
816 ui_scale
= bpy
.context
.preferences
.system
.ui_scale
817 blf
.size(font_id
, round(fsize
* ui_scale
))
818 # blf.size(font_id, fsize)
820 mwidth
, mheight
= blf
.dimensions(font_id
, "Tp") # uses high/low letters
822 # Calculate sum groups
824 while "<#" in display_text
:
826 if m
> 10: # limit loop
828 i
= display_text
.index("<#")
829 tag
= display_text
[i
:i
+ 4]
830 display_text
= display_text
.replace(tag
, get_group_sum(myobj
, tag
.upper()))
833 mylines
= display_text
.split("|")
834 idx
= len(mylines
) - 1
836 maxheight
= len(mylines
) * mheight
837 # -------------------
839 # -------------------
841 text_width
, text_height
= blf
.dimensions(font_id
, line
)
843 newx
= x_pos
- text_width
/ 2
845 newx
= x_pos
- text_width
- gap
848 blf
.enable(font_id
, ROTATION
)
849 blf
.rotation(font_id
, text_rot
)
850 # calculate new Y position
851 new_y
= y_pos
+ (mheight
* idx
)
853 blf
.position(font_id
, newx
, new_y
, 0)
854 blf
.color(font_id
, rgba
[0], rgba
[1], rgba
[2], rgba
[3])
855 blf
.draw(font_id
, " " + line
)
859 if maxwidth
< text_width
:
860 maxwidth
= text_width
863 blf
.disable(font_id
, ROTATION
)
865 return maxwidth
, maxheight
868 # -------------------------------------------------------------
869 # Draw an OpenGL line
871 # -------------------------------------------------------------
872 def draw_line(v1
, v2
, rgba
):
873 coords
= [(v1
[0], v1
[1], 0), (v2
[0], v2
[1], 0)]
874 batch
= batch_for_shader(shader_line
, 'LINES', {"pos": coords
})
876 # noinspection PyBroadException
878 if v1
is not None and v2
is not None:
880 shader_line
.uniform_float("color", rgba
)
881 shader_line
.uniform_float("lineWidth", imm_line_width
)
882 shader_line
.uniform_float("viewportSize", imm_viewport
)
883 batch
.draw(shader_line
)
888 # -------------------------------------------------------------
889 # Draw an OpenGL triangle
891 # -------------------------------------------------------------
892 def draw_triangle(v1
, v2
, v3
, rgba
):
893 coords
= [(v1
[0], v1
[1]), (v2
[0], v2
[1]), (v3
[0], v3
[1])]
894 batch
= batch_for_shader(shader
, 'TRIS', {"pos": coords
})
896 # noinspection PyBroadException
898 if v1
is not None and v2
is not None and v3
is not None:
900 shader
.uniform_float("color", rgba
)
906 # -------------------------------------------------------------
909 # -------------------------------------------------------------
910 def draw_arrow(v1
, v2
, rgba
, size
=20, a_typ
="1", b_typ
="1"):
911 if v1
is None or v2
is None:
915 rad315
= radians(315)
917 rad270
= radians(270)
919 v
= interpolate3d((v1
[0], v1
[1], 0.0), (v2
[0], v2
[1], 0.0), size
)
921 v1i
= (v
[0] - v1
[0], v
[1] - v1
[1])
923 v
= interpolate3d((v2
[0], v2
[1], 0.0), (v1
[0], v1
[1], 0.0), size
)
924 v2i
= (v
[0] - v2
[0], v
[1] - v2
[1])
934 v1a
= (int(v1i
[0] * cos(rad_a
) - v1i
[1] * sin(rad_a
) + v1
[0]),
935 int(v1i
[1] * cos(rad_a
) + v1i
[0] * sin(rad_a
)) + v1
[1])
936 v1b
= (int(v1i
[0] * cos(rad_b
) - v1i
[1] * sin(rad_b
) + v1
[0]),
937 int(v1i
[1] * cos(rad_b
) + v1i
[0] * sin(rad_b
) + v1
[1]))
947 v2a
= (int(v2i
[0] * cos(rad_a
) - v2i
[1] * sin(rad_a
) + v2
[0]),
948 int(v2i
[1] * cos(rad_a
) + v2i
[0] * sin(rad_a
)) + v2
[1])
949 v2b
= (int(v2i
[0] * cos(rad_b
) - v2i
[1] * sin(rad_b
) + v2
[0]),
950 int(v2i
[1] * cos(rad_b
) + v2i
[0] * sin(rad_b
) + v2
[1]))
953 if a_typ
== "1" or a_typ
== "3":
954 draw_line(v1
, v1a
, rgba
)
955 draw_line(v1
, v1b
, rgba
)
957 if b_typ
== "1" or b_typ
== "3":
958 draw_line(v2
, v2a
, rgba
)
959 draw_line(v2
, v2b
, rgba
)
962 draw_triangle(v1
, v1a
, v1b
, rgba
)
964 draw_triangle(v2
, v2a
, v2b
, rgba
)
966 draw_line(v1
, v2
, rgba
)
969 # -------------------------------------------------------------
970 # Draw an OpenGL Rectangle
972 # v1, v2 are corners (bottom left / top right)
973 # -------------------------------------------------------------
974 def draw_rectangle(v1
, v2
, rgba
):
975 # noinspection PyBroadException
977 if v1
is not None and v2
is not None:
980 draw_line(v1
, v1b
, rgba
)
981 draw_line(v1b
, v2
, rgba
)
982 draw_line(v2
, v2b
, rgba
)
983 draw_line(v2b
, v1
, rgba
)
988 # -------------------------------------------------------------
989 # format a point as (x, y, z) for display
991 # -------------------------------------------------------------
992 def format_point(mypoint
, pr
):
993 pf
= "%1." + str(pr
) + "f"
995 fmt
+= pf
% mypoint
[0]
997 fmt
+= pf
% mypoint
[1]
999 fmt
+= pf
% mypoint
[2]
1005 # -------------------------------------------------------------
1006 # Draw object num for debug
1008 # -------------------------------------------------------------
1009 # noinspection PyUnresolvedReferences,PyUnboundLocalVariable,PyUnusedLocal
1010 def draw_object(context
, myobj
, region
, rv3d
):
1011 scene
= bpy
.context
.scene
1012 rgba
= scene
.measureit_debug_obj_color
1013 fsize
= scene
.measureit_debug_font
1014 precision
= scene
.measureit_debug_precision
1015 # --------------------
1017 # --------------------
1018 objs
= bpy
.context
.scene
.objects
1019 obidxs
= list(range(len(bpy
.context
.scene
.objects
)))
1021 # Display only selected
1022 if scene
.measureit_debug_select
is True:
1023 if objs
[o
].select_get() is False:
1025 a_p1
= Vector(get_location(objs
[o
]))
1028 if scene
.measureit_debug_objects
is True:
1030 if scene
.measureit_debug_object_loc
is True:
1031 txt
+= format_point(a_p1
, precision
)
1032 # converting to screen coordinates
1033 txtpoint2d
= get_2d_point(region
, rv3d
, a_p1
)
1034 draw_text(myobj
, txtpoint2d
, txt
, rgba
, fsize
)
1038 # -------------------------------------------------------------
1039 # Draw vertex num for debug
1041 # -------------------------------------------------------------
1042 # noinspection PyUnresolvedReferences,PyUnboundLocalVariable,PyUnusedLocal
1043 def draw_vertices(context
, myobj
, region
, rv3d
):
1045 if myobj
.type != "MESH":
1048 scene
= bpy
.context
.scene
1049 rgba
= scene
.measureit_debug_vert_color
1050 fsize
= scene
.measureit_debug_font
1051 precision
= scene
.measureit_debug_precision
1052 # --------------------
1054 # --------------------
1055 if scene
.measureit_debug_vert_loc_toggle
== '1':
1056 co_mult
= lambda c
: c
1057 else: # if global, convert local c to global
1058 co_mult
= lambda c
: myobj
.matrix_world
@ c
1060 if myobj
.mode
== 'EDIT':
1061 bm
= from_edit_mesh(myobj
.data
)
1064 obverts
= myobj
.data
.vertices
1067 # Display only selected
1068 if scene
.measureit_debug_select
is True:
1069 if v
.select
is False:
1071 # noinspection PyBroadException
1073 a_p1
= get_point(v
.co
, myobj
)
1074 # converting to screen coordinates
1075 txtpoint2d
= get_2d_point(region
, rv3d
, a_p1
)
1078 if scene
.measureit_debug_vertices
is True:
1080 if scene
.measureit_debug_vert_loc
is True:
1081 txt
+= format_point(co_mult(v
.co
), precision
)
1082 draw_text(myobj
, txtpoint2d
, txt
, rgba
, fsize
)
1084 # print("Unexpected error:" + str(exc_info()))
1090 # -------------------------------------------------------------
1091 # Draw edge num for debug
1093 # -------------------------------------------------------------
1094 # noinspection PyUnresolvedReferences,PyUnboundLocalVariable,PyUnusedLocal
1095 def draw_edges(context
, myobj
, region
, rv3d
):
1097 if myobj
.type != "MESH":
1100 scene
= bpy
.context
.scene
1101 rgba
= scene
.measureit_debug_edge_color
1102 fsize
= scene
.measureit_debug_font
1103 precision
= scene
.measureit_debug_precision
1104 # --------------------
1107 # uses lambda for edge midpoint finder (midf) because edit mode
1108 # edge vert coordinate is not stored in same places as in obj mode
1109 # --------------------
1110 if myobj
.mode
== 'EDIT':
1111 bm
= from_edit_mesh(myobj
.data
)
1113 obverts
= None # dummy value to avoid duplicating for loop
1114 midf
= lambda e
, v
: e
.verts
[0].co
.lerp(e
.verts
[1].co
, 0.5)
1116 obedges
= myobj
.data
.edges
1117 obverts
= myobj
.data
.vertices
1118 midf
= lambda e
, v
: v
[e
.vertices
[0]].co
.lerp(v
[e
.vertices
[1]].co
, 0.5)
1121 # Display only selected
1122 if scene
.measureit_debug_select
is True:
1123 if e
.select
is False:
1125 a_mp
= midf(e
, obverts
)
1126 a_p1
= get_point(a_mp
, myobj
)
1127 # converting to screen coordinates
1128 txtpoint2d
= get_2d_point(region
, rv3d
, a_p1
)
1129 draw_text(myobj
, txtpoint2d
, str(e
.index
), rgba
, fsize
)
1133 # -------------------------------------------------------------
1134 # Draw face num for debug
1136 # -------------------------------------------------------------
1137 # noinspection PyUnresolvedReferences,PyUnboundLocalVariable,PyUnusedLocal
1138 def draw_faces(context
, myobj
, region
, rv3d
):
1140 if myobj
.type != "MESH":
1143 scene
= bpy
.context
.scene
1144 rgba
= scene
.measureit_debug_face_color
1145 rgba2
= scene
.measureit_debug_norm_color
1146 fsize
= scene
.measureit_debug_font
1147 ln
= scene
.measureit_debug_normal_size
1148 th
= scene
.measureit_debug_width
1149 precision
= scene
.measureit_debug_precision
1151 # --------------------
1153 # --------------------
1154 if myobj
.mode
== 'EDIT':
1155 bm
= from_edit_mesh(myobj
.data
)
1159 obverts
= myobj
.data
.vertices
1160 myfaces
= myobj
.data
.polygons
1164 # Display only selected
1165 if scene
.measureit_debug_select
is True:
1166 if f
.select
is False:
1168 # noinspection PyBroadException
1170 if myobj
.mode
== 'EDIT':
1171 a_p1
= get_point(f
.calc_center_median(), myobj
)
1173 a_p1
= get_point(f
.center
, myobj
)
1175 a_p2
= (a_p1
[0] + normal
[0] * ln
, a_p1
[1] + normal
[1] * ln
, a_p1
[2] + normal
[2] * ln
)
1177 gpu
.state
.blend_set('ALPHA')
1178 imm_set_line_width(th
)
1179 # converting to screen coordinates
1180 txtpoint2d
= get_2d_point(region
, rv3d
, a_p1
)
1181 point2
= get_2d_point(region
, rv3d
, a_p2
)
1183 if scene
.measureit_debug_faces
is True:
1184 draw_text(myobj
, txtpoint2d
, str(f
.index
), rgba
, fsize
)
1186 if scene
.measureit_debug_normals
is True:
1187 gpu
.state
.blend_set('ALPHA')
1188 draw_arrow(txtpoint2d
, point2
, rgba
, 10, "99", "1")
1190 if len(obverts
) > 2 and scene
.measureit_debug_normal_details
is True:
1191 if myobj
.mode
== 'EDIT':
1192 i1
= f
.verts
[0].index
1193 i2
= f
.verts
[1].index
1194 i3
= f
.verts
[2].index
1200 a_p1
= get_point(obverts
[i1
].co
, myobj
)
1201 a_p2
= get_point(obverts
[i2
].co
, myobj
)
1202 a_p3
= get_point(obverts
[i3
].co
, myobj
)
1203 # converting to screen coordinates
1204 a2d
= get_2d_point(region
, rv3d
, a_p1
)
1205 b2d
= get_2d_point(region
, rv3d
, a_p2
)
1206 c2d
= get_2d_point(region
, rv3d
, a_p3
)
1208 draw_arrow(a2d
, b2d
, rgba
, 10, "99", "1")
1209 draw_arrow(b2d
, c2d
, rgba
, 10, "99", "1")
1210 # Normal vector data
1211 txt
= format_point(normal
, precision
)
1212 draw_text(myobj
, point2
, txt
, rgba2
, fsize
)
1215 print("Unexpected error:" + str(exc_info()))
1221 # --------------------------------------------------------------------
1222 # Distance between 2 points in 3D space
1225 # locx/y/z: Use this axis
1227 # --------------------------------------------------------------------
1228 def distance(v1
, v2
, locx
=True, locy
=True, locz
=True):
1229 x
= sqrt((v2
[0] - v1
[0]) ** 2 + (v2
[1] - v1
[1]) ** 2 + (v2
[2] - v1
[2]) ** 2)
1231 # If axis is not used, make equal both (no distance)
1232 v1b
= [v1
[0], v1
[1], v1
[2]]
1233 v2b
= [v2
[0], v2
[1], v2
[2]]
1241 xloc
= sqrt((v2b
[0] - v1b
[0]) ** 2 + (v2b
[1] - v1b
[1]) ** 2 + (v2b
[2] - v1b
[2]) ** 2)
1246 # --------------------------------------------------------------------
1247 # Interpolate 2 points in 3D space
1251 # return: interpolate point
1252 # --------------------------------------------------------------------
1253 def interpolate3d(v1
, v2
, d1
):
1255 v
= (v2
[0] - v1
[0], v2
[1] - v1
[1], v2
[2] - v1
[2])
1256 # calculate distance between points
1257 d0
, dloc
= distance(v1
, v2
)
1259 # calculate interpolate factor (distance from origin / distance total)
1260 # if d1 > d0, the point is projected in 3D space
1266 final
= (v1
[0] + (v
[0] * x
), v1
[1] + (v
[1] * x
), v1
[2] + (v
[2] * x
))
1270 # --------------------------------------------------------------------
1271 # Get point rotated and relative to parent
1274 # --------------------------------------------------------------------
1275 def get_point(v1
, mainobject
):
1276 # Using World Matrix
1277 vt
= Vector((v1
[0], v1
[1], v1
[2], 1))
1278 m4
= mainobject
.matrix_world
1280 v2
= [vt2
[0], vt2
[1], vt2
[2]]
1285 # --------------------------------------------------------------------
1286 # Get location in world space
1289 # --------------------------------------------------------------------
1290 def get_location(mainobject
):
1291 # Using World Matrix
1292 m4
= mainobject
.matrix_world
1294 return [m4
[0][3], m4
[1][3], m4
[2][3]]
1297 # --------------------------------------------------------------------
1300 # --------------------------------------------------------------------
1301 def get_mesh_vertices(myobj
):
1303 if myobj
.mode
== 'EDIT':
1304 bm
= from_edit_mesh(myobj
.data
)
1307 obverts
= myobj
.data
.vertices
1310 except AttributeError:
1314 # --------------------------------------------------------------------
1315 # Get position for scale text
1317 # --------------------------------------------------------------------
1318 def get_scale_txt_location(context
):
1319 scene
= context
.scene
1320 pos_x
= int(context
.region
.width
* scene
.measureit_scale_pos_x
/ 100)
1321 pos_y
= int(context
.region
.height
* scene
.measureit_scale_pos_y
/ 100)
1326 # --------------------------------------------------------------------
1327 # Get position in final render image
1328 # (Z < 0 out of camera)
1329 # return 2d position
1330 # --------------------------------------------------------------------
1331 def get_render_location(mypoint
):
1333 v1
= Vector(mypoint
)
1334 scene
= bpy
.context
.scene
1335 co_2d
= object_utils
.world_to_camera_view(scene
, scene
.camera
, v1
)
1337 render_scale
= scene
.render
.resolution_percentage
/ 100
1338 render_size
= (int(scene
.render
.resolution_x
* render_scale
),
1339 int(scene
.render
.resolution_y
* render_scale
))
1341 return [round(co_2d
.x
* render_size
[0]), round(co_2d
.y
* render_size
[1])]
1344 # ---------------------------------------------------------
1345 # Get center of circle base on 3 points
1347 # Point a: (x,y,z) arc start
1348 # Point b: (x,y,z) center
1349 # Point c: (x,y,z) midle point in the arc
1350 # Point d: (x,y,z) arc end
1352 # ang: angle (radians)
1355 # ---------------------------------------------------------
1356 def get_arc_data(pointa
, pointb
, pointc
, pointd
):
1357 v1
= Vector((pointa
[0] - pointb
[0], pointa
[1] - pointb
[1], pointa
[2] - pointb
[2]))
1358 v2
= Vector((pointc
[0] - pointb
[0], pointc
[1] - pointb
[1], pointc
[2] - pointb
[2]))
1359 v3
= Vector((pointd
[0] - pointb
[0], pointd
[1] - pointb
[1], pointd
[2] - pointb
[2]))
1361 angle
= v1
.angle(v2
) + v2
.angle(v3
)
1363 rclength
= pi
* 2 * v2
.length
* (angle
/ (pi
* 2))
1365 return angle
, rclength
1368 # -------------------------------------------------------------
1369 # Format a number to the right unit
1371 # -------------------------------------------------------------
1372 def format_distance(fmt
, units
, value
, factor
=1):
1373 s_code
= "\u00b2" # Superscript two
1374 hide_units
= bpy
.context
.scene
.measureit_hide_units
1375 # ------------------------
1377 # ------------------------
1380 if bpy
.context
.scene
.unit_settings
.system
== "IMPERIAL":
1381 feet
= value
* (3.2808399 ** factor
)
1382 if round(feet
, 2) >= 1.0:
1383 if hide_units
is False:
1387 tx_dist
= fmt
% feet
1389 inches
= value
* (39.3700787 ** factor
)
1390 if hide_units
is False:
1394 tx_dist
= fmt
% inches
1395 elif bpy
.context
.scene
.unit_settings
.system
== "METRIC":
1396 if round(value
, 2) >= 1.0:
1397 if hide_units
is False:
1401 tx_dist
= fmt
% value
1403 if round(value
, 2) >= 0.01:
1404 if hide_units
is False:
1408 d_cm
= value
* (100 ** factor
)
1409 tx_dist
= fmt
% d_cm
1411 if hide_units
is False:
1415 d_mm
= value
* (1000 ** factor
)
1416 tx_dist
= fmt
% d_mm
1418 tx_dist
= fmt
% value
1419 # ------------------------
1421 # ------------------------
1423 if hide_units
is False:
1427 tx_dist
= fmt
% value
1428 # ------------------------
1430 # ------------------------
1432 if hide_units
is False:
1436 d_cm
= value
* (100 ** factor
)
1437 tx_dist
= fmt
% d_cm
1438 # ------------------------
1440 # ------------------------
1442 if hide_units
is False:
1446 d_mm
= value
* (1000 ** factor
)
1447 tx_dist
= fmt
% d_mm
1448 # ------------------------
1450 # ------------------------
1452 if hide_units
is False:
1456 feet
= value
* (3.2808399 ** factor
)
1457 tx_dist
= fmt
% feet
1458 # ------------------------
1460 # ------------------------
1462 if hide_units
is False:
1466 inches
= value
* (39.3700787 ** factor
)
1467 tx_dist
= fmt
% inches
1468 # ------------------------
1470 # ------------------------
1472 tx_dist
= fmt
% value
1477 # -------------------------------------------------------------
1478 # Get radian float based on angle choice
1480 # -------------------------------------------------------------
1481 def get_angle_in_rad(fangle
):
1485 return radians(fangle
)