Skip to content

Commit

Permalink
Handle missing vertex normals
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Oct 15, 2024
1 parent 608eeac commit f07d18e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/wings_we_build.erl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ find_hard_edges(Face, FlatNormal, SmoothNs0, EdgeNs, {He0, Possible0}, We) ->
#edge{lf = Face, vs = V, ltsu = Next} -> {VNS, Next};
#edge{rf = Face, ve = V, rtsu = Next} -> {VNE, Next}
end,
case e3d_vec:dist_sqr(VN, FlatNormal) < ?EPSILON of
try e3d_vec:dist_sqr(VN, FlatNormal) < ?EPSILON of
true ->
%% io:format("HE: V=~3w F=~3w Es: ~w ~w~n", [V, Face, Edge, Other]),
{SmoothNs, [Edge, Other|He], Possible};
Expand All @@ -522,6 +522,10 @@ find_hard_edges(Face, FlatNormal, SmoothNs0, EdgeNs, {He0, Possible0}, We) ->
%% io:format(" Calc: ~s Imp: ~s Face: ~s~n", [e3d_vec:format(SN), e3d_vec:format(VN), e3d_vec:format(FlatNormal)]),
{SmoothNs, He, [V|Possible]}
end
catch error:function_clause ->
%% Missing vertex normal, assume face-normal or smooth?
%% Currently we make it smooth
{SmoothNs, He, Possible}
end
end,
{[], He, Poss} = wings_face:fold(Fun, {lists:reverse(SmoothNs0), He0, Possible0}, Face, We),
Expand All @@ -548,11 +552,14 @@ find_he_from_vertex([], _, HeAcc, _) ->
pick_edges({N1, Edge, NextFace}, Tree0, Acc) ->
try gb_trees:take(NextFace, Tree0) of
{{N2, _, _} = Next, Tree} ->
case e3d_vec:dist_sqr(N1,N2) < ?EPSILON of
try e3d_vec:dist_sqr(N1,N2) < ?EPSILON of
true -> pick_edges(Next, Tree, Acc);
false -> pick_edges(Next, Tree, [Edge|Acc])
catch error:function_clause ->
%% Vertex normals assume smooth normal
pick_edges(Next, Tree, Acc)
end
catch _:_ ->
catch _E:_R ->
Acc
end.

Expand Down

0 comments on commit f07d18e

Please sign in to comment.