// ThreeExtras.js r33 - http://github.com/mrdoob/three.js var GeometryUtils={merge:function(a,d){var b=d instanceof THREE.Mesh,f=a.vertices.length,g=b?d.geometry:d,c=a.vertices,e=g.vertices,h=a.faces,j=g.faces,l=a.uvs;g=g.uvs;b&&d.matrixAutoUpdate&&d.updateMatrix();for(var m=0,v=e.length;m= 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&&(c=25);g=(c-1)*0.5;b=Array(c);for(d=f=0;d0||(m=this.vertices.push(new THREE.Vertex(new THREE.Vector3(v,h,q)))-1);l.push(m)}d.push(l)}var n,p,t;g=d.length;for(b=0;b0)for(f=0;f1){n=this.vertices[e].position.clone(); p=this.vertices[j].position.clone();t=this.vertices[l].position.clone();n.normalize();p.normalize();t.normalize();this.faces.push(new THREE.Face3(e,j,l,[new THREE.Vector3(n.x,n.y,n.z),new THREE.Vector3(p.x,p.y,p.z),new THREE.Vector3(t.x,t.y,t.z)]));this.uvs.push([m,v,z])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere; var Torus=function(a,d,b,f){this.radius=a||100;this.tube=d||40;this.segmentsR=b||8;this.segmentsT=f||6;a=[];THREE.Geometry.call(this);for(d=0;d<=this.segmentsR;++d)for(b=0;b<=this.segmentsT;++b){f=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(f),(this.radius+this.tube*Math.cos(g))*Math.sin(f),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){f=(this.segmentsT+1)*d+b;g=(this.segmentsT+1)*d+b-1;var c=(this.segmentsT+1)*(d-1)+b-1,e=(this.segmentsT+1)*(d-1)+b;this.faces.push(new THREE.Face4(f,g,c,e));this.uvs.push([new THREE.UV(a[f][0],a[f][1]),new THREE.UV(a[g][0],a[g][1]),new THREE.UV(a[c][0],a[c][1]),new THREE.UV(a[e][0],a[e][1])])}delete a;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial()};Torus.prototype=new THREE.Geometry;Torus.prototype.constructor=Torus; var Icosahedron=function(a){function d(v,q,n){var p=Math.sqrt(v*v+q*q+n*n);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(v/p,q/p,n/p)))-1}function b(v,q,n,p){p.faces.push(new THREE.Face3(v,q,n))}function f(v,q){var n=g.vertices[v].position,p=g.vertices[q].position;return d((n.x+p.x)/2,(n.y+p.y)/2,(n.z+p.z)/2)}var g=this,c=new THREE.Geometry,e;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,c);b(0,5,1,c);b(0,1,7,c);b(0,7,10,c);b(0,10,11,c);b(1,5,9,c);b(5,11,4,c);b(11,10,2,c);b(10,7,6,c);b(7,1,8,c);b(3,9,4,c);b(3,4,2,c);b(3,2,6,c);b(3,6,8,c);b(3,8,9,c);b(4,9,5,c);b(2,4,11,c);b(6,2,10,c);b(8,6,7,c);b(9,8,1,c);for(a=0;a=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 f=this.count*3;fthis.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 n=Math.floor(m-h);n<1&&(n=1);h=Math.floor(m+h); h>this.size-1&&(h=this.size-1);for(var p,t,z,w,x,k;v0&&(this.field[z+p]+=w)}}}};this.addPlaneX=function(b,f){var g,c,e,h,j,l=this.size,m=this.yd,v=this.zd,q=this.field,n=l*Math.sqrt(b/f);n>l&&(n=l);for(g=0;g0)for(c=0;cm&&(p=m);for(c=0;c0){j=c*v;for(g=0;gsize&&(dist=size);for(e=0;e0){j=zd*e;for(c=0;c>7)-127;y|=(G&127)<<16|B<<8;if(y==0&&N==-127)return 0;return(1-2*(L>>7))*(1+y*Math.pow(2,-23))*Math.pow(2,N)}function h(o,u){var y=m(o,u),B=m(o,u+1),G=m(o,u+2);return(m(o,u+3)<<24)+(G<<16)+(B<<8)+y}function j(o,u){var y=m(o,u);return(m(o,u+1)<<8)+y}function l(o,u){var y=m(o,u);return y>127?y-256:y}function m(o,u){return o.charCodeAt(u)&255}function v(o){var u,y,B;u=h(a,o); y=h(a,o+J);B=h(a,o+A);o=j(a,o+C);THREE.Loader.prototype.f3(w,u,y,B,o)}function q(o){var u,y,B,G,L,N;u=h(a,o);y=h(a,o+J);B=h(a,o+A);G=j(a,o+C);L=h(a,o+H);N=h(a,o+I);o=h(a,o+K);THREE.Loader.prototype.f3n(w,D,u,y,B,G,L,N,o)}function n(o){var u,y,B,G;u=h(a,o);y=h(a,o+M);B=h(a,o+F);G=h(a,o+P);o=j(a,o+Q);THREE.Loader.prototype.f4(w,u,y,B,G,o)}function p(o){var u,y,B,G,L,N,Y,Z;u=h(a,o);y=h(a,o+M);B=h(a,o+F);G=h(a,o+P);L=j(a,o+Q);N=h(a,o+R);Y=h(a,o+S);Z=h(a,o+$);o=h(a,o+aa);THREE.Loader.prototype.f4n(w,D, u,y,B,G,L,N,Y,Z,o)}function t(o){var u,y;u=h(a,o);y=h(a,o+ba);o=h(a,o+ca);THREE.Loader.prototype.uv3(w.uvs,E[u*2],E[u*2+1],E[y*2],E[y*2+1],E[o*2],E[o*2+1])}function z(o){var u,y,B;u=h(a,o);y=h(a,o+da);B=h(a,o+ea);o=h(a,o+fa);THREE.Loader.prototype.uv4(w.uvs,E[u*2],E[u*2+1],E[y*2],E[y*2+1],E[B*2],E[B*2+1],E[o*2],E[o*2+1])}var w=this,x=0,k,D=[],E=[],J,A,C,H,I,K,M,F,P,Q,R,S,$,aa,ba,ca,da,ea,fa,T,U,V,W,X,O;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(w,f,c);k={signature:a.substr(x, 8),header_bytes:m(a,x+8),vertex_coordinate_bytes:m(a,x+9),normal_coordinate_bytes:m(a,x+10),uv_coordinate_bytes:m(a,x+11),vertex_index_bytes:m(a,x+12),normal_index_bytes:m(a,x+13),uv_index_bytes:m(a,x+14),material_index_bytes:m(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+=k.header_bytes;J=k.vertex_index_bytes;A=k.vertex_index_bytes*2;C=k.vertex_index_bytes*3;H=k.vertex_index_bytes*3+k.material_index_bytes;I=k.vertex_index_bytes*3+k.material_index_bytes+k.normal_index_bytes;K=k.vertex_index_bytes*3+k.material_index_bytes+k.normal_index_bytes*2;M=k.vertex_index_bytes;F=k.vertex_index_bytes*2;P=k.vertex_index_bytes*3;Q=k.vertex_index_bytes*4;R=k.vertex_index_bytes*4+k.material_index_bytes;S=k.vertex_index_bytes*4+k.material_index_bytes+k.normal_index_bytes;$=k.vertex_index_bytes* 4+k.material_index_bytes+k.normal_index_bytes*2;aa=k.vertex_index_bytes*4+k.material_index_bytes+k.normal_index_bytes*3;ba=k.uv_index_bytes;ca=k.uv_index_bytes*2;da=k.uv_index_bytes;ea=k.uv_index_bytes*2;fa=k.uv_index_bytes*3;c=k.vertex_index_bytes*3+k.material_index_bytes;O=k.vertex_index_bytes*4+k.material_index_bytes;T=k.ntri_flat*c;U=k.ntri_smooth*(c+k.normal_index_bytes*3);V=k.ntri_flat_uv*(c+k.uv_index_bytes*3);W=k.ntri_smooth_uv*(c+k.normal_index_bytes*3+k.uv_index_bytes*3);X=k.nquad_flat* O;c=k.nquad_smooth*(O+k.normal_index_bytes*4);O=k.nquad_flat_uv*(O+k.uv_index_bytes*4);x+=function(o){for(var u,y,B,G=k.vertex_coordinate_bytes*3,L=o+k.nvertices*G;o