diff --git a/build/d3d.js b/build/d3d.js index b0e8624..0e5ce98 100644 --- a/build/d3d.js +++ b/build/d3d.js @@ -1,7 +1,7 @@ /****************************************************** * * Utils -* requires jQuery, Three.js +* requires jQuery, Three.js, Clipper.js * ******************************************************/ @@ -147,6 +147,8 @@ var requestAnimFrame = (function () { * Box * Representation of de Doodle3DBox * Handles all communication with the doodle box +* JavaScript shell for api communication +* Check http://www.doodle3d.com/help/api-documentation * ******************************************************/ @@ -237,12 +239,12 @@ D3D.Box.prototype.printBatch = function () { var gcode = this.printBatches.shift(); sendAPI(this.api + "printer/print", { - "start": ((this.currentBatch === 0) ? "true" : "false"), - "first": ((this.currentBatch === 0) ? "true" : "false"), + "start": ((this.currentBatch === 0) ? true : false), + "first": ((this.currentBatch === 0) ? true : false), "gcode": gcode.join("\n") }, function (data) { - console.log("batch sent: " + self.currentBatch, data); + if (self.printBatches.length > 0) { //sent new batch self.currentBatch ++; @@ -254,7 +256,7 @@ D3D.Box.prototype.printBatch = function () { self.updateState(); }); }; -D3D.Box.prototype.stop = function () { +D3D.Box.prototype.stopPrint = function () { "use strict"; this.printBatches = []; @@ -275,140 +277,160 @@ D3D.Box.prototype.stop = function () { sendAPI(this.api + "printer/stop", { "gcode": finishMove.join("\n") - //"gcode": {} }, function (data) { console.log("Printer stop command sent"); }); return this; }; -D3D.Box.prototype.setConfig = function (data) { +D3D.Box.prototype.setConfig = function (data, callback) { + //works "use strict"; - sendAPI(this.api + "config", data); + sendAPI(this.api + "config", data, callback); return this; }; -D3D.Box.prototype.getInfoLog = function (callback) { +D3D.Box.prototype.getInfo = function (callback) { + //works "use strict"; - getAPI(self.api + "info/logfiles", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "info", callback); +}; +D3D.Box.prototype.downloadInfoLog = function (callback) { + //works in google chrome... not tested in other browsers + //some browsers may redirect using this code + "use strict"; - return this; + window.location = this.api + "info/logfiles"; }; D3D.Box.prototype.getInfoAcces = function (callback) { + //works "use strict"; - getAPI(self.api + "info/acces", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "info/access", callback); return this; }; -D3D.Box.prototype.getNetwerkScan = function (callback) { +D3D.Box.prototype.getNetworkScan = function (callback) { + //works "use strict"; - getAPI(self.api + "network/scan", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/scan", callback); return this; }; D3D.Box.prototype.getNetworkKnown = function (callback) { + //works "use strict"; - getAPI(self.api + "network/known", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/known", callback); return this; }; D3D.Box.prototype.getNetworkStatus = function (callback) { + //works "use strict"; - getAPI(self.api + "network/status", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/status", callback); return this; }; -D3D.Box.prototype.setNetworkAssosiate = function (data) { +D3D.Box.prototype.setNetworkAssosiate = function (data, callback) { + //works "use strict"; - sendAPI(self.api + "network/assosiate", data); + sendAPI(this.api + "network/associate", data, callback); return this; }; -D3D.Box.prototype.setNetworkDisassosiate = function (data) { +D3D.Box.prototype.setNetworkDisassosiate = function (callback) { + //not tested "use strict"; - sendAPI(self.api + "network/displayassosiate", data); + sendAPI(this.api + "network/disassociate", {}, callback); return this; }; -D3D.Box.prototype.setNetworkOpenap = function (data) { +D3D.Box.prototype.setNetworkOpenAP = function (callback) { + //not tested "use strict"; - sendAPI(self.api + "network/openap", data); + sendAPI(this.api + "network/openap", {}, callback); return this; }; -D3D.Box.prototype.setNetworkRemove = function (ssid) { +D3D.Box.prototype.setNetworkRemove = function (ssid, callback) { + //works "use strict"; - sendAPI(self.api + "network/displayassosiate", {ssid: ssid}); + sendAPI(this.api + "network/remove", { + ssid: ssid + }, callback); return this; }; D3D.Box.prototype.getNetworkAlive = function (callback) { + //works but returns empty array "use strict"; - getAPI(self.api + "network/alive", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/alive", callback); return this; }; D3D.Box.prototype.getPrinterListAll = function (callback) { + //works "use strict"; - getAPI(self.api + "printer/listall", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "printer/listall", callback); return this; }; -D3D.Box.prototype.setPrinterHeatup = function (data) { +D3D.Box.prototype.setPrinterHeatup = function (callback) { + //works "use strict"; - sendAPI(self.api + "printer/heatup", data); + sendAPI(this.api + "printer/heatup", {}, callback); return this; }; -D3D.Box.prototype.getVersion = function (data) { +D3D.Box.prototype.getSystemVersions = function (callback) { + //works "use strict"; - getAPI(self.api + "system/fwversion", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "system/fwversions", callback); + + return this; +}; +D3D.Box.prototype.getUpdateStatus = function (callback) { + //not tested + "use strict"; + + getAPI(this.api + "update/status", callback); + + return this; +}; +D3D.Box.prototype.setUpdateDownload = function (callback) { + //not tested + "use strict"; + + sendAPI(this.api + "update/download", {}, callback); + + return this; +}; +D3D.Box.prototype.setUpdateInstall = function (callback) { + //not tested + "use strict"; + + sendAPI(this.api + "update/install", {}, callback); + + return this; +}; +D3D.Box.prototype.setUpdateClear = function (callback) { + //not tested + "use strict"; + + sendAPI(this.api + "update/clear", {}, callback); return this; }; @@ -499,7 +521,11 @@ D3D.Slicer = function () { D3D.Slicer.prototype.setGeometry = function (geometry) { "use strict"; - this.geometry = geometry; + if (geometry instanceof THREE.BufferGeometry) { + geometry = new THREE.Geometry().fromBufferGeometry(geometry); + } + + this.geometry = geometry.clone(); this.geometry.mergeVertices(); this.createLines(); @@ -909,11 +935,11 @@ D3D.Slicer.prototype.drawPaths = function (printer, min, max) { for (var i = 0; i < paths.length; i ++) { var path = paths[i]; - context.moveTo((path[0].X- 100) * 6.0 + 200, (path[0].Y- 100) * 6.0 + 200); + context.moveTo((path[0].X * 2), (path[0].Y * 2)); for (var j = 0; j < path.length; j ++) { var point = path[j]; - context.lineTo((point.X- 100) * 6.0 + 200, (point.Y- 100) * 6.0 + 200); + context.lineTo((point.X * 2), (point.Y * 2)); } //context.closePath(); } diff --git a/build/d3d.min.js b/build/d3d.min.js index a67edf9..9ce6d12 100644 --- a/build/d3d.min.js +++ b/build/d3d.min.js @@ -1 +1 @@ -function sendAPI(t,e,i){"use strict";$.ajax({url:t,type:"POST",data:e,dataType:"json",timeout:1e4,success:function(t){"success"===t.status?void 0!==i&&i(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),sendAPI(t,e,i)})}function getAPI(t,e){"use strict";$.ajax({url:t,dataType:"json",timeout:5e3,success:function(t){"success"===t.status?void 0!==e&&e(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),getAPI(t,e)})}function downloadFile(t,e){"use strict";$(document.createElement("a")).attr({download:t,href:"data:text/plain,"+e})[0].click()}function applyMouseControls(t,e,i){"use strict";function r(){e.position.x=Math.cos(s)*Math.sin(o)*n,e.position.y=Math.sin(s)*n,e.position.z=Math.cos(s)*Math.cos(o)*n,e.lookAt(new THREE.Vector3(0,0,0))}var n=20,o=0,s=0,a=!1;$(t.domElement).on("mousedown",function(t){a=!0}).on("wheel",function(t){var e=t.originalEvent;e.preventDefault(),n=THREE.Math.clamp(n-e.wheelDelta,1,i),r()}),$(window).on("mouseup",function(t){a=!1}).on("mousemove",function(t){var e=t.originalEvent;a===!0&&(o=(o-e.webkitMovementX/100)%(2*Math.PI),s=THREE.Math.clamp(s+e.webkitMovementY/100,-Math.PI/2,Math.PI/2),r())}),r()}var D3D={version:"0.1",website:"http://www.doodle3d.com/",contact:"develop@doodle3d.com"};THREE.Vector2.prototype.normal=function(){"use strict";var t=this.y,e=-this.x;return this.set(t,e)},Array.prototype.clone=function(){"use strict";for(var t=[],e=0;e0?this.printBatch():this.updateState()},D3D.Box.prototype.updateState=function(){"use strict";var t=this;getAPI(this.api+"info/status",function(e){t.printer.status=e,t.update()})},D3D.Box.prototype.print=function(t){"use strict";for(this.currentBatch=0,t=t.clone();t.length>0;){var e=t.splice(0,Math.min(this.batchSize,t.length));this.printBatches.push(e)}return this},D3D.Box.prototype.printBatch=function(){"use strict";var t=this,e=this.printBatches.shift();sendAPI(this.api+"printer/print",{start:0===this.currentBatch?"true":"false",first:0===this.currentBatch?"true":"false",gcode:e.join("\n")},function(e){console.log("batch sent: "+t.currentBatch,e),t.printBatches.length>0&&t.currentBatch++,t.updateState()})},D3D.Box.prototype.stop=function(){"use strict";this.printBatches=[],this.currentBatch=0;var t=["M107 ;fan off","G91 ;relative positioning","G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure","G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more","G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way","M84 ;disable axes / steppers","G90 ;absolute positioning","M104 S180",";M140 S70","M117 Done ;display message (20 characters to clear whole screen)"];return sendAPI(this.api+"printer/stop",{gcode:t.join("\n")},function(t){console.log("Printer stop command sent")}),this},D3D.Box.prototype.setConfig=function(t){"use strict";return sendAPI(this.api+"config",t),this},D3D.Box.prototype.getInfoLog=function(t){"use strict";return getAPI(self.api+"info/logfiles",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.getInfoAcces=function(t){"use strict";return getAPI(self.api+"info/acces",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.getNetwerkScan=function(t){"use strict";return getAPI(self.api+"network/scan",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.getNetworkKnown=function(t){"use strict";return getAPI(self.api+"network/known",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.getNetworkStatus=function(t){"use strict";return getAPI(self.api+"network/status",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.setNetworkAssosiate=function(t){"use strict";return sendAPI(self.api+"network/assosiate",t),this},D3D.Box.prototype.setNetworkDisassosiate=function(t){"use strict";return sendAPI(self.api+"network/displayassosiate",t),this},D3D.Box.prototype.setNetworkOpenap=function(t){"use strict";return sendAPI(self.api+"network/openap",t),this},D3D.Box.prototype.setNetworkRemove=function(t){"use strict";return sendAPI(self.api+"network/displayassosiate",{ssid:t}),this},D3D.Box.prototype.getNetworkAlive=function(t){"use strict";return getAPI(self.api+"network/alive",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.getPrinterListAll=function(t){"use strict";return getAPI(self.api+"printer/listall",function(e){void 0!==t&&t(e)}),this},D3D.Box.prototype.setPrinterHeatup=function(t){"use strict";return sendAPI(self.api+"printer/heatup",t),this},D3D.Box.prototype.getVersion=function(t){"use strict";return getAPI(self.api+"system/fwversion",function(t){void 0!==callback&&callback(t)}),this},D3D.Printer=function(t){"use strict";this.status={},this.config={};for(var e in t)0===e.indexOf("printer")&&(this.config[e]=t[e])},D3D.Printer.prototype.getStartCode=function(){"use strict";var t=this.config["printer.startcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.getEndCode=function(){"use strict";var t=this.config["printer.endcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.subsituteVariables=function(t){"use strict";var e=this.config["printer.temperature"],i=this.config["printer.bed.temperature"],r=this.config["printer.heatup.temperature"],n=this.config["printer.heatup.bed.temperature"],o=this.config["printer.type"],s=this.config["printer.heatedbed"];switch(o){case"makerbot_replicator2":o="r2";break;case"makerbot_replicator2x":o="r2x";break;case"makerbot_thingomatic":o="t6";break;case"makerbot_generic":o="r2";break;case"_3Dison_plus":o="r2"}var a=s?"":";";return t=t.replace(/{printingTemp}/gi,e),t=t.replace(/{printingBedTemp}/gi,i),t=t.replace(/{preheatTemp}/gi,r),t=t.replace(/{preheatBedTemp}/gi,n),t=t.replace(/{printerType}/gi,o),t=t.replace(/{if heatedBed}/gi,a)},D3D.Slicer=function(){"use strict";this.geometry,this.lines=[]},D3D.Slicer.prototype.setGeometry=function(t){"use strict";return this.geometry=t,this.geometry.mergeVertices(),this.createLines(),this},D3D.Slicer.prototype.createLines=function(){"use strict";function t(t,r){var n=e[t+"_"+r]||e[r+"_"+t];return void 0===n&&(n=i.lines.length,e[t+"_"+r]=n,i.lines.push({line:new THREE.Line3(i.geometry.vertices[t],i.geometry.vertices[r]),connects:[],normals:[]})),n}this.lines=[];for(var e={},i=this,r=0;rn;n+=e){r.set(new THREE.Vector3(0,-1,0),n);for(var o=[],s=[],a=0;a0)break;h=-1}else h=-1}f.length>0&&(f.push({X:f[0].X,Y:f[0].Y}),o.push(f))}if(!(o.length>0))break;i.push(o)}return i},D3D.Slicer.prototype.getInset=function(t,e){"use strict";var i=new ClipperLib.Paths,r=new ClipperLib.ClipperOffset(1,1);return r.AddPaths(t,ClipperLib.JoinType.jtRound,ClipperLib.EndType.etClosedPolygon),r.Execute(i,-e),i},D3D.Slicer.prototype.getFillTemplate=function(t,e,i,r){"use strict";var n=new ClipperLib.Paths;if(i)for(var o=0;t>=o;o+=e)n.push([{X:o,Y:0},{X:o,Y:t}]);if(r)for(var o=0;t>=o;o+=e)n.push([{X:0,Y:o},{X:t,Y:o}]);return n},D3D.Slicer.prototype.slicesToData=function(t,e){"use strict";for(var i=100,r=e.config["printer.layerHeight"]*i,n=e.config["printer.dimensions.z"]*i,o=e.config["printer.wallThickness"]*i,s=e.config["printer.shellThickness"]*i,a=e.config["printer.fillSize"]*i,p=(e.config["printer.brimOffset"]*i,[]),c=this.getFillTemplate(n,a,!0,!0),l=0;ld;d+=o){var g=this.getInset(h,d);f=f.concat(g)}for(var y=g||h,v=!1,d=1;s/r>d;d++){var m=ClipperLib.JS.Clone(t[l+d]);if(ClipperLib.JS.ScaleUpPaths(m,i),0===m.length||v&&0===v.length){v=[];break}if(v===!1)v=m;else{var D=new ClipperLib.Clipper,b=new ClipperLib.Paths;D.AddPaths(m,ClipperLib.PolyType.ptSubject,!0),D.AddPaths(v,ClipperLib.PolyType.ptClip,!0),D.Execute(ClipperLib.ClipType.ctIntersection,b),v=b}}var w=new ClipperLib.Clipper,P=new ClipperLib.Paths;w.AddPaths(y,ClipperLib.PolyType.ptSubject,!0),w.AddPaths(v,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctDifference,P);var w=new ClipperLib.Clipper,C=new ClipperLib.Paths;w.AddPaths(y,ClipperLib.PolyType.ptSubject,!0),w.AddPaths(P,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctDifference,C);var x=[],w=new ClipperLib.Clipper,T=new ClipperLib.Paths;w.AddPaths(c,ClipperLib.PolyType.ptSubject,!1),w.AddPaths(C,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctIntersection,T),x=x.concat(T);var L=this.getFillTemplate(n,o,l%2===0,l%2===1),w=new ClipperLib.Clipper,S=new ClipperLib.Paths;w.AddPaths(L,ClipperLib.PolyType.ptSubject,!1),w.AddPaths(P,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctIntersection,S),x=x.concat(S),ClipperLib.JS.ScaleDownPaths(h,i),ClipperLib.JS.ScaleDownPaths(f,i),ClipperLib.JS.ScaleDownPaths(x,i),p.push({outerLayer:h,innerLayer:f,fill:x})}return p},D3D.Slicer.prototype.dataToGcode=function(t,e){"use strict";function i(t){for(var e=[],i=0;if&&u&&e.push(["G0","E"+(y-d).toFixed(3),"F"+(60*h).toFixed(3)].join(" ")),e.push(["G0","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+P,"F"+60*p].join(" ")),y>f&&u&&e.push(["G0","E"+y.toFixed(3),"F"+(60*h).toFixed(3)].join(" "));else{var c=(new THREE.Vector2).set(a.X,a.Y),g=(new THREE.Vector2).set(n.X,n.Y),b=c.distanceTo(g);y+=b*l*r/m*D,e.push(["G1","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+P,"F"+v,"E"+y.toFixed(3)].join(" "))}n=a}return e}for(var r=e.config["printer.layerHeight"],n=e.config["printer.speed"],o=e.config["printer.bottomLayerSpeed"],s=e.config["printer.firstLayerSlow"],a=e.config["printer.bottomFlowRate"],p=e.config["printer.travelSpeed"],c=e.config["printer.filamentThickness"],l=e.config["printer.wallThickness"],u=(e.config["printer.enableTraveling"],e.config["printer.retraction.enabled"]),h=e.config["printer.retraction.speed"],f=e.config["printer.retraction.minDistance"],d=e.config["printer.retraction.amount"],g=e.getStartCode(),y=0,v=s?(60*o).toFixed(3):(60*n).toFixed(3),m=Math.pow(c/2,2)*Math.PI,D=a,b=0;bl;l++){var u=a[l%a.length];r(u.outerLayer,"red"),r(u.innerLayer,"green"),r(u.fill,"blue")}return p},D3D.Slicer.prototype.getGcode=function(t){"use strict";var e=t.config["printer.layerHeight"],i=t.config["printer.dimensions.z"],r=this.slice(i,e);r.shift();var n=this.slicesToData(r,t),o=this.dataToGcode(n,t);return o}; \ No newline at end of file +function sendAPI(t,e,i){"use strict";$.ajax({url:t,type:"POST",data:e,dataType:"json",timeout:1e4,success:function(t){"success"===t.status?void 0!==i&&i(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),sendAPI(t,e,i)})}function getAPI(t,e){"use strict";$.ajax({url:t,dataType:"json",timeout:5e3,success:function(t){"success"===t.status?void 0!==e&&e(t.data):console.warn(t.msg)}}).fail(function(){console.warn("failed connecting to "+t),getAPI(t,e)})}function downloadFile(t,e){"use strict";$(document.createElement("a")).attr({download:t,href:"data:text/plain,"+e})[0].click()}function applyMouseControls(t,e,i){"use strict";function r(){e.position.x=Math.cos(s)*Math.sin(o)*n,e.position.y=Math.sin(s)*n,e.position.z=Math.cos(s)*Math.cos(o)*n,e.lookAt(new THREE.Vector3(0,0,0))}var n=20,o=0,s=0,a=!1;$(t.domElement).on("mousedown",function(t){a=!0}).on("wheel",function(t){var e=t.originalEvent;e.preventDefault(),n=THREE.Math.clamp(n-e.wheelDelta,1,i),r()}),$(window).on("mouseup",function(t){a=!1}).on("mousemove",function(t){var e=t.originalEvent;a===!0&&(o=(o-e.webkitMovementX/100)%(2*Math.PI),s=THREE.Math.clamp(s+e.webkitMovementY/100,-Math.PI/2,Math.PI/2),r())}),r()}var D3D={version:"0.1",website:"http://www.doodle3d.com/",contact:"develop@doodle3d.com"};THREE.Vector2.prototype.normal=function(){"use strict";var t=this.y,e=-this.x;return this.set(t,e)},Array.prototype.clone=function(){"use strict";for(var t=[],e=0;e0?this.printBatch():this.updateState()},D3D.Box.prototype.updateState=function(){"use strict";var t=this;getAPI(this.api+"info/status",function(e){t.printer.status=e,t.update()})},D3D.Box.prototype.print=function(t){"use strict";for(this.currentBatch=0,t=t.clone();t.length>0;){var e=t.splice(0,Math.min(this.batchSize,t.length));this.printBatches.push(e)}return this},D3D.Box.prototype.printBatch=function(){"use strict";var t=this,e=this.printBatches.shift();sendAPI(this.api+"printer/print",{start:0===this.currentBatch?!0:!1,first:0===this.currentBatch?!0:!1,gcode:e.join("\n")},function(e){console.log("batch sent: "+t.currentBatch,e),t.printBatches.length>0&&t.currentBatch++,t.updateState()})},D3D.Box.prototype.stopPrint=function(){"use strict";this.printBatches=[],this.currentBatch=0;var t=["M107 ;fan off","G91 ;relative positioning","G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure","G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more","G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way","M84 ;disable axes / steppers","G90 ;absolute positioning","M104 S180",";M140 S70","M117 Done ;display message (20 characters to clear whole screen)"];return sendAPI(this.api+"printer/stop",{gcode:t.join("\n")},function(t){console.log("Printer stop command sent")}),this},D3D.Box.prototype.setConfig=function(t,e){"use strict";return sendAPI(this.api+"config",t,e),this},D3D.Box.prototype.getInfo=function(t){"use strict";getAPI(this.api+"info",t)},D3D.Box.prototype.downloadInfoLog=function(t){"use strict";window.location=this.api+"info/logfiles"},D3D.Box.prototype.getInfoAcces=function(t){"use strict";return getAPI(this.api+"info/access",t),this},D3D.Box.prototype.getNetworkScan=function(t){"use strict";return getAPI(this.api+"network/scan",t),this},D3D.Box.prototype.getNetworkKnown=function(t){"use strict";return getAPI(this.api+"network/known",t),this},D3D.Box.prototype.getNetworkStatus=function(t){"use strict";return getAPI(this.api+"network/status",t),this},D3D.Box.prototype.setNetworkAssosiate=function(t,e){"use strict";return sendAPI(this.api+"network/associate",t,e),this},D3D.Box.prototype.setNetworkDisassosiate=function(t){"use strict";return sendAPI(this.api+"network/disassociate",{},t),this},D3D.Box.prototype.setNetworkOpenAP=function(t){"use strict";return sendAPI(this.api+"network/openap",{},t),this},D3D.Box.prototype.setNetworkRemove=function(t,e){"use strict";return sendAPI(this.api+"network/remove",{ssid:t},e),this},D3D.Box.prototype.getNetworkAlive=function(t){"use strict";return getAPI(this.api+"network/alive",t),this},D3D.Box.prototype.getPrinterListAll=function(t){"use strict";return getAPI(this.api+"printer/listall",t),this},D3D.Box.prototype.setPrinterHeatup=function(t){"use strict";return sendAPI(this.api+"printer/heatup",{},t),this},D3D.Box.prototype.getSystemVersions=function(t){"use strict";return getAPI(this.api+"system/fwversions",t),this},D3D.Box.prototype.getUpdateStatus=function(t){"use strict";return getAPI(this.api+"update/status",t),this},D3D.Box.prototype.setUpdateDownload=function(t){"use strict";return sendAPI(this.api+"update/download",{},t),this},D3D.Box.prototype.setUpdateInstall=function(t){"use strict";return sendAPI(this.api+"update/install",{},t),this},D3D.Box.prototype.setUpdateClear=function(t){"use strict";return sendAPI(this.api+"update/clear",{},t),this},D3D.Printer=function(t){"use strict";this.status={},this.config={};for(var e in t)0===e.indexOf("printer")&&(this.config[e]=t[e])},D3D.Printer.prototype.getStartCode=function(){"use strict";var t=this.config["printer.startcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.getEndCode=function(){"use strict";var t=this.config["printer.endcode"];return t=this.subsituteVariables(t),t.split("\n")},D3D.Printer.prototype.subsituteVariables=function(t){"use strict";var e=this.config["printer.temperature"],i=this.config["printer.bed.temperature"],r=this.config["printer.heatup.temperature"],n=this.config["printer.heatup.bed.temperature"],o=this.config["printer.type"],s=this.config["printer.heatedbed"];switch(o){case"makerbot_replicator2":o="r2";break;case"makerbot_replicator2x":o="r2x";break;case"makerbot_thingomatic":o="t6";break;case"makerbot_generic":o="r2";break;case"_3Dison_plus":o="r2"}var a=s?"":";";return t=t.replace(/{printingTemp}/gi,e),t=t.replace(/{printingBedTemp}/gi,i),t=t.replace(/{preheatTemp}/gi,r),t=t.replace(/{preheatBedTemp}/gi,n),t=t.replace(/{printerType}/gi,o),t=t.replace(/{if heatedBed}/gi,a)},D3D.Slicer=function(){"use strict";this.geometry,this.lines=[]},D3D.Slicer.prototype.setGeometry=function(t){"use strict";return t instanceof THREE.BufferGeometry&&(t=(new THREE.Geometry).fromBufferGeometry(t)),this.geometry=t.clone(),this.geometry.mergeVertices(),this.createLines(),this},D3D.Slicer.prototype.createLines=function(){"use strict";function t(t,r){var n=e[t+"_"+r]||e[r+"_"+t];return void 0===n&&(n=i.lines.length,e[t+"_"+r]=n,i.lines.push({line:new THREE.Line3(i.geometry.vertices[t],i.geometry.vertices[r]),connects:[],normals:[]})),n}this.lines=[];for(var e={},i=this,r=0;rn;n+=e){r.set(new THREE.Vector3(0,-1,0),n);for(var o=[],s=[],a=0;a0)break;h=-1}else h=-1}f.length>0&&(f.push({X:f[0].X,Y:f[0].Y}),o.push(f))}if(!(o.length>0))break;i.push(o)}return i},D3D.Slicer.prototype.getInset=function(t,e){"use strict";var i=new ClipperLib.Paths,r=new ClipperLib.ClipperOffset(1,1);return r.AddPaths(t,ClipperLib.JoinType.jtRound,ClipperLib.EndType.etClosedPolygon),r.Execute(i,-e),i},D3D.Slicer.prototype.getFillTemplate=function(t,e,i,r){"use strict";var n=new ClipperLib.Paths;if(i)for(var o=0;t>=o;o+=e)n.push([{X:o,Y:0},{X:o,Y:t}]);if(r)for(var o=0;t>=o;o+=e)n.push([{X:0,Y:o},{X:t,Y:o}]);return n},D3D.Slicer.prototype.slicesToData=function(t,e){"use strict";for(var i=100,r=e.config["printer.layerHeight"]*i,n=e.config["printer.dimensions.z"]*i,o=e.config["printer.wallThickness"]*i,s=e.config["printer.shellThickness"]*i,a=e.config["printer.fillSize"]*i,p=(e.config["printer.brimOffset"]*i,[]),c=this.getFillTemplate(n,a,!0,!0),l=0;ld;d+=o){var g=this.getInset(h,d);f=f.concat(g)}for(var y=g||h,D=!1,d=1;s/r>d;d++){var m=ClipperLib.JS.Clone(t[l+d]);if(ClipperLib.JS.ScaleUpPaths(m,i),0===m.length||D&&0===D.length){D=[];break}if(D===!1)D=m;else{var v=new ClipperLib.Clipper,b=new ClipperLib.Paths;v.AddPaths(m,ClipperLib.PolyType.ptSubject,!0),v.AddPaths(D,ClipperLib.PolyType.ptClip,!0),v.Execute(ClipperLib.ClipType.ctIntersection,b),D=b}}var w=new ClipperLib.Clipper,P=new ClipperLib.Paths;w.AddPaths(y,ClipperLib.PolyType.ptSubject,!0),w.AddPaths(D,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctDifference,P);var w=new ClipperLib.Clipper,x=new ClipperLib.Paths;w.AddPaths(y,ClipperLib.PolyType.ptSubject,!0),w.AddPaths(P,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctDifference,x);var C=[],w=new ClipperLib.Clipper,T=new ClipperLib.Paths;w.AddPaths(c,ClipperLib.PolyType.ptSubject,!1),w.AddPaths(x,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctIntersection,T),C=C.concat(T);var L=this.getFillTemplate(n,o,l%2===0,l%2===1),w=new ClipperLib.Clipper,A=new ClipperLib.Paths;w.AddPaths(L,ClipperLib.PolyType.ptSubject,!1),w.AddPaths(P,ClipperLib.PolyType.ptClip,!0),w.Execute(ClipperLib.ClipType.ctIntersection,A),C=C.concat(A),ClipperLib.JS.ScaleDownPaths(h,i),ClipperLib.JS.ScaleDownPaths(f,i),ClipperLib.JS.ScaleDownPaths(C,i),p.push({outerLayer:h,innerLayer:f,fill:C})}return p},D3D.Slicer.prototype.dataToGcode=function(t,e){"use strict";function i(t){for(var e=[],i=0;if&&u&&e.push(["G0","E"+(y-d).toFixed(3),"F"+(60*h).toFixed(3)].join(" ")),e.push(["G0","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+P,"F"+60*p].join(" ")),y>f&&u&&e.push(["G0","E"+y.toFixed(3),"F"+(60*h).toFixed(3)].join(" "));else{var c=(new THREE.Vector2).set(a.X,a.Y),g=(new THREE.Vector2).set(n.X,n.Y),b=c.distanceTo(g);y+=b*l*r/m*v,e.push(["G1","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+P,"F"+D,"E"+y.toFixed(3)].join(" "))}n=a}return e}for(var r=e.config["printer.layerHeight"],n=e.config["printer.speed"],o=e.config["printer.bottomLayerSpeed"],s=e.config["printer.firstLayerSlow"],a=e.config["printer.bottomFlowRate"],p=e.config["printer.travelSpeed"],c=e.config["printer.filamentThickness"],l=e.config["printer.wallThickness"],u=(e.config["printer.enableTraveling"],e.config["printer.retraction.enabled"]),h=e.config["printer.retraction.speed"],f=e.config["printer.retraction.minDistance"],d=e.config["printer.retraction.amount"],g=e.getStartCode(),y=0,D=s?(60*o).toFixed(3):(60*n).toFixed(3),m=Math.pow(c/2,2)*Math.PI,v=a,b=0;bl;l++){var u=a[l%a.length];r(u.outerLayer,"red"),r(u.innerLayer,"green"),r(u.fill,"blue")}return p},D3D.Slicer.prototype.getGcode=function(t){"use strict";var e=t.config["printer.layerHeight"],i=t.config["printer.dimensions.z"],r=this.slice(i,e);r.shift();var n=this.slicesToData(r,t),o=this.dataToGcode(n,t);return o}; \ No newline at end of file diff --git a/index.html b/index.html index 80d7d38..ceaac8c 100644 --- a/index.html +++ b/index.html @@ -23,19 +23,23 @@ $(document).ready(function () { listDoodle.append("
  • Wired Printer
  • "); listSliceTest.append("
  • Wired Printer
  • "); - /*printers.push({ + /* + printers.push({ name: "wired box", d3dbox: new D3D.Box("192.168.5.1") - });*/ + }); + */ getAPI(api + "list.php", function (boxes) { for (var i = 0; i < boxes.length; i ++) { var box = boxes[i]; - /*printers.push({ + /* + printers.push({ name: box.wifiboxid, d3dbox: new D3D.Box(box.localip) - });*/ + }); + */ listDoodle.append("
  • " + box.wifiboxid + "
  • "); listSliceTest.append("
  • " + box.wifiboxid + "
  • "); @@ -49,7 +53,8 @@ $(document).ready(function () {

    Slice Test

      - - + +--> \ No newline at end of file diff --git a/slice_test.html b/slice_test.html index db22beb..3daa32a 100644 --- a/slice_test.html +++ b/slice_test.html @@ -87,7 +87,7 @@ var geometry = (function () { var hole = new THREE.Path(); hole.absarc(0, 0, 5, 0, Math.PI*2, true ); - //circle.holes.push(hole); + circle.holes.push(hole); var matrix = new THREE.Matrix4(); matrix.makeRotationX(Math.PI*1.5); @@ -123,7 +123,8 @@ var layer = 149; var img = slicer.drawPaths(printer, layer, layer + 1); context.drawImage(img, 0, 0); -/*var loader = new THREE.STLLoader(); +/* +var loader = new THREE.STLLoader(); loader.load('stl/overhang_test.stl', function (geometry) { var matrix = new THREE.Matrix4(); @@ -140,8 +141,14 @@ loader.load('stl/overhang_test.stl', function (geometry) { var slicer = new D3D.Slicer().setGeometry(geometry); - //gcode = slicer.getGcode(printer); -});*/ + var layer = 149; + var img = slicer.drawPaths(printer, layer, layer + 1); + context.drawImage(img, 0, 0); + + var gcode = slicer.getGcode(printer); + console.log(gcode); +}); +*/ (function animate () { "use strict"; diff --git a/src/box.js b/src/box.js index f40c74a..11fb39b 100644 --- a/src/box.js +++ b/src/box.js @@ -3,6 +3,8 @@ * Box * Representation of de Doodle3DBox * Handles all communication with the doodle box +* JavaScript shell for api communication +* Check http://www.doodle3d.com/help/api-documentation * ******************************************************/ @@ -93,12 +95,12 @@ D3D.Box.prototype.printBatch = function () { var gcode = this.printBatches.shift(); sendAPI(this.api + "printer/print", { - "start": ((this.currentBatch === 0) ? "true" : "false"), - "first": ((this.currentBatch === 0) ? "true" : "false"), + "start": ((this.currentBatch === 0) ? true : false), + "first": ((this.currentBatch === 0) ? true : false), "gcode": gcode.join("\n") }, function (data) { - console.log("batch sent: " + self.currentBatch, data); + if (self.printBatches.length > 0) { //sent new batch self.currentBatch ++; @@ -110,7 +112,7 @@ D3D.Box.prototype.printBatch = function () { self.updateState(); }); }; -D3D.Box.prototype.stop = function () { +D3D.Box.prototype.stopPrint = function () { "use strict"; this.printBatches = []; @@ -131,148 +133,160 @@ D3D.Box.prototype.stop = function () { sendAPI(this.api + "printer/stop", { "gcode": finishMove.join("\n") - //"gcode": {} }, function (data) { console.log("Printer stop command sent"); }); return this; }; -D3D.Box.prototype.setConfig = function (data) { +D3D.Box.prototype.setConfig = function (data, callback) { + //works "use strict"; - sendAPI(this.api + "config", data); + sendAPI(this.api + "config", data, callback); return this; }; -D3D.Box.prototype.getInfoLog = function (callback) { +D3D.Box.prototype.getInfo = function (callback) { + //works "use strict"; - getAPI(this.api + "info/logfiles", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "info", callback); +}; +D3D.Box.prototype.downloadInfoLog = function (callback) { + //works in google chrome... not tested in other browsers + //some browsers may redirect using this code + "use strict"; - return this; + window.location = this.api + "info/logfiles"; }; D3D.Box.prototype.getInfoAcces = function (callback) { + //works "use strict"; - //error - //cannot call function or module 'info/acces' ('module/function 'info/acces' does not exist') - - getAPI(this.api + "info/acces", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "info/access", callback); return this; }; -D3D.Box.prototype.getNetwerkScan = function (callback) { +D3D.Box.prototype.getNetworkScan = function (callback) { + //works "use strict"; - getAPI(this.api + "network/scan", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/scan", callback); return this; }; D3D.Box.prototype.getNetworkKnown = function (callback) { + //works "use strict"; - getAPI(this.api + "network/known", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/known", callback); return this; }; D3D.Box.prototype.getNetworkStatus = function (callback) { + //works "use strict"; - getAPI(this.api + "network/status", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/status", callback); return this; }; -D3D.Box.prototype.setNetworkAssosiate = function (data) { +D3D.Box.prototype.setNetworkAssosiate = function (data, callback) { + //works "use strict"; - sendAPI(this.api + "network/assosiate", data); + sendAPI(this.api + "network/associate", data, callback); return this; }; -D3D.Box.prototype.setNetworkDisassosiate = function (data) { +D3D.Box.prototype.setNetworkDisassosiate = function (callback) { + //not tested "use strict"; - sendAPI(this.api + "network/displayassosiate", data); + sendAPI(this.api + "network/disassociate", {}, callback); return this; }; -D3D.Box.prototype.setNetworkOpenap = function (data) { +D3D.Box.prototype.setNetworkOpenAP = function (callback) { + //not tested "use strict"; - sendAPI(this.api + "network/openap", data); + sendAPI(this.api + "network/openap", {}, callback); return this; }; -D3D.Box.prototype.setNetworkRemove = function (ssid) { +D3D.Box.prototype.setNetworkRemove = function (ssid, callback) { + //works "use strict"; - sendAPI(this.api + "network/displayassosiate", {ssid: ssid}); + sendAPI(this.api + "network/remove", { + ssid: ssid + }, callback); return this; }; D3D.Box.prototype.getNetworkAlive = function (callback) { + //works but returns empty array "use strict"; - //emty? - - getAPI(this.api + "network/alive", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "network/alive", callback); return this; }; D3D.Box.prototype.getPrinterListAll = function (callback) { + //works "use strict"; - getAPI(this.api + "printer/listall", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "printer/listall", callback); return this; }; -D3D.Box.prototype.setPrinterHeatup = function (data) { +D3D.Box.prototype.setPrinterHeatup = function (callback) { + //works "use strict"; - sendAPI(this.api + "printer/heatup", data); + sendAPI(this.api + "printer/heatup", {}, callback); return this; }; -D3D.Box.prototype.getVersion = function (data) { +D3D.Box.prototype.getSystemVersions = function (callback) { + //works "use strict"; - //error - //cannot call function or module 'system/fwversion' ('module/function 'system/fwversion' does not exist') + getAPI(this.api + "system/fwversions", callback); + + return this; +}; +D3D.Box.prototype.getUpdateStatus = function (callback) { + //not tested + "use strict"; - getAPI(this.api + "system/fwversion", function (data) { - if (callback !== undefined) { - callback(data); - } - }); + getAPI(this.api + "update/status", callback); + + return this; +}; +D3D.Box.prototype.setUpdateDownload = function (callback) { + //not tested + "use strict"; + + sendAPI(this.api + "update/download", {}, callback); + + return this; +}; +D3D.Box.prototype.setUpdateInstall = function (callback) { + //not tested + "use strict"; + + sendAPI(this.api + "update/install", {}, callback); + + return this; +}; +D3D.Box.prototype.setUpdateClear = function (callback) { + //not tested + "use strict"; + + sendAPI(this.api + "update/clear", {}, callback); return this; }; \ No newline at end of file