add round bed support. split worker/work code
This commit is contained in:
parent
7c45ec041e
commit
05d7ee88fd
11 changed files with 455 additions and 391 deletions
|
|
@ -65,6 +65,8 @@ var gs_kiri_lang = exports;
|
||||||
dev_orgc_desc: "bed origin center",
|
dev_orgc_desc: "bed origin center",
|
||||||
dev_orgt: "origin top",
|
dev_orgt: "origin top",
|
||||||
dev_orgt_desc: "part z origin top",
|
dev_orgt_desc: "part z origin top",
|
||||||
|
dev_bedc: "circular bed",
|
||||||
|
dev_bedc_desc: "device bed is circular",
|
||||||
dev_fanp: "fan power",
|
dev_fanp: "fan power",
|
||||||
dev_fanp_desc: "set cooling fan power",
|
dev_fanp_desc: "set cooling fan power",
|
||||||
dev_prog: "progress",
|
dev_prog: "progress",
|
||||||
|
|
|
||||||
466
js/kiri-work.js
466
js/kiri-work.js
|
|
@ -1,339 +1,141 @@
|
||||||
/** Copyright 2014-2019 Stewart Allen -- All Rights Reserved */
|
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
if (self.window) {
|
// this code runs in kiri's main loop
|
||||||
|
if (!self.kiri) self.kiri = {};
|
||||||
|
|
||||||
if (!self.kiri) self.kiri = {};
|
let loc = self.location,
|
||||||
|
host = loc.hostname,
|
||||||
|
port = loc.port,
|
||||||
|
proto = loc.protocol,
|
||||||
|
pre = host.indexOf(".space") > 0 || host === "localhost" ?
|
||||||
|
proto + "//" + host + ":" + port : "",
|
||||||
|
time = function() { return new Date().getTime() },
|
||||||
|
KIRI = self.kiri,
|
||||||
|
BASE = self.base,
|
||||||
|
seqid = 1,
|
||||||
|
running = {},
|
||||||
|
slicing = {},
|
||||||
|
worker = null;
|
||||||
|
|
||||||
var loc = self.location,
|
// new moto.Ajax(function(body) {
|
||||||
host = loc.hostname,
|
// console.log({body:body});
|
||||||
port = loc.port,
|
// let blob = new Blob([body], {type : 'application/json'});
|
||||||
proto = loc.protocol,
|
// worker = new Worker(URL.createObjectURL(blob));
|
||||||
pre = host.indexOf(".space") > 0 || host === "localhost" ?
|
// }).request(pre + "/code/worker.js/");
|
||||||
proto + "//" + host + ":" + port :
|
|
||||||
"",
|
|
||||||
time = function() { return new Date().getTime() },
|
|
||||||
KIRI = self.kiri,
|
|
||||||
BASE = self.base,
|
|
||||||
seqid = 1,
|
|
||||||
running = {},
|
|
||||||
slicing = {},
|
|
||||||
worker = null;
|
|
||||||
|
|
||||||
// new moto.Ajax(function(body) {
|
function send(fn, data, onreply, async, zerocopy) {
|
||||||
// console.log({body:body});
|
let seq = seqid++;
|
||||||
// var blob = new Blob([body], {type : 'application/json'});
|
|
||||||
// worker = new Worker(URL.createObjectURL(blob));
|
|
||||||
// }).request(pre + "/code/worker.js/");
|
|
||||||
|
|
||||||
function send(fn, data, onreply, async, zerocopy) {
|
running[seq] = {fn:onreply, async:async||false};
|
||||||
var seq = seqid++;
|
|
||||||
|
|
||||||
running[seq] = {fn:onreply, async:async||false};
|
|
||||||
|
|
||||||
worker.postMessage({
|
|
||||||
seq: seq,
|
|
||||||
task: fn,
|
|
||||||
time: time(),
|
|
||||||
data: data
|
|
||||||
}, zerocopy);
|
|
||||||
}
|
|
||||||
|
|
||||||
KIRI.work = {
|
|
||||||
isSlicing : function() {
|
|
||||||
var current = 0;
|
|
||||||
for (var key in slicing) { current++ }
|
|
||||||
return current > 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
restart : function() {
|
|
||||||
if (worker) worker.terminate();
|
|
||||||
|
|
||||||
for (var key in slicing) {
|
|
||||||
slicing[key]({error: "cancelled slicing"});
|
|
||||||
}
|
|
||||||
slicing = {};
|
|
||||||
running = {};
|
|
||||||
|
|
||||||
worker = new Worker(pre + "/code/worker.js/" + exports.VERSION);
|
|
||||||
|
|
||||||
worker.onmessage = function(e) {
|
|
||||||
var now = time(),
|
|
||||||
reply = e.data,
|
|
||||||
record = running[reply.seq],
|
|
||||||
onreply = record.fn;
|
|
||||||
|
|
||||||
if (reply.done) delete running[reply.seq];
|
|
||||||
|
|
||||||
// calculate and replace recv time
|
|
||||||
reply.time_recv = now - reply.time_recv;
|
|
||||||
|
|
||||||
onreply(reply.data, reply);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
decimate : function(vertices, callback) {
|
|
||||||
var vertices = vertices.buffer.slice(0);
|
|
||||||
send("decimate", vertices, function(output) {
|
|
||||||
callback(output);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
clear : function(widget) {
|
|
||||||
send("clear", widget ? {id:widget.id} : {}, function(reply) {
|
|
||||||
// console.log({clear:reply});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
slice : function(settings, widget, callback) {
|
|
||||||
var vertices = widget.getGeoVertices().buffer.slice(0);
|
|
||||||
slicing[widget.id] = callback;
|
|
||||||
send("slice", {
|
|
||||||
id: widget.id,
|
|
||||||
settings: settings,
|
|
||||||
vertices: vertices,
|
|
||||||
position: widget.mesh.position
|
|
||||||
}, function(reply) {
|
|
||||||
if (reply.done || reply.error) delete slicing[widget.id];
|
|
||||||
callback(reply);
|
|
||||||
}, null, [vertices]);
|
|
||||||
},
|
|
||||||
|
|
||||||
printSetup : function(settings, callback) {
|
|
||||||
send("printSetup", {settings:settings}, function(reply) {
|
|
||||||
callback(reply);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
printGCode : function(callback) {
|
|
||||||
var gcode = [],
|
|
||||||
start = BASE.util.time();
|
|
||||||
send("printGCode", {}, function(reply) {
|
|
||||||
if (reply.line) {
|
|
||||||
gcode.push(reply.line);
|
|
||||||
} else {
|
|
||||||
if (!reply.gcode) reply.gcode = gcode.join("\n");
|
|
||||||
// console.log({printGCode:(BASE.util.time() - start)});
|
|
||||||
callback(reply);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
sliceToGCode : function(settings, vertices, callback) {
|
|
||||||
var wid = new Date().toString(36);
|
|
||||||
var vertices = widget.getGeoVertices().buffer.slice(0);
|
|
||||||
send("slice", {settings:settings, id:wiwd, vertices:vertices, position:{x:0,y:0,z:0}}, function(reply) {
|
|
||||||
send("printSetup", {settings:settings}, function(reply) {
|
|
||||||
send("printGCode", {}, function(reply) {
|
|
||||||
callback(reply);
|
|
||||||
});
|
|
||||||
}, null, [vertices]);
|
|
||||||
callback(reply);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// start first worker
|
|
||||||
KIRI.work.restart();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
module = { exports: {} };
|
|
||||||
|
|
||||||
var loc = self.location,
|
|
||||||
host = loc.hostname,
|
|
||||||
ver = exports.VERSION,
|
|
||||||
time = function() { return new Date().getTime() };
|
|
||||||
|
|
||||||
console.log("kiri | init work | " + ver);
|
|
||||||
|
|
||||||
// when running the server in 'web' mode, the obfuscated code is served as a
|
|
||||||
// unified ball via /code/work.js -- otherwise, map "localhost" to "debug"
|
|
||||||
// to debug unobfuscated code. if not, /js/ paths will 404.
|
|
||||||
if (host !== 'grid.space' && host !== 'debug') {
|
|
||||||
try {
|
|
||||||
[
|
|
||||||
"license","ext-n3d","ext-clip","add-array",
|
|
||||||
"add-three","geo","geo-point","geo-debug","geo-bounds",
|
|
||||||
"geo-line","geo-slope","geo-polygon","geo-polygons","geo-gyroid",
|
|
||||||
"kiri-fill","kiri-slice","kiri-slicer","kiri-driver-fdm","kiri-driver-cam",
|
|
||||||
"kiri-driver-laser","kiri-widget","kiri-pack","kiri-print","kiri-codec"
|
|
||||||
].forEach(function(scr) {
|
|
||||||
importScripts(["/js/",scr,".js","/v"+ver].join(''));
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.log("unable to load worker scripts. kiri is likely in debug mode.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
importScripts("/code/work.js/"+ver);
|
|
||||||
base.debug.disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
var base = self.base,
|
|
||||||
moto = self.moto,
|
|
||||||
dbug = base.debug,
|
|
||||||
util = base.util,
|
|
||||||
kiri = self.kiri,
|
|
||||||
Widget = kiri.Widget,
|
|
||||||
currentPrint,
|
|
||||||
cache = {};
|
|
||||||
|
|
||||||
var dispatch = {
|
|
||||||
decimate: function(vertices, send) {
|
|
||||||
vertices = new Float32Array(vertices),
|
|
||||||
vertices = Widget.pointsToVertices(Widget.verticesToPoints(vertices, true));
|
|
||||||
send.done(vertices);
|
|
||||||
},
|
|
||||||
|
|
||||||
slice: function(data, send) {
|
|
||||||
var settings = data.settings,
|
|
||||||
vertices = new Float32Array(data.vertices),
|
|
||||||
position = data.position,
|
|
||||||
points = Widget.verticesToPoints(vertices);
|
|
||||||
|
|
||||||
send.data({update:0.05, updateStatus:"slicing"});
|
|
||||||
|
|
||||||
var widget = kiri.newWidget(data.id).setPoints(points),
|
|
||||||
last = util.time(),
|
|
||||||
now;
|
|
||||||
|
|
||||||
// do it here so cancel can work
|
|
||||||
cache[data.id] = widget;
|
|
||||||
|
|
||||||
// fake mesh object to satisfy printing
|
|
||||||
widget.mesh = {
|
|
||||||
widget: widget,
|
|
||||||
position: position
|
|
||||||
};
|
|
||||||
|
|
||||||
widget.slice(settings, function(error) {
|
|
||||||
if (error) {
|
|
||||||
delete cache[data.id];
|
|
||||||
send.data({error: error});
|
|
||||||
} else {
|
|
||||||
var slices = widget.slices || [];
|
|
||||||
send.data({send_start: time()});
|
|
||||||
send.data({
|
|
||||||
topo: settings.synth.sendTopo ? widget.topo : null,
|
|
||||||
stats: widget.stats,
|
|
||||||
slices: slices.length
|
|
||||||
});
|
|
||||||
slices.forEach(function(slice,index) {
|
|
||||||
send.data({index: index, slice: slice.encode()});
|
|
||||||
})
|
|
||||||
send.data({send_end: time()});
|
|
||||||
}
|
|
||||||
send.done({done: true});
|
|
||||||
// cache results for future printing
|
|
||||||
// cache[data.id] = widget;
|
|
||||||
}, function(update, msg) {
|
|
||||||
now = util.time();
|
|
||||||
if (now - last < 10 && update < 0.99) return;
|
|
||||||
// on update
|
|
||||||
send.data({update: (0.05 + update * 0.95), updateStatus: msg});
|
|
||||||
last = now;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
printSetup: function(data, send) {
|
|
||||||
var widgets = [], key;
|
|
||||||
for (key in cache) {
|
|
||||||
if (cache.hasOwnProperty(key)) widgets.push(cache[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
send.data({update:0.05, updateStatus:"preview"});
|
|
||||||
|
|
||||||
currentPrint = kiri.newPrint(data.settings, widgets, data.id);
|
|
||||||
currentPrint.setup(false, function(update, msg) {
|
|
||||||
send.data({
|
|
||||||
update: update,
|
|
||||||
updateStatus: msg
|
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
send.done({
|
|
||||||
done: true,
|
|
||||||
output: currentPrint.encodeOutput()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
printGCode: function(data, send) {
|
|
||||||
currentPrint.exportGCode(false, function(gcode) {
|
|
||||||
send.done({
|
|
||||||
gcode: gcode,
|
|
||||||
lines: currentPrint.lines,
|
|
||||||
bytes: currentPrint.bytes,
|
|
||||||
bounds: currentPrint.bounds,
|
|
||||||
distance: currentPrint.distance,
|
|
||||||
time: currentPrint.time
|
|
||||||
});
|
|
||||||
}, function(line) {
|
|
||||||
send.data({line:line});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
clear: function(data, send) {
|
|
||||||
if (!data.id) {
|
|
||||||
cache = {};
|
|
||||||
currentPrint = null;
|
|
||||||
send.done({ clear: true });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var had = cache[data.id] !== undefined;
|
|
||||||
delete cache[data.id];
|
|
||||||
send.done({
|
|
||||||
id: data.id,
|
|
||||||
had: had,
|
|
||||||
has: cache[data.id] !== undefined
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
self.onmessage = function(e) {
|
|
||||||
var time_recv = util.time(),
|
|
||||||
msg = e.data,
|
|
||||||
run = dispatch[msg.task],
|
|
||||||
send = {
|
|
||||||
data : function(data,direct) {
|
|
||||||
self.postMessage({
|
|
||||||
seq: msg.seq,
|
|
||||||
task: msg.task,
|
|
||||||
done: false,
|
|
||||||
data: data
|
|
||||||
},direct);
|
|
||||||
},
|
|
||||||
done : function(data,direct) {
|
|
||||||
self.postMessage({
|
|
||||||
seq: msg.seq,
|
|
||||||
task: msg.task,
|
|
||||||
done: true,
|
|
||||||
data: data
|
|
||||||
},direct);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (run) {
|
|
||||||
var time_xfer = (time_recv - msg.time),
|
|
||||||
output = run(msg.data, send),
|
|
||||||
time_send = util.time(),
|
|
||||||
time_proc = time_send - time_recv;
|
|
||||||
|
|
||||||
if (output) self.postMessage({
|
|
||||||
seq: msg.seq,
|
|
||||||
task: msg.task,
|
|
||||||
time_send: time_xfer,
|
|
||||||
time_proc: time_proc,
|
|
||||||
// replaced on reply side
|
|
||||||
time_recv: util.time(),
|
|
||||||
data: output
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log({kiri_msg:e});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// catch clipper alerts and convert to console messages
|
|
||||||
self.alert = function(o) {
|
|
||||||
console.log(o);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
worker.postMessage({
|
||||||
|
seq: seq,
|
||||||
|
task: fn,
|
||||||
|
time: time(),
|
||||||
|
data: data
|
||||||
|
}, zerocopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KIRI.work = {
|
||||||
|
isSlicing : function() {
|
||||||
|
let current = 0;
|
||||||
|
for (let key in slicing) {
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
return current > 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
restart : function() {
|
||||||
|
if (worker) {
|
||||||
|
worker.terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let key in slicing) {
|
||||||
|
slicing[key]({error: "cancelled slicing"});
|
||||||
|
}
|
||||||
|
|
||||||
|
slicing = {};
|
||||||
|
running = {};
|
||||||
|
worker = new Worker(pre + "/code/worker.js/" + exports.VERSION);
|
||||||
|
|
||||||
|
worker.onmessage = function(e) {
|
||||||
|
let now = time(),
|
||||||
|
reply = e.data,
|
||||||
|
record = running[reply.seq],
|
||||||
|
onreply = record.fn;
|
||||||
|
|
||||||
|
if (reply.done) {
|
||||||
|
delete running[reply.seq];
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate and replace recv time
|
||||||
|
reply.time_recv = now - reply.time_recv;
|
||||||
|
|
||||||
|
onreply(reply.data, reply);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
decimate : function(vertices, callback) {
|
||||||
|
vertices = vertices.buffer.slice(0);
|
||||||
|
send("decimate", vertices, function(output) {
|
||||||
|
callback(output);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
clear : function(widget) {
|
||||||
|
send("clear", widget ? {id:widget.id} : {}, function(reply) {
|
||||||
|
// console.log({clear:reply});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
slice : function(settings, widget, callback) {
|
||||||
|
let vertices = widget.getGeoVertices().buffer.slice(0);
|
||||||
|
slicing[widget.id] = callback;
|
||||||
|
send("slice", {
|
||||||
|
id: widget.id,
|
||||||
|
settings: settings,
|
||||||
|
vertices: vertices,
|
||||||
|
position: widget.mesh.position
|
||||||
|
}, function(reply) {
|
||||||
|
if (reply.done || reply.error) delete slicing[widget.id];
|
||||||
|
callback(reply);
|
||||||
|
}, null, [vertices]);
|
||||||
|
},
|
||||||
|
|
||||||
|
printSetup : function(settings, callback) {
|
||||||
|
send("printSetup", {settings:settings}, function(reply) {
|
||||||
|
callback(reply);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
printGCode : function(callback) {
|
||||||
|
let gcode = [];
|
||||||
|
let start = BASE.util.time();
|
||||||
|
send("printGCode", {}, function(reply) {
|
||||||
|
if (reply.line) {
|
||||||
|
gcode.push(reply.line);
|
||||||
|
} else {
|
||||||
|
if (!reply.gcode) reply.gcode = gcode.join("\n");
|
||||||
|
// console.log({printGCode:(BASE.util.time() - start)});
|
||||||
|
callback(reply);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
sliceToGCode : function(settings, vertices, callback) {
|
||||||
|
vertices = widget.getGeoVertices().buffer.slice(0);
|
||||||
|
let wid = new Date().toString(36);
|
||||||
|
send("slice", {settings:settings, id:wiwd, vertices:vertices, position:{x:0,y:0,z:0}}, function(reply) {
|
||||||
|
send("printSetup", {settings:settings}, function(reply) {
|
||||||
|
send("printGCode", {}, function(reply) {
|
||||||
|
callback(reply);
|
||||||
|
});
|
||||||
|
}, null, [vertices]);
|
||||||
|
callback(reply);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// start worker
|
||||||
|
KIRI.work.restart();
|
||||||
|
|
|
||||||
225
js/kiri-worker.js
Normal file
225
js/kiri-worker.js
Normal file
|
|
@ -0,0 +1,225 @@
|
||||||
|
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// this code runs in the web worker
|
||||||
|
module = { exports: {} };
|
||||||
|
|
||||||
|
let loc = self.location,
|
||||||
|
ver = exports.VERSION,
|
||||||
|
time = function() { return new Date().getTime() };
|
||||||
|
host = loc.hostname,
|
||||||
|
debug = (host !== 'grid.space' && host !== 'debug');
|
||||||
|
|
||||||
|
console.log("kiri | init work | " + ver);
|
||||||
|
|
||||||
|
// when running the server in 'web' mode, the obfuscated code is served as a
|
||||||
|
// unified ball via /code/work.js -- otherwise, map "localhost" to "debug"
|
||||||
|
// to debug unobfuscated code. if not, /js/ paths will 404.
|
||||||
|
if (debug) {
|
||||||
|
try {
|
||||||
|
[
|
||||||
|
"license",
|
||||||
|
"ext-n3d",
|
||||||
|
"ext-clip",
|
||||||
|
"add-array",
|
||||||
|
"add-three",
|
||||||
|
"geo",
|
||||||
|
"geo-point",
|
||||||
|
"geo-debug",
|
||||||
|
"geo-bounds",
|
||||||
|
"geo-line",
|
||||||
|
"geo-slope",
|
||||||
|
"geo-polygon",
|
||||||
|
"geo-polygons",
|
||||||
|
"geo-gyroid",
|
||||||
|
"kiri-fill",
|
||||||
|
"kiri-slice",
|
||||||
|
"kiri-slicer",
|
||||||
|
"kiri-driver-fdm",
|
||||||
|
"kiri-driver-cam",
|
||||||
|
"kiri-driver-laser",
|
||||||
|
"kiri-widget",
|
||||||
|
"kiri-pack",
|
||||||
|
"kiri-print",
|
||||||
|
"kiri-codec"
|
||||||
|
].forEach(function(scr) {
|
||||||
|
importScripts(["/js/",scr,".js","/v"+ver].join(''));
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.log("unable to load worker scripts. kiri is likely in debug mode.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
importScripts("/code/work.js/"+ver);
|
||||||
|
}
|
||||||
|
|
||||||
|
let base = self.base,
|
||||||
|
moto = self.moto,
|
||||||
|
dbug = base.debug,
|
||||||
|
util = base.util,
|
||||||
|
kiri = self.kiri,
|
||||||
|
Widget = kiri.Widget,
|
||||||
|
currentPrint,
|
||||||
|
cache = {};
|
||||||
|
|
||||||
|
if (!debug) {
|
||||||
|
base.debug.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
let dispatch = {
|
||||||
|
decimate: function(vertices, send) {
|
||||||
|
vertices = new Float32Array(vertices),
|
||||||
|
vertices = Widget.pointsToVertices(Widget.verticesToPoints(vertices, true));
|
||||||
|
send.done(vertices);
|
||||||
|
},
|
||||||
|
|
||||||
|
slice: function(data, send) {
|
||||||
|
let settings = data.settings,
|
||||||
|
vertices = new Float32Array(data.vertices),
|
||||||
|
position = data.position,
|
||||||
|
points = Widget.verticesToPoints(vertices);
|
||||||
|
|
||||||
|
send.data({update:0.05, updateStatus:"slicing"});
|
||||||
|
|
||||||
|
let widget = kiri.newWidget(data.id).setPoints(points),
|
||||||
|
last = util.time(),
|
||||||
|
now;
|
||||||
|
|
||||||
|
// do it here so cancel can work
|
||||||
|
cache[data.id] = widget;
|
||||||
|
|
||||||
|
// fake mesh object to satisfy printing
|
||||||
|
widget.mesh = {
|
||||||
|
widget: widget,
|
||||||
|
position: position
|
||||||
|
};
|
||||||
|
|
||||||
|
widget.slice(settings, function(error) {
|
||||||
|
if (error) {
|
||||||
|
delete cache[data.id];
|
||||||
|
send.data({error: error});
|
||||||
|
} else {
|
||||||
|
let slices = widget.slices || [];
|
||||||
|
send.data({send_start: time()});
|
||||||
|
send.data({
|
||||||
|
topo: settings.synth.sendTopo ? widget.topo : null,
|
||||||
|
stats: widget.stats,
|
||||||
|
slices: slices.length
|
||||||
|
});
|
||||||
|
slices.forEach(function(slice,index) {
|
||||||
|
send.data({index: index, slice: slice.encode()});
|
||||||
|
})
|
||||||
|
send.data({send_end: time()});
|
||||||
|
}
|
||||||
|
send.done({done: true});
|
||||||
|
// cache results for future printing
|
||||||
|
// cache[data.id] = widget;
|
||||||
|
}, function(update, msg) {
|
||||||
|
now = util.time();
|
||||||
|
if (now - last < 10 && update < 0.99) return;
|
||||||
|
// on update
|
||||||
|
send.data({update: (0.05 + update * 0.95), updateStatus: msg});
|
||||||
|
last = now;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
printSetup: function(data, send) {
|
||||||
|
let widgets = [], key;
|
||||||
|
for (key in cache) {
|
||||||
|
if (cache.hasOwnProperty(key)) widgets.push(cache[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
send.data({update:0.05, updateStatus:"preview"});
|
||||||
|
|
||||||
|
currentPrint = kiri.newPrint(data.settings, widgets, data.id);
|
||||||
|
currentPrint.setup(false, function(update, msg) {
|
||||||
|
send.data({
|
||||||
|
update: update,
|
||||||
|
updateStatus: msg
|
||||||
|
});
|
||||||
|
}, function() {
|
||||||
|
send.done({
|
||||||
|
done: true,
|
||||||
|
output: currentPrint.encodeOutput()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
printGCode: function(data, send) {
|
||||||
|
currentPrint.exportGCode(false, function(gcode) {
|
||||||
|
send.done({
|
||||||
|
gcode: gcode,
|
||||||
|
lines: currentPrint.lines,
|
||||||
|
bytes: currentPrint.bytes,
|
||||||
|
bounds: currentPrint.bounds,
|
||||||
|
distance: currentPrint.distance,
|
||||||
|
time: currentPrint.time
|
||||||
|
});
|
||||||
|
}, function(line) {
|
||||||
|
send.data({line:line});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
clear: function(data, send) {
|
||||||
|
if (!data.id) {
|
||||||
|
cache = {};
|
||||||
|
currentPrint = null;
|
||||||
|
send.done({ clear: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let had = cache[data.id] !== undefined;
|
||||||
|
delete cache[data.id];
|
||||||
|
send.done({
|
||||||
|
id: data.id,
|
||||||
|
had: had,
|
||||||
|
has: cache[data.id] !== undefined
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
self.onmessage = function(e) {
|
||||||
|
let time_recv = util.time(),
|
||||||
|
msg = e.data,
|
||||||
|
run = dispatch[msg.task],
|
||||||
|
send = {
|
||||||
|
data : function(data,direct) {
|
||||||
|
self.postMessage({
|
||||||
|
seq: msg.seq,
|
||||||
|
task: msg.task,
|
||||||
|
done: false,
|
||||||
|
data: data
|
||||||
|
},direct);
|
||||||
|
},
|
||||||
|
done : function(data,direct) {
|
||||||
|
self.postMessage({
|
||||||
|
seq: msg.seq,
|
||||||
|
task: msg.task,
|
||||||
|
done: true,
|
||||||
|
data: data
|
||||||
|
},direct);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (run) {
|
||||||
|
let time_xfer = (time_recv - msg.time),
|
||||||
|
output = run(msg.data, send),
|
||||||
|
time_send = util.time(),
|
||||||
|
time_proc = time_send - time_recv;
|
||||||
|
|
||||||
|
if (output) self.postMessage({
|
||||||
|
seq: msg.seq,
|
||||||
|
task: msg.task,
|
||||||
|
time_send: time_xfer,
|
||||||
|
time_proc: time_proc,
|
||||||
|
// replaced on reply side
|
||||||
|
time_recv: util.time(),
|
||||||
|
data: output
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log({kiri_msg:e});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// catch clipper alerts and convert to console messages
|
||||||
|
self.alert = function(o) {
|
||||||
|
console.log(o);
|
||||||
|
};
|
||||||
18
js/kiri.js
18
js/kiri.js
|
|
@ -1,5 +1,4 @@
|
||||||
/** Copyright 2014-2019 Stewart Allen -- All Rights Reserved */
|
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
self.kiri = (self.kiri || {});
|
self.kiri = (self.kiri || {});
|
||||||
|
|
@ -37,6 +36,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
bedWidth: 1,
|
bedWidth: 1,
|
||||||
bedDepth: 1,
|
bedDepth: 1,
|
||||||
bedHeight: 1,
|
bedHeight: 1,
|
||||||
|
bedRound: 1,
|
||||||
maxHeight: 1,
|
maxHeight: 1,
|
||||||
extrudeAbs: 1,
|
extrudeAbs: 1,
|
||||||
filamentSize: 1,
|
filamentSize: 1,
|
||||||
|
|
@ -253,6 +253,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
bedWidth: 300, // FDM/CAM/Laser
|
bedWidth: 300, // FDM/CAM/Laser
|
||||||
bedDepth: 175, // FDM/CAM/Laser
|
bedDepth: 175, // FDM/CAM/Laser
|
||||||
bedHeight: 2.5, // display only (deprecate)
|
bedHeight: 2.5, // display only (deprecate)
|
||||||
|
bedRound: false, // FDM
|
||||||
maxHeight: 150, // FDM
|
maxHeight: 150, // FDM
|
||||||
filamentSize: 1.75, // FDM
|
filamentSize: 1.75, // FDM
|
||||||
nozzleSize: 0.4, // FDM
|
nozzleSize: 0.4, // FDM
|
||||||
|
|
@ -2069,6 +2070,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
var dev = settings.device,
|
var dev = settings.device,
|
||||||
width, depth,
|
width, depth,
|
||||||
height = Math.round(Math.max(dev.bedHeight, dev.bedWidth/100, dev.bedDepth/100));
|
height = Math.round(Math.max(dev.bedHeight, dev.bedWidth/100, dev.bedDepth/100));
|
||||||
|
SPACE.platform.setRound(dev.bedRound);
|
||||||
SPACE.platform.setGZOff(height/2 - 0.1);
|
SPACE.platform.setGZOff(height/2 - 0.1);
|
||||||
SPACE.platform.setSize(
|
SPACE.platform.setSize(
|
||||||
width = parseInt(dev.bedWidth),
|
width = parseInt(dev.bedWidth),
|
||||||
|
|
@ -2441,11 +2443,6 @@ self.kiri.license = exports.LICENSE;
|
||||||
UI.ctrlRight.style.display = show ? 'block' : 'none';
|
UI.ctrlRight.style.display = show ? 'block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
function eat(ev) {
|
|
||||||
ev.cancelBubble = true;
|
|
||||||
ev.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ******************************************************************
|
/** ******************************************************************
|
||||||
* LETS_GET_THIS_PARTY_STARTED()
|
* LETS_GET_THIS_PARTY_STARTED()
|
||||||
******************************************************************* */
|
******************************************************************* */
|
||||||
|
|
@ -2482,6 +2479,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
showSlices();
|
showSlices();
|
||||||
});
|
});
|
||||||
SPACE.platform.onMove(saveSettings);
|
SPACE.platform.onMove(saveSettings);
|
||||||
|
SPACE.platform.setRound(true);
|
||||||
|
|
||||||
set(UI, {
|
set(UI, {
|
||||||
container: container,
|
container: container,
|
||||||
|
|
@ -2523,6 +2521,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
setDeviceExtrusion: UC.newBoolean(LANG.dev_extab, onBooleanClick, {title:LANG.dev_extab_desc}),
|
setDeviceExtrusion: UC.newBoolean(LANG.dev_extab, onBooleanClick, {title:LANG.dev_extab_desc}),
|
||||||
setDeviceOrigin: UC.newBoolean(LANG.dev_orgc, onBooleanClick, {title:LANG.dev_orgc_desc}),
|
setDeviceOrigin: UC.newBoolean(LANG.dev_orgc, onBooleanClick, {title:LANG.dev_orgc_desc}),
|
||||||
setDeviceOriginTop: UC.newBoolean(LANG.dev_orgt, onBooleanClick, {title:LANG.dev_orgt_desc, modes:CAM}),
|
setDeviceOriginTop: UC.newBoolean(LANG.dev_orgt, onBooleanClick, {title:LANG.dev_orgt_desc, modes:CAM}),
|
||||||
|
setDeviceRound: UC.newBoolean(LANG.dev_bedc, onBooleanClick, {title:LANG.dev_bedc_desc, modes:FDM}),
|
||||||
|
|
||||||
setDevice: UC.newGroup("gcode", $('device')),
|
setDevice: UC.newGroup("gcode", $('device')),
|
||||||
setDeviceFan: UC.newInput(LANG.dev_fanp, {title:LANG.dev_fanp_desc, modes:FDM, size:15}),
|
setDeviceFan: UC.newInput(LANG.dev_fanp, {title:LANG.dev_fanp_desc, modes:FDM, size:15}),
|
||||||
|
|
@ -3254,6 +3253,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
settings: {
|
settings: {
|
||||||
bed_width: parseInt(UI.setDeviceWidth.value) || 300,
|
bed_width: parseInt(UI.setDeviceWidth.value) || 300,
|
||||||
bed_depth: parseInt(UI.setDeviceDepth.value) || 175,
|
bed_depth: parseInt(UI.setDeviceDepth.value) || 175,
|
||||||
|
bed_circle: UI.setDeviceRound.checked,
|
||||||
build_height: parseInt(UI.setDeviceHeight.value) || 150,
|
build_height: parseInt(UI.setDeviceHeight.value) || 150,
|
||||||
nozzle_size: parseFloat(UI.setDeviceNozzle.value) || 0.4,
|
nozzle_size: parseFloat(UI.setDeviceNozzle.value) || 0.4,
|
||||||
filament_diameter: parseFloat(UI.setDeviceFilament.value) || 1.75,
|
filament_diameter: parseFloat(UI.setDeviceFilament.value) || 1.75,
|
||||||
|
|
@ -3295,11 +3295,11 @@ self.kiri.license = exports.LICENSE;
|
||||||
local = isLocalDevice(devicename),
|
local = isLocalDevice(devicename),
|
||||||
dproc = settings.devproc[devicename],
|
dproc = settings.devproc[devicename],
|
||||||
mode = getMode();
|
mode = getMode();
|
||||||
|
|
||||||
settings.device = {
|
settings.device = {
|
||||||
bedHeight: 2.5,
|
bedHeight: 2.5,
|
||||||
bedWidth: valueOf(set.bed_width, 300),
|
bedWidth: valueOf(set.bed_width, 300),
|
||||||
bedDepth: valueOf(set.bed_depth, 175),
|
bedDepth: valueOf(set.bed_depth, 175),
|
||||||
|
bedRound: valueOf(set.bed_circle, false),
|
||||||
maxHeight: valueOf(set.build_height, 150),
|
maxHeight: valueOf(set.build_height, 150),
|
||||||
nozzleSize: valueOf(set.nozzle_size, 0.4),
|
nozzleSize: valueOf(set.nozzle_size, 0.4),
|
||||||
filamentSize: valueOf(set.filament_diameter, 1.75),
|
filamentSize: valueOf(set.filament_diameter, 1.75),
|
||||||
|
|
@ -3336,6 +3336,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
UI.setDeviceHeight.value = dev.maxHeight;
|
UI.setDeviceHeight.value = dev.maxHeight;
|
||||||
UI.setDeviceExtrusion.checked = dev.extrudeAbs;
|
UI.setDeviceExtrusion.checked = dev.extrudeAbs;
|
||||||
UI.setDeviceOrigin.checked = proc.outputOriginCenter;
|
UI.setDeviceOrigin.checked = proc.outputOriginCenter;
|
||||||
|
UI.setDeviceRound.checked = dev.bedRound;
|
||||||
// FDM
|
// FDM
|
||||||
UI.setDeviceFan.value = dev.gcodeFan;
|
UI.setDeviceFan.value = dev.gcodeFan;
|
||||||
UI.setDeviceTrack.value = dev.gcodeTrack;
|
UI.setDeviceTrack.value = dev.gcodeTrack;
|
||||||
|
|
@ -3363,6 +3364,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
UI.setDeviceExtrusion,
|
UI.setDeviceExtrusion,
|
||||||
UI.setDeviceOrigin,
|
UI.setDeviceOrigin,
|
||||||
UI.setDeviceOriginTop,
|
UI.setDeviceOriginTop,
|
||||||
|
UI.setDeviceRound,
|
||||||
UI.setDeviceFan,
|
UI.setDeviceFan,
|
||||||
UI.setDeviceTrack,
|
UI.setDeviceTrack,
|
||||||
UI.setDeviceLayer,
|
UI.setDeviceLayer,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
var exports = {
|
var exports = {
|
||||||
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
|
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
|
||||||
LICENSE:"See the license.md file included with the source distribution",
|
LICENSE:"See the license.md file included with the source distribution",
|
||||||
VERSION:"1.6.3"
|
VERSION:"1.6.4"
|
||||||
};
|
};
|
||||||
if (!module) var module = {};
|
if (!module) var module = {};
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
|
|
|
||||||
137
js/moto-space.js
137
js/moto-space.js
|
|
@ -1,12 +1,11 @@
|
||||||
/** Copyright 2014-2019 Stewart Allen -- All Rights Reserved */
|
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var gs_moto_space = exports;
|
let gs_moto_space = exports;
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var WIN = window,
|
let WIN = window,
|
||||||
DOC = document,
|
DOC = document,
|
||||||
SCENE = new THREE.Scene(),
|
SCENE = new THREE.Scene(),
|
||||||
WORLD = new THREE.Group(),
|
WORLD = new THREE.Group(),
|
||||||
|
|
@ -58,7 +57,16 @@ var gs_moto_space = exports;
|
||||||
light5,
|
light5,
|
||||||
camera,
|
camera,
|
||||||
renderer,
|
renderer,
|
||||||
container;
|
container,
|
||||||
|
isRound = false,
|
||||||
|
platformMaterial = new THREE.MeshPhongMaterial({
|
||||||
|
color: 0xcccccc,
|
||||||
|
specular: 0xcccccc,
|
||||||
|
shininess: 5,
|
||||||
|
transparent: true,
|
||||||
|
opacity: 0.6,
|
||||||
|
side: THREE.DoubleSide
|
||||||
|
});
|
||||||
|
|
||||||
/** ******************************************************************
|
/** ******************************************************************
|
||||||
* TWEENing Functions
|
* TWEENing Functions
|
||||||
|
|
@ -72,7 +80,7 @@ var gs_moto_space = exports;
|
||||||
tweenit();
|
tweenit();
|
||||||
|
|
||||||
function tweenCamPan(x,y,z) {
|
function tweenCamPan(x,y,z) {
|
||||||
var pos = viewControl.getPosition();
|
let pos = viewControl.getPosition();
|
||||||
pos.panX = x;
|
pos.panX = x;
|
||||||
pos.panY = y;
|
pos.panY = y;
|
||||||
pos.panZ = z;
|
pos.panZ = z;
|
||||||
|
|
@ -80,7 +88,7 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tweenCam(pos) {
|
function tweenCam(pos) {
|
||||||
var tf = function () {
|
let tf = function () {
|
||||||
viewControl.setPosition(this);
|
viewControl.setPosition(this);
|
||||||
refresh();
|
refresh();
|
||||||
};
|
};
|
||||||
|
|
@ -91,7 +99,7 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tweenPlatform(w,h,d) {
|
function tweenPlatform(w,h,d) {
|
||||||
var from = {x: platform.scale.x, y: platform.scale.y, z: platform.scale.z},
|
let from = {x: platform.scale.x, y: platform.scale.y, z: platform.scale.z},
|
||||||
to = {x:w, y:h, z:d},
|
to = {x:w, y:h, z:d},
|
||||||
gridMajor = gridUnitMajor,
|
gridMajor = gridUnitMajor,
|
||||||
gridMinor = gridUnitMinor,
|
gridMinor = gridUnitMinor,
|
||||||
|
|
@ -128,14 +136,14 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addEventHandlers(el, pairs) {
|
function addEventHandlers(el, pairs) {
|
||||||
for (var i=0; i<pairs.length; i += 2) {
|
for (let i=0; i<pairs.length; i += 2) {
|
||||||
addEventListener(el, pairs[i], pairs[i+1]);
|
addEventListener(el, pairs[i], pairs[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEnterKey(el, fn) {
|
function onEnterKey(el, fn) {
|
||||||
if (Array.isArray(el)) {
|
if (Array.isArray(el)) {
|
||||||
for (var i=0; i<el.length; i += 2) onEnterKey(el[i], el[i+1]);
|
for (let i=0; i<el.length; i += 2) onEnterKey(el[i], el[i+1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addEventListener(el, 'keyup', function(event) {
|
addEventListener(el, 'keyup', function(event) {
|
||||||
|
|
@ -144,23 +152,30 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLight(x,y,z,i) {
|
function addLight(x,y,z,i) {
|
||||||
var l = new THREE.PointLight(0xffffff, i, 0);
|
let l = new THREE.PointLight(0xffffff, i, 0);
|
||||||
l.position.set(x,y,z);
|
l.position.set(x,y,z);
|
||||||
SCENE.add(l);
|
SCENE.add(l);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePlatformPosition() {
|
function updatePlatformPosition() {
|
||||||
platform.position.y = -platform.scale.z/2 - platformZOff;
|
if (isRound) {
|
||||||
// platform.position.y = -(platform.scale.z / 2 + platformZOff);
|
platform.position.y = -platform.scale.y/2 - platformZOff;
|
||||||
|
} else {
|
||||||
|
platform.position.y = -platform.scale.z/2 - platformZOff;
|
||||||
|
}
|
||||||
requestRefresh();
|
requestRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPlatformSize(width, depth, height) {
|
function setPlatformSize(width, depth, height) {
|
||||||
platform.scale.set(width || 300, depth || 175, height || 5);
|
if (isRound) {
|
||||||
|
platform.scale.set(width || 300, height || 5, depth || 175);
|
||||||
|
} else {
|
||||||
|
platform.scale.set(width || 300, depth || 175, height || 5);
|
||||||
|
}
|
||||||
viewControl.maxDistance = Math.max(width,depth) * 4;
|
viewControl.maxDistance = Math.max(width,depth) * 4;
|
||||||
updatePlatformPosition();
|
updatePlatformPosition();
|
||||||
var y = Math.max(width, height) * 1;
|
let y = Math.max(width, height) * 1;
|
||||||
light1.position.set( width, y, depth);
|
light1.position.set( width, y, depth);
|
||||||
light2.position.set(-width, y, -depth);
|
light2.position.set(-width, y, -depth);
|
||||||
light4.position.set( width, light4.position.y, -depth);
|
light4.position.set( width, light4.position.y, -depth);
|
||||||
|
|
@ -183,29 +198,30 @@ var gs_moto_space = exports;
|
||||||
gridView = new THREE.Group();
|
gridView = new THREE.Group();
|
||||||
gridUnitMajor = unitMajor;
|
gridUnitMajor = unitMajor;
|
||||||
gridUnitMinor = unitMinor;
|
gridUnitMinor = unitMinor;
|
||||||
var x = platform.scale.x,
|
let x = platform.scale.x,
|
||||||
y = platform.scale.y,
|
y = isRound ? platform.scale.z : platform.scale.y,
|
||||||
z = platform.scale.z,
|
z = isRound ? platform.scale.y : platform.scale.z,
|
||||||
xr = ROUND(x / unitMajor) * unitMajor,
|
xr = ROUND(x / unitMajor) * unitMajor,
|
||||||
yr = ROUND(y / unitMajor) * unitMajor,
|
yr = ROUND(y / unitMajor) * unitMajor,
|
||||||
xo = Math.ceil(xr / 2),
|
xo = isRound ? Math.floor(x/2) : Math.ceil(xr / 2),
|
||||||
yo = Math.ceil(yr / 2),
|
yo = isRound ? Math.floor(y/2) : Math.ceil(yr / 2),
|
||||||
w = x / 2,
|
w = x / 2,
|
||||||
h = y / 2,
|
h = y / 2,
|
||||||
d = z / 2,
|
d = z / 2,
|
||||||
zp = -d - platformZOff + gridZOff,
|
zp = -d - platformZOff + gridZOff,
|
||||||
majors = [], minors = unitMinor ? [] : null, i;
|
majors = [], minors = unitMinor ? [] : null, i;
|
||||||
|
|
||||||
for (i = -xo; i <= xo; i++) {
|
for (i = -xo; i <= xo; i++) {
|
||||||
if (i >= -w && i <= w) {
|
if (i >= -w && i <= w) {
|
||||||
if (i % unitMajor === 0) majors.append({x:i, y:-h, z:zp}).append({x:i, y:h, z:zp});
|
let oh = isRound ? Math.sqrt(1-(i/xo)*(i/xo)) * h : h;
|
||||||
else if (minors && i % unitMinor === 0) minors.append({x:i, y:-h, z:zp}).append({x:i, y:h, z:zp});
|
if (i % unitMajor === 0) majors.append({x:i, y:-oh, z:zp}).append({x:i, y:oh, z:zp});
|
||||||
|
else if (minors && i % unitMinor === 0) minors.append({x:i, y:-oh, z:zp}).append({x:i, y:oh, z:zp});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = -yo; i <= yo; i++) {
|
for (i = -yo; i <= yo; i++) {
|
||||||
if (i >= -h && i <= h) {
|
if (i >= -h && i <= h) {
|
||||||
if (i % unitMajor === 0) majors.append({x:-w, y:i, z:zp}).append({x:w, y:i, z:zp});
|
let ow = isRound ? Math.sqrt(1-(i/yo)*(i/yo)) * w : w;
|
||||||
else if (minors && i % unitMinor === 0) minors.append({x:-w, y:i, z:zp}).append({x:w, y:i, z:zp});
|
if (i % unitMajor === 0) majors.append({x:-ow, y:i, z:zp}).append({x:ow, y:i, z:zp});
|
||||||
|
else if (minors && i % unitMinor === 0) minors.append({x:-ow, y:i, z:zp}).append({x:ow, y:i, z:zp});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gridView.add(makeLinesFromPoints(majors, colorMajor || 0x999999, 1));
|
gridView.add(makeLinesFromPoints(majors, colorMajor || 0x999999, 1));
|
||||||
|
|
@ -259,7 +275,7 @@ var gs_moto_space = exports;
|
||||||
function keyHandler(evt) {
|
function keyHandler(evt) {
|
||||||
if (!defaultKeys || inputHasFocus()) return false;
|
if (!defaultKeys || inputHasFocus()) return false;
|
||||||
if (evt.metaKey) return false;
|
if (evt.metaKey) return false;
|
||||||
var handled = true;
|
let handled = true;
|
||||||
switch (evt.charCode) {
|
switch (evt.charCode) {
|
||||||
case cca('z'):
|
case cca('z'):
|
||||||
Space.view.reset();
|
Space.view.reset();
|
||||||
|
|
@ -296,7 +312,7 @@ var gs_moto_space = exports;
|
||||||
|
|
||||||
function makeLinesFromPoints(points, color, width) {
|
function makeLinesFromPoints(points, color, width) {
|
||||||
if (points.length % 2 != 0) throw "invalid line : "+points.length;
|
if (points.length % 2 != 0) throw "invalid line : "+points.length;
|
||||||
var geo = new THREE.Geometry(),
|
let geo = new THREE.Geometry(),
|
||||||
i = 0, p1, p2, mesh;
|
i = 0, p1, p2, mesh;
|
||||||
while (i < points.length) {
|
while (i < points.length) {
|
||||||
p1 = points[i++];
|
p1 = points[i++];
|
||||||
|
|
@ -313,8 +329,8 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function intersect(objects, recurse) {
|
function intersect(objects, recurse) {
|
||||||
var lookAt = new THREE.Vector3(mouse.x, mouse.y, 0.0).unproject(camera);
|
let lookAt = new THREE.Vector3(mouse.x, mouse.y, 0.0).unproject(camera);
|
||||||
var ray = new THREE.Raycaster(camera.position, lookAt.sub(camera.position).normalize());
|
let ray = new THREE.Raycaster(camera.position, lookAt.sub(camera.position).normalize());
|
||||||
return ray.intersectObjects(objects, recurse);
|
return ray.intersectObjects(objects, recurse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -326,16 +342,16 @@ var gs_moto_space = exports;
|
||||||
if (event.target === renderer.domElement) {
|
if (event.target === renderer.domElement) {
|
||||||
DOC.activeElement.blur();
|
DOC.activeElement.blur();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var selection = null,
|
let selection = null,
|
||||||
trackTo = alignedTracking ? trackPlane : platform;
|
trackTo = alignedTracking ? trackPlane : platform;
|
||||||
if (mouseDownSelect) selection = mouseDownSelect();
|
if (mouseDownSelect) selection = mouseDownSelect();
|
||||||
if (selection && selection.length > 0) {
|
if (selection && selection.length > 0) {
|
||||||
trackTo.visible = true;
|
trackTo.visible = true;
|
||||||
var int = intersect(selection.slice().append(trackTo), false);
|
let int = intersect(selection.slice().append(trackTo), false);
|
||||||
trackTo.visible = false;
|
trackTo.visible = false;
|
||||||
if (int.length > 0) {
|
if (int.length > 0) {
|
||||||
var trackInt, selectInt;
|
let trackInt, selectInt;
|
||||||
for (var i=0; i<int.length; i++) {
|
for (let i=0; i<int.length; i++) {
|
||||||
if (!trackInt && int[i].object === trackTo) {
|
if (!trackInt && int[i].object === trackTo) {
|
||||||
trackInt = int[i];
|
trackInt = int[i];
|
||||||
} else if (!selectInt && selection.contains(int[i].object)) {
|
} else if (!selectInt && selection.contains(int[i].object)) {
|
||||||
|
|
@ -351,7 +367,7 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (platformClick) {
|
if (platformClick) {
|
||||||
var vis = platform.visible;
|
let vis = platform.visible;
|
||||||
platform.visible = true;
|
platform.visible = true;
|
||||||
int = intersect([platform], false);
|
int = intersect([platform], false);
|
||||||
platform.visible = vis;
|
platform.visible = vis;
|
||||||
|
|
@ -371,11 +387,11 @@ var gs_moto_space = exports;
|
||||||
if (!mouseMoved) {
|
if (!mouseMoved) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!mouseMoved) {
|
if (!mouseMoved) {
|
||||||
var refresh = false,
|
let refresh = false,
|
||||||
selection = null;
|
selection = null;
|
||||||
if (mouseUpSelect) selection = mouseUpSelect();
|
if (mouseUpSelect) selection = mouseUpSelect();
|
||||||
if (selection && selection.length > 0) {
|
if (selection && selection.length > 0) {
|
||||||
var int = intersect(selection, selectRecurse);
|
let int = intersect(selection, selectRecurse);
|
||||||
if (int.length > 0) {
|
if (int.length > 0) {
|
||||||
mouseUpSelect(int[0], event);
|
mouseUpSelect(int[0], event);
|
||||||
refresh = true;
|
refresh = true;
|
||||||
|
|
@ -396,10 +412,10 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseMove(event) {
|
function onMouseMove(event) {
|
||||||
var int, vis;
|
let int, vis;
|
||||||
if (viewControl.enabled) {
|
if (viewControl.enabled) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var selection = mouseHover ? mouseHover() : null;
|
let selection = mouseHover ? mouseHover() : null;
|
||||||
if (selection && selection.length > 0) {
|
if (selection && selection.length > 0) {
|
||||||
int = intersect(selection, selectRecurse);
|
int = intersect(selection, selectRecurse);
|
||||||
if (int.length > 0) mouseHover(int[0], event);
|
if (int.length > 0) mouseHover(int[0], event);
|
||||||
|
|
@ -413,13 +429,13 @@ var gs_moto_space = exports;
|
||||||
}
|
}
|
||||||
} else if (mouseDragPoint && mouseDrag && mouseDrag()) {
|
} else if (mouseDragPoint && mouseDrag && mouseDrag()) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var trackTo = alignedTracking ? trackPlane : platform;
|
let trackTo = alignedTracking ? trackPlane : platform;
|
||||||
trackTo.visible = true;
|
trackTo.visible = true;
|
||||||
int = intersect([trackTo], false);
|
int = intersect([trackTo], false);
|
||||||
trackTo.visible = false;
|
trackTo.visible = false;
|
||||||
if (int.length > 0 && int[0].object === trackTo) {
|
if (int.length > 0 && int[0].object === trackTo) {
|
||||||
var delta = mouseDragPoint.clone().sub(int[0].point);
|
let delta = mouseDragPoint.clone().sub(int[0].point);
|
||||||
var offset = mouseDragStart.clone().sub(int[0].point);
|
let offset = mouseDragStart.clone().sub(int[0].point);
|
||||||
mouseDragPoint = int[0].point;
|
mouseDragPoint = int[0].point;
|
||||||
mouseDrag({x: -delta.x, y: delta.z}, offset.multiplyVectors(offset, trackDelta));
|
mouseDrag({x: -delta.x, y: delta.z}, offset.multiplyVectors(offset, trackDelta));
|
||||||
requestRefresh();
|
requestRefresh();
|
||||||
|
|
@ -435,7 +451,7 @@ var gs_moto_space = exports;
|
||||||
* Space Object
|
* Space Object
|
||||||
******************************************************************* */
|
******************************************************************* */
|
||||||
|
|
||||||
var Space = {
|
let Space = {
|
||||||
alignTracking: alignTracking,
|
alignTracking: alignTracking,
|
||||||
addEventListener: addEventListener,
|
addEventListener: addEventListener,
|
||||||
addEventHandlers: addEventHandlers,
|
addEventHandlers: addEventHandlers,
|
||||||
|
|
@ -480,7 +496,31 @@ var gs_moto_space = exports;
|
||||||
size: function() { return platform.scale },
|
size: function() { return platform.scale },
|
||||||
isVisible: function() { return platform.visible },
|
isVisible: function() { return platform.visible },
|
||||||
|
|
||||||
showGrid: function(b) { gridView.visible = b }
|
showGrid: function(b) { gridView.visible = b },
|
||||||
|
|
||||||
|
setRound: function(bool) {
|
||||||
|
let current = platform;
|
||||||
|
isRound = bool;
|
||||||
|
if (bool) {
|
||||||
|
platform = new THREE.Mesh(
|
||||||
|
new THREE.CylinderGeometry(.5, .5, 1, 60),
|
||||||
|
platformMaterial
|
||||||
|
);
|
||||||
|
platform.rotation.x = 0;
|
||||||
|
} else {
|
||||||
|
platform = new THREE.Mesh(
|
||||||
|
new THREE.BoxGeometry(1, 1, 1),
|
||||||
|
platformMaterial
|
||||||
|
);
|
||||||
|
platform.rotation.x = -PI2;
|
||||||
|
}
|
||||||
|
|
||||||
|
platform.position.y = current.position.y;
|
||||||
|
platform.visible = current.visible;
|
||||||
|
|
||||||
|
SCENE.remove(current);
|
||||||
|
SCENE.add(platform);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
view: {
|
view: {
|
||||||
|
|
@ -567,14 +607,7 @@ var gs_moto_space = exports;
|
||||||
|
|
||||||
platform = new THREE.Mesh(
|
platform = new THREE.Mesh(
|
||||||
new THREE.BoxGeometry(1, 1, 1),
|
new THREE.BoxGeometry(1, 1, 1),
|
||||||
new THREE.MeshPhongMaterial({
|
platformMaterial
|
||||||
color: 0xcccccc,
|
|
||||||
specular: 0xcccccc,
|
|
||||||
shininess: 5,
|
|
||||||
transparent: true,
|
|
||||||
opacity: 0.6,
|
|
||||||
side: THREE.DoubleSide
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
platform.position.y = platformZOff;
|
platform.position.y = platformZOff;
|
||||||
|
|
@ -588,7 +621,7 @@ var gs_moto_space = exports;
|
||||||
trackPlane.visible = false;
|
trackPlane.visible = false;
|
||||||
trackPlane.rotation.x = PI2;
|
trackPlane.rotation.x = PI2;
|
||||||
|
|
||||||
var sky = new THREE.Mesh(
|
let sky = new THREE.Mesh(
|
||||||
new THREE.BoxGeometry(50000, 50000, 50000, 1, 1, 1),
|
new THREE.BoxGeometry(50000, 50000, 50000, 1, 1, 1),
|
||||||
new THREE.MeshBasicMaterial({ color: skyColor, side: THREE.DoubleSide })
|
new THREE.MeshBasicMaterial({ color: skyColor, side: THREE.DoubleSide })
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
/**
|
/** Copyright Stewart Allen -- All Rights Reserved */
|
||||||
* Copyright Stewart Allen -- All Rights Reserved
|
|
||||||
*/
|
|
||||||
|
|
||||||
Array.prototype.contains = function(v) {
|
Array.prototype.contains = function(v) {
|
||||||
return this.indexOf(v) >= 0;
|
return this.indexOf(v) >= 0;
|
||||||
|
|
@ -844,7 +842,7 @@ let ver = require('../js/license.js'),
|
||||||
],
|
],
|
||||||
worker : [
|
worker : [
|
||||||
"license",
|
"license",
|
||||||
"kiri-work"
|
"kiri-worker"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
code = {},
|
code = {},
|
||||||
|
|
|
||||||
1
notes.md
1
notes.md
|
|
@ -1,6 +1,5 @@
|
||||||
# Kiri:Moto todo
|
# Kiri:Moto todo
|
||||||
|
|
||||||
* circular bed support for delta printers
|
|
||||||
* hide the bed with a checkbox? indication of part outside printable area?
|
* hide the bed with a checkbox? indication of part outside printable area?
|
||||||
* set page background color? or dark mode?
|
* set page background color? or dark mode?
|
||||||
* better small screen support (on screen button for hiding side panels, compact selectors)
|
* better small screen support (on screen button for hiding side panels, compact selectors)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
"origin_center": true,
|
"origin_center": true,
|
||||||
"bed_width": 210,
|
"bed_width": 210,
|
||||||
"bed_depth": 210,
|
"bed_depth": 210,
|
||||||
|
"bed_circle": true,
|
||||||
"build_height": 320
|
"build_height": 320
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
"origin_center": true,
|
"origin_center": true,
|
||||||
"bed_width": 240,
|
"bed_width": 240,
|
||||||
"bed_depth": 240,
|
"bed_depth": 240,
|
||||||
|
"bed_circle": true,
|
||||||
"build_height": 480
|
"build_height": 480
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
"origin_center": true,
|
"origin_center": true,
|
||||||
"bed_width": 240,
|
"bed_width": 240,
|
||||||
"bed_depth": 240,
|
"bed_depth": 240,
|
||||||
|
"bed_circle": true,
|
||||||
"build_height": 260
|
"build_height": 260
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue