add more image import options. fix large array appends. optimize shadow in highly detained meshes

This commit is contained in:
Stewart Allen 2020-11-27 14:42:55 -05:00
commit 7292f1c141
7 changed files with 53 additions and 18 deletions

View file

@ -9,8 +9,6 @@
* laser * laser
* drag knife support * drag knife support
* all * all
* 2d image to 3d part
* cnc: abandon mapping (tshadow) when z count high (organic) and just use top z
* circular fit/layout when no-layout to prevent collisions * circular fit/layout when no-layout to prevent collisions
## 2.5 roadmap ## 2.5 roadmap
@ -25,7 +23,6 @@
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix ## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
* `F` 2D image import
* `F` detect and report slow framerates * `F` detect and report slow framerates
* `F` right click / context menu (object deletion, etc) * `F` right click / context menu (object deletion, etc)
* `P` improve decimation speed by avoiding in/out of Point? * `P` improve decimation speed by avoiding in/out of Point?

View file

@ -50,8 +50,17 @@
* @returns {Array} * @returns {Array}
*/ */
AP.appendAll = function(arr) { AP.appendAll = function(arr) {
// if (arr && arr.length > 0) this.push.apply(this,arr); if (arr && arr.length > 0) {
if (arr && arr.length > 0) this.push(...arr); // avoid hitting stack limits
if (arr.length > 10000) {
for (let i=0, il=arr.length; i<il; i++) {
this.push(arr[i]);
}
} else {
// this.push.apply(this,arr); (slower?)
this.push(...arr);
}
}
return this; return this;
}; };

View file

@ -954,14 +954,22 @@
" be blurred to be usable. Values from 0=off to 50=high are suggested.", " be blurred to be usable. Values from 0=off to 50=high are suggested.",
" Higher values incur more processing time.", " Higher values incur more processing time.",
" </p>", " </p>",
" <div class='f-row'>", " <div class='f-row t-right'><table>",
" <label>blur value</label>&nbsp;<input id='png-blur' value='0' size='3'>", " <tr><th>blur value</th><td><input id='png-blur' value='0' size='3'></td>",
" </div>", " <th>&nbsp;invert image</th><td><input id='png-inv' type='checkbox'></td></tr>",
" <tr><th>base size</th><td><input id='png-base' value='0' size='3'></td>",
" <th>&nbsp;invert alpha</th><td><input id='alpha-inv' type='checkbox'></td></tr>",
" </table></div>",
"</div>" "</div>"
]}; ]};
UC.confirm(undefined, {convert:true, cancel:false}, undefined, opt).then((ok) => { UC.confirm(undefined, {convert:true, cancel:false}, undefined, opt).then((ok) => {
if (ok) { if (ok) {
loadImage(image, {blur: parseInt($('png-blur').value) || 0}); loadImage(image, {
blur: parseInt($('png-blur').value) || 0,
base: parseInt($('png-base').value) || 0,
inv_image: $('png-inv').checked,
inv_alpha: $('alpha-inv').checked,
});
} }
}); });
} }

View file

@ -268,13 +268,19 @@ KIRI.worker = {
// convert png to grayscale // convert png to grayscale
let gray = new Uint8Array(width * height); let gray = new Uint8Array(width * height);
let gi = 0; let gi = 0;
let invi = info.inv_image ? true : false;
let inva = info.inv_alpha ? true : false;
for (let y = 0; y < height; y++) { for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) { for (let x = 0; x < width; x++) {
let di = (x + width * y) * 4; let di = (x + width * y) * 4;
let r = data[di]; let r = data[di];
let g = data[di+1]; let g = data[di+1];
let b = data[di+2]; let b = data[di+2];
let v = (r + g + b) / 3; let a = data[di+3];
let v = ((r + g + b) / 3);
if (invi) v = 255 - v;
if (inva) a = 255 - a;
v *= (a/255);
gray[gi++] = v; gray[gi++] = v;
} }
} }
@ -303,6 +309,7 @@ KIRI.worker = {
gray = blur; gray = blur;
} }
// create indexed mesh output // create indexed mesh output
let base = parseInt(info.base || 0);
let verts = new Float32Array(points * 3); let verts = new Float32Array(points * 3);
let faces = new Uint32Array(flats * 6); let faces = new Uint32Array(flats * 6);
let w2 = width / 2; let w2 = width / 2;
@ -318,7 +325,7 @@ KIRI.worker = {
// create vertex @ x,y // create vertex @ x,y
verts[vi++] = (-w2 + x) / div; verts[vi++] = (-w2 + x) / div;
verts[vi++] = (h2 - y) / div; verts[vi++] = (h2 - y) / div;
verts[vi++] = ((255 - v) / 50); verts[vi++] = ((255 - v) / 50) + base;
VI++; VI++;
// create two surface faces on the rect between x-1,y-1 and x,y // create two surface faces on the rect between x-1,y-1 and x,y
if (x > 0 && y > 0) { if (x > 0 && y > 0) {

View file

@ -140,10 +140,15 @@
let tslices = []; let tslices = [];
let tshadow = []; let tshadow = [];
let tzindex = slicer.interval(minStepDown, { fit: true, off: 0.01, down: true, flats: true }); let tzindex = slicer.interval(minStepDown, { fit: true, off: 0.01, down: true, flats: true });
let fakeTerrain = false;
if (tzindex.length > 100) {
fakeTerrain = tzindex[0];
tzindex = [ tzindex.pop() ];
}
let terrain = slicer.slice(tzindex, { each: (data, index, total) => { let terrain = slicer.slice(tzindex, { each: (data, index, total) => {
tshadow = POLY.union(tshadow.appendAll(data.tops), 0.01, true); tshadow = POLY.union(tshadow.appendAll(data.tops), 0.01, true);
tslices.push(data.slice); tslices.push(data.slice);
if (false) { if (true) {
const slice = data.slice; const slice = data.slice;
sliceAll.push(slice); sliceAll.push(slice);
slice.output() slice.output()
@ -152,6 +157,12 @@
} }
updateOp(index, total); updateOp(index, total);
}, genso: true }); }, 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 shadowTop = terrain[terrain.length - 1];
let center = tshadow[0].bounds.center(); let center = tshadow[0].bounds.center();

View file

@ -69,9 +69,9 @@
center = opt.center, center = opt.center,
debug = false, debug = false,
debug_clips = debug && true, debug_clips = debug && true,
debug_topo = debug && false, debug_topo = debug && true,
debug_topo_lines = debug && false, debug_topo_lines = debug && true,
debug_topo_shells = debug && false; debug_topo_shells = debug && true;
if (tabs) { if (tabs) {
clipTab.appendAll(tabs.map(tab => POLY.expand([tab.poly], toolDiameter/2)).flat()); clipTab.appendAll(tabs.map(tab => POLY.expand([tab.poly], toolDiameter/2)).flat());

View file

@ -126,9 +126,6 @@ th, tr, td, label {
.grow { .grow {
flex-grow: 1; flex-grow: 1;
} }
.t-just {
text-align: justify;
}
.a-start { .a-start {
align-items: flex-start; align-items: flex-start;
} }
@ -156,6 +153,12 @@ th, tr, td, label {
.center { .center {
text-align: center; text-align: center;
} }
.t-just {
text-align: justify;
}
.t-right {
text-align: right;
}
.russo { .russo {
font-family: 'Russo One', sans-serif; font-family: 'Russo One', sans-serif;
} }