complete image import dialog. bump rev 2.4.d6

This commit is contained in:
Stewart Allen 2020-11-27 13:06:56 -05:00
commit 6b90e6a9bd
6 changed files with 60 additions and 11 deletions

View file

@ -945,13 +945,34 @@
});
}
function loadImage(image) {
KIRI.client.image2mesh({settings, png:image}, progress => {
function loadImageDialog(image) {
const opt = {pre: [
"<div class='f-col a-center'>",
" <h3>Image Conversion</h3>",
" <p class='t-just' style='width:300px;line-height:1.5em'>",
" This will create a 3D model from a 2D PNG image. Photos must",
" 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>"
]};
UC.confirm(undefined, {convert:true, cancel:false}, undefined, opt).then((ok) => {
if (ok) {
loadImage(image, {blur: parseInt($('png-blur').value) || 0});
}
});
}
function loadImage(image, opt = {}) {
let info = Object.assign({settings, png:image}, opt);
KIRI.client.image2mesh(info, progress => {
API.show.progress(progress, "converting");
}, output => {
API.show.progress(0);
let {bigv, verts, index, vi, ii} = output;
let {bigv, verts, index} = output;
// let mat = new THREE.MeshPhongMaterial({
// shininess: 0x101010,
// specular: 0x101010,
@ -972,7 +993,6 @@
// mesh.receiveShadow = true;
//
// SPACE.platform.world.add(mesh);
platform.add(newWidget().loadVertices(bigv));
});
}
@ -1750,7 +1770,7 @@
if (isgcode) loadCode(e.target.result, 'gcode');
if (issvg) loadCode(e.target.result, 'svg');
if (isset) settingsImport(e.target.result, true);
if (ispng) loadImage(e.target.result);
if (ispng) loadImageDialog(e.target.result);
if (--loaded === 0) platform.group_done(isgcode);
};
if (isstl || ispng) {

View file

@ -89,9 +89,11 @@
let rnd = Date.now().toString(36);
let any = $('mod-any');
let html = [
`<div class="confirm f-col a-stretch">`,
`<label style="user-select:text">${message}</label>`,
`<div class="confirm f-col a-stretch">`
];
if (message) {
html.push(`<label style="user-select:text">${message}</label>`);
}
if (opt.pre) {
html = opt.pre.appendAll(html);
}

View file

@ -278,6 +278,30 @@ KIRI.worker = {
gray[gi++] = v;
}
}
let blur = parseInt(info.blur || 0);
while (blur-- > 0) {
let blur = new Uint8Array(width * height);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
let xl = Math.max(x-1,0);
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] = (
gray[xl + (width * yu)] +
gray[x + (width * yu)] +
gray[xr + (width * yu)] +
gray[xl + (width * y)] +
gray[x + (width * y)] + // self
gray[xr + (width * y)] +
gray[xl + (width * yd)] +
gray[x + (width * yd)] +
gray[xr + (width * yd)]
) / 9;
}
}
gray = blur;
}
// create indexed mesh output
let verts = new Float32Array(points * 3);
let faces = new Uint32Array(flats * 6);
@ -315,7 +339,7 @@ KIRI.worker = {
// create top vertices & faces
VB = VI;
let TL = VI;
if (true) for (let x = 0; x < width; x++) {
for (let x = 0; x < width; x++) {
let y = 0;
verts[vi++] = (-w2 + x) / div;
verts[vi++] = (h2 - y) / div;

View file

@ -3,7 +3,7 @@
let terms = {
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE: "See the license.md file included with the source distribution",
VERSION: "2.4.D5"
VERSION: "2.4.D6"
};
if (typeof(module) === 'object') {