Merge branch 'master' into cam-topo4

This commit is contained in:
Stewart Allen 2023-01-17 21:29:31 -05:00
commit a6993ba038
2 changed files with 12 additions and 7 deletions

View file

@ -410,7 +410,7 @@ function orderClosest(array, fn, from) {
// wrapper for earcut that handles higher order dimensions and finds the // wrapper for earcut that handles higher order dimensions and finds the
// two with the greatest delta to pass to the earcut algorith, then returns // two with the greatest delta to pass to the earcut algorith, then returns
// an unwrapped array in the original dimensions // an unwrapped array in the original dimensions
function triangulate(array, holes, dims) { function triangulate(array, holes, dims, pos) {
let narray; let narray;
let info; let info;
if (dims === 2) { if (dims === 2) {
@ -452,6 +452,9 @@ function triangulate(array, holes, dims) {
} }
} }
let ec = earcut(narray, holes, 2); let ec = earcut(narray, holes, 2);
if (pos) {
return ec;
}
let oa = new Array(ec.length * dims); let oa = new Array(ec.length * dims);
for (let i = 0, e = 0, l = ec.length, ai; i < l; i++) { for (let i = 0, e = 0, l = ec.length, ai; i < l; i++) {
ai = ec[i] * dims; ai = ec[i] * dims;

View file

@ -44,13 +44,15 @@ function parse(text) {
break; break;
case 'f': case 'f':
let tok = toks.map(f => parseInt(f.split('/')[0])); let tok = toks.map(f => parseInt(f.split('/')[0]));
// add support for negative indices (offset from last vertex array point) if (tok.length > 3) {
if (toks.length > 3) { const p = tok.map(t => verts[t-1]).flat();
// earcut faces > 3 vertices const t = base.util.triangulate(p, [], 3, true);
// faces.appendAll(verts[tok[1]-1]); const r = t.map(i => tok[i]);
// faces.appendAll(verts[tok[2]-1]); for (let v of r) {
// faces.appendAll(verts[tok[3]-1]); faces.appendAll(verts[v - 1]);
}
} else { } else {
// add support for negative indices (offset from last vertex array point)
faces.appendAll(verts[tok[0]-1]); faces.appendAll(verts[tok[0]-1]);
faces.appendAll(verts[tok[1]-1]); faces.appendAll(verts[tok[1]-1]);
faces.appendAll(verts[tok[2]-1]); faces.appendAll(verts[tok[2]-1]);