general improvements and fixes for frame api. added svg parsing
This commit is contained in:
parent
c99d7eaeb2
commit
f448762c94
4 changed files with 70 additions and 17 deletions
|
|
@ -44,6 +44,10 @@ class Engine {
|
|||
});
|
||||
}
|
||||
|
||||
clear() {
|
||||
KIRI.api.platform.clear();
|
||||
}
|
||||
|
||||
parse(data) {
|
||||
return new Promise((accept, reject) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@
|
|||
if (efn) {
|
||||
efn(data.data, data.event);
|
||||
}
|
||||
if (API.onmessage) {
|
||||
API.onmessage(data, msg);
|
||||
}
|
||||
}
|
||||
|
||||
let API = KIRI.frame = {
|
||||
setFrame: (io) => {
|
||||
|
|
@ -46,7 +48,9 @@
|
|||
|
||||
load: (load) => { send({ load }) },
|
||||
|
||||
parse: (data) => { send({ parse })},
|
||||
clear: () => { send({ clear: true }) },
|
||||
|
||||
parse: (data, type) => { send({ parse: data, type })},
|
||||
|
||||
get: (scope) => { send({ get: scope })},
|
||||
|
||||
|
|
@ -58,11 +62,11 @@
|
|||
|
||||
setFeatures: (features) => { send({ features })},
|
||||
|
||||
slice: () => { send({ function: "slice" }) },
|
||||
slice: () => { send({ function: "slice", callback: true }) },
|
||||
|
||||
prepare: () => { send({ function: "prepare" }) },
|
||||
prepare: () => { send({ function: "prepare", callback: true }) },
|
||||
|
||||
export: () => { send({ function: "export" }) },
|
||||
export: (cb) => { send({ function: "export", callback: cb ? true : false }) },
|
||||
|
||||
onmessage: () => { },
|
||||
|
||||
|
|
@ -77,4 +81,6 @@
|
|||
send({ event });
|
||||
}
|
||||
};
|
||||
|
||||
API.on = API.onevent;
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -508,7 +508,12 @@
|
|||
let send = source.window.postMessage;
|
||||
if (data.mode) { API.mode.set(data.mode.toUpperCase()) }
|
||||
if (data.view) { API.view.set(VIEWS[data.view.toUpperCase()]) }
|
||||
if (data.function) { API.function[data.function.toLowerCase()]() }
|
||||
if (data.function) {
|
||||
let cb = data.callback ? (output) => {
|
||||
send({event:`${data.function}.done`, data: output});
|
||||
} : undefined;
|
||||
API.function[data.function.toLowerCase()](cb);
|
||||
}
|
||||
if (data.event) {
|
||||
API.event.on(data.event, (evd) => {
|
||||
send({event: data.event, data: evd});
|
||||
|
|
@ -536,12 +541,39 @@
|
|||
break;
|
||||
}
|
||||
if (data.parse) {
|
||||
new load.STL().parse(data.parse, vertices => {
|
||||
let widget = newWidget().loadVertices(vertices);
|
||||
platform.add(widget);
|
||||
let type = (data.type || 'stl').toLowerCase();
|
||||
let bin = data.parse;
|
||||
let widget;
|
||||
switch (type) {
|
||||
case 'stl':
|
||||
if (!bin.buffer) bin = new Float32Array(bin).buffer;
|
||||
new load.STL().parse(bin, vertices => {
|
||||
platform.add(widget = newWidget().loadVertices(vertices));
|
||||
send({event: "parsed", data: [ widget.id ]});
|
||||
});
|
||||
break;
|
||||
case 'obj':
|
||||
// todo
|
||||
break;
|
||||
case '3mf':
|
||||
// todo
|
||||
break;
|
||||
case 'svg':
|
||||
let wid = [];
|
||||
for (let svg of LOAD.SVG.parse(bin)) {
|
||||
if (!(svg && svg.length)) continue;
|
||||
platform.add(widget = newWidget().loadVertices(svg.toFloat32()));
|
||||
wid.push(widget.id);
|
||||
}
|
||||
if (data.load) platformLoad(data.load);
|
||||
send({event: "parsed", data: wid});
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (data.load) {
|
||||
platformLoad(data.load, (verts, widget) => {
|
||||
send({event: "loaded", data: [ widget.id ]});
|
||||
})
|
||||
};
|
||||
if (data.clear) platform.clear();
|
||||
if (data.alert) alert2(data.alert, data.time);
|
||||
if (data.progress >= 0) setProgress(data.progress, data.message);
|
||||
|
|
|
|||
|
|
@ -87,7 +87,17 @@
|
|||
let defc = [
|
||||
"let api = kiri.frame;",
|
||||
"api.setMode('FDM');",
|
||||
"api.slice();"
|
||||
"api.clear();",
|
||||
"api.load('/obj/cube.stl');",
|
||||
"api.on('loaded', () => {",
|
||||
" api.slice();",
|
||||
"});",
|
||||
"api.on('slice.done', () => {",
|
||||
" api.prepare();",
|
||||
"});",
|
||||
"api.on('prepare.done', () => {",
|
||||
" api.export();",
|
||||
"});"
|
||||
].join('\n');
|
||||
let msgs = [];
|
||||
let edit;
|
||||
|
|
@ -135,15 +145,16 @@
|
|||
<div id="api">
|
||||
<h2>Frame Message API</h2>
|
||||
<li><label>load(url)</label> - where URL points to an STL</li>
|
||||
<li><label>parse(data)</label> - where data is a string or binary STL</li>
|
||||
<li><label>clear()</label> - clear workspace</li>
|
||||
<li><label>parse(data,type)</label> - data is string or binary. type is "stl" or "svg"</li>
|
||||
<li><label>setFrame(id_obj)</label> - id or object of iframe with Kiri:Moto loaded</li>
|
||||
<li><label>setMode(mode)</label> - FDM, CAM, LASER, SLA</li>
|
||||
<li><label>setDevice(options)</label> - change default object parameters</li>
|
||||
<li><label>setProcess(options)</label> - change default process parameters</li>
|
||||
<li><label>slice()</label> - async slice loaded object</li>
|
||||
<li><label>prepare()</label> - async path routing of slice data</li>
|
||||
<li><label>export()</label> - async gcode generation from path routing</li>
|
||||
<li><label>onmessage(fn)</label> - function to receive all messages</li>
|
||||
<li><label>slice()</label> - async slice loaded object. event upon completion</li>
|
||||
<li><label>prepare()</label> - async path routing of slice data. event upon completion</li>
|
||||
<li><label>export(callback)</label> - async gcode generation. opens export dialog or event callback with gcode</li>
|
||||
<li><label>onmessage = fn</label> - function to receive all messages</li>
|
||||
<li><label>onevent(event, fn)</label> - function to receive named messages</li>
|
||||
<li><label>emit(event, data)</label> - send named event with data</li>
|
||||
<li><label>alert(msg, time)</label> - show alert message with optional time in seconds</li>
|
||||
|
|
|
|||
Loading…
Reference in a new issue