add new module loader, comments

This commit is contained in:
Stewart Allen 2020-11-03 11:19:13 -05:00
commit a17ee36335
7 changed files with 62 additions and 69 deletions

View file

@ -2,18 +2,16 @@
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix ## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
* `F` add click-to-activate/dismiss for configuration panels
* `F` implement an in-app bug reporting system * `F` implement an in-app bug reporting system
* `F` extend mesh object to store raw + annotations (rot,scale,pos) * `F` extend mesh object to store raw + annotations (rot,scale,pos)
* share raw data w/ dups, encode/decode * share raw data w/ dups, encode/decode
* `F` gcode color to speed visualization bar * `F` gcode color to speed visualization bar
* `F` X,Y,Z colored axes visualizations * `F` X,Y,Z colored axes visualizations
* `F` 2D image import
* `P` bail on decimation if it's proving ineffective * `P` bail on decimation if it's proving ineffective
* `P` improve decimation speed by avoiding in/out of Point? * `P` improve decimation speed by avoiding in/out of Point?
* `P` server-side processing (determine protocol and storage) * `P` server-side processing (determine protocol and storage)
* `P` refactor / simplify POLY.expand (put onus on collector)
* `P` duplicate objects should share same slice data unless rotated or scaled * `P` duplicate objects should share same slice data unless rotated or scaled
* `F` https://poeditor.com/projects/view_terms?id=336467&per_page=20
# FDM # FDM
@ -35,7 +33,6 @@
* `F` trim support offset from layer below * `F` trim support offset from layer below
* `F` option to support interior bridges when 0% infill * `F` option to support interior bridges when 0% infill
* `F` calculate filament use per extruder per print * `F` calculate filament use per extruder per print
* `P` refactor thin fill to use outline and inside poly normal dist to self
* `P` segment large polygons for extremely large parts / infill * `P` segment large polygons for extremely large parts / infill
* `P` implement infill clipping in wasm * `P` implement infill clipping in wasm
@ -51,13 +48,13 @@
* `B` fails in pancaking (clone) when there are no sliced layers (like z bottom too high) * `B` fails in pancaking (clone) when there are no sliced layers (like z bottom too high)
* `B` contouring should extend beyond part boundaries by tool radius * `B` contouring should extend beyond part boundaries by tool radius
* `B` outside cutting direction in roughing mode inverted * `B` outside cutting direction in roughing mode inverted
* `B` widen outside cuts to prevent chatter on deep (metal) features
* `F` provide planar or other visual hint of current z bottom offset * `F` provide planar or other visual hint of current z bottom offset
* `F` redo collision code use fixed slices and path/poly intersection instead of a topo map * `F` redo collision code use fixed slices and path/poly intersection instead of a topo map
* `F` z bounded slices (extension of z bottom offset feature) * `F` z bounded slices (extension of z bottom offset feature)
* `F` z planar settings visualizations * `F` z planar settings visualizations
* `F` use arcs to connect hard angles * `F` use arcs to connect hard angles
* `F` lead-in milling * `F` lead-in milling
* `F` adaptive clearing in roughing mode
* `F` trapezoidal tabs (in the Z axis) * `F` trapezoidal tabs (in the Z axis)
* `F` ease-in and ease-out especially on tab cut-out start/stop * `F` ease-in and ease-out especially on tab cut-out start/stop
* `F` implement z line-only follows for ball/taper * `F` implement z line-only follows for ball/taper
@ -65,19 +62,14 @@
* `F` add endmill spiral direction to fully respect climb vs conventional * `F` add endmill spiral direction to fully respect climb vs conventional
* `F` add support for tapered ball mills * `F` add support for tapered ball mills
* `F` warn when part > stock or cuts go outside bed * `F` warn when part > stock or cuts go outside bed
* `F` add M03 tool feedrate support
* `P` refactor slicing around flats w/ interpolation instead of culling * `P` refactor slicing around flats w/ interpolation instead of culling
* `P` disable topo generation when no contour xy and no depth first * `P` disable topo generation when no contour xy and no depth first
* `P` store tab and camshell polys in widget.topo to minimize z on edge moves
* `P` contouring is going back to z top too often
* `P` option to skip milling holes that would be drilled
* `P` crossing open space check point is outside camshell before returning max z * `P` crossing open space check point is outside camshell before returning max z
* `P` background worker to speculatively generate topo maps (and maybe pre-slicing) * `P` background worker to speculatively generate topo maps (and maybe pre-slicing)
# Laser # Laser
* `F` overcuts, radii for drag knives * `F` overcuts, radii for drag knives
* `F` output option to uniquely color code each layer
* `F` add PLT / HP-GL output format (https://en.wikipedia.org/wiki/HP-GL) * `F` add PLT / HP-GL output format (https://en.wikipedia.org/wiki/HP-GL)
# References # References

View file

@ -4,8 +4,10 @@
(function () { (function () {
if (self.kiri) return; if (!self.kiri) {
self.kiri = {
self.kiri = { }; loader: [] // module loading: array of functions
};
}
})(); })();

View file

@ -928,7 +928,7 @@
totalProgress += (track[w.id] || 0); totalProgress += (track[w.id] || 0);
}); });
API.show.progress((totalProgress / WIDGETS.length), msg); API.show.progress((totalProgress / WIDGETS.length), msg);
}, true); });
}); });
} }
@ -2116,5 +2116,7 @@
if (Array.isArray(self.kirimod)) { if (Array.isArray(self.kirimod)) {
kirimod.forEach(function(mod) { mod(kiri.api) }); kirimod.forEach(function(mod) { mod(kiri.api) });
} }
// new module loading
kiri.loader.forEach(mod => { mod(kiri.api)} );
})(); })();

View file

@ -638,22 +638,21 @@
* @params {Object} settings * @params {Object} settings
* @params {Function} [ondone] * @params {Function} [ondone]
* @params {Function} [onupdate] * @params {Function} [onupdate]
* @params {boolean} [remote]
*/ */
PRO.slice = function(settings, ondone, onupdate, remote) { PRO.slice = function(settings, ondone, onupdate) {
let widget = this, let widget = this;
startTime = UTIL.time(); let startTime = UTIL.time();
widget.settings = settings; widget.settings = settings;
widget.clearSlices(); widget.clearSlices();
onupdate(0.0001, "slicing"); onupdate(0.0001, "slicing");
if (remote) { if (KIRI.client) {
// in case result of slice is nothing, do not preserve previous // in case result of slice is nothing, do not preserve previous
widget.slices = [] widget.slices = []
// executed from kiri.js // executed from kiri.js
KIRI.work.slice(settings, this, function (reply) { KIRI.client.slice(settings, this, function(reply) {
if (reply.update) { if (reply.update) {
onupdate(reply.update, reply.updateStatus); onupdate(reply.update, reply.updateStatus);
} }
@ -683,9 +682,9 @@
ondone(true); ondone(true);
} }
}); });
}
} else { if (KIRI.server) {
// executed from kiri-worker.js // executed from kiri-worker.js
let catchdone = function(error) { let catchdone = function(error) {
if (error) { if (error) {

View file

@ -17,6 +17,13 @@ let loc = self.location,
slicing = {}, slicing = {},
worker = null; worker = null;
/**
* @param {Function} fn name of function in KIRI.worker
* @param {Object} data to send to server
* @param {Function} onreply function to call on reply messages
* @param {Boolean} async true of function returns many messages
* @param {Object[]} zerocopy array of objects to pass using zerocopy
*/
function send(fn, data, onreply, async, zerocopy) { function send(fn, data, onreply, async, zerocopy) {
let seq = seqid++; let seq = seqid++;
@ -30,7 +37,11 @@ function send(fn, data, onreply, async, zerocopy) {
}, zerocopy); }, zerocopy);
} }
// code is running in the browser / client context
KIRI.client =
KIRI.work = { KIRI.work = {
send: send,
newWorker: function() { newWorker: function() {
if (self.createWorker) { if (self.createWorker) {
return self.createWorker(); return self.createWorker();

View file

@ -2,30 +2,31 @@
"use strict"; "use strict";
// (function() { let BASE = self.base,
KIRI = self.kiri,
const base = self.base, UTIL = BASE.util,
util = base.util, Widget = KIRI.Widget,
time = util.time, time = UTIL.time,
kiri = self.kiri,
ver = kiri.version,
Widget = kiri.Widget,
current = self.worker = { current = self.worker = {
print: null, print: null,
snap: null snap: null
}; },
cache = {};
let cache = {};
console.log(`kiri | init work | ${ver}`);
base.debug.disable();
// catch clipper alerts and convert to console messages // catch clipper alerts and convert to console messages
self.alert = function(o) { self.alert = function(o) {
console.log(o); console.log(o);
}; };
let dispatch = { console.log(`kiri | init work | ${KIRI.version}`);
BASE.debug.disable();
// code is running in the worker / server context
const dispatch =
KIRI.server =
KIRI.worker = {
cache: cache,
decimate: function(vertices, send) { decimate: function(vertices, send) {
vertices = new Float32Array(vertices), vertices = new Float32Array(vertices),
vertices = Widget.pointsToVertices(Widget.verticesToPoints(vertices, true)); vertices = Widget.pointsToVertices(Widget.verticesToPoints(vertices, true));
@ -52,32 +53,10 @@ let dispatch = {
state.rotate = new THREE.Matrix4().makeRotationY(-rotation); state.rotate = new THREE.Matrix4().makeRotationY(-rotation);
} }
// let buf = new THREE.BufferGeometry();
// buf.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
// let geo = new THREE.Geometry().fromBufferGeometry(buf);
// geo.computeFaceNormals();
// console.log(geo);
// let z0 = new THREE.Vector3(0,0,1);
// let ve = geo.vertices;
// geo.faces.forEach((face,ind) => {
// let n = face.normal;
// let v3 = new THREE.Vector3(n.x, n.y, n.z);
// if (n.z >= 0) {
// console.log({skip:ind});
// return;
// }
// let va = v3.angleTo(z0) / Math.PI;
// let i3 = ind * 3;
// let v = [
// ve[i3], ve[i3+1], ve[i3+2]
// ];
// console.log({ind, va, v});
// });
send.data({update:0.05, updateStatus:"slicing"}); send.data({update:0.05, updateStatus:"slicing"});
let widget = kiri.newWidget(data.id).setPoints(points), let widget = KIRI.newWidget(data.id).setPoints(points),
last = util.time(), last = time(),
now; now;
// do it here so cancel can work // do it here so cancel can work
@ -108,13 +87,13 @@ let dispatch = {
send.data({index: index, slice: slice.encode(state)}); send.data({index: index, slice: slice.encode(state)});
}) })
if (self.debug && widget.polish) { if (self.debug && widget.polish) {
send.data({polish: kiri.codec.encode(widget.polish)}); send.data({polish: KIRI.codec.encode(widget.polish)});
} }
send.data({send_end: time()}); send.data({send_end: time()});
} }
send.done({done: true}); send.done({done: true});
}, function(update, msg) { }, function(update, msg) {
now = util.time(); now = time();
if (now - last < 10 && update < 0.99) return; if (now - last < 10 && update < 0.99) return;
// on update // on update
send.data({update: (0.05 + update * 0.95), updateStatus: msg}); send.data({update: (0.05 + update * 0.95), updateStatus: msg});
@ -135,7 +114,7 @@ let dispatch = {
send.data({update:0.05, updateStatus:"preview"}); send.data({update:0.05, updateStatus:"preview"});
current.print = kiri.newPrint(data.settings, widgets, data.id); current.print = KIRI.newPrint(data.settings, widgets, data.id);
current.print.setup(false, function(update, msg) { current.print.setup(false, function(update, msg) {
send.data({ send.data({
update: update, update: update,
@ -193,7 +172,7 @@ let dispatch = {
const update = {}; const update = {};
if (data.base) { if (data.base) {
update.base = data.base; update.base = data.base;
Object.assign(self.base.config, data.base); Object.assign(BASE.config, data.base);
} else { } else {
console.log({invalid:data}); console.log({invalid:data});
} }
@ -202,7 +181,7 @@ let dispatch = {
}; };
self.onmessage = function(e) { self.onmessage = function(e) {
let time_recv = util.time(), let time_recv = time(),
msg = e.data, msg = e.data,
run = dispatch[msg.task], run = dispatch[msg.task],
send = { send = {
@ -227,7 +206,7 @@ self.onmessage = function(e) {
if (run) { if (run) {
let time_xfer = (time_recv - msg.time), let time_xfer = (time_recv - msg.time),
output = run(msg.data, send), output = run(msg.data, send),
time_send = util.time(), time_send = time(),
time_proc = time_send - time_recv; time_proc = time_send - time_recv;
if (output) self.postMessage({ if (output) self.postMessage({
@ -236,7 +215,7 @@ self.onmessage = function(e) {
time_send: time_xfer, time_send: time_xfer,
time_proc: time_proc, time_proc: time_proc,
// replaced on reply side // replaced on reply side
time_recv: util.time(), time_recv: time(),
data: output data: output
}); });
} else { } else {
@ -244,4 +223,7 @@ self.onmessage = function(e) {
} }
}; };
// })(); // load kiri modules
KIRI.loader.forEach(fn => {
fn(dispatch);
});

View file

@ -845,6 +845,11 @@
* @param {Function} output * @param {Function} output
*/ */
function slice(settings, widget, onupdate, ondone) { function slice(settings, widget, onupdate, ondone) {
// * find flats
// * generate master slices (used instead of topo)
// * generate shadow from master
let conf = settings, let conf = settings,
proc = conf.process, proc = conf.process,
sliceAll = widget.slices = [], sliceAll = widget.slices = [],