// ThreeExtras.js r39 - http://github.com/mrdoob/three.js THREE.AnimationHandler=function(){var a=[],d={},b={};b.update=function(c){for(var f=0;f1){console.log("THREE.Animation.update: Warning! Scale out of bounds:"+e+" on bone "+p);e=e<0?0:1}if(b==="pos"){b=a.position;if(this.interpolationType===THREE.AnimationHandler.LINEAR){b.x=c[0]+(f[0]-c[0])*e;b.y=c[1]+(f[1]-c[1])*e;b.z=c[2]+(f[2]-c[2])*e}else if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD){this.points[0]= this.getPrevKeyWith("pos",p,g.index-1).pos;this.points[1]=c;this.points[2]=f;this.points[3]=this.getNextKeyWith("pos",p,h.index+1).pos;e=e*0.33+0.33;c=this.interpolateCatmullRom(this.points,e);b.x=c[0];b.y=c[1];b.z=c[2];if(this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD){e=this.interpolateCatmullRom(this.points,e*1.01);this.target.set(e[0],e[1],e[2]);this.target.subSelf(b);this.target.y=0;this.target.normalize();e=Math.atan2(this.target.x,this.target.z);a.rotation.set(0,e,0)}}}else if(b=== "rot")THREE.Quaternion.slerp(c,f,a.quaternion,e);else if(b==="scl"){b=a.scale;b.x=c[0]+(f[0]-c[0])*e;b.y=c[1]+(f[1]-c[1])*e;b.z=c[2]+(f[2]-c[2])*e}}}}if(this.JITCompile&&k[0][l]===undefined){this.hierarchy[0].update(undefined,!0);for(p=0;pa.length-2?f:f+1;b[3]=f>a.length-3?f:f+2;f=a[b[0]];h=a[b[1]];j=a[b[2]];l=a[b[3]];b=c*c;g=c*b;e[0]=this.interpolate(f[0],h[0],j[0],l[0],c,b,g);e[1]=this.interpolate(f[1],h[1],j[1],l[1],c,b,g);e[2]=this.interpolate(f[2],h[2],j[2],l[2],c,b,g);return e}; THREE.Animation.prototype.interpolate=function(a,d,b,e,c,f,g){a=(b-a)*0.5;e=(e-d)*0.5;return(2*(d-b)+a+e)*g+(-3*(d-b)-2*a-e)*f+a*c+d};THREE.Animation.prototype.getNextKeyWith=function(a,d,b){var e=this.data.hierarchy[d].keys;if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)b=b0?b:0:b>=0?b:b+e.length;b>=0;b--)if(e[b][a]!==undefined)return e[b];return this.data.hierarchy[d].keys[e.length-1]}; var GeometryUtils={merge:function(a,d){var b=d instanceof THREE.Mesh,e=a.vertices.length,c=b?d.geometry:d,f=a.vertices,g=c.vertices,h=a.faces,j=c.faces,l=a.faceVertexUvs[0];c=c.faceVertexUvs[0];b&&d.matrixAutoUpdate&&d.updateMatrix();for(var k=0,t=g.length;k= 0.0 )\npointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight * pointDiffuseWeight;\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 = specularTex.r * pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight * dirDiffuseWeight;\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);c=(f-1)*0.5;b=Array(f);for(d=e=0;dthis.heightMax?this.heightMax:this.position.y)-this.heightMin)*this.heightCoef:0;var e=this.tdiff*this.movementSpeed;(this.moveForward||this.autoForward&&!this.moveBackward)&&this.translateZ(-(e+this.autoSpeedFactor));this.moveBackward&&this.translateZ(e);this.moveLeft&&this.translateX(-e);this.moveRight&&this.translateX(e);e=this.tdiff*this.lookSpeed; this.activeLook||(e=0);this.lon+=this.mouseX*e;this.lookVertical&&(this.lat-=this.mouseY*e);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.lon+=this.mouseX*e;this.lookVertical&&(this.lat-=this.mouseY*e);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;if(this.constrainVertical)this.phi=(this.phi-0)*(this.verticalMax-this.verticalMin)/3.14+this.verticalMin;b=this.target.position;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,m){var p={name:t,fps:0.6,length:m,hierarchy:[]},y,w=k.getControlPointsArray(),B=k.getLength(),n=w.length,x=0;y=n-1;k={parent:-1,keys:[]};k.keys[0]={time:0,pos:w[0],rot:[0,0,0,1],scl:[1,1,1]};k.keys[y]={time:m,pos:w[y],rot:[0,0,0,1],scl:[1,1,1]};for(y=1;y=0?m:m+c;m=this.verticalAngleMap.srcRange;p=this.verticalAngleMap.dstRange; this.phi=(this.phi-m[0])*(p[1]-p[0])/(m[1]-m[0])+p[0];m=this.horizontalAngleMap.srcRange;p=this.horizontalAngleMap.dstRange;this.theta=(this.theta-m[0])*(p[1]-p[0])/(m[1]-m[0])+p[0];m=this.target.position;m.x=100*Math.sin(this.phi)*Math.cos(this.theta);m.y=100*Math.cos(this.phi);m.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 g=new THREE.MeshLambertMaterial({color:65280}),h=new THREE.Cube(10,10,20),j=new THREE.Cube(2,2,10);this.animationParent=new THREE.Mesh(h,a);a=new THREE.Mesh(j,g);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&&e(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; THREE.FlyCamera=function(a){function d(b,e){return function(){e.apply(b,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.005;this.dragToLook=!1;this.autoForward=!1;this.domElement=document;if(a){if(a.movementSpeed!==undefined)this.movementSpeed=a.movementSpeed;if(a.rollSpeed!==undefined)this.rollSpeed=a.rollSpeed;if(a.dragToLook!==undefined)this.dragToLook=a.dragToLook;if(a.autoForward!==undefined)this.autoForward= a.autoForward;if(a.domElement!==undefined)this.domElement=a.domElement}this.useTarget=!1;this.useQuaternion=!0;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.lastUpdate=(new Date).getTime();this.tdiff=0;this.handleEvent=function(b){if(typeof this[b.type]=="function")this[b.type](b)};this.keydown=function(b){if(!b.altKey){switch(b.keyCode){case 16:this.movementSpeedMultiplier= 0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}}; this.keyup=function(b){switch(b.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=0;break;case 39:this.moveState.yawRight=0;break;case 81:this.moveState.rollLeft=0;break; case 69:this.moveState.rollRight=0}this.updateMovementVector();this.updateRotationVector()};this.mousedown=function(b){b.preventDefault();b.stopPropagation();if(this.dragToLook)this.mouseStatus++;else switch(b.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}};this.mousemove=function(b){if(!this.dragToLook||this.mouseStatus>0){var e=this.getContainerDimensions(),c=e.size[0]/2,f=e.size[1]/2;this.moveState.yawLeft=-(b.clientX-e.offset[0]-c)/c;this.moveState.pitchDown=(b.clientY- e.offset[1]-f)/f;this.updateRotationVector()}};this.mouseup=function(b){b.preventDefault();b.stopPropagation();if(this.dragToLook){this.mouseStatus--;this.moveState.yawLeft=this.moveState.pitchDown=0}else switch(b.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=!1}this.updateRotationVector()};this.update=function(){var b=(new Date).getTime();this.tdiff=(b-this.lastUpdate)/1E3;this.lastUpdate=b;b=this.tdiff*this.movementSpeed;var e=this.tdiff*this.rollSpeed;this.translateX(this.moveVector.x* b);this.translateY(this.moveVector.y*b);this.translateZ(this.moveVector.z*b);this.tmpQuaternion.set(this.rotationVector.x*e,this.rotationVector.y*e,this.rotationVector.z*e,1).normalize();this.quaternion.multiplySelf(this.tmpQuaternion);this.matrix.setPosition(this.position);this.matrix.setRotationFromQuaternion(this.quaternion);this.matrixWorldNeedsUpdate=!0;this.supr.update.call(this)};this.updateMovementVector=function(){var b=this.moveState.forward||this.autoForward&&!this.moveState.back?1:0;this.moveVector.x= -this.moveState.left+this.moveState.right;this.moveVector.y=-this.moveState.down+this.moveState.up;this.moveVector.z=-b+this.moveState.back};this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp;this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft;this.rotationVector.z=-this.moveState.rollRight+this.moveState.rollLeft};this.getContainerDimensions=function(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight], offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}};this.domElement.addEventListener("mousemove",d(this,this.mousemove),!1);this.domElement.addEventListener("mousedown",d(this,this.mousedown),!1);this.domElement.addEventListener("mouseup",d(this,this.mouseup),!1);window.addEventListener("keydown",d(this,this.keydown),!1);window.addEventListener("keyup",d(this,this.keyup),!1);this.updateMovementVector();this.updateRotationVector()}; THREE.FlyCamera.prototype=new THREE.Camera;THREE.FlyCamera.prototype.constructor=THREE.FlyCamera;THREE.FlyCamera.prototype.supr=THREE.Camera.prototype; THREE.RollCamera=function(a,d,b,e){THREE.Camera.call(this,a,d,b,e);this.mouseLook=!0;this.autoForward=!1;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.domElement=document;this.useTarget=!1;this.matrixAutoUpdate=!1;this.forward=new THREE.Vector3(0,0,1);this.roll=0;this.lastUpdate=(new Date).getTime();this.delta=0;var c=new THREE.Vector3,f=new THREE.Vector3,g=new THREE.Vector3,h=new THREE.Matrix4,j=!1,l=1,k=0,t=0,m=0,p=0,y=0,w=window.innerWidth/2,B=window.innerHeight/ 2;this.update=function(){var n=(new Date).getTime();this.delta=(n-this.lastUpdate)/1E3;this.lastUpdate=n;if(this.mouseLook){n=this.delta*this.lookSpeed;this.rotateHorizontally(n*p);this.rotateVertically(n*y)}n=this.delta*this.movementSpeed;this.translateZ(n*(k>0||this.autoForward&&!(k<0)?1:k));this.translateX(n*t);this.translateY(n*m);j&&(this.roll+=this.rollSpeed*this.delta*l);if(this.forward.y>this.constrainVertical[1]){this.forward.y=this.constrainVertical[1];this.forward.normalize()}else if(this.forward.y< this.constrainVertical[0]){this.forward.y=this.constrainVertical[0];this.forward.normalize()}g.copy(this.forward);f.set(0,1,0);c.cross(f,g).normalize();f.cross(g,c).normalize();this.matrix.n11=c.x;this.matrix.n12=f.x;this.matrix.n13=g.x;this.matrix.n21=c.y;this.matrix.n22=f.y;this.matrix.n23=g.y;this.matrix.n31=c.z;this.matrix.n32=f.z;this.matrix.n33=g.z;h.identity();h.n11=Math.cos(this.roll);h.n12=-Math.sin(this.roll);h.n21=Math.sin(this.roll);h.n22=Math.cos(this.roll);this.matrix.multiplySelf(h); this.matrixWorldNeedsUpdate=!0;this.matrix.n14=this.position.x;this.matrix.n24=this.position.y;this.matrix.n34=this.position.z;this.supr.update.call(this)};this.translateX=function(n){this.position.x+=this.matrix.n11*n;this.position.y+=this.matrix.n21*n;this.position.z+=this.matrix.n31*n};this.translateY=function(n){this.position.x+=this.matrix.n12*n;this.position.y+=this.matrix.n22*n;this.position.z+=this.matrix.n32*n};this.translateZ=function(n){this.position.x-=this.matrix.n13*n;this.position.y-= this.matrix.n23*n;this.position.z-=this.matrix.n33*n};this.rotateHorizontally=function(n){c.set(this.matrix.n11,this.matrix.n21,this.matrix.n31);c.multiplyScalar(n);this.forward.subSelf(c);this.forward.normalize()};this.rotateVertically=function(n){f.set(this.matrix.n12,this.matrix.n22,this.matrix.n32);f.multiplyScalar(n);this.forward.addSelf(f);this.forward.normalize()};this.domElement.addEventListener("contextmenu",function(n){n.preventDefault()},!1);this.domElement.addEventListener("mousemove", function(n){p=(n.clientX-w)/window.innerWidth;y=(n.clientY-B)/window.innerHeight},!1);this.domElement.addEventListener("mousedown",function(n){n.preventDefault();n.stopPropagation();switch(n.button){case 0:k=1;break;case 2:k=-1}},!1);this.domElement.addEventListener("mouseup",function(n){n.preventDefault();n.stopPropagation();switch(n.button){case 0:k=0;break;case 2:k=0}},!1);this.domElement.addEventListener("keydown",function(n){switch(n.keyCode){case 38:case 87:k=1;break;case 37:case 65:t=-1;break; case 40:case 83:k=-1;break;case 39:case 68:t=1;break;case 81:j=!0;l=1;break;case 69:j=!0;l=-1;break;case 82:m=1;break;case 70:m=-1}},!1);this.domElement.addEventListener("keyup",function(n){switch(n.keyCode){case 38:case 87:k=0;break;case 37:case 65:t=0;break;case 40:case 83:k=0;break;case 39:case 68:t=0;break;case 81:j=!1;break;case 69:j=!1;break;case 82:m=0;break;case 70:m=0}},!1)};THREE.RollCamera.prototype=new THREE.Camera;THREE.RollCamera.prototype.constructor=THREE.RollCamera; THREE.RollCamera.prototype.supr=THREE.Camera.prototype; THREE.Cube=function(a,d,b,e,c,f,g,h,j){function l(B,n,x,o,D,z,G,K){var H,J,L=e||1,E=c||1,R=D/2,S=z/2,N=k.vertices.length;if(B=="x"&&n=="y"||B=="y"&&n=="x")H="z";else if(B=="x"&&n=="z"||B=="z"&&n=="x"){H="y";E=f||1}else if(B=="z"&&n=="y"||B=="y"&&n=="z"){H="x";L=f||1}var M=L+1,T=E+1;D/=L;var U=z/E;for(J=0;J0){g(0,0,-k-(f||0));for(j=a;j0){g(0,0,k+(c||0)); for(j=a+a/2;j<2*a;j++)h.faces.push(new THREE.Face4(2*a+1,(2*j-2*a+2)%a+a,(2*j-2*a+1)%a+a,(2*j-2*a)%a+a))}j=0;for(a=this.faces.length;j0||(k=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,h,m)))-1);l.push(k)}d.push(l)}var p,y,w;c=d.length;for(b=0;b0)for(e=0;e1){p=this.vertices[g].position.clone(); y=this.vertices[j].position.clone();w=this.vertices[l].position.clone();p.normalize();y.normalize();w.normalize();this.faces.push(new THREE.Face3(g,j,l,[new THREE.Vector3(p.x,p.y,p.z),new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(w.x,w.y,w.z)]));this.faceVertexUvs[0].push([k,t,B])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:a}};THREE.Sphere.prototype=new THREE.Geometry;THREE.Sphere.prototype.constructor=THREE.Sphere; THREE.Torus=function(a,d,b,e){THREE.Geometry.call(this);this.radius=a||100;this.tube=d||40;this.segmentsR=b||8;this.segmentsT=e||6;a=[];for(d=0;d<=this.segmentsR;++d)for(b=0;b<=this.segmentsT;++b){e=b/this.segmentsT*2*Math.PI;var c=d/this.segmentsR*2*Math.PI;this.vertices.push(new THREE.Vertex(new THREE.Vector3((this.radius+this.tube*Math.cos(c))*Math.cos(e),(this.radius+this.tube*Math.cos(c))*Math.sin(e),this.tube*Math.sin(c))));a.push([b/this.segmentsT,1-d/this.segmentsR])}for(d=1;d<=this.segmentsR;++d)for(b= 1;b<=this.segmentsT;++b){e=(this.segmentsT+1)*d+b;c=(this.segmentsT+1)*d+b-1;var f=(this.segmentsT+1)*(d-1)+b-1,g=(this.segmentsT+1)*(d-1)+b;this.faces.push(new THREE.Face4(e,c,f,g));this.faceVertexUvs[0].push([new THREE.UV(a[e][0],a[e][1]),new THREE.UV(a[c][0],a[c][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()};THREE.Torus.prototype=new THREE.Geometry;THREE.Torus.prototype.constructor=THREE.Torus; THREE.TorusKnot=function(a,d,b,e,c,f,g){function h(t,m,p,y,w,B){m=p/y*t;p=Math.cos(m);return new THREE.Vector3(w*(2+p)*0.5*Math.cos(t),w*(2+p)*Math.sin(t)*0.5,B*w*Math.sin(m)*0.5)}THREE.Geometry.call(this);this.radius=a||200;this.tube=d||40;this.segmentsR=b||64;this.segmentsT=e||8;this.p=c||2;this.q=f||3;this.heightScale=g||1;this.grid=Array(this.segmentsR);b=new THREE.Vector3;e=new THREE.Vector3;f=new THREE.Vector3;for(a=0;a>7)-127;A|=(I&127)<<16|C<<8;if(A==0&&V==-127)return 0;return(1-2*(P>>7))*(1+A*Math.pow(2,-23))*Math.pow(2,V)}function h(u,v){var A=k(u,v),C=k(u,v+1),I=k(u,v+2);return(k(u,v+3)<<24)+(I<<16)+(C<<8)+A}function j(u,v){var A=k(u,v);return(k(u,v+1)<<8)+A}function l(u,v){var A=k(u,v);return A>127?A-256:A}function k(u, v){return u.charCodeAt(v)&255}function t(u){var v,A,C;v=h(a,u);A=h(a,u+G);C=h(a,u+K);u=j(a,u+H);THREE.BinaryLoader.prototype.f3(n,v,A,C,u)}function m(u){var v,A,C,I,P,V;v=h(a,u);A=h(a,u+G);C=h(a,u+K);I=j(a,u+H);P=h(a,u+J);V=h(a,u+L);u=h(a,u+E);THREE.BinaryLoader.prototype.f3n(n,D,v,A,C,I,P,V,u)}function p(u){var v,A,C,I;v=h(a,u);A=h(a,u+R);C=h(a,u+S);I=h(a,u+N);u=j(a,u+M);THREE.BinaryLoader.prototype.f4(n,v,A,C,I,u)}function y(u){var v,A,C,I,P,V,da,ea;v=h(a,u);A=h(a,u+R);C=h(a,u+S);I=h(a,u+N);P=j(a, u+M);V=h(a,u+T);da=h(a,u+U);ea=h(a,u+F);u=h(a,u+W);THREE.BinaryLoader.prototype.f4n(n,D,v,A,C,I,P,V,da,ea,u)}function w(u){var v,A;v=h(a,u);A=h(a,u+Q);u=h(a,u+O);THREE.BinaryLoader.prototype.uv3(n.faceVertexUvs[0],z[v*2],z[v*2+1],z[A*2],z[A*2+1],z[u*2],z[u*2+1])}function B(u){var v,A,C;v=h(a,u);A=h(a,u+Y);C=h(a,u+fa);u=h(a,u+ga);THREE.BinaryLoader.prototype.uv4(n.faceVertexUvs[0],z[v*2],z[v*2+1],z[A*2],z[A*2+1],z[C*2],z[C*2+1],z[u*2],z[u*2+1])}var n=this,x=0,o,D=[],z=[],G,K,H,J,L,E,R,S,N,M,T,U,F, W,Q,O,Y,fa,ga,Z,$,aa,ba,ca,X;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(n,e,f);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;G=o.vertex_index_bytes;K=o.vertex_index_bytes*2;H=o.vertex_index_bytes*3;J=o.vertex_index_bytes*3+o.material_index_bytes;L=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes;E=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*2;R=o.vertex_index_bytes;S=o.vertex_index_bytes*2;N=o.vertex_index_bytes*3;M=o.vertex_index_bytes*4;T=o.vertex_index_bytes* 4+o.material_index_bytes;U=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes;F=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*2;W=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*3;Q=o.uv_index_bytes;O=o.uv_index_bytes*2;Y=o.uv_index_bytes;fa=o.uv_index_bytes*2;ga=o.uv_index_bytes*3;f=o.vertex_index_bytes*3+o.material_index_bytes;X=o.vertex_index_bytes*4+o.material_index_bytes;Z=o.ntri_flat*f;$=o.ntri_smooth*(f+o.normal_index_bytes*3);aa=o.ntri_flat_uv* (f+o.uv_index_bytes*3);ba=o.ntri_smooth_uv*(f+o.normal_index_bytes*3+o.uv_index_bytes*3);ca=o.nquad_flat*X;f=o.nquad_smooth*(X+o.normal_index_bytes*4);X=o.nquad_flat_uv*(X+o.uv_index_bytes*4);x+=function(u){for(var v,A,C,I=o.vertex_coordinate_bytes*3,P=u+o.nvertices*I;u1&& (L=[new THREE.MeshFaceMaterial]);object=new THREE.Mesh(K,L);object.name=y;object.position.set(D[0],D[1],D[2]);if(q){object.quaternion.set(q[0],q[1],q[2],q[3]);object.useQuaternion=!0}else object.rotation.set(r[0],r[1],r[2]);object.scale.set(s[0],s[1],s[2]);object.visible=o.visible;F.scene.addObject(object);F.objects[y]=object;if(o.meshCollider){var O=THREE.CollisionUtils.MeshColliderWBox(object);THREE.Collisions.colliders.push(O)}if(o.castsShadow){O=new THREE.ShadowVolume(K);F.scene.addChild(O);O.position= object.position;O.rotation=object.rotation;O.scale=object.scale}}}}function k(O){return function(Y){F.geometries[O]=Y;l();N-=1;c.onLoadComplete();t()}}function t(){e({total_models:T,total_textures:U,loaded_models:T-N,loaded_textures:U-M},F);c.onLoadProgress();N==0&&M==0&&b(F)}var m,p,y,w,B,n,x,o,D,z,G,K,H,J,L,E,R,S,N,M,T,U,F;E=h.data;R=new THREE.BinaryLoader;S=new THREE.JSONLoader;M=N=0;F={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{}};if(E.transform){h= E.transform.position;z=E.transform.rotation;var W=E.transform.scale;h&&F.scene.position.set(h[0],h[1],h[2]);z&&F.scene.rotation.set(z[0],z[1],z[2]);W&&F.scene.scale.set(W[0],W[1],W[2]);(h||z||W)&&F.scene.updateMatrix()}h=function(){M-=1;t();c.onLoadComplete()};for(B in E.cameras){z=E.cameras[B];if(z.type=="perspective")H=new THREE.Camera(z.fov,z.aspect,z.near,z.far);else if(z.type=="ortho"){H=new THREE.Camera;H.projectionMatrix=THREE.Matrix4.makeOrtho(z.left,z.right,z.top,z.bottom,z.near,z.far)}D= z.position;z=z.target;H.position.set(D[0],D[1],D[2]);H.target.position.set(z[0],z[1],z[2]);F.cameras[B]=H}for(w in E.lights){B=E.lights[w];H=B.color!==undefined?B.color:16777215;z=B.intensity!==undefined?B.intensity:1;if(B.type=="directional"){D=B.direction;light=new THREE.DirectionalLight(H,z);light.position.set(D[0],D[1],D[2]);light.position.normalize()}else if(B.type=="point"){D=B.position;light=new THREE.PointLight(H,z);light.position.set(D[0],D[1],D[2])}F.scene.addLight(light);F.lights[w]=light}for(n in E.fogs){w= E.fogs[n];if(w.type=="linear")J=new THREE.Fog(0,w.near,w.far);else w.type=="exp2"&&(J=new THREE.FogExp2(0,w.density));z=w.color;J.color.setRGB(z[0],z[1],z[2]);F.fogs[n]=J}if(F.cameras&&E.defaults.camera)F.currentCamera=F.cameras[E.defaults.camera];if(F.fogs&&E.defaults.fog)F.scene.fog=F.fogs[E.defaults.fog];z=E.defaults.bgcolor;F.bgColor=new THREE.Color;F.bgColor.setRGB(z[0],z[1],z[2]);F.bgColorAlpha=E.defaults.bgalpha;for(m in E.geometries){n=E.geometries[m];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){N+= 1;c.onLoadStart()}}T=N;for(m in E.geometries){n=E.geometries[m];if(n.type=="cube"){K=new THREE.Cube(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides);F.geometries[m]=K}else if(n.type=="plane"){K=new THREE.Plane(n.width,n.height,n.segmentsWidth,n.segmentsHeight);F.geometries[m]=K}else if(n.type=="sphere"){K=new THREE.Sphere(n.radius,n.segmentsWidth,n.segmentsHeight);F.geometries[m]=K}else if(n.type=="cylinder"){K=new THREE.Cylinder(n.numSegs,n.topRad, n.botRad,n.height,n.topOffset,n.botOffset);F.geometries[m]=K}else if(n.type=="torus"){K=new THREE.Torus(n.radius,n.tube,n.segmentsR,n.segmentsT);F.geometries[m]=K}else if(n.type=="icosahedron"){K=new THREE.Icosahedron(n.subdivisions);F.geometries[m]=K}else if(n.type=="bin_mesh")R.load({model:j(n.url,E.urlBaseType),callback:k(m)});else n.type=="ascii_mesh"&&S.load({model:j(n.url,E.urlBaseType),callback:k(m)})}for(x in E.textures){m=E.textures[x];if(m.url instanceof Array){M+=m.url.length;for(n=0;n< m.url.length;n++)c.onLoadStart()}else{M+=1;c.onLoadStart()}}U=M;for(x in E.textures){m=E.textures[x];if(m.mapping!=undefined&&THREE[m.mapping]!=undefined)m.mapping=new THREE[m.mapping];if(m.url instanceof Array){n=[];for(var Q=0;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 e=this.count*3;ethis.size-1&&(j=this.size-1);var m=Math.floor(l-h);m<1&&(m=1);l=Math.floor(l+h);l>this.size-1&&(l=this.size-1);var p=Math.floor(k-h);p<1&&(p=1);h=Math.floor(k+h); h>this.size-1&&(h=this.size-1);for(var y,w,B,n,x,o;t0&&(this.field[B+y]+=n)}}}};this.addPlaneX=function(b,e){var c,f,g,h,j,l=this.size,k=this.yd,t=this.zd,m=this.field,p=l*Math.sqrt(b/e);p>l&&(p=l);for(c=0;c0)for(f=0;fk&&(y=k);for(f=0;f0){j=f*t;for(c=0;csize&&(dist=size);for(g=0;g0){j=zd*g;for(f=0;ff?this.hits.push(c):this.hits.unshift(c);f=e}}return this.hits}; THREE.CollisionSystem.prototype.rayCastNearest=function(a){var d=this.rayCastAll(a);if(d.length==0)return null;for(var b=0;d[b]instanceof THREE.MeshCollider;){var e=this.rayMesh(a,d[b]);if(ed.length)return null;return d[b]}; THREE.CollisionSystem.prototype.rayCast=function(a,d){if(d instanceof THREE.PlaneCollider)return this.rayPlane(a,d);else if(d instanceof THREE.SphereCollider)return this.raySphere(a,d);else if(d instanceof THREE.BoxCollider)return this.rayBox(a,d);else if(d instanceof THREE.MeshCollider&&d.box)return this.rayBox(a,d.box)}; THREE.CollisionSystem.prototype.rayMesh=function(a,d){for(var b=this.makeRayLocal(a,d.mesh),e=Number.MAX_VALUE,c=0;c=g*c))return Number.MAX_VALUE;f/=g;var j=THREE.CollisionSystem.__v3;j.copy(a.direction);j.multiplyScalar(f);j.addSelf(a.origin);if(Math.abs(h.x)>Math.abs(h.y))if(Math.abs(h.x)> Math.abs(h.z)){a=j.y-d.y;c=b.y-d.y;g=e.y-d.y;j=j.z-d.z;b=b.z-d.z;e=e.z-d.z}else{a=j.x-d.x;c=b.x-d.x;g=e.x-d.x;j=j.y-d.y;b=b.y-d.y;e=e.y-d.y}else if(Math.abs(h.y)>Math.abs(h.z)){a=j.x-d.x;c=b.x-d.x;g=e.x-d.x;j=j.z-d.z;b=b.z-d.z;e=e.z-d.z}else{a=j.x-d.x;c=b.x-d.x;g=e.x-d.x;j=j.y-d.y;b=b.y-d.y;e=e.y-d.y}d=c*e-b*g;if(d==0)return Number.MAX_VALUE;d=1/d;e=(a*e-j*g)*d;if(!(e>=0))return Number.MAX_VALUE;d*=c*j-b*a;if(!(d>=0))return Number.MAX_VALUE;if(!(1-e-d>=0))return Number.MAX_VALUE;this.collisionNormal= h;return f};THREE.CollisionSystem.prototype.makeRayLocal=function(a,d){var b=new THREE.Ray(a.origin.clone(),a.direction.clone()),e=THREE.Matrix4.makeInvert(d.matrixWorld);e.multiplyVector3(b.origin);e.rotateAxis(b.direction);b.direction.normalize();return b}; THREE.CollisionSystem.prototype.rayBox=function(a,d){var b;b=d.dynamic&&d.mesh&&d.mesh.matrixWorld?this.makeRayLocal(a,d.mesh):new THREE.Ray(a.origin.clone(),a.direction.clone());var e=0,c=0,f=0,g=0,h=0,j=0,l=!0;if(b.origin.xd.max.x){e=d.max.x-b.origin.x;e/=b.direction.x;l=!1;g=1}if(b.origin.yd.max.y){c=d.max.y-b.origin.y;c/=b.direction.y;l=!1;h= 1}if(b.origin.zd.max.z){f=d.max.z-b.origin.z;f/=b.direction.z;l=!1;j=1}if(l)return-1;l=0;if(c>e){l=1;e=c}if(f>e){l=2;e=f}switch(l){case 0:h=b.origin.y+b.direction.y*e;if(hd.max.y)return Number.MAX_VALUE;b=b.origin.z+b.direction.z*e;if(bd.max.z)return Number.MAX_VALUE;d.normal=new THREE.Vector3(g,0,0);break;case 1:g=b.origin.x+b.direction.x*e;if(gd.max.x)return Number.MAX_VALUE;b=b.origin.z+ b.direction.z*e;if(bd.max.z)return Number.MAX_VALUE;d.normal=new THREE.Vector3(0,h,0);break;case 2:g=b.origin.x+b.direction.x*e;if(gd.max.x)return Number.MAX_VALUE;h=b.origin.y+b.direction.y*e;if(hd.max.y)return Number.MAX_VALUE;d.normal=new THREE.Vector3(0,0,j)}return e};THREE.CollisionSystem.prototype.rayPlane=function(a,d){var b=a.direction.dot(d.normal),e=d.point.dot(d.normal);if(b<0)b=(e-a.origin.dot(d.normal))/b;else return Number.MAX_VALUE;return b>0?b:Number.MAX_VALUE}; THREE.CollisionSystem.prototype.raySphere=function(a,d){var b=d.center.clone().subSelf(a.origin);if(b.lengthSq=0)return Math.abs(e)-Math.sqrt(b);return Number.MAX_VALUE};THREE.CollisionSystem.__v1=new THREE.Vector3;THREE.CollisionSystem.__v2=new THREE.Vector3;THREE.CollisionSystem.__v3=new THREE.Vector3;THREE.CollisionSystem.__nr=new THREE.Vector3;THREE.CollisionUtils={}; THREE.CollisionUtils.MeshOBB=function(a){a.geometry.computeBoundingBox();var d=a.geometry.boundingBox,b=new THREE.Vector3(d.x[0],d.y[0],d.z[0]);d=new THREE.Vector3(d.x[1],d.y[1],d.z[1]);b=new THREE.BoxCollider(b,d);b.mesh=a;return b};THREE.CollisionUtils.MeshAABB=function(a){var d=THREE.CollisionUtils.MeshOBB(a);d.min.addSelf(a.position);d.max.addSelf(a.position);d.dynamic=!1;return d}; THREE.CollisionUtils.MeshColliderWBox=function(a){for(var d=a.geometry.vertices,b=d.length,e=a.geometry.faces,c=e.length,f=[],g=[],h=[],j=0;j