Skip to content

Commit

Permalink
Handle bad geometry in bvh
Browse files Browse the repository at this point in the history
Crashed if more than two faces was exactly the same.
  • Loading branch information
dgud committed Feb 9, 2019
1 parent b2981d1 commit 199eea7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions e3d/e3d_bvh.erl
Expand Up @@ -172,10 +172,14 @@ build_hierarchy([Node], _TT) -> Node;
build_hierarchy(Nodes, TT) ->
Split = find_best_split(Nodes),
case partition(Split, Nodes) of
{L1,L2} ->
{L1,L2} when L1 =/= [], L2 =/= [] ->
#{bb:=LBB} = Left = build_hierarchy(L1, TT),
#{bb:=RBB} = Right = build_hierarchy(L2, TT),
#{bb=>e3d_bv:union(LBB,RBB), left=>Left, right=>Right}
#{bb=>e3d_bv:union(LBB,RBB), left=>Left, right=>Right};
_ -> %% More than two faces in the same place, arbitrary split
[Left|Rest] = Nodes,
#{bb:=RBB} = Right = build_hierarchy(Rest, TT),
#{bb=>RBB, left=>Left, right=>Right}
end.

find_best_split(Nodes) ->
Expand Down

0 comments on commit 199eea7

Please sign in to comment.