convert bulk of root kiri packages to gapp.register() loading
This commit is contained in:
parent
64d825b48c
commit
57a2129dba
33 changed files with 3092 additions and 3030 deletions
2
app.js
2
app.js
|
|
@ -365,7 +365,6 @@ const script = {
|
||||||
"kiri/stats",
|
"kiri/stats",
|
||||||
"kiri/api",
|
"kiri/api",
|
||||||
"kiri/ui",
|
"kiri/ui",
|
||||||
"kiri/do",
|
|
||||||
"kiri/pack",
|
"kiri/pack",
|
||||||
"kiri/lang",
|
"kiri/lang",
|
||||||
"kiri/lang-en",
|
"kiri/lang-en",
|
||||||
|
|
@ -395,6 +394,7 @@ const script = {
|
||||||
"kiri/codec",
|
"kiri/codec",
|
||||||
"kiri/main",
|
"kiri/main",
|
||||||
"kiri/init",
|
"kiri/init",
|
||||||
|
"kiri/do",
|
||||||
"kiri/export",
|
"kiri/export",
|
||||||
"kiri/tools",
|
"kiri/tools",
|
||||||
"kiri/frame",
|
"kiri/frame",
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,10 @@
|
||||||
"geo/polygon",
|
"geo/polygon",
|
||||||
"geo/gyroid",
|
"geo/gyroid",
|
||||||
"geo/slicer",
|
"geo/slicer",
|
||||||
|
"data/local",
|
||||||
"load/obj",
|
"load/obj",
|
||||||
"load/stl",
|
"load/stl",
|
||||||
|
"kiri/consts",
|
||||||
"kiri/conf",
|
"kiri/conf",
|
||||||
"kiri/pack",
|
"kiri/pack",
|
||||||
"kiri/client",
|
"kiri/client",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const { base, kiri } = self;
|
||||||
const { util, config } = base;
|
const { util, config } = base;
|
||||||
const { FDM } = kiri.driver;
|
const { FDM } = kiri.driver;
|
||||||
const { getRangeParameters } = FDM;
|
const { getRangeParameters } = FDM;
|
||||||
|
const debug = false;
|
||||||
|
|
||||||
FDM.export = function(print, online, ondone, ondebug) {
|
FDM.export = function(print, online, ondone, ondebug) {
|
||||||
const { settings, belty, tools } = print;
|
const { settings, belty, tools } = print;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// dep: kiri.api
|
// dep: kiri.api
|
||||||
gapp.register("kiri.alerts", [], (root, exports) => {
|
gapp.register("kiri.alerts", [], (root, exports) => {
|
||||||
|
|
||||||
const { kiri } = self;
|
const { kiri } = root;
|
||||||
const { api } = kiri;
|
const { api } = kiri;
|
||||||
|
|
||||||
let alerts = [];
|
let alerts = [];
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
// use: kiri.settings
|
// use: kiri.settings
|
||||||
gapp.register("kiri.api", [], (root, exports) => {
|
gapp.register("kiri.api", [], (root, exports) => {
|
||||||
|
|
||||||
const { data, kiri, noop } = self;
|
const { data, kiri, noop } = root;
|
||||||
const { consts, utils } = kiri;
|
const { consts, utils } = kiri;
|
||||||
const { areEqual, parseOpt, encodeOpt, ajax, o2js, js2o } = utils;
|
const { areEqual, parseOpt, encodeOpt, ajax, o2js, js2o } = utils;
|
||||||
const { LISTS } = consts;
|
const { LISTS } = consts;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@
|
||||||
// dep: geo.base
|
// dep: geo.base
|
||||||
gapp.register("kiri.codec", [], (root, exports) => {
|
gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
|
|
||||||
const BASE = self.base, KIRI = self.kiri, handlers = {};
|
const { base, kiri } = root;
|
||||||
const freeMem = true;
|
const handlers = {};
|
||||||
const zeroOut = true;
|
const freeMem = true;
|
||||||
|
const zeroOut = true;
|
||||||
|
|
||||||
const codec = exports({
|
const codec = exports({
|
||||||
undef: undefined,
|
undef: undefined,
|
||||||
encode: encode,
|
encode: encode,
|
||||||
decode: decode,
|
decode: decode,
|
||||||
|
|
@ -19,9 +20,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
encodePointArray,
|
encodePointArray,
|
||||||
decodePointArray,
|
decodePointArray,
|
||||||
toCodable
|
toCodable
|
||||||
});
|
});
|
||||||
|
|
||||||
function toCodable(object) {
|
function toCodable(object) {
|
||||||
switch (typeof object) {
|
switch (typeof object) {
|
||||||
case 'function':
|
case 'function':
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
@ -51,9 +52,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
function allocFloat32Array(arg) {
|
function allocFloat32Array(arg) {
|
||||||
if (arg.byteLength) {
|
if (arg.byteLength) {
|
||||||
// already a float array
|
// already a float array
|
||||||
return arg;
|
return arg;
|
||||||
|
|
@ -64,9 +65,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
}
|
}
|
||||||
// usually a number (size) for array
|
// usually a number (size) for array
|
||||||
return new Float32Array(arg);
|
return new Float32Array(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function encode(o, state) {
|
function encode(o, state) {
|
||||||
state = state || {};
|
state = state || {};
|
||||||
if (o === null) return null;
|
if (o === null) return null;
|
||||||
if (o === undefined) return undefined;
|
if (o === undefined) return undefined;
|
||||||
|
|
@ -84,9 +85,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
return genOEncode(o, state);
|
return genOEncode(o, state);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decode(o, state) {
|
function decode(o, state) {
|
||||||
state = state || {};
|
state = state || {};
|
||||||
if (o === null) return null;
|
if (o === null) return null;
|
||||||
if (o === undefined) return undefined;
|
if (o === undefined) return undefined;
|
||||||
|
|
@ -103,35 +104,35 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
return genODecode(o, state);
|
return genODecode(o, state);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerDecoder(type, handler) {
|
function registerDecoder(type, handler) {
|
||||||
handlers[type] = handler;
|
handlers[type] = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genOEncode(o, state) {
|
function genOEncode(o, state) {
|
||||||
if (o instanceof Float32Array) return o;
|
if (o instanceof Float32Array) return o;
|
||||||
let out = {};
|
let out = {};
|
||||||
for (let k in o) {
|
for (let k in o) {
|
||||||
if (o.hasOwnProperty(k)) out[k] = encode(o[k], state);
|
if (o.hasOwnProperty(k)) out[k] = encode(o[k], state);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genODecode(o, state) {
|
function genODecode(o, state) {
|
||||||
if (o instanceof Float32Array) return o;
|
if (o instanceof Float32Array) return o;
|
||||||
let out = {};
|
let out = {};
|
||||||
for (let k in o) {
|
for (let k in o) {
|
||||||
if (o.hasOwnProperty(k)) out[k] = decode(o[k], state);
|
if (o.hasOwnProperty(k)) out[k] = decode(o[k], state);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ******************************************************************
|
/** ******************************************************************
|
||||||
* Object Class CODEC Functions
|
* Object Class CODEC Functions
|
||||||
******************************************************************* */
|
******************************************************************* */
|
||||||
|
|
||||||
KIRI.Widget.prototype.encode = function(state) {
|
kiri.Widget.prototype.encode = function(state) {
|
||||||
const json = state._json_;
|
const json = state._json_;
|
||||||
const geo = this.getGeoVertices();
|
const geo = this.getGeoVertices();
|
||||||
const coded = {
|
const coded = {
|
||||||
|
|
@ -150,7 +151,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
const id = v.id,
|
const id = v.id,
|
||||||
group = v.group || id,
|
group = v.group || id,
|
||||||
track = v.track || undefined,
|
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.loadVertices(v.json ? v.geo.toFloat32() : v.geo);
|
||||||
widget.saved = Date.now();
|
widget.saved = Date.now();
|
||||||
if (track && track.pos) {
|
if (track && track.pos) {
|
||||||
|
|
@ -158,9 +159,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
widget.move(track.pos.x, track.pos.y, track.pos.z, true);
|
widget.move(track.pos.x, track.pos.y, track.pos.z, true);
|
||||||
}
|
}
|
||||||
return widget;
|
return widget;
|
||||||
});
|
});
|
||||||
|
|
||||||
KIRI.Slice.prototype.encode = function(state) {
|
kiri.Slice.prototype.encode = function(state) {
|
||||||
const rv = {
|
const rv = {
|
||||||
type: 'slice',
|
type: 'slice',
|
||||||
z: this.z,
|
z: this.z,
|
||||||
|
|
@ -170,18 +171,18 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
// aggressively free memory
|
// aggressively free memory
|
||||||
if (freeMem) this.layers = undefined;
|
if (freeMem) this.layers = undefined;
|
||||||
return rv;
|
return rv;
|
||||||
};
|
};
|
||||||
|
|
||||||
registerDecoder('slice', function(v, state) {
|
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.index = v.index;
|
||||||
slice.layers = decode(v.layers, state)
|
slice.layers = decode(v.layers, state)
|
||||||
|
|
||||||
return slice;
|
return slice;
|
||||||
});
|
});
|
||||||
|
|
||||||
KIRI.Layers.prototype.encode = function(state) {
|
kiri.Layers.prototype.encode = function(state) {
|
||||||
let enc = {
|
let enc = {
|
||||||
type: 'layers',
|
type: 'layers',
|
||||||
layers: Object.keys(this.layers),
|
layers: Object.keys(this.layers),
|
||||||
|
|
@ -216,10 +217,10 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
// aggressively free memory
|
// aggressively free memory
|
||||||
if (freeMem) this.init();
|
if (freeMem) this.init();
|
||||||
return enc;
|
return enc;
|
||||||
};
|
};
|
||||||
|
|
||||||
registerDecoder('layers', function(v, state) {
|
registerDecoder('layers', function(v, state) {
|
||||||
let render = new KIRI.Layers();
|
let render = new kiri.Layers();
|
||||||
for (let i=0; i<v.layers.length; i++) {
|
for (let i=0; i<v.layers.length; i++) {
|
||||||
const d = render.layers[v.layers[i]] = {
|
const d = render.layers[v.layers[i]] = {
|
||||||
polys: decode(v.data[i].polys, state),
|
polys: decode(v.data[i].polys, state),
|
||||||
|
|
@ -263,9 +264,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
// console.log('<--',d);
|
// console.log('<--',d);
|
||||||
}
|
}
|
||||||
return render;
|
return render;
|
||||||
});
|
});
|
||||||
|
|
||||||
KIRI.Top.prototype.encode = function(state) {
|
kiri.Top.prototype.encode = function(state) {
|
||||||
let obj = {
|
let obj = {
|
||||||
type: 'top',
|
type: 'top',
|
||||||
poly: encode(this.poly, state)
|
poly: encode(this.poly, state)
|
||||||
|
|
@ -277,10 +278,10 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
obj.fill_lines = encode(this.fill_lines, state);
|
obj.fill_lines = encode(this.fill_lines, state);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
registerDecoder('top', function(v, state) {
|
registerDecoder('top', function(v, state) {
|
||||||
let top = KIRI.newTop(decode(v.poly, state));
|
let top = kiri.newTop(decode(v.poly, state));
|
||||||
if (state.full) {
|
if (state.full) {
|
||||||
top.last = decode(v.last, state);
|
top.last = decode(v.last, state);
|
||||||
top.shells = decode(v.shells, state);
|
top.shells = decode(v.shells, state);
|
||||||
|
|
@ -288,9 +289,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
top.fill_lines = decode(v.fill_lines, state);
|
top.fill_lines = decode(v.fill_lines, state);
|
||||||
}
|
}
|
||||||
return top;
|
return top;
|
||||||
});
|
});
|
||||||
|
|
||||||
function encodePointArray(points, state, z) {
|
function encodePointArray(points, state, z) {
|
||||||
if (!points) return null;
|
if (!points) return null;
|
||||||
|
|
||||||
let array = codec.allocFloat32Array(points.length * 3),
|
let array = codec.allocFloat32Array(points.length * 3),
|
||||||
|
|
@ -321,9 +322,9 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodePointArray(array) {
|
function decodePointArray(array) {
|
||||||
if (!array) return null;
|
if (!array) return null;
|
||||||
|
|
||||||
let vid = 0,
|
let vid = 0,
|
||||||
|
|
@ -331,13 +332,13 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
points = new Array(array.length/3);
|
points = new Array(array.length/3);
|
||||||
|
|
||||||
while (vid < array.length) {
|
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;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
BASE.Polygon.prototype.encode = function(state) {
|
base.Polygon.prototype.encode = function(state) {
|
||||||
if (!state.poly) state.poly = {};
|
if (!state.poly) state.poly = {};
|
||||||
|
|
||||||
let cached = state.poly[this.id];
|
let cached = state.poly[this.id];
|
||||||
|
|
@ -357,14 +358,14 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
color: this.color,
|
color: this.color,
|
||||||
open: this.open
|
open: this.open
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
registerDecoder('poly', function(v, state) {
|
registerDecoder('poly', function(v, state) {
|
||||||
if (!state.poly) state.poly = {};
|
if (!state.poly) state.poly = {};
|
||||||
|
|
||||||
if (v.ref) return state.poly[v.ref];
|
if (v.ref) return state.poly[v.ref];
|
||||||
|
|
||||||
let poly = BASE.newPolygon(),
|
let poly = base.newPolygon(),
|
||||||
vid = 0;
|
vid = 0;
|
||||||
|
|
||||||
// if passed a normal array, convert to float32
|
// if passed a normal array, convert to float32
|
||||||
|
|
@ -373,7 +374,7 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (vid < v.array.length) {
|
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;
|
poly.id = v.id;
|
||||||
|
|
@ -387,6 +388,6 @@ gapp.register("kiri.codec", [], (root, exports) => {
|
||||||
poly.color = v.color;
|
poly.color = v.color;
|
||||||
|
|
||||||
return poly;
|
return poly;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,24 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// dep: data.local
|
||||||
gapp.register("kiri.conf", [], (root, exports) => {
|
gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
|
|
||||||
const { kiri } = root;
|
const { data } = root;
|
||||||
|
const { local } = data;
|
||||||
|
const { clone } = Object;
|
||||||
|
const CVER = 185;
|
||||||
|
|
||||||
const CVER = 185, clone = Object.clone;
|
function genID() {
|
||||||
|
|
||||||
function genID() {
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let k = Math.round(Math.random() * 9999999999).toString(36);
|
let k = Math.round(Math.random() * 9999999999).toString(36);
|
||||||
if (k.length >= 4 && k.length <= 8) return k;
|
if (k.length >= 4 && k.length <= 8) return k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add fields to o(bject) from d(efault) that are missing
|
// add fields to o(bject) from d(efault) that are missing
|
||||||
// remove fields from o(bject) that don't exist in d(efault)
|
// remove fields from o(bject) that don't exist in d(efault)
|
||||||
function fill_cull_once(obj, def, debug) {
|
function fill_cull_once(obj, def, debug) {
|
||||||
if (!obj) return;
|
if (!obj) return;
|
||||||
// handle renaming
|
// handle renaming
|
||||||
for (let k in obj) {
|
for (let k in obj) {
|
||||||
|
|
@ -53,30 +55,30 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
delete obj[k];
|
delete obj[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fill_cull_many(map, def) {
|
function fill_cull_many(map, def) {
|
||||||
forValues(map, (obj) => { fill_cull_once(obj, def) });
|
forValues(map, (obj) => { fill_cull_once(obj, def) });
|
||||||
}
|
}
|
||||||
|
|
||||||
function objectMap(o, fn) {
|
function objectMap(o, fn) {
|
||||||
for (let [key, val] of Object.entries(o)) {
|
for (let [key, val] of Object.entries(o)) {
|
||||||
o[key] = fn(val) || val;
|
o[key] = fn(val) || val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function valueOf(val, dv) {
|
function valueOf(val, dv) {
|
||||||
if (typeof(val) === 'string' && Array.isArray(dv)) {
|
if (typeof(val) === 'string' && Array.isArray(dv)) {
|
||||||
val = [val];
|
val = [val];
|
||||||
}
|
}
|
||||||
return typeof(val) !== 'undefined' ? val : dv;
|
return typeof(val) !== 'undefined' ? val : dv;
|
||||||
}
|
}
|
||||||
|
|
||||||
function forValues(o, fn) {
|
function forValues(o, fn) {
|
||||||
Object.values(o).forEach(v => fn(v));
|
Object.values(o).forEach(v => fn(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
function device_v1_to_v2(device) {
|
function device_v1_to_v2(device) {
|
||||||
if (device && device.filamentSize) {
|
if (device && device.filamentSize) {
|
||||||
device.extruders = [{
|
device.extruders = [{
|
||||||
extFilament: device.filamentSize,
|
extFilament: device.filamentSize,
|
||||||
|
|
@ -89,15 +91,14 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
delete device.filamentSize;
|
delete device.filamentSize;
|
||||||
delete device.nozzleSize;
|
delete device.nozzleSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert default filter (from server) into device structure
|
// convert default filter (from server) into device structure
|
||||||
function device_from_code(code,mode) {
|
function device_from_code(code,mode) {
|
||||||
// presence of internal field indicates already converted
|
// presence of internal field indicates already converted
|
||||||
if (code.internal >= 0) return code;
|
if (code.internal >= 0) return code;
|
||||||
// if (self.navigator) console.log({mode, convert: code});
|
// if (self.navigator) console.log({mode, convert: code});
|
||||||
let API = kiri.api,
|
let cmd = code.cmd || {},
|
||||||
cmd = code.cmd || {},
|
|
||||||
set = code.settings || {},
|
set = code.settings || {},
|
||||||
ext = code.extruders;
|
ext = code.extruders;
|
||||||
|
|
||||||
|
|
@ -145,7 +146,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
if (ext) {
|
if (ext) {
|
||||||
// synthesize extruders from new style settings
|
// synthesize extruders from new style settings
|
||||||
ext.forEach(rec => {
|
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.nozzle) e.extNozzle = rec.nozzle;
|
||||||
if (rec.filament) e.extFilament = rec.filament;
|
if (rec.filament) e.extFilament = rec.filament;
|
||||||
if (rec.offset_x) e.extOffsetX = rec.offset_x;
|
if (rec.offset_x) e.extOffsetX = rec.offset_x;
|
||||||
|
|
@ -156,18 +157,17 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// synthesize extruders from old style settings
|
// 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].extNozzle = valueOf(set.nozzle_size, 0.4);
|
||||||
device.extruders[0].extFilament = valueOf(set.filament_diameter, 1.75);
|
device.extruders[0].extFilament = valueOf(set.filament_diameter, 1.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure settings structure is up-to-date
|
// ensure settings structure is up-to-date
|
||||||
function normalize(settings) {
|
function normalize(settings) {
|
||||||
let API = kiri.api,
|
let defaults = conf.defaults,
|
||||||
defaults = conf.defaults,
|
|
||||||
template = conf.template,
|
template = conf.template,
|
||||||
mode = settings.mode.toLowerCase(),
|
mode = settings.mode.toLowerCase(),
|
||||||
default_dev = defaults[mode].d,
|
default_dev = defaults[mode].d,
|
||||||
|
|
@ -176,7 +176,7 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
// v1 to v2 changed FDM extruder / nozzle / filament structure
|
// v1 to v2 changed FDM extruder / nozzle / filament structure
|
||||||
if (settings.ver != CVER) {
|
if (settings.ver != CVER) {
|
||||||
// backup settings before upgrade
|
// 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.device);
|
||||||
device_v1_to_v2(settings.cdev.FDM);
|
device_v1_to_v2(settings.cdev.FDM);
|
||||||
objectMap(settings.devices, dev => {
|
objectMap(settings.devices, dev => {
|
||||||
|
|
@ -212,10 +212,10 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
fill_cull_once(settings.controller, template.controller);
|
fill_cull_once(settings.controller, template.controller);
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto field renaming on import
|
// auto field renaming on import
|
||||||
const renamed = {
|
const renamed = {
|
||||||
roughingTool: "camRoughTool",
|
roughingTool: "camRoughTool",
|
||||||
roughingSpindle: "camRoughSpindle",
|
roughingSpindle: "camRoughSpindle",
|
||||||
roughingDown: "camRoughDown",
|
roughingDown: "camRoughDown",
|
||||||
|
|
@ -244,9 +244,9 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
camPocketOnlyFinish: "camOutlinePocket",
|
camPocketOnlyFinish: "camOutlinePocket",
|
||||||
camWideCutout: "camOutlineWide",
|
camWideCutout: "camOutlineWide",
|
||||||
outputClockwise: "camConventional"
|
outputClockwise: "camConventional"
|
||||||
};
|
};
|
||||||
|
|
||||||
const conf = exports({
|
const conf = exports({
|
||||||
// --------------- helper functions
|
// --------------- helper functions
|
||||||
normalize,
|
normalize,
|
||||||
device_from_code,
|
device_from_code,
|
||||||
|
|
@ -707,18 +707,18 @@ gapp.register("kiri.conf", [], (root, exports) => {
|
||||||
id: genID(),
|
id: genID(),
|
||||||
ver: CVER
|
ver: CVER
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const settings = conf.template;
|
const settings = conf.template;
|
||||||
|
|
||||||
// seed defaults. will get culled on save
|
// seed defaults. will get culled on save
|
||||||
settings.sproc.FDM.default = clone(settings.process);
|
settings.sproc.FDM.default = clone(settings.process);
|
||||||
settings.sproc.SLA.default = clone(settings.process);
|
settings.sproc.SLA.default = clone(settings.process);
|
||||||
settings.sproc.CAM.default = clone(settings.process);
|
settings.sproc.CAM.default = clone(settings.process);
|
||||||
settings.sproc.LASER.default = clone(settings.process);
|
settings.sproc.LASER.default = clone(settings.process);
|
||||||
settings.cdev.FDM = clone(settings.device);
|
settings.cdev.FDM = clone(settings.device);
|
||||||
settings.cdev.SLA = clone(settings.device);
|
settings.cdev.SLA = clone(settings.device);
|
||||||
settings.cdev.CAM = clone(settings.device);
|
settings.cdev.CAM = clone(settings.device);
|
||||||
settings.cdev.LASER = clone(settings.device);
|
settings.cdev.LASER = clone(settings.device);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function () {
|
gapp.register("kiri.consts", [], (root, exports) => {
|
||||||
|
|
||||||
const { kiri } = self;
|
|
||||||
|
|
||||||
const COLOR = {
|
const COLOR = {
|
||||||
wireframe: 0x444444,
|
wireframe: 0x444444,
|
||||||
|
|
@ -124,7 +122,7 @@ const PMODES = {
|
||||||
|
|
||||||
const SEED = 'kiri-seed';
|
const SEED = 'kiri-seed';
|
||||||
|
|
||||||
kiri.consts = {
|
exports({
|
||||||
PMODES,
|
PMODES,
|
||||||
COLOR,
|
COLOR,
|
||||||
LISTS,
|
LISTS,
|
||||||
|
|
@ -132,6 +130,6 @@ kiri.consts = {
|
||||||
VIEWS,
|
VIEWS,
|
||||||
SEED,
|
SEED,
|
||||||
beltfact: Math.cos(Math.PI / 4)
|
beltfact: Math.cos(Math.PI / 4)
|
||||||
};
|
});
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
100
src/kiri/do.js
100
src/kiri/do.js
|
|
@ -1,56 +1,63 @@
|
||||||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
|
|
||||||
kiri.load(function(API) {
|
// dep: kiri.api
|
||||||
let stack = [];
|
// use: kiri.selection
|
||||||
let stpos = 0;
|
// use: moto.space
|
||||||
|
gapp.register("kiri.do", [], (root, events) => {
|
||||||
|
|
||||||
let event = API.event;
|
const { kiri, moto } = root;
|
||||||
let moved = {x:0, y:0};
|
const { api } = kiri;
|
||||||
let msgid;
|
const { space } = moto;
|
||||||
|
const { event } = api;
|
||||||
|
|
||||||
event.on("init-done", () => {
|
let stack = [];
|
||||||
|
let stpos = 0;
|
||||||
|
let moved = { x: 0, y: 0 };
|
||||||
|
let msgid;
|
||||||
|
|
||||||
|
event.on("init-done", () => {
|
||||||
$('undo').onclick = undo;
|
$('undo').onclick = undo;
|
||||||
$('redo').onclick = redo;
|
$('redo').onclick = redo;
|
||||||
});
|
});
|
||||||
|
|
||||||
let undo = API.doit.undo = function() {
|
let undo = api.doit.undo = function() {
|
||||||
if (stpos) {
|
if (stpos) {
|
||||||
action(stack[--stpos].undo);
|
action(stack[--stpos].undo);
|
||||||
} else {
|
} else {
|
||||||
message('nothing to undo');
|
message('nothing to undo');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let redo = API.doit.redo = function() {
|
let redo = api.doit.redo = function() {
|
||||||
if (stpos < stack.length) {
|
if (stpos < stack.length) {
|
||||||
action(stack[stpos++].redo);
|
action(stack[stpos++].redo);
|
||||||
} else {
|
} else {
|
||||||
message('nothing to redo');
|
message('nothing to redo');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let clear = API.doit.clear = function() {
|
let clear = api.doit.clear = function() {
|
||||||
stack = [];
|
stack = [];
|
||||||
stpos = 0;
|
stpos = 0;
|
||||||
moved = {x:0, y:0};
|
moved = {x:0, y:0};
|
||||||
updateButtons();
|
updateButtons();
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateButtons() {
|
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';
|
$('doit').style.display = isArrange && stack.length ? 'flex' : 'none';
|
||||||
$('undo').disabled = stpos === 0;
|
$('undo').disabled = stpos === 0;
|
||||||
$('redo').disabled = stpos == stack.length;
|
$('redo').disabled = stpos == stack.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function message(txt) {
|
function message(txt) {
|
||||||
if (msgid) {
|
if (msgid) {
|
||||||
API.hide.alert(msgid);
|
api.hide.alert(msgid);
|
||||||
}
|
|
||||||
msgid = API.show.alert(txt);
|
|
||||||
}
|
}
|
||||||
|
msgid = api.show.alert(txt);
|
||||||
|
}
|
||||||
|
|
||||||
function action(rec) {
|
function action(rec) {
|
||||||
switch (rec.type) {
|
switch (rec.type) {
|
||||||
case 'move':
|
case 'move':
|
||||||
for (let w of rec.widgets) {
|
for (let w of rec.widgets) {
|
||||||
|
|
@ -66,35 +73,35 @@ kiri.load(function(API) {
|
||||||
for (let w of rec.widgets) {
|
for (let w of rec.widgets) {
|
||||||
w._scale(rec.x, rec.y, rec.z);
|
w._scale(rec.x, rec.y, rec.z);
|
||||||
}
|
}
|
||||||
API.selection.update_info();
|
api.selection.update_info();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
API.space.update();
|
space.update();
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushActions(ur) {
|
function pushActions(ur) {
|
||||||
stack.length = stpos++;
|
stack.length = stpos++;
|
||||||
stack.push(ur);
|
stack.push(ur);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.on([
|
event.on([
|
||||||
'platform.layout',
|
'platform.layout',
|
||||||
'widget.add',
|
'widget.add',
|
||||||
'widget.delete'
|
'widget.delete'
|
||||||
], (widget) => {
|
], (widget) => {
|
||||||
clear();
|
clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
event.on('view.set', mode => {
|
event.on('view.set', mode => {
|
||||||
updateButtons();
|
updateButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
// selection event (store position)
|
// selection event (store position)
|
||||||
event.on('selection.rotate', (rec) => {
|
event.on('selection.rotate', (rec) => {
|
||||||
let type = "rotate";
|
let type = "rotate";
|
||||||
let widgets = API.selection.widgets(true);
|
let widgets = api.selection.widgets(true);
|
||||||
if (!widgets.length) {
|
if (!widgets.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -114,15 +121,15 @@ kiri.load(function(API) {
|
||||||
x: -x, y: -y, z: -z
|
x: -x, y: -y, z: -z
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
event.on('selection.scale', (rec) => {
|
event.on('selection.scale', (rec) => {
|
||||||
let [x, y, z] = rec;
|
let [x, y, z] = rec;
|
||||||
// ignore scale close to 1
|
// ignore scale close to 1
|
||||||
if (Math.abs(1 - (x * y * z)) < 0.0001) {
|
if (Math.abs(1 - (x * y * z)) < 0.0001) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let widgets = API.selection.widgets(true);
|
let widgets = api.selection.widgets(true);
|
||||||
if (!widgets.length) {
|
if (!widgets.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -139,17 +146,17 @@ kiri.load(function(API) {
|
||||||
x: 1/x, y: 1/y, z: 1/z
|
x: 1/x, y: 1/y, z: 1/z
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// selection moved (accumulator)
|
// selection moved (accumulator)
|
||||||
event.on('selection.drag', (delta) => {
|
event.on('selection.drag', (delta) => {
|
||||||
moved.x += delta.x;
|
moved.x += delta.x;
|
||||||
moved.y += delta.y;
|
moved.y += delta.y;
|
||||||
});
|
});
|
||||||
|
|
||||||
// move complete (store updated position)
|
// move complete (store updated position)
|
||||||
event.on('mouse.drag.done', () => {
|
event.on('mouse.drag.done', () => {
|
||||||
let widgets = API.selection.widgets(true);
|
let widgets = api.selection.widgets(true);
|
||||||
if (!widgets.length) {
|
if (!widgets.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -167,5 +174,6 @@ kiri.load(function(API) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
moved = {x:0, y:0};
|
moved = {x:0, y:0};
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,46 @@
|
||||||
console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
|
|
||||||
"use strict";
|
"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,
|
kiri.export = exportFile;
|
||||||
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;
|
let printSeq = parseInt(local['kiri-print-seq'] || local['print-seq'] || "0") + 1;
|
||||||
|
|
||||||
let printSeq = parseInt(SDB['kiri-print-seq'] || SDB['print-seq'] || "0") + 1;
|
function exportFile(options) {
|
||||||
|
let mode = api.mode.get();
|
||||||
function exportFile(options) {
|
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)
|
.filter(v => v)
|
||||||
.map(v => v.replace(/ /g,'-'))
|
.map(v => v.replace(/ /g,'-'))
|
||||||
.map(v => v.substring(0,20))
|
.map(v => v.substring(0,20))
|
||||||
.map(v => v.split('.')[0]);
|
.map(v => v.split('.')[0]);
|
||||||
API.event.emit('export', mode);
|
api.event.emit('export', mode);
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'LASER': return callExportLaser(options, names);
|
case 'LASER': return callExportLaser(options, names);
|
||||||
case 'FDM': return callExport(options, mode, names);
|
case 'FDM': return callExport(options, mode, names);
|
||||||
case 'CAM': return callExport(options, mode, names);
|
case 'CAM': return callExport(options, mode, names);
|
||||||
case 'SLA': return callExportSLA(options, names);
|
case 'SLA': return callExportSLA(options, names);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function callExport(callback, mode, names) {
|
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 gcode = [];
|
||||||
let section = [];
|
let section = [];
|
||||||
let sections = { };
|
let sections = { };
|
||||||
KIRI.client.export(API.conf.get(), (line) => {
|
kiri.client.export(api.conf.get(), (line) => {
|
||||||
if (typeof line !== 'string') {
|
if (typeof line !== 'string') {
|
||||||
if (line.section) {
|
if (line.section) {
|
||||||
sections[line.section] = section = [];
|
sections[line.section] = section = [];
|
||||||
|
|
@ -50,89 +50,89 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
gcode.push(line);
|
gcode.push(line);
|
||||||
section.push(line);
|
section.push(line);
|
||||||
}, (output, error) => {
|
}, (output, error) => {
|
||||||
API.hide.alert(alert);
|
api.hide.alert(alert);
|
||||||
if (error) {
|
if (error) {
|
||||||
API.show.alert(error, 5);
|
api.show.alert(error, 5);
|
||||||
} else if (callback) {
|
} else if (callback) {
|
||||||
callback(gcode.join('\r\n'), output);
|
callback(gcode.join('\r\n'), output);
|
||||||
} else {
|
} else {
|
||||||
exportGCodeDialog(gcode, mode === 'CAM' ? sections : undefined, output, names);
|
exportGCodeDialog(gcode, mode === 'CAM' ? sections : undefined, output, names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function callExportLaser(options, names) {
|
function callExportLaser(options, names) {
|
||||||
KIRI.client.export(API.conf.get(), (line) => {
|
kiri.client.export(api.conf.get(), (line) => {
|
||||||
console.log({unexpected_line: line});
|
console.log({unexpected_line: line});
|
||||||
}, (output, error) => {
|
}, (output, error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
API.show.alert(error, 5);
|
api.show.alert(error, 5);
|
||||||
} else {
|
} else {
|
||||||
exportLaserDialog(output, names);
|
exportLaserDialog(output, names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function callExportSLA(options, names) {
|
function callExportSLA(options, names) {
|
||||||
KIRI.client.export(API.conf.get(), (line) => {
|
kiri.client.export(api.conf.get(), (line) => {
|
||||||
API.show.progress(line.progress, "exporting");
|
api.show.progress(line.progress, "exporting");
|
||||||
}, (output, error) => {
|
}, (output, error) => {
|
||||||
API.show.progress(0);
|
api.show.progress(0);
|
||||||
if (error) {
|
if (error) {
|
||||||
API.show.alert(error, 5);
|
api.show.alert(error, 5);
|
||||||
} else {
|
} else {
|
||||||
KIRI.driver.SLA.printDownload(output, API, names);
|
kiri.driver.SLA.printDownload(output, api, names);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportLaserDialog(data, names) {
|
function exportLaserDialog(data, names) {
|
||||||
SDB['kiri-print-seq'] = printSeq++;
|
local['kiri-print-seq'] = printSeq++;
|
||||||
|
|
||||||
const fileroot = names[0] || "laser";
|
const fileroot = names[0] || "laser";
|
||||||
const filename = `${fileroot}-${(printSeq.toString().padStart(3,"0"))}`;
|
const filename = `${fileroot}-${(printSeq.toString().padStart(3,"0"))}`;
|
||||||
const settings = API.conf.get();
|
const settings = api.conf.get();
|
||||||
const driver = KIRI.driver.LASER;
|
const driver = kiri.driver.LASER;
|
||||||
|
|
||||||
function download_svg() {
|
function download_svg() {
|
||||||
API.util.download(
|
api.util.download(
|
||||||
driver.exportSVG(settings, data),
|
driver.exportSVG(settings, data),
|
||||||
$('print-filename').value + ".svg"
|
$('print-filename').value + ".svg"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_dxf() {
|
function download_dxf() {
|
||||||
API.util.download(
|
api.util.download(
|
||||||
driver.exportDXF(settings, data),
|
driver.exportDXF(settings, data),
|
||||||
$('print-filename').value + ".dxf"
|
$('print-filename').value + ".dxf"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_gcode() {
|
function download_gcode() {
|
||||||
API.util.download(
|
api.util.download(
|
||||||
driver.exportGCode(settings, data),
|
driver.exportGCode(settings, data),
|
||||||
$('print-filename').value + ".gcode"
|
$('print-filename').value + ".gcode"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
API.ajax("/kiri/output-laser.html", function(html) {
|
api.ajax("/kiri/output-laser.html", function(html) {
|
||||||
let segments = 0;
|
let segments = 0;
|
||||||
data.forEach(layer => { segments += layer.length });
|
data.forEach(layer => { segments += layer.length });
|
||||||
UI.print.innerHTML = html;
|
ui.print.innerHTML = html;
|
||||||
$('print-filename').value = filename;
|
$('print-filename').value = filename;
|
||||||
$('print-lines').value = UTIL.comma(segments);
|
$('print-lines').value = util.comma(segments);
|
||||||
$('print-svg').onclick = download_svg;
|
$('print-svg').onclick = download_svg;
|
||||||
$('print-dxf').onclick = download_dxf;
|
$('print-dxf').onclick = download_dxf;
|
||||||
$('print-lg').onclick = download_gcode;
|
$('print-lg').onclick = download_gcode;
|
||||||
API.modal.show('print');
|
api.modal.show('print');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportGCodeDialog(gcode, sections, info, names) {
|
function exportGCodeDialog(gcode, sections, info, names) {
|
||||||
SDB['kiri-print-seq'] = printSeq++;
|
local['kiri-print-seq'] = printSeq++;
|
||||||
|
|
||||||
let settings = API.conf.get(),
|
let settings = api.conf.get(),
|
||||||
MODE = API.mode.get_id(),
|
MODE = api.mode.get_id(),
|
||||||
name = names[0] || (MODE === MODES.CAM ? "cnc" : "print"),
|
name = names[0] || (MODE === MODES.CAM ? "cnc" : "print"),
|
||||||
pre = `${name}-${(printSeq.toString().padStart(3,"0"))}`,
|
pre = `${name}-${(printSeq.toString().padStart(3,"0"))}`,
|
||||||
filename = pre,// + (new Date().getTime().toString(36)),
|
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;
|
apik = octo_apik.value;
|
||||||
|
|
||||||
if (host.indexOf("http") !== 0) {
|
if (host.indexOf("http") !== 0) {
|
||||||
API.show.alert("host missing protocol (http:// or https://)");
|
api.show.alert("host missing protocol (http:// or https://)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (API.const.SECURE && !API.util.isSecure(host)) {
|
if (api.const.SECURE && !api.util.isSecure(host)) {
|
||||||
API.show.alert("host must begin with 'https' on a secure site");
|
api.show.alert("host must begin with 'https' on a secure site");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDB['octo-host'] = host.trim();
|
local['octo-host'] = host.trim();
|
||||||
SDB['octo-apik'] = apik.trim();
|
local['octo-apik'] = apik.trim();
|
||||||
|
|
||||||
filename = $('print-filename').value;
|
filename = $('print-filename').value;
|
||||||
form.append("file", getBlob(), filename+"."+fileext);
|
form.append("file", getBlob(), filename+"."+fileext);
|
||||||
ajax.onreadystatechange = function() {
|
ajax.onreadystatechange = function() {
|
||||||
if (ajax.readyState === 4) {
|
if (ajax.readyState === 4) {
|
||||||
let status = ajax.status;
|
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) {
|
if (status >= 200 && status < 300) {
|
||||||
API.modal.hide();
|
api.modal.hide();
|
||||||
} else {
|
} 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) {
|
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");
|
ajax.open("POST", host+"/api/files/local");
|
||||||
if (apik) {
|
if (apik) {
|
||||||
|
|
@ -219,11 +219,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
function gridlocal_probe(ev, devs) {
|
function gridlocal_probe(ev, devs) {
|
||||||
if (ev && ev.code !== 'Enter') return;
|
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;
|
grid_local = devs;
|
||||||
|
|
||||||
let gdev = SDB['grid-local'];
|
let gdev = local['grid-local'];
|
||||||
let gloc = $('grid-local');
|
let gloc = $('grid-local');
|
||||||
let html = [];
|
let html = [];
|
||||||
for (let uuid in devs) {
|
for (let uuid in devs) {
|
||||||
|
|
@ -236,7 +236,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
if (html.length) {
|
if (html.length) {
|
||||||
gloc.innerHTML = html.join('\n');
|
gloc.innerHTML = html.join('\n');
|
||||||
gloc.onchange = (ev) => {
|
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-gridhead').style.display = 'flex';
|
||||||
$('send-to-gridspool').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) {
|
if (dev) {
|
||||||
let file = $('print-filename').value;
|
let file = $('print-filename').value;
|
||||||
fetch(
|
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}
|
{method: "POST", body: gcode}
|
||||||
)
|
)
|
||||||
.then(t => t.text())
|
.then(t => t.text())
|
||||||
.then(t => {
|
.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});
|
console.log({grid_spool_said: t});
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.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});
|
console.log({grid_local_spool_error: e});
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.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 (!apik) $('gpapik').style.display = 'none';
|
||||||
|
|
||||||
if (!host && API.probe.grid(gridhost_probe)) return;
|
if (!host && api.probe.grid(gridhost_probe)) return;
|
||||||
|
|
||||||
if (!host) return;
|
if (!host) return;
|
||||||
|
|
||||||
xhtr.onreadystatechange = function() {
|
xhtr.onreadystatechange = function() {
|
||||||
if (xhtr.readyState === 4) {
|
if (xhtr.readyState === 4) {
|
||||||
if (xhtr.status >= 200 && xhtr.status < 300) {
|
if (xhtr.status >= 200 && xhtr.status < 300) {
|
||||||
SDB['grid-host'] = host;
|
local['grid-host'] = host;
|
||||||
SDB['grid-apik'] = apik;
|
local['grid-apik'] = apik;
|
||||||
let res = JSON.parse(xhtr.responseText);
|
let res = JSON.parse(xhtr.responseText);
|
||||||
let sel = false;
|
let sel = false;
|
||||||
let match = false;
|
let match = false;
|
||||||
|
|
@ -308,11 +308,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
grid_targets = {};
|
grid_targets = {};
|
||||||
for (let key in res) {
|
for (let key in res) {
|
||||||
first = first || key;
|
first = first || key;
|
||||||
if (!SDB['grid-target']) {
|
if (!local['grid-target']) {
|
||||||
SDB['grid-target'] = key;
|
local['grid-target'] = key;
|
||||||
sel = true;
|
sel = true;
|
||||||
} else {
|
} else {
|
||||||
sel = SDB['grid-target'] === key;
|
sel = local['grid-target'] === key;
|
||||||
}
|
}
|
||||||
match = match || sel;
|
match = match || sel;
|
||||||
grid_targets[html.length] = key;
|
grid_targets[html.length] = key;
|
||||||
|
|
@ -325,14 +325,14 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!match) {
|
if (!match) {
|
||||||
SDB['grid-target'] = first;
|
local['grid-target'] = first;
|
||||||
}
|
}
|
||||||
grid_target.innerHTML = html.join('\n');
|
grid_target.innerHTML = html.join('\n');
|
||||||
} else if (xhtr.status === 401) {
|
} else if (xhtr.status === 401) {
|
||||||
$('gpapik').style.display = '';
|
$('gpapik').style.display = '';
|
||||||
} else {
|
} else {
|
||||||
SDB.removeItem('grid-host');
|
local.removeItem('grid-host');
|
||||||
SDB.removeItem('grid-apik');
|
local.removeItem('grid-apik');
|
||||||
console.log("invalid grid:host url");
|
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(),
|
let xhtr = new XMLHttpRequest(),
|
||||||
host = grid_host.value,
|
host = grid_host.value,
|
||||||
apik = grid_apik.value,
|
apik = grid_apik.value,
|
||||||
target = SDB['grid-target'] || '';
|
target = local['grid-target'] || '';
|
||||||
|
|
||||||
if (target === '') {
|
if (target === '') {
|
||||||
API.show.alert('invalid or missing target');
|
api.show.alert('invalid or missing target');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (host.indexOf("http") !== 0) {
|
if (host.indexOf("http") !== 0) {
|
||||||
API.show.alert("host missing protocol (http:// or https://)");
|
api.show.alert("host missing protocol (http:// or https://)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (host.indexOf("://") < 0) {
|
if (host.indexOf("://") < 0) {
|
||||||
API.show.alert("host:port malformed");
|
api.show.alert("host:port malformed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (API.const.SECURE && !API.util.isSecure(host)) {
|
if (api.const.SECURE && !api.util.isSecure(host)) {
|
||||||
API.show.alert("host must begin with 'https' on a secure site");
|
api.show.alert("host must begin with 'https' on a secure site");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDB['grid-host'] = host.trim();
|
local['grid-host'] = host.trim();
|
||||||
SDB['grid-apik'] = apik.trim();
|
local['grid-apik'] = apik.trim();
|
||||||
|
|
||||||
xhtr.onreadystatechange = function() {
|
xhtr.onreadystatechange = function() {
|
||||||
if (xhtr.readyState === 4) {
|
if (xhtr.readyState === 4) {
|
||||||
let status = xhtr.status;
|
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) {
|
if (status >= 200 && status < 300) {
|
||||||
let json = js2o(xhtr.responseText);
|
let json = js2o(xhtr.responseText);
|
||||||
gridhost_tracker(host,json.key);
|
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);
|
data = js2o(data);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
API.show.alert("print to "+target+": "+data.status, 600);
|
api.show.alert("print to "+target+": "+data.status, 600);
|
||||||
});
|
});
|
||||||
} else {
|
} 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) {
|
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;
|
filename = $('print-filename').value;
|
||||||
xhtr.open("POST",
|
xhtr.open("POST",
|
||||||
|
|
@ -402,14 +402,14 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
"&image=" + filename
|
"&image=" + filename
|
||||||
);
|
);
|
||||||
xhtr.setRequestHeader("Content-Type", "text/plain");
|
xhtr.setRequestHeader("Content-Type", "text/plain");
|
||||||
let snapshot = API.view.snapshot;
|
let snapshot = api.view.snapshot;
|
||||||
xhtr.send(snapshot ? [gcode,snapshot].join("\0") : gcode);
|
xhtr.send(snapshot ? [gcode,snapshot].join("\0") : gcode);
|
||||||
API.modal.hide();
|
api.modal.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
function download() {
|
function download() {
|
||||||
filename = $('print-filename').value;
|
filename = $('print-filename').value;
|
||||||
API.util.download(gcode, filename + "." + fileext);
|
api.util.download(gcode, filename + "." + fileext);
|
||||||
// saveAs(getBlob(), filename + "." + fileext);
|
// saveAs(getBlob(), filename + "." + fileext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +422,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
try {
|
try {
|
||||||
let density = $('print-density');
|
let density = $('print-density');
|
||||||
$('print-weight').value = (
|
$('print-weight').value = (
|
||||||
(Math.PI * UTIL.sqr(
|
(Math.PI * util.sqr(
|
||||||
info.settings.device.extruders[0].extFilament / 2
|
info.settings.device.extruders[0].extFilament / 2
|
||||||
)) *
|
)) *
|
||||||
info.distance *
|
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 => {
|
fetch("/kiri/output-gcode.html").then(r => r.text()).then(html => {
|
||||||
UI.print.innerHTML = html;
|
ui.print.innerHTML = html;
|
||||||
let set = API.conf.get();
|
let set = api.conf.get();
|
||||||
let fdm = MODE === MODES.FDM;
|
let fdm = MODE === MODES.FDM;
|
||||||
let octo = set.controller.exportOcto && MODE !== MODES.CAM;
|
let octo = set.controller.exportOcto && MODE !== MODES.CAM;
|
||||||
let ghost = set.controller.exportGhost;
|
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-head').style.display = fdm ? '' : 'none';
|
||||||
$('print-filament-info').style.display = fdm ? '' : 'none';
|
$('print-filament-info').style.display = fdm ? '' : 'none';
|
||||||
$('print-filename').value = filename;
|
$('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);
|
$('print-filament').value = Math.round(info.distance);
|
||||||
calcTime();
|
calcTime();
|
||||||
if (fdm) {
|
if (fdm) {
|
||||||
|
|
@ -482,11 +482,11 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KIRI.client.zip(files, progress => {
|
kiri.client.zip(files, progress => {
|
||||||
API.show.progress(progress.percent/100, "generating zip files");
|
api.show.progress(progress.percent/100, "generating zip files");
|
||||||
}, output => {
|
}, output => {
|
||||||
API.show.progress(0);
|
api.show.progress(0);
|
||||||
API.util.download(output, `${$('print-filename').value}.zip`);
|
api.util.download(output, `${$('print-filename').value}.zip`);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -599,20 +599,20 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
algorithms
|
algorithms
|
||||||
};
|
};
|
||||||
let png;
|
let png;
|
||||||
KIRI.work.png({}, data => {
|
kiri.client.png({}, data => {
|
||||||
png = data.png;
|
png = data.png;
|
||||||
});
|
});
|
||||||
console.log({meta,palette});
|
console.log({meta,palette});
|
||||||
downloadPalette.onclick = function() {
|
downloadPalette.onclick = function() {
|
||||||
KIRI.client.zip([
|
kiri.client.zip([
|
||||||
{name:"meta.json", data:JSON.stringify(meta,undefined,4)},
|
{name:"meta.json", data:JSON.stringify(meta,undefined,4)},
|
||||||
{name:"palette.json", data:JSON.stringify(palette,undefined,4)},
|
{name:"palette.json", data:JSON.stringify(palette,undefined,4)},
|
||||||
{name:"thumbnail.png", data:png.buffer}
|
{name:"thumbnail.png", data:png.buffer}
|
||||||
], progress => {
|
], progress => {
|
||||||
API.show.progress(progress.percent/100, "generating palette files");
|
api.show.progress(progress.percent/100, "generating palette files");
|
||||||
}, output => {
|
}, output => {
|
||||||
API.show.progress(0);
|
api.show.progress(0);
|
||||||
API.util.download(output, `${$('print-filename').value}.mafx`);
|
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 = '';
|
$('send-to-octoprint').style.display = '';
|
||||||
}
|
}
|
||||||
// hide octoprint when hard-coded in the url
|
// hide octoprint when hard-coded in the url
|
||||||
if (API.const.OCTO) {
|
if (api.const.OCTO) {
|
||||||
$('ophost').style.display = 'none';
|
$('ophost').style.display = 'none';
|
||||||
$('opapik').style.display = 'none';
|
$('opapik').style.display = 'none';
|
||||||
$('oph1nt').style.display = 'none';
|
$('oph1nt').style.display = 'none';
|
||||||
$('send-to-gridhost').style.display = 'none';
|
$('send-to-gridhost').style.display = 'none';
|
||||||
}
|
}
|
||||||
octo_host.value = SDB['octo-host'] || '';
|
octo_host.value = local['octo-host'] || '';
|
||||||
octo_apik.value = SDB['octo-apik'] || '';
|
octo_apik.value = local['octo-apik'] || '';
|
||||||
} catch (e) { console.log(e) }
|
} catch (e) { console.log(e) }
|
||||||
|
|
||||||
// grid:host setup
|
// grid:host setup
|
||||||
|
|
@ -653,10 +653,10 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
grid_apik = $('grid-apik');
|
grid_apik = $('grid-apik');
|
||||||
grid_target = $('grid-target');
|
grid_target = $('grid-target');
|
||||||
grid_target.onchange = function(ev) {
|
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_host.value = local['grid-host'] || '';
|
||||||
grid_apik.value = SDB['grid-apik'] || '';
|
grid_apik.value = local['grid-apik'] || '';
|
||||||
gridhost_probe();
|
gridhost_probe();
|
||||||
} catch (e) { console.log(e) }
|
} 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);
|
if (preview && gcode) $('code-preview-textarea').value = gcode.substring(0,65535);
|
||||||
|
|
||||||
// show dialog
|
// show dialog
|
||||||
API.modal.show('print');
|
api.modal.show('print');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
// dep: main.kiri
|
||||||
|
// use: data.index
|
||||||
|
gapp.register("kiri.files", [], (root, exports) => {
|
||||||
|
|
||||||
const { kiri } = self;
|
const { kiri } = self;
|
||||||
|
|
||||||
class Files {
|
class Files {
|
||||||
constructor(indexdb, options) {
|
constructor(indexdb, options) {
|
||||||
let store = this;
|
let store = this;
|
||||||
this.db = indexdb;
|
this.db = indexdb;
|
||||||
|
|
@ -202,21 +204,21 @@
|
||||||
}
|
}
|
||||||
}, from, to);
|
}, from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFileList(store) {
|
function saveFileList(store) {
|
||||||
store.db.put('files', store.files);
|
store.db.put('files', store.files);
|
||||||
notifyFileListeners(store);
|
notifyFileListeners(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
function notifyFileListeners(store) {
|
function notifyFileListeners(store) {
|
||||||
for (let i=0; i<store.listeners.length; i++) {
|
for (let i=0; i<store.listeners.length; i++) {
|
||||||
store.listeners[i](store.files);
|
store.listeners[i](store.files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kiri.openFiles = function(indexdb, options) {
|
kiri.openFiles = function(indexdb, options) {
|
||||||
return new Files(indexdb, options);
|
return new Files(indexdb, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,14 @@
|
||||||
|
|
||||||
"use strict";
|
"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
|
// add frame message api listener
|
||||||
window.addEventListener('message', msg => {
|
window.addEventListener('message', msg => {
|
||||||
|
|
@ -113,4 +120,4 @@ window.addEventListener('message', msg => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { api, client, consts, utils } = kiri;
|
||||||
const { space } = moto;
|
const { space } = moto;
|
||||||
const { COLOR, PMODES } = consts;
|
const { COLOR, PMODES } = consts;
|
||||||
|
|
@ -59,6 +61,11 @@ function prepareSlices(callback, scale = 1, offset = 0) {
|
||||||
const slicing = api.widgets.all()
|
const slicing = api.widgets.all()
|
||||||
.slice()
|
.slice()
|
||||||
.filter(w => !w.track.ignore && !w.meta.disabled);
|
.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 totalv = slicing.map(w => w.getVertices().count).reduce((a,v) => a + v);
|
||||||
const defvert = totalv / slicing.length;
|
const defvert = totalv / slicing.length;
|
||||||
const track = {};
|
const track = {};
|
||||||
|
|
@ -413,4 +420,4 @@ const functions = api.function = {
|
||||||
clear_progress() { complete = {} }
|
clear_progress() { complete = {} }
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,15 @@
|
||||||
|
|
||||||
"use strict";
|
"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 } = root;
|
||||||
|
|
||||||
const { base, kiri, moto } = self;
|
|
||||||
const { api, catalog, conf, consts, space } = kiri;
|
const { api, catalog, conf, consts, space } = kiri;
|
||||||
const { sdb, stats, js2o, o2js, platform, selection, ui, uc } = api;
|
const { sdb, stats, js2o, o2js, platform, selection, ui, uc } = api;
|
||||||
const { VIEWS, MODES, SEED } = consts;
|
const { VIEWS, MODES, SEED } = consts;
|
||||||
|
|
@ -2287,11 +2291,9 @@
|
||||||
uc.hoverPop(ui.ltact, { group: hpops, target: $('pop-slice') });
|
uc.hoverPop(ui.ltact, { group: hpops, target: $('pop-slice') });
|
||||||
uc.hoverPop(ui.render, { group: hpops, target: $('pop-render'), sticky: false });
|
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.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(ui.nozzle, { group: hpops, target: $('pop-nozzle'), sticky: true });
|
||||||
uc.hoverPop($('app-acct'), { group: hpops, target: $('acct-pop') } );
|
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.hoverPop($('app-name'), { group: hpops, target: $('app-info') } );
|
||||||
|
|
||||||
uc.onBlur([
|
uc.onBlur([
|
||||||
|
|
@ -2925,4 +2927,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,15 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
gapp.register("kiri.lang", [], (root, exports) => {
|
||||||
|
|
||||||
if (self.kiri.lang) return;
|
const { kiri } = root;
|
||||||
|
const LANG = kiri.lang = { current: {} };
|
||||||
|
const KDFL = 'en-us';
|
||||||
|
|
||||||
const KIRI = self.kiri, LANG = self.kiri.lang = { current: {} };
|
let lset = navigator.language.toLocaleLowerCase();
|
||||||
const KDFL = 'en-us';
|
|
||||||
|
|
||||||
let lset = navigator.language.toLocaleLowerCase();
|
LANG.map = function(key) {
|
||||||
|
|
||||||
LANG.map = function(key) {
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return KDFL;
|
return KDFL;
|
||||||
}
|
}
|
||||||
|
|
@ -27,13 +26,13 @@
|
||||||
case 'zh': return 'zh';
|
case 'zh': return 'zh';
|
||||||
}
|
}
|
||||||
return KDFL;
|
return KDFL;
|
||||||
};
|
};
|
||||||
|
|
||||||
LANG.get = function() {
|
LANG.get = function() {
|
||||||
return lset;
|
return lset;
|
||||||
};
|
};
|
||||||
|
|
||||||
LANG.set = function() {
|
LANG.set = function() {
|
||||||
let map, key, keys = [...arguments];
|
let map, key, keys = [...arguments];
|
||||||
// provide default if none given
|
// provide default if none given
|
||||||
if (keys.length === 0) {
|
if (keys.length === 0) {
|
||||||
|
|
@ -77,6 +76,6 @@
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,17 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
// dep: geo.base
|
||||||
let KIRI = self.kiri,
|
// dep: geo.polygon
|
||||||
BASE = self.base,
|
// dep: geo.polygons
|
||||||
POLY = BASE.polygons,
|
gapp.register("kiri.layers", [], (root, exports) => {
|
||||||
newPolygon = BASE.newPolygon;
|
|
||||||
|
|
||||||
class Layers {
|
const { base, kiri } = root;
|
||||||
|
const { polygons, newPolygon } = base;
|
||||||
|
|
||||||
|
const POLY = base.polygons;
|
||||||
|
|
||||||
|
class Layers {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +70,7 @@
|
||||||
options.open = true;
|
options.open = true;
|
||||||
const polys = [];
|
const polys = [];
|
||||||
for (let i=0; i<lines.length-1; i += 2) {
|
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])
|
||||||
.append(lines[i+1])
|
.append(lines[i+1])
|
||||||
.setOpen());
|
.setOpen());
|
||||||
|
|
@ -247,17 +251,17 @@
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function flat(polys) {
|
function flat(polys) {
|
||||||
if (Array.isArray(polys)) {
|
if (Array.isArray(polys)) {
|
||||||
return POLY.flatten(polys.clone(true), [], true);
|
return POLY.flatten(polys.clone(true), [], true);
|
||||||
} else {
|
} else {
|
||||||
return POLY.flatten([polys.clone(true)], [], true);
|
return POLY.flatten([polys.clone(true)], [], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProfiledContourGeometry(profileShape, contour, contourClosed) {
|
function ProfiledContourGeometry(profileShape, contour, contourClosed) {
|
||||||
|
|
||||||
contourClosed = contourClosed !== undefined ? contourClosed : true;
|
contourClosed = contourClosed !== undefined ? contourClosed : true;
|
||||||
|
|
||||||
|
|
@ -349,7 +353,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return {index, faces};
|
return {index, faces};
|
||||||
}
|
}
|
||||||
|
|
||||||
self.kiri.Layers = Layers;
|
kiri.Layers = Layers;
|
||||||
})();
|
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { api, consts, lang, Widget, newWidget, utils, stats } = kiri;
|
||||||
const { areEqual, parseOpt, encodeOpt, ajax, o2js, js2o, ls2o } = utils;
|
const { areEqual, parseOpt, encodeOpt, ajax, o2js, js2o, ls2o } = utils;
|
||||||
const { feature, platform, selection, settings } = api;
|
const { feature, platform, selection, settings } = api;
|
||||||
|
|
@ -943,4 +943,5 @@
|
||||||
|
|
||||||
// upon restore, seed presets
|
// upon restore, seed presets
|
||||||
api.event.emit('preset', api.conf.dbo());
|
api.event.emit('preset', api.conf.dbo());
|
||||||
})();
|
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,24 +7,12 @@
|
||||||
* http://codeincomplete.com/posts/2011/5/7/bin_packing/
|
* http://codeincomplete.com/posts/2011/5/7/bin_packing/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
gapp.register("kiri.pack", [], (root, exports) => {
|
||||||
|
|
||||||
let kiri = self.kiri = self.kiri || {};
|
const { kiri } = root;
|
||||||
if (kiri.Pack) return;
|
|
||||||
|
|
||||||
kiri.Pack = Packer;
|
class Packer {
|
||||||
|
constructor(w, h, spacing) {
|
||||||
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) {
|
|
||||||
this.root = { x: 0, y: 0, w: w, h: h };
|
this.root = { x: 0, y: 0, w: w, h: h };
|
||||||
this.max = { w: 0, h: 0 };
|
this.max = { w: 0, h: 0 };
|
||||||
this.packed = false;
|
this.packed = false;
|
||||||
|
|
@ -32,9 +20,7 @@
|
||||||
this.pad = this.spacing / 2;
|
this.pad = this.spacing / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Packer.prototype = {
|
simple(blocks) {
|
||||||
|
|
||||||
simple: function (blocks) {
|
|
||||||
let n = 0, block, x = 0, y = 0, mh = 0;
|
let n = 0, block, x = 0, y = 0, mh = 0;
|
||||||
while (n < blocks.length) {
|
while (n < blocks.length) {
|
||||||
block = blocks[n++];
|
block = blocks[n++];
|
||||||
|
|
@ -54,9 +40,9 @@
|
||||||
}
|
}
|
||||||
this.packed = true;
|
this.packed = true;
|
||||||
return this;
|
return this;
|
||||||
},
|
}
|
||||||
|
|
||||||
fit: function (blocks, simple) {
|
fit(blocks, simple) {
|
||||||
if (simple) {
|
if (simple) {
|
||||||
return this.simple(blocks);
|
return this.simple(blocks);
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +59,9 @@
|
||||||
}
|
}
|
||||||
this.packed = true;
|
this.packed = true;
|
||||||
return this;
|
return this;
|
||||||
},
|
}
|
||||||
|
|
||||||
findNode: function (root, w, h) {
|
findNode(root, w, h) {
|
||||||
if (root.used) {
|
if (root.used) {
|
||||||
return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);
|
return this.findNode(root.right, w, h) || this.findNode(root.down, w, h);
|
||||||
} else if (w <= root.w && h <= root.h) {
|
} else if (w <= root.w && h <= root.h) {
|
||||||
|
|
@ -83,9 +69,9 @@
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
splitNode: function (node, w, h) {
|
splitNode(node, w, h) {
|
||||||
node.used = true;
|
node.used = true;
|
||||||
node.down = { x: node.x, y: node.y + h, w: node.w, h: node.h - h };
|
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 };
|
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);
|
this.max.h = Math.max(this.max.h, node.y + h);
|
||||||
return node;
|
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;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { api, consts, driver, utils, newWidget, Widget } = kiri;
|
||||||
const { ajax, js2o } = utils;
|
const { ajax, js2o } = utils;
|
||||||
const { space } = moto;
|
const { space } = moto;
|
||||||
|
|
@ -796,4 +801,4 @@ const platform = api.platform = {
|
||||||
clear() { api.space.clear(); api.space.save(true) }
|
clear() { api.space.clear(); api.space.save(true) }
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { base, kiri } = self;
|
||||||
const { paths, util, newPoint, Polygon } = base;
|
const { paths, util, newPoint, Polygon } = base;
|
||||||
|
|
@ -10,10 +15,6 @@ const { tip2tipEmit } = paths;
|
||||||
const { numOrDefault } = util;
|
const { numOrDefault } = util;
|
||||||
const { beltfact } = kiri.consts;
|
const { beltfact } = kiri.consts;
|
||||||
|
|
||||||
kiri.newPrint = function(settings, widgets, id) {
|
|
||||||
return new Print(settings, widgets, id);
|
|
||||||
};
|
|
||||||
|
|
||||||
class Print {
|
class Print {
|
||||||
constructor(settings, widgets, id) {
|
constructor(settings, widgets, id) {
|
||||||
this.id = id || new Date().getTime().toString(36);
|
this.id = id || new Date().getTime().toString(36);
|
||||||
|
|
@ -523,7 +524,6 @@ class Print {
|
||||||
|
|
||||||
done({ output: scope.output });
|
done({ output: scope.output });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class 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
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { api, consts, utils } = kiri;
|
||||||
const { space } = moto;
|
const { space } = moto;
|
||||||
|
|
||||||
|
|
@ -293,4 +297,4 @@ const selection = api.selection = {
|
||||||
meshes() { return selectedMeshes.slice() },
|
meshes() { return selectedMeshes.slice() },
|
||||||
};
|
};
|
||||||
|
|
||||||
}());
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { data, kiri, moto, noop } = self;
|
||||||
const { api, conf, consts, utils } = kiri;
|
const { api, conf, consts, utils } = kiri;
|
||||||
|
|
@ -147,6 +152,7 @@ function updateSettings(opt = {}) {
|
||||||
|
|
||||||
$('mode-device').innerText = device.deviceName;
|
$('mode-device').innerText = device.deviceName;
|
||||||
$('mode-profile').innerText = `${cproc[mode]}${same ? '' : ' *'}`;
|
$('mode-profile').innerText = `${cproc[mode]}${same ? '' : ' *'}`;
|
||||||
|
$('mode-info').style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSettingsFromFields(setrec, uirec = api.ui, changes) {
|
function updateSettingsFromFields(setrec, uirec = api.ui, changes) {
|
||||||
|
|
@ -544,7 +550,7 @@ function settingsImport(data, ask) {
|
||||||
if (isWork) {
|
if (isWork) {
|
||||||
api.platform.clear();
|
api.platform.clear();
|
||||||
kiri.codec.decode(data.work).forEach(widget => {
|
kiri.codec.decode(data.work).forEach(widget => {
|
||||||
platform.add(widget, 0, true);
|
api.platform.add(widget, 0, true);
|
||||||
});
|
});
|
||||||
if (data.view) {
|
if (data.view) {
|
||||||
space.view.load(data.view);
|
space.view.load(data.view);
|
||||||
|
|
@ -696,4 +702,4 @@ api.settings = {
|
||||||
mode() { return settings.mode },
|
mode() { return settings.mode },
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,25 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
// dep: geo.base
|
||||||
|
// dep: geo.polygons
|
||||||
|
gapp.register("kiri.slice", [], (root, exports) => {
|
||||||
|
|
||||||
const KIRI = self.kiri,
|
const { base, kiri } = root;
|
||||||
PRO = Slice.prototype,
|
const { key, polygons } = base;
|
||||||
BASE = self.base,
|
const { util } = base;
|
||||||
UTIL = BASE.util,
|
|
||||||
POLY = BASE.polygons,
|
|
||||||
NOKEY = BASE.key.NONE;
|
|
||||||
|
|
||||||
KIRI.Top = Top;
|
const POLY = base.polygons;
|
||||||
KIRI.Slice = Slice;
|
const NOKEY = key.NONE;
|
||||||
KIRI.newTop = newTop;
|
|
||||||
KIRI.newSlice = newSlice;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object encapsulates a z-slice from an object. This code is shared by the
|
* 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
|
* client and the worker thread. As such, the view layers are ignored in the
|
||||||
* worker code paths.
|
* 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.z = z; // z-index
|
||||||
this.index = 0; // slice index
|
this.index = 0; // slice index
|
||||||
this.lines = null; // slice raw
|
this.lines = null; // slice raw
|
||||||
|
|
@ -38,63 +33,18 @@
|
||||||
this.layers = null; // will replace most of the layer output data
|
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.
|
* return Layers object for this slice. creates it if necessary.
|
||||||
*/
|
*/
|
||||||
PRO.output = function() {
|
output() {
|
||||||
if (this.layers) return this.layers;
|
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
|
* 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);
|
const from = this, slice = newSlice(from.z, from.view);
|
||||||
from.tops.forEach(function(top) {
|
from.tops.forEach(function(top) {
|
||||||
slice.addTop(top.poly.clone(deep));
|
slice.addTop(top.poly.clone(deep));
|
||||||
|
|
@ -102,16 +52,16 @@
|
||||||
return slice;
|
return slice;
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.topPolys = function() {
|
topPolys() {
|
||||||
return this.tops.map(top => top.poly);
|
return this.tops.map(top => top.poly);
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.topSimples = function() {
|
topSimples() {
|
||||||
return this.tops.map(top => top.simple);
|
return this.tops.map(top => top.simple);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FDM top intersect optimization
|
// FDM top intersect optimization
|
||||||
PRO.topPolysFlat = function() {
|
topPolysFlat() {
|
||||||
if (this.topFlatPolys) {
|
if (this.topFlatPolys) {
|
||||||
return this.topFlatPolys;
|
return this.topFlatPolys;
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +69,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// FDM retract path routing using first shell
|
// FDM retract path routing using first shell
|
||||||
PRO.topRouteFlat = function() {
|
topRouteFlat() {
|
||||||
if (this.topFlatRoutes) {
|
if (this.topFlatRoutes) {
|
||||||
return this.topFlatRoutes;
|
return this.topFlatRoutes;
|
||||||
}
|
}
|
||||||
|
|
@ -128,27 +78,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// CAM only
|
// CAM only
|
||||||
PRO.topPolyInners = function() {
|
topPolyInners() {
|
||||||
return this.tops.map(top => top.poly.inner).flat().filter(poly => poly);
|
return this.tops.map(top => top.poly.inner).flat().filter(poly => poly);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FDM / SLA only
|
// FDM / SLA only
|
||||||
PRO.topInners = function() {
|
topInners() {
|
||||||
return this.tops.map(top => top.last).flat().filter(poly => poly);
|
return this.tops.map(top => top.last).flat().filter(poly => poly);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FDM / SLA only
|
// FDM / SLA only
|
||||||
PRO.topFillOff = function() {
|
topFillOff() {
|
||||||
return this.tops.map(top => top.fill_off).flat().filter(poly => poly);
|
return this.tops.map(top => top.fill_off).flat().filter(poly => poly);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FDM only
|
// FDM only
|
||||||
PRO.topFill = function() {
|
topFill() {
|
||||||
return this.tops.map(top => top.fill_lines).flat().filter(poly => poly);
|
return this.tops.map(top => top.fill_lines).flat().filter(poly => poly);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FDM only
|
// FDM only
|
||||||
PRO.topShells = function() {
|
topShells() {
|
||||||
return this.tops.map(top => top.shells).flat().filter(poly => poly);
|
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
|
* vertical wall regions. this allows us to eliminate expensive diffs
|
||||||
* and infill computation when we detect the layers are the same.
|
* and infill computation when we detect the layers are the same.
|
||||||
*/
|
*/
|
||||||
PRO.fingerprint = function() {
|
fingerprint() {
|
||||||
if (this.finger) {
|
if (this.finger) {
|
||||||
return this.finger;
|
return this.finger;
|
||||||
}
|
}
|
||||||
|
|
@ -168,18 +118,18 @@
|
||||||
/**
|
/**
|
||||||
* returns true if the layers' fingerprints are the same
|
* returns true if the layers' fingerprints are the same
|
||||||
*/
|
*/
|
||||||
PRO.fingerprintSame = function(slice) {
|
fingerprintSame(slice) {
|
||||||
return slice ? POLY.fingerprintCompare(this.fingerprint(), slice.fingerprint()) : false;
|
return slice ? POLY.fingerprintCompare(this.fingerprint(), slice.fingerprint()) : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.addTops = function(polys) {
|
addTops(polys) {
|
||||||
polys.forEach(p => {
|
polys.forEach(p => {
|
||||||
this.addTop(p);
|
this.addTop(p);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRO.addTop = function(poly) {
|
addTop(poly) {
|
||||||
if (poly.length) {
|
if (poly.length) {
|
||||||
// standard legacy polygon
|
// standard legacy polygon
|
||||||
let top = new Top(poly);
|
let top = new Top(poly);
|
||||||
|
|
@ -189,7 +139,7 @@
|
||||||
} else {
|
} else {
|
||||||
// frop top object passed back by slicePost()
|
// frop top object passed back by slicePost()
|
||||||
let top = new Top(poly.poly);
|
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_lines = poly.fill_lines;
|
||||||
top.fill_off = poly.fill_off;
|
top.fill_off = poly.fill_off;
|
||||||
top.last = poly.last;
|
top.last = poly.last;
|
||||||
|
|
@ -202,7 +152,7 @@
|
||||||
throw "invalid top";
|
throw "invalid top";
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.findClosestPointTo = function(target) {
|
findClosestPointTo(target) {
|
||||||
let min, find;
|
let min, find;
|
||||||
|
|
||||||
if (this.tops.length) {
|
if (this.tops.length) {
|
||||||
|
|
@ -224,7 +174,7 @@
|
||||||
return min;
|
return min;
|
||||||
};
|
};
|
||||||
|
|
||||||
PRO.xray = function(dash = 3) {
|
xray(dash = 3) {
|
||||||
// console.log('xray', this);
|
// console.log('xray', this);
|
||||||
this.output().setLayer(`xp`, 0x888800).addPolys(this.topPolys());
|
this.output().setLayer(`xp`, 0x888800).addPolys(this.topPolys());
|
||||||
this.lines.forEach((line, i) => {
|
this.lines.forEach((line, i) => {
|
||||||
|
|
@ -232,19 +182,65 @@
|
||||||
const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group];
|
const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group];
|
||||||
this.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2);
|
this.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
function newTop(poly) {
|
}
|
||||||
return new Top(poly);
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} z
|
* return innermost traces under a given top. for FDM, this represents
|
||||||
* @param {THREE.Group} view
|
* the outline shell that the fill touches. used by Print, Laser
|
||||||
* @returns {Slice}
|
|
||||||
*/
|
*/
|
||||||
function newSlice(z, view) {
|
innerShells() {
|
||||||
return new Slice(z, view);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
function newSlice(z, view) {
|
||||||
|
return new Slice(z, view);
|
||||||
|
}
|
||||||
|
|
||||||
|
gapp.overlay(kiri, {
|
||||||
|
Top,
|
||||||
|
Slice,
|
||||||
|
newTop,
|
||||||
|
newSlice
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
gapp.register("kiri.stack", [], (root, exports) => {
|
||||||
|
|
||||||
class Stack {
|
const { kiri } = root;
|
||||||
|
|
||||||
|
class Stack {
|
||||||
constructor(view, freeMem) {
|
constructor(view, freeMem) {
|
||||||
this._view = view;
|
this._view = view;
|
||||||
this.view = view.newGroup();
|
this.view = view.newGroup();
|
||||||
|
|
@ -212,18 +214,18 @@
|
||||||
mats.forEach(mat => mat.visible = defstate);
|
mats.forEach(mat => mat.visible = defstate);
|
||||||
return mats;
|
return mats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.kiri.Stack = Stack;
|
kiri.Stack = Stack;
|
||||||
|
|
||||||
let shininess = 15,
|
let shininess = 15,
|
||||||
specular = 0x444444,
|
specular = 0x444444,
|
||||||
emissive = 0x101010,
|
emissive = 0x101010,
|
||||||
metalness = 0,
|
metalness = 0,
|
||||||
roughness = 0.3,
|
roughness = 0.3,
|
||||||
newMat = createPhongMaterial;
|
newMat = createPhongMaterial;
|
||||||
|
|
||||||
function createLineMaterial(color, array) {
|
function createLineMaterial(color, array) {
|
||||||
const opacity = color.lopacity || color.opacity || 1;
|
const opacity = color.lopacity || color.opacity || 1;
|
||||||
const mat = new THREE.LineBasicMaterial({
|
const mat = new THREE.LineBasicMaterial({
|
||||||
transparent: true,
|
transparent: true,
|
||||||
|
|
@ -234,9 +236,9 @@
|
||||||
array.push(mat);
|
array.push(mat);
|
||||||
}
|
}
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStandardMaterial(color, flat) {
|
function createStandardMaterial(color, flat) {
|
||||||
return new THREE.MeshStandardMaterial({
|
return new THREE.MeshStandardMaterial({
|
||||||
emissive,
|
emissive,
|
||||||
roughness,
|
roughness,
|
||||||
|
|
@ -246,9 +248,9 @@
|
||||||
color: color.face,
|
color: color.face,
|
||||||
side: flat ? THREE.DoubleSide : THREE.FrontSide
|
side: flat ? THREE.DoubleSide : THREE.FrontSide
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPhongMaterial(color, flat) {
|
function createPhongMaterial(color, flat) {
|
||||||
return new THREE.MeshPhongMaterial({
|
return new THREE.MeshPhongMaterial({
|
||||||
shininess,
|
shininess,
|
||||||
specular,
|
specular,
|
||||||
|
|
@ -257,6 +259,6 @@
|
||||||
color: color.face,
|
color: color.face,
|
||||||
side: flat ? THREE.DoubleSide : THREE.FrontSide
|
side: flat ? THREE.DoubleSide : THREE.FrontSide
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,34 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
// dep: kiri.stack
|
||||||
|
// use: kiri.api
|
||||||
|
// use: kiri.ui
|
||||||
|
gapp.register("kiri.stacks", [], (root, exports) => {
|
||||||
|
|
||||||
let KIRI = self.kiri,
|
const { kiri } = root;
|
||||||
freeMem = true,
|
|
||||||
|
let freeMem = true,
|
||||||
stacks = {},
|
stacks = {},
|
||||||
tallest = 0,
|
tallest = 0,
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 0,
|
max = 0,
|
||||||
labels, API, UC, UI, DYN;
|
labels, API, UC, UI, DYN;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
labels = $("layers");
|
labels = $("layers");
|
||||||
API = KIRI.api,
|
API = kiri.api,
|
||||||
UC = API.uc,
|
UC = API.uc,
|
||||||
UI = API.ui;
|
UI = API.ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFreeMem(bool) {
|
function setFreeMem(bool) {
|
||||||
Object.values(stacks).forEach(stack => stack.obj.setFreeMem(bool));
|
Object.values(stacks).forEach(stack => stack.obj.setFreeMem(bool));
|
||||||
freeMem = bool;
|
freeMem = bool;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
if (!API) {
|
if (!API) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
@ -40,27 +44,27 @@
|
||||||
// clear labels
|
// clear labels
|
||||||
UC.setGroup(labels);
|
UC.setGroup(labels);
|
||||||
labels.innerHTML = '';
|
labels.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotate(set) {
|
function rotate(set) {
|
||||||
Object.values(stacks).forEach(stack => {
|
Object.values(stacks).forEach(stack => {
|
||||||
stack.obj.rotate(set);
|
stack.obj.rotate(set);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStack(name) {
|
function getStack(name) {
|
||||||
return stacks[name];
|
return stacks[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStacks() {
|
function getStacks() {
|
||||||
return Object.entries(stacks);
|
return Object.entries(stacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLabels() {
|
function getLabels() {
|
||||||
return Object.keys(DYN);
|
return Object.keys(DYN);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setVisible(label, bool) {
|
function setVisible(label, bool) {
|
||||||
let ctrl = DYN[label];
|
let ctrl = DYN[label];
|
||||||
if (ctrl) {
|
if (ctrl) {
|
||||||
ctrl.toggle.checked = bool;
|
ctrl.toggle.checked = bool;
|
||||||
|
|
@ -68,15 +72,15 @@
|
||||||
mat.visible = bool;
|
mat.visible = bool;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(name, view) {
|
function create(name, view) {
|
||||||
if (stacks[name]) {
|
if (stacks[name]) {
|
||||||
return stacks[name];
|
return stacks[name];
|
||||||
}
|
}
|
||||||
const stack = stacks[name] = {
|
const stack = stacks[name] = {
|
||||||
layers: [ ],
|
layers: [ ],
|
||||||
obj: new KIRI.Stack(view, freeMem),
|
obj: new kiri.Stack(view, freeMem),
|
||||||
add: function(layers) {
|
add: function(layers) {
|
||||||
let lmap = layers.layers;
|
let lmap = layers.layers;
|
||||||
let map = stack.obj.addLayers(layers);
|
let map = stack.obj.addLayers(layers);
|
||||||
|
|
@ -89,9 +93,9 @@
|
||||||
mat.visible = ctrl.toggle.checked;
|
mat.visible = ctrl.toggle.checked;
|
||||||
});
|
});
|
||||||
if (ctrl.toggle.checked) {
|
if (ctrl.toggle.checked) {
|
||||||
KIRI.api.event.emit("stack.show", label);
|
kiri.api.event.emit("stack.show", label);
|
||||||
} else {
|
} else {
|
||||||
KIRI.api.event.emit("stack.hide", label)
|
kiri.api.event.emit("stack.hide", label)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
@ -123,35 +127,35 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(name) {
|
function remove(name) {
|
||||||
const stack = stacks[name];
|
const stack = stacks[name];
|
||||||
if (stack) {
|
if (stack) {
|
||||||
stack.remove();
|
stack.remove();
|
||||||
delete stacks[name];
|
delete stacks[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRange() {
|
function getRange() {
|
||||||
return {min, max, tallest};
|
return {min, max, tallest};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRange(newMin, newMax) {
|
function setRange(newMin, newMax) {
|
||||||
Object.values(stacks).forEach(stack => {
|
Object.values(stacks).forEach(stack => {
|
||||||
stack.obj.setVisible(newMin,newMax);
|
stack.obj.setVisible(newMin,newMax);
|
||||||
});
|
});
|
||||||
min = newMin;
|
min = newMin;
|
||||||
max = newMax;
|
max = newMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFraction(frac) {
|
function setFraction(frac) {
|
||||||
Object.values(stacks).forEach(stack => {
|
Object.values(stacks).forEach(stack => {
|
||||||
stack.obj.setLastFraction(frac);
|
stack.obj.setLastFraction(frac);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
KIRI.stacks = {
|
kiri.stacks = {
|
||||||
clear,
|
clear,
|
||||||
create,
|
create,
|
||||||
rotate,
|
rotate,
|
||||||
|
|
@ -164,6 +168,6 @@
|
||||||
setVisible,
|
setVisible,
|
||||||
setFraction,
|
setFraction,
|
||||||
setFreeMem
|
setFreeMem
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { broker } = gapp;
|
||||||
const { api, utils } = kiri;
|
const { api, utils } = kiri;
|
||||||
const { js2o, o2js } = utils;
|
const { js2o, o2js } = utils;
|
||||||
|
|
@ -55,4 +58,4 @@ class Stats {
|
||||||
|
|
||||||
kiri.stats = new Stats();
|
kiri.stats = new Stats();
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,21 @@
|
||||||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
|
|
||||||
kiri.load(function(API) {
|
// dep: add.three
|
||||||
// circle
|
// dep: kiri.api
|
||||||
let pgeo = new THREE.CircleGeometry(8, 30);
|
gapp.register("kiri.tools", [], (root, exports) => {
|
||||||
let pmat = new THREE.MeshBasicMaterial({color: 0xff0000, opacity: 0.5, transparent: true});
|
|
||||||
let pmesh = new THREE.Mesh(pgeo, pmat);
|
const { kiri } = root;
|
||||||
// circle outline
|
const { api } = kiri;
|
||||||
let pi = pgeo.index.array;
|
|
||||||
let pp = pgeo.attributes.position.array;
|
// circle
|
||||||
let np = [];
|
let pgeo = new THREE.CircleGeometry(8, 30);
|
||||||
for (let i=0; i<pi.length; i++) {
|
let pmat = new THREE.MeshBasicMaterial({color: 0xff0000, opacity: 0.5, transparent: true});
|
||||||
|
let pmesh = new THREE.Mesh(pgeo, pmat);
|
||||||
|
// circle outline
|
||||||
|
let pi = pgeo.index.array;
|
||||||
|
let pp = pgeo.attributes.position.array;
|
||||||
|
let np = [];
|
||||||
|
for (let i=0; i<pi.length; i++) {
|
||||||
if (pi[i] * pi[i+1]) {
|
if (pi[i] * pi[i+1]) {
|
||||||
np.push(pp[pi[i]*3+0]);
|
np.push(pp[pi[i]*3+0]);
|
||||||
np.push(pp[pi[i]*3+1]);
|
np.push(pp[pi[i]*3+1]);
|
||||||
|
|
@ -18,52 +24,56 @@ kiri.load(function(API) {
|
||||||
np.push(pp[pi[i+1]*3+1]);
|
np.push(pp[pi[i+1]*3+1]);
|
||||||
np.push(pp[pi[i+1]*3+2]);
|
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);
|
|
||||||
|
|
||||||
let alert;
|
let wgeo = new THREE.BufferGeometry();
|
||||||
let lastobj;
|
wgeo.setAttribute('position', new THREE.BufferAttribute(np.toFloat32(), 3));
|
||||||
let lastface;
|
|
||||||
let enabled = false;
|
|
||||||
|
|
||||||
function cleanup() {
|
let wmat = new THREE.LineBasicMaterial({ color: 0x883333 });
|
||||||
|
let wmesh = new THREE.LineSegments(wgeo, wmat);
|
||||||
|
pmesh.add(wmesh);
|
||||||
|
|
||||||
|
let alert;
|
||||||
|
let lastobj;
|
||||||
|
let lastface;
|
||||||
|
let enabled = false;
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
if (lastobj) {
|
if (lastobj) {
|
||||||
lastobj.remove(pmesh);
|
lastobj.remove(pmesh);
|
||||||
lastobj = undefined;
|
lastobj = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function endit() {
|
function endit() {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
API.hide.alert(alert);
|
api.hide.alert(alert);
|
||||||
$('lay-flat').classList.remove('selected');
|
$('lay-flat').classList.remove('selected');
|
||||||
API.feature.hover = false;
|
api.feature.hover = false;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
alert = undefined;
|
alert = undefined;
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
API.event.on('key.esc', endit);
|
api.event.on('key.esc', endit);
|
||||||
API.event.on('tool.mesh.lay-flat', () => {
|
|
||||||
|
api.event.on('tool.mesh.lay-flat', () => {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
endit();
|
endit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (API.feature.hover) {
|
if (api.feature.hover) {
|
||||||
console.log('lay flat cannot pre-empt hover');
|
console.log('lay flat cannot pre-empt hover');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('lay-flat').classList.add('selected');
|
$('lay-flat').classList.add('selected');
|
||||||
API.feature.hover = true;
|
api.feature.hover = true;
|
||||||
enabled = 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) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -84,8 +94,9 @@ kiri.load(function(API) {
|
||||||
);
|
);
|
||||||
pmesh.setRotationFromQuaternion(q);
|
pmesh.setRotationFromQuaternion(q);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
API.event.on('mouse.hover.up', (ev) => {
|
|
||||||
|
api.event.on('mouse.hover.up', (ev) => {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +105,8 @@ kiri.load(function(API) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let q = new THREE.Quaternion().setFromUnitVectors(lastface.normal, new THREE.Vector3(0,0,-1));
|
let q = new THREE.Quaternion().setFromUnitVectors(lastface.normal, new THREE.Vector3(0,0,-1));
|
||||||
API.selection.rotate(q);
|
api.selection.rotate(q);
|
||||||
endit();
|
endit();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
gapp.register("kiri.ui", [], (root, exports) => {
|
||||||
|
|
||||||
if (kiri.ui) return;
|
if (kiri.ui) return;
|
||||||
|
|
||||||
|
|
@ -939,4 +939,4 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
// dep: data.local
|
// dep: data.local
|
||||||
// dep: main.kiri
|
// dep: main.kiri
|
||||||
// use: moto.ajax
|
// use: moto.ajax
|
||||||
(function () {
|
gapp.register("kiri.utils", [], (root, exports) => {
|
||||||
|
|
||||||
const { kiri, moto, data } = self;
|
const { kiri, moto, data } = root;
|
||||||
|
|
||||||
function parseOpt(ov) {
|
function parseOpt(ov) {
|
||||||
let opt = {}, kv, kva;
|
let opt = {}, kv, kva;
|
||||||
|
|
@ -96,7 +96,7 @@ function areEqual(o1, o2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
kiri.utils = {
|
exports({
|
||||||
areEqual,
|
areEqual,
|
||||||
parseOpt,
|
parseOpt,
|
||||||
encodeOpt,
|
encodeOpt,
|
||||||
|
|
@ -107,6 +107,6 @@ kiri.utils = {
|
||||||
avgc,
|
avgc,
|
||||||
rgb,
|
rgb,
|
||||||
a2c
|
a2c
|
||||||
};
|
});
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -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";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
gapp.register("kiri.widget", [], (root, exports) => {
|
||||||
|
|
||||||
if (self.kiri.Widget) return;
|
const { base, kiri } = root;
|
||||||
|
|
||||||
const { base, kiri } = self;
|
|
||||||
const { api, driver, utils } = kiri;
|
const { api, driver, utils } = kiri;
|
||||||
const { config, util, polygons } = base;
|
const { config, util, polygons } = base;
|
||||||
const { Mesh, newPoint, verticesToPoints } = base;
|
const { Mesh, newPoint, verticesToPoints } = base;
|
||||||
|
|
@ -963,4 +961,4 @@ Widget.deleteFromState = function(id,ondone) {
|
||||||
kiri.Widget = Widget;
|
kiri.Widget = Widget;
|
||||||
kiri.newWidget = newWidget;
|
kiri.newWidget = newWidget;
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
"use strict";
|
"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 { api, consts, utils, newWidget, Widget } = kiri;
|
||||||
const { space } = moto;
|
const { space } = moto;
|
||||||
|
|
||||||
|
|
@ -110,4 +110,4 @@ const widgets = api.widgets = {
|
||||||
for(fn) { widgets.each(fn) },
|
for(fn) { widgets.each(fn) },
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
});
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,9 @@ a, a:hover, a:visited {
|
||||||
transform: translateX(-50%) translateY(-50%);
|
transform: translateX(-50%) translateY(-50%);
|
||||||
z-index: 50;
|
z-index: 50;
|
||||||
}
|
}
|
||||||
#app-name, #app-mode-name, #app-acct {
|
#app-name, #app-acct {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
#app-mode-name {
|
|
||||||
border-bottom: 2px dotted grey;
|
|
||||||
}
|
|
||||||
#app,div {
|
#app,div {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
@ -296,18 +293,16 @@ th, tr, td, label {
|
||||||
margin: 0 5px 0 5px;
|
margin: 0 5px 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#mode-info.hoverpop {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
#mode-info {
|
#mode-info {
|
||||||
display: none;
|
display: none;
|
||||||
position: absolute;
|
xposition: absolute;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
left: 100%;
|
top: 50%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 1px 5px 1px 5px;
|
transform: translateY(-50%);
|
||||||
|
padding: 1px 0 1px 0;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@
|
||||||
<div id="top-sep"></div>
|
<div id="top-sep"></div>
|
||||||
<div id="top" class="f-row">
|
<div id="top" class="f-row">
|
||||||
<div id="app-mode">
|
<div id="app-mode">
|
||||||
<div id="app-mode-name"></div>
|
|
||||||
<div id="mode-info" class="f-row">
|
<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>Device</label><div id="mode-device"></div>
|
||||||
<label>Profile</label><div id="mode-profile"></div>
|
<label>Profile</label><div id="mode-profile"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue