move packer to kiri, mesh to own directory, normalize work/pool names
This commit is contained in:
parent
81f7a391c4
commit
7176ab0822
11 changed files with 56 additions and 24 deletions
16
app.js
16
app.js
|
|
@ -249,7 +249,6 @@ const script = {
|
|||
"moto/kv",
|
||||
"moto/ajax",
|
||||
"moto/ctrl",
|
||||
"moto/pack",
|
||||
"moto/space",
|
||||
"load/3mf",
|
||||
"load/obj",
|
||||
|
|
@ -261,6 +260,7 @@ const script = {
|
|||
"moto/idb",
|
||||
"kiri/ui",
|
||||
"kiri/do",
|
||||
"kiri/pack",
|
||||
"kiri/lang",
|
||||
"kiri/lang-en",
|
||||
"kiri/catalog",
|
||||
|
|
@ -290,7 +290,7 @@ const script = {
|
|||
"@devices",
|
||||
"@icons"
|
||||
],
|
||||
worker : [
|
||||
kiri_work : [
|
||||
"main/kiri",
|
||||
"ext/three",
|
||||
"ext/pngjs",
|
||||
|
|
@ -312,8 +312,8 @@ const script = {
|
|||
"geo/polygons",
|
||||
"geo/gyroid",
|
||||
"geo/mesh",
|
||||
"moto/pack",
|
||||
"moto/broker",
|
||||
// "moto/broker",
|
||||
"kiri/pack",
|
||||
"kiri/slice",
|
||||
"kiri/slicer",
|
||||
"kiri/slicer2",
|
||||
|
|
@ -342,7 +342,7 @@ const script = {
|
|||
"kiri/codec",
|
||||
"kiri/worker"
|
||||
],
|
||||
minion : [
|
||||
kiri_pool : [
|
||||
"main/kiri",
|
||||
"moto/license",
|
||||
"ext/clip2",
|
||||
|
|
@ -422,7 +422,7 @@ const script = {
|
|||
"load/url",
|
||||
"load/file",
|
||||
"moto/idb",
|
||||
"main/mesh-ui"
|
||||
"main/mesh"
|
||||
],
|
||||
mesh_work : [
|
||||
"moto/client",
|
||||
|
|
@ -446,12 +446,12 @@ const script = {
|
|||
"geo/mesh",
|
||||
"moto/broker",
|
||||
"moto/idb",
|
||||
"main/mesh-work"
|
||||
"mesh/work"
|
||||
],
|
||||
mesh_pool : [
|
||||
"moto/worker",
|
||||
"moto/license",
|
||||
"main/mesh-pool"
|
||||
"mesh/pool"
|
||||
]
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ KIRI.work = {
|
|||
if (self.createWorker) {
|
||||
return self.createWorker();
|
||||
} else {
|
||||
return new Worker(`/code/worker.js?${self.kiri.version}`);
|
||||
return new Worker(`/code/kiri_work.js?${self.kiri.version}`);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -2260,12 +2260,12 @@
|
|||
mp = [sz.x, sz.y],
|
||||
ms = [mp[0] / 2, mp[1] / 2],
|
||||
c = Widget.Groups.blocks().sort(MOTO.Sort),
|
||||
p = new MOTO.Pack(ms[0], ms[1], gap).fit(c);
|
||||
p = new KIRI.Pack(ms[0], ms[1], gap).fit(c);
|
||||
|
||||
while (!p.packed) {
|
||||
ms[0] *= 1.1;
|
||||
ms[1] *= 1.1;
|
||||
p = new MOTO.Pack(ms[0], ms[1], gap).fit(c);
|
||||
p = new KIRI.Pack(ms[0], ms[1], gap).fit(c);
|
||||
}
|
||||
|
||||
for (i = 0; i < c.length; i++) {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@
|
|||
|
||||
(function () {
|
||||
|
||||
let moto = self.moto = self.moto || {};
|
||||
if (moto.Pack) return;
|
||||
let kiri = self.kiri = self.kiri || {};
|
||||
if (kiri.Pack) return;
|
||||
|
||||
moto.Pack = Packer;
|
||||
moto.Sort = function (a, b) {
|
||||
kiri.Pack = Packer;
|
||||
|
||||
kiri.Sort = function (a, b) {
|
||||
let aa = (a.w * a.h);
|
||||
let ab = (b.w * b.h);
|
||||
if (Math.abs(aa-ab) < 1) {
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
}
|
||||
};
|
||||
|
||||
function Packer (w, h, spacing) {
|
||||
function Packer(w, h, spacing) {
|
||||
this.root = { x: 0, y: 0, w: w, h: h };
|
||||
this.max = { w: 0, h: 0 };
|
||||
this.packed = false;
|
||||
|
|
@ -40,11 +40,11 @@ if (concurrent) {
|
|||
}
|
||||
|
||||
for (let i=0; i < concurrent; i++) {
|
||||
let minion = new Worker(`/code/minion.js?${self.kiri.version}`);
|
||||
let minion = new Worker(`/code/kiri_pool.js?${self.kiri.version}`);
|
||||
minion.onmessage = minhandler;
|
||||
minions.push(minion);
|
||||
}
|
||||
console.log(`kiri | init mini | ${KIRI.version || "rogue"} | ${concurrent + 1}`);
|
||||
console.log(`kiri | init pool | ${KIRI.version || "rogue"} | ${concurrent + 1}`);
|
||||
}
|
||||
|
||||
// for concurrent operations
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ function load_data(data, file, ext) {
|
|||
|
||||
function load_file(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!file) {
|
||||
return reject('invalid or missing file');
|
||||
}
|
||||
let reader = new FileReader();
|
||||
let name = file.name;
|
||||
let ext = name.toLowerCase().split('.').pop();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ function $h(id, h) {
|
|||
$(id).innerHTML = h;
|
||||
}
|
||||
|
||||
function estop(evt) {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
}
|
||||
|
||||
(function() {
|
||||
|
||||
let DOC = document,
|
||||
|
|
@ -27,7 +32,8 @@ function init() {
|
|||
zoomrev = true,
|
||||
zoomspd = 1,
|
||||
space = moto.Space,
|
||||
platform = space.platform;
|
||||
platform = space.platform,
|
||||
platcolor = 0x00ff00;
|
||||
|
||||
// setup default workspace
|
||||
space.sky.set({
|
||||
|
|
@ -49,6 +55,27 @@ function init() {
|
|||
space.view.setZoom(zoomrev, zoomspd);
|
||||
space.useDefaultKeys(true);
|
||||
|
||||
// add file drop handler
|
||||
space.event.addHandlers(self, [
|
||||
'drop', (evt) => {
|
||||
estop(evt);
|
||||
platform.setColor(platcolor);
|
||||
load.File.load(evt.dataTransfer.files[0])
|
||||
.then(data => {
|
||||
console.log({data});
|
||||
})
|
||||
},
|
||||
'dragover', (evt) => {
|
||||
estop(evt);
|
||||
evt.dataTransfer.dropEffect = 'copy';
|
||||
let color = platform.setColor(0x00ff00);
|
||||
if (color !== 0x00ff00) platcolor = color;
|
||||
},
|
||||
'dragleave', (evt) => {
|
||||
platform.setColor(platcolor);
|
||||
}
|
||||
]);
|
||||
|
||||
// start worker
|
||||
moto.client.start(`/code/mesh_work?${gapp.version}`);
|
||||
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
if (!self.kiri.driver) self.kiri.driver = { };
|
||||
if (self.kiri.driver.LASER) return;
|
||||
|
||||
const KIRI = self.kiri,
|
||||
let KIRI = self.kiri,
|
||||
BASE = self.base,
|
||||
UTIL = BASE.util,
|
||||
POLY = BASE.polygons,
|
||||
|
|
@ -295,19 +295,18 @@
|
|||
|
||||
// do object layout packing
|
||||
let i, m, e,
|
||||
MOTO = self.moto,
|
||||
dw = device.bedWidth / 2,
|
||||
dh = device.bedDepth / 2,
|
||||
sort = !process.outputLaserLayer,
|
||||
// sort objects by size when not using laser layer ordering
|
||||
c = sort ? output.sort(MOTO.Sort) : output,
|
||||
p = new MOTO.Pack(dw, dh, process.outputTileSpacing).fit(c, !sort);
|
||||
c = sort ? output.sort(KIRI.Sort) : output,
|
||||
p = new KIRI.Pack(dw, dh, process.outputTileSpacing).fit(c, !sort);
|
||||
|
||||
// test different ratios until packed
|
||||
while (!p.packed) {
|
||||
dw *= 1.1;
|
||||
dh *= 1.1;
|
||||
p = new MOTO.Pack(dw, dh, process.outputTileSpacing).fit(c ,!sort);
|
||||
p = new KIRI.Pack(dw, dh, process.outputTileSpacing).fit(c ,!sort);
|
||||
}
|
||||
|
||||
for (i = 0; i < c.length; i++) {
|
||||
|
|
|
|||
|
|
@ -1182,6 +1182,8 @@
|
|||
requestAnimationFrame(animate);
|
||||
if (docVisible && !freeze && Date.now() - lastAction < 1500) {
|
||||
renderer.render(SCENE, camera);
|
||||
} else {
|
||||
fps = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue