SaiDAV-StlSaver/herosaver.min.js

2 lines
7.1 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(n){console.log(n);var r="";for(var o in r+="solid exported\n",n)n[o].traverse(function(n){if(n instanceof RK.Mesh){if(0==n.visible)return;var o=n.geometry,a=n.matrixWorld,i=n.skeleton,s=n;if(o instanceof RK.BufferGeometry){var c=o.clone();o=(new RK.Geometry).fromBufferGeometry(o);for(var l=c.getAttribute("skinIndex"),d=c.getAttribute("skinWeight"),p=c.getAttribute("morphTarget0"),f=0;void 0!==p;)f++,p=c.getAttribute("morphTarget"+f);if(void 0!==l){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(l,m)),o.skinWeights.push((new THREE.Vector4).fromBufferAttribute(d,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,h=o.faces;if(t.getNormalMatrix(a),void 0!==h){m=0;for(var v=h.length;m<v;m++){var y=h[m];e.copy(y.normal).applyMatrix3(t).normalize(),r+="\tfacet normal "+e.x+" "+e.y+" "+e.z+"\n",r+="\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),r+="\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=[],C=0;C<o.morphTargets.length;C++)k[C]=o.morphTargets[C].vertices[x].x,j[C]=o.morphTargets[C].vertices[x].y,S[C]=o.morphTargets[C].vertices[x].z,A[C]=s.morphTargetInfluences[C];var K=new THREE.Vector4;if("undefined"!==s.geometry.morphTargets){var I=new THREE.Vector4(e.x,e.y,e.z);for(C=0;C<o.morphTargets.length;C++)I.lerp(new THREE.Vector4(k[C],j[C],S[C],1),A[C])}for(var L=0;L<4;L++){var B=new THREE.Vector4(e.x,e.y,e.z);B.multiplyScalar(T[L]),B.applyMatrix4(E[L]).applyMatrix4(R[L]),K.add(B)}r+="\t\t\tvertex "+K.x+" "+K.y+" "+K.z+"\n"}}r+="\t\tendloop\n",r+="\tendfacet\n"}}}}});return r+="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 n=jQuery(".characterArea"),r=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");n.append(stl),n.append(r),n.append(o),n.append(a),n.append(i),n.css("right",0),stl.click(function(e){e.preventDefault();var t,n=new RK.STLExporter,r=CK.character.children,o=r[0],a=[],i=0;for(t in r)r[t].children.length>r[i].children.length&&(console.log("Id "+i+" is not the character"),o=r[t],i=t);if(o.children.length>9&&(console.log("Found Character, id="+i),console.log(o),a.push(o)),void 0!==CK.data.parts.mount){console.log("Exporting Mount");var s=void 0;for(t in r){var c;for(c in r[t].children)"mount"==r[t].children[c].name&&r[t].children.length<10&&(console.log("Found mount, id="+t+","+c),s=r[t])}console.log(s),a.push(s),console.log(a)}console.log(a);var l=n.parse(a),d=CK.data.meta.character_name;d=""===d?"unnamed":d,download(l,d+".stl","application/sla")}),r.click(function(e){e.preventDefault();var t=(new RK.STLExporter).parse([CK.characte