Skip to content

Commit

Permalink
Fix the calculation of vertical and horizontal edges
Browse files Browse the repository at this point in the history
- we now take the edges with the least angle to the appropriate axis
- fixes the issue with railing offsets when the face is not square with the xy-plane eg in a cirular floorplan
  • Loading branch information
ranjian0 committed Dec 2, 2024
1 parent ddb7a96 commit 3ef2290
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions btools/utils/util_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import bpy
from bmesh.types import BMVert, BMEdge, BMFace

from .util_constants import VEC_UP, VEC_DOWN
from .util_common import local_xyz, equal, minmax
from .util_constants import VEC_UP, VEC_DOWN, VEC_FORWARD, VEC_RIGHT


def get_edit_mesh():
Expand Down Expand Up @@ -137,9 +137,11 @@ def filter_vertical_edges(edges):
In 2D space(XY Plane), vertical is Y-axis, In 3D, vertical is Z-axis
"""
rnd = ft.partial(round, ndigits=3)
todeg = lambda x: rnd(math.degrees(x))
space_2d = len(set(rnd(v.co.z) for e in edges for v in e.verts)) == 1
if space_2d:
return list(filter(lambda e: abs(rnd(edge_vector(e).y)) == 1.0, edges))
# -- the vertical edges will have the smallest angle to Y-AXIS
return list(sorted(edges, key=lambda e: todeg(edge_vector(e).angle(VEC_FORWARD))))[:2]

# Any edge that has upward vector is considered vertical
# if the edge is slanting, it must be slanting on only one axis
Expand All @@ -158,9 +160,11 @@ def filter_horizontal_edges(edges):
In 2D space(XY Plane), horizontal is X-axis, In 3D, horizontal is XY-plane
"""
rnd = ft.partial(round, ndigits=3)
todeg = lambda x: rnd(math.degrees(x))
space_2d = len(set(rnd(v.co.z) for e in edges for v in e.verts)) == 1
if space_2d:
return list(filter(lambda e: abs(rnd(edge_vector(e).x)) == 1.0, edges))
# -- the horizontal edges will have the smallest angle to X-AXIS
return list(sorted(edges, key=lambda e: todeg(edge_vector(e).angle(VEC_RIGHT))))[:2]

# Any edge that is at right angle to global up vector is horizontal
def horizontal_3d(e):
Expand Down

0 comments on commit 3ef2290

Please sign in to comment.