From 3ba4e3c5ecb97ee676df03201ab3addcf0475a2b Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 14 Jun 2025 11:11:20 -0400 Subject: [PATCH] more missing code, module adaptations --- src2/add/class.js | 6 +- src2/add/three.js | 2 +- src2/geo/base.js | 3 +- src2/geo/csg.js | 6 +- src2/geo/polygons.js | 3 +- src2/geo/slicer.js | 33 ++++------- src2/main/mesh.js | 4 +- src2/main/service.js | 3 +- src2/mesh/api.js | 2 +- src2/mesh/build.js | 3 +- src2/mesh/object.js | 2 +- src2/mesh/util.js | 3 +- src2/mesh/work.js | 135 ++++++++++++++++++++++++++++++++++++------- src2/moto/client.js | 9 ++- src2/moto/license.js | 1 + src2/moto/service.js | 3 +- src2/moto/space.js | 36 ++++++------ 17 files changed, 172 insertions(+), 82 deletions(-) diff --git a/src2/add/class.js b/src2/add/class.js index 1314b07a..7d3b0ad6 100644 --- a/src2/add/class.js +++ b/src2/add/class.js @@ -170,9 +170,9 @@ class DataReader { } } -window.ArrayWriter = ArrayWriter; -window.DataWriter = DataWriter; -window.DataReader = DataReader; +self.ArrayWriter = ArrayWriter; +self.DataWriter = DataWriter; +self.DataReader = DataReader; // Export for ES modules export { ArrayWriter, DataWriter, DataReader }; diff --git a/src2/add/three.js b/src2/add/three.js index d090176b..889c119c 100644 --- a/src2/add/three.js +++ b/src2/add/three.js @@ -7,7 +7,7 @@ import { LineSegmentsGeometry, MeshBVHLib } from '../ext/three.js'; // Make THREE available globally -window.THREE = THREE; +self.THREE = THREE; THREE.BufferGeometryUtils = BufferGeometryUtils; THREE.SVGLoader = SVGLoader.SVGLoader; THREE.LineMaterial = LineMaterial; diff --git a/src2/geo/base.js b/src2/geo/base.js index b604786b..e0b3ad99 100644 --- a/src2/geo/base.js +++ b/src2/geo/base.js @@ -843,10 +843,9 @@ function v2pr(rec) { return p; } -const earcut = window.earcut; +const earcut = self.earcut; // Export the base object and its properties export { base }; export { earcut }; export const { config, key, util, paths } = base; -export { newPoint }; diff --git a/src2/geo/csg.js b/src2/geo/csg.js index f5541133..94ea78a4 100644 --- a/src2/geo/csg.js +++ b/src2/geo/csg.js @@ -12,11 +12,7 @@ const precision = 0.001; const factor = 1/precision; function log() { - if (root?.mesh?.log) { - root.mesh.log(...arguments) - } else if (root.debug === true) { - console.log(...arguments); - } + console.log(...arguments); } export const CSG = { diff --git a/src2/geo/polygons.js b/src2/geo/polygons.js index 3895a8e0..3cbe35b3 100644 --- a/src2/geo/polygons.js +++ b/src2/geo/polygons.js @@ -2,7 +2,8 @@ "use strict"; -import { base, util, paths, config, newPoint } from './base.js'; +import { base, util, paths, config } from './base.js'; +import { newPoint } from './point.js'; import { ClipperLib } from '../ext/clip2.esm.js'; const { sqr, numOrDefault } = util; diff --git a/src2/geo/slicer.js b/src2/geo/slicer.js index 37f7db6a..683d0f1d 100644 --- a/src2/geo/slicer.js +++ b/src2/geo/slicer.js @@ -1,23 +1,15 @@ /** Copyright Stewart Allen -- All Rights Reserved */ -"use strict"; - /** * basic slice and line connection. In future, replace kiri's fdm and cam slicers * with wrappers on this one. */ -// dep: geo.base -// dep: geo.line -// dep: geo.point -// dep: geo.polygon -// dep: geo.polygons -import { newPolygon, newPoint, newOrderedLine } from '../geo/polygon.js'; -gapp.register("geo.slicer", [], (root, exports) => { - -const { base } = root; -const { config, util, polygons } = base - -const POLY = base.polygons; +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) { return v !== undefined ? v : dv; @@ -32,7 +24,7 @@ function dval(v, dv) { * @param {Point[]} points vertex array * @param {Object} options slicing parameters */ -async function slice(points, options = {}) { +export async function slice(points, options = {}) { let zMin = options.zMin || 0, zMax = options.zMax || 0, zInc = options.zInc || 0, @@ -322,7 +314,7 @@ function makeZLine(phash, p1, p2, coplanar, edge) { * * @param {number} z */ -async function sliceZ(z, points, options = {}) { +export async function sliceZ(z, points, options = {}) { if (Array.isArray(z)) { return Promise.all(z.map(z => sliceZ(z, points, options))); } @@ -458,7 +450,7 @@ async function sliceZ(z, points, options = {}) { * @param {number} [index] * @returns {Array} */ -function sliceConnect(input, z, opt = {}) { +export function sliceConnect(input, z, opt = {}) { let { debug, both } = opt; if (both) { @@ -782,7 +774,7 @@ function sliceConnect(input, z, opt = {}) { * @param {Line[]} lines * @returns {Line[]} */ -function removeDuplicateLines(lines) { +export function removeDuplicateLines(lines) { let output = [], tmplines = [], points = [], @@ -873,12 +865,11 @@ function removeDuplicateLines(lines) { return output; } -gapp.overlay(base, { +export const slicer = { slice, sliceZ, slicePost: {}, sliceDedup: removeDuplicateLines, sliceConnect -}); +} -}); diff --git a/src2/main/mesh.js b/src2/main/mesh.js index 7ccc2d89..1a75109e 100644 --- a/src2/main/mesh.js +++ b/src2/main/mesh.js @@ -1,5 +1,7 @@ /** Copyright Stewart Allen -- All Rights Reserved */ +// import '../mesh/work.js'; + import '../add/array.js'; import '../add/class.js'; import '../add/three.js'; @@ -77,7 +79,7 @@ function init() { motoClient.on('ready', restore_space); // start worker - motoClient.start(`/code/mesh_work?${version}`); + motoClient.start(`/v2/lib/mesh/work.js?${version}`); // trigger space event binding call.space_init({ space: motoSpace, platform }); diff --git a/src2/main/service.js b/src2/main/service.js index a3ee1949..6d8af693 100644 --- a/src2/main/service.js +++ b/src2/main/service.js @@ -1,9 +1,8 @@ const service_worker = navigator.serviceWorker; -import { license } from '../moto/license.js'; +import { version } from '../moto/license.js'; async function start_service_worker() { - const version = license.version; function debug() { console.log(`[${version}]`, ...arguments); } diff --git a/src2/mesh/api.js b/src2/mesh/api.js index 85d6430c..76d14277 100644 --- a/src2/mesh/api.js +++ b/src2/mesh/api.js @@ -1614,7 +1614,7 @@ broker.wrapObject(model, 'model'); broker.wrapObject(group, 'group'); // optimize db writes by merging updates -prefs.save = meshUtil.deferWrap(prefs.save, 100); +// prefs.save = meshUtil.deferWrap(prefs.save, 100); export { selection, diff --git a/src2/mesh/build.js b/src2/mesh/build.js index 9dd7bcf7..d474dc8b 100644 --- a/src2/mesh/build.js +++ b/src2/mesh/build.js @@ -7,6 +7,7 @@ import { util } from './util.js'; import { space } from '../moto/space.js'; import { split } from './split.js'; import { newPolygon } from '../geo/polygon.js'; +import { version } from '../moto/license.js'; const { div, label, input, hr } = h; const { dbug } = api; @@ -525,7 +526,7 @@ function ui_build() { div({ class: "menu" }, [ div('Help'), div({ class: "menu-items" }, [ - menu_item('About', () => { api.welcome(license.version) }), + menu_item('About', () => { api.welcome(version) }), hr(), menu_item('Documentation', api.help), menu_item('Report Bugs', api.bugs), diff --git a/src2/mesh/object.js b/src2/mesh/object.js index bea6d5e0..c81bc123 100644 --- a/src2/mesh/object.js +++ b/src2/mesh/object.js @@ -1,13 +1,13 @@ /** Copyright Stewart Allen -- All Rights Reserved */ import { THREE } from '../ext/three.js'; -const { Matrix4, Vector3, Box3, Box3Helper, Quaternion } = THREE; import { broker as motoBroker } from '../moto/broker.js'; import { client as motoClient } from '../moto/client.js'; import { space as motoSpace } from '../moto/space.js'; import { api as meshApi } from './api.js'; import { util as meshUtil } from './util.js'; +const { Matrix4, Vector3, Box3, Box3Helper, Quaternion } = THREE; const worker = motoClient.fn; const lookUp = new Vector3(0,0,-1); diff --git a/src2/mesh/util.js b/src2/mesh/util.js index 6a543315..58aa341c 100644 --- a/src2/mesh/util.js +++ b/src2/mesh/util.js @@ -1,11 +1,10 @@ /** Copyright Stewart Allen -- All Rights Reserved */ import { THREE } from '../ext/three.js'; -const { Matrix4, Matrix3, Vector3, Box3, LineSegments, BufferGeometry, Float32BufferAttribute, LineBasicMaterial } = THREE; -import { license as motoLicense } from '../moto/license.js'; import { api as meshApi } from './api.js'; import { object as meshObject } from './object.js'; +const { Matrix4, Matrix3, Vector3, Box3, LineSegments, BufferGeometry, Float32BufferAttribute, LineBasicMaterial } = THREE; const deferFn = []; const boundsCache = {}; diff --git a/src2/mesh/work.js b/src2/mesh/work.js index d2fdf6fb..663aa7e4 100644 --- a/src2/mesh/work.js +++ b/src2/mesh/work.js @@ -1,23 +1,21 @@ /** Copyright Stewart Allen -- All Rights Reserved */ -import { THREE } from '../ext/three.js'; -const { Triangle, Vector3, BufferGeometry, BufferAttribute, computeFaceNormal } = THREE; -import { license as motoLicense } from '../moto/license.js'; +import "../ext/earcut.js"; +import '../add/array.js'; +import '../add/class.js'; +import '../add/three.js'; +import { version } from '../moto/license.js'; import { client as motoClient } from '../moto/client.js'; -import { worker as motoWorker } from '../moto/worker.js'; -import { util as meshUtil } from './util.js'; +import { worker } from '../moto/worker.js'; +import { sliceConnect } from '../geo/slicer.js'; +import { newPolygon } from '../geo/polygon.js'; +import { polygons } from '../geo/polygons.js'; +import { CSG } from '../geo/csg.js'; +import { util } from './util.js'; import { tool as meshTool } from './tool.js'; -import { CSG, newPoint, newPolygon, sliceConnect, polygons } from '../geo/base.js'; -import { line as geoLine } from '../geo/line.js'; -import { point as geoPoint } from '../geo/point.js'; -import { polygon as geoPolygon } from '../geo/polygon.js'; -import { polygons as geoPolygons } from '../geo/polygons.js'; -import { bounds as geoBounds } from '../geo/bounds.js'; -import { slicer as geoSlicer } from '../geo/slicer.js'; -import { csg as geoCsg } from '../geo/csg.js'; -import { broker } from '../moto/broker.js'; -import { api } from './api.js'; -import { model } from './model.js'; +import { THREE } from '../ext/three.js'; + +const { Triangle, Vector3, BufferGeometry, BufferAttribute, computeFaceNormal } = THREE; const cache = {}; @@ -25,7 +23,7 @@ const cache = {}; const work = { cache }; // start worker pool (disabled for now with *0) -motoClient.start(`/code/mesh_pool?${license.version}`, motoClient.max() * 0); +motoClient.start(`/v2/lib/mesh/pool.js?${version}`, motoClient.max() * 0); function log(msg) { return motoWorker.publish("mesh.log", msg); @@ -444,9 +442,9 @@ const model = { const zh = height || 15; const verts = poly.extrude(zh, { chamfer }); if (twist) { - const rad = base.util.toRadians(twist); + const rad = util.toRadians(twist); for (let i=0; i v.round(5)); + vtot += (vs.length / 3); + } + switch (format) { + case "obj": + let p = 1; + let obj = [header]; + for (let rec of recs) { + let { file, varr } = rec; + obj.push(`g ${file}`); + for (let i=0; i { + dat.setUint8(i, c.charCodeAt(0)); + }); + // todo put Mesh:Tool info in header + dat.setInt32(80, vtot/3, true); + for (let rec of recs) { + let { id, matrix, file, varr } = rec; + for (let i=0, l=varr.length; i { - docVisible = DOC[hiddenKey] ? false : true; -}, false); + DOC.addEventListener(vizChange, () => { + docVisible = DOC[hiddenKey] ? false : true; + }, false); +} function updateLastAction() { lastAction = Date.now(); @@ -172,7 +174,7 @@ WORLD.contains = (obj) => { ******************************************************************* */ function tweenit() { - TWEEN.update(); + self.TWEEN?.update(); setTimeout(tweenit, tweenDelay); }