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
|
// 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;
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,19 @@ 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) {
|
||||||
faces.appendAll(verts[tok[0]-1]);
|
const p = tok.map(t => verts[t-1]).flat();
|
||||||
faces.appendAll(verts[tok[1]-1]);
|
const t = base.util.triangulate(p, [], 3, true);
|
||||||
faces.appendAll(verts[tok[2]-1]);
|
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;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
if (faces.length) {
|
if (faces.length) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue