diff --git a/build/d3d.js b/build/d3d.js index 41365e2..b0e8624 100644 --- a/build/d3d.js +++ b/build/d3d.js @@ -173,8 +173,6 @@ D3D.Box = function (localIp) { this.onload; getAPI(self.api + "config/all", function (data) { - //self.config = data; - for (var i in data) { if (i.indexOf("doodle3d") === 0) { self.config[i] = data[i]; @@ -229,6 +227,8 @@ D3D.Box.prototype.print = function (gcode) { var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length)); this.printBatches.push(gcodeBatch); } + + return this; }; D3D.Box.prototype.printBatch = function () { "use strict"; @@ -279,6 +279,138 @@ D3D.Box.prototype.stop = function () { }, function (data) { console.log("Printer stop command sent"); }); + + return this; +}; +D3D.Box.prototype.setConfig = function (data) { + "use strict"; + + sendAPI(this.api + "config", data); + + return this; +}; +D3D.Box.prototype.getInfoLog = function (callback) { + "use strict"; + + getAPI(self.api + "info/logfiles", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getInfoAcces = function (callback) { + "use strict"; + + getAPI(self.api + "info/acces", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getNetwerkScan = function (callback) { + "use strict"; + + getAPI(self.api + "network/scan", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getNetworkKnown = function (callback) { + "use strict"; + + getAPI(self.api + "network/known", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getNetworkStatus = function (callback) { + "use strict"; + + getAPI(self.api + "network/status", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.setNetworkAssosiate = function (data) { + "use strict"; + + sendAPI(self.api + "network/assosiate", data); + + return this; +}; +D3D.Box.prototype.setNetworkDisassosiate = function (data) { + "use strict"; + + sendAPI(self.api + "network/displayassosiate", data); + + return this; +}; +D3D.Box.prototype.setNetworkOpenap = function (data) { + "use strict"; + + sendAPI(self.api + "network/openap", data); + + return this; +}; +D3D.Box.prototype.setNetworkRemove = function (ssid) { + "use strict"; + + sendAPI(self.api + "network/displayassosiate", {ssid: ssid}); + + return this; +}; +D3D.Box.prototype.getNetworkAlive = function (callback) { + "use strict"; + + getAPI(self.api + "network/alive", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getPrinterListAll = function (callback) { + "use strict"; + + getAPI(self.api + "printer/listall", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.setPrinterHeatup = function (data) { + "use strict"; + + sendAPI(self.api + "printer/heatup", data); + + return this; +}; +D3D.Box.prototype.getVersion = function (data) { + "use strict"; + + getAPI(self.api + "system/fwversion", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; }; /****************************************************** * @@ -363,7 +495,6 @@ D3D.Slicer = function () { this.geometry; this.lines = []; - this.lineLookup = {}; }; D3D.Slicer.prototype.setGeometry = function (geometry) { "use strict"; @@ -375,30 +506,32 @@ D3D.Slicer.prototype.setGeometry = function (geometry) { return this; }; -D3D.Slicer.prototype.addLine = function (a, b) { - "use strict"; - - //think lookup can only be b_a, a_b is only possible when face is flipped - var index = this.lineLookup[a + "_" + b] || this.lineLookup[b + "_" + a]; - - if (index === undefined) { - index = this.lines.length; - this.lineLookup[a + "_" + b] = index; - - this.lines.push({ - line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]), - connects: [], - normals: [] - }); - } - - return index; -}; D3D.Slicer.prototype.createLines = function () { "use strict"; this.lines = []; - this.lineLookup = {}; + var lineLookup = {}; + + var self = this; + function addLine (a, b) { + "use strict"; + + //think lookup can only be b_a, a_b is only possible when face is flipped + var index = lineLookup[a + "_" + b] || lineLookup[b + "_" + a]; + + if (index === undefined) { + index = self.lines.length; + lineLookup[a + "_" + b] = index; + + self.lines.push({ + line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]), + connects: [], + normals: [] + }); + } + + return index; + }; for (var i = 0; i < this.geometry.faces.length; i ++) { var face = this.geometry.faces[i]; @@ -406,9 +539,9 @@ D3D.Slicer.prototype.createLines = function () { //check for only adding unique lines //returns index of said line - var a = this.addLine(face.a, face.b); - var b = this.addLine(face.b, face.c); - var c = this.addLine(face.c, face.a); + var a = addLine(face.a, face.b); + var b = addLine(face.b, face.c); + var c = addLine(face.c, face.a); //set connecting lines (based on face) @@ -497,6 +630,7 @@ D3D.Slicer.prototype.slice = function (height, step) { //think this check is not nescesary, always higher as 0 if (shape.length > 0) { + shape.push({X: shape[0].X, Y: shape[0].Y}); slice.push(shape); } } @@ -573,13 +707,13 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { innerLayer = innerLayer.concat(inset); } - var fillArea = this.getInset((inset || outerLayer), wallThickness); + //moet fillArea wel kleiner? + //var fillArea = this.getInset((inset || outerLayer), wallThickness); + var fillArea = (inset || outerLayer); - var highFill; - - var fillAbove = undefined; + var fillAbove = false; //for (var i = 1; i < shellThickness/layerHeight; i ++) { - for (var i = 1; i < shellThickness/layerHeight + 4; i ++) { + for (var i = 1; i < shellThickness/layerHeight; i ++) { var newLayer = ClipperLib.JS.Clone(slices[layer + i]); ClipperLib.JS.ScaleUpPaths(newLayer, scale); @@ -588,13 +722,13 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { break; } - else if (fillAbove === undefined) { + else if (fillAbove === false) { fillAbove = newLayer; } else { var c = new ClipperLib.Clipper(); var solution = new ClipperLib.Paths(); - c.AddPaths(fillArea, ClipperLib.PolyType.ptSubject, true); + c.AddPaths(newLayer, ClipperLib.PolyType.ptSubject, true); c.AddPaths(fillAbove, ClipperLib.PolyType.ptClip, true); c.Execute(ClipperLib.ClipType.ctIntersection, solution); @@ -675,7 +809,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { var retractionSpeed = printer.config["printer.retraction.speed"]; var retractionMinDistance = printer.config["printer.retraction.minDistance"]; var retractionAmount = printer.config["printer.retraction.amount"]; - + function sliceToGcode (slice) { var gcode = []; @@ -684,9 +818,8 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { var previousPoint; - for (var j = 0; j <= shape.length; j ++) { - //Finish shape by going to first point - var point = shape[(j % shape.length)]; + for (var j = 0; j < shape.length; j ++) { + var point = shape[j]; if (j === 0) { //TODO @@ -782,7 +915,7 @@ D3D.Slicer.prototype.drawPaths = function (printer, min, max) { var point = path[j]; context.lineTo((point.X- 100) * 6.0 + 200, (point.Y- 100) * 6.0 + 200); } - context.closePath(); + //context.closePath(); } context.stroke(); } @@ -798,8 +931,6 @@ D3D.Slicer.prototype.drawPaths = function (printer, min, max) { var context = canvas.getContext("2d"); for (var layer = min; layer < max; layer ++) { - var layer = 0; - context.clearRect(0, 0, 400, 400); var slice = data[layer % data.length]; drawPolygons(slice.outerLayer, "red"); diff --git a/build/d3d.min.js b/build/d3d.min.js index 93bbb4e..a67edf9 100644 --- a/build/d3d.min.js +++ b/build/d3d.min.js @@ -1 +1 @@ -function sendAPI(e,t,i){"use strict";$.ajax({url:e,type:"POST",data:t,dataType:"json",timeout:1e4,success:function(e){"success"===e.status?void 0!==i&&i(e.data):console.warn(e.msg)}}).fail(function(){console.warn("failed connecting to "+e),sendAPI(e,t,i)})}function getAPI(e,t){"use strict";$.ajax({url:e,dataType:"json",timeout:5e3,success:function(e){"success"===e.status?void 0!==t&&t(e.data):console.warn(e.msg)}}).fail(function(){console.warn("failed connecting to "+e),getAPI(e,t)})}function downloadFile(e,t){"use strict";$(document.createElement("a")).attr({download:e,href:"data:text/plain,"+t})[0].click()}function applyMouseControls(e,t,i){"use strict";function r(){t.position.x=Math.cos(s)*Math.sin(o)*n,t.position.y=Math.sin(s)*n,t.position.z=Math.cos(s)*Math.cos(o)*n,t.lookAt(new THREE.Vector3(0,0,0))}var n=20,o=0,s=0,a=!1;$(e.domElement).on("mousedown",function(e){a=!0}).on("wheel",function(e){var t=e.originalEvent;t.preventDefault(),n=THREE.Math.clamp(n-t.wheelDelta,1,i),r()}),$(window).on("mouseup",function(e){a=!1}).on("mousemove",function(e){var t=e.originalEvent;a===!0&&(o=(o-t.webkitMovementX/100)%(2*Math.PI),s=THREE.Math.clamp(s+t.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 e=this.y,t=-this.x;return this.set(e,t)},Array.prototype.clone=function(){"use strict";for(var e=[],t=0;t0?this.printBatch():this.updateState()},D3D.Box.prototype.updateState=function(){"use strict";var e=this;getAPI(this.api+"info/status",function(t){e.printer.status=t,e.update()})},D3D.Box.prototype.print=function(e){"use strict";for(this.currentBatch=0,e=e.clone();e.length>0;){var t=e.splice(0,Math.min(this.batchSize,e.length));this.printBatches.push(t)}},D3D.Box.prototype.printBatch=function(){"use strict";var e=this,t=this.printBatches.shift();sendAPI(this.api+"printer/print",{start:0===this.currentBatch?"true":"false",first:0===this.currentBatch?"true":"false",gcode:t.join("\n")},function(t){console.log("batch sent: "+e.currentBatch,t),e.printBatches.length>0&&e.currentBatch++,e.updateState()})},D3D.Box.prototype.stop=function(){"use strict";this.printBatches=[],this.currentBatch=0;var e=["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)"];sendAPI(this.api+"printer/stop",{gcode:e.join("\n")},function(e){console.log("Printer stop command sent")})},D3D.Printer=function(e){"use strict";this.status={},this.config={};for(var t in e)0===t.indexOf("printer")&&(this.config[t]=e[t])},D3D.Printer.prototype.getStartCode=function(){"use strict";var e=this.config["printer.startcode"];return e=this.subsituteVariables(e),e.split("\n")},D3D.Printer.prototype.getEndCode=function(){"use strict";var e=this.config["printer.endcode"];return e=this.subsituteVariables(e),e.split("\n")},D3D.Printer.prototype.subsituteVariables=function(e){"use strict";var t=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 e=e.replace(/{printingTemp}/gi,t),e=e.replace(/{printingBedTemp}/gi,i),e=e.replace(/{preheatTemp}/gi,r),e=e.replace(/{preheatBedTemp}/gi,n),e=e.replace(/{printerType}/gi,o),e=e.replace(/{if heatedBed}/gi,a)},D3D.Slicer=function(){"use strict";this.geometry,this.lines=[],this.lineLookup={}},D3D.Slicer.prototype.setGeometry=function(e){"use strict";return this.geometry=e,this.geometry.mergeVertices(),this.createLines(),this},D3D.Slicer.prototype.addLine=function(e,t){"use strict";var i=this.lineLookup[e+"_"+t]||this.lineLookup[t+"_"+e];return void 0===i&&(i=this.lines.length,this.lineLookup[e+"_"+t]=i,this.lines.push({line:new THREE.Line3(this.geometry.vertices[e],this.geometry.vertices[t]),connects:[],normals:[]})),i},D3D.Slicer.prototype.createLines=function(){"use strict";this.lines=[],this.lineLookup={};for(var e=0;en;n+=t){r.set(new THREE.Vector3(0,-1,0),n);for(var o=[],s=[],a=0;a0)break;u=-1}else u=-1}f.length>0&&o.push(f)}if(!(o.length>0))break;i.push(o)}return i},D3D.Slicer.prototype.getInset=function(e,t){"use strict";var i=new ClipperLib.Paths,r=new ClipperLib.ClipperOffset(1,1);return r.AddPaths(e,ClipperLib.JoinType.jtRound,ClipperLib.EndType.etClosedPolygon),r.Execute(i,-t),i},D3D.Slicer.prototype.getFillTemplate=function(e,t,i,r){"use strict";var n=new ClipperLib.Paths;if(i)for(var o=0;e>=o;o+=t)n.push([{X:o,Y:0},{X:o,Y:e}]);if(r)for(var o=0;e>=o;o+=t)n.push([{X:0,Y:o},{X:e,Y:o}]);return n},D3D.Slicer.prototype.slicesToData=function(e,t){"use strict";for(var i=100,r=t.config["printer.layerHeight"]*i,n=t.config["printer.dimensions.z"]*i,o=t.config["printer.wallThickness"]*i,s=t.config["printer.shellThickness"]*i,a=t.config["printer.fillSize"]*i,p=(t.config["printer.brimOffset"]*i,[]),c=this.getFillTemplate(n,a,!0,!0),l=0;ld;d+=o){var g=this.getInset(u,d);f=f.concat(g)}for(var m=this.getInset(g||u,o),v=void 0,d=1;s/r+4>d;d++){var b=ClipperLib.JS.Clone(e[l+d]);if(ClipperLib.JS.ScaleUpPaths(b,i),0===b.length||v&&0===v.length){v=[];break}if(void 0===v)v=b;else{var y=new ClipperLib.Clipper,C=new ClipperLib.Paths;y.AddPaths(m,ClipperLib.PolyType.ptSubject,!0),y.AddPaths(v,ClipperLib.PolyType.ptClip,!0),y.Execute(ClipperLib.ClipType.ctIntersection,C),v=C}}var D=new ClipperLib.Clipper,L=new ClipperLib.Paths;D.AddPaths(m,ClipperLib.PolyType.ptSubject,!0),D.AddPaths(v,ClipperLib.PolyType.ptClip,!0),D.Execute(ClipperLib.ClipType.ctDifference,L);var D=new ClipperLib.Clipper,P=new ClipperLib.Paths;D.AddPaths(m,ClipperLib.PolyType.ptSubject,!0),D.AddPaths(L,ClipperLib.PolyType.ptClip,!0),D.Execute(ClipperLib.ClipType.ctDifference,P);var w=[],D=new ClipperLib.Clipper,T=new ClipperLib.Paths;D.AddPaths(c,ClipperLib.PolyType.ptSubject,!1),D.AddPaths(P,ClipperLib.PolyType.ptClip,!0),D.Execute(ClipperLib.ClipType.ctIntersection,T),w=w.concat(T);var x=this.getFillTemplate(n,o,l%2===0,l%2===1),D=new ClipperLib.Clipper,E=new ClipperLib.Paths;D.AddPaths(x,ClipperLib.PolyType.ptSubject,!1),D.AddPaths(L,ClipperLib.PolyType.ptClip,!0),D.Execute(ClipperLib.ClipType.ctIntersection,E),w=w.concat(E),ClipperLib.JS.ScaleDownPaths(u,i),ClipperLib.JS.ScaleDownPaths(f,i),ClipperLib.JS.ScaleDownPaths(w,i),p.push({outerLayer:u,innerLayer:f,fill:w})}return p},D3D.Slicer.prototype.dataToGcode=function(e,t){"use strict";function i(e){for(var t=[],i=0;if&&h&&t.push(["G0","E"+(m-d).toFixed(3),"F"+(60*u).toFixed(3)].join(" ")),t.push(["G0","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+L,"F"+60*p].join(" ")),m>f&&h&&t.push(["G0","E"+m.toFixed(3),"F"+(60*u).toFixed(3)].join(" "));else{var c=(new THREE.Vector2).set(a.X,a.Y),g=(new THREE.Vector2).set(n.X,n.Y),C=c.distanceTo(g);m+=C*l*r/b*y,t.push(["G1","X"+a.X.toFixed(3)+" Y"+a.Y.toFixed(3)+" Z"+L,"F"+v,"E"+m.toFixed(3)].join(" "))}n=a}return t}for(var r=t.config["printer.layerHeight"],n=t.config["printer.speed"],o=t.config["printer.bottomLayerSpeed"],s=t.config["printer.firstLayerSlow"],a=t.config["printer.bottomFlowRate"],p=t.config["printer.travelSpeed"],c=t.config["printer.filamentThickness"],l=t.config["printer.wallThickness"],h=(t.config["printer.enableTraveling"],t.config["printer.retraction.enabled"]),u=t.config["printer.retraction.speed"],f=t.config["printer.retraction.minDistance"],d=t.config["printer.retraction.amount"],g=t.getStartCode(),m=0,v=s?(60*o).toFixed(3):(60*n).toFixed(3),b=Math.pow(c/2,2)*Math.PI,y=a,C=0;Cl;l++){var l=0;c.clearRect(0,0,400,400);var h=a[l%a.length];r(h.outerLayer,"red"),r(h.innerLayer,"green"),r(h.fill,"blue")}return p},D3D.Slicer.prototype.getGcode=function(e){"use strict";var t=e.config["printer.layerHeight"],i=e.config["printer.dimensions.z"],r=this.slice(i,t);r.shift();var n=this.slicesToData(r,e),o=this.dataToGcode(n,e);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?"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 diff --git a/library/stl_loader.js b/library/stl_loader.js new file mode 100644 index 0000000..71bb4ad --- /dev/null +++ b/library/stl_loader.js @@ -0,0 +1,433 @@ +/** + * @author aleeper / http://adamleeper.com/ + * @author mrdoob / http://mrdoob.com/ + * @author gero3 / https://github.com/gero3 + * + * Description: A THREE loader for STL ASCII files, as created by Solidworks and other CAD programs. + * + * Supports both binary and ASCII encoded files, with automatic detection of type. + * + * Limitations: + * Binary decoding supports "Magics" color format (http://en.wikipedia.org/wiki/STL_(file_format)#Color_in_binary_STL). + * There is perhaps some question as to how valid it is to always assume little-endian-ness. + * ASCII decoding assumes file is UTF-8. Seems to work for the examples... + * + * Usage: + * var loader = new THREE.STLLoader(); + * loader.load( './models/stl/slotted_disk.stl', function ( geometry ) { + * scene.add( new THREE.Mesh( geometry ) ); + * }); + * + * For binary STLs geometry might contain colors for vertices. To use it: + * // use the same code to load STL as above + * if (geometry.hasColors) { + * material = new THREE.MeshPhongMaterial({ opacity: geometry.alpha, vertexColors: THREE.VertexColors }); + * } else { .... } + * var mesh = new THREE.Mesh( geometry, material ); + */ + + +THREE.STLLoader = function ( manager ) { + + this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; + +}; + +THREE.STLLoader.prototype = { + + constructor: THREE.STLLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new THREE.XHRLoader( scope.manager ); + loader.setCrossOrigin( this.crossOrigin ); + loader.setResponseType('arraybuffer'); + loader.load( url, function ( text ) { + + onLoad( scope.parse( text ) ); + + }, onProgress, onError ); + + }, + + parse: function ( data ) { + + var isBinary = function () { + + var expect, face_size, n_faces, reader; + reader = new DataView( binData ); + face_size = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8); + n_faces = reader.getUint32(80, true); + expect = 80 + (32 / 8) + (n_faces * face_size); + + if ( expect === reader.byteLength ) { + + return true; + + } + + // some binary files will have different size from expected, + // checking characters higher than ASCII to confirm is binary + var fileLength = reader.byteLength; + for ( var index = 0; index < fileLength; index ++ ) { + + if ( reader.getUint8(index, false) > 127 ) { + + return true; + + } + + } + + return false; + + }; + + var binData = this.ensureBinary( data ); + + return isBinary() + ? this.parseBinary( binData ) + : this.parseASCII( this.ensureString( data ) ); + + }, + + parseBinary: function ( data ) { + + var reader = new DataView( data ); + var faces = reader.getUint32( 80, true ); + + var r, g, b, hasColors = false, colors; + var defaultR, defaultG, defaultB, alpha; + + // process STL header + // check for default color in header ("COLOR=rgba" sequence). + + for ( var index = 0; index < 80 - 10; index ++ ) { + + if ((reader.getUint32(index, false) == 0x434F4C4F /*COLO*/) && + (reader.getUint8(index + 4) == 0x52 /*'R'*/) && + (reader.getUint8(index + 5) == 0x3D /*'='*/)) { + + hasColors = true; + colors = new Float32Array( faces * 3 * 3); + + defaultR = reader.getUint8(index + 6) / 255; + defaultG = reader.getUint8(index + 7) / 255; + defaultB = reader.getUint8(index + 8) / 255; + alpha = reader.getUint8(index + 9) / 255; + } + } + + var dataOffset = 84; + var faceLength = 12 * 4 + 2; + + var offset = 0; + + var geometry = new THREE.BufferGeometry(); + + var vertices = new Float32Array( faces * 3 * 3 ); + var normals = new Float32Array( faces * 3 * 3 ); + + for ( var face = 0; face < faces; face ++ ) { + + var start = dataOffset + face * faceLength; + var normalX = reader.getFloat32(start, true); + var normalY = reader.getFloat32(start + 4, true); + var normalZ = reader.getFloat32(start + 8, true); + + if (hasColors) { + + var packedColor = reader.getUint16(start + 48, true); + + if ((packedColor & 0x8000) === 0) { // facet has its own unique color + + r = (packedColor & 0x1F) / 31; + g = ((packedColor >> 5) & 0x1F) / 31; + b = ((packedColor >> 10) & 0x1F) / 31; + } else { + + r = defaultR; + g = defaultG; + b = defaultB; + } + } + + for ( var i = 1; i <= 3; i ++ ) { + + var vertexstart = start + i * 12; + + vertices[ offset ] = reader.getFloat32( vertexstart, true ); + vertices[ offset + 1 ] = reader.getFloat32( vertexstart + 4, true ); + vertices[ offset + 2 ] = reader.getFloat32( vertexstart + 8, true ); + + normals[ offset ] = normalX; + normals[ offset + 1 ] = normalY; + normals[ offset + 2 ] = normalZ; + + if (hasColors) { + colors[ offset ] = r; + colors[ offset + 1 ] = g; + colors[ offset + 2 ] = b; + } + + offset += 3; + + } + + } + + geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) ); + geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) ); + + if (hasColors) { + geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) ); + geometry.hasColors = true; + geometry.alpha = alpha; + } + + return geometry; + + }, + + parseASCII: function ( data ) { + + var geometry, length, normal, patternFace, patternNormal, patternVertex, result, text; + geometry = new THREE.Geometry(); + patternFace = /facet([\s\S]*?)endfacet/g; + + while ( ( result = patternFace.exec( data ) ) !== null ) { + + text = result[0]; + patternNormal = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g; + + while ( ( result = patternNormal.exec( text ) ) !== null ) { + + normal = new THREE.Vector3( parseFloat( result[ 1 ] ), parseFloat( result[ 3 ] ), parseFloat( result[ 5 ] ) ); + + } + + patternVertex = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g; + + while ( ( result = patternVertex.exec( text ) ) !== null ) { + + geometry.vertices.push( new THREE.Vector3( parseFloat( result[ 1 ] ), parseFloat( result[ 3 ] ), parseFloat( result[ 5 ] ) ) ); + + } + + length = geometry.vertices.length; + + geometry.faces.push( new THREE.Face3( length - 3, length - 2, length - 1, normal ) ); + + } + + geometry.computeBoundingBox(); + geometry.computeBoundingSphere(); + + return geometry; + + }, + + ensureString: function ( buf ) { + + if (typeof buf !== "string") { + var array_buffer = new Uint8Array(buf); + var str = ''; + for (var i = 0; i < buf.byteLength; i ++) { + str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian + } + return str; + } else { + return buf; + } + + }, + + ensureBinary: function ( buf ) { + + if (typeof buf === "string") { + var array_buffer = new Uint8Array(buf.length); + for (var i = 0; i < buf.length; i ++) { + array_buffer[i] = buf.charCodeAt(i) & 0xff; // implicitly assumes little-endian + } + return array_buffer.buffer || array_buffer; + } else { + return buf; + } + + } + +}; + +if ( typeof DataView === 'undefined') { + + DataView = function(buffer, byteOffset, byteLength) { + + this.buffer = buffer; + this.byteOffset = byteOffset || 0; + this.byteLength = byteLength || buffer.byteLength || buffer.length; + this._isString = typeof buffer === "string"; + + } + + DataView.prototype = { + + _getCharCodes:function(buffer,start,length) { + start = start || 0; + length = length || buffer.length; + var end = start + length; + var codes = []; + for (var i = start; i < end; i ++) { + codes.push(buffer.charCodeAt(i) & 0xff); + } + return codes; + }, + + _getBytes: function (length, byteOffset, littleEndian) { + + var result; + + // Handle the lack of endianness + if (littleEndian === undefined) { + + littleEndian = this._littleEndian; + + } + + // Handle the lack of byteOffset + if (byteOffset === undefined) { + + byteOffset = this.byteOffset; + + } else { + + byteOffset = this.byteOffset + byteOffset; + + } + + if (length === undefined) { + + length = this.byteLength - byteOffset; + + } + + // Error Checking + if (typeof byteOffset !== 'number') { + + throw new TypeError('DataView byteOffset is not a number'); + + } + + if (length < 0 || byteOffset + length > this.byteLength) { + + throw new Error('DataView length or (byteOffset+length) value is out of bounds'); + + } + + if (this.isString) { + + result = this._getCharCodes(this.buffer, byteOffset, byteOffset + length); + + } else { + + result = this.buffer.slice(byteOffset, byteOffset + length); + + } + + if (!littleEndian && length > 1) { + + if (!(result instanceof Array)) { + + result = Array.prototype.slice.call(result); + + } + + result.reverse(); + } + + return result; + + }, + + // Compatibility functions on a String Buffer + + getFloat64: function (byteOffset, littleEndian) { + + var b = this._getBytes(8, byteOffset, littleEndian), + + sign = 1 - (2 * (b[7] >> 7)), + exponent = ((((b[7] << 1) & 0xff) << 3) | (b[6] >> 4)) - ((1 << 10) - 1), + + // Binary operators such as | and << operate on 32 bit values, using + and Math.pow(2) instead + mantissa = ((b[6] & 0x0f) * Math.pow(2, 48)) + (b[5] * Math.pow(2, 40)) + (b[4] * Math.pow(2, 32)) + + (b[3] * Math.pow(2, 24)) + (b[2] * Math.pow(2, 16)) + (b[1] * Math.pow(2, 8)) + b[0]; + + if (exponent === 1024) { + if (mantissa !== 0) { + return NaN; + } else { + return sign * Infinity; + } + } + + if (exponent === -1023) { // Denormalized + return sign * mantissa * Math.pow(2, -1022 - 52); + } + + return sign * (1 + mantissa * Math.pow(2, -52)) * Math.pow(2, exponent); + + }, + + getFloat32: function (byteOffset, littleEndian) { + + var b = this._getBytes(4, byteOffset, littleEndian), + + sign = 1 - (2 * (b[3] >> 7)), + exponent = (((b[3] << 1) & 0xff) | (b[2] >> 7)) - 127, + mantissa = ((b[2] & 0x7f) << 16) | (b[1] << 8) | b[0]; + + if (exponent === 128) { + if (mantissa !== 0) { + return NaN; + } else { + return sign * Infinity; + } + } + + if (exponent === -127) { // Denormalized + return sign * mantissa * Math.pow(2, -126 - 23); + } + + return sign * (1 + mantissa * Math.pow(2, -23)) * Math.pow(2, exponent); + }, + + getInt32: function (byteOffset, littleEndian) { + var b = this._getBytes(4, byteOffset, littleEndian); + return (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0]; + }, + + getUint32: function (byteOffset, littleEndian) { + return this.getInt32(byteOffset, littleEndian) >>> 0; + }, + + getInt16: function (byteOffset, littleEndian) { + return (this.getUint16(byteOffset, littleEndian) << 16) >> 16; + }, + + getUint16: function (byteOffset, littleEndian) { + var b = this._getBytes(2, byteOffset, littleEndian); + return (b[1] << 8) | b[0]; + }, + + getInt8: function (byteOffset) { + return (this.getUint8(byteOffset) << 24) >> 24; + }, + + getUint8: function (byteOffset) { + return this._getBytes(1, byteOffset)[0]; + } + + }; + +} diff --git a/slice_test.html b/slice_test.html index 86b69ad..db22beb 100644 --- a/slice_test.html +++ b/slice_test.html @@ -5,6 +5,7 @@ + @@ -42,12 +43,12 @@ var printerConfig = { "printer.heatup.bed.temperature": 70, "printer.heatup.enabled": true, "printer.heatup.temperature": 180, - "printer.layerHeight": 0.3, + "printer.layerHeight": 0.2, "printer.retraction.amount": 3, - "printer.retraction.enabled": false, + "printer.retraction.enabled": true, "printer.retraction.minDistance": 5, "printer.retraction.speed": 50, - "printer.screenToMillimeterScale": 0.3, + "printer.screenToMillimeterScale": 0.3, //???? "printer.speed": 70, "printer.startcode": ";Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)", "printer.temperature": 230, @@ -102,28 +103,46 @@ var geometry = (function () { })(); var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true}); -//var geometry = new THREE.TorusGeometry(20, 10, 10, 10); +//var geometry = new THREE.TorusGeometry(20, 10, 30, 30); //var geometry = new THREE.BoxGeometry(20, 5, 20, 1, 1, 1); //var geometry = new THREE.SphereGeometry(10, 10, 10); var mesh = new THREE.Mesh(geometry, material); scene.add(mesh); -var slicer = new D3D.Slicer().setGeometry(geometry); - var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); var slicer = new D3D.Slicer().setGeometry(geometry); -var gcode = slicer.getGcode(printer); +gcode = slicer.getGcode(printer); var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); -var layer = 9; +var layer = 149; var img = slicer.drawPaths(printer, layer, layer + 1); context.drawImage(img, 0, 0); +/*var loader = new THREE.STLLoader(); +loader.load('stl/overhang_test.stl', function (geometry) { + + var matrix = new THREE.Matrix4(); + matrix.makeRotationX(Math.PI*1.5); + + geometry.applyMatrix(matrix); + + var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true}); + var mesh = new THREE.Mesh(geometry, material); + scene.add(mesh); + + var canvas = document.getElementById("canvas"); + var context = canvas.getContext("2d"); + + var slicer = new D3D.Slicer().setGeometry(geometry); + + //gcode = slicer.getGcode(printer); +});*/ + (function animate () { "use strict"; diff --git a/src/box.js b/src/box.js index 2706725..f40c74a 100644 --- a/src/box.js +++ b/src/box.js @@ -29,8 +29,6 @@ D3D.Box = function (localIp) { this.onload; getAPI(self.api + "config/all", function (data) { - //self.config = data; - for (var i in data) { if (i.indexOf("doodle3d") === 0) { self.config[i] = data[i]; @@ -85,6 +83,8 @@ D3D.Box.prototype.print = function (gcode) { var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length)); this.printBatches.push(gcodeBatch); } + + return this; }; D3D.Box.prototype.printBatch = function () { "use strict"; @@ -135,4 +135,144 @@ D3D.Box.prototype.stop = function () { }, function (data) { console.log("Printer stop command sent"); }); + + return this; +}; +D3D.Box.prototype.setConfig = function (data) { + "use strict"; + + sendAPI(this.api + "config", data); + + return this; +}; +D3D.Box.prototype.getInfoLog = function (callback) { + "use strict"; + + getAPI(this.api + "info/logfiles", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getInfoAcces = function (callback) { + "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); + } + }); + + return this; +}; +D3D.Box.prototype.getNetwerkScan = function (callback) { + "use strict"; + + getAPI(this.api + "network/scan", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getNetworkKnown = function (callback) { + "use strict"; + + getAPI(this.api + "network/known", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getNetworkStatus = function (callback) { + "use strict"; + + getAPI(this.api + "network/status", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.setNetworkAssosiate = function (data) { + "use strict"; + + sendAPI(this.api + "network/assosiate", data); + + return this; +}; +D3D.Box.prototype.setNetworkDisassosiate = function (data) { + "use strict"; + + sendAPI(this.api + "network/displayassosiate", data); + + return this; +}; +D3D.Box.prototype.setNetworkOpenap = function (data) { + "use strict"; + + sendAPI(this.api + "network/openap", data); + + return this; +}; +D3D.Box.prototype.setNetworkRemove = function (ssid) { + "use strict"; + + sendAPI(this.api + "network/displayassosiate", {ssid: ssid}); + + return this; +}; +D3D.Box.prototype.getNetworkAlive = function (callback) { + "use strict"; + + //emty? + + getAPI(this.api + "network/alive", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.getPrinterListAll = function (callback) { + "use strict"; + + getAPI(this.api + "printer/listall", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; +}; +D3D.Box.prototype.setPrinterHeatup = function (data) { + "use strict"; + + sendAPI(this.api + "printer/heatup", data); + + return this; +}; +D3D.Box.prototype.getVersion = function (data) { + "use strict"; + + //error + //cannot call function or module 'system/fwversion' ('module/function 'system/fwversion' does not exist') + + getAPI(this.api + "system/fwversion", function (data) { + if (callback !== undefined) { + callback(data); + } + }); + + return this; }; \ No newline at end of file diff --git a/src/slicer.js b/src/slicer.js index d939fce..4c069c8 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -22,7 +22,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(); @@ -153,6 +157,7 @@ D3D.Slicer.prototype.slice = function (height, step) { //think this check is not nescesary, always higher as 0 if (shape.length > 0) { + shape.push({X: shape[0].X, Y: shape[0].Y}); slice.push(shape); } } @@ -230,7 +235,8 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { } //moet fillArea wel kleiner? - var fillArea = this.getInset((inset || outerLayer), wallThickness); + //var fillArea = this.getInset((inset || outerLayer), wallThickness); + var fillArea = (inset || outerLayer); var fillAbove = false; //for (var i = 1; i < shellThickness/layerHeight; i ++) { @@ -330,7 +336,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { var retractionSpeed = printer.config["printer.retraction.speed"]; var retractionMinDistance = printer.config["printer.retraction.minDistance"]; var retractionAmount = printer.config["printer.retraction.amount"]; - + function sliceToGcode (slice) { var gcode = []; @@ -339,9 +345,8 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) { var previousPoint; - for (var j = 0; j <= shape.length; j ++) { - //Finish shape by going to first point - var point = shape[(j % shape.length)]; + for (var j = 0; j < shape.length; j ++) { + var point = shape[j]; if (j === 0) { //TODO @@ -431,13 +436,13 @@ 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(); + //context.closePath(); } context.stroke(); } diff --git a/stl/overhang_test.stl b/stl/overhang_test.stl new file mode 100644 index 0000000..71987a6 Binary files /dev/null and b/stl/overhang_test.stl differ