fixes #327 cleaning up svg to poly/extrusion legacy code
This commit is contained in:
parent
18b09d728d
commit
561911ee8e
1 changed files with 36 additions and 62 deletions
|
|
@ -22,11 +22,11 @@ function parse(text, opt = { }) {
|
|||
const rez = (opt.resolution || 1);
|
||||
const dpi = (opt.dpi || 0);
|
||||
const segmin = Math.max(1, opt.segmin || 10);
|
||||
const objs = [];
|
||||
const data = new THREE.SVGLoader().parse(text);
|
||||
const paths = data.paths;
|
||||
const xmlat = data.xml.attributes;
|
||||
const polys = fromSoup ? [] : undefined;
|
||||
const objs = [];
|
||||
const polys = [];
|
||||
const isinch = xmlat.width?.value.endsWith('in');
|
||||
const scale = isinch ? 25.4 : (dpi ? 1 / (dpi / 25.4) : 1);
|
||||
const depth = parseFloat(opt.depth || xmlat['data-km-extrude']?.value
|
||||
|
|
@ -39,7 +39,6 @@ function parse(text, opt = { }) {
|
|||
let type = path.userData?.node?.nodeName;
|
||||
let width = path.userData?.style?.strokeWidth;
|
||||
let miter = path.userData?.style?.strokeMiterLimit;
|
||||
if (fromSoup) {
|
||||
for (let sub of path.subPaths) {
|
||||
let points = sub.curves.map(curve => {
|
||||
let length = curve.getLength();
|
||||
|
|
@ -60,34 +59,10 @@ function parse(text, opt = { }) {
|
|||
poly.scale({ x: scale, y: scale, z: 1 });
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (justPoly) {
|
||||
continue;
|
||||
}
|
||||
let geom = new THREE.ExtrudeGeometry(shapes, {
|
||||
depth,
|
||||
steps: 1,
|
||||
bevelEnabled: false
|
||||
});
|
||||
let array = geom.attributes.position.array;
|
||||
// invert y
|
||||
for (let i=1; i<array.length; i+=3) {
|
||||
array[i] = -array[i];
|
||||
}
|
||||
// invert vertex order to compensate for inverted y
|
||||
for (let i=0; i<array.length; i+=9) {
|
||||
let tmp = array.slice(i,i+3);
|
||||
for (let j=0; j<3; j++) {
|
||||
array[i+j] = array[i+j+3];
|
||||
array[i+j+3] = tmp[j];
|
||||
}
|
||||
}
|
||||
objs.push([ ...array ]);
|
||||
}
|
||||
|
||||
if (fromSoup) {
|
||||
const nest = base.polygons.nest(polys.filter(p => {
|
||||
const sub = fromSoup ? base.polygons.nest(polys) : polys;
|
||||
const nest = sub.filter(p => {
|
||||
// filter duplicates
|
||||
for (let pc of polys) {
|
||||
if (pc === p) {
|
||||
|
|
@ -96,7 +71,7 @@ function parse(text, opt = { }) {
|
|||
return !pc.isEquivalent(p);
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
if (justPoly) {
|
||||
return nest;
|
||||
|
|
@ -106,9 +81,8 @@ function parse(text, opt = { }) {
|
|||
let obj = poly.extrude(depth);
|
||||
objs.push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
return justPoly ? polys : objs;
|
||||
return objs;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue