change fakeTerrain to skipTerrain and do proper implementation. better alpha handling for 2d image conversions
This commit is contained in:
parent
6555368b1a
commit
f8ce55b7f0
3 changed files with 23 additions and 21 deletions
|
|
@ -279,6 +279,7 @@ KIRI.worker = {
|
|||
1; // base
|
||||
// convert png to grayscale
|
||||
let gray = new Uint8Array(width * height);
|
||||
let alpha = new Uint8Array(width * height);
|
||||
let gi = 0;
|
||||
let invi = info.inv_image ? true : false;
|
||||
let inva = info.inv_alpha ? true : false;
|
||||
|
|
@ -291,15 +292,15 @@ KIRI.worker = {
|
|||
let b = data[di+2];
|
||||
let a = data[di+3];
|
||||
let v = ((r + g + b) / 3);
|
||||
if (inva) a = 255 - a;
|
||||
if (invi) v = 255 - v;
|
||||
if (border) {
|
||||
if (x < border || y < border || x > width-border-1 || y > height-border-1) {
|
||||
v = 255;
|
||||
}
|
||||
}
|
||||
if (invi) v = 255 - v;
|
||||
if (inva) a = 255 - a;
|
||||
v *= (a/255);
|
||||
gray[gi++] = v;
|
||||
alpha[gi] = a;
|
||||
gray[gi++] = v * (a / 255);
|
||||
}
|
||||
}
|
||||
let blur = parseInt(info.blur || 0);
|
||||
|
|
@ -311,7 +312,8 @@ KIRI.worker = {
|
|||
let xr = Math.min(x+1,width-1);
|
||||
let yu = Math.max(y-1,0);
|
||||
let yd = Math.min(y+1,height-1);
|
||||
blur[x + width * y] = (
|
||||
let id = x + width * y;
|
||||
blur[id] = ((
|
||||
gray[xl + (width * yu)] +
|
||||
gray[x + (width * yu)] +
|
||||
gray[xr + (width * yu)] +
|
||||
|
|
@ -321,7 +323,7 @@ KIRI.worker = {
|
|||
gray[xl + (width * yd)] +
|
||||
gray[x + (width * yd)] +
|
||||
gray[xr + (width * yd)]
|
||||
) / 9;
|
||||
) / 9);
|
||||
}
|
||||
}
|
||||
gray = blur;
|
||||
|
|
@ -339,11 +341,12 @@ KIRI.worker = {
|
|||
// create surface vertices & faces
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let y = 0; y < height; y++) {
|
||||
let v = gray[x + width * y];
|
||||
let id = x + width * y;
|
||||
let v = gray[id];
|
||||
// create vertex @ x,y
|
||||
verts[vi++] = (-w2 + x) / div;
|
||||
verts[vi++] = (h2 - y) / div;
|
||||
verts[vi++] = ((255 - v) / 50) + base;
|
||||
verts[vi++] = (v / 50) + (base * alpha[id] / 255);
|
||||
VI++;
|
||||
// create two surface faces on the rect between x-1,y-1 and x,y
|
||||
if (x > 0 && y > 0) {
|
||||
|
|
|
|||
|
|
@ -99,12 +99,12 @@
|
|||
tip2tipEmit = print.tip2tipEmit,
|
||||
poly2polyEmit = print.poly2polyEmit,
|
||||
maxToolDiam = widget.maxToolDiam,
|
||||
terrain = widget.terrain.map(data => {
|
||||
terrain = widget.terrain ? widget.terrain.map(data => {
|
||||
return {
|
||||
z: data.z,
|
||||
tops: data.tops,
|
||||
};
|
||||
});
|
||||
}) : zmax;
|
||||
|
||||
function newLayer() {
|
||||
if (layerOut.length < 2) {
|
||||
|
|
@ -637,6 +637,9 @@
|
|||
* return tool Z clearance height for a line segment movement path
|
||||
*/
|
||||
function getZClearPath(terrain, x1, y1, x2, y2, z, zadd, off, over) {
|
||||
if (terrain > 0) {
|
||||
return terrain + zadd + over;
|
||||
}
|
||||
let maxz = z;
|
||||
let check = [];
|
||||
for (let i=0; i<terrain.length; i++) {
|
||||
|
|
|
|||
|
|
@ -168,11 +168,12 @@
|
|||
let tslices = [];
|
||||
let tshadow = [];
|
||||
let tzindex = slicer.interval(minStepDown, { fit: true, off: 0.01, down: true, flats: true });
|
||||
let fakeTerrain = false;
|
||||
// if (tzindex.length > 200) {
|
||||
// fakeTerrain = tzindex[0];
|
||||
// tzindex = [ tzindex.pop() ];
|
||||
// }
|
||||
let skipTerrain = !(procRough || procOutline) && tzindex.length > 50;
|
||||
|
||||
if (skipTerrain) {
|
||||
console.log("skipping terrain generation for speed");
|
||||
tzindex = [ tzindex.pop() ];
|
||||
}
|
||||
|
||||
let terrain = slicer.slice(tzindex, { each: (data, index, total) => {
|
||||
tshadow = POLY.union(tshadow.slice().appendAll(data.tops), 0.01, true);
|
||||
|
|
@ -186,11 +187,6 @@
|
|||
}
|
||||
updateOp(index, total);
|
||||
}, genso: true });
|
||||
if (fakeTerrain) {
|
||||
// to avoid compute for highly detailed maps, force all
|
||||
// moves above part top by synthesizing a single terrain slice
|
||||
terrain[0].z = fakeTerrain.z;
|
||||
}
|
||||
|
||||
let shadowTop = terrain[terrain.length - 1];
|
||||
let center = tshadow[0].bounds.center();
|
||||
|
|
@ -572,7 +568,7 @@
|
|||
// dslice.output().setLayer("shadowOff", { line: 0xff0000 }).addPolys(shadowOff);
|
||||
// sliceAll.push(dslice);
|
||||
|
||||
widget.terrain = terrain;
|
||||
widget.terrain = skipTerrain ? null : terrain;
|
||||
widget.minToolDiam = minToolDiam;
|
||||
widget.maxToolDiam = maxToolDiam;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue