SaiDAV-StlSaver/herosaver.min.js

2 lines
6.4 KiB
JavaScript

function init(){!function(){var e,t;RK.STLExporter=function(){},RK.STLExporter.prototype={constructor:THREE.STLExporter,parse:(e=new THREE.Vector3,t=new THREE.Matrix3,function(r){console.log(r);var n="";for(var o in n+="solid exported\n",r)r[o].traverse(function(r){if(r instanceof RK.Mesh){if(0==r.visible)return;var o=r.geometry,a=r.matrixWorld,i=r.skeleton,s=r;if(o instanceof RK.BufferGeometry){var c=o.clone();o=(new RK.Geometry).fromBufferGeometry(o);for(var d=c.getAttribute("skinIndex"),l=c.getAttribute("skinWeight"),p=c.getAttribute("morphTarget0"),f=0;void 0!==p;)f++,p=c.getAttribute("morphTarget"+f);if(void 0!==d){o.skinIndices=[],o.skinWeights=[],o.morphTargets=[];for(var u=0;u<f;u++)o.morphTargets[u]={},o.morphTargets[u].vertices=[];for(var m=0;m<o.vertices.length;m++)for(o.skinIndices.push((new THREE.Vector4).fromBufferAttribute(d,m)),o.skinWeights.push((new THREE.Vector4).fromBufferAttribute(l,m)),u=0;u<f;u++)o.morphTargets[u].vertices.push((new THREE.Vector3).fromBufferAttribute(c.getAttribute("morphTarget"+u)))}}if(o instanceof RK.Geometry){var g=o.vertices,v=o.faces;if(t.getNormalMatrix(a),void 0!==v){m=0;for(var h=v.length;m<h;m++){var y=v[m];e.copy(y.normal).applyMatrix3(t).normalize(),n+="\tfacet normal "+e.x+" "+e.y+" "+e.z+"\n",n+="\t\touter loop\n";var b=[y.a,y.b,y.c];for(u=0;u<3;u++){var x=b[u];if(void 0!==o.skinIndices&&0==o.skinIndices.length)e.copy(g[x]).applyMatrix4(a),n+="\t\t\tvertex "+e.x+" "+e.y+" "+e.z+"\n";else{e.copy(g[x]);var w=[o.skinIndices[x].x,o.skinIndices[x].y,o.skinIndices[x].z,o.skinIndices[x].w],T=[o.skinWeights[x].x,o.skinWeights[x].y,o.skinWeights[x].z,o.skinWeights[x].w],E=[i.boneInverses[w[0]],i.boneInverses[w[1]],i.boneInverses[w[2]],i.boneInverses[w[3]]],R=[i.bones[w[0]].matrixWorld,i.bones[w[1]].matrixWorld,i.bones[w[2]].matrixWorld,i.bones[w[3]].matrixWorld];if("undefined"!==o.morphTargets)for(var k=[],j=[],S=[],A=[],I=0;I<o.morphTargets.length;I++)k[I]=o.morphTargets[I].vertices[x].x,j[I]=o.morphTargets[I].vertices[x].y,S[I]=o.morphTargets[I].vertices[x].z,A[I]=s.morphTargetInfluences[I];var L=new THREE.Vector4;if("undefined"!==s.geometry.morphTargets){var B=new THREE.Vector4(e.x,e.y,e.z);for(I=0;I<o.morphTargets.length;I++)B.lerp(new THREE.Vector4(k[I],j[I],S[I],1),A[I])}for(var C=0;C<4;C++){var K=new THREE.Vector4(e.x,e.y,e.z);K.multiplyScalar(T[C]),K.applyMatrix4(E[C]).applyMatrix4(R[C]),L.add(K)}n+="\t\t\tvertex "+L.x+" "+L.y+" "+L.z+"\n"}}n+="\t\tendloop\n",n+="\tendfacet\n"}}}}});return n+="endsolid exported\n"})},"undefined"!=typeof module&&module.exports?module.exports=RK.STLExporter:"undefined"!=typeof define&&null!==define&&null!==define.amd&&define([],function(){return saveAs});var r=jQuery(".characterArea"),n=jQuery("<a />").css({"margin-left":"20px","font-size":"1.4em",color:"rgba(255, 255, 255, 0.8)",cursor:"pointer"}).text("Export Figure"),o=jQuery("<a />").css({"margin-left":"20px","font-size":"1.4em",color:"rgba(255, 255, 255, 0.8)",cursor:"pointer"}).text("Save JSON"),a=jQuery("<input/>").attr({type:"file",id:"ljson"}).css({display:"none"}).text("Load JSON"),i=jQuery("<label/>").attr({for:"ljson"}).css({"margin-left":"20px","font-size":"1.4em",color:"rgba(255, 255, 255, 0.8)",cursor:"pointer"}).text("Load JSON");r.append(n),r.append(o),r.append(a),r.append(i),r.css("right",0),n.click(function(e){e.preventDefault();var t=(new RK.STLExporter).parse([CK.character]),r=CK.data.meta.character_name;r=""===r?"unnamed":r,download(t,r+"_base.stl","application/sla")}),o.click(function(e){e.preventDefault();var t=JSON.stringify(CK.data),r=CK.data.meta.character_name;r=""===r?"unnamed":r,download(t,r+".json","text/plain")}),a.on("change",function(e){e.preventDefault();var t=e.target.files[0],r=new FileReader;r.onload=function(e){e.preventDefault(),CK.change(JSON.parse(e.target.result))},r.readAsText(t)})}()}function inject_script(e,t){var r=document.getElementsByTagName("head")[0],n=document.createElement("script");n.src=e,n.onload=function(e){t()},r.appendChild(n)}!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.download=t()}(this,function(){return function e(t,r,n){function o(e){e=(t=e.split(/[:;,]/))[1];for(var t,r=(t=("base64"==t[2]?atob:decodeURIComponent)(t.pop())).length,n=0,o=new Uint8Array(r);n<r;++n)o[n]=t.charCodeAt(n);return new l([o],{type:e})}function a(e,t){if("download"in d)return d.href=e,d.setAttribute("download",p),d.className="download-js-link",d.innerHTML="downloading...",d.style.display="none",document.body.appendChild(d),setTimeout(function(){d.click(),document.body.removeChild(d),!0===t&&setTimeout(function(){i.URL.revokeObjectURL(d.href)},250)},66),!0;if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent))return/^data:/.test(e)&&(e="data:"+e.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),!window.open(e)&&confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")&&(location.href=e),!0;var r=document.createElement("iframe");document.body.appendChild(r),!t&&/^data:/.test(e)&&(e="data:"+e.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),r.src=e,setTimeout(function(){document.body.removeChild(r)},333)}var i=window,s=n||"application/octet-stream",c=!r&&!n&&t,d=document.createElement("a");n=function(e){return String(e)};var l=i.Blob||i.MozBlob||i.WebKitBlob||n,p=r||"download";l=l.call?l.bind(i):Blob;if("true"===String(this)&&(s=(t=[t,s])[0],t=t[1]),c&&2048>c.length&&(p=c.split("/").pop().split("?")[0],d.href=c,-1!==d.href.indexOf(c))){var f=new XMLHttpRequest;return f.open("GET",c,!0),f.responseType="blob",f.onload=function(t){e(t.target.response,p,"application/octet-stream")},setTimeout(function(){f.send()},0),f}if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(t)){if(!(2096103.424<t.length&&l!==n))return navigator.msSaveBlob?navigator.msSaveBlob(o(t),p):a(t);s=(t=o(t)).type||"application/octet-stream"}else if(/([\x80-\xff])/.test(t)){r=0;for(var u=(c=new Uint8Array(t.length)).length;r<u;++r)c[r]=t.charCodeAt(r);t=new l([c],{type:s})}if(t=t instanceof l?t:new l([t],{type:s}),navigator.msSaveBlob)return navigator.msSaveBlob(t,p);if(i.URL)a(i.URL.createObjectURL(t),!0);else{if("string"==typeof t||t.constructor===n)try{return a("data:"+s+";base64,"+i.btoa(t))}catch(e){return a("data:"+s+","+encodeURIComponent(t))}(s=new FileReader).onload=function(e){a(this.result)},s.readAsDataURL(t)}return!0}}),inject_script("//code.jquery.com/jquery-3.3.1.min.js",function(){inject_script("//cdnjs.cloudflare.com/ajax/libs/three.js/100/three.js",function(){init()})});