improve flat layer additions
This commit is contained in:
parent
ab422d20c0
commit
766b1ef2cc
2 changed files with 18 additions and 19 deletions
|
|
@ -196,7 +196,6 @@ function pointsToPath(points, offset, open, miter = 1.5) {
|
|||
const left = [];
|
||||
const right = [];
|
||||
const faces = [];
|
||||
// const normals = new FloatPacker(points.length * 10, 1.25);
|
||||
const normals = [];
|
||||
const zn = -1;
|
||||
// calculate vertex normals from segments normals
|
||||
|
|
@ -331,7 +330,6 @@ function pointsToPath(points, offset, open, miter = 1.5) {
|
|||
normals.push(ln.dx, ln.dy, zn);
|
||||
}
|
||||
|
||||
// return { left, right, faces, normals: normals.finalize(), open };
|
||||
return { left, right, faces, normals, open };
|
||||
}
|
||||
|
||||
|
|
@ -537,15 +535,16 @@ class FloatPacker {
|
|||
push() {
|
||||
const array = this.array;
|
||||
const size = this.size;
|
||||
for (let i=0, l=arguments.length; i<l; i++) {
|
||||
const args = arguments.length;
|
||||
if (this.pos + args >= size) {
|
||||
let nusize = ((size * this.factor) | 0) + args;
|
||||
let nuarray = new Float32Array(nusize);
|
||||
nuarray.set(array);
|
||||
this.array = nuarray;
|
||||
this.size = nusize;
|
||||
}
|
||||
for (let i=0; i<args; i++) {
|
||||
array[this.pos++] = arguments[i];
|
||||
if (this.pos >= size) {
|
||||
let nusize = ((size * this.factor) | 0) + 1;
|
||||
let nuarray = new Float32Array(nusize);
|
||||
nuarray.set(array);
|
||||
this.array = nuarray;
|
||||
this.size = nusize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -156,16 +156,16 @@ class Layers {
|
|||
if (!polys.length) {
|
||||
return;
|
||||
}
|
||||
const cur = this.current;
|
||||
const z = polys[0].getZ(), faces = cur.faces;
|
||||
const off_opt = { z, flat: true };
|
||||
const cur = this.current, faces = cur.faces;
|
||||
const norms = [];
|
||||
for (let poly of polys) {
|
||||
const faceidx = faces.length / 3;
|
||||
const path = poly.toPath2D(offset * 0.95);
|
||||
const { left, right, normals } = path;
|
||||
for (let p of path.faces) {
|
||||
faces.push(p.x, p.y, poly.z || p.z);
|
||||
faces.push(p.x, p.y, p.z);
|
||||
}
|
||||
norms.push(normals);
|
||||
if (opts.outline) {
|
||||
let p1 = newPolygon().addPoints(left).setOpenValue(poly.open);
|
||||
let p2 = newPolygon().addPoints(right).setOpenValue(poly.open);
|
||||
|
|
@ -176,11 +176,6 @@ class Layers {
|
|||
this.addPolys(p1);
|
||||
this.addPolys(p2);
|
||||
}
|
||||
if (cur.norms) {
|
||||
cur.norms.appendAll(normals);
|
||||
} else {
|
||||
cur.norms = normals;
|
||||
}
|
||||
const color = opts.color ?
|
||||
(typeof(opts.color) === 'number' ? { line: opts.color, face: opts.color } : opts.color) :
|
||||
cur.color;
|
||||
|
|
@ -195,6 +190,11 @@ class Layers {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (cur.norms) {
|
||||
cur.norms.appendAll(norms.flat());
|
||||
} else {
|
||||
cur.norms = norms.flat();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue