alecjacobson / gptoolbox

Matlab toolbox for Geometry Processing.
MIT License
629 stars 169 forks source link

Allow split_backfacing to handle single trimesh elements #124

Open ThSGM opened 3 years ago

ThSGM commented 3 years ago

I had an issue with using split_backfacing when the input consists of a single trimesh patch. For example, running this command:

tplot = tsurf(faces, verts);
[backtri, fronttri] = split_backfacing(tplot);

produces an error since split_backfacing is attempting to access tplot{1} instead of tplot.

I changed the initial lines of the for loop to:

  for ti = 1:numel(ts)
    if iscell(ts) == 0 && numel(ts) == 1
        tmp = ts; ts = []; ts{1} = tmp;        
    end
    t = ts{ti};
...

and also added this at the end:

if numel(ts) == 1
      ts = ts{1};
      bs = bs{1};
  end

which outputs the trimesh patches direct if there is only a single element.

There are probably slicker ways to do it, but this seemed like an issue for me.