X-Git-Url: http://git.scottworley.com/nt3d/blobdiff_plain/1e62819c99e2c97c4f11c9612012c83cf36dd4ff..1b9ec3f33236204d027507b7dec5215677b51707:/nt3d.js diff --git a/nt3d.js b/nt3d.js index 1cabfb1..59b11b2 100644 --- a/nt3d.js +++ b/nt3d.js @@ -91,14 +91,18 @@ nt3d = { // constrain its rotation about shapenormals[i]. var rot1axis = this.unit(this.cross([0,0,1], shapenormals[i])); var rot1angle = this.angle_between([0,0,1], this.unit(shapenormals[i])); + var shapex = [[1,0,0]]; if (rot1angle > 1e-7) { loop = this.rotate_about_origin(loop, rot1axis, rot1angle); + shapex = this.rotate_about_origin(shapex, rot1axis, rot1angle); + } // 2. Rotate around shapenormals[i] so that [1,0,0] // becomes fixedpathnormals[i]. var rot2axis = this.unit(shapenormals[i]); - var rot2angle = this.angle_between([1,0,0], this.unit(fixedpathnormals[i])); + var rot2angle = this.angle_between(shapex[0], this.unit(fixedpathnormals[i])); + console.log(rot2angle); if (rot2angle > 1e-7) { loop = this.rotate_about_origin(loop, rot2axis, rot2angle); } @@ -197,10 +201,22 @@ nt3d = { center); }, go: function() { + // Remove any previous download links + var old_download_link = document.getElementById("nt3d_download"); + if (old_download_link) { + old_download_link.parentNode.removeChild(old_download_link); + } + + // Continue in a callback, so that there's not a stale download + // link hanging around while we process. + setTimeout(function(the_this) { (function() { + // Get params from form var params = []; for (var i = 0; i < this.user_params.length; i++) { - params[i] = this.form.elements["param"+i].value; + var as_string = this.form.elements["param"+i].value; + var as_num = +as_string; + params[i] = isNaN(as_num) ? as_string : as_num; } // Run user_function @@ -227,11 +243,6 @@ nt3d = { } this.stl += "endsolid " + this.user_function.name + "\n"; - // Remove any previous download links - var old_download_link = document.getElementById("nt3d_download"); - if (old_download_link) { - old_download_link.parentNode.removeChild(old_download_link); - } // Offer result as download var download_link = document.createElement("a"); @@ -242,6 +253,8 @@ nt3d = { download_link.setAttribute("href", "data:application/sla," + encodeURIComponent(this.stl)); this.ui.appendChild(download_link); setTimeout(function() { download_link.setAttribute("style", "-webkit-transition: background-color 0.4s; -moz-transition: background-color 0.4s; -o-transition: background-color 0.4s; -ms-transition: background-color 0.4s; transition: background-color 0.4s; background-color: inherit"); }, 0); + + }).call(the_this); }, 0, this); // (We were in a callback this whole time, remember?) }, framework: function (f, params) { this.user_function = f;