Skip to content

Commit 8df36d3

Browse files
committed
fix(VertexNormal): weight polygon vertex normal by vertex angles
1 parent 54661ba commit 8df36d3

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/geode/mesh/core/surface_mesh.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <geode/basic/pimpl_impl.hpp>
3939
#include <geode/basic/uuid.hpp>
4040

41+
#include <geode/geometry/angle.hpp>
4142
#include <geode/geometry/basic_objects/infinite_line.hpp>
4243
#include <geode/geometry/basic_objects/polygon.hpp>
4344
#include <geode/geometry/basic_objects/segment.hpp>
@@ -1205,9 +1206,25 @@ namespace geode
12051206
Vector3D normal;
12061207
for( const auto& polygon : polygons_around_vertex( vertex_id ) )
12071208
{
1208-
if( const auto p_normal = polygon_normal( polygon.polygon_id ) )
1209+
const auto polygon_id = polygon.polygon_id;
1210+
if( const auto p_normal = polygon_normal( polygon_id ) )
12091211
{
1210-
normal = normal + p_normal.value();
1212+
const auto local_id =
1213+
this->vertex_in_polygon( polygon_id, vertex_id );
1214+
const auto polygon_vertex =
1215+
PolygonVertex( polygon_id, local_id.value() );
1216+
const auto previous_vertex =
1217+
this->previous_polygon_vertex( polygon_vertex );
1218+
const auto next_vertex =
1219+
this->next_polygon_vertex( polygon_vertex );
1220+
const Vector3D prev{ this->point( this->polygon_vertex(
1221+
previous_vertex ) ),
1222+
this->point( vertex_id ) };
1223+
const Vector3D next{ this->point(
1224+
this->polygon_vertex( next_vertex ) ),
1225+
this->point( vertex_id ) };
1226+
const auto angle = Angle::create_from_vectors( prev, next );
1227+
normal = normal + p_normal.value() * angle.radians();
12111228
}
12121229
}
12131230
try

0 commit comments

Comments
 (0)