SaiDAV-StlSaver/herosaver.min.js

2 lines
6.4 KiB
JavaScript
Raw Normal View History

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.expo