convert bulk of root kiri packages to gapp.register() loading

This commit is contained in:
Stewart Allen 2022-02-20 22:47:04 -05:00
commit 57a2129dba
33 changed files with 3092 additions and 3030 deletions

2
app.js
View file

@ -365,7 +365,6 @@ const script = {
"kiri/stats",
"kiri/api",
"kiri/ui",
"kiri/do",
"kiri/pack",
"kiri/lang",
"kiri/lang-en",
@ -395,6 +394,7 @@ const script = {
"kiri/codec",
"kiri/main",
"kiri/init",
"kiri/do",
"kiri/export",
"kiri/tools",
"kiri/frame",

View file

@ -22,8 +22,10 @@
"geo/polygon",
"geo/gyroid",
"geo/slicer",
"data/local",
"load/obj",
"load/stl",
"kiri/consts",
"kiri/conf",
"kiri/pack",
"kiri/client",

View file

@ -8,6 +8,7 @@ const { base, kiri } = self;
const { util, config } = base;
const { FDM } = kiri.driver;
const { getRangeParameters } = FDM;
const debug = false;
FDM.export = function(print, online, ondone, ondebug) {
const { settings, belty, tools } = print;

View file

@ -5,7 +5,7 @@
// dep: kiri.api
gapp.register("kiri.alerts", [], (root, exports) => {
const { kiri } = self;
const { kiri } = root;
const { api } = kiri;
let alerts = [];

View file

@ -9,7 +9,7 @@
// use: kiri.settings
gapp.register("kiri.api", [], (root, exports) => {
const { data, kiri, noop } = self;
const { data, kiri, noop } = root;
const { consts, utils } = kiri;
const { areEqual, parseOpt, encodeOpt, ajax, o2js, js2o } = utils;
const { LISTS } = consts;

View file

@ -6,7 +6,8 @@
// dep: geo.base
gapp.register("kiri.codec", [], (root, exports) => {
const BASE = self.base, KIRI = self.kiri, handlers = {};
const { base, kiri } = root;
const handlers = {};
const freeMem = true;
const zeroOut = true;
@ -131,7 +132,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
* Object Class CODEC Functions
******************************************************************* */
KIRI.Widget.prototype.encode = function(state) {
kiri.Widget.prototype.encode = function(state) {
const json = state._json_;
const geo = this.getGeoVertices();
const coded = {
@ -150,7 +151,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
const id = v.id,
group = v.group || id,
track = v.track || undefined,
widget = KIRI.newWidget(id, KIRI.Widget.Groups.forid(group));
widget = kiri.newWidget(id, kiri.Widget.Groups.forid(group));
widget.loadVertices(v.json ? v.geo.toFloat32() : v.geo);
widget.saved = Date.now();
if (track && track.pos) {
@ -160,7 +161,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
return widget;
});
KIRI.Slice.prototype.encode = function(state) {
kiri.Slice.prototype.encode = function(state) {
const rv = {
type: 'slice',
z: this.z,
@ -173,7 +174,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
};
registerDecoder('slice', function(v, state) {
let slice = KIRI.newSlice(v.z, state.mesh ? state.mesh.newGroup() : null);
let slice = kiri.newSlice(v.z, state.mesh ? state.mesh.newGroup() : null);
slice.index = v.index;
slice.layers = decode(v.layers, state)
@ -181,7 +182,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
return slice;
});
KIRI.Layers.prototype.encode = function(state) {
kiri.Layers.prototype.encode = function(state) {
let enc = {
type: 'layers',
layers: Object.keys(this.layers),
@ -219,7 +220,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
};
registerDecoder('layers', function(v, state) {
let render = new KIRI.Layers();
let render = new kiri.Layers();
for (let i=0; i<v.layers.length; i++) {
const d = render.layers[v.layers[i]] = {
polys: decode(v.data[i].polys, state),
@ -265,7 +266,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
return render;
});
KIRI.Top.prototype.encode = function(state) {
kiri.Top.prototype.encode = function(state) {
let obj = {
type: 'top',
poly: encode(this.poly, state)
@ -280,7 +281,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
};
registerDecoder('top', function(v, state) {
let top = KIRI.newTop(decode(v.poly, state));
let top = kiri.newTop(decode(v.poly, state));
if (state.full) {
top.last = decode(v.last, state);
top.shells = decode(v.shells, state);
@ -331,13 +332,13 @@ gapp.register("kiri.codec", [], (root, exports) => {
points = new Array(array.length/3);
while (vid < array.length) {
points[pid++] = BASE.newPoint(array[vid++], array[vid++], array[vid++]);
points[pid++] = base.newPoint(array[vid++], array[vid++], array[vid++]);
}
return points;
}
BASE.Polygon.prototype.encode = function(state) {
base.Polygon.prototype.encode = function(state) {
if (!state.poly) state.poly = {};
let cached = state.poly[this.id];
@ -364,7 +365,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
if (v.ref) return state.poly[v.ref];
let poly = BASE.newPolygon(),
let poly = base.newPolygon(),
vid = 0;
// if passed a normal array, convert to float32
@ -373,7 +374,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
}
while (vid < v.array.length) {
poly.push(BASE.newPoint(v.array[vid++], v.array[vid++], v.array[vid++]));
poly.push(base.newPoint(v.array[vid++], v.array[vid++], v.array[vid++]));
}
poly.id = v.id;

View file

@ -2,11 +2,13 @@
"use strict";
// dep: data.local
gapp.register("kiri.conf", [], (root, exports) => {
const { kiri } = root;
const CVER = 185, clone = Object.clone;
const { data } = root;
const { local } = data;
const { clone } = Object;
const CVER = 185;
function genID() {
while (true) {
@ -96,8 +98,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
// presence of internal field indicates already converted
if (code.internal >= 0) return code;
// if (self.navigator) console.log({mode, convert: code});
let API = kiri.api,
cmd = code.cmd || {},
let cmd = code.cmd || {},
set = code.settings || {},
ext = code.extruders;
@ -145,7 +146,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
if (ext) {
// synthesize extruders from new style settings
ext.forEach(rec => {
let e = API.clone(conf.defaults.fdm.d.extruders[0]);
let e = clone(conf.defaults.fdm.d.extruders[0]);
if (rec.nozzle) e.extNozzle = rec.nozzle;
if (rec.filament) e.extFilament = rec.filament;
if (rec.offset_x) e.extOffsetX = rec.offset_x;
@ -156,7 +157,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
});
} else {
// synthesize extruders from old style settings
device.extruders = [API.clone(conf.defaults.fdm.d.extruders[0])];
device.extruders = [ clone(conf.defaults.fdm.d.extruders[0]) ];
device.extruders[0].extNozzle = valueOf(set.nozzle_size, 0.4);
device.extruders[0].extFilament = valueOf(set.filament_diameter, 1.75);
}
@ -166,8 +167,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
// ensure settings structure is up-to-date
function normalize(settings) {
let API = kiri.api,
defaults = conf.defaults,
let defaults = conf.defaults,
template = conf.template,
mode = settings.mode.toLowerCase(),
default_dev = defaults[mode].d,
@ -176,7 +176,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
// v1 to v2 changed FDM extruder / nozzle / filament structure
if (settings.ver != CVER) {
// backup settings before upgrade
API.sdb.setItem(`ws-settings-${Date.now()}`, JSON.stringify(settings));
local.setItem(`ws-settings-${Date.now()}`, JSON.stringify(settings));
device_v1_to_v2(settings.device);
device_v1_to_v2(settings.cdev.FDM);
objectMap(settings.devices, dev => {

View file

@ -2,9 +2,7 @@
"use strict";
(function () {
const { kiri } = self;
gapp.register("kiri.consts", [], (root, exports) => {
const COLOR = {
wireframe: 0x444444,
@ -124,7 +122,7 @@ const PMODES = {
const SEED = 'kiri-seed';
kiri.consts = {
exports({
PMODES,
COLOR,
LISTS,
@ -132,6 +130,6 @@ kiri.consts = {
VIEWS,
SEED,
beltfact: Math.cos(Math.PI / 4)
};
});
})();
});

View file

@ -1,10 +1,17 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
kiri.load(function(API) {
// dep: kiri.api
// use: kiri.selection
// use: moto.space
gapp.register("kiri.do", [], (root, events) => {
const { kiri, moto } = root;
const { api } = kiri;
const { space } = moto;
const { event } = api;
let stack = [];
let stpos = 0;
let event = API.event;
let moved = { x: 0, y: 0 };
let msgid;
@ -13,7 +20,7 @@ kiri.load(function(API) {
$('redo').onclick = redo;
});
let undo = API.doit.undo = function() {
let undo = api.doit.undo = function() {
if (stpos) {
action(stack[--stpos].undo);
} else {
@ -21,7 +28,7 @@ kiri.load(function(API) {
}
};
let redo = API.doit.redo = function() {
let redo = api.doit.redo = function() {
if (stpos < stack.length) {
action(stack[stpos++].redo);
} else {
@ -29,7 +36,7 @@ kiri.load(function(API) {
}
};
let clear = API.doit.clear = function() {
let clear = api.doit.clear = function() {
stack = [];
stpos = 0;
moved = {x:0, y:0};
@ -37,7 +44,7 @@ kiri.load(function(API) {
};
function updateButtons() {
let isArrange = API.view.get() === kiri.consts.VIEWS.ARRANGE;
let isArrange = api.view.get() === kiri.consts.VIEWS.ARRANGE;
$('doit').style.display = isArrange && stack.length ? 'flex' : 'none';
$('undo').disabled = stpos === 0;
$('redo').disabled = stpos == stack.length;
@ -45,9 +52,9 @@ kiri.load(function(API) {
function message(txt) {
if (msgid) {
API.hide.alert(msgid);
api.hide.alert(msgid);
}
msgid = API.show.alert(txt);
msgid = api.show.alert(txt);
}
function action(rec) {
@ -66,10 +73,10 @@ kiri.load(function(API) {
for (let w of rec.widgets) {
w._scale(rec.x, rec.y, rec.z);
}
API.selection.update_info();
api.selection.update_info();
break;
}
API.space.update();
space.update();
updateButtons();
}
@ -94,7 +101,7 @@ kiri.load(function(API) {
// selection event (store position)
event.on('selection.rotate', (rec) => {
let type = "rotate";
let widgets = API.selection.widgets(true);
let widgets = api.selection.widgets(true);
if (!widgets.length) {
return;
}
@ -122,7 +129,7 @@ kiri.load(function(API) {
if (Math.abs(1 - (x * y * z)) < 0.0001) {
return;
}
let widgets = API.selection.widgets(true);
let widgets = api.selection.widgets(true);
if (!widgets.length) {
return;
}
@ -149,7 +156,7 @@ kiri.load(function(API) {
// move complete (store updated position)
event.on('mouse.drag.done', () => {
let widgets = API.selection.widgets(true);
let widgets = api.selection.widgets(true);
if (!widgets.length) {
return;
}
@ -168,4 +175,5 @@ kiri.load(function(API) {
});
moved = {x:0, y:0};
});
});

View file

@ -1,32 +1,32 @@
console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
(function() {
// dep: geo.base
// dep: data.local
// dep: kiri.consts
// dep: kiri.api
gapp.register("kiri.export", [], (root, exports) => {
if (self.kiri.export) return;
const { base, data, kiri } = root;
const { api, consts } = kiri;
const { local } = data;
const { util } = base;
const { stats, ui } = api;
const { MODES } = consts;
const KIRI = self.kiri,
BASE = self.base,
UTIL = BASE.util,
API = KIRI.api,
SDB = API.sdb,
UI = API.ui,
STATS = API.stats,
MODES = KIRI.consts.MODES;
kiri.export = exportFile;
KIRI.export = exportFile;
let printSeq = parseInt(SDB['kiri-print-seq'] || SDB['print-seq'] || "0") + 1;
let printSeq = parseInt(local['kiri-print-seq'] || local['print-seq'] || "0") + 1;
function exportFile(options) {
let mode = API.mode.get();
let names = API.widgets.all().map(w => w.meta ? w.meta.file : undefined)
let mode = api.mode.get();
let names = api.widgets.all().map(w => w.meta ? w.meta.file : undefined)
.filter(v => v)
.map(v => v.replace(/ /g,'-'))
.map(v => v.substring(0,20))
.map(v => v.split('.')[0]);
API.event.emit('export', mode);
api.event.emit('export', mode);
switch (mode) {
case 'LASER': return callExportLaser(options, names);
case 'FDM': return callExport(options, mode, names);
@ -36,11 +36,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}
function callExport(callback, mode, names) {
let alert = API.feature.work_alerts ? API.show.alert("Exporting") : null;
let alert = api.feature.work_alerts ? api.show.alert("Exporting") : null;
let gcode = [];
let section = [];
let sections = { };
KIRI.client.export(API.conf.get(), (line) => {
kiri.client.export(api.conf.get(), (line) => {
if (typeof line !== 'string') {
if (line.section) {
sections[line.section] = section = [];
@ -50,9 +50,9 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
gcode.push(line);
section.push(line);
}, (output, error) => {
API.hide.alert(alert);
api.hide.alert(alert);
if (error) {
API.show.alert(error, 5);
api.show.alert(error, 5);
} else if (callback) {
callback(gcode.join('\r\n'), output);
} else {
@ -62,11 +62,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}
function callExportLaser(options, names) {
KIRI.client.export(API.conf.get(), (line) => {
kiri.client.export(api.conf.get(), (line) => {
console.log({unexpected_line: line});
}, (output, error) => {
if (error) {
API.show.alert(error, 5);
api.show.alert(error, 5);
} else {
exportLaserDialog(output, names);
}
@ -74,65 +74,65 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}
function callExportSLA(options, names) {
KIRI.client.export(API.conf.get(), (line) => {
API.show.progress(line.progress, "exporting");
kiri.client.export(api.conf.get(), (line) => {
api.show.progress(line.progress, "exporting");
}, (output, error) => {
API.show.progress(0);
api.show.progress(0);
if (error) {
API.show.alert(error, 5);
api.show.alert(error, 5);
} else {
KIRI.driver.SLA.printDownload(output, API, names);
kiri.driver.SLA.printDownload(output, api, names);
}
});
}
function exportLaserDialog(data, names) {
SDB['kiri-print-seq'] = printSeq++;
local['kiri-print-seq'] = printSeq++;
const fileroot = names[0] || "laser";
const filename = `${fileroot}-${(printSeq.toString().padStart(3,"0"))}`;
const settings = API.conf.get();
const driver = KIRI.driver.LASER;
const settings = api.conf.get();
const driver = kiri.driver.LASER;
function download_svg() {
API.util.download(
api.util.download(
driver.exportSVG(settings, data),
$('print-filename').value + ".svg"
);
}
function download_dxf() {
API.util.download(
api.util.download(
driver.exportDXF(settings, data),
$('print-filename').value + ".dxf"
);
}
function download_gcode() {
API.util.download(
api.util.download(
driver.exportGCode(settings, data),
$('print-filename').value + ".gcode"
);
}
API.ajax("/kiri/output-laser.html", function(html) {
api.ajax("/kiri/output-laser.html", function(html) {
let segments = 0;
data.forEach(layer => { segments += layer.length });
UI.print.innerHTML = html;
ui.print.innerHTML = html;
$('print-filename').value = filename;
$('print-lines').value = UTIL.comma(segments);
$('print-lines').value = util.comma(segments);
$('print-svg').onclick = download_svg;
$('print-dxf').onclick = download_dxf;
$('print-lg').onclick = download_gcode;
API.modal.show('print');
api.modal.show('print');
});
}
function exportGCodeDialog(gcode, sections, info, names) {
SDB['kiri-print-seq'] = printSeq++;
local['kiri-print-seq'] = printSeq++;
let settings = API.conf.get(),
MODE = API.mode.get_id(),
let settings = api.conf.get(),
MODE = api.mode.get_id(),
name = names[0] || (MODE === MODES.CAM ? "cnc" : "print"),
pre = `${name}-${(printSeq.toString().padStart(3,"0"))}`,
filename = pre,// + (new Date().getTime().toString(36)),
@ -170,34 +170,34 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
apik = octo_apik.value;
if (host.indexOf("http") !== 0) {
API.show.alert("host missing protocol (http:// or https://)");
api.show.alert("host missing protocol (http:// or https://)");
return;
}
if (API.const.SECURE && !API.util.isSecure(host)) {
API.show.alert("host must begin with 'https' on a secure site");
if (api.const.SECURE && !api.util.isSecure(host)) {
api.show.alert("host must begin with 'https' on a secure site");
return;
}
SDB['octo-host'] = host.trim();
SDB['octo-apik'] = apik.trim();
local['octo-host'] = host.trim();
local['octo-apik'] = apik.trim();
filename = $('print-filename').value;
form.append("file", getBlob(), filename+"."+fileext);
ajax.onreadystatechange = function() {
if (ajax.readyState === 4) {
let status = ajax.status;
STATS.add(`ua_${API.mode.get_lower()}_print_octo_${status}`);
stats.add(`ua_${api.mode.get_lower()}_print_octo_${status}`);
if (status >= 200 && status < 300) {
API.modal.hide();
api.modal.hide();
} else {
API.show.alert("octoprint error\nstatus: "+status+"\nmessage: "+ajax.responseText);
api.show.alert("octoprint error\nstatus: "+status+"\nmessage: "+ajax.responseText);
}
API.show.progress(0);
api.show.progress(0);
}
API.show.progress(0);
api.show.progress(0);
};
ajax.upload.addEventListener('progress', function(evt) {
API.show.progress(evt.loaded/evt.total, "sending");
api.show.progress(evt.loaded/evt.total, "sending");
});
ajax.open("POST", host+"/api/files/local");
if (apik) {
@ -219,11 +219,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
function gridlocal_probe(ev, devs) {
if (ev && ev.code !== 'Enter') return;
if (!devs && API.probe.local(gridlocal_probe)) return;
if (!devs && api.probe.local(gridlocal_probe)) return;
grid_local = devs;
let gdev = SDB['grid-local'];
let gdev = local['grid-local'];
let gloc = $('grid-local');
let html = [];
for (let uuid in devs) {
@ -236,7 +236,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
if (html.length) {
gloc.innerHTML = html.join('\n');
gloc.onchange = (ev) => {
SDB['grid-local'] = gloc.options[gloc.selectedIndex].value
local['grid-local'] = gloc.options[gloc.selectedIndex].value
};
$('send-to-gridhead').style.display = 'flex';
$('send-to-gridspool').style.display = 'flex';
@ -252,20 +252,20 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
if (dev) {
let file = $('print-filename').value;
fetch(
`${API.probe.live}/api/grid_send?uuid=${uuid}&file=${encodeURIComponent(file + "." + fileext)}`,
`${api.probe.live}/api/grid_send?uuid=${uuid}&file=${encodeURIComponent(file + "." + fileext)}`,
{method: "POST", body: gcode}
)
.then(t => t.text())
.then(t => {
STATS.add(`ua_${API.mode.get_lower()}_print_local_ok`);
stats.add(`ua_${api.mode.get_lower()}_print_local_ok`);
console.log({grid_spool_said: t});
})
.catch(e => {
STATS.add(`ua_${API.mode.get_lower()}_print_local_err`);
stats.add(`ua_${api.mode.get_lower()}_print_local_err`);
console.log({grid_local_spool_error: e});
})
.finally(() => {
API.modal.hide();
api.modal.hide();
});
}
}
@ -291,15 +291,15 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
if (!apik) $('gpapik').style.display = 'none';
if (!host && API.probe.grid(gridhost_probe)) return;
if (!host && api.probe.grid(gridhost_probe)) return;
if (!host) return;
xhtr.onreadystatechange = function() {
if (xhtr.readyState === 4) {
if (xhtr.status >= 200 && xhtr.status < 300) {
SDB['grid-host'] = host;
SDB['grid-apik'] = apik;
local['grid-host'] = host;
local['grid-apik'] = apik;
let res = JSON.parse(xhtr.responseText);
let sel = false;
let match = false;
@ -308,11 +308,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
grid_targets = {};
for (let key in res) {
first = first || key;
if (!SDB['grid-target']) {
SDB['grid-target'] = key;
if (!local['grid-target']) {
local['grid-target'] = key;
sel = true;
} else {
sel = SDB['grid-target'] === key;
sel = local['grid-target'] === key;
}
match = match || sel;
grid_targets[html.length] = key;
@ -325,14 +325,14 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
);
}
if (!match) {
SDB['grid-target'] = first;
local['grid-target'] = first;
}
grid_target.innerHTML = html.join('\n');
} else if (xhtr.status === 401) {
$('gpapik').style.display = '';
} else {
SDB.removeItem('grid-host');
SDB.removeItem('grid-apik');
local.removeItem('grid-host');
local.removeItem('grid-apik');
console.log("invalid grid:host url");
}
}
@ -348,48 +348,48 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
let xhtr = new XMLHttpRequest(),
host = grid_host.value,
apik = grid_apik.value,
target = SDB['grid-target'] || '';
target = local['grid-target'] || '';
if (target === '') {
API.show.alert('invalid or missing target');
api.show.alert('invalid or missing target');
return;
}
if (host.indexOf("http") !== 0) {
API.show.alert("host missing protocol (http:// or https://)");
api.show.alert("host missing protocol (http:// or https://)");
return;
}
if (host.indexOf("://") < 0) {
API.show.alert("host:port malformed");
api.show.alert("host:port malformed");
return;
}
if (API.const.SECURE && !API.util.isSecure(host)) {
API.show.alert("host must begin with 'https' on a secure site");
if (api.const.SECURE && !api.util.isSecure(host)) {
api.show.alert("host must begin with 'https' on a secure site");
return;
}
SDB['grid-host'] = host.trim();
SDB['grid-apik'] = apik.trim();
local['grid-host'] = host.trim();
local['grid-apik'] = apik.trim();
xhtr.onreadystatechange = function() {
if (xhtr.readyState === 4) {
let status = xhtr.status;
STATS.add(`ua_${API.mode.get_lower()}_print_grid_${status}`);
stats.add(`ua_${api.mode.get_lower()}_print_grid_${status}`);
if (status >= 200 && status < 300) {
let json = js2o(xhtr.responseText);
gridhost_tracker(host,json.key);
API.ajax(host+"/api/wait?key="+json.key, function(data) {
api.ajax(host+"/api/wait?key="+json.key, function(data) {
data = js2o(data);
console.log(data);
API.show.alert("print to "+target+": "+data.status, 600);
api.show.alert("print to "+target+": "+data.status, 600);
});
} else {
API.show.alert("grid:host error\nstatus: "+status+"\nmessage: "+xhtr.responseText, 10000);
api.show.alert("grid:host error\nstatus: "+status+"\nmessage: "+xhtr.responseText, 10000);
}
API.show.progress(0);
api.show.progress(0);
}
};
xhtr.upload.addEventListener('progress', function(evt) {
API.show.progress(evt.loaded/evt.total, "sending");
api.show.progress(evt.loaded/evt.total, "sending");
});
filename = $('print-filename').value;
xhtr.open("POST",
@ -402,14 +402,14 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"&image=" + filename
);
xhtr.setRequestHeader("Content-Type", "text/plain");
let snapshot = API.view.snapshot;
let snapshot = api.view.snapshot;
xhtr.send(snapshot ? [gcode,snapshot].join("\0") : gcode);
API.modal.hide();
api.modal.hide();
}
function download() {
filename = $('print-filename').value;
API.util.download(gcode, filename + "." + fileext);
api.util.download(gcode, filename + "." + fileext);
// saveAs(getBlob(), filename + "." + fileext);
}
@ -422,7 +422,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
try {
let density = $('print-density');
$('print-weight').value = (
(Math.PI * UTIL.sqr(
(Math.PI * util.sqr(
info.settings.device.extruders[0].extFilament / 2
)) *
info.distance *
@ -447,8 +447,8 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}
fetch("/kiri/output-gcode.html").then(r => r.text()).then(html => {
UI.print.innerHTML = html;
let set = API.conf.get();
ui.print.innerHTML = html;
let set = api.conf.get();
let fdm = MODE === MODES.FDM;
let octo = set.controller.exportOcto && MODE !== MODES.CAM;
let ghost = set.controller.exportGhost;
@ -460,7 +460,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
$('print-filament-head').style.display = fdm ? '' : 'none';
$('print-filament-info').style.display = fdm ? '' : 'none';
$('print-filename').value = filename;
$('print-filesize').value = UTIL.comma(info.bytes);
$('print-filesize').value = util.comma(info.bytes);
$('print-filament').value = Math.round(info.distance);
calcTime();
if (fdm) {
@ -482,11 +482,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
})
}
}
KIRI.client.zip(files, progress => {
API.show.progress(progress.percent/100, "generating zip files");
kiri.client.zip(files, progress => {
api.show.progress(progress.percent/100, "generating zip files");
}, output => {
API.show.progress(0);
API.util.download(output, `${$('print-filename').value}.zip`);
api.show.progress(0);
api.util.download(output, `${$('print-filename').value}.zip`);
})
};
@ -599,20 +599,20 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
algorithms
};
let png;
KIRI.work.png({}, data => {
kiri.client.png({}, data => {
png = data.png;
});
console.log({meta,palette});
downloadPalette.onclick = function() {
KIRI.client.zip([
kiri.client.zip([
{name:"meta.json", data:JSON.stringify(meta,undefined,4)},
{name:"palette.json", data:JSON.stringify(palette,undefined,4)},
{name:"thumbnail.png", data:png.buffer}
], progress => {
API.show.progress(progress.percent/100, "generating palette files");
api.show.progress(progress.percent/100, "generating palette files");
}, output => {
API.show.progress(0);
API.util.download(output, `${$('print-filename').value}.mafx`);
api.show.progress(0);
api.util.download(output, `${$('print-filename').value}.mafx`);
})
};
}
@ -632,14 +632,14 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
$('send-to-octoprint').style.display = '';
}
// hide octoprint when hard-coded in the url
if (API.const.OCTO) {
if (api.const.OCTO) {
$('ophost').style.display = 'none';
$('opapik').style.display = 'none';
$('oph1nt').style.display = 'none';
$('send-to-gridhost').style.display = 'none';
}
octo_host.value = SDB['octo-host'] || '';
octo_apik.value = SDB['octo-apik'] || '';
octo_host.value = local['octo-host'] || '';
octo_apik.value = local['octo-apik'] || '';
} catch (e) { console.log(e) }
// grid:host setup
@ -653,10 +653,10 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
grid_apik = $('grid-apik');
grid_target = $('grid-target');
grid_target.onchange = function(ev) {
SDB['grid-target'] = grid_targets[grid_target.selectedIndex];
local['grid-target'] = grid_targets[grid_target.selectedIndex];
};
grid_host.value = SDB['grid-host'] || '';
grid_apik.value = SDB['grid-apik'] || '';
grid_host.value = local['grid-host'] || '';
grid_apik.value = local['grid-apik'] || '';
gridhost_probe();
} catch (e) { console.log(e) }
@ -671,8 +671,8 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
if (preview && gcode) $('code-preview-textarea').value = gcode.substring(0,65535);
// show dialog
API.modal.show('print');
api.modal.show('print');
});
}
})();
});

View file

@ -2,7 +2,9 @@
"use strict";
(function() {
// dep: main.kiri
// use: data.index
gapp.register("kiri.files", [], (root, exports) => {
const { kiri } = self;
@ -219,4 +221,4 @@
return new Files(indexdb, options);
};
})();
});

View file

@ -2,7 +2,14 @@
"use strict";
(function () {
// use: load.stl
// use: load.svg
// use: kiri.api
// use: kiri.feature
// use: kiri.platform
// use: kiri.settings
// use: kiri.widget
gapp.register("kiri.frame", [], (root, exports) => {
// add frame message api listener
window.addEventListener('message', msg => {
@ -113,4 +120,4 @@ window.addEventListener('message', msg => {
}
});
})();
});

View file

@ -2,9 +2,11 @@
"use strict";
(function () {
// dep: kiri.api
// dep: moto.space
gapp.register("kiri.function", [], (root, exports) => {
const { data, kiri, noop } = self;
const { kiri, noop } = root;
const { api, client, consts, utils } = kiri;
const { space } = moto;
const { COLOR, PMODES } = consts;
@ -59,6 +61,11 @@ function prepareSlices(callback, scale = 1, offset = 0) {
const slicing = api.widgets.all()
.slice()
.filter(w => !w.track.ignore && !w.meta.disabled);
if (slicing.length === 0) {
return api.show.alert('nothing to slice');
}
const totalv = slicing.map(w => w.getVertices().count).reduce((a,v) => a + v);
const defvert = totalv / slicing.length;
const track = {};
@ -413,4 +420,4 @@ const functions = api.function = {
clear_progress() { complete = {} }
};
})();
});

View file

@ -2,11 +2,15 @@
"use strict";
(function() {
// dep: geo.base
// dep: kiri.api
// dep: kiri.stats
// dep: kiri.consts
// dep: kiri.platform
// dep: kiri.selection
gapp.register("kiri.init", [], (root, exports) => {
if (self.kiri.init) return;
const { base, kiri, moto } = self;
const { base, kiri } = root;
const { api, catalog, conf, consts, space } = kiri;
const { sdb, stats, js2o, o2js, platform, selection, ui, uc } = api;
const { VIEWS, MODES, SEED } = consts;
@ -2287,11 +2291,9 @@
uc.hoverPop(ui.ltact, { group: hpops, target: $('pop-slice') });
uc.hoverPop(ui.render, { group: hpops, target: $('pop-render'), sticky: false });
uc.hoverPop(ui.edit, { group: hpops, target: $('pop-tools'), sticky: false });
// uc.hoverPop(ui.rotate, { group: hpops, target: $('pop-rotate'), sticky: true });
// uc.hoverPop(ui.scale, { group: hpops, target: $('pop-scale'), sticky: true });
uc.hoverPop(ui.nozzle, { group: hpops, target: $('pop-nozzle'), sticky: true });
uc.hoverPop($('app-acct'), { group: hpops, target: $('acct-pop') } );
uc.hoverPop($('app-mode'), { group: hpops, target: $('mode-info') } );
// uc.hoverPop($('app-mode'), { group: hpops, target: $('mode-info') } );
uc.hoverPop($('app-name'), { group: hpops, target: $('app-info') } );
uc.onBlur([
@ -2925,4 +2927,4 @@
}
}
})();
});

View file

@ -2,11 +2,10 @@
"use strict";
(function() {
gapp.register("kiri.lang", [], (root, exports) => {
if (self.kiri.lang) return;
const KIRI = self.kiri, LANG = self.kiri.lang = { current: {} };
const { kiri } = root;
const LANG = kiri.lang = { current: {} };
const KDFL = 'en-us';
let lset = navigator.language.toLocaleLowerCase();
@ -79,4 +78,4 @@
return undefined;
}
})();
});

View file

@ -2,11 +2,15 @@
"use strict";
(function() {
let KIRI = self.kiri,
BASE = self.base,
POLY = BASE.polygons,
newPolygon = BASE.newPolygon;
// dep: geo.base
// dep: geo.polygon
// dep: geo.polygons
gapp.register("kiri.layers", [], (root, exports) => {
const { base, kiri } = root;
const { polygons, newPolygon } = base;
const POLY = base.polygons;
class Layers {
constructor() {
@ -66,7 +70,7 @@
options.open = true;
const polys = [];
for (let i=0; i<lines.length-1; i += 2) {
polys.push(new BASE.Polygon()
polys.push(new base.Polygon()
.append(lines[i])
.append(lines[i+1])
.setOpen());
@ -351,5 +355,6 @@
return {index, faces};
}
self.kiri.Layers = Layers;
})();
kiri.Layers = Layers;
});

View file

@ -2,9 +2,9 @@
"use strict";
(function () {
gapp.register("kiri.main", [], (root, exports) => {
const { base, data, load, kiri, moto, noop } = self;
const { base, data, load, kiri, moto, noop } = root;
const { api, consts, lang, Widget, newWidget, utils, stats } = kiri;
const { areEqual, parseOpt, encodeOpt, ajax, o2js, js2o, ls2o } = utils;
const { feature, platform, selection, settings } = api;
@ -943,4 +943,5 @@
// upon restore, seed presets
api.event.emit('preset', api.conf.dbo());
})();
});

View file

@ -7,24 +7,12 @@
* http://codeincomplete.com/posts/2011/5/7/bin_packing/
*/
(function () {
gapp.register("kiri.pack", [], (root, exports) => {
let kiri = self.kiri = self.kiri || {};
if (kiri.Pack) return;
const { kiri } = root;
kiri.Pack = Packer;
kiri.Sort = function (a, b) {
let aa = (a.w * a.h);
let ab = (b.w * b.h);
if (Math.abs(aa-ab) < 1) {
return (b.w / b.h) - (a.w / a.h);
} else {
return ab - aa;
}
};
function Packer(w, h, spacing) {
class Packer {
constructor(w, h, spacing) {
this.root = { x: 0, y: 0, w: w, h: h };
this.max = { w: 0, h: 0 };
this.packed = false;
@ -32,9 +20,7 @@
this.pad = this.spacing / 2;
}
Packer.prototype = {
simple: function (blocks) {
simple(blocks) {
let n = 0, block, x = 0, y = 0, mh = 0;
while (n < blocks.length) {
block = blocks[n++];
@ -54,9 +40,9 @@
}
this.packed = true;
return this;
},
}
fit: function (blocks, simple) {
fit(blocks, simple) {
if (simple) {
return this.simple(blocks);
}
@ -73,9 +59,9 @@
}
this.packed = true;
return this;
},
}
findNode: function (root, w, h) {
findNode(root, w, h) {
if (root.used) {
return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);
} else if (w <= root.w && h <= root.h) {
@ -83,9 +69,9 @@
} else {
return null;
}
},
}
splitNode: function (node, w, h) {
splitNode(node, w, h) {
node.used = true;
node.down = { x: node.x, y: node.y + h, w: node.w, h: node.h - h };
node.right = { x: node.x + w, y: node.y, w: node.w - w, h: h };
@ -93,7 +79,18 @@
this.max.h = Math.max(this.max.h, node.y + h);
return node;
}
}
};
// kiri.Sort = function (a, b) {
// let aa = (a.w * a.h);
// let ab = (b.w * b.h);
// if (Math.abs(aa - ab) < 1) {
// return (b.w / b.h) - (a.w / a.h);
// } else {
// return ab - aa;
// }
// };
})();
kiri.Pack = Packer;
});

View file

@ -2,9 +2,14 @@
"use strict";
(function () {
// dep: moto.space
// dep: kiri.api
// dep: kiri.consts
// dep: kiri.utils
// dep: kiri.widget
gapp.register("kiri.platform", [], (root, exports) => {
const { kiri, moto, load } = self;
const { kiri, moto, load } = root;
const { api, consts, driver, utils, newWidget, Widget } = kiri;
const { ajax, js2o } = utils;
const { space } = moto;
@ -796,4 +801,4 @@ const platform = api.platform = {
clear() { api.space.clear(); api.space.save(true) }
};
})();
});

View file

@ -2,7 +2,12 @@
"use strict";
(function() {
// dep: geo.base
// dep: geo.point
// dep: geo.polygon
// dep: geo.paths
// dep: kiri.consts
gapp.register("kiri.print", [], (root, evets) => {
const { base, kiri } = self;
const { paths, util, newPoint, Polygon } = base;
@ -10,10 +15,6 @@ const { tip2tipEmit } = paths;
const { numOrDefault } = util;
const { beltfact } = kiri.consts;
kiri.newPrint = function(settings, widgets, id) {
return new Print(settings, widgets, id);
};
class Print {
constructor(settings, widgets, id) {
this.id = id || new Date().getTime().toString(36);
@ -523,7 +524,6 @@ class Print {
done({ output: scope.output });
}
}
class Output {
@ -550,6 +550,13 @@ class Output {
}
}
kiri.Print = Print;
function newPrint(settings, widgets, id) {
return new Print(settings, widgets, id);
};
})();
gapp.overlay(kiri, {
Print,
newPrint
});
});

View file

@ -2,9 +2,13 @@
"use strict";
(function () {
// dep: moto.space
// dep: kiri.api
// dep: kiri.consts
// dep: kiri.utils
gapp.register("kiri.selection", [], (root, exports) => {
const { data, kiri, moto, noop } = self;
const { kiri, moto, noop } = self;
const { api, consts, utils } = kiri;
const { space } = moto;
@ -293,4 +297,4 @@ const selection = api.selection = {
meshes() { return selectedMeshes.slice() },
};
}());
});

View file

@ -2,7 +2,12 @@
"use strict";
(function () {
// dep: kiri.api
// dep: kiri.conf
// dep: kiri.utils
// dep: moto.space
// dep: data.local
gapp.register("kiri.settings", [], (root, exports) => {
const { data, kiri, moto, noop } = self;
const { api, conf, consts, utils } = kiri;
@ -147,6 +152,7 @@ function updateSettings(opt = {}) {
$('mode-device').innerText = device.deviceName;
$('mode-profile').innerText = `${cproc[mode]}${same ? '' : ' *'}`;
$('mode-info').style.display = 'flex';
}
function updateSettingsFromFields(setrec, uirec = api.ui, changes) {
@ -544,7 +550,7 @@ function settingsImport(data, ask) {
if (isWork) {
api.platform.clear();
kiri.codec.decode(data.work).forEach(widget => {
platform.add(widget, 0, true);
api.platform.add(widget, 0, true);
});
if (data.view) {
space.view.load(data.view);
@ -696,4 +702,4 @@ api.settings = {
mode() { return settings.mode },
};
})();
});

View file

@ -2,30 +2,25 @@
"use strict";
(function() {
// dep: geo.base
// dep: geo.polygons
gapp.register("kiri.slice", [], (root, exports) => {
const KIRI = self.kiri,
PRO = Slice.prototype,
BASE = self.base,
UTIL = BASE.util,
POLY = BASE.polygons,
NOKEY = BASE.key.NONE;
const { base, kiri } = root;
const { key, polygons } = base;
const { util } = base;
KIRI.Top = Top;
KIRI.Slice = Slice;
KIRI.newTop = newTop;
KIRI.newSlice = newSlice;
const POLY = base.polygons;
const NOKEY = key.NONE;
/**
* Object encapsulates a z-slice from an object. This code is shared by the
* client and the worker thread. As such, the view layers are ignored in the
* worker code paths.
*
* @param {number} z offset from ground
* @param {THREE.Group} [view] optional view parent object for layers
* @constructor
*/
function Slice(z, view) {
class Slice {
constructor (z, view) {
this.z = z; // z-index
this.index = 0; // slice index
this.lines = null; // slice raw
@ -38,63 +33,18 @@
this.layers = null; // will replace most of the layer output data
}
/**
* Represents a top-level (outer) polygon in a slice. Slices may contain
* multiple tops each with nested structures. Top objects contain cached
* and computed objects for quick access for rendering and dependent computations.
*
* @param {Polygon} polygon
* @constructor
*/
function Top(polygon) {
this.poly = polygon; // outline poly
}
Top.prototype.clone = function(deep) {
let top = new Top(this.poly.clone(deep));
return top;
};
/**
* return innermost traces under a given top. for FDM, this represents
* the outline shell that the fill touches. used by Print, Laser
*/
Top.prototype.innerShells = function() {
let shells = this.shells,
array = [];
if (shells) shells.forEach(function(p) {
if (p.inner) array.appendAll(p.inner);
});
return array;
};
/**
* Returns shell polygons of a given depth
* used by Print (FDM)
*
* @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons
*/
Top.prototype.shellsAtDepth = function(depth) {
return this.shells ? this.shells.filter(poly => poly.depth === depth) : [];
};
/** ******************************************************************
* Slice Prototype Functions
******************************************************************* */
/**
* return Layers object for this slice. creates it if necessary.
*/
PRO.output = function() {
output() {
if (this.layers) return this.layers;
return this.layers = new KIRI.Layers();
return this.layers = new kiri.Layers();
};
/**
* returns a cloned slice the option of a deep clone on the top polys
*/
PRO.clone = function(deep) {
clone(deep) {
const from = this, slice = newSlice(from.z, from.view);
from.tops.forEach(function(top) {
slice.addTop(top.poly.clone(deep));
@ -102,16 +52,16 @@
return slice;
};
PRO.topPolys = function() {
topPolys() {
return this.tops.map(top => top.poly);
};
PRO.topSimples = function() {
topSimples() {
return this.tops.map(top => top.simple);
};
// FDM top intersect optimization
PRO.topPolysFlat = function() {
topPolysFlat() {
if (this.topFlatPolys) {
return this.topFlatPolys;
}
@ -119,7 +69,7 @@
};
// FDM retract path routing using first shell
PRO.topRouteFlat = function() {
topRouteFlat() {
if (this.topFlatRoutes) {
return this.topFlatRoutes;
}
@ -128,27 +78,27 @@
}
// CAM only
PRO.topPolyInners = function() {
topPolyInners() {
return this.tops.map(top => top.poly.inner).flat().filter(poly => poly);
};
// FDM / SLA only
PRO.topInners = function() {
topInners() {
return this.tops.map(top => top.last).flat().filter(poly => poly);
};
// FDM / SLA only
PRO.topFillOff = function() {
topFillOff() {
return this.tops.map(top => top.fill_off).flat().filter(poly => poly);
};
// FDM only
PRO.topFill = function() {
topFill() {
return this.tops.map(top => top.fill_lines).flat().filter(poly => poly);
};
// FDM only
PRO.topShells = function() {
topShells() {
return this.tops.map(top => top.shells).flat().filter(poly => poly);
};
@ -158,7 +108,7 @@
* vertical wall regions. this allows us to eliminate expensive diffs
* and infill computation when we detect the layers are the same.
*/
PRO.fingerprint = function() {
fingerprint() {
if (this.finger) {
return this.finger;
}
@ -168,18 +118,18 @@
/**
* returns true if the layers' fingerprints are the same
*/
PRO.fingerprintSame = function(slice) {
fingerprintSame(slice) {
return slice ? POLY.fingerprintCompare(this.fingerprint(), slice.fingerprint()) : false;
};
PRO.addTops = function(polys) {
addTops(polys) {
polys.forEach(p => {
this.addTop(p);
});
return this;
}
PRO.addTop = function(poly) {
addTop(poly) {
if (poly.length) {
// standard legacy polygon
let top = new Top(poly);
@ -189,7 +139,7 @@
} else {
// frop top object passed back by slicePost()
let top = new Top(poly.poly);
top.thin_fill = poly.thin_fill ? poly.thin_fill.map(p => BASE.newPoint(p.x,p.y,p.z)) : undefined;
top.thin_fill = poly.thin_fill ? poly.thin_fill.map(p => base.newPoint(p.x,p.y,p.z)) : undefined;
top.fill_lines = poly.fill_lines;
top.fill_off = poly.fill_off;
top.last = poly.last;
@ -202,7 +152,7 @@
throw "invalid top";
};
PRO.findClosestPointTo = function(target) {
findClosestPointTo(target) {
let min, find;
if (this.tops.length) {
@ -224,7 +174,7 @@
return min;
};
PRO.xray = function(dash = 3) {
xray(dash = 3) {
// console.log('xray', this);
this.output().setLayer(`xp`, 0x888800).addPolys(this.topPolys());
this.lines.forEach((line, i) => {
@ -232,19 +182,65 @@
const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group];
this.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2);
});
};
}
}
/**
* Represents a top-level (outer) polygon in a slice. Slices may contain
* multiple tops each with nested structures. Top objects contain cached
* and computed objects for quick access for rendering and dependent computations.
*/
class Top {
constructor(polygon) {
this.poly = polygon; // outline poly
}
clone(deep) {
let top = new Top(this.poly.clone(deep));
return top;
}
/**
* return innermost traces under a given top. for FDM, this represents
* the outline shell that the fill touches. used by Print, Laser
*/
innerShells() {
let shells = this.shells,
array = [];
if (shells) shells.forEach(function(p) {
if (p.inner) array.appendAll(p.inner);
});
return array;
}
/**
* Returns shell polygons of a given depth
* used by Print (FDM)
*
* @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons
*/
shellsAtDepth(depth) {
return this.shells ? this.shells.filter(poly => poly.depth === depth) : [];
}
}
function newTop(poly) {
return new Top(poly);
}
/**
* @param {number} z
* @param {THREE.Group} view
* @returns {Slice}
*/
function newSlice(z, view) {
return new Slice(z, view);
}
})();
gapp.overlay(kiri, {
Top,
Slice,
newTop,
newSlice
});
});

View file

@ -2,7 +2,9 @@
"use strict";
(function() {
gapp.register("kiri.stack", [], (root, exports) => {
const { kiri } = root;
class Stack {
constructor(view, freeMem) {
@ -214,7 +216,7 @@
}
}
self.kiri.Stack = Stack;
kiri.Stack = Stack;
let shininess = 15,
specular = 0x444444,
@ -259,4 +261,4 @@
});
}
})();
});

View file

@ -2,10 +2,14 @@
"use strict";
(function() {
// dep: kiri.stack
// use: kiri.api
// use: kiri.ui
gapp.register("kiri.stacks", [], (root, exports) => {
let KIRI = self.kiri,
freeMem = true,
const { kiri } = root;
let freeMem = true,
stacks = {},
tallest = 0,
min = 0,
@ -14,7 +18,7 @@
function init() {
labels = $("layers");
API = KIRI.api,
API = kiri.api,
UC = API.uc,
UI = API.ui;
}
@ -76,7 +80,7 @@
}
const stack = stacks[name] = {
layers: [ ],
obj: new KIRI.Stack(view, freeMem),
obj: new kiri.Stack(view, freeMem),
add: function(layers) {
let lmap = layers.layers;
let map = stack.obj.addLayers(layers);
@ -89,9 +93,9 @@
mat.visible = ctrl.toggle.checked;
});
if (ctrl.toggle.checked) {
KIRI.api.event.emit("stack.show", label);
kiri.api.event.emit("stack.show", label);
} else {
KIRI.api.event.emit("stack.hide", label)
kiri.api.event.emit("stack.hide", label)
}
})
};
@ -151,7 +155,7 @@
});
}
KIRI.stacks = {
kiri.stacks = {
clear,
create,
rotate,
@ -166,4 +170,4 @@
setFreeMem
};
})();
});

View file

@ -2,9 +2,12 @@
"use strict";
(function () {
// dep: moto.broker
// dep: kiri.api
// dep: kiri.utils
gapp.register("kiri.stats", [], (root, exports) => {
const { data, kiri, gapp } = self;
const { data, kiri, gapp } = root;
const { broker } = gapp;
const { api, utils } = kiri;
const { js2o, o2js } = utils;
@ -55,4 +58,4 @@ class Stats {
kiri.stats = new Stats();
})();
});

View file

@ -1,6 +1,12 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
kiri.load(function(API) {
// dep: add.three
// dep: kiri.api
gapp.register("kiri.tools", [], (root, exports) => {
const { kiri } = root;
const { api } = kiri;
// circle
let pgeo = new THREE.CircleGeometry(8, 30);
let pmat = new THREE.MeshBasicMaterial({color: 0xff0000, opacity: 0.5, transparent: true});
@ -19,8 +25,10 @@ kiri.load(function(API) {
np.push(pp[pi[i+1]*3+2]);
}
}
let wgeo = new THREE.BufferGeometry();
wgeo.setAttribute('position', new THREE.BufferAttribute(np.toFloat32(), 3));
let wmat = new THREE.LineBasicMaterial({ color: 0x883333 });
let wmesh = new THREE.LineSegments(wgeo, wmat);
pmesh.add(wmesh);
@ -39,31 +47,33 @@ kiri.load(function(API) {
function endit() {
if (enabled) {
API.hide.alert(alert);
api.hide.alert(alert);
$('lay-flat').classList.remove('selected');
API.feature.hover = false;
api.feature.hover = false;
enabled = false;
alert = undefined;
cleanup();
}
}
API.event.on('key.esc', endit);
API.event.on('tool.mesh.lay-flat', () => {
api.event.on('key.esc', endit);
api.event.on('tool.mesh.lay-flat', () => {
if (enabled) {
endit();
return;
}
if (API.feature.hover) {
if (api.feature.hover) {
console.log('lay flat cannot pre-empt hover');
return;
}
$('lay-flat').classList.add('selected');
API.feature.hover = true;
api.feature.hover = true;
enabled = true;
alert = API.show.alert('[ESC] to end lay-flat operation', 600000);
alert = api.show.alert('[ESC] to end lay-flat operation', 600000);
});
API.event.on('mouse.hover', (ev) => {
api.event.on('mouse.hover', (ev) => {
if (!enabled) {
return;
}
@ -85,7 +95,8 @@ kiri.load(function(API) {
pmesh.setRotationFromQuaternion(q);
}
});
API.event.on('mouse.hover.up', (ev) => {
api.event.on('mouse.hover.up', (ev) => {
if (!enabled) {
return;
}
@ -94,7 +105,8 @@ kiri.load(function(API) {
return;
}
let q = new THREE.Quaternion().setFromUnitVectors(lastface.normal, new THREE.Vector3(0,0,-1));
API.selection.rotate(q);
api.selection.rotate(q);
endit();
});
});

View file

@ -2,7 +2,7 @@
"use strict";
(function() {
gapp.register("kiri.ui", [], (root, exports) => {
if (kiri.ui) return;
@ -939,4 +939,4 @@
});
}
})();
});

View file

@ -5,9 +5,9 @@
// dep: data.local
// dep: main.kiri
// use: moto.ajax
(function () {
gapp.register("kiri.utils", [], (root, exports) => {
const { kiri, moto, data } = self;
const { kiri, moto, data } = root;
function parseOpt(ov) {
let opt = {}, kv, kva;
@ -96,7 +96,7 @@ function areEqual(o1, o2) {
return false;
}
kiri.utils = {
exports({
areEqual,
parseOpt,
encodeOpt,
@ -107,6 +107,6 @@ kiri.utils = {
avgc,
rgb,
a2c
};
});
})();
});

View file

@ -1,12 +1,10 @@
console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
(function() {
gapp.register("kiri.widget", [], (root, exports) => {
if (self.kiri.Widget) return;
const { base, kiri } = self;
const { base, kiri } = root;
const { api, driver, utils } = kiri;
const { config, util, polygons } = base;
const { Mesh, newPoint, verticesToPoints } = base;
@ -963,4 +961,4 @@ Widget.deleteFromState = function(id,ondone) {
kiri.Widget = Widget;
kiri.newWidget = newWidget;
})();
});

View file

@ -2,9 +2,9 @@
"use strict";
(function () {
gapp.register("kiri.widgets", [], (root, exports) => {
const { data, kiri, moto, noop } = self;
const { data, kiri, moto, noop } = root;
const { api, consts, utils, newWidget, Widget } = kiri;
const { space } = moto;
@ -110,4 +110,4 @@ const widgets = api.widgets = {
for(fn) { widgets.each(fn) },
};
})();
});

View file

@ -34,12 +34,9 @@ a, a:hover, a:visited {
transform: translateX(-50%) translateY(-50%);
z-index: 50;
}
#app-name, #app-mode-name, #app-acct {
#app-name, #app-acct {
cursor: pointer;
}
#app-mode-name {
border-bottom: 2px dotted grey;
}
#app,div {
display: flex;
padding: 0;
@ -296,18 +293,16 @@ th, tr, td, label {
margin: 0 5px 0 5px;
}
#mode-info.hoverpop {
display: flex;
}
#mode-info {
display: none;
position: absolute;
xposition: absolute;
white-space: nowrap;
font-size: smaller;
font-family: sans-serif;
left: 100%;
top: 50%;
height: 100%;
padding: 1px 5px 1px 5px;
transform: translateY(-50%);
padding: 1px 0 1px 0;
align-items: center;
justify-content: center;
}

View file

@ -30,8 +30,8 @@
<div id="top-sep"></div>
<div id="top" class="f-row">
<div id="app-mode">
<div id="app-mode-name"></div>
<div id="mode-info" class="f-row">
<label>Mode</label><div id="app-mode-name"></div>
<label>Device</label><div id="mode-device"></div>
<label>Profile</label><div id="mode-profile"></div>
</div>