Commit 90f1a488 authored by Jennie Yoder's avatar Jennie Yoder

lost the stl button! Argh.

parent b721e6d1
......@@ -411,7 +411,7 @@ Blockscad.init = function() {
root.find('.sub-menu:visible').hide();
});
});
$('#stl_buttons').addClass('hidden');
$('#stl_buttons').hide();
if (!Blockscad.standalone) {
BSUtils.loadBlocks('');
......
......@@ -1142,14 +1142,14 @@ Blockscad.Processor.prototype = {
} catch(e) {
this.picdiv.innerHTML = "<b><br><br>Error: " + e.toString() + "</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled";
}
$("#picdiv").hide();
$("#picdiv").addClass('hidden');
try {
this.rpicviewer = new Blockscad.Viewer(this.rpicdiv, rpicdiv.offsetWidth, rpicdiv.offsetHeight, this.initialViewerDistance);
} catch(e) {
this.rpicdiv.innerHTML = "<b><br><br>Error: " + e.toString() + "</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled";
}
$("#rpicdiv").hide();
$("#rpicdiv").addClass('hidden');
try {
this.viewer = new Blockscad.Viewer(this.viewerdiv, viewerdiv.offsetWidth, viewerdiv.offsetHeight, this.initialViewerDistance);
......@@ -1223,7 +1223,7 @@ Blockscad.Processor.prototype = {
}
// console.log("trying to turn on stl_buttons");
$('#stl_buttons').show();
$('#stl_buttons').removeClass('hidden');
while(this.formatDropdown.options.length > 0)
this.formatDropdown.options.remove(0);
......@@ -1260,7 +1260,7 @@ Blockscad.Processor.prototype = {
this.imgStrip = "none";
this.img = "none";
// console.log('trying to hid stl_buttons');
$('#stl_buttons').hide();
$('#stl_buttons').addClass('hidden');
this.enableItems();
},
......
......@@ -35,19 +35,20 @@ Blockscad.Processor=function(h,m){this.containerdiv=h;this.onchange=m;this.rpicv
Blockscad.Processor.convertToSolid=function(h){if("object"==typeof h&&h instanceof CAG)h=h.extrude({offset:[0,0,.1]});else if(!("object"==typeof h&&h instanceof CSG))if(h.length){console.log("putting them together");for(var m=h[0],n=1;n<h.length;n++)m=m.unionForNonIntersecting(h[n]);h=m}else throw Error("Cannot convert to solid");return h};
Blockscad.Processor.prototype={createElements:function(){for(var h=this;7<this.containerdiv.children.length;)this.containerdiv.removeChild(7);var m=document.createElement("div");m.style.width="100%";m.style.height="100%";m.style.top="0px";m.style.position="absolute";m.style.zIndex="9";this.containerdiv.appendChild(m);this.viewerdiv=m;var n=document.createElement("div");n.setAttribute("id","picdiv");n.style.width=Blockscad.picSize[0]+"px";n.style.height=Blockscad.picSize[1]+"px";n.style.top="0px";
n.style.right="10px";n.style.position="absolute";n.style.zIndex="-1";document.getElementById("blocklyDiv").appendChild(n);this.picdiv=n;var k=document.createElement("div");k.setAttribute("id","picdiv");k.style.width=Blockscad.rpicSize[0]+"px";k.style.height=Blockscad.rpicSize[1]+"px";k.style.top="0px";k.style.right="10px";k.style.position="absolute";k.style.zIndex="-1";document.getElementById("blocklyDiv").appendChild(k);this.rpicdiv=k;try{this.picviewer=new Blockscad.Viewer(this.picdiv,n.offsetWidth,
n.offsetHeight,this.initialViewerDistance)}catch(c){this.picdiv.innerHTML="<b><br><br>Error: "+c.toString()+"</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled"}$("#picdiv").hide();try{this.rpicviewer=new Blockscad.Viewer(this.rpicdiv,k.offsetWidth,k.offsetHeight,this.initialViewerDistance)}catch(c){this.rpicdiv.innerHTML="<b><br><br>Error: "+c.toString()+"</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled"}$("#rpicdiv").hide();try{this.viewer=
new Blockscad.Viewer(this.viewerdiv,m.offsetWidth,m.offsetHeight,this.initialViewerDistance)}catch(c){this.viewerdiv.innerHTML="<b><br><br>Error: "+c.toString()+"</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled"}this.abortbutton=document.getElementById("abortButton");this.renderbutton=document.getElementById("renderButton");this.ongoingrender=document.getElementById("render-ongoing");this.abortbutton.onclick=function(c){h.abort();$("#renderButton").prop("disabled",
n.offsetHeight,this.initialViewerDistance)}catch(c){this.picdiv.innerHTML="<b><br><br>Error: "+c.toString()+"</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled"}$("#picdiv").addClass("hidden");try{this.rpicviewer=new Blockscad.Viewer(this.rpicdiv,k.offsetWidth,k.offsetHeight,this.initialViewerDistance)}catch(c){this.rpicdiv.innerHTML="<b><br><br>Error: "+c.toString()+"</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled"}$("#rpicdiv").addClass("hidden");
try{this.viewer=new Blockscad.Viewer(this.viewerdiv,m.offsetWidth,m.offsetHeight,this.initialViewerDistance)}catch(c){this.viewerdiv.innerHTML="<b><br><br>Error: "+c.toString()+"</b><br><br>BlocksCAD currently requires Google Chrome or Firefox with WebGL enabled"}this.abortbutton=document.getElementById("abortButton");this.renderbutton=document.getElementById("renderButton");this.ongoingrender=document.getElementById("render-ongoing");this.abortbutton.onclick=function(c){h.abort();$("#renderButton").prop("disabled",
!1)};this.formatDropdown=document.getElementById("render-type");this.formatDropdown.onchange=function(c){h.currentFormat=h.formatDropdown.options[h.formatDropdown.selectedIndex].value;h.updateDownloadLink()};this.generateOutputFileButton=document.getElementById("stlButton");this.generateOutputFileButton.onclick=function(c){h.generateOutputFile()};this.enableItems()},setCurrentObject:function(h){this.currentObject=h=Blockscad.Processor.convertToSolid(h);this.hasValidCurrentObject=!0;this.viewer&&this.viewer.setCsg(h);
this.picviewer&&(this.picviewer.bbox=h.getBounds(),this.picviewer.bsph=h.getBoundingSphere(),this.picviewer.setCsg(h));this.rpicviewer&&(this.rpicviewer.bbox=h.getBounds(),this.rpicviewer.bsph=h.getBoundingSphere(),this.rpicviewer.setCsg(h));for($("#stl_buttons").show();0<this.formatDropdown.options.length;)this.formatDropdown.options.remove(0);var m=this;this.supportedFormatsForCurrentObject().forEach(function(h){var k=document.createElement("option");k.setAttribute("value",h);k.appendChild(document.createTextNode(m.formatInfo(h).displayName));
this.picviewer&&(this.picviewer.bbox=h.getBounds(),this.picviewer.bsph=h.getBoundingSphere(),this.picviewer.setCsg(h));this.rpicviewer&&(this.rpicviewer.bbox=h.getBounds(),this.rpicviewer.bsph=h.getBoundingSphere(),this.rpicviewer.setCsg(h));for($("#stl_buttons").removeClass("hidden");0<this.formatDropdown.options.length;)this.formatDropdown.options.remove(0);var m=this;this.supportedFormatsForCurrentObject().forEach(function(h){var k=document.createElement("option");k.setAttribute("value",h);k.appendChild(document.createTextNode(m.formatInfo(h).displayName));
m.formatDropdown.options.add(k)});this.updateDownloadLink()},selectedFormat:function(){return this.formatDropdown.options[this.formatDropdown.selectedIndex].value},selectedFormatInfo:function(){return this.formatInfo(this.selectedFormat())},updateDownloadLink:function(){var h=this.selectedFormatInfo().extension;this.generateOutputFileButton.innerHTML=Blockscad.Msg.GENERATE_STL+" "+h.toUpperCase()},clearViewer:function(){this.clearOutputFile();this.setCurrentObject(new CSG);this.hasValidCurrentObject=
!1;this.img=this.imgStrip=this.thumbnail="none";$("#stl_buttons").hide();this.enableItems()},abort:function(){if(this.processing&&(this.processing=!1,this.worker.terminate(),this.enableItems(),this.onchange))this.onchange()},enableItems:function(){this.abortbutton.style.display=this.processing?"inline-block":"none";this.renderbutton.style.display=this.processing?"none":"inline-block";this.ongoingrender.style.display=this.processing?"inline-block":"none"},setError:function(h){this.hasError=""!=h;$("#error-message").text(h);
this.enableItems()},setDebugging:function(h){this.debugging=h},setBlockscad:function(h){this.abort();this.clearViewer();this.script=h;this.rebuildSolid()},rebuildSolid:function(){this.abort();this.setError("");this.clearViewer();this.processing=!0;$("#renderButton").html(Blockscad.Msg.RENDER_BUTTON);$("#renderButton").prop("disabled",!1);this.enableItems();var h=this,m=this.debugging;if(!m)try{this.worker=Blockscad.parseBlockscadScriptASync(this.script,function(k,c){h.processing=!1;h.worker=null;
if(k)console.log("error in proc"+k),h.setError(k);else{h.setCurrentObject(c);var m=h.picviewer.takePic(Blockscad.picQuality,0,1);h.img=m[0];h.thumbnail=m[1];h.imgStrip=h.takeRotatingPic(1,Blockscad.numRotPics)}if(h.onchange)h.onchange();h.enableItems()})}catch(k){console.log("async failed, try sync compute, error: "+k.message),m=!0}if(m){try{var n=Blockscad.parseBlockscadScriptSync(this.script,this.debugging);h.setCurrentObject(n);h.processing=!1}catch(k){h.processing=!1,(m=k.stack)||(m=k.toString()),
h.setError(m)}h.enableItems();if(h.onchange)h.onchange()}},hasSolid:function(){return this.hasValidCurrentObject},isProcessing:function(){return this.processing},clearOutputFile:function(){if(this.hasOutputFile&&(this.outputFileBlobUrl&&(Blockscad.revokeBlobUrl(this.outputFileBlobUrl),this.outputFileBlobUrl=null),this.enableItems(),this.onchange))this.onchange()},generateOutputFile:function(){this.clearOutputFile();this.hasValidCurrentObject&&this.generateAndSaveRenderedFile()},currentObjectToBlob:function(){var h=
this.selectedFormat();if("stla"==h)h=this.currentObject.toStlString(),h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("stlb"==h)h=this.currentObject.toStlBinary({webBlob:!0});else if("amf"==h)h=this.currentObject.toAMFString({producer:"BlocksCAD "+Blockscad.version,date:new Date}),h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("x3d"==h)h=this.currentObject.toX3D(),h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("dxf"==h)h=this.currentObject.toDxf(),h=new Blob([h],
{type:"text/plain; charset=utf-8"});else if("obj"==h)h=this.currentObject.toObj(),h=new Blob([h],{type:"text/plain; charset=utf-8"});else throw Error("Not supported");return h},supportedFormatsForCurrentObject:function(){if(this.currentObject instanceof CSG)return-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")?["stla","amf","x3d"]:["stlb","stla","x3d","obj","amf"];if(this.currentObject instanceof CAG)return["dxf"];throw Error("Not supported");},formatInfo:function(h){return{stla:{displayName:"STL (ASCII)",
extension:"stl",mimetype:"application/sla"},obj:{displayName:"OBJ (ASCII)",extension:"obj",mimetype:"application/sla"},stlb:{displayName:"STL (Binary)",extension:"stl",mimetype:"application/sla"},amf:{displayName:"AMF",extension:"amf",mimetype:"application/amf+xml"},x3d:{displayName:"X3D",extension:"x3d",mimetype:"model/x3d+xml"},dxf:{displayName:"DXF",extension:"dxf",mimetype:"application/dxf"}}[h]},generateAndSaveRenderedFile:function(){var h=this.currentObjectToBlob(),m=this.selectedFormatInfo().extension,
n=$("#project-name").val();n?saveAs(h,n+"."+m):($("#message-text").html("<h4>"+Blockscad.Msg.SAVE_FAILED+" "+Blockscad.Msg.SAVE_FAILED_PROJECT_NAME+".</h4>"),$("#message-modal").modal())},takeRotatingPic:function(h,m){var n=[],k=[],c=document.createElement("canvas");c.width=Blockscad.rpicSize[0]*m;c.height=Blockscad.rpicSize[0];for(var p=c.getContext("2d"),a=0;a<m;a+=1)n[a]=this.rpicviewer.takePic(h,2*Math.PI/m*-a)[0],k[a]=new Image,k[a].src=n[a],p.drawImage(k[a],a*Blockscad.rpicSize[0],0);return c.toDataURL("image/jpeg")}};(function(h){function m(a,b){return a-b}function n(a,b,d){for(var c=0,f=a.length;f>c;){var g=Math.floor((c+f)/2);0<d(b,a[g])?c=g+1:f=g}a.splice(c,0,b)}function k(a,b){return a.index-b.index}var c=function(){this.polygons=[];this.properties=new c.Properties;this.isRetesselated=this.isCanonicalized=!0};c.defaultResolution2D=32;c.defaultResolution3D=12;c.fromPolygons=function(a){var b=new c;b.polygons=a;b.isCanonicalized=!1;b.isRetesselated=!1;return b};c.fromSlices=function(a){return(new c.Polygon.createFromPoints([[0,
!1;this.img=this.imgStrip=this.thumbnail="none";$("#stl_buttons").addClass("hidden");this.enableItems()},abort:function(){if(this.processing&&(this.processing=!1,this.worker.terminate(),this.enableItems(),this.onchange))this.onchange()},enableItems:function(){this.abortbutton.style.display=this.processing?"inline-block":"none";this.renderbutton.style.display=this.processing?"none":"inline-block";this.ongoingrender.style.display=this.processing?"inline-block":"none"},setError:function(h){this.hasError=
""!=h;$("#error-message").text(h);this.enableItems()},setDebugging:function(h){this.debugging=h},setBlockscad:function(h){this.abort();this.clearViewer();this.script=h;this.rebuildSolid()},rebuildSolid:function(){this.abort();this.setError("");this.clearViewer();this.processing=!0;$("#renderButton").html(Blockscad.Msg.RENDER_BUTTON);$("#renderButton").prop("disabled",!1);this.enableItems();var h=this,m=this.debugging;if(!m)try{this.worker=Blockscad.parseBlockscadScriptASync(this.script,function(k,
c){h.processing=!1;h.worker=null;if(k)console.log("error in proc"+k),h.setError(k);else{h.setCurrentObject(c);var m=h.picviewer.takePic(Blockscad.picQuality,0,1);h.img=m[0];h.thumbnail=m[1];h.imgStrip=h.takeRotatingPic(1,Blockscad.numRotPics)}if(h.onchange)h.onchange();h.enableItems()})}catch(k){console.log("async failed, try sync compute, error: "+k.message),m=!0}if(m){try{var n=Blockscad.parseBlockscadScriptSync(this.script,this.debugging);h.setCurrentObject(n);h.processing=!1}catch(k){h.processing=
!1,(m=k.stack)||(m=k.toString()),h.setError(m)}h.enableItems();if(h.onchange)h.onchange()}},hasSolid:function(){return this.hasValidCurrentObject},isProcessing:function(){return this.processing},clearOutputFile:function(){if(this.hasOutputFile&&(this.outputFileBlobUrl&&(Blockscad.revokeBlobUrl(this.outputFileBlobUrl),this.outputFileBlobUrl=null),this.enableItems(),this.onchange))this.onchange()},generateOutputFile:function(){this.clearOutputFile();this.hasValidCurrentObject&&this.generateAndSaveRenderedFile()},
currentObjectToBlob:function(){var h=this.selectedFormat();if("stla"==h)h=this.currentObject.toStlString(),h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("stlb"==h)h=this.currentObject.toStlBinary({webBlob:!0});else if("amf"==h)h=this.currentObject.toAMFString({producer:"BlocksCAD "+Blockscad.version,date:new Date}),h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("x3d"==h)h=this.currentObject.toX3D(),h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("dxf"==h)h=this.currentObject.toDxf(),
h=new Blob([h],{type:"text/plain; charset=utf-8"});else if("obj"==h)h=this.currentObject.toObj(),h=new Blob([h],{type:"text/plain; charset=utf-8"});else throw Error("Not supported");return h},supportedFormatsForCurrentObject:function(){if(this.currentObject instanceof CSG)return-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")?["stla","amf","x3d"]:["stlb","stla","x3d","obj","amf"];if(this.currentObject instanceof CAG)return["dxf"];throw Error("Not supported");},
formatInfo:function(h){return{stla:{displayName:"STL (ASCII)",extension:"stl",mimetype:"application/sla"},obj:{displayName:"OBJ (ASCII)",extension:"obj",mimetype:"application/sla"},stlb:{displayName:"STL (Binary)",extension:"stl",mimetype:"application/sla"},amf:{displayName:"AMF",extension:"amf",mimetype:"application/amf+xml"},x3d:{displayName:"X3D",extension:"x3d",mimetype:"model/x3d+xml"},dxf:{displayName:"DXF",extension:"dxf",mimetype:"application/dxf"}}[h]},generateAndSaveRenderedFile:function(){var h=
this.currentObjectToBlob(),m=this.selectedFormatInfo().extension,n=$("#project-name").val();n?saveAs(h,n+"."+m):($("#message-text").html("<h4>"+Blockscad.Msg.SAVE_FAILED+" "+Blockscad.Msg.SAVE_FAILED_PROJECT_NAME+".</h4>"),$("#message-modal").modal())},takeRotatingPic:function(h,m){var n=[],k=[],c=document.createElement("canvas");c.width=Blockscad.rpicSize[0]*m;c.height=Blockscad.rpicSize[0];for(var p=c.getContext("2d"),a=0;a<m;a+=1)n[a]=this.rpicviewer.takePic(h,2*Math.PI/m*-a)[0],k[a]=new Image,
k[a].src=n[a],p.drawImage(k[a],a*Blockscad.rpicSize[0],0);return c.toDataURL("image/jpeg")}};(function(h){function m(a,b){return a-b}function n(a,b,d){for(var c=0,f=a.length;f>c;){var g=Math.floor((c+f)/2);0<d(b,a[g])?c=g+1:f=g}a.splice(c,0,b)}function k(a,b){return a.index-b.index}var c=function(){this.polygons=[];this.properties=new c.Properties;this.isRetesselated=this.isCanonicalized=!0};c.defaultResolution2D=32;c.defaultResolution3D=12;c.fromPolygons=function(a){var b=new c;b.polygons=a;b.isCanonicalized=!1;b.isRetesselated=!1;return b};c.fromSlices=function(a){return(new c.Polygon.createFromPoints([[0,
0,0],[1,0,0],[1,1,0],[0,1,0]])).solidFromSlices(a)};c.fromObject=function(a){a=a.polygons.map(function(a){return c.Polygon.fromObject(a)});a=c.fromPolygons(a);return a=a.canonicalized()};c.uniqBy=function(a,b){var d={};return a.filter(function(a){a=b(a);return d.hasOwnProperty(a)?!1:d[a]=!0})};c.fromCompactBinary=function(a){if("CSG"!=a["class"])throw Error("Not a CSG");for(var b=[],d=a.planeData,e=d.length/4,f=0,g,l,q,y,k=0;k<e;k++)g=d[f++],l=d[f++],q=d[f++],y=d[f++],g=c.Vector3D.Create(g,l,q),g=
new c.Plane(g,y),b.push(g);d=[];e=a.vertexData;k=e.length/3;for(y=f=0;y<k;y++)g=e[f++],l=e[f++],q=e[f++],g=c.Vector3D.Create(g,l,q),g=new c.Vertex(g),d.push(g);l=a.shared.map(function(a){return c.Polygon.Shared.fromObject(a)});q=[];e=a.numPolygons;k=a.numVerticesPerPolygon;y=a.polygonVertices;var h=a.polygonPlaneIndexes;a=a.polygonSharedIndexes;for(var m,r,p=f=0;p<e;p++){g=k[p];m=[];for(r=0;r<g;r++)m.push(d[y[f++]]);g=b[h[p]];r=l[a[p]];g=new c.Polygon(m,r,g);q.push(g)}b=c.fromPolygons(q);b.isCanonicalized=
!0;b.isRetesselated=!0;return b};c.prototype={toPolygons:function(){return this.polygons},union:function(a){a instanceof Array?(a=a.slice(0),a.push(this)):a=[this,a];for(var b=1;b<a.length;b+=2)a.push(a[b-1].unionSub(a[b]));return a[b-1].reTesselated().canonicalized()},unionSub:function(a,b,d){if(this.mayOverlap(a)){var e=new c.Tree(this.polygons),f=new c.Tree(a.polygons);e.clipTo(f,!1);f.clipTo(e);f.invert();f.clipTo(e);f.invert();e=e.allPolygons().concat(f.allPolygons());e=c.fromPolygons(e);e.properties=
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment