From 44c05ce71d3f10470d53d1a738eea7b29eb3272d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 4 Dec 2023 12:00:22 +0500 Subject: [PATCH] Fix normals for generic parametric stairs #4020 Also made concrete stair normals defined more explicitly. --- src/blenderbim/blenderbim/tool/model.py | 12 +++++++++--- src/blenderbim/test/tool/test_model.py | 14 +++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/blenderbim/blenderbim/tool/model.py b/src/blenderbim/blenderbim/tool/model.py index a6cb9a58b2..192959bc1c 100644 --- a/src/blenderbim/blenderbim/tool/model.py +++ b/src/blenderbim/blenderbim/tool/model.py @@ -1109,6 +1109,9 @@ class Model(blenderbim.core.tool.Model): vertices.append(vertices[-1] * V(1, 0)) edges.extend([(last_vert_i - 1, last_vert_i), (last_vert_i, 0)]) + # flip edges direction for ccw polygon winding order + edges = [e[::-1] for e in edges] + elif stair_type == "CONCRETE": define_generic_stair_treads() @@ -1158,19 +1161,22 @@ class Model(blenderbim.core.tool.Model): if base_point.y > -base_slab_depth: # stair doesn't meet the slab vertices.append(base_point) - edges.append((0, len(vertices) - 1)) + edges.append((len(vertices) - 1, 0)) bottom_nib_end = len(vertices) - 1 else: # slab overlaps stair vertices.append(get_point_on_2d_line(y=start_vert.y - base_slab_depth)) vertices.append(start_vert + Vector((0, -base_slab_depth))) last_vertex_i = len(vertices) - 1 - edges.append((0, last_vertex_i)) + edges.append((last_vertex_i, 0)) edges.append((last_vertex_i - 1, last_vertex_i)) bottom_nib_end = len(vertices) - 2 # close the shape - edges.append((bottom_nib_end, top_nib_end)) + edges.append((top_nib_end, bottom_nib_end)) + + # flip edges direction for ccw polygon winding order + edges = [e[::-1] for e in edges] else: raise Exception(f"Unsupported stair type: {stair_type}") diff --git a/src/blenderbim/test/tool/test_model.py b/src/blenderbim/test/tool/test_model.py index 3137e19ca4..1a7f914ff3 100644 --- a/src/blenderbim/test/tool/test_model.py +++ b/src/blenderbim/test/tool/test_model.py @@ -199,10 +199,11 @@ class TestGenerateStair2DProfile(NewFile): (6, 7), (7, 8), (8, 9), - (0, 11), + (11, 0), (10, 11), - (10, 9), + (9, 10), ) + edges_data = [e[::-1] for e in edges_data] faces_data = () expected_profile = (verts_data, edges_data, faces_data) generated_profile = subject.generate_stair_2d_profile(**kwargs) @@ -235,7 +236,6 @@ class TestGenerateStair2DProfile(NewFile): V(0.1, 0, -0.25), V(0.0, 0, -0.25), ) - edges_data = ( (0, 1), (1, 2), @@ -247,10 +247,11 @@ class TestGenerateStair2DProfile(NewFile): (7, 8), (8, 9), (9, 10), - (0, 12), + (12, 0), (11, 12), - (11, 10), + (10, 11), ) + edges_data = [e[::-1] for e in edges_data] faces_data = () expected_profile = (verts_data, edges_data, faces_data) @@ -284,7 +285,6 @@ class TestGenerateStair2DProfile(NewFile): V(1.2, 0, 1.0), V(0.9, 0, 1.0), ) - edges_data = ( (0, 1), (1, 2), @@ -324,7 +324,6 @@ class TestGenerateStair2DProfile(NewFile): V(1.2, 0, 1.0), V(1.2, 0, 0.0), ) - edges_data = ( (0, 1), (1, 2), @@ -337,6 +336,7 @@ class TestGenerateStair2DProfile(NewFile): (8, 9), (9, 0), ) + edges_data = [e[::-1] for e in edges_data] faces_data = () expected_profile = (verts_data, edges_data, faces_data)