// ThreeExtras.js r37 - http://github.com/mrdoob/three.js var GeometryUtils={merge:function(a,e){var b=e instanceof THREE.Mesh,c=a.vertices.length,d=b?e.geometry:e,f=a.vertices,g=d.vertices,h=a.faces,l=d.faces,k=a.faceVertexUvs[0];d=d.faceVertexUvs[0];b&&e.matrixAutoUpdate&&e.updateMatrix();for(var j=0,m=g.length;j= 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&&(f=25);d=(f-1)*0.5;b=Array(f);for(e=c=0;ethis.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",e(this,this.onMouseMove),!1);this.domElement.addEventListener("mousedown",e(this,this.onMouseDown),!1);this.domElement.addEventListener("mouseup",e(this,this.onMouseUp),!1);this.domElement.addEventListener("keydown",e(this,this.onKeyDown),!1);this.domElement.addEventListener("keyup",e(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,e){this.matrix.rotateAxis(e);if(this.noFly)e.y=0;this.position.addSelf(e.multiplyScalar(a));this.target.position.addSelf(e.multiplyScalar(a))}; THREE.PathCamera=function(a){function e(k,j,m,p){var w={name:m,fps:0.6,length:p,hierarchy:[]},t,z=j.getControlPointsArray(),y=j.getLength(),A=z.length,C=0;t=A-1;j={parent:-1,keys:[]};j.keys[0]={time:0,pos:z[0],rot:[0,0,0,1],scl:[1,1,1]};j.keys[t]={time:p,pos:z[t],rot:[0,0,0,1],scl:[1,1,1]};for(t=1;t=0?p:p+d;p=this.verticalAngleMap.srcRange;w=this.verticalAngleMap.dstRange; this.phi=(this.phi-p[0])*(w[1]-w[0])/(p[1]-p[0])+w[0];p=this.horizontalAngleMap.srcRange;w=this.horizontalAngleMap.dstRange;this.theta=(this.theta-p[0])*(w[1]-w[0])/(p[1]-p[0])+w[0];p=this.target.position;p.x=100*Math.sin(this.phi)*Math.cos(this.theta);p.y=100*Math.cos(this.phi);p.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this,k,j,m)};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 g=new THREE.MeshLambertMaterial({color:65280}),h=new Cube(10,10,20),l=new Cube(2,2,10);this.animationParent=new THREE.Mesh(h,a);a=new THREE.Mesh(l,g);a.position.set(0,10,0);this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(a)}else{this.animation= e(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,j){return function(){j.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,e,b,c,d,f,g,h,l){function k(y,A,C,n,E,D,L,M){var K,J,G=c||1,N=d||1,U=E/2,R=D/2,P=j.vertices.length;if(y=="x"&&A=="y"||y=="y"&&A=="x")K="z";else if(y=="x"&&A=="z"||y=="z"&&A=="x"){K="y";N=f||1}else if(y=="z"&&A=="y"||y=="y"&&A=="z"){K="x";G=f||1}var Q=G+1,T=N+1;E/=G;var H=D/N;for(J=0;J0){g(0,0,-k-(f||0));for(c=a;c0){g(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 e(m,p,w){var t=Math.sqrt(m*m+p*p+w*w);return d.vertices.push(new THREE.Vertex(new THREE.Vector3(m/t,p/t,w/t)))-1}function b(m,p,w,t){t.faces.push(new THREE.Face3(m,p,w))}function c(m,p){var w=d.vertices[m].position,t=d.vertices[p].position;return e((w.x+t.x)/2,(w.y+t.y)/2,(w.z+t.z)/2)}var d=this,f=new THREE.Geometry,g;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;e(-1,a,0);e(1,a,0);e(-1,-a,0);e(1,-a,0);e(0,-1,a);e(0,1,a);e(0,-1,-a);e(0, 1,-a);e(a,0,-1);e(a,0,1);e(-a,0,-1);e(-a,0,1);b(0,11,5,f);b(0,5,1,f);b(0,1,7,f);b(0,7,10,f);b(0,10,11,f);b(1,5,9,f);b(5,11,4,f);b(11,10,2,f);b(10,7,6,f);b(7,1,8,f);b(3,9,4,f);b(3,4,2,f);b(3,2,6,f);b(3,6,8,f);b(3,8,9,f);b(4,9,5,f);b(2,4,11,f);b(6,2,10,f);b(8,6,7,f);b(9,8,1,f);for(a=0;a0||(j=this.vertices.push(new THREE.Vertex(new THREE.Vector3(m,h,p)))-1);k.push(j)}e.push(k)}var w,t,z;d=e.length;for(b=0;b0)for(c=0;c1){w=this.vertices[g].position.clone(); t=this.vertices[l].position.clone();z=this.vertices[k].position.clone();w.normalize();t.normalize();z.normalize();this.faces.push(new THREE.Face3(g,l,k,[new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(t.x,t.y,t.z),new THREE.Vector3(z.x,z.y,z.z)]));this.faceVertexUvs[0].push([j,m,y])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere; var Torus=function(a,e,b,c){this.radius=a||100;this.tube=e||40;this.segmentsR=b||8;this.segmentsT=c||6;a=[];THREE.Geometry.call(this);for(e=0;e<=this.segmentsR;++e)for(b=0;b<=this.segmentsT;++b){c=b/this.segmentsT*2*Math.PI;var d=e/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-e/this.segmentsR])}for(e=1;e<=this.segmentsR;++e)for(b= 1;b<=this.segmentsT;++b){c=(this.segmentsT+1)*e+b;d=(this.segmentsT+1)*e+b-1;var f=(this.segmentsT+1)*(e-1)+b-1,g=(this.segmentsT+1)*(e-1)+b;this.faces.push(new THREE.Face4(c,d,f,g));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[f][0],a[f][1]),new THREE.UV(a[g][0],a[g][1])])}delete a;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};Torus.prototype=new THREE.Geometry;Torus.prototype.constructor=Torus; var TorusKnot=function(a,e,b,c,d,f,g){function h(m,p,w,t,z,y){p=w/t*m;w=Math.cos(p);return new THREE.Vector3(z*(2+w)*0.5*Math.cos(m),z*(2+w)*Math.sin(m)*0.5,y*z*Math.sin(p)*0.5)}THREE.Geometry.call(this);this.radius=a||200;this.tube=e||40;this.segmentsR=b||64;this.segmentsT=c||8;this.p=d||2;this.q=f||3;this.heightScale=g||1;this.grid=Array(this.segmentsR);b=new THREE.Vector3;c=new THREE.Vector3;f=new THREE.Vector3;for(a=0;a>7)-127;B|=(I&127)<<16|F<<8;if(B==0&&V==-127)return 0;return(1-2*(S>>7))*(1+B*Math.pow(2,-23))*Math.pow(2,V)}function h(o,x){var B=j(o,x),F=j(o,x+1),I=j(o,x+2);return(j(o,x+3)<<24)+(I<<16)+(F<<8)+B}function l(o,x){var B=j(o,x);return(j(o,x+1)<<8)+B}function k(o,x){var B=j(o,x);return B>127?B-256:B}function j(o, x){return o.charCodeAt(x)&255}function m(o){var x,B,F;x=h(a,o);B=h(a,o+L);F=h(a,o+M);o=l(a,o+K);THREE.BinaryLoader.prototype.f3(A,x,B,F,o)}function p(o){var x,B,F,I,S,V;x=h(a,o);B=h(a,o+L);F=h(a,o+M);I=l(a,o+K);S=h(a,o+J);V=h(a,o+G);o=h(a,o+N);THREE.BinaryLoader.prototype.f3n(A,E,x,B,F,I,S,V,o)}function w(o){var x,B,F,I;x=h(a,o);B=h(a,o+U);F=h(a,o+R);I=h(a,o+P);o=l(a,o+Q);THREE.BinaryLoader.prototype.f4(A,x,B,F,I,o)}function t(o){var x,B,F,I,S,V,da,ea;x=h(a,o);B=h(a,o+U);F=h(a,o+R);I=h(a,o+P);S=l(a, o+Q);V=h(a,o+T);da=h(a,o+H);ea=h(a,o+O);o=h(a,o+X);THREE.BinaryLoader.prototype.f4n(A,E,x,B,F,I,S,V,da,ea,o)}function z(o){var x,B;x=h(a,o);B=h(a,o+Y);o=h(a,o+fa);THREE.BinaryLoader.prototype.uv3(A.faceVertexUvs[0],D[x*2],D[x*2+1],D[B*2],D[B*2+1],D[o*2],D[o*2+1])}function y(o){var x,B,F;x=h(a,o);B=h(a,o+ga);F=h(a,o+ha);o=h(a,o+ia);THREE.BinaryLoader.prototype.uv4(A.faceVertexUvs[0],D[x*2],D[x*2+1],D[B*2],D[B*2+1],D[F*2],D[F*2+1],D[o*2],D[o*2+1])}var A=this,C=0,n,E=[],D=[],L,M,K,J,G,N,U,R,P,Q,T,H, O,X,Y,fa,ga,ha,ia,Z,$,aa,ba,ca,W;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(A,c,f);n={signature:a.substr(C,8),header_bytes:j(a,C+8),vertex_coordinate_bytes:j(a,C+9),normal_coordinate_bytes:j(a,C+10),uv_coordinate_bytes:j(a,C+11),vertex_index_bytes:j(a,C+12),normal_index_bytes:j(a,C+13),uv_index_bytes:j(a,C+14),material_index_bytes:j(a,C+15),nvertices:h(a,C+16),nnormals:h(a,C+16+4),nuvs:h(a,C+16+8),ntri_flat:h(a,C+16+12),ntri_smooth:h(a,C+16+16),ntri_flat_uv:h(a,C+16+20),ntri_smooth_uv:h(a, C+16+24),nquad_flat:h(a,C+16+28),nquad_smooth:h(a,C+16+32),nquad_flat_uv:h(a,C+16+36),nquad_smooth_uv:h(a,C+16+40)};C+=n.header_bytes;L=n.vertex_index_bytes;M=n.vertex_index_bytes*2;K=n.vertex_index_bytes*3;J=n.vertex_index_bytes*3+n.material_index_bytes;G=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes;N=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*2;U=n.vertex_index_bytes;R=n.vertex_index_bytes*2;P=n.vertex_index_bytes*3;Q=n.vertex_index_bytes*4;T=n.vertex_index_bytes* 4+n.material_index_bytes;H=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes;O=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*2;X=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*3;Y=n.uv_index_bytes;fa=n.uv_index_bytes*2;ga=n.uv_index_bytes;ha=n.uv_index_bytes*2;ia=n.uv_index_bytes*3;f=n.vertex_index_bytes*3+n.material_index_bytes;W=n.vertex_index_bytes*4+n.material_index_bytes;Z=n.ntri_flat*f;$=n.ntri_smooth*(f+n.normal_index_bytes*3);aa=n.ntri_flat_uv* (f+n.uv_index_bytes*3);ba=n.ntri_smooth_uv*(f+n.normal_index_bytes*3+n.uv_index_bytes*3);ca=n.nquad_flat*W;f=n.nquad_smooth*(W+n.normal_index_bytes*4);W=n.nquad_flat_uv*(W+n.uv_index_bytes*4);C+=function(o){for(var x,B,F,I=n.vertex_coordinate_bytes*3,S=o+n.nvertices*I;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&&(l=this.size-1);var p=Math.floor(k-h);p<1&&(p=1);k=Math.floor(k+h);k>this.size-1&&(k=this.size-1);var w=Math.floor(j-h);w<1&&(w=1);h=Math.floor(j+h); h>this.size-1&&(h=this.size-1);for(var t,z,y,A,C,n;m0&&(this.field[y+t]+=A)}}}};this.addPlaneX=function(b,c){var d,f,g,h,l,k=this.size,j=this.yd,m=this.zd,p=this.field,w=k*Math.sqrt(b/c);w>k&&(w=k);for(d=0;d0)for(f=0;fj&&(t=j);for(f=0;f0){l=f*m;for(d=0;dsize&&(dist=size);for(g=0;g0){l=zd*g;for(f=0;f