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

@ -954,14 +954,22 @@
" be blurred to be usable. Values from 0=off to 50=high are suggested.",
" Higher values incur more processing time.",
" </p>",
" <div class='f-row'>",
" <label>blur value</label>&nbsp;<input id='png-blur' value='0' size='3'>",
" </div>",
" <div class='f-row t-right'><table>",
" <tr><th>blur value</th><td><input id='png-blur' value='0' size='3'></td>",
" <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>"
]};
UC.confirm(undefined, {convert:true, cancel:false}, undefined, opt).then((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
let gray = new Uint8Array(width * height);
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 x = 0; x < width; x++) {
let di = (x + width * y) * 4;
let r = data[di];
let g = data[di+1];
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;
}
}
@ -303,6 +309,7 @@ KIRI.worker = {
gray = blur;
}
// create indexed mesh output
let base = parseInt(info.base || 0);
let verts = new Float32Array(points * 3);
let faces = new Uint32Array(flats * 6);
let w2 = width / 2;
@ -318,7 +325,7 @@ KIRI.worker = {
// create vertex @ x,y
verts[vi++] = (-w2 + x) / div;
verts[vi++] = (h2 - y) / div;
verts[vi++] = ((255 - v) / 50);
verts[vi++] = ((255 - v) / 50) + base;
VI++;
// create two surface faces on the rect between x-1,y-1 and x,y
if (x > 0 && y > 0) {