Skip to content

Commit

Permalink
vertex normal
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanyiLi committed Nov 13, 2023
1 parent 7c85d5c commit a4d2cf0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions metadrive/utils/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def make_polygon_model(points, height, auto_anticlockwise=True, force_anticlockw
Returns: panda3d.NodePath
"""
no_side = abs(height) > 0.01
need_side = abs(height) > 0.01
if force_anticlockwise:
points = sort_points_anticlockwise(points)
elif not is_anticlockwise(points) and auto_anticlockwise:
Expand Down Expand Up @@ -126,11 +126,11 @@ def make_polygon_model(points, height, auto_anticlockwise=True, force_anticlockw
edge_1 = [edge_1[0] / l_1, edge_1[1] / l_1]
edge_2 = [edge_2[0] / l2, edge_2[1] / l2]

normal = np.array([[edge_1[1], -edge_1[0], 0], [edge_2[1], -edge_2[0], 0]])
normal = np.array([[-edge_1[1], edge_1[0], 0], [-edge_2[1], edge_2[0], 0]])
normal = np.mean(normal, axis=0)
normal = normal / np.linalg.norm(normal)

if no_side:
if need_side:
back_side_values.extend((x, y, -height, *normal, x * texture_scale, y * texture_scale))
triangulator.add_vertex(x, y)
triangulator.add_polygon_vertex(i)
Expand All @@ -146,7 +146,7 @@ def make_polygon_model(points, height, auto_anticlockwise=True, force_anticlockw
prim.add_vertices(index0, index1, index2)
# prim.closePrimitive()

if no_side:
if need_side:
# Add side
for i in range(p_num):
# First triangle
Expand All @@ -159,11 +159,11 @@ def make_polygon_model(points, height, auto_anticlockwise=True, force_anticlockw
# since the size of a memoryview cannot change, the vertex data table
# already needs to have the right amount of rows before creating
# memoryviews from its array(s)
vertex_data.unclean_set_num_rows(len(coords) * 2 if no_side else len(coords))
vertex_data.unclean_set_num_rows(len(coords) * 2 if need_side else len(coords))
# retrieve the data array for modification
data_array = vertex_data.modify_array(0)
memview = memoryview(data_array).cast("B").cast("f")
if no_side:
if need_side:
memview[:] = values + back_side_values
else:
memview[:] = values
Expand Down

0 comments on commit a4d2cf0

Please sign in to comment.