diff --git a/app.js b/app.js index d8872b38..3d177790 100644 --- a/app.js +++ b/app.js @@ -937,6 +937,7 @@ function cookieValue(cookie,key) { function rewriteHtmlVersion(req, res, next) { if ([ "/v2/kiri/", + "/v2/lib/kiri-run/minion.js", "/v2/lib/kiri-run/worker.js" ].indexOf(req.app.path) >= 0) { addCorsHeaders(req, res); diff --git a/src2/geo/polygon.js b/src2/geo/polygon.js index e9a424a2..7dafa190 100644 --- a/src2/geo/polygon.js +++ b/src2/geo/polygon.js @@ -6,13 +6,12 @@ import { base, config, util } from './base.js'; import { ClipperLib } from '../ext/clip2.esm.js'; import { newBounds } from './bounds.js'; import { newPoint, pointFromClipper } from './point.js'; -import { polygons } from './polygons.js'; +import { polygons as POLY } from './polygons.js'; import { earcut } from '../geo/base.js'; const { Vector3 } = THREE; -const POLY = polygons, - XAXIS = new Vector3(1,0,0), +let XAXIS = new Vector3(1,0,0), DEG2RAD = Math.PI / 180, Clipper = ClipperLib.Clipper, ClipType = ClipperLib.ClipType, @@ -2381,5 +2380,3 @@ export function fromClipperPath(path, z) { export function newPolygon(points) { return new Polygon(points); } - -export { polygons }; \ No newline at end of file diff --git a/src2/geo/slicer.js b/src2/geo/slicer.js index 4969d477..e9713328 100644 --- a/src2/geo/slicer.js +++ b/src2/geo/slicer.js @@ -10,7 +10,6 @@ import { newOrderedLine } from './line.js'; import { newPolygon } from '../geo/polygon.js'; import { polygons } from '../geo/polygons.js'; import { newPoint } from '../geo/point.js'; -import { util } from '../mesh/util.js'; import { config } from '../geo/base.js'; function dval(v, dv) { @@ -409,7 +408,6 @@ export async function sliceZ(z, points, options = {}) { // look for driver-specific slice post-processor if (options.post) { - console.log({ options }); let fn = slicer.slicePost[options.post]; if (fn) fn(rval, options); } diff --git a/src2/kiri-mode/fdm/post.js b/src2/kiri-mode/fdm/post.js index bf4190ff..2fe7dd85 100644 --- a/src2/kiri-mode/fdm/post.js +++ b/src2/kiri-mode/fdm/post.js @@ -3,6 +3,9 @@ import { base } from '../../geo/base.js'; import { polygons as POLY, fillArea } from '../../geo/polygons.js'; import { getRangeParameters } from './driver.js'; +import { slicer } from '../../geo/slicer.js'; + +slicer.slicePost.FDM = slicePost; /** * may run in minion or worker context. do not create objects diff --git a/src2/kiri-run/minion.js b/src2/kiri-run/minion.js index 5d3671fa..f20135ad 100644 --- a/src2/kiri-run/minion.js +++ b/src2/kiri-run/minion.js @@ -1,26 +1,20 @@ /** Copyright Stewart Allen -- All Rights Reserved */ -// Base dependencies -import { polygons } from '../../geo/base.js'; +import "../ext/clip2.js"; +import "../ext/earcut.js"; +import '../add/array.js'; +import '../add/class.js'; +import '../add/three.js'; -// Kiri dependencies -import { codec } from '../../kiri/index.js'; +import { base } from '../geo/base.js'; +import { newPoint } from '../geo/point.js'; +import { polygons as POLY } from '../geo/polygons.js'; +import { sliceZ } from '../geo/slicer.js'; +import { codec } from '../kiri/codec.js'; +import { broker } from '../moto/broker.js'; +import { doTopShells } from '../kiri-mode/fdm/post.js'; +import { wasm_ctrl } from '../geo/wasm.js'; -// Moto dependencies -import { broker } from '../../moto/broker.js'; - -// Note: This module also depends on: -// - moto.license (for licensing functionality) -// - geo.slicer (for slicing functionality) -// - geo.wasm (for WebAssembly functionality) -// - kiri-mode.fdm.post (for FDM post processing) -// - kiri-mode.cam.topo (for CAM topo functionality) -// - kiri-mode.cam.topo4 (for CAM topo4 functionality) -// - kiri-mode.cam.slicer (for CAM slicing) -// - ext.clip2 (for clipping operations) -// - Various kiri API functions injected via root - -const POLY = polygons; const clib = self.ClipperLib; const ctyp = clib.ClipType; const ptyp = clib.PolyType; @@ -75,7 +69,7 @@ const funcs = self.minion = { topShells: (data, seq) => { let top = codec.decode(data.top, {full: true}); let {z, count, offset1, offsetN, fillOffset, opt} = data; - kiri.driver.FDM.doTopShells(z, top, count, offset1, offsetN, fillOffset, opt); + doTopShells(z, top, count, offset1, offsetN, fillOffset, opt); let state = { zeros: [] }; reply({ seq, top: codec.encode(top, {full: true}) }, state.zeros); }, @@ -122,14 +116,15 @@ const funcs = self.minion = { }, sliceZ: (data, seq) => { + console.log('minion.sliceZ', { data, seq }); let { z, points, options } = data; let i = 0, p = 0, realp = new Array(points.length / 3); while (i < points.length) { - realp[p++] = base.newPoint(points[i++], points[i++], points[i++]).round(3); + realp[p++] = newPoint(points[i++], points[i++], points[i++]).round(3); } let state = { zero: [] }; let output = []; - base.sliceZ(z, realp, { + sliceZ(z, realp, { ...options, each(out) { output.push(out) } }).then(() => { @@ -159,9 +154,9 @@ const funcs = self.minion = { wasm: data => { if (data.enable) { - base.wasm_ctrl.enable(); + wasm_ctrl.enable(); } else { - base.wasm_ctrl.disable(); + wasm_ctrl.disable(); } }, @@ -170,18 +165,4 @@ const funcs = self.minion = { } }; -moto.broker.publish("minion.started", { funcs, cache, reply, log }); - -// Future exports for src/kiri-run/minion.js when unwrapped from gapp.register() - -// Utility functions -export { reply, log }; - -// Constants -export { POLY, clib, ctyp, ptyp, cfil }; - -// Global variables -export { cache, name }; - -// Default export - the main minion functionality -export default funcs; \ No newline at end of file +broker.publish("minion.started", { funcs, cache, reply, log }); diff --git a/src2/kiri-run/worker.js b/src2/kiri-run/worker.js index be40fc37..91935b5f 100644 --- a/src2/kiri-run/worker.js +++ b/src2/kiri-run/worker.js @@ -78,7 +78,16 @@ const minwork = { return; } for (let i=0; i < concurrent; i++) { - let minion = new Worker(`/v2/lib/kiri-run/minion.js`); + let minion = new Worker(`/v2/lib/kiri-run/minion.js`, { type: 'module' }); + minion.onerror = (error) => { + console.log({ MINION_ERROR: error }); + error.preventDefault(); + }; + minion.onmessageerror = (error) => { + console.log({ MINION_MESSAGE_ERROR: error }); + error.preventDefault(); + }; + console.log({ minion }); minion.onmessage = minhandler; minion.postMessage({ cmd: "label", name: `#${i}` }); minions.push(minion); @@ -173,6 +182,7 @@ const minwork = { }, sliceZ(z, points, options) { + console.log('minwork.sliceZ', { z, points, options }); return new Promise((resolve, reject) => { if (concurrent < 2) { reject("concurrent slice unavaiable"); diff --git a/src2/kiri/client.js b/src2/kiri/client.js index c8bf6032..cb273e9b 100644 --- a/src2/kiri/client.js +++ b/src2/kiri/client.js @@ -68,11 +68,12 @@ export const client = { } else { let worker = new Worker(`/v2/lib/kiri-run/worker.js`, { type: 'module' }); worker.onerror = (error) => { - console.log({ worker_error: error }); + console.log({ WORKER_ERROR: error }); error.preventDefault(); }; worker.onmessageerror = (error) => { - console.log({ worker_message_error: error }); + console.log({ WORKER_MESSAGE_ERROR: error }); + error.preventDefault(); }; console.log({ worker }); return worker; diff --git a/src2/mesh/model.js b/src2/mesh/model.js index 098de910..70a5a92d 100644 --- a/src2/mesh/model.js +++ b/src2/mesh/model.js @@ -5,7 +5,8 @@ import { client as motoClient } from '../moto/client.js'; import { api as meshApi } from './api.js'; import { object as meshObject } from './object.js'; import { model as meshModel } from './model.js'; -import { newPolygon, polygons } from '../geo/polygon.js'; +import { newPolygon } from '../geo/polygon.js'; +import { polygons } from '../geo/polygons.js'; import { space } from '../moto/space.js'; import { util } from './util.js'; diff --git a/web2/kiri/index.html b/web2/kiri/index.html index 78240eed..8519e823 100644 --- a/web2/kiri/index.html +++ b/web2/kiri/index.html @@ -23,6 +23,7 @@ +