From bfcc8decc06657ce4627f23aeb9d2eea754c469d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 30 Jun 2023 15:02:39 +0500 Subject: [PATCH] Calculating angle based on world position instead of camera pos #3362 --- .../blenderbim/bim/module/drawing/decoration.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/decoration.py b/src/blenderbim/blenderbim/bim/module/drawing/decoration.py index a5d6c8067a..39178e9bf4 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/decoration.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/decoration.py @@ -772,19 +772,23 @@ class AngleDecorator(BaseDecorator): v0 = Vector(vertices[i0]) v1 = Vector(vertices[i1]) v2 = Vector(vertices[i1 + 1]) - p0 = location_3d_to_region_2d(region, region3d, v0) - p1 = location_3d_to_region_2d(region, region3d, v1) - p2 = location_3d_to_region_2d(region, region3d, v2) - edge0 = p0 - p1 - edge1 = p2 - p1 + # calculate angle value + edge0_ws = v0 - v1 + edge1_ws = v2 - v1 try: - cos_a = edge0.dot(edge1) / (edge0.length * edge1.length) + cos_a = edge0_ws.dot(edge1_ws) / (edge0_ws.length * edge1_ws.length) except ZeroDivisionError: continue circle_angle_rad = acos(cos_a) circle_angle = circle_angle_rad / pi * 180 + # calculate angle position + p0 = location_3d_to_region_2d(region, region3d, v0) + p1 = location_3d_to_region_2d(region, region3d, v1) + p2 = location_3d_to_region_2d(region, region3d, v2) + edge0 = p0 - p1 + edge1 = p2 - p1 base_edge = edge0 if ccw(p0, p1, p2) else edge1 text_offset = (Matrix.Rotation(-circle_angle_rad / 2, 2) @ base_edge).normalized() * ANGLE_LABEL_OFFSET label_position = p1 + text_offset