jocly/dist/browser/jocly-xdview.js
2017-05-24 00:21:29 +02:00

20 lines
132 KiB
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){(n=u.indexOf(t))!==-1&&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)&&p.enabled!==!1){if(t.preventDefault(),t.stopPropagation(),0===t.button){if(p.noRotate===!0)return;V=k.ROTATE,g.set(t.clientX,t.clientY)}else if(1===t.button){if(p.noZoom===!0)return;V=k.DOLLY,O.set(t.clientX,t.clientY)}else if(2===t.button){if(p.noPan===!0)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(p.enabled!==!1){t.preventDefault(),t.stopPropagation();var e=p.domElement===document?p.domElement.body:p.domElement;if(V===k.ROTATE){if(p.noRotate===!0)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(p.noZoom===!0)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(p.noPan===!0)return;y.set(t.clientX,t.clientY),v.subVectors(y,b),p.pan(v),b.copy(y)}E()}}function r(){p.enabled!==!1&&(p.domElement.removeEventListener("mousemove",s,!1),p.domElement.removeEventListener("mouseup",r,!1),V=k.NONE)}function c(t){if(t.stopPropagation(),t.preventDefault(),p.enabled!==!1&&p.noZoom!==!0){var e=0;t.wheelDelta?e=t.wheelDelta:t.detail&&(e=-t.detail),e>0?p.dollyOut():p.dollyIn(),E()}}function h(t){p.enabled!==!1&&(this.mouseIsDown=!1,V=k.NONE)}function d(t){if(p.enabled!==!1&&p.noKeys!==!0&&p.noPan!==!0){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)&&p.enabled!==!1){switch(t.touches.length){case 1:if(p.noRotate===!0)return;V=k.TOUCH_ROTATE,g.set(t.touches[0].pageX,t.touches[0].pageY);break;case 2:if(p.noZoom===!0)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(p.noPan===!0)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(p.enabled!==!1){t.preventDefault(),t.stopPropagation();var e=p.domElement===document?p.domElement.body:p.domElement;switch(t.touches.length){case 1:if(p.noRotate===!0)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(p.noZoom===!0)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(p.noPan===!0)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(){p.enabled!==!1&&(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(n.enabled!==!1){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 e.visible===!0||r.visible===!0||t.visible===!0||(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(l(i,o,a)!==!1&&(x.side===THREE.DoubleSide||p(i,o,a)===!0)){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,c.autoUpdate===!0&&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(e.material.visible===!1)return;if(e.frustumCulled===!0&&F.intersectsObject(e)===!1)return;H(e)}else if(e instanceof THREE.Sprite){if(e.material.visible===!1)return;if(e.frustumCulled===!0&&F.intersectsSprite(e)===!1)return;H(e)}}),x===!0&&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),Z.morphTargets===!0)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(G.checkTriangleVisibility(he,fe,ve)!==!1){var me=G.checkBackfaceCulling(he,fe,ve);if(de!==THREE.DoubleSide){if(de===THREE.FrontSide&&me===!1)continue;if(de===THREE.BackSide&&me===!0)continue}E=t(),E.id=b.id,E.v1.copy(he),E.v2.copy(fe),E.v3.copy(ve),E.normalModel.copy(ue.normal),me!==!1||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]),me!==!1||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),a(P,A)===!0&&(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 T===!0&&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(THREEx.DomEvent.eventNames.indexOf(e)!==-1,"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(THREEx.DomEvent.eventNames.indexOf(e)!==-1,"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=2*+((t-n.left)/o.width())-1,i=2*-((e-n.top)/o.height())+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=2*+((o-i.left)/s.width())-1,r=2*-((n-i.top)/s.height())+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&&(r.useCapture===!1&&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=2*+((e.clientX-n.left)/o.width())-1,i=2*-((e.clientY-n.top)/o.height())+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=2*+((e.touches[0].clientX-n.left)/o.width())-1,i=2*-((e.touches[0].clientY-n.top)/o.height())+1,u=e.touches[0].clientX-n.left,r=e.touches[0].clientY-n.top):e.changedTouches&&e.changedTouches.length>0&&(s=2*+((e.changedTouches[0].clientX-n.left)/o.width())-1,i=2*-((e.changedTouches[0].clientY-n.top)/o.height())+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:function(e,t){return!1},click:function(e,t){},reset:function(){},speed:10,move:function(e){},visionCrosshairAngle:-Math.PI/8,movementMin:.2},e),o=null;t.prototype=Object.create(THREE.Object3D.prototype),t.prototype.constructor=t;var s=[];this.getHarborPad=function(){return o},this.update=function(){i(),s.forEach(function(e){e.update()})},this.clearAll=function(){s.forEach(function(e){e.destroyGamepad()}),s=[]}}
THREE.VRControls=function(t,s){function n(t){i=t,t.length>0?e=t[0]:s&&s("VR input not available.")}var e,i,o=this,a=new THREE.Matrix4,r=null;"VRFrameData"in window&&(r=new VRFrameData),navigator.getVRDisplays&&navigator.getVRDisplays().then(n).catch(function(){console.warn("THREE.VRControls: Unable to get VR Displays")}),this.scale=1,this.standing=!1,this.userHeight=1.6,this.getVRDisplay=function(){return e},this.setVRDisplay=function(t){e=t},this.getVRDisplays=function(){return console.warn("THREE.VRControls: getVRDisplays() is being deprecated."),i},this.getStandingMatrix=function(){return a},this.update=function(){if(e){var s;e.getFrameData?(e.getFrameData(r),s=r.pose):e.getPose&&(s=e.getPose()),null!==s.orientation&&t.quaternion.fromArray(s.orientation),null!==s.position?t.position.fromArray(s.position):t.position.set(0,0,0),this.standing&&(e.stageParameters?(t.updateMatrix(),a.fromArray(e.stageParameters.sittingToStandingTransform),t.applyMatrix(a)):t.position.setY(t.position.y+this.userHeight)),t.position.multiplyScalar(o.scale)}},this.resetPose=function(){e&&e.resetPose()},this.resetSensor=function(){console.warn("THREE.VRControls: .resetSensor() is now .resetPose()."),this.resetPose()},this.zeroSensor=function(){console.warn("THREE.VRControls: .zeroSensor() is now .resetPose()."),this.resetPose()},this.dispose=function(){e=null}};
THREE.VREffect=function(e,t){function i(e){h=e,e.length>0?o=e[0]:t&&t("HMD not available")}function r(){var t=f.isPresenting;if(f.isPresenting=void 0!==o&&o.isPresenting,f.isPresenting){var i=o.getEyeParameters("left"),r=i.renderWidth,n=i.renderHeight;t||(p=e.getPixelRatio(),w=e.getSize(),e.setPixelRatio(1),e.setSize(2*r,n,!1))}else t&&(e.setPixelRatio(p),e.setSize(w.width,w.height,m))}function n(e){var t=2/(e.leftTan+e.rightTan),i=(e.leftTan-e.rightTan)*t*.5,r=2/(e.upTan+e.downTan);return{scale:[t,r],offset:[i,(e.upTan-e.downTan)*r*.5]}}function a(e,t,i,r){t=void 0===t||t,i=void 0===i?.01:i,r=void 0===r?1e4:r;var a=t?-1:1,s=new THREE.Matrix4,o=s.elements,h=n(e);return o[0]=h.scale[0],o[1]=0,o[2]=h.offset[0]*a,o[3]=0,o[4]=0,o[5]=h.scale[1],o[6]=-h.offset[1]*a,o[7]=0,o[8]=0,o[9]=0,o[10]=r/(i-r)*-a,o[11]=r*i/(i-r),o[12]=0,o[13]=0,o[14]=a,o[15]=0,s.transpose(),s}function s(e,t,i,r){var n=Math.PI/180;return a({upTan:Math.tan(e.upDegrees*n),downTan:Math.tan(e.downDegrees*n),leftTan:Math.tan(e.leftDegrees*n),rightTan:Math.tan(e.rightDegrees*n)},t,i,r)}var o,h,d,l,u=new THREE.Vector3,g=new THREE.Vector3,c=null;"VRFrameData"in window&&(c=new window.VRFrameData),navigator.getVRDisplays&&navigator.getVRDisplays().then(i).catch(function(){console.warn("THREE.VREffect: Unable to get VR Displays")}),this.isPresenting=!1,this.scale=1;var f=this,w=e.getSize(),m=!1,p=e.getPixelRatio();this.getVRDisplay=function(){return o},this.setVRDisplay=function(e){o=e},this.getVRDisplays=function(){return console.warn("THREE.VREffect: getVRDisplays() is being deprecated."),h},this.setSize=function(t,i,r){if(w={width:t,height:i},m=r,f.isPresenting){var n=o.getEyeParameters("left");e.setPixelRatio(1),e.setSize(2*n.renderWidth,n.renderHeight,!1)}else e.setPixelRatio(p),e.setSize(t,i,r)};var v=e.domElement,y=[0,0,.5,1],R=[.5,0,.5,1];window.addEventListener("vrdisplaypresentchange",r,!1),this.setFullScreen=function(e){return new Promise(function(t,i){return void 0===o?void i(new Error("No VR hardware found.")):f.isPresenting===e?void t():void t(e?o.requestPresent([{source:v}]):o.exitPresent())})},this.requestPresent=function(){return this.setFullScreen(!0)},this.exitPresent=function(){return this.setFullScreen(!1)},this.requestAnimationFrame=function(e){return void 0!==o?o.requestAnimationFrame(e):window.requestAnimationFrame(e)},this.cancelAnimationFrame=function(e){void 0!==o?o.cancelAnimationFrame(e):window.cancelAnimationFrame(e)},this.submitFrame=function(){void 0!==o&&f.isPresenting&&o.submitFrame()},this.autoSubmitFrame=!0;var x=new THREE.PerspectiveCamera;x.layers.enable(1);var E=new THREE.PerspectiveCamera;E.layers.enable(2),this.render=function(t,i,r,n){if(o&&f.isPresenting){var a=t.autoUpdate;a&&(t.updateMatrixWorld(),t.autoUpdate=!1);var h=o.getEyeParameters("left"),w=o.getEyeParameters("right");u.fromArray(h.offset),g.fromArray(w.offset),Array.isArray(t)&&(console.warn("THREE.VREffect.render() no longer supports arrays. Use object.layers instead."),t=t[0]);var m,p,v=e.getSize(),P=o.getLayers();if(P.length){var T=P[0];m=null!==T.leftBounds&&4===T.leftBounds.length?T.leftBounds:y,p=null!==T.rightBounds&&4===T.rightBounds.length?T.rightBounds:R}else m=y,p=R;d={x:Math.round(v.width*m[0]),y:Math.round(v.height*m[1]),width:Math.round(v.width*m[2]),height:Math.round(v.height*m[3])},l={x:Math.round(v.width*p[0]),y:Math.round(v.height*p[1]),width:Math.round(v.width*p[2]),height:Math.round(v.height*p[3])},r?(e.setRenderTarget(r),r.scissorTest=!0):(e.setRenderTarget(null),e.setScissorTest(!0)),(e.autoClear||n)&&e.clear(),null===i.parent&&i.updateMatrixWorld(),i.matrixWorld.decompose(x.position,x.quaternion,x.scale),i.matrixWorld.decompose(E.position,E.quaternion,E.scale);var M=this.scale;return x.translateOnAxis(u,M),E.translateOnAxis(g,M),o.getFrameData?(o.depthNear=i.near,o.depthFar=i.far,o.getFrameData(c),x.projectionMatrix.elements=c.leftProjectionMatrix,E.projectionMatrix.elements=c.rightProjectionMatrix):(x.projectionMatrix=s(h.fieldOfView,!0,i.near,i.far),E.projectionMatrix=s(w.fieldOfView,!0,i.near,i.far)),r?(r.viewport.set(d.x,d.y,d.width,d.height),r.scissor.set(d.x,d.y,d.width,d.height)):(e.setViewport(d.x,d.y,d.width,d.height),e.setScissor(d.x,d.y,d.width,d.height)),e.render(t,x,r,n),r?(r.viewport.set(l.x,l.y,l.width,l.height),r.scissor.set(l.x,l.y,l.width,l.height)):(e.setViewport(l.x,l.y,l.width,l.height),e.setScissor(l.x,l.y,l.width,l.height)),e.render(t,E,r,n),r?(r.viewport.set(0,0,v.width,v.height),r.scissor.set(0,0,v.width,v.height),r.scissorTest=!1,e.setRenderTarget(null)):(e.setViewport(0,0,v.width,v.height),e.setScissorTest(!1)),a&&(t.autoUpdate=!0),void(f.autoSubmitFrame&&f.submitFrame())}e.render(t,i,r,n)},this.dispose=function(){window.removeEventListener("vrdisplaypresentchange",r,!1)}};
THREE.OBJLoader=function(e){this.manager=void 0!==e?e:THREE.DefaultLoadingManager,this.materials=null,this.regexp={vertex_pattern:/^v\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,normal_pattern:/^vn\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,uv_pattern:/^vt\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,face_vertex:/^f\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)(?:\s+(-?\d+))?/,face_vertex_uv:/^f\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+))?/,face_vertex_uv_normal:/^f\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+)\/(-?\d+))?/,face_vertex_normal:/^f\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)(?:\s+(-?\d+)\/\/(-?\d+))?/,object_pattern:/^[og]\s*(.+)?/,smoothing_pattern:/^s\s+(\d+|on|off)/,material_library_pattern:/^mtllib /,material_use_pattern:/^usemtl /}},THREE.OBJLoader.prototype={constructor:THREE.OBJLoader,load:function(e,t,r,s){var a=this,i=new THREE.FileLoader(a.manager);i.setPath(this.path),i.load(e,function(e){t(a.parse(e))},r,s)},setPath:function(e){this.path=e},setMaterials:function(e){this.materials=e},_createParserState:function(){var e={objects:[],object:{},vertices:[],normals:[],uvs:[],materialLibraries:[],startObject:function(e,t){if(this.object&&this.object.fromDeclaration===!1)return this.object.name=e,void(this.object.fromDeclaration=t!==!1);var r=this.object&&"function"==typeof this.object.currentMaterial?this.object.currentMaterial():void 0;if(this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:t!==!1,geometry:{vertices:[],normals:[],uvs:[]},materials:[],smooth:!0,startMaterial:function(e,t){var r=this._finalize(!1);r&&(r.inherited||r.groupCount<=0)&&this.materials.splice(r.index,1);var s={index:this.materials.length,name:e||"",mtllib:Array.isArray(t)&&t.length>0?t[t.length-1]:"",smooth:void 0!==r?r.smooth:this.smooth,groupStart:void 0!==r?r.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(e){var t={index:"number"==typeof e?e:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return t.clone=this.clone.bind(t),t}};return this.materials.push(s),s},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(e){var t=this.currentMaterial();if(t&&t.groupEnd===-1&&(t.groupEnd=this.geometry.vertices.length/3,t.groupCount=t.groupEnd-t.groupStart,t.inherited=!1),e&&this.materials.length>1)for(var r=this.materials.length-1;r>=0;r--)this.materials[r].groupCount<=0&&this.materials.splice(r,1);return e&&0===this.materials.length&&this.materials.push({name:"",smooth:this.smooth}),t}},r&&r.name&&"function"==typeof r.clone){var s=r.clone(0);s.inherited=!0,this.object.materials.push(s)}this.objects.push(this.object)},finalize:function(){this.object&&"function"==typeof this.object._finalize&&this.object._finalize(!0)},parseVertexIndex:function(e,t){var r=parseInt(e,10);return 3*(r>=0?r-1:r+t/3)},parseNormalIndex:function(e,t){var r=parseInt(e,10);return 3*(r>=0?r-1:r+t/3)},parseUVIndex:function(e,t){var r=parseInt(e,10);return 2*(r>=0?r-1:r+t/2)},addVertex:function(e,t,r){var s=this.vertices,a=this.object.geometry.vertices;a.push(s[e+0]),a.push(s[e+1]),a.push(s[e+2]),a.push(s[t+0]),a.push(s[t+1]),a.push(s[t+2]),a.push(s[r+0]),a.push(s[r+1]),a.push(s[r+2])},addVertexLine:function(e){var t=this.vertices,r=this.object.geometry.vertices;r.push(t[e+0]),r.push(t[e+1]),r.push(t[e+2])},addNormal:function(e,t,r){var s=this.normals,a=this.object.geometry.normals;a.push(s[e+0]),a.push(s[e+1]),a.push(s[e+2]),a.push(s[t+0]),a.push(s[t+1]),a.push(s[t+2]),a.push(s[r+0]),a.push(s[r+1]),a.push(s[r+2])},addUV:function(e,t,r){var s=this.uvs,a=this.object.geometry.uvs;a.push(s[e+0]),a.push(s[e+1]),a.push(s[t+0]),a.push(s[t+1]),a.push(s[r+0]),a.push(s[r+1])},addUVLine:function(e){var t=this.uvs,r=this.object.geometry.uvs;r.push(t[e+0]),r.push(t[e+1])},addFace:function(e,t,r,s,a,i,n,o,h,l,d,u){var p,c=this.vertices.length,m=this.parseVertexIndex(e,c),f=this.parseVertexIndex(t,c),v=this.parseVertexIndex(r,c);if(void 0===s?this.addVertex(m,f,v):(p=this.parseVertexIndex(s,c),this.addVertex(m,f,p),this.addVertex(f,v,p)),void 0!==a){var g=this.uvs.length;m=this.parseUVIndex(a,g),f=this.parseUVIndex(i,g),v=this.parseUVIndex(n,g),void 0===s?this.addUV(m,f,v):(p=this.parseUVIndex(o,g),this.addUV(m,f,p),this.addUV(f,v,p))}if(void 0!==h){var x=this.normals.length;m=this.parseNormalIndex(h,x),f=h===l?m:this.parseNormalIndex(l,x),v=h===d?m:this.parseNormalIndex(d,x),void 0===s?this.addNormal(m,f,v):(p=this.parseNormalIndex(u,x),this.addNormal(m,f,p),this.addNormal(f,v,p))}},addLineGeometry:function(e,t){this.object.geometry.type="Line";for(var r=this.vertices.length,s=this.uvs.length,a=0,i=e.length;a<i;a++)this.addVertexLine(this.parseVertexIndex(e[a],r));for(var n=0,i=t.length;n<i;n++)this.addUVLine(this.parseUVIndex(t[n],s))}};return e.startObject("",!1),e},parse:function(e){console.time("OBJLoader");var t=this._createParserState();e.indexOf("\r\n")!==-1&&(e=e.replace(/\r\n/g,"\n")),e.indexOf("\\\n")!==-1&&(e=e.replace(/\\\n/g,""));for(var r=e.split("\n"),s="",a="",i="",n=[],o="function"==typeof"".trimLeft,h=0,l=r.length;h<l;h++)if(s=r[h],s=o?s.trimLeft():s.trim(),0!==s.length&&"#"!==(a=s.charAt(0)))if("v"===a)if(" "===(i=s.charAt(1))&&null!==(n=this.regexp.vertex_pattern.exec(s)))t.vertices.push(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3]));else if("n"===i&&null!==(n=this.regexp.normal_pattern.exec(s)))t.normals.push(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3]));else{if("t"!==i||null===(n=this.regexp.uv_pattern.exec(s)))throw new Error("Unexpected vertex/normal/uv line: '"+s+"'");t.uvs.push(parseFloat(n[1]),parseFloat(n[2]))}else if("f"===a)if(null!==(n=this.regexp.face_vertex_uv_normal.exec(s)))t.addFace(n[1],n[4],n[7],n[10],n[2],n[5],n[8],n[11],n[3],n[6],n[9],n[12]);else if(null!==(n=this.regexp.face_vertex_uv.exec(s)))t.addFace(n[1],n[3],n[5],n[7],n[2],n[4],n[6],n[8]);else if(null!==(n=this.regexp.face_vertex_normal.exec(s)))t.addFace(n[1],n[3],n[5],n[7],void 0,void 0,void 0,void 0,n[2],n[4],n[6],n[8]);else{if(null===(n=this.regexp.face_vertex.exec(s)))throw new Error("Unexpected face line: '"+s+"'");t.addFace(n[1],n[2],n[3],n[4])}else if("l"===a){var d=s.substring(1).trim().split(" "),u=[],p=[];if(s.indexOf("/")===-1)u=d;else for(var c=0,m=d.length;c<m;c++){var f=d[c].split("/");""!==f[0]&&u.push(f[0]),""!==f[1]&&p.push(f[1])}t.addLineGeometry(u,p)}else if(null!==(n=this.regexp.object_pattern.exec(s))){var v=(" "+n[0].substr(1).trim()).substr(1);t.startObject(v)}else if(this.regexp.material_use_pattern.test(s))t.object.startMaterial(s.substring(7).trim(),t.materialLibraries);else if(this.regexp.material_library_pattern.test(s))t.materialLibraries.push(s.substring(7).trim());else{if(null===(n=this.regexp.smoothing_pattern.exec(s))){if("\0"===s)continue;throw new Error("Unexpected line: '"+s+"'")}var g=n[1].trim().toLowerCase();t.object.smooth="1"===g||"on"===g;var x=t.object.currentMaterial();x&&(x.smooth=t.object.smooth)}t.finalize();var b=new THREE.Group;b.materialLibraries=[].concat(t.materialLibraries);for(var h=0,l=t.objects.length;h<l;h++){var E=t.objects[h],_=E.geometry,j=E.materials,y="Line"===_.type;if(0!==_.vertices.length){var L=new THREE.BufferGeometry;L.addAttribute("position",new THREE.BufferAttribute(new Float32Array(_.vertices),3)),_.normals.length>0?L.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(_.normals),3)):L.computeVertexNormals(),_.uvs.length>0&&L.addAttribute("uv",new THREE.BufferAttribute(new Float32Array(_.uvs),2));for(var V=[],w=0,H=j.length;w<H;w++){var I=j[w],x=void 0;if(null!==this.materials&&(x=this.materials.create(I.name),y&&x&&!(x instanceof THREE.LineBasicMaterial))){var R=new THREE.LineBasicMaterial;R.copy(x),x=R}x||(x=y?new THREE.LineBasicMaterial:new THREE.MeshPhongMaterial,x.name=I.name),x.shading=I.smooth?THREE.SmoothShading:THREE.FlatShading,V.push(x)}var T;if(V.length>1){for(var w=0,H=j.length;w<H;w++){var I=j[w];L.addGroup(I.groupStart,I.groupCount,w)}T=y?new THREE.LineSegments(L,V):new THREE.Mesh(L,V)}else T=y?new THREE.LineSegments(L,V[0]):new THREE.Mesh(L,V[0]);T.name=E.name,b.add(T)}}return console.timeEnd("OBJLoader"),b}};
THREE.MTLLoader=function(t){this.manager=void 0!==t?t:THREE.DefaultLoadingManager},THREE.MTLLoader.prototype={constructor:THREE.MTLLoader,load:function(t,a,e,r){var s=this,i=new THREE.FileLoader(this.manager);i.setPath(this.path),i.load(t,function(t){a(s.parse(t))},e,r)},setPath:function(t){this.path=t},setTexturePath:function(t){this.texturePath=t},setBaseUrl:function(t){console.warn("THREE.MTLLoader: .setBaseUrl() is deprecated. Use .setTexturePath( path ) for texture path or .setPath( path ) for general base path instead."),this.setTexturePath(t)},setCrossOrigin:function(t){this.crossOrigin=t},setMaterialOptions:function(t){this.materialOptions=t},parse:function(t){for(var a=t.split("\n"),e={},r={},s=0;s<a.length;s++){var i=a[s];if(i=i.trim(),0!==i.length&&"#"!==i.charAt(0)){var o=i.indexOf(" "),n=o>=0?i.substring(0,o):i;n=n.toLowerCase();var h=o>=0?i.substring(o+1):"";if(h=h.trim(),"newmtl"===n)e={name:h},r[h]=e;else if(e)if("ka"===n||"kd"===n||"ks"===n){var p=h.split(/\s+/,3);e[n]=[parseFloat(p[0]),parseFloat(p[1]),parseFloat(p[2])]}else e[n]=h}}var l=new THREE.MTLLoader.MaterialCreator(this.texturePath||this.path,this.materialOptions);return l.setCrossOrigin(this.crossOrigin),l.setManager(this.manager),l.setMaterials(r),l}},THREE.MTLLoader.MaterialCreator=function(t,a){this.baseUrl=t||"",this.options=a,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.side=this.options&&this.options.side?this.options.side:THREE.FrontSide,this.wrap=this.options&&this.options.wrap?this.options.wrap:THREE.RepeatWrapping},THREE.MTLLoader.MaterialCreator.prototype={constructor:THREE.MTLLoader.MaterialCreator,setCrossOrigin:function(t){this.crossOrigin=t},setManager:function(t){this.manager=t},setMaterials:function(t){this.materialsInfo=this.convert(t),this.materials={},this.materialsArray=[],this.nameLookup={}},convert:function(t){if(!this.options)return t;var a={};for(var e in t){var r=t[e],s={};a[e]=s;for(var i in r){var o=!0,n=r[i],h=i.toLowerCase();switch(h){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(n=[n[0]/255,n[1]/255,n[2]/255]),this.options&&this.options.ignoreZeroRGBs&&0===n[0]&&0===n[1]&&0===n[2]&&(o=!1)}o&&(s[h]=n)}}return a},preload:function(){for(var t in this.materialsInfo)this.create(t)},getIndex:function(t){return this.nameLookup[t]},getAsArray:function(){var t=0;for(var a in this.materialsInfo)this.materialsArray[t]=this.create(a),this.nameLookup[a]=t,t++;return this.materialsArray},create:function(t){return void 0===this.materials[t]&&this.createMaterial_(t),this.materials[t]},createMaterial_:function(t){function a(t,a){return"string"!=typeof a||""===a?"":/^https?:\/\//i.test(a)?a:t+a}function e(t,e){if(!i[t]){var s=r.getTextureParams(e,i),o=r.loadTexture(a(r.baseUrl,s.url));o.repeat.copy(s.scale),o.offset.copy(s.offset),o.wrapS=r.wrap,o.wrapT=r.wrap,i[t]=o}}var r=this,s=this.materialsInfo[t],i={name:t,side:this.side};for(var o in s){var n=s[o];if(""!==n)switch(o.toLowerCase()){case"kd":i.color=(new THREE.Color).fromArray(n);break;case"ks":i.specular=(new THREE.Color).fromArray(n);break;case"map_kd":e("map",n);break;case"map_ks":e("specularMap",n);break;case"map_bump":case"bump":e("bumpMap",n);break;case"ns":i.shininess=parseFloat(n);break;case"d":n<1&&(i.opacity=n,i.transparent=!0);break;case"Tr":n>0&&(i.opacity=1-n,i.transparent=!0)}}return this.materials[t]=new THREE.MeshPhongMaterial(i),this.materials[t]},getTextureParams:function(t,a){var e,r={scale:new THREE.Vector2(1,1),offset:new THREE.Vector2(0,0)},s=t.split(/\s+/);return e=s.indexOf("-bm"),e>=0&&(a.bumpScale=parseFloat(s[e+1]),s.splice(e,2)),e=s.indexOf("-s"),e>=0&&(r.scale.set(parseFloat(s[e+1]),parseFloat(s[e+2])),s.splice(e,4)),e=s.indexOf("-o"),e>=0&&(r.offset.set(parseFloat(s[e+1]),parseFloat(s[e+2])),s.splice(e,4)),r.url=s.join(" ").trim(),r},loadTexture:function(t,a,e,r,s){var i,o=THREE.Loader.Handlers.get(t),n=void 0!==this.manager?this.manager:THREE.DefaultLoadingManager;return null===o&&(o=new THREE.TextureLoader(n)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin),i=o.load(t,e,r,s),void 0!==a&&(i.mapping=a),i}};
function KalmanFilter(t){this.R=void 0===t.R?1:t.R,this.Q=void 0===t.Q?1:t.Q,this.A=void 0===t.A?1:t.A,this.C=void 0===t.C?1:t.C,this.B=void 0===t.B?0:t.B,this.cov=NaN,this.x=NaN}KalmanFilter.prototype.filter=function(t,i){if(void 0===i&&(i=0),isNaN(this.x))this.x=1/this.C*t,this.cov=1/this.C*this.Q*(1/this.C);else{const s=this.A*this.x+this.B*i,h=this.A*this.cov*this.A+this.R,o=h*this.C*(1/(this.C*h*this.C+this.Q));this.x=s+o*(t-this.C*s),this.cov=h-o*this.C*h}return this.x},KalmanFilter.prototype.lastMeasurement=function(){return this.x},KalmanFilter.prototype.setMeasurementNoise=function(t){this.Q=t},KalmanFilter.prototype.setProcessNoise=function(t){this.R=t};
JoclyAR=function(e){function t(){if(i)if(u||l.readyState!==l.HAVE_ENOUGH_DATA)requestAnimationFrame(t);else{u=!0,r.drawImage(l,0,0,s,c);var e=r.getImageData(0,0,s,c);h.postMessage({type:"Detect",imageData:e,vwidth:l.clientWidth,vheight:l.clientHeight})}}function n(e){var t=e.clientY,n=(t-b)/e.target.clientHeight;m=E*(1-n),d.animControl.trigger()}function o(e){switch(e.type){case"mousedown":1!=e.button&&2!=e.button||(b=e.clientY,E=m,e.target.addEventListener("mousemove",n));break;case"mouseup":case"mouseout":e.target.removeEventListener("mousemove",n)}}var a,r,i=!1,l=null,s=320,c=240,m=.2,d=null,u=!1,h=null,g=new THREE.Vector3,v=new THREE.Euler,b=null,E=m;return{start:function(){JoclyPlazza.webrtc.startLocal(!0,{video:{width:{ideal:s},height:{ideal:c},facingMode:"environment",frameRate:{ideal:24}}})},stop:function(){JoclyPlazza.webrtc.setChannel(null)},attach:function(e){l=e.element,JoclyPlazza.webrtc.attachMediaStream(e.element,e.stream),a=document.createElement("canvas"),a.setAttribute("width",s),a.setAttribute("height",c),Object.assign(a.style,{width:s,height:c,visibility:"hidden",position:"absolute","z-index":-2,top:0}),document.body.appendChild(a),r=a.getContext("2d"),d=e.threeCtx,i=!0,u=!1,d.renderer.domElement.addEventListener("mousedown",o),d.renderer.domElement.addEventListener("mouseup",o),d.renderer.domElement.addEventListener("mouseout",o),h=new Worker(JoclyPlazza.config.baseURL+JoclyPlazza.config.joclyPath+"/jocly.arworker.js"),h.onmessage=function(e){u=!1;var n=e.data;switch(n.type){case"Pose":var o=n.rotation,a=n.translation;d.body.position.set(0,0,0),d.camera.lookAt(new THREE.Vector3(0,-1,0)),d.harbor.scale.set(5*m,5*m,5*m),d.harbor.rotation.set(-Math.asin(-o[1][2]),Math.atan2(o[1][0],o[1][1]),-Math.atan2(o[0][2],o[2][2])),d.harbor.position.set(a[0],-a[2],-a[1]),d.harbor.position.equals(g)&&d.harbor.rotation.equals(v)||d.animControl.trigger(),g.copy(d.harbor.position),v.copy(d.harbor.rotation)}setTimeout(t,20)},h.postMessage({type:"Init",baseUrl:JoclyPlazza.config.baseURL+JoclyPlazza.config.joclyPath,modelSize:5,width:s,height:c}),requestAnimationFrame(t)},detach:function(e){d.renderer.domElement.removeEventListener("mousedown",o),d.renderer.domElement.removeEventListener("mouseup",o),d.renderer.domElement.removeEventListener("mouseout",o),JoclyPlazza.webrtc.detachMediaStream(e.element),l=null,i=!1,a.parentNode.removeChild(a),r=null,d=null,h.terminate(),h=null}}}();
function JHStateMachine(){}JHStateMachine.prototype={},JHStateMachine.prototype.init=function(){this.smState=null,this.smStates={},this.smEventQueue=[],this.smScheduled=!1,this.smPauseNotified=!1,this.smPaused=!0,this.smHistory=[],this.smGroups={}},JHStateMachine.prototype.smDebug=function(){},JHStateMachine.prototype.smWarning=function(){},JHStateMachine.prototype.smError=function(){},JHStateMachine.prototype.smTransition=function(t,s,e,i){t=this.smSolveStates(t),"string"==typeof s&&(s=[s]),"string"==typeof i&&(i=[i]);for(var n in t){var a=t[n];void 0===this.smStates[a]&&(this.smStates[a]={transitions:{},enteringMethods:[],leavingMethods:[]});for(var o in s){var h=s[o];void 0===this.smStates[a].transitions[h]&&(this.smStates[a].transitions[h]={state:null!=e?e:a,methods:[]});for(var r in i){var m=i[r];this.smStates[a].transitions[h].methods.push(m)}}}null!=e&&void 0===this.smStates[e]&&(this.smStates[e]={transitions:{},enteringMethods:[],leavingMethods:[]})},JHStateMachine.prototype.smEntering=function(t,s){"string"==typeof t&&(t=[t]),"string"==typeof s&&(s=[s]);for(var e in t){var i=t[e];void 0===this.smStates[i]&&(this.smStates[i]={transitions:{},enteringMethods:[],leavingMethods:[]});for(var n in s){var a=s[n];this.smStates[i].enteringMethods.push(a)}}},JHStateMachine.prototype.smLeaving=function(t,s){"string"==typeof t&&(t=[t]),"string"==typeof s&&(s=[s]);for(var e in t){var i=t[e];void 0===this.smStates[i]&&(this.smStates[i]={transitions:{},enteringMethods:[],leavingMethods:[]});for(var n in s){var a=s[n];this.smStates[i].leavingMethods.push(a)}}},JHStateMachine.prototype.smStateGroup=function(t,s){"string"==typeof s&&(s=[s]),void 0===this.smGroups[t]&&(this.smGroups[t]=[]),s=this.smSolveStates(s);for(var e in s){var i=s[e];this.smContained(i,this.smGroups[t])||this.smGroups[t].push(i)}},JHStateMachine.prototype.smSetInitialState=function(t){this.smState=t},JHStateMachine.prototype.smGetState=function(){return this.smState},JHStateMachine.prototype.smHandleEvent=function(t,s){if(void 0===this.smStates[this.smState])return void console.error("Unknown state '",this.smState,"'");var e={date:(new Date).getTime(),fromState:this.smState,event:t,methods:[]};try{e.args=JSON.stringify(s)}catch(t){}var i=this.smStates[this.smState].transitions[t];if(void 0===i)return void console.warn("JHStateMachine: Event '",t,"' not handled in state '",this.smState,"'");this.smCurrentEvent=t;var n=this.smState!=i.state;if(n){var a=this.smStates[this.smState].leavingMethods;for(var o in a)try{e.methods.push(a[o]),"function"==typeof a[o]?a[o].call(this,s):this["$"+a[o]](s)}catch(t){throw console.error("Exception in leaving [",this.smState,"] --> "+("function"==typeof a[o]?a[o].name:a[o])+"(",s,"): ",t),t}}for(var o in i.methods)try{e.methods.push(i.methods[o]),"function"==typeof i.methods[o]?i.methods[o].call(this,s):this["$"+i.methods[o]](s)}catch(e){throw console.error("Exception in ["+this.smState+"] -- "+t+" --> "+("function"==typeof i.methods[o]?i.methods[o].name:i.methods[o])+"(",s,"): ",e),e}if(this.smJHStateMachineLeavingState(this.smState,t,s),this.smDebug("{",this.smState,"} == [",t,"] ==> {",i.state,"}"),this.smState=i.state,n){var h=this.smStates[this.smState].enteringMethods;for(var o in h)try{e.methods.push(h[o]),"function"==typeof h[o]?h[o].call(this,s):this["$"+h[o]](s)}catch(t){throw console.error("Exception in entering ["+this.smState+"] --> "+("function"==typeof h[o]?h[o].name:h[o])+"(",s,"): ",t),t}}for(this.smCurrentEvent=null,this.smJHStateMachineEnteringState(this.smState,t,s),e.toState=this.smState,this.smHistory.splice(0,0,e);this.smHistory.length>50;)this.smHistory.pop()},JHStateMachine.prototype.smPlay=function(){var t=this;this.smPaused&&(this.smPaused=!1,setTimeout(function(){t.smRun()},0))},JHStateMachine.prototype.smPause=function(){this.smPaused=!0},JHStateMachine.prototype.smStep=function(){if(this.smPauseNotified=!1,this.smEventQueue.length>0){var t=this.smEventQueue.shift();this.smHandleEvent(t.event,t.args)}this.smNotifyPause()},JHStateMachine.prototype.smRun=function(){this.smScheduled=!1;for(var t=0;this.smEventQueue.length>0;){if(this.smPaused)return void this.smRunEnd(t);t++,this.smStep()}for(;0==this.smPaused&&this.smEventQueue.length>0;)t++,this.smStep();this.smRunEnd(t)},JHStateMachine.prototype.smRunEnd=function(){},JHStateMachine.prototype.smQueueEvent=function(t,s){var e=this;this.smEventQueue.push({event:t,args:s}),this.smNotifyPause(),this.smScheduled||(this.smScheduled=!0,setTimeout(function(){e.smRun()},0))},JHStateMachine.prototype.smNotifyPause=function(){if(this.smEventQueue.length>0&&1==this.smPaused){var t=this.smEventQueue[0];this.smJHStateMachinePaused(t.event,t.args)}},JHStateMachine.prototype.smJHStateMachineEnteringState=function(t,s,e){},JHStateMachine.prototype.smJHStateMachineLeavingState=function(t,s,e){},JHStateMachine.prototype.smJHStateMachinePaused=function(t,s,e){},JHStateMachine.prototype.smGetTable=function(){var t={};for(var s in this.smStates){var e=this.smStates[s];for(var i in e.transitions){var n=e.transitions[i].state,a=s+"/"+n;if(void 0===t[a]&&(t[a]={}),t[a][i]=[],s!=n)for(var o in e.leavingMethods)t[a][i].push(e.leavingMethods[o]);for(var o in e.transitions[i].methods)t[a][i].push(e.transitions[i].methods[o]);if(s!=n)for(var o in this.smStates[n].enteringMethods)t[a][i].push(this.smStates[n].enteringMethods[o])}}var h=["<table><tr><td></td>"];for(var s in this.smStates)h.push("<td class='state'>"+s+"</td>");h.push("</tr>");for(var r in this.smStates){h.push("<tr><td class='state'>"+r+"</td>");this.smStates[r];for(var m in this.smStates){var a=(this.smStates[m],r+"/"+m);if(void 0===t[a])h.push("<td class='empty'></td>");else{h.push("<td class='transition'>");for(var i in t[a]){h.push("<div class='event'>"),h.push("<div class='eventname'>"+i+"</div>");for(var o in t[a][i])h.push("<div class='method'>"+t[a][i][o]+"</div>");h.push("</div>")}h.push("</td>")}}h.push("</tr>")}return h.push("</table>"),h.join("")},JHStateMachine.prototype.smGetHistoryTable=function(){var t=["<table><tr><th>Date</th><th>To</th><th>Event</th><th>Methods</th><th>From</th></tr>"];for(var s in this.smHistory){var e=this.smHistory[s];t.push("<tr>");var i=new Date(e.date),n=i.getHours()+":"+i.getMinutes()+":"+i.getSeconds()+"."+i.getMilliseconds();t.push("<td class='timestamp'>"+n+"</td>"),t.push("<td class='to'>"+e.toState+"</td>"),t.push("<td><div class='event'>"+e.event+"</div><div class='args'>("+e.args+")</div></td>"),t.push("<td class='methods'>");for(var a in e.methods)t.push(e.methods[a]+"<br/>");t.push("</td>"),t.push("<td class='from'>"+e.fromState+"</td>"),t.push("</tr>")}return t.push("</table>"),t.join("")},JHStateMachine.prototype.smSolveStates=function(t){var s=[];"string"==typeof t&&(t=[t]);for(var e in t){var i=t[e];if(void 0===this.smGroups[i])this.smContained(i,s)||s.push(i);else for(var n in this.smGroups[i])this.smContained(this.smGroups[i][n]),s&&s.push(this.smGroups[i][n])}return s},JHStateMachine.prototype.smContained=function(t,s){for(var e in s)if(t==s[e])return!0;return!1},JHStateMachine.prototype.smCheck=function(){var t={missing:[],unused:[]},s=[];for(var e in this.smStates){for(var i in this.smStates[e].enteringMethods){var n=this.smStates[e].enteringMethods[i];s[n]=!0}for(var i in this.smStates[e].leavingMethods){var n=this.smStates[e].leavingMethods[i];s[n]=!0}for(var a in this.smStates[e].transitions){var o=this.smStates[e].transitions[a];for(var i in o.methods){var n=o.methods[i];s[n]=!0}}}for(var n in s)"function"!=typeof this["$"+n]&&(t.missing.push(n),console.error("JHStateMachine: missing function $",n));for(var h in this)try{if("$"==h[0]&&"function"==typeof this[h]){var n=h.substr(1);void 0===s[n]&&t.unused.push(n)}}catch(a){}return t};
exports.view=View={Game:{},Board:{}},window.JoclyXdViewCleanup&&window.JoclyXdViewCleanup(),function(){function t(t,e){e=e||{bubbles:!1,cancelable:!1};var i=document.createEvent("Event");return i.initEvent(t,e.bubbles,e.cancelable),i}function e(){console.info.apply(console,arguments)}function i(){}function a(t,e){var i={},o=!1;for(var n in e)if(e.hasOwnProperty(n))if(t.hasOwnProperty(n))if("object"==typeof e[n]){var s=a(t[n],e[n]);s&&(i[n]=s,o=!0)}else e[n]!=t[n]&&(i[n]=e[n],o=!0);else i[n]=e[n],o=!0;return o?i:null}function o(){0==D++&&(M=$(".jocly-res-loading-mask"),0==M.length?M=$("<div/>").addClass("jocly-res-loading-mask").css({position:"absolute",top:0,left:0,width:$("body").width(),height:$("body").height(),"background-color":"rgba(0,0,0,.8)","background-image":"url("+O+")","background-position":"center center","background-repeat":"no-repeat","z-index":1e5}).appendTo($("body")):M.show())}function n(){0==--D&&M&&M.hide()}function s(t,e){if(z[t])e(z[t]);else{var i=new THREE.TextureLoader;i.setCrossOrigin("anonymous"),H&&console.log("Loading map",t),o(),i.load(t,function(i){z[t]=i,H&&console.log("Loaded",t),n(),j.animControl.trigger(),e(z[t])},function(t){},function(i){H&&console.log("(not) Loaded",t),n(),j.animControl.trigger(),e(null)})}}function r(t,e){function i(e){r.image=e,H&&console.log("Loaded",t),r.status="loaded",r.imgSrc=p,n();for(var i=0;i<r.pending.length;i++)r.pending[i](r.image,p);r.pending=null,j&&j.animControl.trigger()}function a(e,i){H&&console.log("Loaded",t);for(var a=0;a<e.faceVertexUvs.length;a++){for(var o=0;o<e.faceVertexUvs[a].length;o++){void 0===e.faceVertexUvs[a][o]&&(e.faceVertexUvs[a][o]=[{x:0,y:0},{x:0,y:0},{x:0,y:0}])}for(;o<e.faces.length;o++)e.faceVertexUvs[a].push([{x:0,y:0},{x:0,y:0},{x:0,y:0}])}if(v>0){new THREE.SubdivisionModifier(v).modify(e)}r.status="loaded",n(),r.geometry=e,r.materials=i;for(var a=0;a<r.pending.length;a++)r.pending[a](e,i);r.pending=null,j.animControl.trigger(3e3)}function s(e,i){H&&console.log("Loaded",t);var a=/^(\.)?(.*)$/.exec(h);if(i.url.substr(-a[2].length)==a[2]){$(document).unbind("jocly.json-resource",s),r.status="loaded",n(),r.data=i.data;for(var o=0;o<r.pending.length;o++)r.pending[o](r.data);r.pending=null,j&&j.animControl.trigger()}else console.warn("Expecting",h,"got",i.url)}var r=C[t];if(void 0===r){r=C[t]={pending:[e],status:"loading"};var c=null,l=/^(.*\|)(.*?)$/.exec(t);if(l){var d=l[1],h=l[2];for(var u in k){var m=/^(.*\|)(.*?)$/.exec(u);if(m&&d==l[1]&&h.substr(-m[2].length)==m[2]){c=k[u];break}}}if(/^image\|/.test(t)){var p=/^image\|(.*)/.exec(t)[1];if(H&&console.log("Loading resource",t),o(),c)c(function(t){var e=new Image;e.onload=function(){i(e)},e.src=t});else{var g=new Image;g.onload=function(){i(g)},g.src=p}}else if(/^smoothedfilegeo\|/.test(t)){if(H&&console.log("Loading resource",t),!j)return delete C[t],void V.push([t,e]);var l=/^smoothedfilegeo\|([^\|]*)\|(.*)$/.exec(t),v=parseInt(l[1]),f=l[2];o(),c?c(function(t){try{var e=j.loader.parse(JSON.parse(t));a(e.geometry,e.materials)}catch(t){}}):j.loader.load(f,a)}else if(/^json\|/.test(t)){H&&console.log("Loading resource",t),o();var h=/^json\|(.*)/.exec(t)[1];$(document).bind("jocly.json-resource",s),$("<script/>").attr("type","text/javascript").attr("jocly-type","json-resource").attr("src",h).appendTo($("head"))}else if(/^json2\|/.test(t)){H&&console.log("Loading resource",t),o();var h=/^json2\|(.*)/.exec(t)[1],y=new XMLHttpRequest;y.onreadystatechange=function(){if(y.readyState==XMLHttpRequest.DONE){H&&console.log("Loaded",t);var e=JSON.parse(y.responseText);r.status="loaded",n(),r.data=e;for(var i=0;i<r.pending.length;i++)r.pending[i](r.data);r.pending=null,j&&j.animControl.trigger()}},y.open("GET",h,!0),y.send(null)}else if(/^font\|/.test(t)){H&&console.info("font path",b);var b=/^font\|(.*)/.exec(t)[1];o();var E=new THREE.FontLoader;E.load(b,function(t){n(),r.status="loaded",r.font=t;for(var e=0;e<r.pending.length;e++)r.pending[e](t);r.pending=null,j&&j.animControl.trigger()})}}else"loading"==r.status?r.pending.push(e):/^image\|/.test(t)?e(r.image,r.imgSrc):/^smoothedfilegeo\|/.test(t)?e(r.geometry,r.materials):/^json\|/.test(t)?e(r.data):/^json2\|/.test(t)?e(r.data):/^font\|/.test(t)&&e(r.font)}function c(){if(j)for(;V.length;){var t=V.shift();r.call(null,t[0],t[1])}}function l(){E=new P,w=12600,x=w/2,T=null,j=null,S=.001,k={},C={},f=null,y=null,b=null}function d(t,e){try{"mediaOn"==e.webrtcType&&(e.ar?v(e.stream):it.addStream(e.side,e.stream,e.local)),"mediaOff"==e.webrtcType&&(I?v(null):it.removeStream(e.side)),"ccv"==e.webrtcType&&it.receiveRemoteLock(e.message)}catch(t){console.error("xd-view webrtc error",t)}}function h(){E.createGadget("camera",{"3d":{type:"camera3d",x:j.camera.position.x/S,y:j.camera.position.z/S,z:j.camera.position.y/S,targetX:j.cameraControls.camTarget.x/S,targetY:j.cameraControls.camTarget.z/S,targetZ:j.cameraControls.camTarget.y/S}}),E.saveGadgetProps("camera",["targetX","targetY","targetZ"],"initial"),E.updateGadget("camera",{"3d":{visible:!0}})}function u(t){function e(){var e=.001;return void 0!==t.smooth&&(e=t.smooth),new KalmanFilter({R:e})}function i(){h.angle=c,j.dolly=new TWEEN.Tween(h).to({angle:l},1e3*(t.speed||30)).onComplete(function(){i()}).onUpdate(function(){j.animControl.trigger()}).start()}var a={x:e(),y:e()},o=j.cameraControls.camTarget.x,n=j.cameraControls.camTarget.z,s=j.body.position.x,r=j.body.position.z,c=Math.atan2(r-n,s-o),l=c-2*Math.PI;"ccw"==t.direction&&(l=c+2*Math.PI);var d=Math.sqrt((s-o)*(s-o)+(r-n)*(r-n));j.dolly&&TWEEN.remove(j.dolly);var h={};j.animateCallbacks.dolly={_this:null,callback:function(){j.body.position.x=a.x.filter(o+d*Math.cos(h.angle)),j.body.position.z=a.y.filter(n+d*Math.sin(h.angle))}},i(),j.animControl.trigger()}function m(t){function e(){var e=.001;return void 0!==t.smooth&&(e=t.smooth),new KalmanFilter({R:e})}var i={x:e(),y:e(),z:e(),targetX:e(),targetY:e(),targetZ:e()},a={x:j.body.position.x,y:j.body.position.y,z:j.body.position.z,targetX:j.cameraControls.camTarget.x,targetY:j.cameraControls.camTarget.y,targetZ:j.cameraControls.camTarget.z},o={x:t.camera.x*S,z:t.camera.y*S,y:t.camera.z*S,targetX:t.camera.targetX*S,targetZ:t.camera.targetY*S,targetY:t.camera.targetZ*S},n=new THREE.Vector3(o.x,o.y,o.z),s=new THREE.Vector3(o.targetX,o.targetY,o.targetZ);j.dolly&&TWEEN.remove(j.dolly),j.dolly=new TWEEN.Tween(a).to(o,1e3*t.speed).onUpdate(function(){j.animControl.trigger()}).start(),j.animateCallbacks.dolly={_this:null,callback:function(){(j.body.position.x=i.x.filter(a.x),j.body.position.y=i.y.filter(a.y),j.body.position.z=i.z.filter(a.z),j.cameraControls.camTarget.x=i.targetX.filter(a.targetX),j.cameraControls.camTarget.y=i.targetY.filter(a.targetY),j.cameraControls.camTarget.z=i.targetZ.filter(a.targetZ),new THREE.Vector3(j.body.position.x,j.body.position.y,j.body.position.z).distanceTo(n)<.1)&&(new THREE.Vector3(j.cameraControls.camTarget.x,j.cameraControls.camTarget.y,j.cameraControls.camTarget.z).distanceTo(s)<.1&&(delete j.animateCallbacks.dolly,TWEEN.remove(j.dolly),delete j.dolly))}},j.animControl.trigger()}function p(t,e,i){function a(){this.animating=!1,this.animateTimer=null,this.nextStop=0}function o(t,e,i){var a=THREE.Object3D._threexDomEvent;y.set(t,e);try{var o=y.intersectObjects(a._boundObjs[a._boundContext])}catch(t){return i(null,null)}if(0==o.length)return i(null,null);var n=o[0],s=a.getRootObject(n.object);a._objectCtxGet(s)?i(s,n.point):i(null,null)}var n=new THREE.PerspectiveCamera(55,f.width()/f.height(),1,4e3),s=new THREE.Scene,r=new THREE.Object3D;s.add(r),r.add(n);var c=new THREE.Object3D;s.add(c);var l=new THREE.AmbientLight(12303291);c.add(l);var d=new THREE.SpotLight(16777215,1.75,0,1.05,1,2);d.position.set(-12,12,12),d.castShadow=!0,d.shadow.camera.near=1,d.shadow.camera.far=27,d.shadow.camera.fov=90,d.shadow.mapSize.width=4096,d.shadow.mapSize.height=4096,d.target=c,c.add(d);var h=new THREE.PointLight(13421772,2,150);h.position.set(-45,45,45),c.add(h);var u=new THREE.WebGLRenderer({antialias:!0,alpha:!0});u.setSize(f.width(),f.height());new THREE.Projector;f.append($(u.domElement)),u.gammaInput=!0,u.gammaOutput=!0,u.shadowMap.enabled=!0,u.shadowMapSoft=!0;var m=!1,p=new THREE.StereoEffect(u);p.setSize(f.width(),f.height());var g=new THREE.AnaglyphEffect(u);g.setSize(f.width(),f.height());var v=new VRGamepads({camera:n,scene:s,resBase:t.config.baseURL+"res/vr/",drag:function(t,e,i,a){var n=null,s=null;return o(t,e,function(t,e){n=e,s=t}),n?{point:n,object:s}:null},click:function(t,e){o(t,e,function(t,e){t&&THREE.Object3D._threexDomEvent._notify("mouseup",t,null,e)})},move:function(t){r.position.add(t)}}),y=new THREE.Raycaster,b=!!t.mViewOptions.camAnim,E={},w=0;a.prototype={start:function(){r.updateMatrixWorld(),null!=this.animateTimer&&(clearTimeout(this.animateTimer),this.animateTimer=null),0==this.animating&&(this.animating=!0,this.animate())},stop:function(t){if(j&&L.vrEffect&&L.vrEffect.isPresenting)return void(null!=this.animateTimer&&(clearTimeout(this.animateTimer),this.animateTimer=null));void 0===t&&(t=200);var e=Date.now(),i=this;if(this.animating){if(null!=this.animateTimer){if(!(this.nextStop<e+t))return;clearTimeout(this.animateTimer)}this.nextStop=Math.max(this.nextStop,e+t),this.animateTimer=setTimeout(function(){i.animateTimer=null,i.animating=!1},this.nextStop-e)}},trigger:function(){this.animating&&null==this.animateTimer||(this.start(),this.stop.apply(this,arguments))},animate:function(){function e(a){w--;if(i.animating&&(w++,requestAnimationFrame(e)),TWEEN.update(),L.vrEffect&&L.vrEffect.isPresenting){v.update();var o=v.getHarborPad();if(o){o.visible=!1,o.getWorldPosition(k.harbor.position);var r=.03*(o.getAxes()[1]+1.1);k.harbor.scale.set(r,r,r),o.getWorldQuaternion(k.harbor.quaternion)}else k.harbor.position.set(0,0,0),k.harbor.scale.set(1,1,1),k.harbor.quaternion.copy(k.defaultHarborQuaternion);L.vrControls.update(),L.vrEffect.render(s,n)}else I||(k.harbor.position.set(0,0,0),k.harbor.scale.set(1,1,1),k.harbor.quaternion.copy(k.defaultHarborQuaternion)),I||(T.update(),S.update()),m?(v.update(),p.render(s,n)):k.anaglyph||t.mAnaglyph?g.render(s,n):u.render(s,n);for(var c in E){var l=E[c];l.callback.call(l._this)}}var i=this;w++,e(window.performance.now())}};var x=new a,T=new THREE.OrbitControls(n,r,u.domElement);$.extend(T,{autoRotate:b,animControl:x}),T.camTarget.set(0,.8,0);var C=!1,S=new THREE.DeviceOrientationControls(r,function(t){void 0!==L&&x.trigger(),!C&&t.enabled&&(C=!0,f.find(".vr-button").show())});"function"==typeof T.addEventListener&&T.addEventListener("change",function(){x.trigger()});var k={scene:s,renderer:u,light:d,skyLight:h,ambientLight:l,loader:new THREE.JSONLoader,camera:n,cameraControls:T,animateCallbacks:E,camTarget:T.camTarget,animControl:x,body:r,harbor:c,defaultHarborQuaternion:c.quaternion.clone(),anaglyphEffect:g,anaglyph:!1},L=function(e){function i(){L.vrControls.resetPose()}function a(){e.vrButton=document.createElement("img"),e.vrButton.className="vr-button",e.vrButton.setAttribute("data-vr-enter-src",t.config.baseURL+"res/vr/vr-enter.png"),e.vrButton.setAttribute("data-vr-exit-src",t.config.baseURL+"res/vr/vr-exit.png"),e.vrButton.setAttribute("src",e.vrButton.getAttribute("data-vr-enter-src")),Object.assign(e.vrButton.style,{position:"absolute",bottom:"8px",right:"8px",cursor:"pointer","z-index":2147483647}),f[0].appendChild(e.vrButton)}function o(){a(),e.vrButton.style.display="none",e.vrButton.addEventListener("click",function(){if(m){m=!1,e.vrButton.setAttribute("src",e.vrButton.getAttribute("data-vr-enter-src"));var t=u.getSize();u.setViewport(0,0,t.width,t.height)}else m=!0,e.vrButton.setAttribute("src",e.vrButton.getAttribute("data-vr-exit-src"));x.trigger()})}function n(){a();var t=new THREE.VRControls(e.camera);L.vrControls=t,window.lastVrEffect&&window.lastVrEffect.isPresenting&&window.lastVrEffect.exitPresent();var o=new THREE.VREffect(e.renderer);L.vrEffect=o,window.lastVrEffect=o,window.addEventListener("vrdisplaypresentchange",function(t){e.animControl.trigger()},!1),e.vrButton.addEventListener("click",function(){o.isPresenting?(o.exitPresent(),e.vrButton.setAttribute("src",e.vrButton.getAttribute("data-vr-enter-src"))):(o.requestPresent(),e.vrButton.setAttribute("src",e.vrButton.getAttribute("data-vr-exit-src")),i()),x.trigger()})}return L={},void 0!==navigator.getVRDisplays?navigator.getVRDisplays().then(function(t){0==t.length?o():n()}).catch(function(){o()}):o(),L}(k);return $.extend(k,L)}function g(t){return t.originalEvent?g(t.originalEvent):t.changedTouches&&t.changedTouches.length>0?[t.changedTouches[0].pageX,t.changedTouches[0].pageY]:t.touches&&t.touches.length>0?[t.touches[0].pageX,t.touches[0].pageY]:[t.pageX,t.pageY]}function v(t){if(!!I==!!t)return void console.warn("AR is already",!!t);if(I=t){var e=$("<video/>").addClass("ar-video").attr("autoplay","autoplay").css({position:"absolute",top:0,width:"100%",height:"100%",left:0,"z-index":-1,backgroundColor:"#0f0",objectFit:"cover"}).appendTo(f.parent());JoclyAR.attach({element:e[0],stream:I,threeCtx:j}),E.redisplayGadgets(),j.renderer.setClearColor(new THREE.Color(j.world.color),0),j.animControl.trigger()}else{var e=f.parent().find(".ar-video");e.length&&(JoclyAR.detach({element:e[0]}),e.remove()),E.redisplayGadgets(),j.renderer.setClearColor(new THREE.Color(j.world.color),1),j.animControl.trigger()}}window.JoclyXdViewCleanup=function(){var t=j&&j.renderer;t&&(t.forceContextLoss(),t.context=null,t.domElement=null,delete j.renderer),I&&v(null)};var f,y,b,E,w,x,T,C,j=null,S=.001,k={},I=null,L=0,R=0,O="";void 0===t&&(t.prototype=window.Event.prototype,window.CustomEvent=t);var A=function(){};!function(){var t=!1,e=/xyz/.test(function(){})?/\b_super\b/:/.*/;A.extend=function(i){function a(e){!t&&this.init&&(arguments.length>0&&e.jBlocksArgsList?this.init.apply(this,e):this.init.apply(this,arguments))}var o=this.prototype;t=!0;var n=new this;t=!1;for(var s in i)n[s]="function"==typeof i[s]&&"function"==typeof o[s]&&e.test(i[s])?function(t,e){return function(){var i=this._super;this._super=o[t];var a=e.apply(this,arguments);return this._super=i,a}}(s,i[s]):i[s];return a.prototype=n,a.prototype.constructor=a,a.extend=arguments.callee,a}}();var _,H=!1;View.Board.Log=e,View.Game.Log=e,i.prototype=new JHStateMachine,i.prototype.smError=function(){},i.prototype.smWarning=function(){},i.prototype.smDebug=function(){};var M=null,D=0,z={},V=[],P=A.extend({init:function(){this.gadgets={},this.resources={},this.game=null,this.initDone=!1,this.ratio=0,this.center=null,this.getMaterialMap=s},createGadget:function(t,e){this.ratio>0&&(void 0===e.base&&(e.base={}),e.base.ratio=this.ratio,e.base.center=this.center),this.gadgets[t]=new G(t,e)},updateGadget:function(t,e,i,a){var o=this.gadgets[t];o&&((arguments.length<3||void 0===i)&&(i=0),(arguments.length<4||void 0===a)&&(a=function(){}),o.update(e,i,a))},removeGadget:function(t){var e=this.gadgets[t];e&&(e.unbuild(),delete this.gadgets[t])},showGadget:function(t){this.updateGadget(t,{base:{visible:!0}})},hideGadget:function(t){this.updateGadget(t,{base:{visible:!1}})},updateArea:function(t,e){this.ratio=t,this.center=e;for(var i in this.gadgets)this.gadgets[i].update({base:{ratio:t,center:e}})},redisplayGadgets:function(){for(var t in this.gadgets){this.gadgets[t].update({})}},unbuildGadgets:function(){for(var t in this.gadgets)this.gadgets[t].unbuild()},saveGadgetProps:function(t,e,i){var a=this.gadgets[t];a&&a.saveProps(e,i)},restoreGadgetProps:function(t,e,i,a){var o=this.gadgets[t];o?o.restoreProps(e,i,a):a&&a()},listScene:function(){function t(e,i){if(e.geometry){var a=e.geometry;a.faces&&(i+=a.faces.length)}if(e.getDescendants){var o=e.getDescendants();o&&(i+=t(o,i))}return i}console.log("listScene:");var e=[];e.faces=0;var i="========= Scene summary ===========",a=-1;if(j&&j.scene){var o=j.scene;a=o.__lights.length,console.log(o);var n=o.getDescendants();for(var s in n){var r=t(n[s],0);e.faces+=r}}i+=" :: nb lights: "+a,i+=" :: Nb faces: "+e.faces,console.log(i)}});l();var G=A.extend({init:function(t,e){this.id=t,this.options=$.extend(!0,{base:{visible:!1}},e),this.avatar=null,this.savedProps={}},mergeOptions:function(){return $.extend(!0,{x:0,y:0,z:0},this.options.base,y["3d"]?this.options["3d"]:this.options["2d"],this.options[y.name])},build:function(t){this.avatar||0==arguments.length&&this.mergeOptions()},unbuild:function(){this.avatar&&(this.avatar.remove(),this.avatar=null)},canDisplay:function(t){return void 0!==y&&null!==y&&(0==arguments.length&&(t=this.mergeOptions()),t.visible&&(!y["3d"]&&void 0!==t.ratio&&void 0!==t.center||y["3d"]))},update:function(t,e,i){if((arguments.length<2||void 0===e)&&(e=0),(arguments.length<3||void 0===i)&&(i=function(){}),void 0!==y&&null!==y){var a=y["3d"]?"3d":"2d";if(t.base)for(var o in t.base)this.options[a]&&delete this.options[a][o],this.options[y.name]&&delete this.options[y.name][o];if(t[a])for(var o in t[a])this.options[y.name]&&delete this.options[y.name][o];$.extend(!0,this.options,t);var n=this.mergeOptions();if(!this.avatar&&this.canDisplay(n)){var s=st[n.type];void 0!==s&&(this.avatar=new s(this,n))}"object"==typeof e&&(e=void 0!==e[y.name]?e[y.name]:void 0!==e[a]?e[a]:void 0!==e.base?e.base:0),this.avatar&&this.avatar.update(n,e,i)}else $.extend(!0,this.options,t)},saveProps:function(t,e){var i={};for(var a in this.options){var o=this.options[a];for(var n in t){var s=t[n];void 0!==o[s]&&(i[a]=i[a]||{},i[a][s]=o[s])}}this.savedProps[e]=i},restoreProps:function(t,e,i){void 0!==this.savedProps[t]?this.update(this.savedProps[t],e,i):i&&i()}}),N=1,W=A.extend({init:function(t,e){this.gadget=t,this.options=e,this.SCALE3D=S,this.animCounts={}},remove:function(){},display:function(t){},update:function(t,e,i){var a=$.extend(!0,{},this.options,t);a.updateOp=N++,a.updateCallback=i,this.display(a,e,i),a.visible?this.show():this.hide(),this.options=a},show:function(){},hide:function(){},animStart:function(t){return void 0===t?void console.error("animStart without options"):void 0===t.updateOp?void console.error("animStart without options"):(this.object3d&&(this.object3d.matrixAutoUpdate=!0),void(void 0===this.animCounts[t.updateOp]?this.animCounts[t.updateOp]=1:this.animCounts[t.updateOp]++))},animEnd:function(t){return void 0===t?void console.error("animEnd without options"):void 0===t.updateOp?void console.error("animEnd without options"):void 0===this.animCounts[t.updateOp]?void console.error("animEnd without animCount"):void(0==--this.animCounts[t.updateOp]&&(this.object3d&&(this.object3d.matrixAutoUpdate=!1),t.updateCallback(),delete this.animCounts[t.updateOp]))},getResource:r}),B=W.extend({init:function(t,e){e=$.extend(!0,{display:function(){}},e),this._super.apply(this,arguments),this.options=$.extend(!0,{x:0,y:0,z:0,width:1e3,height:1e3,tag:"div",opacity:1,rotate:0,css:{}},e),this.element=$("<"+this.options.tag+"/>").css({position:"absolute","z-index":this.options.z}).hide().addClass("jocly-gadget").appendTo(f),this.options.initialClasses&&this.element.addClass(this.options.initialClasses)},display:function(t,e){var i=this;this.element?(this.displayElement.call(this,!this.displayCalled,t,e),this.displayCalled=!0):e&&(this.animStart(t),setTimeout(function(){i.animEnd(t)},e))},displayElement:function(e,i,a){var o=this;if(this.element.css($.extend(!0,this.options.css,i.css)),e||void 0===this.aWidth||void 0===this.aHeight||i.ratio!=this.options.ratio||i.center.x!=this.options.center.x||i.center.y!=this.options.center.y||i.width!=this.options.width||i.height!=this.options.height||i.x!=this.options.x||i.y!=this.options.y||i.z!=this.options.z){this.aWidth=i.width*i.ratio,this.aHeight=i.height*i.ratio;var n=i.x*i.ratio+i.center.x-this.aWidth/2,s=i.y*i.ratio+i.center.y-this.aHeight/2;a?(this.animStart(i),this.element.css({"z-index":i.z}).animate({width:this.aWidth,height:this.aHeight,left:n,top:s},a,function(){o.animEnd(i)})):this.element.css({width:this.aWidth,height:this.aHeight,left:n,top:s,"z-index":i.z}),this.options.display(this.element,this.aWidth,this.aHeight)}if((e||i.classes!=this.options.classes)&&(this.options.classes&&this.element.removeClass(this.options.classes),this.element.addClass(i.classes)),(e||i.click!=this.options.click)&&(this.element.unbind(JocGame.MOUSEMOVE_EVENT),this.element.unbind(JocGame.MOUSEDOWN_EVENT),this.element.unbind(JocGame.MOUSEUP_EVENT),i.click)){var r=!!navigator.userAgent.match(/(iPad|iPhone|iPod)/g);!function(){var e=!1,a=!1,n=[0,0];o.element.bind(JocGame.MOUSEDOWN_EVENT,function(t){t.preventDefault(),r&&"mousedown"==t.type||("touchstart"==t.type&&(L=Date.now()),"mousedown"==t.type&&Date.now()-L<500||(e=!0,n=g(t)))}),o.element.bind(JocGame.MOUSEUP_EVENT,function(a){if(a.preventDefault(),!(r&&"mouseup"==a.type||(e=!1,"joclyclick"==a.type&&(R=Date.now()),"mouseup"==a.type&&Date.now()-R<500)))if("mouseup"==a.type||"joclyclick"==a.type)i.click.call(o);else{a.stopPropagation();var n,s,c=new t("joclyclick",{});if(a.originalEvent.changedTouches&&a.originalEvent.changedTouches.length>0)n=a.originalEvent.changedTouches[0].pageX,s=a.originalEvent.changedTouches[0].pageY;else{if(!(a.originalEvent.touches&&a.originalEvent.touches.length>0))return void console.warn("Invalid touch event");n=a.originalEvent.touches[0].pageX,s=a.originalEvent.touches[0].pageY}var l=document.elementFromPoint(n,s);l.dispatchEvent(c)}}),o.element.bind(JocGame.MOUSEMOVE_EVENT,function(t){if(t.preventDefault(),(!r||"mousemove"!=t.type)&&e&&!a){var s=g(t),c=s[0]-n[0],l=s[1]-n[1];c*c+l*l>100&&(a=!0,i.click.call(o))}})}()}if(e||i.rotate!=this.options.rotate){for(;i.rotate<0;)i.rotate+=360;i.rotate%=360;var c=i.rotate,l=this.options.rotate;c-this.options.rotate>180?l=360:this.options.rotate-c>180&&(c+=360),a?(this.animStart(i),$({deg:l}).animate({deg:c},{step:function(t){o.element.css("transform","rotate("+t+"deg)")},duration:a,complete:function(){o.animEnd(i)}})):this.element.css({transform:"rotate("+i.rotate+"deg)"})}else a&&(this.animStart(i),setTimeout(function(){o.animEnd(i)},0));(e||i.opacity!=this.options.opacity)&&(a?(this.animStart(i),this.element.stop().animate({opacity:i.opacity},a,function(){o.animEnd(i)})):this.element.css({opacity:i.opacity}))},show:function(){this.element.show()},hide:function(){this.element.hide()},remove:function(){this._super.apply(this,arguments),this.element.unbind(JocGame.CLICK),this.element.remove()}}),U=B.extend({displayElement:function(t,e){var i=this;this._super.apply(this,arguments),(t||this.options.file!=e.file)&&(this.options.file=e.file,r("image|"+e.file,function(t,e){e==i.options.file?i.element.css({"background-image":"url("+t.src+")","background-size":"100% 100%","background-repeat":"no-repeat"}):console.log("file has changed to",i.options.file,"(",e,")")}))}}),F=B.extend({init:function(t,e){e=$.extend({tag:"canvas",draw:function(){}},e),this._super.call(this,t,e),this.canvasContext=this.element[0].getContext("2d")},displayElement:function(t,e){this._super.apply(this,arguments),this.element.attr("width",this.aWidth).attr("height",this.aHeight),this.canvasContext.clearRect(0,0,e.width,e.height),this.canvasContext.translate(this.aWidth/2,this.aHeight/2),this.canvasContext.scale(e.ratio,e.ratio),this.options.draw.call(this,this.canvasContext,1/e.ratio)}}),X=F.extend({init:function(t,e){var i=this,a=e.radius,o=a*Math.sqrt(3)/2;e=$.extend({lineWidthFactor:1},e,{draw:function(t,e){t.lineWidth=e*i.options.lineWidthFactor,t.beginPath(),t.moveTo(-o,o/2),t.lineTo(0,a),t.lineTo(o,o/2),t.lineTo(o,-o/2),t.lineTo(0,-a),t.lineTo(-o,-o/2),t.closePath(),i.options.strokeStyle&&(t.strokeStyle=i.options.strokeStyle,t.stroke()),i.options.fillStyle&&(t.fillStyle=i.options.fillStyle,t.fill())}}),this._super.call(this,t,e),this.element.attr("width",e.width).attr("height",e.height),this.canvasContext=this.element[0].getContext("2d")}}),Y=F.extend({init:function(t,e){this._super.apply(this,arguments),this.displayArgs=null},displayElement:function(t,e){var i=this;this._super.apply(this,arguments),(t||this.options.file!=e.file)&&r("image|"+e.file,function(t,e){e==i.options.file&&(i.image=t,i.element.css({"background-image":"url("+t.src+")","background-size":"100% 100%","background-repeat":"no-repeat"})),i.displayArgs&&void 0!==i.options.clipx&&void 0!==i.options.clipy&&void 0!==i.options.clipwidth&&void 0!==i.options.clipheight&&i.drawImage.apply(i,i.displayArgs)}),(t||this.options.clipx!=e.clipx||this.options.clipy!=e.clipy||this.options.clipwidth!=e.clipwidth||this.options.clipheight!=e.clipheight)&&(this.image&&void 0!==e.clipx&&void 0!==e.clipy&&void 0!==e.clipwidth&&void 0!==e.clipheight?this.drawImage.call(this,t,e):this.displayArgs=arguments),this.image&&void 0!==e.clipx&&void 0!==e.clipy&&void 0!==e.clipwidth&&void 0!==e.clipheight?this.drawImage.apply(this,arguments):this.displayArgs=arguments},drawImage:function(t,e){var i=e.clipwidth/this.aWidth,a=e.clipheight/this.aHeight,o=parseInt(this.image.width/i+.5),n=parseInt(this.image.height/a+.5),s=o+"px "+n+"px";this.element.css({width:parseInt(this.aWidth+.5),height:parseInt(this.aHeight+.5),"background-image":e.file,"background-size":s,"background-position":"-"+parseInt(e.clipx/i+.5)+"px -"+parseInt(e.clipy/a+.5)+"px"})}}),J=B.extend({init:function(t,e){this._super.apply(this,arguments)},displayElement:function(t,e){this._super.apply(this,arguments),this.element.css({"border-radius":"50%"})}}),Z=W.extend({init:function(t,e){this._super.apply(this,arguments),this.displayCalled=!1,this.options=$.extend(!0,{x:0,y:0,z:0,color:null,castShadow:!0,receiveShadow:!1,harbor:!0},e),this.createObject()},createObject:function(){},objectReady:function(t){this.object3d=t,t.castShadow=this.options.castShadow,t.receiveShadow=this.options.receiveShadow,t.name=this.gadget.id,t.matrixAutoUpdate=!1,this.shouldUpdate=!0,this.update(this.options),this.options.harbor?j.harbor.add(t):j.scene.add(t)},display:function(t,e){var i=this;this.object3d&&(this.shouldUpdate=!1,this.displayObject3D.call(this,!this.displayCalled,t,e),this.displayCalled=!0,this.shouldUpdate&&this.object3d.updateMatrix()),e&&(i.animStart(t),setTimeout(function(){i.animEnd(t)},e))},displayObject3D:function(t,e,i){var a=this;j.animControl.trigger((isNaN(i)?0:i)+200),(t||e.x!=this.options.x||e.y!=this.options.y||e.z!=this.options.z)&&(this.shouldUpdate=!0,i?(this.animStart(e),new TWEEN.Tween(this.object3d.position).to({x:e.x*S,y:e.z*S,z:e.y*S},i).easing(e.positionEasing?e.positionEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){a.animEnd(e)}).onUpdate(function(t){e.positionEasingUpdate&&e.positionEasingUpdate.call(a,t)}).start()):(this.object3d.position.x=e.x*S,this.object3d.position.y=e.z*S,this.object3d.position.z=e.y*S)),(t||e.click!=this.options.click)&&(this.options.click&&this.object3d.off("mouseup"),e.click&&this.object3d.on("mouseup",function(){e.click.call()})),(t||e.castShadow!=this.options.castShadow)&&(this.object3d.castShadow=e.castShadow),(t||e.receiveShadow!=this.options.receiveShadow)&&(this.object3d.receiveShadow=e.receiveShadow)},show:function(){if(I&&!this.options.harbor)return this.hide();if(this.object3d&&(this.object3d.visible=!0,this.object3d.children))for(var t=0;t<this.object3d.children.length;t++){var e=this.object3d.children[t];void 0===e.joclyVisible||e.joclyVisible?e.visible=!0:e.visible=!1}},hide:function(){if(this.object3d&&(this.object3d.visible=!1,this.object3d.children))for(var t=0;t<this.object3d.children.length;t++)this.object3d.children[t].visible=!1},remove:function(){this._super.apply(this,arguments),this.object3d&&(this.options.click&&this.object3d.off("mouseup"),this.object3d.parent&&this.object3d.parent.remove(this.object3d),this.object3d=null)},getMaterialMap:s}),q=Z.extend({init:function(t,e){e=$.extend(!0,{rotate:0,rotateX:0,rotateY:0,scale:[1,1,1],materials:{},smooth:0,opacity:1,flatShading:!1,morphing:[]},e,{}),this._super.call(this,t,e)},displayObject3D:function(t,e,i){var o=this;if(this._super.apply(this,arguments),t||e.rotate!=this.options.rotate||e.rotateX!=this.options.rotateX||e.rotateY!=this.options.rotateY){this.shouldUpdate=!0;var n=e.rotate-this.options.rotate;n>180?e.rotate-=360:n<-180&&(e.rotate+=360),n=e.rotateX-this.options.rotateX,n>180?e.rotateX-=360:n<-180&&(e.rotateX+=360),n=e.rotateY-this.options.rotateY,n>180?e.rotateY-=360:n<-180&&(e.rotateY+=360),i?(this.animStart(e),new TWEEN.Tween(this.object3d.rotation).to({x:e.rotateX*(Math.PI/180),y:e.rotate*(Math.PI/180),z:e.rotateY*(Math.PI/180)},i).easing(e.rotateEasing?e.rotateEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){o.animEnd(e)}).start()):(this.object3d.rotation.x=e.rotateX*(Math.PI/180),this.object3d.rotation.y=e.rotate*(Math.PI/180),this.object3d.rotation.z=e.rotateY*(Math.PI/180))}if((t||e.scale[0]!=this.options.scale[0]||e.scale[1]!=this.options.scale[1]||e.scale[2]!=this.options.scale[2])&&(this.shouldUpdate=!0,i?(this.animStart(e),new TWEEN.Tween(this.object3d.scale).to({x:e.scale[0],y:e.scale[2],z:e.scale[1]},i).easing(e.scaleEasing?e.scaleEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){o.animEnd(e)}).start()):this.object3d.scale.set(e.scale[0],e.scale[2],e.scale[1])),(t||e.color!=this.options.color)&&this.object3d.material&&void 0!==this.object3d.material.color&&null!==e.color&&this.object3d.material.color.setHex(e.color),(t||e.opacity!=this.options.opacity)&&this.object3d.material&&void 0!==this.object3d.material.opacity&&(null===e.opacity&&(e.opacity=1),i?(this.animStart(e),new TWEEN.Tween(this.object3d.material).to({opacity:e.opacity},i).easing(e.opacityEasing?e.opacityEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){o.animEnd(e)}).start()):this.object3d.material.opacity=e.opacity),(t||e.morphing.toString()!=this.options.morphing.toString())&&(this.shouldUpdate=!0,e.morphing.length>0)){if(this.object3d.material&&this.object3d.material.materials&&this.object3d.material.materials.length>0&&!this.object3d.material.materials[0].morphTargets)for(var r=0;r<this.object3d.material.materials.length;r++)this.object3d.material.materials[r].morphTargets=!0;if(i)this.animStart(e),new TWEEN.Tween(this.object3d.morphTargetInfluences).to(e.morphing,i).easing(e.morphingEasing?e.morphingEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){o.animEnd(e)}).start();else for(var r=0;r<e.morphing.length&&r<this.object3d.morphTargetInfluences.length;r++)this.object3d.morphTargetInfluences[r]=e.morphing[r]}if(this.object3d.material&&e.materials)if(t){if(this.object3d.material.materials)for(var c in this.object3d.material.materials){var l=o.object3d.material.materials[c];if(e.materials[l.name])for(var d in e.materials[l.name]){var h=e.materials[l.name][d];!function(t,e){"map"==e?s(h,function(i){t[e]=i,t.needsUpdate=!0}):"color"==e?(void 0!==t.ambient&&t.ambient.setHex(h),t[e].setHex(h)):t[e]=h}(l,d)}}}else{var u=a(this.options.materials,e.materials);if(u)for(var m in u){var p=u[m];if(this.object3d.material.materials)for(var c in this.object3d.material.materials){var l=o.object3d.material.materials[c];if(l.name==m)if(p)for(var d in p){var h=p[d];null!==h?function(t,a){if("map"==a)s(h,function(e){t[a]=e,t.needsUpdate=!0});else if("color"==a)void 0!==t.ambient&&t.ambient.setHex(h),t[a].setHex(h);else if(i)if(o.animStart(e),void 0===t[a]||isNaN(h))t[a]=h,setTimeout(function(){o.animEnd(e)});else{var n={};n[a]=h,new TWEEN.Tween(t).to(n,i).easing(e.materialEasing?e.materialEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){o.animEnd(e)}).start()}else t[a]=h}(l,d):delete l[d]}else delete l.map,delete l.opacity,delete l.color}}}}}),Q=q.extend({init:function(t,e){e=$.extend(!0,{create:function(){return null},display:function(){}},e,{}),this._super.call(this,t,e)},createObject:function(){function t(t){e.objectReady(t)}var e=this,i=this.options.create.call(this,t);i&&this.objectReady(i)},displayObject3D:function(t,e,i){this._super.apply(this,arguments),this.options.display.call(this,t,e,i)},replaceMesh:function(t,e,i){this.object3d&&(this.options.click&&this.object3d.off("mouseup"),this.object3d.parent&&this.object3d.parent.remove(this.object3d)),
this.object3d=t,this.options.visible?this.show():this.hide(),this.options.harbor?j.harbor.add(this.object3d):j.scene.add(this.object3d),i?(this.displayObject3D(!0,this.options),this.displayObject3D(!0,e,i)):this.displayObject3D(!0,e)}}),K=q.extend({init:function(t,e){e=$.extend(!0,{display:function(){},sx:1e3,sy:1e3,color:16777215,horizontal:!0,texture:null,material:"basic",side:null},e,{}),this._super.call(this,t,e)},createObject:function(){var t=new THREE.PlaneGeometry(this.options.sx*S,this.options.sy*S,1,1),e={color:this.options.data,opacity:0};if(this.options.texture){var i=this.options.texture;i.file&&s(i.file,function(t){void 0!==i.wrapS&&(t.wrapS=i.wrapS),void 0!==i.wrapT&&(t.wrapT=i.wrapT),i.repeat&&t.repeat.set.apply(t.repeat,i.repeat),e.map=t})}void 0!==this.options.side&&(e.side=this.options.side),void 0!==this.options.transparent&&(e.transparent=this.options.transparent);var a;switch(this.options.material){case"phong":a=new THREE.MeshPhongMaterial(e);break;default:a=new THREE.MeshBasicMaterial(e)}var o=new THREE.Mesh(t,a);this.objectReady(o)}}),tt=Z.extend({init:function(t,e){e=$.extend(!0,{create:function(){return null},display:function(){}},e,{}),this._super.call(this,t,e)},createObject:function(){function t(t){e.objectReady(t)}var e=this,i=this.options.create.call(this,t);i&&this.objectReady(i)},displayObject3D:function(t,e,i){this._super.apply(this,arguments),this.options.display.call(this,t,e,i)}}),et=q.extend({init:function(t,e){this._super.apply(this,arguments),this.meshFileForceDisplay=!1},createObject:function(){var t=this,e=this.options.file;this.options.smooth;r("smoothedfilegeo|"+this.options.smooth+"|"+e,function(i,a){if(e==t.options.file){for(var o=[],n=0;n<a.length;n++)o.push(a[n].clone());if(a=o,t.options.flatShading)for(var s=0;s<a.length;s++)a[s].shading=THREE.FlatShading;var r=new THREE.Mesh(i,new THREE.MultiMaterial(a));t.objectReady(r),t.meshFileForceDisplay&&(t.displayObject3D(!0,t.meshFileForceDisplay),t.meshFileForceDisplay=!1)}})},displayObject3D:function(t,e,i){var a=e.file!=this.options.file;a&&(e.click=null),this._super.apply(this,arguments),a&&(this.object3d&&(this.options.click&&this.object3d.off("mouseup"),this.object3d.parent&&this.object3d.parent.remove(this.object3d),this.object3d=null),this.options.file=e.file,this.meshFileForceDisplay=e,this.createObject())}}),it=q.extend({init:function(t,e){e=$.extend(!0,{scale:[1,1,1],playerSide:1,makeMesh:function(t,e){var i=new THREE.MeshBasicMaterial({map:t,overdraw:!0}),a=new THREE.PlaneGeometry(12,9,1,1);return new THREE.Mesh(a,i)},videoPlaying:function(t){},ccvLocked:function(t){},ccv:!1,ccvMargin:[.1,.1,.3,.1],ccvWidth:80,ccvHeight:60,hideBeforeFirstLock:!0},e),this._super.call(this,t,e),this.videoConnected=!1,this.videoErrorCount=0,this.videoSkipError=!1,this.shouldBeVisible=!1,this.gotFirstLock=!1},objectReady:function(t){t.visible=!1;for(var e=0;e<t.children.length;e++)t.children[e].visible=!1;this.streamReady(it.isStreamReady(this.options.playerSide)),this._super.apply(this,arguments)},createObject:function(){it.addAvatar(this,this.options.playerSide);var t=null;this.ccvContextKey&&(t=it.getCCVVideoTexture(this.options.playerSide,this.ccvContextKey));var e=this.options.makeMesh.call(this,it.getVideoTexture(this.options.playerSide),t);e&&this.objectReady(e)},remove:function(){it.removeAvatar(this,this.options.playerSide),this._super.apply(this,arguments)},show:function(){this.shouldBeVisible=!0,!this.videoConnected||0!=this.options.ccv&&!this.gotFirstLock&&this.options.hideBeforeFirstLock||this._super()},hide:function(){this.shouldBeVisible=!1,this._super()},streamReady:function(t){this.videoConnected=t,t?this.show():this.hide()},ccvLocked:function(t){t&&this.shouldBeVisible&&(this.gotFirstLock=!0,this.show()),this.options.ccvLocked(t)}});it.streams={},it.avatars={1:[],"-1":[]},it.textures={1:null,"-1":null},it.renderLoopHooked=!1,it.ccvLibRequested=!1,it.getStream=function(t){if(!this.streams[t]){var e={stream:null,avatars:this.avatars[t],video:null,videoImage:null,videoContext:null,videoTexture:null,streamReady:!1,ownVideoElement:!1,errorCount:0,loopCount:0,local:!1,ccvVideoImage:null,ccvInProgress:!1,ccvLock:null,ccvContexts:{},ccvLastAnalyzed:null,ccvLastSuccess:null},i=$("video[joclyhub-video='"+t+"']");i.length>0?e.video=i:(e.ownVideoElement=!0,e.video=$("<video/>").attr("autoplay","autoplay").width(160).height(120).css({visibility:"hidden",position:"absolute","z-index":-1,top:0}).attr("joclyhub-video",t).appendTo("body"));var a=$("canvas[joclyhub-video-canvas='"+t+"']");a.length>0?(e.videoImage=a,this.textures[t]?e.videoTexture=this.textures[t]:(e.videoTexture=new THREE.Texture(e.videoImage[0]),this.textures[t]=e.videoTexture)):(e.videoImage=this.makeCanvas(160,120).attr("joclyhub-video-canvas",t),e.videoTexture=new THREE.Texture(e.videoImage[0]),this.textures[t]=e.videoTexture),e.videoTexture.minFilter=THREE.LinearFilter,e.videoTexture.magFilter=THREE.LinearFilter,e.videoImageContext=e.videoImage[0].getContext("2d"),this.streams[t]=e}return this.streams[t]},it.addStream=function(t,e,i){var a=this,o=this.getStream(t);o.stream=e,o.local=i,j&&j.animControl.trigger(3e3),this.renderLoopHooked||(this.renderLoopHooked=!0,j&&(j.animateCallbacks.Gadget3DVideo={_this:a,callback:a.animate}))},it.removeStream=function(t){var e=this.streams[t];if(e){if(e.streamReady)for(var i=0;i<e.avatars.length;i++)e.avatars[i].streamReady(!1);if(e.ccvLastSuccess&&e.ccvLastSuccess.videoImage.remove(),e.ccvLastAnalyzed&&e.ccvLastAnalyzed.remove(),delete this.streams[t],this.renderLoopHooked){var a=0;for(var o in this.streams)a++;0==a&&(j&&delete j.animateCallbacks.Gadget3DVideo,this.renderLoopHooked=!1)}}},it.addAvatar=function(t,e){this.avatars[e].push(t);var i=this.getStream(e);if(t.ccvContextKey||(t.ccvContextKey=t.options.ccvWidth+","+t.options.ccvHeight+","+JSON.stringify(t.options.ccvMargin)),!i.ccvContexts[t.ccvContextKey]){var a={width:t.options.ccvWidth,height:t.options.ccvHeight,margin:t.options.ccvMargin};a.videoImage=this.makeCanvas(a.width,a.height),a.videoImageContext=a.videoImage[0].getContext("2d"),a.videoImageContext.fillStyle="rgb(0,255,0)",a.videoImageContext.fillRect(0,0,a.width,a.height),a.videoTexture=new THREE.Texture(a.videoImage[0]),a.videoTexture.minFilter=THREE.LinearFilter,a.videoTexture.magFilter=THREE.LinearFilter,a.videoTexture.needsUpdate=!0,i.ccvContexts[t.ccvContextKey]=a}return i.streamReady},it.getVideoTexture=function(t){var e=this.streams[t];return e?e.videoTexture:null},it.getCCVVideoTexture=function(t,e){var i=this.streams[t];if(i){var a=i.ccvContexts[e];if(a)return a.videoTexture}return null},it.isStreamReady=function(t){return this.streams[t]&&this.streams[t].streamReady},it.isCCVLocked=function(t){return this.streams[t]&&this.streams[t].ccvLock},it.removeAvatar=function(t,e){var i=this.streams[e];if(i)for(var a=0;a<i.avatars.length;a++)if(t==i.avatars[a]){i.avatars.splice(a,1);break}},it.animate=function(){for(var t in this.streams){var e=this.streams[t];try{if(e.loopCount++,"1"===e.video[0].getAttribute("webrtc-attached")&&e.video[0].readyState===e.video[0].HAVE_ENOUGH_DATA){if(e.videoImageContext.drawImage(e.video[0],0,0,e.videoImage[0].width,e.videoImage[0].height),e.videoTexture&&(e.videoTexture.needsUpdate=!0,!e.streamReady)){e.streamReady=!0;for(var i=0;i<e.avatars.length;i++)e.avatars[i].streamReady(!0)}for(var a=!1,o=!1,i=0;i<e.avatars.length;i++)if(e.avatars[i].options.ccv&&(o=!0,e.local)){a=!0;break}if(a)if("undefined"==typeof ccv){if(!this.ccvLibRequested){console.error("No CCV path available"),this.ccvLibRequested=!0}}else e.ccvInProgress||this.ccvPoll(e);o&&this.ccvAnimate(e),j.animControl.trigger()}}catch(i){e.errorCount%1e6==0&&console.warn("Gadget3DVideo.animate error",e.errorCount,t,i),e.errorCount++}}},it.ccvLocked=function(t,e){for(var i=0;i<t.avatars.length;i++)t.avatars[i].ccvLocked(e)},it.ccvPoll=function(t){function e(){setTimeout(function(){t.ccvInProgress=!1},200)}t.ccvInProgress=!0;t.videoImage[0].width,t.videoImage[0].height,Date.now();t.ccvLastAnalyzed||(t.ccvLastAnalyzed=this.makeCanvas(t.videoImage[0].width,t.videoImage[0].height),t.ccvLastAnalyzedContext=t.ccvLastAnalyzed[0].getContext("2d")),t.ccvLastAnalyzedContext.drawImage(t.videoImage[0],0,0,t.videoImage[0].width,t.videoImage[0].height),function(i){if(0==i.length)t.ccvLock&&(t.ccvLock=null,it.ccvLocked(t,!1),_.sendCCVMessage({locked:!1}));else{var a=i[0],o=t.ccvLock;t.ccvLock={x:a.x,y:a.y,width:a.width,height:a.height},t.ccvLastSuccess&&t.ccvLastSuccess.videoImage.remove(),t.ccvLastSuccess=$.extend({videoImage:t.ccvLastAnalyzed,copied:!1},t.ccvLock),t.ccvLastAnalyzed=null,t.ccvLastAnalyzedContext=null,o||it.ccvLocked(t,!0),_.sendCCVMessage({locked:!0,x:a.x,y:a.y,width:a.width,height:a.height})}e()}(ccv.detect_objects({canvas:ccv.grayscale(t.videoImage[0]),cascade:cascade,interval:5,min_neighbors:1,async:!1,worker:1}))},it.makeCanvas=function(t,e){return $("<canvas/>").attr("width",t).attr("height",e).width(t).height(e).css({visibility:"hidden",position:"absolute","z-index":-1,top:0}).appendTo("body")},it.ccvAnimate=function(t){function e(t,e,i){var a=e.width*(1+t.margin[1]+t.margin[3]),o=e.height*(1+t.margin[0]+t.margin[2]),n=e.x-e.width*t.margin[3],s=e.y-e.height*t.margin[0];n<0&&(a+=n,n=0),s<0&&(o+=s,s=0),n+a>i.width&&(a=i.width-n),s+o>i.height&&(o=i.height-s),t.videoImageContext.drawImage(i,n,s,a,o,0,0,t.width,t.height),t.videoTexture.needsUpdate=!0}for(var i in t.ccvContexts){var a=t.ccvContexts[i];t.ccvLock?e(a,t.ccvLock,t.videoImage[0]):t.ccvLastSuccess&&!t.ccvLastSuccess.copied&&(t.ccvLastSuccess.copied=!0,e(a,t.ccvLastSuccess,t.ccvLastSuccess.videoImage[0]))}},it.receiveRemoteLock=function(t){for(var e in this.streams){var i=this.streams[e];if(!i.local){var a=i.ccvLock;if(t.locked){i.ccvLock={x:t.x,y:t.y,width:t.width,height:t.height},i.ccvLastSuccess&&i.ccvLastSuccess.videoImage.remove();var o=this.makeCanvas(i.videoImage[0].width,i.videoImage[0].height);o[0].getContext("2d").drawImage(i.videoImage[0],0,0,i.videoImage[0].width,i.videoImage[0].height),i.ccvLastSuccess=$.extend({videoImage:o,copied:!1},i.ccvLock),a||it.ccvLocked(i,!0)}else a&&(i.ccvLock=null,it.ccvLocked(i,!1))}}},$(document).bind("joclyhub.webrtc",d);var at=Q.extend({init:function(t,e){e=$.extend(!0,{scale:[1,1,1],makeMesh:function(t){var e=new THREE.MeshBasicMaterial({map:t,overdraw:!0}),i=new THREE.PlaneGeometry(this.options.width*this.SCALE3D,this.options.height*this.SCALE3D,1,1);return new THREE.Mesh(i,e)},width:12,height:9},e),this.videoPlayer=at.GetVideoPlayer(e.src),this._super.call(this,t,e)},createObject:function(){var t=this.options.makeMesh.call(this,this.videoPlayer.texture);t&&this.objectReady(t)},remove:function(){var t=ot[this.options.src];t&&0==--t.count&&(delete j.animateCallbacks["Gadget3DVideoFile."+this.options.src],t.tag.remove(),t.canvas.remove(),delete ot[this.options.src]),this._super.apply(this,arguments)}}),ot={};at.GetVideoPlayer=function(t){function e(){i.context.drawImage(i.tag[0],0,0,a,o),i.texture.needsUpdate=!0}var i=ot[t];if(i)i.count++;else{var a=638,o=360,n=$("<video/>").attr("autoplay","autoplay").attr("loop","loop").css({width:a,height:o,position:"absolute"}).append($("<source/>").attr("src",t).attr("type","video/webm")).appendTo("body");i={count:1,tag:n,canvas:it.makeCanvas(a,o)},i.context=i.canvas[0].getContext("2d"),i.context.fillStyle="rgb(0,255,0)",i.context.fillRect(0,0,a,o),i.texture=new THREE.Texture(i.canvas[0]),i.texture.minFilter=THREE.LinearFilter,i.texture.magFilter=THREE.LinearFilter,i.texture.needsUpdate=!0,j.animateCallbacks["Gadget3DVideoFile."+t]={_this:null,callback:e},ot[t]=i}return i};var nt=Z.extend({init:function(t,e){this._super.call(this,t,e),this.object3d=j.body,this.cameraObject=this.object3d.children[0],this.targetAnim=null,this.camTarget=j.camTarget},displayObject3D:function(t,e,i){var a=this;if(this.options.x=this.object3d.position.x/S,this.options.y=this.object3d.position.z/S,this.options.z=this.object3d.position.y/S,this._super.apply(this,arguments),t||e.targetX*S!=j.cameraControls.camTarget.x||e.targetY*S!=j.cameraControls.camTarget.z||e.targetZ*S!=j.cameraControls.camTarget.y)if(i){var o=e.traveling,n=j.cameraControls.camTarget.x,s=j.cameraControls.camTarget.y,r=j.cameraControls.camTarget.z;e.traveling=!1,this.targetAnim&&(this.targetAnim.stop(),this.animEnd(e)),this.animStart(e),this.targetAnim=new TWEEN.Tween(j.cameraControls.camTarget).to({x:e.targetX*S,y:e.targetZ*S,z:e.targetY*S},i).easing(e.targetEasing?e.targetEasing:TWEEN.Easing.Cubic.EaseInOut).onComplete(function(){a.targetAnim=null,a.animEnd(e)}).onUpdate(function(t){if(e.targetEasingUpdate&&e.targetEasingUpdate.call(a,t),o){j.cameraControls.camTarget.x,j.cameraControls.camTarget.y,j.cameraControls.camTarget.z;n=j.cameraControls.camTarget.x,s=j.cameraControls.camTarget.y,r=j.cameraControls.camTarget.z}a.cameraObject.lookAt(j.cameraControls.camTarget)}).start()}else j.cameraControls.camTarget.x=e.targetX*S,j.cameraControls.camTarget.y=e.targetZ*S,j.cameraControls.camTarget.z=e.targetY*S}}),st={image:U,element:B,canvas:F,hexagon:X,sprite:Y,disk:J,meshfile:et,custom3d:tt,plane3d:K,custommesh3d:Q,video3d:it,camera3d:nt,videofile3d:at},rt=null;View.Game.CamAnim={isSupported:function(){return!!j},isRunning:function(){return j&&j.camAnim},set:function(t){j&&j.setCamAnim(t)}},View.Game.InitView=function(){k=this.resources||{},this!=E.game&&(E.game=this,0==this.mWidget.find(".jocly-xdv-area").length&&(f=$("<div/>").css({position:"absolute","z-index":0,overflow:"hidden"}).addClass("jocly-xdv-area").appendTo(this.mWidget))),rt&&(rt.appendTo(f),rt=null),E.initDone||(this.xdInit(E),E.initDone=!0);var t=!1;if(!y||this.mSkin!=y.name){y=null;for(var i=0;i<this.mViewOptions.skins.length;i++){var a=this.mViewOptions.skins[i];if(a.name==this.mSkin){y=a;break}}if(null==y)return void e("!!! InitView","skin",this.mSkin,"not found");E.unbuildGadgets(),rt=null,y["3d"]&&(t=!0)}var o,n=Math.min(this.mGeometry.width,this.mGeometry.height*(this.mViewOptions.preferredRatio||1)),s=Math.min(this.mGeometry.width/(this.mViewOptions.preferredRatio||1),this.mGeometry.height);if(y["3d"]){if(f.css({left:0,top:0,width:this.mGeometry.width,height:this.mGeometry.height}),o={x:this.mGeometry.width/2,y:this.mGeometry.height/2},j?(j.renderer.setSize(this.mGeometry.width,this.mGeometry.height),j.anaglyphEffect.setSize(this.mGeometry.width,this.mGeometry.height),j.camera.aspect=this.mGeometry.width/this.mGeometry.height,j.camera.updateProjectionMatrix()):(THREE.Object3D._threexDomEvent||(THREE.Object3D._threexDomEvent=new THREEx.DomEvent),j=p(this,n,s),h(),j.camera.updateProjectionMatrix()),THREE.Object3D._threexDomEvent.setDOMElement(j.renderer.domElement),THREE.Object3D._threexDomEvent.setBoundContext(ct),THREE.Object3D._threexDomEvent.camera(j.camera),c(),j.animControl.trigger(),t){var r=$.extend(!0,{radius:12,elevationAngle:60,rotationAngle:90,distMax:20,distMin:0,elevationMax:89,elevationMin:10,startAngle:90,camAnim:!1,limitCamMoves:!0,enableDrag:!0,targetBounds:[3e3,3e3,3e3],target:[0,0,800],fov:55,near:.01},y.camera);j.camera.fov=r.fov,j.camera.near=r.near,j.camera.updateProjectionMatrix(),$.extend(j.cameraControls,{minDistance:r.distMin,maxDistance:r.distMax,minPolarAngle:(90-r.elevationMax)*Math.PI/180,maxPolarAngle:(90-r.elevationMin)*Math.PI/180,enableDrag:r.enableDrag,targetBounds:[r.targetBounds[0]*S,r.targetBounds[2]*S,r.targetBounds[1]*S]});var l={x:r.radius*Math.cos(r.elevationAngle*Math.PI/180)*Math.cos(r.rotationAngle*Math.PI/180),z:r.radius*Math.cos(r.elevationAngle*Math.PI/180)*Math.sin(r.rotationAngle*Math.PI/180),y:r.radius*Math.sin(r.elevationAngle*Math.PI/180)},d={x:r.target[0],y:r.target[1],z:r.target[2]};E.updateGadget("camera",{"3d":{x:l.x/S,y:l.z/S,z:l.y/S,targetX:d.x,targetY:d.y,targetZ:d.z}}),j.cameraControls.camTarget.copy(d),j.cameraControls.update();var u={color:2121084,fog:!0,fogNear:10,fogFar:100,lightCastShadow:!0,lightIntensity:1.75,lightPosition:{x:-12,y:12,z:12},ambientLightColor:12303291,skyLightPosition:{x:-45,y:45,z:45},skyLightIntensity:2};if($.extend(!0,u,y.world),j.scene.fog&&(j.scene.remove(j.scene.fog),delete j.scene.fog),u.fog){var m=u.color;u.fogColor&&(m=u.fogColor),j.scene.fog=new THREE.Fog(m,u.fogNear,u.fogFar)}j.world=u,j.renderer.setClearColor(new THREE.Color(u.color),1),j.light.castShadow=u.lightCastShadow,j.light.intensity=u.lightIntensity,j.light.position.set(u.lightPosition.x,u.lightPosition.y,u.lightPosition.z),j.ambientLight.color.setHex(u.ambientLightColor),j.skyLight.intensity=u.skyLightIntensity,j.skyLight.position.set(u.skyLightPosition.x,u.skyLightPosition.y,u.skyLightPosition.z)}j.renderer.domElement.style.display="block"}else f.css({left:(this.mGeometry.width-n)/2,top:(this.mGeometry.height-s)/2,width:n,height:s}),o={x:n/2,y:s/2},j&&(j.renderer.domElement.style.display="none");this.xdBuildScene(E),E.updateArea(Math.max(n,s)/w,o)},View.Game.DestroyView=function(){if(!E.game)return void e("!!! InitView","game already unset");M&&M.hide(),E.game=null,rt=f.children().detach(),j&&j.cameraControls.autoRotate&&(j.cameraControls.autoRotate=!1)},View.Game.CloseView=function(){E.unbuildGadgets(),j&&(THREE.Object3D._threexDomEvent.unsetBoundContext(ct),j.cameraControls.destroy(),j=null),l()},View.Game.xdResourceLoaded=function(t){return!/^map\|/.test(t)&&!(!C[t]||"loaded"!=C[t].status)},View.Game.xdLoadResources=function(t,e){function i(){0==--a&&e()}for(var a=0,o=0;o<t.length;o++){a++;var n=/^map\|(.*)$/.exec(t[o]);n?s(n[1],function(){setTimeout(i,0)}):r(t[o],function(){setTimeout(i,0)})}},View.Game.xdExternalCommand=function(t,e){switch(t.type){case"updateCamera":E.updateGadget("camera",{"3d":t.camera},t.delay||0);break;case"getCamera":var i={type:"camera",cameraId:t.cameraId};j?i.camera={x:j.camera.position.x/S,y:j.camera.position.z/S,z:j.camera.position.y/S,targetX:j.cameraControls.camTarget.x/S,targetY:j.cameraControls.camTarget.z/S,targetZ:j.cameraControls.camTarget.y/S}:(console.warn("cannot get camera without 3D context"),i.camera=null),e.sendEmbed(i);break;case"snapshot":var i={type:"snapshot",snapshotId:t.snapshotId};if(j){var a=j.renderer,o=a.domElement;a.render(j.scene,j.camera),i.image=o.toDataURL("image/png")}else console.warn("cannot get snapshot without 3D context"),i.image=null;e.sendEmbed(i)}},View.Game.ViewControl=function(t,e){return e=e||{},new Promise(function(i,a){switch(t){case"enterAnaglyph":if(j){j.anaglyph=!0;j.scene.scale.set(.4,.4,.4),j.camera.scale.set(2.5,2.5,2.5),j.animControl.trigger()}i();break;case"exitAnaglyph":j&&(j.anaglyph=!1,j.scene.scale.set(1,1,1),j.camera.scale.set(1,1,1),j.animControl.trigger()),i();break;case"stopAnimations":var o=0,n=[];TWEEN.getAll().forEach(function(t){o++,t!==j.dolly&&n.push(t)}),n.forEach(function(t){TWEEN.remove(t)}),i(o>0);break;case"setPanorama":e.pictureUrl||e.pictureData?(E.removeGadget("panorama"),E.createGadget("panorama",{"3d":{type:"custommesh3d",harbor:!1,rotate:e.rotate||0,create:function(t){var i=new THREE.SphereGeometry(500,60,40);i.scale(-1,1,1),new Promise(function(t,i){if(e.pictureData){var a=new Image;a.src=e.pictureData;var o=new THREE.Texture(a);a.onload=function(){o.needsUpdate=!0,t(o)}}else t((new THREE.TextureLoader).load(e.pictureUrl))}).then(function(e){var a=new THREE.MeshBasicMaterial({map:e});mesh=new THREE.Mesh(i,a),t(mesh)})}}}),E.updateGadget("panorama",{"3d":{visible:!0}})):(E.updateGadget("panorama",{"3d":{visible:!1}}),E.removeGadget("panorama")),i();break;case"takeSnapshot":if(j){var s=j.renderer.domElement;j.renderer.render(j.scene,j.camera),i(s.toDataURL("image/"+(e.format||"png"),e.quality||void 0))}else a(new Error("Snapshot only available on 3D views"));break;case"getCamera":j?i({x:j.body.position.x/S,y:j.body.position.z/S,z:j.body.position.y/S,targetX:j.cameraControls.camTarget.x/S,targetY:j.cameraControls.camTarget.z/S,targetZ:j.cameraControls.camTarget.y/S}):a(new Error("Camera only available on 3D views"));break;case"setCamera":if(!j)return a(new Error("Camera only available on 3D views"));switch(e.type){case"spin":i(u(e));break;case"stop":j.dolly&&(delete j.animateCallbacks.dolly,TWEEN.remove(j.dolly),delete j.dolly,j.animControl.stop(0));break;case"move":default:i(m(e))}break;default:a(new Error("ViewControl: unsupported command "+t))}})},View.Board.Display=function(t){this.xdDisplay(E,t)},View.Board.xdInput=function(t,e){return console.error("View.Board.xdInput must be overriden"),{initial:{},getActions:function(t,e){return{}}}},View.Board.xdBuildHTStateMachine=function(t,e,i){function a(t,i){"select"==i?e.smQueueEvent("E_ACTION",{action:t}):"cancel"==i&&e.smQueueEvent("E_CANCEL",{action:t})}function o(e){y=x.xdInput(t,i),b=[y.initial];var a={};x.mMoves.forEach(function(t){a[JSON.stringify(t)]=t});var o=[];for(var n in a)o.push(a[n]);E=[o],w=[]}function n(e){y.furnitures&&y.furnitures.forEach(function(e){t.updateGadget(e,{base:{visible:!0}})})}function s(e){y.furnitures&&y.furnitures.forEach(function(e){t.updateGadget(e,{base:{visible:!1}})})}function r(e,i){"select"==i&&(e.pre&&e.pre.call(x),e.cancel&&e.cancel.forEach(function(i){T[i]=!0,t.updateGadget(i,{base:{click:function(){a(e,"cancel")}}})})),e.click&&e.click.forEach(function(o){T[o]=!0,t.updateGadget(o,{base:{click:function(){a(e,i)}}})}),"function"==typeof e.highlight&&("function"!=typeof e.unhighlight?console.warn("No unhighlight function defined for",e):j.push(function(){e.unhighlight.call(x,i)}),e.highlight.call(x,i)),e.view&&e.view.forEach(function(e){C[e]=!0,t.updateGadget(e,{base:{visible:!0}})})}function c(t){var a=y.getActions.call(x,E[E.length-1],b[b.length-1]);if(null==a)return void e.smQueueEvent("E_MOVE_DONE",{move:E[E.length-1][0]});var o,n=0;for(var s in a)o=a[s],n++;if(n>1||1==b.length&&!y.allowForced||1==n&&!i.mAutoComplete&&!o.skipable)for(var c in a){var s=a[c];s.forced=!1,r(s,"select")}else 0==n?e.smQueueEvent("E_MOVE_DONE",{move:w[w.length-1].moves[0]}):(o.forced=!0,e.smQueueEvent("E_ACTION",{action:o}))}function l(t){i.HumanMove(t.move)}function d(e){for(var i in T)t.updateGadget(i,{base:{click:null}});T={};for(var i in C)t.updateGadget(i,{base:{visible:!1}});C={};for(var a=0;a<j.length;a++)j[a].call(x)}function h(t,e){function i(t){0==--o&&e()}if(t.execute){var a=t.execute;"function"==typeof a&&(a=[a]);var o=0;a.forEach(function(t){o++,setTimeout(function(){t.call(x,i)},0)})}else e()}function u(t){E.push(t.action.moves),h(t.action,function(){e.smQueueEvent("E_DONE",{action:t.action})})}function m(t){t.action.post&&t.action.post.call(x)}function p(t){w.length>0&&!w[w.length-1].noAutoCancel&&r(w[w.length-1],"cancel")}function g(t){b.push($.extend(!0,{},b[b.length-1],t.action.validate))}function v(t){for(;w.length>0;){var e=w.pop();if(b.pop(),E.pop(),e.unexecute&&e.unexecute.call(x),e.post&&e.post.call(x),0==e.forced)break}}function f(t){w.push(t.action)}var y,b,E,w,x=this,T={},C={},j=[];e.smTransition("S_INIT","E_INIT","S_WAIT_ACTION",[o,n]),e.smEntering("S_WAIT_ACTION",[c,p]),e.smLeaving("S_WAIT_ACTION",[d]),e.smTransition("S_WAIT_ACTION","E_ACTION","S_ACTION",[f,g,u]),e.smTransition("S_WAIT_ACTION","E_CANCEL",null,[v,d,c,p]),e.smTransition("S_WAIT_ACTION","E_MOVE_DONE","S_DONE",[l,s]),e.smTransition(["S_WAIT_ACTION","S_ACTION"],"E_END","S_DONE",[]),e.smTransition("S_ACTION","E_DONE","S_WAIT_ACTION",[m]),e.smTransition("S_DONE","E_END",null,[s])},View.Board.HumanTurn=function(t){T=new i,T.init(),this.xdBuildHTStateMachine(E,T,t),T.smSetInitialState("S_INIT"),T.smQueueEvent("E_INIT",{}),T.smPlay()},View.Board.HumanTurnEnd=function(t){T&&(T.smQueueEvent("E_END",{}),T=null)},View.Board.PlayedMove=function(t,e){return this.xdPlayedMove(E,t,e)},View.Board.xdShowEnd=function(t,e){return!0},View.Board.ShowEnd=function(t){return this.xdShowEnd(E,t)};var ct=""+Math.random()}();