// ThreeExtras.js r37 - http://github.com/mrdoob/three.js
var GeometryUtils={merge:function(a,g){var b=g instanceof THREE.Mesh,c=a.vertices.length,d=b?g.geometry:g,e=a.vertices,f=d.vertices,h=a.faces,j=d.faces,k=a.faceVertexUvs[0];d=d.faceVertexUvs[0];b&&g.matrixAutoUpdate&&g.updateMatrix();for(var l=0,p=f.length;l
= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );\ntotalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );\ntotalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );\ngl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );\n}",
vertexShader:"attribute vec4 tangent;\nuniform vec3 uPointLightPos;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"},
cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"},convolution:{uniforms:{tDiffuse:{type:"t",
value:0,texture:null},uImageIncrement:{type:"v2",value:new THREE.Vector2(0.001953125,0)},cKernel:{type:"fv1",value:[]}},vertexShader:"varying vec2 vUv;\nuniform vec2 uImageIncrement;\nvoid main(void) {\nvUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform vec2 uImageIncrement;\nuniform float cKernel[KERNEL_SIZE];\nvoid main(void) {\nvec2 imageCoord = vUv;\nvec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );\nfor( int i=0; i25&&(e=25);d=(e-1)*0.5;b=Array(e);for(g=c=0;gthis.heightMax?this.heightMax:this.position.y)-this.heightMin)*this.heightCoef:0;(this.moveForward||this.autoForward)&&this.translateZ(-(this.movementSpeed+this.autoSpeedFactor));this.moveBackward&&this.translateZ(this.movementSpeed);this.moveLeft&&this.translateX(-this.movementSpeed);this.moveRight&&this.translateX(this.movementSpeed);
var b=this.lookSpeed;this.dragToLook&&!this.mouseDragOn&&(b=0);this.lon+=this.mouseX*b;this.lookVertical&&(this.lat-=this.mouseY*b);this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;b=this.target.position;var c=this.position;b.x=c.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=c.y+100*Math.cos(this.phi);b.z=c.z+100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this)};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},
!1);this.domElement.addEventListener("mousemove",g(this,this.onMouseMove),!1);this.domElement.addEventListener("mousedown",g(this,this.onMouseDown),!1);this.domElement.addEventListener("mouseup",g(this,this.onMouseUp),!1);this.domElement.addEventListener("keydown",g(this,this.onKeyDown),!1);this.domElement.addEventListener("keyup",g(this,this.onKeyUp),!1)};THREE.QuakeCamera.prototype=new THREE.Camera;THREE.QuakeCamera.prototype.constructor=THREE.QuakeCamera;THREE.QuakeCamera.prototype.supr=THREE.Camera.prototype;
THREE.QuakeCamera.prototype.translate=function(a,g){this.matrix.rotateAxis(g);if(this.noFly)g.y=0;this.position.addSelf(g.multiplyScalar(a));this.target.position.addSelf(g.multiplyScalar(a))};
THREE.PathCamera=function(a){function g(k,l,p,q){var m={name:p,fps:0.6,length:q,hierarchy:[]},t,y=l.getControlPointsArray(),C=l.getLength(),x=y.length,z=0;t=x-1;l={parent:-1,keys:[]};l.keys[0]={time:0,pos:y[0],rot:[0,0,0,1],scl:[1,1,1]};l.keys[t]={time:q,pos:y[t],rot:[0,0,0,1],scl:[1,1,1]};for(t=1;t=0?q:q+d;q=this.verticalAngleMap.srcRange;m=this.verticalAngleMap.dstRange;
this.phi=(this.phi-q[0])*(m[1]-m[0])/(q[1]-q[0])+m[0];q=this.horizontalAngleMap.srcRange;m=this.horizontalAngleMap.dstRange;this.theta=(this.theta-q[0])*(m[1]-m[0])/(q[1]-q[0])+m[0];q=this.target.position;q.x=100*Math.sin(this.phi)*Math.cos(this.theta);q.y=100*Math.cos(this.phi);q.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this,k,l,p)};this.onMouseMove=function(k){this.mouseX=k.clientX-this.windowHalfX;this.mouseY=k.clientY-this.windowHalfY};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);
this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){a=new THREE.MeshLambertMaterial({color:30719});var f=new THREE.MeshLambertMaterial({color:65280}),h=new Cube(10,10,20),j=new Cube(2,2,10);this.animationParent=new THREE.Mesh(h,a);a=new THREE.Mesh(j,f);a.position.set(0,10,0);this.animation=g(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(a)}else{this.animation=
g(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this.target);this.animationParent.addChild(this)}this.createDebugPath&&c(this.debugPath,this.spline);this.domElement.addEventListener("mousemove",function(k,l){return function(){l.apply(k,arguments)}}(this,this.onMouseMove),!1)};THREE.PathCamera.prototype=new THREE.Camera;THREE.PathCamera.prototype.constructor=THREE.PathCamera;THREE.PathCamera.prototype.supr=THREE.Camera.prototype;THREE.PathCameraIdCounter=0;
var Cube=function(a,g,b,c,d,e,f,h,j){function k(C,x,z,n,H,D,M,F){var J,I,K=c||1,L=d||1,P=H/2,Q=D/2,E=l.vertices.length;if(C=="x"&&x=="y"||C=="y"&&x=="x")J="z";else if(C=="x"&&x=="z"||C=="z"&&x=="x"){J="y";L=e||1}else if(C=="z"&&x=="y"||C=="y"&&x=="z"){J="x";K=e||1}var O=K+1,U=L+1;H/=K;var $=D/L;for(I=0;I0){f(0,0,-k-(e||0));for(c=a;c0){f(0,0,k+(d||0));
for(c=a+a/2;c<2*a;c++)h.faces.push(new THREE.Face4(2*a+1,(2*c-2*a+2)%a+a,(2*c-2*a+1)%a+a,(2*c-2*a)%a+a))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
var Icosahedron=function(a){function g(p,q,m){var t=Math.sqrt(p*p+q*q+m*m);return d.vertices.push(new THREE.Vertex(new THREE.Vector3(p/t,q/t,m/t)))-1}function b(p,q,m,t){t.faces.push(new THREE.Face3(p,q,m))}function c(p,q){var m=d.vertices[p].position,t=d.vertices[q].position;return g((m.x+t.x)/2,(m.y+t.y)/2,(m.z+t.z)/2)}var d=this,e=new THREE.Geometry,f;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;g(-1,a,0);g(1,a,0);g(-1,-a,0);g(1,-a,0);g(0,-1,a);g(0,1,a);g(0,-1,-a);g(0,
1,-a);g(a,0,-1);g(a,0,1);g(-a,0,-1);g(-a,0,1);b(0,11,5,e);b(0,5,1,e);b(0,1,7,e);b(0,7,10,e);b(0,10,11,e);b(1,5,9,e);b(5,11,4,e);b(11,10,2,e);b(10,7,6,e);b(7,1,8,e);b(3,9,4,e);b(3,4,2,e);b(3,2,6,e);b(3,6,8,e);b(3,8,9,e);b(4,9,5,e);b(2,4,11,e);b(6,2,10,e);b(8,6,7,e);b(9,8,1,e);for(a=0;a0||(l=this.vertices.push(new THREE.Vertex(new THREE.Vector3(p,h,q)))-1);k.push(l)}g.push(k)}var m,t,y;d=g.length;for(b=0;b0)for(c=0;c1){m=this.vertices[f].position.clone();
t=this.vertices[j].position.clone();y=this.vertices[k].position.clone();m.normalize();t.normalize();y.normalize();this.faces.push(new THREE.Face3(f,j,k,[new THREE.Vector3(m.x,m.y,m.z),new THREE.Vector3(t.x,t.y,t.z),new THREE.Vector3(y.x,y.y,y.z)]));this.faceVertexUvs[0].push([l,p,C])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
var Torus=function(a,g,b,c){this.radius=a||100;this.tube=g||40;this.segmentsR=b||8;this.segmentsT=c||6;a=[];THREE.Geometry.call(this);for(g=0;g<=this.segmentsR;++g)for(b=0;b<=this.segmentsT;++b){c=b/this.segmentsT*2*Math.PI;var d=g/this.segmentsR*2*Math.PI;this.vertices.push(new THREE.Vertex(new THREE.Vector3((this.radius+this.tube*Math.cos(d))*Math.cos(c),(this.radius+this.tube*Math.cos(d))*Math.sin(c),this.tube*Math.sin(d))));a.push([b/this.segmentsT,1-g/this.segmentsR])}for(g=1;g<=this.segmentsR;++g)for(b=
1;b<=this.segmentsT;++b){c=(this.segmentsT+1)*g+b;d=(this.segmentsT+1)*g+b-1;var e=(this.segmentsT+1)*(g-1)+b-1,f=(this.segmentsT+1)*(g-1)+b;this.faces.push(new THREE.Face4(c,d,e,f));this.faceVertexUvs[0].push([new THREE.UV(a[c][0],a[c][1]),new THREE.UV(a[d][0],a[d][1]),new THREE.UV(a[e][0],a[e][1]),new THREE.UV(a[f][0],a[f][1])])}delete a;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};Torus.prototype=new THREE.Geometry;Torus.prototype.constructor=Torus;
var TorusKnot=function(a,g,b,c,d,e,f){function h(p,q,m,t,y,C){q=m/t*p;m=Math.cos(q);return new THREE.Vector3(y*(2+m)*0.5*Math.cos(p),y*(2+m)*Math.sin(p)*0.5,C*y*Math.sin(q)*0.5)}THREE.Geometry.call(this);this.radius=a||200;this.tube=g||40;this.segmentsR=b||64;this.segmentsT=c||8;this.p=d||2;this.q=e||3;this.heightScale=f||1;this.grid=Array(this.segmentsR);b=new THREE.Vector3;c=new THREE.Vector3;e=new THREE.Vector3;for(a=0;a>7)-127;A|=(G&127)<<16|B<<8;if(A==0&&R==-127)return 0;return(1-2*(N>>7))*(1+A*Math.pow(2,-23))*Math.pow(2,R)}function h(o,w){var A=l(o,w),B=l(o,w+1),G=l(o,w+2);return(l(o,w+3)<<24)+(G<<16)+(B<<8)+A}function j(o,w){var A=l(o,w);return(l(o,w+1)<<8)+A}function k(o,w){var A=l(o,w);return A>127?A-256:A}function l(o,
w){return o.charCodeAt(w)&255}function p(o){var w,A,B;w=h(a,o);A=h(a,o+M);B=h(a,o+F);o=j(a,o+J);THREE.BinaryLoader.prototype.f3(x,w,A,B,o)}function q(o){var w,A,B,G,N,R;w=h(a,o);A=h(a,o+M);B=h(a,o+F);G=j(a,o+J);N=h(a,o+I);R=h(a,o+K);o=h(a,o+L);THREE.BinaryLoader.prototype.f3n(x,H,w,A,B,G,N,R,o)}function m(o){var w,A,B,G;w=h(a,o);A=h(a,o+P);B=h(a,o+Q);G=h(a,o+E);o=j(a,o+O);THREE.BinaryLoader.prototype.f4(x,w,A,B,G,o)}function t(o){var w,A,B,G,N,R,aa,ba;w=h(a,o);A=h(a,o+P);B=h(a,o+Q);G=h(a,o+E);N=j(a,
o+O);R=h(a,o+U);aa=h(a,o+$);ba=h(a,o+T);o=h(a,o+ca);THREE.BinaryLoader.prototype.f4n(x,H,w,A,B,G,N,R,aa,ba,o)}function y(o){var w,A;w=h(a,o);A=h(a,o+da);o=h(a,o+ea);THREE.BinaryLoader.prototype.uv3(x.faceVertexUvs[0],D[w*2],D[w*2+1],D[A*2],D[A*2+1],D[o*2],D[o*2+1])}function C(o){var w,A,B;w=h(a,o);A=h(a,o+fa);B=h(a,o+ga);o=h(a,o+ha);THREE.BinaryLoader.prototype.uv4(x.faceVertexUvs[0],D[w*2],D[w*2+1],D[A*2],D[A*2+1],D[B*2],D[B*2+1],D[o*2],D[o*2+1])}var x=this,z=0,n,H=[],D=[],M,F,J,I,K,L,P,Q,E,O,U,
$,T,ca,da,ea,fa,ga,ha,V,W,X,Y,Z,S;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(x,c,e);n={signature:a.substr(z,8),header_bytes:l(a,z+8),vertex_coordinate_bytes:l(a,z+9),normal_coordinate_bytes:l(a,z+10),uv_coordinate_bytes:l(a,z+11),vertex_index_bytes:l(a,z+12),normal_index_bytes:l(a,z+13),uv_index_bytes:l(a,z+14),material_index_bytes:l(a,z+15),nvertices:h(a,z+16),nnormals:h(a,z+16+4),nuvs:h(a,z+16+8),ntri_flat:h(a,z+16+12),ntri_smooth:h(a,z+16+16),ntri_flat_uv:h(a,z+16+20),ntri_smooth_uv:h(a,
z+16+24),nquad_flat:h(a,z+16+28),nquad_smooth:h(a,z+16+32),nquad_flat_uv:h(a,z+16+36),nquad_smooth_uv:h(a,z+16+40)};z+=n.header_bytes;M=n.vertex_index_bytes;F=n.vertex_index_bytes*2;J=n.vertex_index_bytes*3;I=n.vertex_index_bytes*3+n.material_index_bytes;K=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes;L=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*2;P=n.vertex_index_bytes;Q=n.vertex_index_bytes*2;E=n.vertex_index_bytes*3;O=n.vertex_index_bytes*4;U=n.vertex_index_bytes*
4+n.material_index_bytes;$=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes;T=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*2;ca=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*3;da=n.uv_index_bytes;ea=n.uv_index_bytes*2;fa=n.uv_index_bytes;ga=n.uv_index_bytes*2;ha=n.uv_index_bytes*3;e=n.vertex_index_bytes*3+n.material_index_bytes;S=n.vertex_index_bytes*4+n.material_index_bytes;V=n.ntri_flat*e;W=n.ntri_smooth*(e+n.normal_index_bytes*3);X=n.ntri_flat_uv*
(e+n.uv_index_bytes*3);Y=n.ntri_smooth_uv*(e+n.normal_index_bytes*3+n.uv_index_bytes*3);Z=n.nquad_flat*S;e=n.nquad_smooth*(S+n.normal_index_bytes*4);S=n.nquad_flat_uv*(S+n.uv_index_bytes*4);z+=function(o){for(var w,A,B,G=n.vertex_coordinate_bytes*3,N=o+n.nvertices*G;o=this.maxCount-3&&h(this)};this.begin=
function(){this.count=0;this.hasPos=!1;this.hasNormal=!1};this.end=function(b){if(this.count!=0){for(var c=this.count*3;cthis.size-1&&(j=this.size-1);var q=Math.floor(k-h);q<1&&(q=1);k=Math.floor(k+h);k>this.size-1&&(k=this.size-1);var m=Math.floor(l-h);m<1&&(m=1);h=Math.floor(l+h);
h>this.size-1&&(h=this.size-1);for(var t,y,C,x,z,n;p0&&(this.field[C+t]+=x)}}}};this.addPlaneX=function(b,c){var d,e,f,h,j,k=this.size,l=this.yd,p=this.zd,q=this.field,m=k*Math.sqrt(b/c);m>k&&(m=k);for(d=0;d0)for(e=0;el&&(t=l);for(e=0;e0){j=e*p;for(d=0;dsize&&(dist=size);for(f=0;f0){j=zd*f;for(e=0;e