jocly
Version:
Board games 3D/2D UI and AI web library
11 lines • 136 kB
JavaScript
THREE.SubdivisionModifier=function(e){this.subdivisions=void 0===e?1:e,this.useOldVertexColors=!1,this.supportUVs=!0,this.debug=!1},THREE.SubdivisionModifier.prototype.modify=function(e){for(var o=this.subdivisions;o-- >0;)this.smooth(e)},THREE.GeometryUtils.orderedKey=function(e,o){return Math.min(e,o)+"_"+Math.max(e,o)},THREE.GeometryUtils.computeEdgeFaces=function(e){function o(e,o){void 0===i[e]&&(i[e]=[]),i[e].push(o)}var t,a,r,n,i={},c=THREE.GeometryUtils.orderedKey;for(t=0,a=e.faces.length;t<a;t++)r=e.faces[t],r instanceof THREE.Face3?(n=c(r.a,r.b),o(n,t),n=c(r.b,r.c),o(n,t),n=c(r.c,r.a),o(n,t)):r instanceof THREE.Face4&&(n=c(r.a,r.b),o(n,t),n=c(r.b,r.c),o(n,t),n=c(r.c,r.d),o(n,t),n=c(r.d,r.a),o(n,t));return i},THREE.SubdivisionModifier.prototype.smooth=function(e){function o(){y.debug&&console&&console.assert&&console.assert.apply(console,arguments)}function t(){y.debug&&console.log.apply(console,arguments)}function a(){console&&console.log.apply(console,arguments)}function r(e,o,a,r,i,c,s){var d=new THREE.Face4(e,o,a,r,null,i.color,i.materialIndex);if(y.useOldVertexColors){d.vertexColors=[];for(var l,u,f,v=0;v<4;v++){f=c[v],l=new THREE.Color,l.setRGB(0,0,0);for(var h=0;h<f.length;h++)u=i.vertexColors[f[h]-1],l.r+=u.r,l.g+=u.g,l.b+=u.b;l.r/=f.length,l.g/=f.length,l.b/=f.length,d.vertexColors[v]=l}}if(E.push(d),y.supportUVs){var p=[n(e,""),n(o,s),n(a,s),n(r,s)];p[0]?p[1]?p[2]?p[3]?g.push(p):t("d :( ",r+":"+s):t("c :( ",a+":"+s):t("b :( ",o+":"+s):t("a :( ",e+":"+s)}}function n(e,o){var r=e+":"+o,n=F[r];return n||(t(e>=H&&e<H+R.length?"face pt":"edge pt"),a("warning, UV not found for",r),null)}function i(e,o,t){var r=e+":"+o;r in F?a("dup vertexNo",e,"oldFaceNo",o,"value",t,"key",r,F[r]):F[r]=t}function c(e,o){void 0===z[e]&&(z[e]=[]),z[e].push(o)}function s(e,o,t){void 0===D[e]&&(D[e]={}),D[e][o]=t}var d,l,u,f,v,h,p=[],E=[],g=[],y=this,x=THREE.GeometryUtils.orderedKey,b=THREE.GeometryUtils.computeEdgeFaces,m=e.vertices,R=e.faces,H=m.length,T=m.concat(),V=[],S={},U={},w=[],F={},C=e.faceVertexUvs[0],G="abcd";if(t("originalFaces, uvs, originalVerticesLength",R.length,C.length,H),y.supportUVs)for(d=0,l=C.length;d<l;d++)for(u=0,f=C[d].length;u<f;u++)h=R[d][G.charAt(u)],i(h,d,C[d][u]);0==C.length&&(y.supportUVs=!1);var M=0;for(var _ in F)M++;M||(y.supportUVs=!1,t("no uvs"));var N;for(d=0,l=R.length;d<l;d++)v=R[d],V.push(v.centroid),T.push(v.centroid),y.supportUVs&&(N=new THREE.Vector2,v instanceof THREE.Face3?(N.x=n(v.a,d).x+n(v.b,d).x+n(v.c,d).x,N.y=n(v.a,d).y+n(v.b,d).y+n(v.c,d).y,N.x/=3,N.y/=3):v instanceof THREE.Face4&&(N.x=n(v.a,d).x+n(v.b,d).x+n(v.c,d).x+n(v.d,d).x,N.y=n(v.a,d).y+n(v.b,d).y+n(v.c,d).y+n(v.d,d).y,N.x/=4,N.y/=4),i(H+d,"",N));var K,O,k,A,B,I,L,j=b(e),q=0,z={},D={};for(d in j){for(K=j[d],B=d.split("_"),I=B[0],L=B[1],c(I,[I,L]),c(L,[I,L]),u=0,f=K.length;u<f;u++)v=K[u],s(I,v,d),s(L,v,d);K.length<2&&(U[d]=!0,w[I]=!0,w[L]=!0)}for(d in j)K=j[d],O=K[0],k=K[1],B=d.split("_"),I=B[0],L=B[1],A=new THREE.Vector3,o(K.length>0,"an edge without faces?!"),1==K.length?(A.add(m[I]),A.add(m[L]),A.multiplyScalar(.5),w[T.length]=!0):(A.add(V[O]),A.add(V[k]),A.add(m[I]),A.add(m[L]),A.multiplyScalar(.25)),S[d]=H+R.length+q,T.push(A),q++,y.supportUVs&&(N=new THREE.Vector2,N.x=n(I,O).x+n(L,O).x,N.y=n(I,O).y+n(L,O).y,N.x/=2,N.y/=2,i(S[d],O,N),K.length>=2&&(o(2==K.length,"did we plan for more than 2 edges?"),N=new THREE.Vector2,N.x=n(I,k).x+n(L,k).x,N.y=n(I,k).y+n(L,k).y,N.x/=2,N.y/=2,i(S[d],k,N)));t("-- Step 2 done");var J,P,Q,W,X,Y,Z=["123","12","2","23"],$=["123","23","3","31"],ee=["123","31","1","12"],oe=["1234","12","2","23"],te=["1234","23","3","34"],ae=["1234","34","4","41"],re=["1234","41","1","12"];for(d=0,l=V.length;d<l;d++)V[d],v=R[d],J=H+d,v instanceof THREE.Face3?(P=x(v.a,v.b),Q=x(v.b,v.c),Y=x(v.c,v.a),r(J,S[P],v.b,S[Q],v,Z,d),r(J,S[Q],v.c,S[Y],v,$,d),r(J,S[Y],v.a,S[P],v,ee,d)):v instanceof THREE.Face4?(P=x(v.a,v.b),Q=x(v.b,v.c),W=x(v.c,v.d),X=x(v.d,v.a),r(J,S[P],v.b,S[Q],v,oe,d),r(J,S[Q],v.c,S[W],v,te,d),r(J,S[W],v.d,S[X],v,ae,d),r(J,S[X],v.a,S[P],v,re,d)):t("face should be a face!",v);p=T;var ne,ie=new THREE.Vector3,ce=new THREE.Vector3;for(d=0,l=m.length;d<l;d++)if(void 0!==z[d]){ie.set(0,0,0),ce.set(0,0,0);var se=new THREE.Vector3(0,0,0),de=0;for(u in D[d])ie.add(V[u]),de++;var le=0;ne=z[d].length;var ue=de!=ne;for(u=0;u<ne;u++)U[x(z[d][u][0],z[d][u][1])]&&le++;ie.divideScalar(de);var fe=0;if(ue){for(u=0;u<ne;u++)if(K=z[d][u],1==j[x(K[0],K[1])].length){var ve=m[K[0]].clone().add(m[K[1]]).divideScalar(2);ce.add(ve),fe++}ce.divideScalar(4),o(2==fe,"should have only 2 boundary edges")}else{for(u=0;u<ne;u++){K=z[d][u];var ve=m[K[0]].clone().add(m[K[1]]).divideScalar(2);ce.add(ve)}ce.divideScalar(ne)}se.add(m[d]),ue?(se.divideScalar(2),se.add(ce)):(se.multiplyScalar(ne-3),se.add(ie),se.add(ce.multiplyScalar(2)),se.divideScalar(ne)),p[d]=se}var he=e;he.vertices=p,he.faces=E,he.faceVertexUvs[0]=g,delete he.__tmpVertices,he.computeCentroids(),he.computeFaceNormals(),he.computeVertexNormals()};
var TWEEN=TWEEN||function(){var n,t,a=60,i=!1,u=[];return{setFPS:function(n){a=n||60},start:function(n){0!=arguments.length&&this.setFPS(n),t=setInterval(this.update,1e3/a)},stop:function(){clearInterval(t)},setAutostart:function(n){(i=n)&&!t&&this.start()},add:function(n){u.push(n),i&&!t&&this.start()},getAll:function(){return u},removeAll:function(){u=[]},remove:function(t){-1!==(n=u.indexOf(t))&&u.splice(n,1)},update:function(t){for(n=0,num_tweens=u.length,t=t||Date.now();n<num_tweens;)u[n].update(t)?n++:(u.splice(n,1),num_tweens--);0==num_tweens&&1==i&&this.stop()}}}();TWEEN.Tween=function(n){var t={},a={},i={},u=1e3,E=0,s=null,e=TWEEN.Easing.Linear.EaseNone,r=null,o=null,c=null;this.to=function(t,a){null!==a&&(u=a);for(var E in t)null!==n[E]&&(i[E]=t[E]);return this},this.start=function(u){TWEEN.add(this),s=u?u+E:Date.now()+E;for(var e in i)null!==n[e]&&(t[e]=n[e],a[e]=i[e]-n[e]);return this},this.stop=function(){return TWEEN.remove(this),this},this.delay=function(n){return E=n,this},this.easing=function(n){return e=n,this},this.chain=function(n){r=n},this.onUpdate=function(n){return o=n,this},this.onComplete=function(n){return c=function(){var t=this;setTimeout(function(){n.call(t)},0)},this},this.update=function(i){var E,h;if(i<s)return!0;i=(i-s)/u,i=i>1?1:i,h=e(i);for(E in a)n[E]=t[E]+a[E]*h;return null!==o&&o.call(n,h),1!=i||(null!==c&&c.call(n),null!==r&&r.start(),!1)}},TWEEN.Easing={Linear:{},Quadratic:{},Cubic:{},Quartic:{},Quintic:{},Sinusoidal:{},Exponential:{},Circular:{},Elastic:{},Back:{},Bounce:{}},TWEEN.Easing.Linear.EaseNone=function(n){return n},TWEEN.Easing.Quadratic.EaseIn=function(n){return n*n},TWEEN.Easing.Quadratic.EaseOut=function(n){return-n*(n-2)},TWEEN.Easing.Quadratic.EaseInOut=function(n){return(n*=2)<1?.5*n*n:-.5*(--n*(n-2)-1)},TWEEN.Easing.Cubic.EaseIn=function(n){return n*n*n},TWEEN.Easing.Cubic.EaseOut=function(n){return--n*n*n+1},TWEEN.Easing.Cubic.EaseInOut=function(n){return(n*=2)<1?.5*n*n*n:.5*((n-=2)*n*n+2)},TWEEN.Easing.Quartic.EaseIn=function(n){return n*n*n*n},TWEEN.Easing.Quartic.EaseOut=function(n){return-(--n*n*n*n-1)},TWEEN.Easing.Quartic.EaseInOut=function(n){return(n*=2)<1?.5*n*n*n*n:-.5*((n-=2)*n*n*n-2)},TWEEN.Easing.Quintic.EaseIn=function(n){return n*n*n*n*n},TWEEN.Easing.Quintic.EaseOut=function(n){return(n-=1)*n*n*n*n+1},TWEEN.Easing.Quintic.EaseInOut=function(n){return(n*=2)<1?.5*n*n*n*n*n:.5*((n-=2)*n*n*n*n+2)},TWEEN.Easing.Sinusoidal.EaseIn=function(n){return 1-Math.cos(n*Math.PI/2)},TWEEN.Easing.Sinusoidal.EaseOut=function(n){return Math.sin(n*Math.PI/2)},TWEEN.Easing.Sinusoidal.EaseInOut=function(n){return-.5*(Math.cos(Math.PI*n)-1)},TWEEN.Easing.Exponential.EaseIn=function(n){return 0==n?0:Math.pow(2,10*(n-1))},TWEEN.Easing.Exponential.EaseOut=function(n){return 1==n?1:1-Math.pow(2,-10*n)},TWEEN.Easing.Exponential.EaseInOut=function(n){return 0==n?0:1==n?1:(n*=2)<1?.5*Math.pow(2,10*(n-1)):.5*(2-Math.pow(2,-10*(n-1)))},TWEEN.Easing.Circular.EaseIn=function(n){return-(Math.sqrt(1-n*n)-1)},TWEEN.Easing.Circular.EaseOut=function(n){return Math.sqrt(1- --n*n)},TWEEN.Easing.Circular.EaseInOut=function(n){return(n/=.5)<1?-.5*(Math.sqrt(1-n*n)-1):.5*(Math.sqrt(1-(n-=2)*n)+1)},TWEEN.Easing.Elastic.EaseIn=function(n){var t,a=.1,i=.4;return 0==n?0:1==n?1:(i||(i=.3),!a||a<1?(a=1,t=i/4):t=i/(2*Math.PI)*Math.asin(1/a),-a*Math.pow(2,10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i))},TWEEN.Easing.Elastic.EaseOut=function(n){var t,a=.1,i=.4;return 0==n?0:1==n?1:(i||(i=.3),!a||a<1?(a=1,t=i/4):t=i/(2*Math.PI)*Math.asin(1/a),a*Math.pow(2,-10*n)*Math.sin(2*(n-t)*Math.PI/i)+1)},TWEEN.Easing.Elastic.EaseInOut=function(n){var t,a=.1,i=.4;return 0==n?0:1==n?1:(i||(i=.3),!a||a<1?(a=1,t=i/4):t=i/(2*Math.PI)*Math.asin(1/a),(n*=2)<1?-.5*a*Math.pow(2,10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i):a*Math.pow(2,-10*(n-=1))*Math.sin(2*(n-t)*Math.PI/i)*.5+1)},TWEEN.Easing.Back.EaseIn=function(n){return n*n*(2.70158*n-1.70158)},TWEEN.Easing.Back.EaseOut=function(n){return(n-=1)*n*(2.70158*n+1.70158)+1},TWEEN.Easing.Back.EaseInOut=function(n){return(n*=2)<1?.5*n*n*(3.5949095*n-2.5949095):.5*((n-=2)*n*(3.5949095*n+2.5949095)+2)},TWEEN.Easing.Bounce.EaseIn=function(n){return 1-TWEEN.Easing.Bounce.EaseOut(1-n)},TWEEN.Easing.Bounce.EaseOut=function(n){return(n/=1)<1/2.75?7.5625*n*n:n<2/2.75?7.5625*(n-=1.5/2.75)*n+.75:n<2.5/2.75?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375},TWEEN.Easing.Bounce.EaseInOut=function(n){return n<.5?.5*TWEEN.Easing.Bounce.EaseIn(2*n):.5*TWEEN.Easing.Bounce.EaseOut(2*n-1)+.5};
!function(){var E=TWEEN.Tween;TWEEN.Tween=function(a){var n=this;$.extend(this,new E(a));var i=this.onComplete;this.onComplete=function(E){return i.call(n,function(){setTimeout(function(){E.call(n)},0)}),this}},TWEEN.Easing.Linear.EaseNone=TWEEN.Easing.Linear.EaseNone||TWEEN.Easing.Linear.None,TWEEN.Easing.Quadratic.EaseIn=TWEEN.Easing.Quadratic.EaseIn||TWEEN.Easing.Quadratic.In,TWEEN.Easing.Quadratic.EaseOut=TWEEN.Easing.Quadratic.EaseOut||TWEEN.Easing.Quadratic.Out,TWEEN.Easing.Quadratic.EaseInOut=TWEEN.Easing.Quadratic.EaseInOut||TWEEN.Easing.Quadratic.InOut,TWEEN.Easing.Cubic.EaseIn=TWEEN.Easing.Cubic.EaseIn||TWEEN.Easing.Cubic.In,TWEEN.Easing.Cubic.EaseOut=TWEEN.Easing.Cubic.EaseOut||TWEEN.Easing.Cubic.Out,TWEEN.Easing.Cubic.EaseInOut=TWEEN.Easing.Cubic.EaseInOut||TWEEN.Easing.Cubic.InOut,TWEEN.Easing.Quartic.EaseIn=TWEEN.Easing.Quartic.EaseIn||TWEEN.Easing.Quartic.In,TWEEN.Easing.Quartic.EaseOut=TWEEN.Easing.Quartic.EaseOut||TWEEN.Easing.Quartic.Out,TWEEN.Easing.Quartic.EaseInOut=TWEEN.Easing.Quartic.EaseInOut||TWEEN.Easing.Quartic.InOut,TWEEN.Easing.Quintic.EaseIn=TWEEN.Easing.Quintic.EaseIn||TWEEN.Easing.Quintic.In,TWEEN.Easing.Quintic.EaseOut=TWEEN.Easing.Quintic.EaseOut||TWEEN.Easing.Quintic.Out,TWEEN.Easing.Quintic.EaseInOut=TWEEN.Easing.Quintic.EaseInOut||TWEEN.Easing.Quintic.InOut,TWEEN.Easing.Sinusoidal.EaseIn=TWEEN.Easing.Sinusoidal.EaseIn||TWEEN.Easing.Sinusoidal.In,TWEEN.Easing.Sinusoidal.EaseOut=TWEEN.Easing.Sinusoidal.EaseOut||TWEEN.Easing.Sinusoidal.Out,TWEEN.Easing.Sinusoidal.EaseInOut=TWEEN.Easing.Sinusoidal.EaseInOut||TWEEN.Easing.Sinusoidal.InOut,TWEEN.Easing.Exponential.EaseIn=TWEEN.Easing.Exponential.EaseIn||TWEEN.Easing.Exponential.In,TWEEN.Easing.Exponential.EaseOut=TWEEN.Easing.Exponential.EaseOut||TWEEN.Easing.Exponential.Out,TWEEN.Easing.Exponential.EaseInOut=TWEEN.Easing.Exponential.EaseInOut||TWEEN.Easing.Exponential.InOut,TWEEN.Easing.Circular.EaseIn=TWEEN.Easing.Circular.EaseIn||TWEEN.Easing.Circular.In,TWEEN.Easing.Circular.EaseOut=TWEEN.Easing.Circular.EaseOut||TWEEN.Easing.Circular.Out,TWEEN.Easing.Circular.EaseInOut=TWEEN.Easing.Circular.EaseInOut||TWEEN.Easing.Circular.InOut,TWEEN.Easing.Elastic.EaseIn=TWEEN.Easing.Elastic.EaseIn||TWEEN.Easing.Elastic.In,TWEEN.Easing.Elastic.EaseOut=TWEEN.Easing.Elastic.EaseOut||TWEEN.Easing.Elastic.Out,TWEEN.Easing.Elastic.EaseInOut=TWEEN.Easing.Elastic.EaseInOut||TWEEN.Easing.Elastic.InOut,TWEEN.Easing.Back.EaseIn=TWEEN.Easing.Back.EaseIn||TWEEN.Easing.Back.In,TWEEN.Easing.Back.EaseOut=TWEEN.Easing.Back.EaseOut||TWEEN.Easing.Back.Out,TWEEN.Easing.Back.EaseInOut=TWEEN.Easing.Back.EaseInOut||TWEEN.Easing.Back.InOut,TWEEN.Easing.Bounce.EaseIn=TWEEN.Easing.Bounce.EaseIn||TWEEN.Easing.Bounce.In,TWEEN.Easing.Bounce.EaseOut=TWEEN.Easing.Bounce.EaseOut||TWEEN.Easing.Bounce.Out,TWEEN.Easing.Bounce.EaseInOut=TWEEN.Easing.Bounce.EaseInOut||TWEEN.Easing.Bounce.InOut}();
THREE.OrbitControls=function(t,e,n){function o(){return 2*Math.PI/60/60*p.autoRotateSpeed}function a(){return Math.pow(.95,p.zoomSpeed)}function i(t){if(!THREE.Object3D._threexDomEvent.lockObject(t,p.enableDrag)&&!1!==p.enabled){if(t.preventDefault(),t.stopPropagation(),0===t.button){if(!0===p.noRotate)return;V=k.ROTATE,g.set(t.clientX,t.clientY)}else if(1===t.button){if(!0===p.noZoom)return;V=k.DOLLY,O.set(t.clientX,t.clientY)}else if(2===t.button){if(!0===p.noPan)return;V=k.PAN,b.set(t.clientX,t.clientY)}p.domElement.addEventListener("mousemove",s,!1),p.domElement.addEventListener("mouseup",r,!1)}}function s(t){if(!1!==p.enabled){t.preventDefault(),t.stopPropagation();var e=p.domElement===document?p.domElement.body:p.domElement;if(V===k.ROTATE){if(!0===p.noRotate)return;T.set(t.clientX,t.clientY),f.subVectors(T,g),p.rotateLeft(2*Math.PI*f.x/e.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*f.y/e.clientHeight*p.rotateSpeed),g.copy(T)}else if(V===k.DOLLY){if(!0===p.noZoom)return;R.set(t.clientX,t.clientY),H.subVectors(R,O),H.y>0?p.dollyIn():p.dollyOut(),O.copy(R)}else if(V===k.PAN){if(!0===p.noPan)return;y.set(t.clientX,t.clientY),v.subVectors(y,b),p.pan(v),b.copy(y)}E()}}function r(){!1!==p.enabled&&(p.domElement.removeEventListener("mousemove",s,!1),p.domElement.removeEventListener("mouseup",r,!1),V=k.NONE)}function c(t){if(t.stopPropagation(),t.preventDefault(),!1!==p.enabled&&!0!==p.noZoom){var e=0;t.wheelDelta?e=t.wheelDelta:t.detail&&(e=-t.detail),e>0?p.dollyOut():p.dollyIn(),E()}}function h(t){!1!==p.enabled&&(this.mouseIsDown=!1,V=k.NONE)}function d(t){if(!1!==p.enabled&&!0!==p.noKeys&&!0!==p.noPan){var e=!1;switch(t.keyCode){case p.keys.UP:p.pan(new THREE.Vector2(0,p.keyPanSpeed)),e=!0;break;case p.keys.BOTTOM:p.pan(new THREE.Vector2(0,-p.keyPanSpeed)),e=!0;break;case p.keys.LEFT:p.pan(new THREE.Vector2(p.keyPanSpeed,0)),e=!0;break;case p.keys.RIGHT:p.pan(new THREE.Vector2(-p.keyPanSpeed,0)),e=!0}e&&p.update()}}function l(t){if(!THREE.Object3D._threexDomEvent.lockObject(t,p.enableDrag)&&!1!==p.enabled){switch(t.touches.length){case 1:if(!0===p.noRotate)return;V=k.TOUCH_ROTATE,g.set(t.touches[0].pageX,t.touches[0].pageY);break;case 2:if(!0===p.noZoom)return;V=k.TOUCH_DOLLY;var e=t.touches[0].pageX-t.touches[1].pageX,n=t.touches[0].pageY-t.touches[1].pageY,o=Math.sqrt(e*e+n*n);O.set(0,o);break;case 3:if(!0===p.noPan)return;V=k.TOUCH_PAN,b.set(t.touches[0].pageX,t.touches[0].pageY);break;default:V=k.NONE}E()}}function m(t){if(!1!==p.enabled){t.preventDefault(),t.stopPropagation();var e=p.domElement===document?p.domElement.body:p.domElement;switch(t.touches.length){case 1:if(!0===p.noRotate)return;if(V!==k.TOUCH_ROTATE)return;T.set(t.touches[0].pageX,t.touches[0].pageY),f.subVectors(T,g),p.rotateLeft(2*Math.PI*f.x/e.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*f.y/e.clientHeight*p.rotateSpeed),g.copy(T);break;case 2:if(!0===p.noZoom)return;if(V!==k.TOUCH_DOLLY)return;var n=t.touches[0].pageX-t.touches[1].pageX,o=t.touches[0].pageY-t.touches[1].pageY,a=Math.sqrt(n*n+o*o);R.set(0,a),H.subVectors(R,O),H.y>0?p.dollyOut():p.dollyIn(),O.copy(R);break;case 3:if(!0===p.noPan)return;if(V!==k.TOUCH_PAN)return;y.set(t.touches[0].pageX,t.touches[0].pageY),v.subVectors(y,b),p.pan(v),b.copy(y);break;default:V=k.NONE}E()}}function u(){!1!==p.enabled&&(V=k.NONE)}function E(){p.animControl&&p.animControl.trigger()}this.object=e,this.camera=t,this.domElement=void 0!==n?n:document,this.enabled=!0,this.camTarget=new THREE.Vector3,this.center=this.camTarget,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},this.animControl=null,this.enableDrag=!0,this.targetBounds=[3,3,3];var p=this,g=new THREE.Vector2,T=new THREE.Vector2,f=new THREE.Vector2,b=new THREE.Vector2,y=new THREE.Vector2,v=new THREE.Vector2,O=new THREE.Vector2,R=new THREE.Vector2,H=new THREE.Vector2,P=0,L=0,w=1,M=new THREE.Vector3,D=new THREE.Vector3,k={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},V=k.NONE,x={type:"change"};this.rotateLeft=function(t){void 0===t&&(t=o()),L-=t},this.rotateUp=function(t){void 0===t&&(t=o()),P-=t},this.panLeft=function(t){var e=new THREE.Vector3,n=this.object.matrix.elements;e.set(n[0],n[1],n[2]),e.multiplyScalar(-t),M.add(e)},this.panUp=function(t){var e=new THREE.Vector3,n=this.object.matrix.elements;e.set(n[4],n[5],n[6]),e.multiplyScalar(t),M.add(e)},this.pan=function(t){var e=p.domElement===document?p.domElement.body:p.domElement;if(void 0!==p.camera.fov){var n=p.object.position,o=n.clone().sub(p.camTarget),a=o.length();a*=Math.tan(p.camera.fov/2*Math.PI/180),p.panLeft(2*t.x*a/e.clientHeight),p.panUp(2*t.y*a/e.clientHeight)}else void 0!==p.object.top?(p.panLeft(t.x*(p.object.right-p.object.left)/e.clientWidth),p.panUp(t.y*(p.object.top-p.object.bottom)/e.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(t){void 0===t&&(t=a()),w/=t},this.dollyOut=function(t){void 0===t&&(t=a()),w*=t},this.update=function(){var t=this.object.position,e=t.clone().sub(this.camTarget),n=Math.atan2(e.x,e.z),a=Math.atan2(Math.sqrt(e.x*e.x+e.z*e.z),e.y);this.autoRotate&&this.rotateLeft(o()),n+=L,a+=P,a=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,a)),a=Math.max(1e-6,Math.min(Math.PI-1e-6,a));var i=e.length()*w;i=Math.max(this.minDistance,Math.min(this.maxDistance,i)),this.camTarget.add(M),e.x=i*Math.sin(a)*Math.sin(n),e.y=i*Math.cos(a),e.z=i*Math.sin(a)*Math.cos(n),this.camTarget.x<-this.targetBounds[0]&&this.camTarget.setX(-this.targetBounds[0]),this.camTarget.x>this.targetBounds[0]&&this.camTarget.setX(this.targetBounds[0]),this.camTarget.y<-this.targetBounds[1]&&this.camTarget.setY(-this.targetBounds[1]),this.camTarget.y>this.targetBounds[1]&&this.camTarget.setY(this.targetBounds[1]),this.camTarget.z<-this.targetBounds[2]&&this.camTarget.setZ(-this.targetBounds[2]),this.camTarget.z>this.targetBounds[2]&&this.camTarget.setZ(this.targetBounds[2]),t.copy(this.camTarget).add(e);var s=new THREE.Vector3;s.copy(this.camera.position),this.camera.position.copy(this.object.position),this.camera.lookAt(this.camTarget),this.camera.position.copy(s),L=0,P=0,w=1,M.set(0,0,0),D.distanceTo(this.object.position)>0&&("function"==typeof this.dispatchEvent&&this.dispatchEvent(x),D.copy(this.object.position))},this.destroy=function(){},this.domElement.addEventListener("contextmenu",function(t){t.preventDefault(),t.stopPropagation()},!1),this.domElement.addEventListener("mousedown",i,!1),this.domElement.addEventListener("mousewheel",c,!1),this.domElement.addEventListener("mouseout",h,!1),this.domElement.addEventListener("DOMMouseScroll",c,!1),this.domElement.addEventListener("keydown",d,!1),this.domElement.addEventListener("touchstart",l,!1),this.domElement.addEventListener("touchend",u,!1),this.domElement.addEventListener("touchmove",m,!1)},THREE.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype);
THREE.DeviceOrientationControls=function(e,t){var n=this;this.object=e,this.enabled=!1,this.deviceOrientation={},this.screenOrientation=0,this.alpha=0,this.alphaOffsetAngle=0,this.calibration=!0;var i=function(e){(null!==e.alpha||null!==e.beta|null!==e.gamma)&&(n.object.rotation.reorder("YXZ"),n.enabled=!0),n.deviceOrientation=e,t(n)},a=function(){n.screenOrientation=window.orientation||0,t(n)},o=function(){var e=new THREE.Vector3(0,0,1),t=new THREE.Euler,n=new THREE.Quaternion,i=new THREE.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5));return function(a,o,r,s,c){t.set(r,o,-s,"YXZ"),a.setFromEuler(t),a.multiply(i),a.multiply(n.setFromAxisAngle(e,-c))}}();this.connect=function(){a(),window.addEventListener("orientationchange",a,!1),window.addEventListener("deviceorientation",i,!1)},this.disconnect=function(){window.removeEventListener("orientationchange",a,!1),window.removeEventListener("deviceorientation",i,!1),n.enabled=!1},this.update=function(){if(!1!==n.enabled){n.calibration&&(n.calibration=!1,this.alphaOffsetAngle=-e.rotation.y-THREE.Math.degToRad(n.deviceOrientation.alpha)+Math.PI/2);var t=n.deviceOrientation.alpha?THREE.Math.degToRad(n.deviceOrientation.alpha)+this.alphaOffsetAngle:0,i=n.deviceOrientation.beta?THREE.Math.degToRad(n.deviceOrientation.beta):0,a=n.deviceOrientation.gamma?THREE.Math.degToRad(n.deviceOrientation.gamma):0,r=n.screenOrientation?THREE.Math.degToRad(n.screenOrientation):0;o(n.object.quaternion,t,i,a,r),this.alpha=t}},this.updateAlphaOffsetAngle=function(e){this.alphaOffsetAngle=e,this.update()},this.dispose=function(){this.disconnect()},this.connect()};
THREE.RenderableObject=function(){this.id=0,this.object=null,this.z=0,this.renderOrder=0},THREE.RenderableFace=function(){this.id=0,this.v1=new THREE.RenderableVertex,this.v2=new THREE.RenderableVertex,this.v3=new THREE.RenderableVertex,this.normalModel=new THREE.Vector3,this.vertexNormalsModel=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3],this.vertexNormalsLength=0,this.color=new THREE.Color,this.material=null,this.uvs=[new THREE.Vector2,new THREE.Vector2,new THREE.Vector2],this.z=0,this.renderOrder=0},THREE.RenderableVertex=function(){this.position=new THREE.Vector3,this.positionWorld=new THREE.Vector3,this.positionScreen=new THREE.Vector4,this.visible=!0},THREE.RenderableVertex.prototype.copy=function(e){this.positionWorld.copy(e.positionWorld),this.positionScreen.copy(e.positionScreen)},THREE.RenderableLine=function(){this.id=0,this.v1=new THREE.RenderableVertex,this.v2=new THREE.RenderableVertex,this.vertexColors=[new THREE.Color,new THREE.Color],this.material=null,this.z=0,this.renderOrder=0},THREE.RenderableSprite=function(){this.id=0,this.object=null,this.x=0,this.y=0,this.z=0,this.rotation=0,this.scale=new THREE.Vector2,this.material=null,this.renderOrder=0},THREE.Projector=function(){function e(){if(l===x){var e=new THREE.RenderableObject;return R.push(e),x++,l++,e}return R[l++]}function r(){if(p===T){var e=new THREE.RenderableVertex;return y.push(e),T++,p++,e}return y[p++]}function t(){if(u===w){var e=new THREE.RenderableFace;return H.push(e),w++,u++,e}return H[u++]}function n(){if(h===b){var e=new THREE.RenderableLine;return g.push(e),b++,h++,e}return g[h++]}function i(){if(v===S){var e=new THREE.RenderableSprite;return M.push(e),S++,v++,e}return M[v++]}function o(e,r){return e.renderOrder!==r.renderOrder?e.renderOrder-r.renderOrder:e.z!==r.z?r.z-e.z:e.id!==r.id?e.id-r.id:0}function a(e,r){var t=0,n=1,i=e.z+e.w,o=r.z+r.w,a=-e.z+e.w,s=-r.z+r.w;return i>=0&&o>=0&&a>=0&&s>=0||!(i<0&&o<0||a<0&&s<0)&&(i<0?t=Math.max(t,i/(i-o)):o<0&&(n=Math.min(n,i/(i-o))),a<0?t=Math.max(t,a/(a-s)):s<0&&(n=Math.min(n,a/(a-s))),!(n<t)&&(e.lerp(r,t),r.lerp(e,1-n),!0))}var s,l,c,p,E,u,d,h,f,v,m,R=[],x=0,y=[],T=0,H=[],w=0,g=[],b=0,M=[],S=0,z={objects:[],lights:[],elements:[]},V=new THREE.Vector3,j=new THREE.Vector4,O=new THREE.Box3(new THREE.Vector3(-1,-1,-1),new THREE.Vector3(1,1,1)),C=new THREE.Box3,L=new Array(3),k=(new Array(4),new THREE.Matrix4),N=new THREE.Matrix4,W=new THREE.Matrix4,B=new THREE.Matrix3,F=new THREE.Frustum,P=new THREE.Vector4,A=new THREE.Vector4;this.projectVector=function(e,r){console.warn("THREE.Projector: .projectVector() is now vector.project()."),e.project(r)},this.unprojectVector=function(e,r){console.warn("THREE.Projector: .unprojectVector() is now vector.unproject()."),e.unproject(r)},this.pickingRay=function(e,r){console.error("THREE.Projector: .pickingRay() is now raycaster.setFromCamera().")};var D=function(){function e(e){R=e,x=R.material,T.getNormalMatrix(R.matrixWorld),f.length=0,v.length=0}function i(e){var r=e.position,t=e.positionWorld,n=e.positionScreen;t.copy(r).applyMatrix4(m),n.copy(t).applyMatrix4(N);var i=1/n.w;n.x*=i,n.y*=i,n.z*=i,e.visible=n.x>=-1&&n.x<=1&&n.y>=-1&&n.y<=1&&n.z>=-1&&n.z<=1}function o(e,t,n){c=r(),c.position.set(e,t,n),i(c)}function a(e,r,t){f.push(e,r,t)}function s(e,r){v.push(e,r)}function l(e,r,t){return!0===e.visible||!0===r.visible||!0===t.visible||(L[0]=e.positionScreen,L[1]=r.positionScreen,L[2]=t.positionScreen,O.intersectsBox(C.setFromPoints(L)))}function p(e,r,t){return(t.positionScreen.x-e.positionScreen.x)*(r.positionScreen.y-e.positionScreen.y)-(t.positionScreen.y-e.positionScreen.y)*(r.positionScreen.x-e.positionScreen.x)<0}function u(e,r){var t=y[e],i=y[r];d=n(),d.id=R.id,d.v1.copy(t),d.v2.copy(i),d.z=(t.positionScreen.z+i.positionScreen.z)/2,d.renderOrder=R.renderOrder,d.material=R.material,z.elements.push(d)}function h(e,r,n){var i=y[e],o=y[r],a=y[n];if(!1!==l(i,o,a)&&(x.side===THREE.DoubleSide||!0===p(i,o,a))){E=t(),E.id=R.id,E.v1.copy(i),E.v2.copy(o),E.v3.copy(a),E.z=(i.positionScreen.z+o.positionScreen.z+a.positionScreen.z)/3,E.renderOrder=R.renderOrder,E.normalModel.fromArray(f,3*e),E.normalModel.applyMatrix3(T).normalize();for(var s=0;s<3;s++){var c=E.vertexNormalsModel[s];c.fromArray(f,3*arguments[s]),c.applyMatrix3(T).normalize();E.uvs[s].fromArray(v,2*arguments[s])}E.vertexNormalsLength=3,E.material=R.material,z.elements.push(E)}}var f=[],v=[],R=null,x=null,T=new THREE.Matrix3;return{setObject:e,projectVertex:i,checkTriangleVisibility:l,checkBackfaceCulling:p,pushVertex:o,pushNormal:a,pushUv:s,pushLine:u,pushTriangle:h}},G=new D;this.projectScene=function(c,R,x,T){function H(r){s=e(),s.id=r.id,s.object=r,V.setFromMatrixPosition(r.matrixWorld),V.applyMatrix4(N),s.z=V.z,s.renderOrder=r.renderOrder,z.objects.push(s)}u=0,h=0,v=0,z.elements.length=0,!0===c.autoUpdate&&c.updateMatrixWorld(),null===R.parent&&R.updateMatrixWorld(),k.copy(R.matrixWorldInverse.getInverse(R.matrixWorld)),N.multiplyMatrices(R.projectionMatrix,k),F.setFromMatrix(N),l=0,z.objects.length=0,z.lights.length=0,c.traverseVisible(function(e){if(e instanceof THREE.Light)z.lights.push(e);else if(e instanceof THREE.Mesh||e instanceof THREE.Line){if(!1===e.material.visible)return;if(!0===e.frustumCulled&&!1===F.intersectsObject(e))return;H(e)}else if(e instanceof THREE.Sprite){if(!1===e.material.visible)return;if(!0===e.frustumCulled&&!1===F.intersectsSprite(e))return;H(e)}}),!0===x&&z.objects.sort(o);for(var w=0,g=z.objects.length;w<g;w++){var b=z.objects[w].object,M=b.geometry;if(G.setObject(b),m=b.matrixWorld,p=0,b instanceof THREE.Mesh){if(M instanceof THREE.BufferGeometry){var S=M.attributes,O=M.groups;if(void 0===S.position)continue;for(var C=S.position.array,L=0,D=C.length;L<D;L+=3)G.pushVertex(C[L],C[L+1],C[L+2]);if(void 0!==S.normal)for(var I=S.normal.array,L=0,D=I.length;L<D;L+=3)G.pushNormal(I[L],I[L+1],I[L+2]);if(void 0!==S.uv)for(var U=S.uv.array,L=0,D=U.length;L<D;L+=2)G.pushUv(U[L],U[L+1]);if(null!==M.index){var q=M.index.array;if(O.length>0)for(var J=0;J<O.length;J++)for(var K=O[J],L=K.start,D=K.start+K.count;L<D;L+=3)G.pushTriangle(q[L],q[L+1],q[L+2]);else for(var L=0,D=q.length;L<D;L+=3)G.pushTriangle(q[L],q[L+1],q[L+2])}else for(var L=0,D=C.length/3;L<D;L+=3)G.pushTriangle(L,L+1,L+2)}else if(M instanceof THREE.Geometry){var Q=M.vertices,X=M.faces,Y=M.faceVertexUvs[0];B.getNormalMatrix(m);for(var Z=b.material,$=Z instanceof THREE.MultiMaterial,_=!0===$?b.material:null,ee=0,re=Q.length;ee<re;ee++){var te=Q[ee];if(V.copy(te),!0===Z.morphTargets)for(var ne=M.morphTargets,ie=b.morphTargetInfluences,oe=0,ae=ne.length;oe<ae;oe++){var se=ie[oe];if(0!==se){var le=ne[oe],ce=le.vertices[ee];V.x+=(ce.x-te.x)*se,V.y+=(ce.y-te.y)*se,V.z+=(ce.z-te.z)*se}}G.pushVertex(V.x,V.y,V.z)}for(var pe=0,Ee=X.length;pe<Ee;pe++){var ue=X[pe];if(void 0!==(Z=!0===$?_.materials[ue.materialIndex]:b.material)){var de=Z.side,he=y[ue.a],fe=y[ue.b],ve=y[ue.c];if(!1!==G.checkTriangleVisibility(he,fe,ve)){var me=G.checkBackfaceCulling(he,fe,ve);if(de!==THREE.DoubleSide){if(de===THREE.FrontSide&&!1===me)continue;if(de===THREE.BackSide&&!0===me)continue}E=t(),E.id=b.id,E.v1.copy(he),E.v2.copy(fe),E.v3.copy(ve),E.normalModel.copy(ue.normal),!1!==me||de!==THREE.BackSide&&de!==THREE.DoubleSide||E.normalModel.negate(),E.normalModel.applyMatrix3(B).normalize();for(var Re=ue.vertexNormals,xe=0,ye=Math.min(Re.length,3);xe<ye;xe++){var Te=E.vertexNormalsModel[xe];Te.copy(Re[xe]),!1!==me||de!==THREE.BackSide&&de!==THREE.DoubleSide||Te.negate(),Te.applyMatrix3(B).normalize()}E.vertexNormalsLength=Re.length;var He=Y[pe];if(void 0!==He)for(var we=0;we<3;we++)E.uvs[we].copy(He[we]);E.color=ue.color,E.material=Z,E.z=(he.positionScreen.z+fe.positionScreen.z+ve.positionScreen.z)/3,E.renderOrder=b.renderOrder,z.elements.push(E)}}}}}else if(b instanceof THREE.Line){if(M instanceof THREE.BufferGeometry){var S=M.attributes;if(void 0!==S.position){for(var C=S.position.array,L=0,D=C.length;L<D;L+=3)G.pushVertex(C[L],C[L+1],C[L+2]);if(null!==M.index)for(var q=M.index.array,L=0,D=q.length;L<D;L+=2)G.pushLine(q[L],q[L+1]);else for(var ge=b instanceof THREE.LineSegments?2:1,L=0,D=C.length/3-1;L<D;L+=ge)G.pushLine(L,L+1)}}else if(M instanceof THREE.Geometry){W.multiplyMatrices(N,m);var Q=b.geometry.vertices;if(0===Q.length)continue;he=r(),he.positionScreen.copy(Q[0]).applyMatrix4(W);for(var ge=b instanceof THREE.LineSegments?2:1,ee=1,re=Q.length;ee<re;ee++)he=r(),he.positionScreen.copy(Q[ee]).applyMatrix4(W),(ee+1)%ge>0||(fe=y[p-2],P.copy(he.positionScreen),A.copy(fe.positionScreen),!0===a(P,A)&&(P.multiplyScalar(1/P.w),A.multiplyScalar(1/A.w),d=n(),d.id=b.id,d.v1.positionScreen.copy(P),d.v2.positionScreen.copy(A),d.z=Math.max(P.z,A.z),d.renderOrder=b.renderOrder,d.material=b.material,b.material.vertexColors===THREE.VertexColors&&(d.vertexColors[0].copy(b.geometry.colors[ee]),d.vertexColors[1].copy(b.geometry.colors[ee-1])),z.elements.push(d)))}}else if(b instanceof THREE.Sprite){j.set(m.elements[12],m.elements[13],m.elements[14],1),j.applyMatrix4(N);var be=1/j.w;j.z*=be,j.z>=-1&&j.z<=1&&(f=i(),f.id=b.id,f.x=j.x*be,f.y=j.y*be,f.z=j.z,f.renderOrder=b.renderOrder,f.object=b,f.rotation=b.rotation,f.scale.x=b.scale.x*Math.abs(f.x-(j.x+R.projectionMatrix.elements[0])/(j.w+R.projectionMatrix.elements[12])),f.scale.y=b.scale.y*Math.abs(f.y-(j.y+R.projectionMatrix.elements[5])/(j.w+R.projectionMatrix.elements[13])),f.material=b.material,z.elements.push(f))}}return!0===T&&z.elements.sort(o),z}};
var THREEx=THREEx||{};THREEx.DomEvent=function(t){this._camera=t||null,this._domElement=null,this._projector=new THREE.Projector,this._selected=null,this._boundObjs={},this.setBoundContext("_"),this.mouseIsDown=!1,this.mouseDragNotified=!1,this.lastDownTime=0;var e=this;this._$onMouseMove=function(){e._onMouseMove.apply(e,arguments)},this._$onMouseDown=function(){e._onMouseDown.apply(e,arguments)},this._$onMouseUp=function(){e._onMouseUp.apply(e,arguments)},this._$onTouchMove=function(){e._onTouchMove.apply(e,arguments)},this._$onTouchStart=function(){e._onTouchStart.apply(e,arguments)},this._$onTouchEnd=function(){e._onTouchEnd.apply(e,arguments)}},THREEx.DomEvent.prototype.setDOMElement=function(t){this._domElement&&this.unsetDOMElement(),this._domElement=t,this._domElement.addEventListener("mousemove",this._$onMouseMove,!1),this._domElement.addEventListener("mousedown",this._$onMouseDown,!1),this._domElement.addEventListener("mouseup",this._$onMouseUp,!1),this._domElement.addEventListener("touchmove",this._$onTouchMove,!1),this._domElement.addEventListener("touchstart",this._$onTouchStart,!1),this._domElement.addEventListener("touchend",this._$onTouchEnd,!1)},THREEx.DomEvent.prototype.unsetDOMElement=function(){this._domElement&&(this._domElement.removeEventListener("mousemove",this._$onMouseMove,!1),this._domElement.removeEventListener("mousedown",this._$onMouseDown,!1),this._domElement.removeEventListener("mouseup",this._$onMouseUp,!1),this._domElement.removeEventListener("touchmove",this._$onTouchMove,!1),this._domElement.removeEventListener("touchstart",this._$onTouchStart,!1),this._domElement.removeEventListener("touchend",this._$onTouchEnd,!1),this._domElement=null)},THREEx.DomEvent.prototype.setBoundContext=function(t){this._boundContext=t,void 0===this._boundObjs[t]&&(this._boundObjs[t]=[])},THREEx.DomEvent.prototype.unsetBoundContext=function(t){if(void 0!==this._boundObjs[t])for(var e=this._boundObjs[t],o=0;o<e.length;o++){var n=e[o];if(n._3xDomEvent)for(var s in n._3xDomEvent){var i=/^(.*)Handlers$/.exec(s);if(i)for(var u=i[1],r=n._3xDomEvent[s],h=0;h<r.length;h++){var c=r[h];this.unbind(n,u,c.callback,c.useCapture)}}}},THREEx.DomEvent.prototype.destroy=function(){for(var t in this._boundObjs)this.unsetBoundContext(t);this.unsetDOMElement()},THREEx.DomEvent.eventNames=["mousedown","mouseup","mousemove","touchmove","touchstart","touchend"],THREEx.DomEvent.prototype._objectCtxInit=function(t){t._3xDomEvent={}},THREEx.DomEvent.prototype._objectCtxDeinit=function(t){delete t._3xDomEvent},THREEx.DomEvent.prototype._objectCtxIsInit=function(t){return!!t._3xDomEvent},THREEx.DomEvent.prototype._objectCtxGet=function(t){return t._3xDomEvent},THREEx.DomEvent.prototype.camera=function(t){return t&&(this._camera=t),this._camera},THREEx.DomEvent.prototype.bind=function(t,e,o,n){function s(t){i._boundObjs[i._boundContext].push(t);for(var e=0;e<t.children.length;e++)s(t.children[e])}var i=this;console.assert(-1!==THREEx.DomEvent.eventNames.indexOf(e),"not available events:"+e),this._objectCtxIsInit(t)||this._objectCtxInit(t);var u=this._objectCtxGet(t);u[e+"Handlers"]||(u[e+"Handlers"]=[]),u[e+"Handlers"].push({callback:o,useCapture:n}),s(t)},THREEx.DomEvent.prototype.unbind=function(t,e,o){function n(t){var e=s._boundObjs[s._boundContext].indexOf(t);e>=0&&s._boundObjs[s._boundContext].splice(e,1);for(var o=0;o<t.children.length;o++)n(t.children[o])}var s=this;console.assert(-1!==THREEx.DomEvent.eventNames.indexOf(e),"not available events:"+e),this._objectCtxIsInit(t)||this._objectCtxInit(t);var i=this._objectCtxGet(t);i[e+"Handlers"]||(i[e+"Handlers"]=[]);for(var u=i[e+"Handlers"],r=0;r<u.length;r++){var h=u[r];if(!o||o==h.callback){u.splice(r,1),n(t);break}}},THREEx.DomEvent.prototype._bound=function(t,e){var o=this._objectCtxGet(this.getRootObject(e));return!!o&&!!o[t+"Handlers"]},THREEx.DomEvent.prototype.getRootObject=function(t){for(var e=t;t&&!t._3xDomEvent;)t=t.parent;return t||console.error("Could not find root object for",e),t},THREEx.DomEvent.prototype.isTHREExTarget=function(t,e){var o=$(this._domElement),n=o.offset(),s=+(t-n.left)/o.width()*2-1,i=-(e-n.top)/o.height()*2+1,u=new THREE.Vector3(s,i,1);u.unproject(this._camera);var r=this._camera.getWorldPosition();return u.sub(r).normalize(),0!==new THREE.Raycaster(r,u).intersectObjects(this._boundObjs[this._boundContext]).length},THREEx.DomEvent.prototype.lockObject=function(t,e){if(/^mouse/.test(t.type)&&0!=t.button)return!1;var o,n,s=$(this._domElement),i=s.offset();if(void 0!==t.clientX&&void 0!==t.clientY)o=t.clientX,n=t.clientY;else if(t.touches&&t.touches.length>0)o=t.touches[0].pageX,n=t.touches[0].pageY;else{if(!(t.changedTouches&&t.changedTouches.length>0))return console.warn("Unable to get event position"),!1;o=t.changedTouches[0].pageX,n=t.changedTouches[0].pageY}var u=+(o-i.left)/s.width()*2-1,r=-(n-i.top)/s.height()*2+1,h=new THREE.Vector3(u,r,1);h.unproject(this._camera);var c=this._camera.getWorldPosition();h.sub(c).normalize();var E=new THREE.Raycaster(c,h),a=E.intersectObjects(this._boundObjs[this._boundContext]);return this.objectLocked=0!==a.length,this.enableDrag=this.objectLocked&&e,this.objectLocked},THREEx.DomEvent.prototype._onEvent=function(t,e,o,n,s,i){if("mouseup"==t){if(this.mouseIsDown=!1,!this.objectLocked)return null}else if("mousedown"==t)this.mouseIsDown=!0,this.mouseDownPos=[s,i],this.mouseDragNotified=!1,this.lastDownTime=Date.now();else if("mousemove"==t&&this.mouseIsDown){var u=this.mouseDownPos[0]-s,r=this.mouseDownPos[1]-i,h=u*u+r*r;if(this.enableDrag){if(h<100)return null;if(!this.mouseDragNotified)return Date.now()-this.lastDownTime<50?null:(this.mouseDragNotified=!0,this._onEvent("mouseup",this.mouseEventPos[0],this.mouseEventPos[1],n,s,i))}else if(h>100)return this.objectLocked=!1,null}var c=new THREE.Vector3(e,o,1);c.unproject(this._camera);var E=this._camera.getWorldPosition();c.sub(E).normalize();var a=new THREE.Raycaster(E,c),m=a.intersectObjects(this._boundObjs[this._boundContext]);if(0===m.length)return null;var l=m[0],v=this.getRootObject(l.object);if(!this._objectCtxGet(v))return null;this._notify(t,v,n,l.point)},THREEx.DomEvent.prototype._notify=function(t,e,o,n){var s=this._objectCtxGet(e),i=s?s[t+"Handlers"]:null;if(!s||!i||0===i.length)return void(e.parent&&this._notify(t,e.parent));for(var i=s[t+"Handlers"],u=0;u<i.length;u++){var r=i[u],h=!0;r.callback({type:t,target:e,origDomEvent:o,stopPropagation:function(){h=!1},point:n}),h&&(!1===r.useCapture&&e.parent&&this._notify(t,e.parent,o,n))}},THREEx.DomEvent.prototype._onMouseDown=function(t){if(0===t.button)return this._onMouseEvent("mousedown",t)},THREEx.DomEvent.prototype._onMouseUp=function(t){if(0===t.button)return this._onMouseEvent("mouseup",t)},THREEx.DomEvent.prototype._onMouseMove=function(t){return this.mouseIsDown?this._onMouseEvent("mousemove",t):null},THREEx.DomEvent.prototype._onMouseEvent=function(t,e){var o=$(this._domElement),n=o.offset(),s=+(e.clientX-n.left)/o.width()*2-1,i=-(e.clientY-n.top)/o.height()*2+1;return this.mouseEventPos=[s,i],this._onEvent(t,s,i,e,e.clientX-n.left,e.clientY-n.top)},THREEx.DomEvent.prototype._onTouchStart=function(t){return this._onTouchEvent("mousedown",t)},THREEx.DomEvent.prototype._onTouchEnd=function(t){return this._onTouchEvent("mouseup",t)},THREEx.DomEvent.prototype._onTouchMove=function(t){return this.mouseIsDown?this._onTouchEvent("mousemove",t):null},THREEx.DomEvent.prototype._onTouchEvent=function(t,e){var o=$(this._domElement),n=o.offset(),s=0,i=0,u=0,r=0;return e.touches&&e.touches.length>0?(s=+(e.touches[0].clientX-n.left)/o.width()*2-1,i=-(e.touches[0].clientY-n.top)/o.height()*2+1,u=e.touches[0].clientX-n.left,r=e.touches[0].clientY-n.top):e.changedTouches&&e.changedTouches.length>0&&(s=+(e.changedTouches[0].clientX-n.left)/o.width()*2-1,i=-(e.changedTouches[0].clientY-n.top)/o.height()*2+1,u=e.changedTouches[0].clientX-n.left,r=e.changedTouches[0].clientY-n.top),this.mouseEventPos=[s,i],this._onEvent(t,s,i,e,u,r)};
THREEx.DomEvent.noConflict=function(){THREEx.DomEvent.noConflict.symbols.forEach(function(t){THREE.Object3D.prototype[t]=THREEx.DomEvent.noConflict.previous[t]})},THREEx.DomEvent.noConflict.symbols=["on","off","addEventListener","removeEventListener"],THREEx.DomEvent.noConflict.previous={},THREEx.DomEvent.noConflict.symbols.forEach(function(t){THREEx.DomEvent.noConflict.previous[t]=THREE.Object3D.prototype[t]}),THREE.Object3D.prototype._addEventListener=THREE.Object3D.prototype.addEventListener,THREE.Object3D.prototype.on=THREE.Object3D.prototype.addEventListener=function(t,e){return THREE.Object3D._threexDomEvent.bind(this,t,e),this},THREE.Object3D.prototype._removeEventListener=THREE.Object3D.prototype.removeEventListener,THREE.Object3D.prototype.off=THREE.Object3D.prototype.removeEventListener=function(t,e){return THREE.Object3D._threexDomEvent.unbind(this,t,e),this};
THREE.StereoEffect=function(e){var t=new THREE.StereoCamera;t.aspect=.5,this.setEyeSeparation=function(e){t.eyeSep=e},this.setSize=function(t,i){e.setSize(t,i)},this.render=function(i,r){i.updateMatrixWorld(),null===r.parent&&r.updateMatrixWorld(),t.update(r);var s=e.getSize();e.autoClear&&e.clear(),e.setScissorTest(!0),e.setScissor(0,0,s.width/2,s.height),e.setViewport(0,0,s.width/2,s.height),e.render(i,t.cameraL),e.setScissor(s.width/2,0,s.width/2,s.height),e.setViewport(s.width/2,0,s.width/2,s.height),e.render(i,t.cameraR),e.setScissorTest(!1)}};
THREE.AnaglyphEffect=function(t,e,r){this.colorMatrixLeft=(new THREE.Matrix3).fromArray([1.0671679973602295,-.0016435992438346148,.0001777536963345483,-.028107794001698494,-.00019593400065787137,-.0002875397040043026,-.04279090091586113,15809757314855233e-21,-.00024287120322696865]),this.colorMatrixRight=(new THREE.Matrix3).fromArray([-.0355340838432312,-.06440307199954987,.018319187685847282,-.10269022732973099,.8079727292060852,-.04835830628871918,.0001224992738571018,-.009558862075209618,.567823588848114]);var o=new THREE.OrthographicCamera(-1,1,1,-1,0,1),i=new THREE.Scene,a=new THREE.StereoCamera,n={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat};void 0===e&&(e=512),void 0===r&&(r=512);var c=new THREE.WebGLRenderTarget(e,r,n),l=new THREE.WebGLRenderTarget(e,r,n),v=new THREE.ShaderMaterial({uniforms:{mapLeft:{value:c.texture},mapRight:{value:l.texture},colorMatrixLeft:{value:this.colorMatrixLeft},colorMatrixRight:{value:this.colorMatrixRight}},vertexShader:["varying vec2 vUv;","void main() {","\tvUv = vec2( uv.x, uv.y );","\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform sampler2D mapLeft;","uniform sampler2D mapRight;","varying vec2 vUv;","uniform mat3 colorMatrixLeft;","uniform mat3 colorMatrixRight;","float lin( float c ) {","\treturn c <= 0.04045 ? c * 0.0773993808 :","\t\t\tpow( c * 0.9478672986 + 0.0521327014, 2.4 );","}","vec4 lin( vec4 c ) {","\treturn vec4( lin( c.r ), lin( c.g ), lin( c.b ), c.a );","}","float dev( float c ) {","\treturn c <= 0.0031308 ? c * 12.92","\t\t\t: pow( c, 0.41666 ) * 1.055 - 0.055;","}","void main() {","\tvec2 uv = vUv;","\tvec4 colorL = lin( texture2D( mapLeft, uv ) );","\tvec4 colorR = lin( texture2D( mapRight, uv ) );","\tvec3 color = clamp(","\t\t\tcolorMatrixLeft * colorL.rgb +","\t\t\tcolorMatrixRight * colorR.rgb, 0., 1. );","\tgl_FragColor = vec4(","\t\t\tdev( color.r ), dev( color.g ), dev( color.b ),","\t\t\tmax( colorL.a, colorR.a ) );","}"].join("\n")}),m=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,2),v);i.add(m),this.setSize=function(e,r){t.setSize(e,r);var o=t.getPixelRatio();c.setSize(e*o,r*o),l.setSize(e*o,r*o)},this.render=function(e,r){e.updateMatrixWorld(),null===r.parent&&r.updateMatrixWorld(),a.update(r),t.render(e,a.cameraL,c,!0),t.render(e,a.cameraR,l,!0),t.render(i,o)},this.dispose=function(){c&&c.dispose(),l&&l.dispose()}};
function VRGamepads(e){function t(e){THREE.Object3D.call(this),this.matrixAutoUpdate=!1,this.isVRPad=!1;var t=[],i=[],s={move:-1,click:-1,reset:-1};this.getGamepad=function(){return e},this.getButtonState=function(e){return!1},this.drag=function(){var e=this.getPointer(),t=this.progressObject,i=r.drag(e.position,e.direction);if(i){if(this.pointerRescale){var s=e.position.distanceTo(i.point),a=o?.1:1;this.pointerObject.scale.set(a,s,a)}if(this.pointerObject.material.color.setRGB(0,1,0),t){var n=i.object.id;if(this.pointedId==n){var c=Date.now(),h=1-(c-this.pointedTime)/2e3;h<0?(r.click(e.position,e.direction),this.pointedId=null):t.scale.set(h,h,h)}else this.pointedId=n,t.scale.set(1,1,1),this.pointedTime=Date.now(),t.visible=!0}}else{if(this.pointerObject.material.color.setRGB(1,.75,0),this.pointerRescale){var a=o?.1:1;this.pointerObject.scale.set(a,100,a)}t&&this.pointedId&&(t.visible=!1,this.pointedId=null)}},this.update=function(){var o=this;if(this.crosshairNeedsUpdate){var a=this.getPointer();this.pointerObject.position.copy(a.position),this.pointerObject.position.add(a.direction)}if(this.progressNeedsUpdate){var a=this.getPointer();this.progressObject.position.copy(a.position),this.progressObject.position.add(a.direction)}var n=e.pose;if(n&&(n.position&&this.position.fromArray(n.position),n.orientation&&this.quaternion.fromArray(n.orientation),this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0),e.buttons){var c=!1;e.buttons.forEach(function(e,t){t===s.click&&e.pressed&&o.drag(),e.pressed!==i[t]&&(i[t]=e.pressed,void 0!==i[t]&&(c=!0,t===s.move&&o.moveButtonChanged(e.pressed),t===s.click&&o.clickButtonChanged(e.pressed),t===s.reset&&o.resetButtonChanged(e.pressed)))})}if(e.axes){var h=!1;if(e.axes.forEach(function(e,i){e!==t[i]&&(t[i]=e,h=!0)}),s.move>=0&&i[s.move]){var l=window.performance.now(),p=this.lastThumbpadTimestamp,d=l-p,v=(new THREE.Matrix4).extractRotation(this.matrixWorld),u=new THREE.Vector3(t[0],0,-t[1]).applyMatrix4(v);u.multiplyScalar(r.speed*d/1e3),r.move(u),this.lastThumbpadTimestamp=l}if(s.move<0){var l=window.performance.now();if(new THREE.Vector3(t[0],0,t[1]).length()>r.movementMin){var p=this.lastThumbpadTimestamp,d=l-p,u=r.camera.getWorldDirection(),f=new THREE.Vector3(u.x,0,u.z);f.normalize(),f.applyAxisAngle(new THREE.Vector3(0,1,0),-Math.PI/2);var m=new THREE.Vector3(f.x,0,f.z);m.normalize();var E=(new THREE.Vector3).copy(u);E.applyAxisAngle(m,Math.PI/2);var g=Math.atan2(-t[0],-t[1]);u.applyAxisAngle(E,g),u.multiplyScalar(r.speed*d/1e3),r.move(u)}this.lastThumbpadTimestamp=l}}this.alwaysDrag&&this.drag()},this.getPointer=function(){var t=this.getWorldPosition();if(e.pose&&e.pose.hasOrientation){var i=this.pointerObject,o=new THREE.Vector3(0,0,0);o.applyMatrix4(i.matrixWorld);var s=new THREE.Vector3(0,-1,0);return s.applyMatrix4(i.matrixWorld),s.sub(o),s.normalize(),{position:t,direction:s}}var t=r.camera.getWorldPosition(),s=r.camera.getWorldDirection();return t.add(s),{position:t,direction:s}},this.moveButtonChanged=function(e){e&&(this.lastThumbpadTimestamp=window.performance.now())},this.clickButtonChanged=function(e){if(e)this.pointerObject.visible=!0;else{this.pointerObject.visible=!1;var t=this.getPointer();r.click(t.position,t.direction)}},this.resetButtonChanged=function(e){},this.destroyGamepad=function(){this.parent&&this.parent.remove(this),this.pointerObject&&this.pointerObject.parent&&this.pointerObject.parent.remove(this.pointerObject),this.progressObject&&this.progressObject.parent&&this.progressObject.parent.remove(this.progressObject)};var a={};this.createCrosshair=function(){var e=a.crosshair;if(void 0===e){var t=new THREE.SphereGeometry(.02),i=new THREE.MeshBasicMaterial({color:16711680});e=new THREE.Mesh(t,i),a.crosshair=e}e=e.clone(),this.crosshairNeedsUpdate=!0,this.pointerObject=e,r.scene.add(e),this.pointerRescale=!1},this.createProgress=function(){var e=a.progress;if(void 0===e){var t=new THREE.SphereGeometry(.2,16,12),i=new THREE.MeshBasicMaterial({color:16711680,opacity:.5,transparent:!0});e=new THREE.Mesh(t,i),e.visible=!1,a.progress=e}e=e.clone(),this.progressNeedsUpdate=!0,this.progressObject=e,r.scene.add(e)},this.createViveControllerMesh=function(){function e(e){t.add(e)}var t=this,i=a["vive-controller-ray"];if(void 0===i){var o=new THREE.CylinderGeometry(.008,.008,1,8);o.translate(0,-.5,0);var s=new THREE.MeshBasicMaterial({color:8454016});i=new THREE.Mesh(o,s),i.scale.set(1,100,1),i.rotateX(Math.PI/6),i.visible=!1,a["vive-controller-ray"]=i}this.pointerObject=i.clone(),this.add(this.pointerObject),this.pointerRescale=!0;var n=a["vive-controller"];if(void 0===n){a["vive-controller"]=[e];(new THREE.JSONLoader).load(r.resBase+"vive-controller/vr_controller_vive_1_5.js",function(e){var t=new THREE.TextureLoader;t.setPath(r.resBase+"vive-controller/");var i=new THREE.MeshBasicMaterial({color:16777215});i.map=t.load("onepointfive_texture.png"),i.specularMap=t.load("onepointfive_spec.png");var o=new THREE.Mesh(e,i),s=new THREE.Object3D;s.add(o),a["vive-controller"].forEach(function(e){e(s.clone())}),a["vive-controller"]=s})}else Array.isArray(n)?a["vive-controller"].push(e):e(n.clone());r.camera.parent.add(this)},this.createOculusTouchMesh=function(){function e(e){t.add(e)}var t=this,i=a["touch-controller-ray"];if(void 0===i){var o=new THREE.CylinderGeometry(.008,.008,1,8);o.translate(0,-.5,0);var s=new THREE.MeshBasicMaterial({color:8454016});i=new THREE.Mesh(o,s),i.scale.set(1,100,1),i.rotateX(Math.PI/6),i.visible=!1,a["touch-controller-ray"]=i}this.pointerObject=i.clone(),this.add(this.pointerObject),this.pointerRescale=!0;var n="touch-controller-"+this.whichHand,c=a[n];if(void 0===c){a[n]=[e];var h=new THREE.MTLLoader;h.setPath(r.resBase+"touch-controller/"),h.load("oculus-touch-controller-"+this.whichHand+".mtl",function(e){e.preload();var i=new THREE.OBJLoader;i.setMaterials(e),i.setPath(r.resBase+"touch-controller/"),i.load("oculus-touch-controller-"+t.whichHand+".obj",function(e){var t=new THREE.Object3D;e.position.add(new THREE.Vector3(.008,.03,-.03)),t.add(e),a[n].forEach(function(e){e(t.clone())}),a[n]=t})})}else Array.isArray(c)?a[n].push(e):e(c.clone());r.camera.parent.add(this)},this.getAxes=function(){return t},/left/i.test(e.id)&&(this.whichHand="left"),/right/i.test(e.id)&&(this.whichHand="right"),/openvr/i.test(e.id)?(this.createViveControllerMesh(),s={move:0,click:1,reset:3},this.isVRPad=!0):/touch/i.test(e.id)?(this.createOculusTouchMesh(),s={move:-1,click:1,reset:3},this.isVRPad=!0):"simulated"==e.id?(this.createCrosshair(),this.createProgress(),this.alwaysDrag=!0):e.id==/gear vr/i.test(e.id)?(this.createCrosshair(),s={move:-1,click:1,reset:1}):(this.createCrosshair(),s={move:-1,click:7,reset:1})}function i(){var e=[];if("function"==typeof navigator.getGamepads)for(var i=navigator.getGamepads(),r=0;r<i.length;r++){var a=i[r];if(a){for(var n=!0,c=0;c<s.length;c++){var h=s[c];if(a===h.getGamepad()){e.push(h),s.splice(c,1),n=!1;break}}n&&e.push(new t(a))}}if(0==e.length){for(var l=!0,c=0;c<s.length;c++){var h=s[c];"simulated"==h.getGamepad().id&&(e.push(h),s.splice(c,1),l=!1)}l&&e.push(new t({id:"simulated"}))}s.forEach(function(e){e.destroyGamepad()}),s=e,o=null;for(var p=null,r=0;r<s.length;r++){var a=s[r];if(a.isVRPad){if(p){o=a;break}p=a}}if(o){if("right"==o.whichHand&&"left"==p.whichHand){var d=o;o=p,p=d}p.pointerObject.scale.setX(.1),p.pointerObject.scale.setZ(.1)}else p&&(p.pointerObject.scale.setX(1),p.pointerObject.scale.setZ(1))}var r=Object.assign({drag:functi