add obj import grouping, naming, and auto-scaling for Onshape exports

This commit is contained in:
Stewart Allen 2021-08-28 19:20:37 -04:00
commit 94b85351c2
3 changed files with 44 additions and 9 deletions

View file

@ -18,6 +18,7 @@
let lines = text.split('\n').map(l => l.trim());
let verts = [];
let faces = [];
let obj = [ faces ];
for (let line of lines) {
let toks = line.split(' ');
@ -27,17 +28,23 @@
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]);
break;
case 'g':
case 'o':
if (faces.length) {
obj.push(faces = []);
}
if (toks[0]) {
faces.name = toks[0];
}
break;
}
}
return [ faces ];
return obj;
}
})();