// 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,g=b?e.geometry:e,f=a.vertices,d=g.vertices,h=a.faces,j=g.faces,l=a.faceVertexUvs[0];g=g.faceVertexUvs[0];b&&e.matrixAutoUpdate&&e.updateMatrix();for(var k=0,o=d.length;k= 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);g=(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(l,k,o,q){var m={name:o,fps:0.6,length:q,hierarchy:[]},t,A=k.getControlPointsArray(),z=k.getLength(),x=A.length,y=0;t=x-1;k={parent:-1,keys:[]};k.keys[0]={time:0,pos:A[0],rot:[0,0,0,1],scl:[1,1,1]};k.keys[t]={time:q,pos:A[t],rot:[0,0,0,1],scl:[1,1,1]};for(t=1;t=0?q:q+g;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,l,k,o)};this.onMouseMove=function(l){this.mouseX=l.clientX-this.windowHalfX;this.mouseY=l.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 d=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,d);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(l,k){return function(){k.apply(l,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,g,f,d,h,j){function l(z,x,y,n,H,D,M,F){var J,I,K=c||1,L=g||1,P=H/2,Q=D/2,E=k.vertices.length;if(z=="x"&&x=="y"||z=="y"&&x=="x")J="z";else if(z=="x"&&x=="z"||z=="z"&&x=="x"){J="y";L=f||1}else if(z=="z"&&x=="y"||z=="y"&&x=="z"){J="x";K=f||1}var O=K+1,U=L+1;H/=K;var $=D/L;for(I=0;I0){d(0,0,-l-(f||0));for(c=a;c0){d(0,0,l+(g||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(o,q,m){var t=Math.sqrt(o*o+q*q+m*m);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(o/t,q/t,m/t)))-1}function b(o,q,m,t){t.faces.push(new THREE.Face3(o,q,m))}function c(o,q){var m=g.vertices[o].position,t=g.vertices[q].position;return e((m.x+t.x)/2,(m.y+t.y)/2,(m.z+t.z)/2)}var g=this,f=new THREE.Geometry,d;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||(k=this.vertices.push(new THREE.Vertex(new THREE.Vector3(o,h,q)))-1);l.push(k)}e.push(l)}var m,t,A;g=e.length;for(b=0;b0)for(c=0;c1){m=this.vertices[d].position.clone(); t=this.vertices[j].position.clone();A=this.vertices[l].position.clone();m.normalize();t.normalize();A.normalize();this.faces.push(new THREE.Face3(d,j,l,[new THREE.Vector3(m.x,m.y,m.z),new THREE.Vector3(t.x,t.y,t.z),new THREE.Vector3(A.x,A.y,A.z)]));this.faceVertexUvs[0].push([k,o,z])}}}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 g=e/this.segmentsR*2*Math.PI;this.vertices.push(new THREE.Vertex(new THREE.Vector3((this.radius+this.tube*Math.cos(g))*Math.cos(c),(this.radius+this.tube*Math.cos(g))*Math.sin(c),this.tube*Math.sin(g))));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;g=(this.segmentsT+1)*e+b-1;var f=(this.segmentsT+1)*(e-1)+b-1,d=(this.segmentsT+1)*(e-1)+b;this.faces.push(new THREE.Face4(c,g,f,d));this.faceVertexUvs[0].push([new THREE.UV(a[c][0],a[c][1]),new THREE.UV(a[g][0],a[g][1]),new THREE.UV(a[f][0],a[f][1]),new THREE.UV(a[d][0],a[d][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,g,f,d){function h(o,q,m,t,A,z){q=m/t*o;m=Math.cos(q);return new THREE.Vector3(A*(2+m)*0.5*Math.cos(o),A*(2+m)*Math.sin(o)*0.5,z*A*Math.sin(q)*0.5)}THREE.Geometry.call(this);this.radius=a||200;this.tube=e||40;this.segmentsR=b||64;this.segmentsT=c||8;this.p=g||2;this.q=f||3;this.heightScale=d||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|=(G&127)<<16|C<<8;if(B==0&&R==-127)return 0;return(1-2*(N>>7))*(1+B*Math.pow(2,-23))*Math.pow(2,R)}function h(p,w){var B=k(p,w),C=k(p,w+1),G=k(p,w+2);return(k(p,w+3)<<24)+(G<<16)+(C<<8)+B}function j(p,w){var B=k(p,w);return(k(p,w+1)<<8)+B}function l(p,w){var B=k(p,w);return B>127?B-256:B}function k(p, w){return p.charCodeAt(w)&255}function o(p){var w,B,C;w=h(a,p);B=h(a,p+M);C=h(a,p+F);p=j(a,p+J);THREE.BinaryLoader.prototype.f3(x,w,B,C,p)}function q(p){var w,B,C,G,N,R;w=h(a,p);B=h(a,p+M);C=h(a,p+F);G=j(a,p+J);N=h(a,p+I);R=h(a,p+K);p=h(a,p+L);THREE.BinaryLoader.prototype.f3n(x,H,w,B,C,G,N,R,p)}function m(p){var w,B,C,G;w=h(a,p);B=h(a,p+P);C=h(a,p+Q);G=h(a,p+E);p=j(a,p+O);THREE.BinaryLoader.prototype.f4(x,w,B,C,G,p)}function t(p){var w,B,C,G,N,R,aa,ba;w=h(a,p);B=h(a,p+P);C=h(a,p+Q);G=h(a,p+E);N=j(a, p+O);R=h(a,p+U);aa=h(a,p+$);ba=h(a,p+T);p=h(a,p+ca);THREE.BinaryLoader.prototype.f4n(x,H,w,B,C,G,N,R,aa,ba,p)}function A(p){var w,B;w=h(a,p);B=h(a,p+da);p=h(a,p+ea);THREE.BinaryLoader.prototype.uv3(x.faceVertexUvs[0],D[w*2],D[w*2+1],D[B*2],D[B*2+1],D[p*2],D[p*2+1])}function z(p){var w,B,C;w=h(a,p);B=h(a,p+fa);C=h(a,p+ga);p=h(a,p+ha);THREE.BinaryLoader.prototype.uv4(x.faceVertexUvs[0],D[w*2],D[w*2+1],D[B*2],D[B*2+1],D[C*2],D[C*2+1],D[p*2],D[p*2+1])}var x=this,y=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,f);n={signature:a.substr(y,8),header_bytes:k(a,y+8),vertex_coordinate_bytes:k(a,y+9),normal_coordinate_bytes:k(a,y+10),uv_coordinate_bytes:k(a,y+11),vertex_index_bytes:k(a,y+12),normal_index_bytes:k(a,y+13),uv_index_bytes:k(a,y+14),material_index_bytes:k(a,y+15),nvertices:h(a,y+16),nnormals:h(a,y+16+4),nuvs:h(a,y+16+8),ntri_flat:h(a,y+16+12),ntri_smooth:h(a,y+16+16),ntri_flat_uv:h(a,y+16+20),ntri_smooth_uv:h(a, y+16+24),nquad_flat:h(a,y+16+28),nquad_smooth:h(a,y+16+32),nquad_flat_uv:h(a,y+16+36),nquad_smooth_uv:h(a,y+16+40)};y+=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;f=n.vertex_index_bytes*3+n.material_index_bytes;S=n.vertex_index_bytes*4+n.material_index_bytes;V=n.ntri_flat*f;W=n.ntri_smooth*(f+n.normal_index_bytes*3);X=n.ntri_flat_uv* (f+n.uv_index_bytes*3);Y=n.ntri_smooth_uv*(f+n.normal_index_bytes*3+n.uv_index_bytes*3);Z=n.nquad_flat*S;f=n.nquad_smooth*(S+n.normal_index_bytes*4);S=n.nquad_flat_uv*(S+n.uv_index_bytes*4);y+=function(p){for(var w,B,C,G=n.vertex_coordinate_bytes*3,N=p+n.nvertices*G;p=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(l-h);q<1&&(q=1);l=Math.floor(l+h);l>this.size-1&&(l=this.size-1);var m=Math.floor(k-h);m<1&&(m=1);h=Math.floor(k+h); h>this.size-1&&(h=this.size-1);for(var t,A,z,x,y,n;o0&&(this.field[z+t]+=x)}}}};this.addPlaneX=function(b,c){var g,f,d,h,j,l=this.size,k=this.yd,o=this.zd,q=this.field,m=l*Math.sqrt(b/c);m>l&&(m=l);for(g=0;g0)for(f=0;fk&&(t=k);for(f=0;f0){j=f*o;for(g=0;gsize&&(dist=size);for(d=0;d0){j=zd*d;for(f=0;f