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