add support for obj extended face declaration
This commit is contained in:
parent
0dc3f190e4
commit
ffe1ca05e8
2 changed files with 17 additions and 5 deletions
|
|
@ -410,7 +410,7 @@ function orderClosest(array, fn, from) {
|
|||
// wrapper for earcut that handles higher order dimensions and finds the
|
||||
// two with the greatest delta to pass to the earcut algorith, then returns
|
||||
// an unwrapped array in the original dimensions
|
||||
function triangulate(array, holes, dims) {
|
||||
function triangulate(array, holes, dims, pos) {
|
||||
let narray;
|
||||
let info;
|
||||
if (dims === 2) {
|
||||
|
|
@ -452,6 +452,9 @@ function triangulate(array, holes, dims) {
|
|||
}
|
||||
}
|
||||
let ec = earcut(narray, holes, 2);
|
||||
if (pos) {
|
||||
return ec;
|
||||
}
|
||||
let oa = new Array(ec.length * dims);
|
||||
for (let i = 0, e = 0, l = ec.length, ai; i < l; i++) {
|
||||
ai = ec[i] * dims;
|
||||
|
|
|
|||
|
|
@ -44,10 +44,19 @@ function parse(text) {
|
|||
break;
|
||||
case 'f':
|
||||
let tok = toks.map(f => parseInt(f.split('/')[0]));
|
||||
// add support for negative indices (offset from last vertex array point)
|
||||
faces.appendAll(verts[tok[0]-1]);
|
||||
faces.appendAll(verts[tok[1]-1]);
|
||||
faces.appendAll(verts[tok[2]-1]);
|
||||
if (tok.length > 3) {
|
||||
const p = tok.map(t => verts[t-1]).flat();
|
||||
const t = base.util.triangulate(p, [], 3, true);
|
||||
const r = t.map(i => tok[i]);
|
||||
for (let v of r) {
|
||||
faces.appendAll(verts[v - 1]);
|
||||
}
|
||||
} else {
|
||||
// add support for negative indices (offset from last vertex array point)
|
||||
faces.appendAll(verts[tok[0]-1]);
|
||||
faces.appendAll(verts[tok[1]-1]);
|
||||
faces.appendAll(verts[tok[2]-1]);
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if (faces.length) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue