From a17ee36335569bb29ce527ce02c40243b136602a Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 3 Nov 2020 11:19:13 -0500 Subject: [PATCH] add new module loader, comments --- notes.md | 12 ++----- src/kiri.js | 8 +++-- src/kiri/main.js | 4 ++- src/kiri/widget.js | 15 ++++----- src/kiri/work.js | 11 ++++++ src/kiri/worker.js | 76 ++++++++++++++++-------------------------- src/mode/cam/driver.js | 5 +++ 7 files changed, 62 insertions(+), 69 deletions(-) diff --git a/notes.md b/notes.md index 3fd44ce6..07900624 100644 --- a/notes.md +++ b/notes.md @@ -2,18 +2,16 @@ ## `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` extend mesh object to store raw + annotations (rot,scale,pos) * share raw data w/ dups, encode/decode * `F` gcode color to speed visualization bar * `F` X,Y,Z colored axes visualizations +* `F` 2D image import * `P` bail on decimation if it's proving ineffective * `P` improve decimation speed by avoiding in/out of Point? * `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 -* `F` https://poeditor.com/projects/view_terms?id=336467&per_page=20 # FDM @@ -35,7 +33,6 @@ * `F` trim support offset from layer below * `F` option to support interior bridges when 0% infill * `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` 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` contouring should extend beyond part boundaries by tool radius * `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` 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 planar settings visualizations * `F` use arcs to connect hard angles * `F` lead-in milling +* `F` adaptive clearing in roughing mode * `F` trapezoidal tabs (in the Z axis) * `F` ease-in and ease-out especially on tab cut-out start/stop * `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 support for tapered ball mills * `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` 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` background worker to speculatively generate topo maps (and maybe pre-slicing) # Laser * `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) # References diff --git a/src/kiri.js b/src/kiri.js index 83708208..b29ac2d8 100644 --- a/src/kiri.js +++ b/src/kiri.js @@ -4,8 +4,10 @@ (function () { - if (self.kiri) return; - - self.kiri = { }; + if (!self.kiri) { + self.kiri = { + loader: [] // module loading: array of functions + }; + } })(); diff --git a/src/kiri/main.js b/src/kiri/main.js index 458d078f..da49fb1a 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -928,7 +928,7 @@ totalProgress += (track[w.id] || 0); }); API.show.progress((totalProgress / WIDGETS.length), msg); - }, true); + }); }); } @@ -2116,5 +2116,7 @@ if (Array.isArray(self.kirimod)) { kirimod.forEach(function(mod) { mod(kiri.api) }); } + // new module loading + kiri.loader.forEach(mod => { mod(kiri.api)} ); })(); diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 25a79ac8..869de09b 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -638,22 +638,21 @@ * @params {Object} settings * @params {Function} [ondone] * @params {Function} [onupdate] - * @params {boolean} [remote] */ - PRO.slice = function(settings, ondone, onupdate, remote) { - let widget = this, - startTime = UTIL.time(); + PRO.slice = function(settings, ondone, onupdate) { + let widget = this; + let startTime = UTIL.time(); widget.settings = settings; widget.clearSlices(); onupdate(0.0001, "slicing"); - if (remote) { + if (KIRI.client) { // in case result of slice is nothing, do not preserve previous widget.slices = [] // executed from kiri.js - KIRI.work.slice(settings, this, function (reply) { + KIRI.client.slice(settings, this, function(reply) { if (reply.update) { onupdate(reply.update, reply.updateStatus); } @@ -683,9 +682,9 @@ ondone(true); } }); + } - } else { - + if (KIRI.server) { // executed from kiri-worker.js let catchdone = function(error) { if (error) { diff --git a/src/kiri/work.js b/src/kiri/work.js index b331eead..c4ddfb5d 100644 --- a/src/kiri/work.js +++ b/src/kiri/work.js @@ -17,6 +17,13 @@ let loc = self.location, slicing = {}, 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) { let seq = seqid++; @@ -30,7 +37,11 @@ function send(fn, data, onreply, async, zerocopy) { }, zerocopy); } +// code is running in the browser / client context +KIRI.client = KIRI.work = { + send: send, + newWorker: function() { if (self.createWorker) { return self.createWorker(); diff --git a/src/kiri/worker.js b/src/kiri/worker.js index 65d26f2d..34d08e91 100644 --- a/src/kiri/worker.js +++ b/src/kiri/worker.js @@ -2,30 +2,31 @@ "use strict"; -// (function() { - -const base = self.base, - util = base.util, - time = util.time, - kiri = self.kiri, - ver = kiri.version, - Widget = kiri.Widget, +let BASE = self.base, + KIRI = self.kiri, + UTIL = BASE.util, + Widget = KIRI.Widget, + time = UTIL.time, current = self.worker = { print: null, snap: null - }; - -let cache = {}; - -console.log(`kiri | init work | ${ver}`); -base.debug.disable(); + }, + cache = {}; // catch clipper alerts and convert to console messages self.alert = function(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) { vertices = new Float32Array(vertices), vertices = Widget.pointsToVertices(Widget.verticesToPoints(vertices, true)); @@ -52,32 +53,10 @@ let dispatch = { 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"}); - let widget = kiri.newWidget(data.id).setPoints(points), - last = util.time(), + let widget = KIRI.newWidget(data.id).setPoints(points), + last = time(), now; // do it here so cancel can work @@ -108,13 +87,13 @@ let dispatch = { send.data({index: index, slice: slice.encode(state)}); }) 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.done({done: true}); }, function(update, msg) { - now = util.time(); + now = time(); if (now - last < 10 && update < 0.99) return; // on update send.data({update: (0.05 + update * 0.95), updateStatus: msg}); @@ -135,7 +114,7 @@ let dispatch = { 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) { send.data({ update: update, @@ -193,7 +172,7 @@ let dispatch = { const update = {}; if (data.base) { update.base = data.base; - Object.assign(self.base.config, data.base); + Object.assign(BASE.config, data.base); } else { console.log({invalid:data}); } @@ -202,7 +181,7 @@ let dispatch = { }; self.onmessage = function(e) { - let time_recv = util.time(), + let time_recv = time(), msg = e.data, run = dispatch[msg.task], send = { @@ -227,7 +206,7 @@ self.onmessage = function(e) { if (run) { let time_xfer = (time_recv - msg.time), output = run(msg.data, send), - time_send = util.time(), + time_send = time(), time_proc = time_send - time_recv; if (output) self.postMessage({ @@ -236,7 +215,7 @@ self.onmessage = function(e) { time_send: time_xfer, time_proc: time_proc, // replaced on reply side - time_recv: util.time(), + time_recv: time(), data: output }); } else { @@ -244,4 +223,7 @@ self.onmessage = function(e) { } }; -// })(); +// load kiri modules +KIRI.loader.forEach(fn => { + fn(dispatch); +}); diff --git a/src/mode/cam/driver.js b/src/mode/cam/driver.js index 4bb9bb7d..c63e7e60 100644 --- a/src/mode/cam/driver.js +++ b/src/mode/cam/driver.js @@ -845,6 +845,11 @@ * @param {Function} output */ function slice(settings, widget, onupdate, ondone) { + + // * find flats + // * generate master slices (used instead of topo) + // * generate shadow from master + let conf = settings, proc = conf.process, sliceAll = widget.slices = [],