update add, data, geo to use gapp.register()
This commit is contained in:
parent
19522665b2
commit
32e9ceca55
23 changed files with 504 additions and 489 deletions
2
app.js
2
app.js
|
|
@ -399,7 +399,7 @@ const script = {
|
|||
"kiri/tools",
|
||||
"kiri/frame",
|
||||
"@devices",
|
||||
"@icons"
|
||||
"@icons",
|
||||
],
|
||||
kiri_work : [
|
||||
"main/gapp",
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
// extend Array, String, Number, Math
|
||||
(function() {
|
||||
|
||||
gapp.register('add.array');
|
||||
gapp.register("add.array", [], (root, exports) => {
|
||||
|
||||
let AP = {};
|
||||
|
||||
|
|
@ -234,4 +232,4 @@ Number.prototype.round = function(digits) {
|
|||
return Math.round(this.valueOf() * pow) / pow;
|
||||
};
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
if (self.ArrayWriter) return;
|
||||
|
||||
gapp.register('add.class');
|
||||
gapp.register("add.class", [], (root, exports) => {
|
||||
|
||||
self.ArrayWriter = class ArrayWriter {
|
||||
constructor() {
|
||||
|
|
@ -174,4 +170,4 @@ self.DataReader = class DataReader {
|
|||
}
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
// dep: ext.three-svg
|
||||
gapp.register('add.three');
|
||||
gapp.register("add.three", [], (root, exports) => {
|
||||
|
||||
let MP = THREE.Mesh.prototype,
|
||||
XP = THREE.Box3.prototype,
|
||||
|
|
@ -129,4 +127,4 @@ THREE.Object3D.prototype.removeAll = function() {
|
|||
this.children = [];
|
||||
};
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
gapp.register("data.index", [], (root, exports) => {
|
||||
|
||||
gapp.register('data.index');
|
||||
|
||||
let data = self.data = self.data || {};
|
||||
if (data.Index) return;
|
||||
const { data } = root;
|
||||
|
||||
data.Index = IDBStore;
|
||||
|
||||
|
|
@ -322,4 +319,4 @@ SP.clear = function(key, store = this.current) {
|
|||
.objectStore(store).clear();
|
||||
};
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
gapp.register("data.local", [], (root, exports) => {
|
||||
|
||||
gapp.register('data.local');
|
||||
|
||||
let data = self.data = self.data || {};
|
||||
if (data.local) return;
|
||||
const { data } = root;
|
||||
|
||||
function Local() {
|
||||
this.__data__ = {};
|
||||
|
|
@ -47,4 +44,4 @@ try {
|
|||
// alert(msg);
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
gapp.register("geo.base", [], (root, exports) => {
|
||||
|
||||
if (self.base) return;
|
||||
|
||||
const base = self.base = {};
|
||||
const base = root.base = {};
|
||||
const round_decimal_precision = 5;
|
||||
|
||||
function time() {
|
||||
|
|
@ -580,4 +578,4 @@ base.util = {
|
|||
zInPlane
|
||||
};
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
"use strict";
|
||||
|
||||
// dep: geo.base
|
||||
(function() {
|
||||
gapp.register("geo.bounds", [], (root, exports) => {
|
||||
|
||||
let base = self.base;
|
||||
if (base.Bounds) return;
|
||||
|
||||
let { config, util } = base;
|
||||
const { base } = root;
|
||||
const { config, util } = base;
|
||||
|
||||
class Bounds {
|
||||
constructor() {
|
||||
|
|
@ -132,9 +130,12 @@ class Bounds {
|
|||
|
||||
centery() {
|
||||
return this.miny + this.height() / 2;
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
base.Bounds = Bounds;
|
||||
base.newBounds = function() { return new Bounds() };
|
||||
gapp.overlay(base, {
|
||||
Bounds,
|
||||
newBounds() { return new Bounds() }
|
||||
});
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
// dep: geo.base
|
||||
let base = self.base;
|
||||
if (base.CSG) return;
|
||||
gapp.register("geo.csg", [], (root, exports) => {
|
||||
|
||||
base.CSG = {
|
||||
const { base } = root;
|
||||
|
||||
const CSG = {
|
||||
|
||||
union() {
|
||||
return jscadModeling.booleans.union(...arguments);
|
||||
|
|
@ -52,4 +51,8 @@ base.CSG = {
|
|||
|
||||
};
|
||||
|
||||
})();
|
||||
gapp.overlay(base, {
|
||||
CSG
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
// dep: geo.base
|
||||
gapp.register("geo.gyroid", [], (root, exports) => {
|
||||
|
||||
if (self.base.gyroid) return;
|
||||
|
||||
const base = self.base;
|
||||
const { base } = root;
|
||||
const PI2 = Math.PI * 2;
|
||||
|
||||
let cache = {};
|
||||
|
|
@ -215,6 +214,8 @@ function distTo(a, b, dir) {
|
|||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
base.gyroid = { slice };
|
||||
gapp.overlay(base, {
|
||||
gyroid: { slice }
|
||||
})
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
// dep: geo.base
|
||||
gapp.register("geo.line", [], (root, exports) => {
|
||||
|
||||
if (self.base.Line) return;
|
||||
|
||||
const base = self.base;
|
||||
const { base } = root;
|
||||
|
||||
class Line {
|
||||
constructor(p1, p2, key) {
|
||||
|
|
@ -63,8 +62,10 @@ function newOrderedLine(p1, p2, key) {
|
|||
return p1.key < p2.key ? newLine(p1,p2,key) : newLine(p2,p1,key);
|
||||
}
|
||||
|
||||
base.Line = Line;
|
||||
base.newLine = newLine;
|
||||
base.newOrderedLine = newOrderedLine;
|
||||
gapp.overlay(base, {
|
||||
Line,
|
||||
newLine,
|
||||
newOrderedLine
|
||||
});
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,16 +2,13 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
// dep: geo.base
|
||||
gapp.register("geo.mesh", [], (root, exports) => {
|
||||
|
||||
const BASE = self.base = self.base || {};
|
||||
const { base } = root;
|
||||
const TEST = 0;
|
||||
|
||||
if (BASE.Mesh) {
|
||||
return;
|
||||
}
|
||||
|
||||
BASE.Mesh = class Mesh {
|
||||
class Mesh {
|
||||
constructor(params = {}) {
|
||||
this.precision = Math.pow(10, params.precision || 6);
|
||||
if (params.vertices) {
|
||||
|
|
@ -385,4 +382,6 @@
|
|||
}
|
||||
};
|
||||
|
||||
})();
|
||||
gapp.overlay(base, { Mesh });
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
"use strict";
|
||||
|
||||
// path & routing output utilities
|
||||
(function() {
|
||||
|
||||
const { base } = self;
|
||||
// dep: geo.base
|
||||
// dep: geo.point
|
||||
gapp.register("geo.paths", [], (root, exports) => {
|
||||
|
||||
const { base } = root;
|
||||
const { util, config, newPoint } = base;
|
||||
const { sqr, numOrDefault } = util;
|
||||
|
||||
|
|
@ -107,4 +110,4 @@ base.paths = {
|
|||
tip2tipEmit
|
||||
};
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
// dep: geo.base
|
||||
gapp.register("geo.point", [], (root, exports) => {
|
||||
|
||||
if (self.base.Point) return;
|
||||
|
||||
const base = self.base;
|
||||
const { base } = root;
|
||||
const { util, config, key } = base;
|
||||
const { round } = util;
|
||||
|
||||
|
|
@ -564,14 +563,19 @@ function p2l(p, l1, l2) {
|
|||
};
|
||||
return d(p, pb);
|
||||
}
|
||||
|
||||
function newPoint(x, y, z, key) {
|
||||
return new Point(x, y, z, key);
|
||||
}
|
||||
|
||||
base.Point = Point;
|
||||
base.newPoint = newPoint;
|
||||
base.pointFromClipper = function(cp, z) {
|
||||
function pointFromClipper(cp, z) {
|
||||
return newPoint(cp.X / config.clipper, cp.Y / config.clipper, z);
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
gapp.overlay(base, {
|
||||
Point,
|
||||
newPoint,
|
||||
pointFromClipper
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
// dep: geo.base
|
||||
// dep: geo.point
|
||||
gapp.register("geo.points", [], (root, exports) => {
|
||||
|
||||
const base = self.base;
|
||||
const { base } = root;
|
||||
const { config } = base;
|
||||
|
||||
base.verticesToPoints = verticesToPoints;
|
||||
base.pointsToVertices = pointsToVertices;
|
||||
gapp.overlay(base, {
|
||||
verticesToPoints,
|
||||
pointsToVertices
|
||||
});
|
||||
|
||||
/**
|
||||
* converts a geometry point array into a kiri point array
|
||||
|
|
@ -125,4 +129,4 @@ function pointsToVertices(points) {
|
|||
return vertices;
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
"use strict";
|
||||
|
||||
// dep: ext.clip2
|
||||
// dep: geo.point
|
||||
// dep: geo.bounds
|
||||
// dep: geo.polygons
|
||||
(function() {
|
||||
|
||||
const base = self.base;
|
||||
if (base.Polygon) return;
|
||||
// use: geo.polygons
|
||||
gapp.register("geo.polygon", [], (root, exports) => {
|
||||
|
||||
const { base } = root;
|
||||
const { config, util, polygons, newBounds, newPoint } = base;
|
||||
|
||||
const POLY = polygons,
|
||||
DEG2RAD = Math.PI / 180,
|
||||
clib = self.ClipperLib,
|
||||
|
|
@ -1804,11 +1804,13 @@ function newPolygon(points) {
|
|||
return new Polygon(points);
|
||||
}
|
||||
|
||||
base.Polygon = Polygon;
|
||||
base.newPolygon = newPolygon;
|
||||
|
||||
Polygon.fromArray = function(array) {
|
||||
return newPolygon().fromArray(array);
|
||||
};
|
||||
|
||||
})();
|
||||
gapp.overlay(base, {
|
||||
Polygon,
|
||||
newPolygon
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
const base = self.base;
|
||||
if (base.polygons) return;
|
||||
// dep: geo.base
|
||||
// dep: geo.point
|
||||
// use: geo.polygon
|
||||
gapp.register("base.polygons", [], (root, exports) => {
|
||||
|
||||
const { base } = root;
|
||||
const { util, config, newPoint } = base;
|
||||
const { sqr, numOrDefault } = util;
|
||||
|
||||
|
|
@ -954,4 +955,4 @@ function route(polys, start) {
|
|||
return routed.map(r => r.poly);
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@
|
|||
* basic slice and line connection. In future, replace kiri's fdm and cam slicers
|
||||
* with wrappers on this one.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
const base = self.base;
|
||||
if (base.slice) return;
|
||||
// dep: geo.base
|
||||
// dep: geo.line
|
||||
// dep: geo.point
|
||||
// dep: geo.polygon
|
||||
gapp.register("geo.slicer", [], (root, exports) => {
|
||||
|
||||
const { base } = root;
|
||||
const { config, util, polygons } = base
|
||||
const { newOrderedLine, newPolygon, newPoint } = base;
|
||||
|
||||
|
|
@ -819,8 +821,10 @@ function removeDuplicateLines(lines) {
|
|||
return output;
|
||||
}
|
||||
|
||||
base.slice = slice;
|
||||
base.sliceZ = sliceZ;
|
||||
base.slicePost = {};
|
||||
gapp.overlay(base, {
|
||||
slice,
|
||||
sliceZ,
|
||||
slicePost: {}
|
||||
});
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
|
||||
const base = self.base;
|
||||
if (base.Slope) return;
|
||||
// dep: geo.base
|
||||
// use: geo.line
|
||||
// use: geo.point
|
||||
gapp.register("geo.slope", [], (root, exports) => {
|
||||
|
||||
const { base } = root;
|
||||
const { config } = base;
|
||||
|
||||
const ABS = Math.abs,
|
||||
DEG2RAD = Math.PI / 180,
|
||||
RAD2DEG = 180 / Math.PI;
|
||||
|
|
@ -96,13 +98,17 @@ function newSlope(p1, p2, dx, dy) {
|
|||
return new Slope(p1, p2, dx, dy);
|
||||
}
|
||||
|
||||
base.Slope = Slope;
|
||||
base.newSlope = newSlope;
|
||||
base.newSlopeFromAngle = function(angle) {
|
||||
function newSlopeFromAngle(angle) {
|
||||
return newSlope(0,0,
|
||||
Math.cos(angle * DEG2RAD),
|
||||
Math.sin(angle * DEG2RAD)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
gapp.overlay(base, {
|
||||
Slope,
|
||||
newSlope,
|
||||
newSlopeFromAngle
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,10 +2,15 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
// only active in workers
|
||||
if (!self.window) (function() {
|
||||
// dep: geo.base
|
||||
// dep: ext.clip2
|
||||
gapp.register("geo.wasm", [], (root, exports) => {
|
||||
|
||||
if (!self.geo) self.geo = {
|
||||
const { base } = root;
|
||||
const { config } = base;
|
||||
|
||||
const factor = config.clipper;
|
||||
const wasm_ctrl = {
|
||||
enable,
|
||||
disable,
|
||||
count: {
|
||||
|
|
@ -15,8 +20,7 @@ if (!self.geo) self.geo = {
|
|||
}
|
||||
};
|
||||
|
||||
const factor = self.base.config.clipper;
|
||||
const geo = self.geo;
|
||||
gapp.overlay(base, { wasm_ctrl });
|
||||
|
||||
function log() {
|
||||
console.log(...arguments);
|
||||
|
|
@ -76,9 +80,9 @@ function readPolys(view, z, out = []) {
|
|||
}
|
||||
|
||||
function polyOffset(polys, offset, z, clean, simple) {
|
||||
geo.count.offset++;
|
||||
let wasm = geo.wasm,
|
||||
buffer = geo.wasm.shared,
|
||||
wasm_ctrl.count.offset++;
|
||||
let wasm = base.wasm,
|
||||
buffer = wasm.shared,
|
||||
pcount = writePolys(new DataWriter(wasm.heap, buffer), polys),
|
||||
resat = wasm.fn.offset(buffer, pcount, offset * factor, clean, simple),
|
||||
out = readPolys(new DataReader(wasm.heap, resat), z);
|
||||
|
|
@ -86,9 +90,9 @@ function polyOffset(polys, offset, z, clean, simple) {
|
|||
}
|
||||
|
||||
function polyUnion(polys, z) {
|
||||
geo.count.union++;
|
||||
let wasm = geo.wasm,
|
||||
buffer = geo.wasm.shared,
|
||||
wasm_ctrl.count.union++;
|
||||
let wasm = base.wasm,
|
||||
buffer = wasm.shared,
|
||||
pcount = writePolys(new DataWriter(wasm.heap, buffer), polys),
|
||||
resat = wasm.fn.union(buffer, pcount),
|
||||
out = readPolys(new DataReader(wasm.heap, resat), z);
|
||||
|
|
@ -96,13 +100,13 @@ function polyUnion(polys, z) {
|
|||
}
|
||||
|
||||
function polyDiff(polysA, polysB, z, AB, BA) {
|
||||
geo.count.diff++;
|
||||
let wasm = geo.wasm,
|
||||
buffer = geo.wasm.shared,
|
||||
wasm_ctrl.count.diff++;
|
||||
let wasm = base.wasm,
|
||||
buffer = wasm.shared,
|
||||
writer = new DataWriter(wasm.heap, buffer),
|
||||
pcountA = writePolys(writer, polysA),
|
||||
pcountB = writePolys(writer, polysB),
|
||||
resat = wasm.fn.diff(buffer, pcountA, pcountB, AB?1:0, BA?1:0, base.config.clipperClean),
|
||||
resat = wasm.fn.diff(buffer, pcountA, pcountB, AB?1:0, BA?1:0, config.clipperClean),
|
||||
reader = new DataReader(wasm.heap, resat);
|
||||
if (AB) {
|
||||
AB.appendAll(polyNest(readPolys(reader, z)));
|
||||
|
|
@ -141,7 +145,7 @@ function polyNest(polys) {
|
|||
}
|
||||
|
||||
function readString(pos, len) {
|
||||
let view = new DataReader(geo.wasm.heap, pos);
|
||||
let view = new DataReader(base.wasm.heap, pos);
|
||||
let out = [];
|
||||
while (len-- > 0) {
|
||||
out.push(String.fromCharCode(view.readU8()));
|
||||
|
|
@ -150,10 +154,10 @@ function readString(pos, len) {
|
|||
}
|
||||
|
||||
function enable() {
|
||||
if (geo.wasm || geo._wasm) {
|
||||
if (base.wasm || base._wasm) {
|
||||
return;
|
||||
}
|
||||
geo._wasm = 'loading';
|
||||
base._wasm = 'loading';
|
||||
fetch('/wasm/kiri-geo.wasm')
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(bytes => WebAssembly.instantiate(bytes, {
|
||||
|
|
@ -169,12 +173,12 @@ function enable() {
|
|||
}
|
||||
}))
|
||||
.then(results => {
|
||||
// console.log({enabled: geo.wasm});
|
||||
delete geo._wasm;
|
||||
// console.log({enabled: base.wasm});
|
||||
delete base._wasm;
|
||||
let { module, instance } = results;
|
||||
let { exports } = instance;
|
||||
let heap = new DataView(exports.memory.buffer);
|
||||
let wasm = geo.wasm = {
|
||||
let wasm = base.wasm = {
|
||||
heap,
|
||||
exports,
|
||||
memory: exports.memory,
|
||||
|
|
@ -197,10 +201,10 @@ function enable() {
|
|||
}
|
||||
|
||||
function disable() {
|
||||
if (geo.wasm) {
|
||||
delete geo.wasm;
|
||||
if (base.wasm) {
|
||||
delete base.wasm;
|
||||
// console.log({disabled: geo});
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -115,9 +115,9 @@ const funcs = {
|
|||
|
||||
wasm: data => {
|
||||
if (data.enable) {
|
||||
geo.enable();
|
||||
base.wasm_ctrl.enable();
|
||||
} else {
|
||||
geo.disable();
|
||||
base.wasm_ctrl.disable();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { base, kiri } = self;
|
||||
const { util, polygons } = base;
|
||||
const { util, polygons, wasm_ctrl } = base;
|
||||
const { codec } = kiri;
|
||||
const { time } = util;
|
||||
const POLY = polygons;
|
||||
|
|
@ -798,9 +798,9 @@ kiri.worker = {
|
|||
|
||||
wasm: function(data, send) {
|
||||
if (data.enable) {
|
||||
geo.enable();
|
||||
wasm_ctrl.enable();
|
||||
} else {
|
||||
geo.disable();
|
||||
wasm_ctrl.disable();
|
||||
}
|
||||
minwork.wasm(data.enable);
|
||||
send.done({ wasm: data });
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function () {
|
||||
gapp.register("main.kiri", [], (root) => {
|
||||
|
||||
if (!self.kiri) {
|
||||
let modfns = self.kirimod = [];
|
||||
const modfns = root.kirimod = [];
|
||||
|
||||
let kiri = self.kiri = {
|
||||
const kiri = root.kiri = {
|
||||
beta: 3303,
|
||||
driver: {}, // driver modules
|
||||
load(fn) {
|
||||
|
|
@ -20,6 +19,5 @@
|
|||
kiri.load = (modfn) => { modfn(api || kiri.api) };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue