From 35d2f488590b873364cedb081be7e22192fd894b Mon Sep 17 00:00:00 2001 From: alteredq Date: Tue, 24 Apr 2012 12:29:05 +0200 Subject: [PATCH] Refactored morph target setting. Still need to fix influence sorting. --- build/Three.js | 472 +-- build/custom/ThreeCanvas.js | 6975 +------------------------------- build/custom/ThreeExtras.js | 10 +- build/custom/ThreeWebGL.js | 554 +-- src/renderers/WebGLRenderer.js | 113 +- 5 files changed, 578 insertions(+), 7546 deletions(-) diff --git a/build/Three.js b/build/Three.js index fba546db5c..ee47470a76 100644 --- a/build/Three.js +++ b/build/Three.js @@ -14,47 +14,47 @@ THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a; a;this.z=this.z+a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x=this.x*a.x;this.y=this.y*a.y;this.z=this.z*a.z;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;return this},divideSelf:function(a){this.x=this.x/a.x;this.y= this.y/a.y;this.z=this.z/a.z;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a}else this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())}, setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;return this},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this, -a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,e=b?b.z:1,f=a.elements[0]/c,g=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,h=a.elements[9]/e,j=a.elements[10]/e;this.y=Math.asin(a.elements[8]/e);e=Math.cos(this.y);if(Math.abs(e)>1.0E-5){this.x=Math.atan2(-h/e,j/e);this.z=Math.atan2(-g/e,f/e)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b= +a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,e=b?b.z:1,f=a.elements[0]/c,g=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,h=a.elements[9]/e,k=a.elements[10]/e;this.y=Math.asin(a.elements[8]/e);e=Math.cos(this.y);if(Math.abs(e)>1.0E-5){this.x=Math.atan2(-h/e,k/e);this.z=Math.atan2(-g/e,f/e)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b= this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},isZero:function(){return this.lengthSq()<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1}; THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w!==void 0?a.w:1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;this.z=this.z+a.z;this.w=this.w+a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x= this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;this.w=this.w-a.w;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a;this.w=this.w/a}else{this.z=this.y=this.x=0;this.w=1}return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())}, normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;this.w=this.w+(a.w-this.w)*b;return this},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)}};THREE.Frustum=function(){this.planes=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4]}; -THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var e=d[2],f=d[3],g=d[4],h=d[5],j=d[6],k=d[7],l=d[8],o=d[9],m=d[10],p=d[11],q=d[12],n=d[13],r=d[14],d=d[15];c[0].set(f-a,k-g,p-l,d-q);c[1].set(f+a,k+g,p+l,d+q);c[2].set(f+b,k+h,p+o,d+n);c[3].set(f-b,k-h,p-o,d-n);c[4].set(f-e,k-j,p-m,d-r);c[5].set(f+e,k+j,p+m,d+r);for(a=0;a<6;a++){b=c[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}}; +THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var e=d[2],f=d[3],g=d[4],h=d[5],k=d[6],j=d[7],l=d[8],o=d[9],m=d[10],p=d[11],q=d[12],n=d[13],r=d[14],d=d[15];c[0].set(f-a,j-g,p-l,d-q);c[1].set(f+a,j+g,p+l,d+q);c[2].set(f+b,j+h,p+o,d+n);c[3].set(f-b,j-h,p-o,d-n);c[4].set(f-e,j-k,p-m,d-r);c[5].set(f+e,j+k,p+m,d+r);for(a=0;a<6;a++){b=c[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}}; THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=c.elements,c=-a.geometry.boundingSphere.radius*c.getMaxScaleOnAxis(),e=0;e<6;e++){a=b[e].x*d[12]+b[e].y*d[13]+b[e].z*d[14]+b[e].w;if(a<=c)return false}return true};THREE.Frustum.__v1=new THREE.Vector3; -THREE.Ray=function(a,b){function c(a,b,c){q.sub(c,a);u=q.dot(b);t=n.add(a,r.copy(b).multiplyScalar(u));return y=c.distanceTo(t)}function d(a,b,c,d){q.sub(d,b);n.sub(c,b);r.sub(a,b);s=q.dot(q);x=q.dot(n);D=q.dot(r);C=n.dot(n);z=n.dot(r);v=1/(s*C-x*x);F=(C*D-x*z)*v;I=(s*z-x*D)*v;return F>=0&&I>=0&&F+I<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var e=1.0E-4;this.setPrecision=function(a){e=a};var f=new THREE.Vector3,g=new THREE.Vector3,h=new THREE.Vector3,j=new THREE.Vector3, -k=new THREE.Vector3,l=new THREE.Vector3,o=new THREE.Vector3,m=new THREE.Vector3,p=new THREE.Vector3;this.intersectObject=function(a){var b,n=[];if(a instanceof THREE.Particle){var q=c(this.origin,this.direction,a.matrixWorld.getPosition());if(q>a.scale.x)return[];b={distance:q,point:a.position,face:null,object:a};n.push(b)}else if(a instanceof THREE.Mesh){var q=c(this.origin,this.direction,a.matrixWorld.getPosition()),r=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(), -a.matrixWorld.getColumnZ().length());if(q>a.geometry.boundingSphere.radius*Math.max(r.x,Math.max(r.y,r.z)))return n;var s,t,i=a.geometry,u=i.vertices,v;a.matrixRotationWorld.extractRotation(a.matrixWorld);q=0;for(r=i.faces.length;q0:s<0))){p.add(k,l.multiplyScalar(t));if(b instanceof THREE.Face3){f=v.multiplyVector3(f.copy(u[b.a]));g=v.multiplyVector3(g.copy(u[b.b]));h=v.multiplyVector3(h.copy(u[b.c]));if(d(p,f,g,h)){b={distance:k.distanceTo(p),point:p.clone(),face:b,object:a};n.push(b)}}else if(b instanceof THREE.Face4){f=v.multiplyVector3(f.copy(u[b.a]));g=v.multiplyVector3(g.copy(u[b.b]));h=v.multiplyVector3(h.copy(u[b.c]));j=v.multiplyVector3(j.copy(u[b.d]));if(d(p,f,g,j)||d(p,g,h,j)){b={distance:k.distanceTo(p),point:p.clone(), +THREE.Ray=function(a,b){function c(a,b,c){q.sub(c,a);u=q.dot(b);t=n.add(a,r.copy(b).multiplyScalar(u));return y=c.distanceTo(t)}function d(a,b,c,d){q.sub(d,b);n.sub(c,b);r.sub(a,b);s=q.dot(q);x=q.dot(n);D=q.dot(r);C=n.dot(n);z=n.dot(r);v=1/(s*C-x*x);F=(C*D-x*z)*v;I=(s*z-x*D)*v;return F>=0&&I>=0&&F+I<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var e=1.0E-4;this.setPrecision=function(a){e=a};var f=new THREE.Vector3,g=new THREE.Vector3,h=new THREE.Vector3,k=new THREE.Vector3, +j=new THREE.Vector3,l=new THREE.Vector3,o=new THREE.Vector3,m=new THREE.Vector3,p=new THREE.Vector3;this.intersectObject=function(a){var b,n=[];if(a instanceof THREE.Particle){var q=c(this.origin,this.direction,a.matrixWorld.getPosition());if(q>a.scale.x)return[];b={distance:q,point:a.position,face:null,object:a};n.push(b)}else if(a instanceof THREE.Mesh){var q=c(this.origin,this.direction,a.matrixWorld.getPosition()),r=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(), +a.matrixWorld.getColumnZ().length());if(q>a.geometry.boundingSphere.radius*Math.max(r.x,Math.max(r.y,r.z)))return n;var s,t,i=a.geometry,u=i.vertices,v;a.matrixRotationWorld.extractRotation(a.matrixWorld);q=0;for(r=i.faces.length;q0:s<0))){p.add(j,l.multiplyScalar(t));if(b instanceof THREE.Face3){f=v.multiplyVector3(f.copy(u[b.a]));g=v.multiplyVector3(g.copy(u[b.b]));h=v.multiplyVector3(h.copy(u[b.c]));if(d(p,f,g,h)){b={distance:j.distanceTo(p),point:p.clone(),face:b,object:a};n.push(b)}}else if(b instanceof THREE.Face4){f=v.multiplyVector3(f.copy(u[b.a]));g=v.multiplyVector3(g.copy(u[b.b]));h=v.multiplyVector3(h.copy(u[b.c]));k=v.multiplyVector3(k.copy(u[b.d]));if(d(p,f,g,k)||d(p,g,h,k)){b={distance:j.distanceTo(p),point:p.clone(), face:b,object:a};n.push(b)}}}}}}return n};this.intersectObjects=function(a){for(var b=[],c=0,d=a.length;cf?d:f;e=e>g? e:g}a()};this.add3Points=function(f,g,l,o,m,p){if(h){h=false;b=fl?f>m?f:m:l>m?l:m;e=g>o?g>p?g:p:o>p?o:p}else{b=fl?f>m?f>d?f:d:m>d?m:d:l>m?l>d?l:d:m>d?m:d;e=g>o?g>p?g>e?g:e:p>e?p:e:o>p?o>e?o:e:p>e?p:e}a()};this.addRectangle=function(f){if(h){h=false;b=f.getLeft();c=f.getTop();d=f.getRight();e=f.getBottom()}else{b=bf.getRight()?d:f.getRight();e=e>f.getBottom()?e:f.getBottom()}a()};this.inflate=function(f){b=b-f;c=c-f;d=d+f;e=e+f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=da.getRight()||ea.getBottom()?false:true};this.empty=function(){h=true;e=d=c=b=0;a()};this.isEmpty=function(){return h}}; THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return a0?1:0}};THREE.Matrix3=function(){this.elements=new Float32Array(9)}; -THREE.Matrix3.prototype={constructor:THREE.Matrix3,getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*b[4]+b[6]*b[8],f=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],h=b[9]*b[4]-b[5]*b[8],j=-b[9]*b[0]+b[1]*b[8],k=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*h;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,l=this.elements;l[0]=b*a;l[1]=b*c;l[2]=b*d;l[3]=b*e;l[4]=b*f;l[5]=b*g;l[6]=b*h;l[7]=b*j;l[8]=b*k;return this}, -transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,f,g,h,j,k,l,o,m,p,q,n){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,j||0,k||0,l!==void 0?l:1,o||0,m||0,p||0,q||0,n!==void 0?n:1)}; -THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,f,g,h,j,k,l,o,m,p,q,n){var r=this.elements;r[0]=a;r[4]=b;r[8]=c;r[12]=d;r[1]=e;r[5]=f;r[9]=g;r[13]=h;r[2]=j;r[6]=k;r[10]=l;r[14]=o;r[3]=m;r[7]=p;r[11]=q;r[15]=n;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){a=a.elements;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this},lookAt:function(a,b,c){var d=this.elements, -e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;e.cross(c,g).normalize();if(e.length()===0){g.x=g.x+1.0E-4;e.cross(c,g).normalize()}f.cross(g,e);d[0]=e.x;d[4]=f.x;d[8]=g.x;d[1]=e.y;d[5]=f.y;d[9]=g.y;d[2]=e.z;d[6]=f.z;d[10]=g.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,e=this.elements,f=c[0],g=c[4],h=c[8],j=c[12],k=c[1],l=c[5],o=c[9],m=c[13],p=c[2],q=c[6],n=c[10],r=c[14],u=c[3],t=c[7],y=c[11],c=c[15],s=d[0],x=d[4], -D=d[8],C=d[12],z=d[1],v=d[5],F=d[9],I=d[13],O=d[2],T=d[6],S=d[10],B=d[14],K=d[3],L=d[7],G=d[11],d=d[15];e[0]=f*s+g*z+h*O+j*K;e[4]=f*x+g*v+h*T+j*L;e[8]=f*D+g*F+h*S+j*G;e[12]=f*C+g*I+h*B+j*d;e[1]=k*s+l*z+o*O+m*K;e[5]=k*x+l*v+o*T+m*L;e[9]=k*D+l*F+o*S+m*G;e[13]=k*C+l*I+o*B+m*d;e[2]=p*s+q*z+n*O+r*K;e[6]=p*x+q*v+n*T+r*L;e[10]=p*D+q*F+n*S+r*G;e[14]=p*C+q*I+n*B+r*d;e[3]=u*s+t*z+y*O+c*K;e[7]=u*x+t*v+y*T+c*L;e[11]=u*D+t*F+y*S+c*G;e[15]=u*C+t*I+y*B+c*d;return this},multiplySelf:function(a){return this.multiply(this, +THREE.Matrix3.prototype={constructor:THREE.Matrix3,getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*b[4]+b[6]*b[8],f=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],h=b[9]*b[4]-b[5]*b[8],k=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*h;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,l=this.elements;l[0]=b*a;l[1]=b*c;l[2]=b*d;l[3]=b*e;l[4]=b*f;l[5]=b*g;l[6]=b*h;l[7]=b*k;l[8]=b*j;return this}, +transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,f,g,h,k,j,l,o,m,p,q,n){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,k||0,j||0,l!==void 0?l:1,o||0,m||0,p||0,q||0,n!==void 0?n:1)}; +THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,f,g,h,k,j,l,o,m,p,q,n){var r=this.elements;r[0]=a;r[4]=b;r[8]=c;r[12]=d;r[1]=e;r[5]=f;r[9]=g;r[13]=h;r[2]=k;r[6]=j;r[10]=l;r[14]=o;r[3]=m;r[7]=p;r[11]=q;r[15]=n;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){a=a.elements;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this},lookAt:function(a,b,c){var d=this.elements, +e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;e.cross(c,g).normalize();if(e.length()===0){g.x=g.x+1.0E-4;e.cross(c,g).normalize()}f.cross(g,e);d[0]=e.x;d[4]=f.x;d[8]=g.x;d[1]=e.y;d[5]=f.y;d[9]=g.y;d[2]=e.z;d[6]=f.z;d[10]=g.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,e=this.elements,f=c[0],g=c[4],h=c[8],k=c[12],j=c[1],l=c[5],o=c[9],m=c[13],p=c[2],q=c[6],n=c[10],r=c[14],u=c[3],t=c[7],y=c[11],c=c[15],s=d[0],x=d[4], +D=d[8],C=d[12],z=d[1],v=d[5],F=d[9],I=d[13],O=d[2],T=d[6],S=d[10],B=d[14],K=d[3],L=d[7],G=d[11],d=d[15];e[0]=f*s+g*z+h*O+k*K;e[4]=f*x+g*v+h*T+k*L;e[8]=f*D+g*F+h*S+k*G;e[12]=f*C+g*I+h*B+k*d;e[1]=j*s+l*z+o*O+m*K;e[5]=j*x+l*v+o*T+m*L;e[9]=j*D+l*F+o*S+m*G;e[13]=j*C+l*I+o*B+m*d;e[2]=p*s+q*z+n*O+r*K;e[6]=p*x+q*v+n*T+r*L;e[10]=p*D+q*F+n*S+r*G;e[14]=p*C+q*I+n*B+r*d;e[3]=u*s+t*z+y*O+c*K;e[7]=u*x+t*v+y*T+c*L;e[11]=u*D+t*F+y*S+c*G;e[15]=u*C+t*I+y*B+c*d;return this},multiplySelf:function(a){return this.multiply(this, a)},multiplyToArray:function(a,b,c){var d=this.elements;this.multiply(a,b);c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[5]=d[5];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12];c[13]=d[13];c[14]=d[14];c[15]=d[15];return this},multiplyScalar:function(a){var b=this.elements;b[0]=b[0]*a;b[4]=b[4]*a;b[8]=b[8]*a;b[12]=b[12]*a;b[1]=b[1]*a;b[5]=b[5]*a;b[9]=b[9]*a;b[13]=b[13]*a;b[2]=b[2]*a;b[6]=b[6]*a;b[10]=b[10]*a;b[14]=b[14]*a;b[3]=b[3]*a;b[7]=b[7]*a;b[11]=b[11]*a;b[15]= b[15]*a;return this},multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=1/(b[3]*c+b[7]*d+b[11]*e+b[15]);a.x=(b[0]*c+b[4]*d+b[8]*e+b[12])*f;a.y=(b[1]*c+b[5]*d+b[9]*e+b[13])*f;a.z=(b[2]*c+b[6]*d+b[10]*e+b[14])*f;return a},multiplyVector4:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w;a.x=b[0]*c+b[4]*d+b[8]*e+b[12]*f;a.y=b[1]*c+b[5]*d+b[9]*e+b[13]*f;a.z=b[2]*c+b[6]*d+b[10]*e+b[14]*f;a.w=b[3]*c+b[7]*d+b[11]*e+b[15]*f;return a},rotateAxis:function(a){var b=this.elements,c=a.x, -d=a.y,e=a.z;a.x=c*b[0]+d*b[4]+e*b[8];a.y=c*b[1]+d*b[5]+e*b[9];a.z=c*b[2]+d*b[6]+e*b[10];a.normalize();return a},crossVector:function(a){var b=this.elements,c=new THREE.Vector4;c.x=b[0]*a.x+b[4]*a.y+b[8]*a.z+b[12]*a.w;c.y=b[1]*a.x+b[5]*a.y+b[9]*a.z+b[13]*a.w;c.z=b[2]*a.x+b[6]*a.y+b[10]*a.z+b[14]*a.w;c.w=a.w?b[3]*a.x+b[7]*a.y+b[11]*a.z+b[15]*a.w:1;return c},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],e=a[12],f=a[1],g=a[5],h=a[9],j=a[13],k=a[2],l=a[6],o=a[10],m=a[14],p=a[3],q=a[7], -n=a[11],a=a[15];return e*h*l*p-d*j*l*p-e*g*o*p+c*j*o*p+d*g*m*p-c*h*m*p-e*h*k*q+d*j*k*q+e*f*o*q-b*j*o*q-d*f*m*q+b*h*m*q+e*g*k*n-c*j*k*n-e*f*l*n+b*j*l*n+c*f*m*n-b*g*m*n-d*g*k*a+c*h*k*a+d*f*l*a-b*h*l*a-c*f*o*a+b*g*o*a},transpose:function(){var a=this.elements,b;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},flattenToArray:function(a){var b=this.elements;a[0]=b[0];a[1]=b[1];a[2]=b[2]; +d=a.y,e=a.z;a.x=c*b[0]+d*b[4]+e*b[8];a.y=c*b[1]+d*b[5]+e*b[9];a.z=c*b[2]+d*b[6]+e*b[10];a.normalize();return a},crossVector:function(a){var b=this.elements,c=new THREE.Vector4;c.x=b[0]*a.x+b[4]*a.y+b[8]*a.z+b[12]*a.w;c.y=b[1]*a.x+b[5]*a.y+b[9]*a.z+b[13]*a.w;c.z=b[2]*a.x+b[6]*a.y+b[10]*a.z+b[14]*a.w;c.w=a.w?b[3]*a.x+b[7]*a.y+b[11]*a.z+b[15]*a.w:1;return c},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],e=a[12],f=a[1],g=a[5],h=a[9],k=a[13],j=a[2],l=a[6],o=a[10],m=a[14],p=a[3],q=a[7], +n=a[11],a=a[15];return e*h*l*p-d*k*l*p-e*g*o*p+c*k*o*p+d*g*m*p-c*h*m*p-e*h*j*q+d*k*j*q+e*f*o*q-b*k*o*q-d*f*m*q+b*h*m*q+e*g*j*n-c*k*j*n-e*f*l*n+b*k*l*n+c*f*m*n-b*g*m*n-d*g*j*a+c*h*j*a+d*f*l*a-b*h*l*a-c*f*o*a+b*g*o*a},transpose:function(){var a=this.elements,b;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},flattenToArray:function(a){var b=this.elements;a[0]=b[0];a[1]=b[1];a[2]=b[2]; a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return a},flattenToArrayOffset:function(a,b){var c=this.elements;a[b]=c[0];a[b+1]=c[1];a[b+2]=c[2];a[b+3]=c[3];a[b+4]=c[4];a[b+5]=c[5];a[b+6]=c[6];a[b+7]=c[7];a[b+8]=c[8];a[b+9]=c[9];a[b+10]=c[10];a[b+11]=c[11];a[b+12]=c[12];a[b+13]=c[13];a[b+14]=c[14];a[b+15]=c[15];return a},getPosition:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[12],a[13], -a[14])},setPosition:function(a){var b=this.elements;b[12]=a.x;b[13]=a.y;b[14]=a.z;return this},getColumnX:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[0],a[1],a[2])},getColumnY:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[4],a[5],a[6])},getColumnZ:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[8],a[9],a[10])},getInverse:function(a){var b=this.elements,c=a.elements,d=c[0],e=c[4],f=c[8],g=c[12],h=c[1],j=c[5],k=c[9],l=c[13],o=c[2],m=c[6],p=c[10],q= -c[14],n=c[3],r=c[7],u=c[11],c=c[15];b[0]=k*q*r-l*p*r+l*m*u-j*q*u-k*m*c+j*p*c;b[4]=g*p*r-f*q*r-g*m*u+e*q*u+f*m*c-e*p*c;b[8]=f*l*r-g*k*r+g*j*u-e*l*u-f*j*c+e*k*c;b[12]=g*k*m-f*l*m-g*j*p+e*l*p+f*j*q-e*k*q;b[1]=l*p*n-k*q*n-l*o*u+h*q*u+k*o*c-h*p*c;b[5]=f*q*n-g*p*n+g*o*u-d*q*u-f*o*c+d*p*c;b[9]=g*k*n-f*l*n-g*h*u+d*l*u+f*h*c-d*k*c;b[13]=f*l*o-g*k*o+g*h*p-d*l*p-f*h*q+d*k*q;b[2]=j*q*n-l*m*n+l*o*r-h*q*r-j*o*c+h*m*c;b[6]=g*m*n-e*q*n-g*o*r+d*q*r+e*o*c-d*m*c;b[10]=e*l*n-g*j*n+g*h*r-d*l*r-e*h*c+d*j*c;b[14]=g*j*o- -e*l*o-g*h*m+d*l*m+e*h*q-d*j*q;b[3]=k*m*n-j*p*n-k*o*r+h*p*r+j*o*u-h*m*u;b[7]=e*p*n-f*m*n+f*o*r-d*p*r-e*o*u+d*m*u;b[11]=f*j*n-e*k*n-f*h*r+d*k*r+e*h*u-d*j*u;b[15]=e*k*o-f*j*o+f*h*m-d*k*m-e*h*p+d*j*p;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,e=a.y,f=a.z,g=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e),j=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var k=h*j,l=h*f,o=e*j,m=e*f;c[0]=k+m*d;c[4]=o*d-l;c[8]=g*e;c[1]=g*f;c[5]=g* -j;c[9]=-d;c[2]=l*d-o;c[6]=m+k*d;c[10]=g*h;break;case "ZXY":k=h*j;l=h*f;o=e*j;m=e*f;c[0]=k-m*d;c[4]=-g*f;c[8]=o+l*d;c[1]=l+o*d;c[5]=g*j;c[9]=m-k*d;c[2]=-g*e;c[6]=d;c[10]=g*h;break;case "ZYX":k=g*j;l=g*f;o=d*j;m=d*f;c[0]=h*j;c[4]=o*e-l;c[8]=k*e+m;c[1]=h*f;c[5]=m*e+k;c[9]=l*e-o;c[2]=-e;c[6]=d*h;c[10]=g*h;break;case "YZX":k=g*h;l=g*e;o=d*h;m=d*e;c[0]=h*j;c[4]=m-k*f;c[8]=o*f+l;c[1]=f;c[5]=g*j;c[9]=-d*j;c[2]=-e*j;c[6]=l*f+o;c[10]=k-m*f;break;case "XZY":k=g*h;l=g*e;o=d*h;m=d*e;c[0]=h*j;c[4]=-f;c[8]=e*j; -c[1]=k*f+m;c[5]=g*j;c[9]=l*f-o;c[2]=o*f-l;c[6]=d*j;c[10]=m*f+k;break;default:k=g*j;l=g*f;o=d*j;m=d*f;c[0]=h*j;c[4]=-h*f;c[8]=e;c[1]=l+o*e;c[5]=k-m*e;c[9]=-d*h;c[2]=m-k*e;c[6]=o+l*e;c[10]=g*h}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,h=d+d,j=e+e,a=c*g,k=c*h,c=c*j,l=d*h,d=d*j,e=e*j,g=f*g,h=f*h,f=f*j;b[0]=1-(l+e);b[4]=k-f;b[8]=c+h;b[1]=k+f;b[5]=1-(a+e);b[9]=d-g;b[2]=c-h;b[6]=d+g;b[10]=1-(a+l);return this},compose:function(a,b,c){var d=this.elements, +a[14])},setPosition:function(a){var b=this.elements;b[12]=a.x;b[13]=a.y;b[14]=a.z;return this},getColumnX:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[0],a[1],a[2])},getColumnY:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[4],a[5],a[6])},getColumnZ:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[8],a[9],a[10])},getInverse:function(a){var b=this.elements,c=a.elements,d=c[0],e=c[4],f=c[8],g=c[12],h=c[1],k=c[5],j=c[9],l=c[13],o=c[2],m=c[6],p=c[10],q= +c[14],n=c[3],r=c[7],u=c[11],c=c[15];b[0]=j*q*r-l*p*r+l*m*u-k*q*u-j*m*c+k*p*c;b[4]=g*p*r-f*q*r-g*m*u+e*q*u+f*m*c-e*p*c;b[8]=f*l*r-g*j*r+g*k*u-e*l*u-f*k*c+e*j*c;b[12]=g*j*m-f*l*m-g*k*p+e*l*p+f*k*q-e*j*q;b[1]=l*p*n-j*q*n-l*o*u+h*q*u+j*o*c-h*p*c;b[5]=f*q*n-g*p*n+g*o*u-d*q*u-f*o*c+d*p*c;b[9]=g*j*n-f*l*n-g*h*u+d*l*u+f*h*c-d*j*c;b[13]=f*l*o-g*j*o+g*h*p-d*l*p-f*h*q+d*j*q;b[2]=k*q*n-l*m*n+l*o*r-h*q*r-k*o*c+h*m*c;b[6]=g*m*n-e*q*n-g*o*r+d*q*r+e*o*c-d*m*c;b[10]=e*l*n-g*k*n+g*h*r-d*l*r-e*h*c+d*k*c;b[14]=g*k*o- +e*l*o-g*h*m+d*l*m+e*h*q-d*k*q;b[3]=j*m*n-k*p*n-j*o*r+h*p*r+k*o*u-h*m*u;b[7]=e*p*n-f*m*n+f*o*r-d*p*r-e*o*u+d*m*u;b[11]=f*k*n-e*j*n-f*h*r+d*j*r+e*h*u-d*k*u;b[15]=e*j*o-f*k*o+f*h*m-d*j*m-e*h*p+d*k*p;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,e=a.y,f=a.z,g=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e),k=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var j=h*k,l=h*f,o=e*k,m=e*f;c[0]=j+m*d;c[4]=o*d-l;c[8]=g*e;c[1]=g*f;c[5]=g* +k;c[9]=-d;c[2]=l*d-o;c[6]=m+j*d;c[10]=g*h;break;case "ZXY":j=h*k;l=h*f;o=e*k;m=e*f;c[0]=j-m*d;c[4]=-g*f;c[8]=o+l*d;c[1]=l+o*d;c[5]=g*k;c[9]=m-j*d;c[2]=-g*e;c[6]=d;c[10]=g*h;break;case "ZYX":j=g*k;l=g*f;o=d*k;m=d*f;c[0]=h*k;c[4]=o*e-l;c[8]=j*e+m;c[1]=h*f;c[5]=m*e+j;c[9]=l*e-o;c[2]=-e;c[6]=d*h;c[10]=g*h;break;case "YZX":j=g*h;l=g*e;o=d*h;m=d*e;c[0]=h*k;c[4]=m-j*f;c[8]=o*f+l;c[1]=f;c[5]=g*k;c[9]=-d*k;c[2]=-e*k;c[6]=l*f+o;c[10]=j-m*f;break;case "XZY":j=g*h;l=g*e;o=d*h;m=d*e;c[0]=h*k;c[4]=-f;c[8]=e*k; +c[1]=j*f+m;c[5]=g*k;c[9]=l*f-o;c[2]=o*f-l;c[6]=d*k;c[10]=m*f+j;break;default:j=g*k;l=g*f;o=d*k;m=d*f;c[0]=h*k;c[4]=-h*f;c[8]=e;c[1]=l+o*e;c[5]=j-m*e;c[9]=-d*h;c[2]=m-j*e;c[6]=o+l*e;c[10]=g*h}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,h=d+d,k=e+e,a=c*g,j=c*h,c=c*k,l=d*h,d=d*k,e=e*k,g=f*g,h=f*h,f=f*k;b[0]=1-(l+e);b[4]=j-f;b[8]=c+h;b[1]=j+f;b[5]=1-(a+e);b[9]=d-g;b[2]=c-h;b[6]=d+g;b[10]=1-(a+l);return this},compose:function(a,b,c){var d=this.elements, e=THREE.Matrix4.__m1,f=THREE.Matrix4.__m2;e.identity();e.setRotationFromQuaternion(b);f.makeScale(c.x,c.y,c.z);this.multiply(e,f);d[12]=a.x;d[13]=a.y;d[14]=a.z;return this},decompose:function(a,b,c){var d=this.elements,e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;e.set(d[0],d[1],d[2]);f.set(d[4],d[5],d[6]);g.set(d[8],d[9],d[10]);a=a instanceof THREE.Vector3?a:new THREE.Vector3;b=b instanceof THREE.Quaternion?b:new THREE.Quaternion;c=c instanceof THREE.Vector3?c:new THREE.Vector3; c.x=e.length();c.y=f.length();c.z=g.length();a.x=d[12];a.y=d[13];a.z=d[14];d=THREE.Matrix4.__m1;d.copy(this);d.elements[0]=d.elements[0]/c.x;d.elements[1]=d.elements[1]/c.x;d.elements[2]=d.elements[2]/c.x;d.elements[4]=d.elements[4]/c.y;d.elements[5]=d.elements[5]/c.y;d.elements[6]=d.elements[6]/c.y;d.elements[8]=d.elements[8]/c.z;d.elements[9]=d.elements[9]/c.z;d.elements[10]=d.elements[10]/c.z;b.setFromRotationMatrix(d);return[a,b,c]},extractPosition:function(a){var b=this.elements,a=a.elements; b[12]=a[12];b[13]=a[13];b[14]=a[14];return this},extractRotation:function(a){var b=this.elements,a=a.elements,c=THREE.Matrix4.__v1,d=1/c.set(a[0],a[1],a[2]).length(),e=1/c.set(a[4],a[5],a[6]).length(),c=1/c.set(a[8],a[9],a[10]).length();b[0]=a[0]*d;b[1]=a[1]*d;b[2]=a[2]*d;b[4]=a[4]*e;b[5]=a[5]*e;b[6]=a[6]*e;b[8]=a[8]*c;b[9]=a[9]*c;b[10]=a[10]*c;return this},translate:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[12]=b[0]*c+b[4]*d+b[8]*a+b[12];b[13]=b[1]*c+b[5]*d+b[9]*a+b[13];b[14]=b[2]*c+b[6]* -d+b[10]*a+b[14];b[15]=b[3]*c+b[7]*d+b[11]*a+b[15];return this},rotateX:function(a){var b=this.elements,c=b[4],d=b[5],e=b[6],f=b[7],g=b[8],h=b[9],j=b[10],k=b[11],l=Math.cos(a),a=Math.sin(a);b[4]=l*c+a*g;b[5]=l*d+a*h;b[6]=l*e+a*j;b[7]=l*f+a*k;b[8]=l*g-a*c;b[9]=l*h-a*d;b[10]=l*j-a*e;b[11]=l*k-a*f;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[8],h=b[9],j=b[10],k=b[11],l=Math.cos(a),a=Math.sin(a);b[0]=l*c-a*g;b[1]=l*d-a*h;b[2]=l*e-a*j;b[3]=l*f-a*k;b[8]=l*g+a*c;b[9]= -l*h+a*d;b[10]=l*j+a*e;b[11]=l*k+a*f;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],j=b[6],k=b[7],l=Math.cos(a),a=Math.sin(a);b[0]=l*c+a*g;b[1]=l*d+a*h;b[2]=l*e+a*j;b[3]=l*f+a*k;b[4]=l*g-a*c;b[5]=l*h-a*d;b[6]=l*j-a*e;b[7]=l*k-a*f;return this},rotateByAxis:function(a,b){var c=this.elements;if(a.x===1&&a.y===0&&a.z===0)return this.rotateX(b);if(a.x===0&&a.y===1&&a.z===0)return this.rotateY(b);if(a.x===0&&a.y===0&&a.z===1)return this.rotateZ(b);var d=a.x, -e=a.y,f=a.z,g=Math.sqrt(d*d+e*e+f*f),d=d/g,e=e/g,f=f/g,g=d*d,h=e*e,j=f*f,k=Math.cos(b),l=Math.sin(b),o=1-k,m=d*e*o,p=d*f*o,o=e*f*o,d=d*l,q=e*l,l=f*l,f=g+(1-g)*k,g=m+l,e=p-q,m=m-l,h=h+(1-h)*k,l=o+d,p=p+q,o=o-d,j=j+(1-j)*k,k=c[0],d=c[1],q=c[2],n=c[3],r=c[4],u=c[5],t=c[6],y=c[7],s=c[8],x=c[9],D=c[10],C=c[11];c[0]=f*k+g*r+e*s;c[1]=f*d+g*u+e*x;c[2]=f*q+g*t+e*D;c[3]=f*n+g*y+e*C;c[4]=m*k+h*r+l*s;c[5]=m*d+h*u+l*x;c[6]=m*q+h*t+l*D;c[7]=m*n+h*y+l*C;c[8]=p*k+o*r+j*s;c[9]=p*d+o*u+j*x;c[10]=p*q+o*t+j*D;c[11]= -p*n+o*y+j*C;return this},scale:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[0]=b[0]*c;b[4]=b[4]*d;b[8]=b[8]*a;b[1]=b[1]*c;b[5]=b[5]*d;b[9]=b[9]*a;b[2]=b[2]*c;b[6]=b[6]*d;b[10]=b[10]*a;b[3]=b[3]*c;b[7]=b[7]*d;b[11]=b[11]*a;return this},getMaxScaleOnAxis:function(){var a=this.elements;return Math.sqrt(Math.max(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],Math.max(a[4]*a[4]+a[5]*a[5]+a[6]*a[6],a[8]*a[8]+a[9]*a[9]+a[10]*a[10])))},makeTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this}, -makeRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},makeRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},makeRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,f=a.x,g=a.y,h=a.z,j=e*f,k=e*g;this.set(j*f+c,j*g-d*h,j*h+d*g,0,j*g+d*h,k*g+c,k*h-d*f,0,j*h- -d*g,k*h+d*f,e*h*h+c,0,0,0,0,1);return this},makeScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},makeFrustum:function(a,b,c,d,e,f){var g=this.elements;g[0]=2*e/(b-a);g[4]=0;g[8]=(b+a)/(b-a);g[12]=0;g[1]=0;g[5]=2*e/(d-c);g[9]=(d+c)/(d-c);g[13]=0;g[2]=0;g[6]=0;g[10]=-(f+e)/(f-e);g[14]=-2*f*e/(f-e);g[3]=0;g[7]=0;g[11]=-1;g[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),e=-a;return this.makeFrustum(e*b,a*b,e,a,c,d)},makeOrthographic:function(a, -b,c,d,e,f){var g=this.elements,h=b-a,j=c-d,k=f-e;g[0]=2/h;g[4]=0;g[8]=0;g[12]=-((b+a)/h);g[1]=0;g[5]=2/j;g[9]=0;g[13]=-((c+d)/j);g[2]=0;g[6]=0;g[10]=-2/k;g[14]=-((f+e)/k);g[3]=0;g[7]=0;g[11]=0;g[15]=1;return this},clone:function(){var a=this.elements;return new THREE.Matrix4(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15])}};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;THREE.Matrix4.__m1=new THREE.Matrix4; +d+b[10]*a+b[14];b[15]=b[3]*c+b[7]*d+b[11]*a+b[15];return this},rotateX:function(a){var b=this.elements,c=b[4],d=b[5],e=b[6],f=b[7],g=b[8],h=b[9],k=b[10],j=b[11],l=Math.cos(a),a=Math.sin(a);b[4]=l*c+a*g;b[5]=l*d+a*h;b[6]=l*e+a*k;b[7]=l*f+a*j;b[8]=l*g-a*c;b[9]=l*h-a*d;b[10]=l*k-a*e;b[11]=l*j-a*f;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[8],h=b[9],k=b[10],j=b[11],l=Math.cos(a),a=Math.sin(a);b[0]=l*c-a*g;b[1]=l*d-a*h;b[2]=l*e-a*k;b[3]=l*f-a*j;b[8]=l*g+a*c;b[9]= +l*h+a*d;b[10]=l*k+a*e;b[11]=l*j+a*f;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],k=b[6],j=b[7],l=Math.cos(a),a=Math.sin(a);b[0]=l*c+a*g;b[1]=l*d+a*h;b[2]=l*e+a*k;b[3]=l*f+a*j;b[4]=l*g-a*c;b[5]=l*h-a*d;b[6]=l*k-a*e;b[7]=l*j-a*f;return this},rotateByAxis:function(a,b){var c=this.elements;if(a.x===1&&a.y===0&&a.z===0)return this.rotateX(b);if(a.x===0&&a.y===1&&a.z===0)return this.rotateY(b);if(a.x===0&&a.y===0&&a.z===1)return this.rotateZ(b);var d=a.x, +e=a.y,f=a.z,g=Math.sqrt(d*d+e*e+f*f),d=d/g,e=e/g,f=f/g,g=d*d,h=e*e,k=f*f,j=Math.cos(b),l=Math.sin(b),o=1-j,m=d*e*o,p=d*f*o,o=e*f*o,d=d*l,q=e*l,l=f*l,f=g+(1-g)*j,g=m+l,e=p-q,m=m-l,h=h+(1-h)*j,l=o+d,p=p+q,o=o-d,k=k+(1-k)*j,j=c[0],d=c[1],q=c[2],n=c[3],r=c[4],u=c[5],t=c[6],y=c[7],s=c[8],x=c[9],D=c[10],C=c[11];c[0]=f*j+g*r+e*s;c[1]=f*d+g*u+e*x;c[2]=f*q+g*t+e*D;c[3]=f*n+g*y+e*C;c[4]=m*j+h*r+l*s;c[5]=m*d+h*u+l*x;c[6]=m*q+h*t+l*D;c[7]=m*n+h*y+l*C;c[8]=p*j+o*r+k*s;c[9]=p*d+o*u+k*x;c[10]=p*q+o*t+k*D;c[11]= +p*n+o*y+k*C;return this},scale:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[0]=b[0]*c;b[4]=b[4]*d;b[8]=b[8]*a;b[1]=b[1]*c;b[5]=b[5]*d;b[9]=b[9]*a;b[2]=b[2]*c;b[6]=b[6]*d;b[10]=b[10]*a;b[3]=b[3]*c;b[7]=b[7]*d;b[11]=b[11]*a;return this},getMaxScaleOnAxis:function(){var a=this.elements;return Math.sqrt(Math.max(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],Math.max(a[4]*a[4]+a[5]*a[5]+a[6]*a[6],a[8]*a[8]+a[9]*a[9]+a[10]*a[10])))},makeTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this}, +makeRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},makeRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},makeRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,f=a.x,g=a.y,h=a.z,k=e*f,j=e*g;this.set(k*f+c,k*g-d*h,k*h+d*g,0,k*g+d*h,j*g+c,j*h-d*f,0,k*h- +d*g,j*h+d*f,e*h*h+c,0,0,0,0,1);return this},makeScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},makeFrustum:function(a,b,c,d,e,f){var g=this.elements;g[0]=2*e/(b-a);g[4]=0;g[8]=(b+a)/(b-a);g[12]=0;g[1]=0;g[5]=2*e/(d-c);g[9]=(d+c)/(d-c);g[13]=0;g[2]=0;g[6]=0;g[10]=-(f+e)/(f-e);g[14]=-2*f*e/(f-e);g[3]=0;g[7]=0;g[11]=-1;g[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),e=-a;return this.makeFrustum(e*b,a*b,e,a,c,d)},makeOrthographic:function(a, +b,c,d,e,f){var g=this.elements,h=b-a,k=c-d,j=f-e;g[0]=2/h;g[4]=0;g[8]=0;g[12]=-((b+a)/h);g[1]=0;g[5]=2/k;g[9]=0;g[13]=-((c+d)/k);g[2]=0;g[6]=0;g[10]=-2/j;g[14]=-((f+e)/j);g[3]=0;g[7]=0;g[11]=0;g[15]=1;return this},clone:function(){var a=this.elements;return new THREE.Matrix4(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15])}};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;THREE.Matrix4.__m1=new THREE.Matrix4; THREE.Matrix4.__m2=new THREE.Matrix4; THREE.Object3D=function(){this.id=THREE.Object3DCount++;this.name="";this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=false;this.renderDepth=null;this.rotationAutoUpdate=true;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate= true;this.quaternion=new THREE.Quaternion;this.useQuaternion=false;this.boundRadius=0;this.boundRadiusScale=1;this.visible=true;this.receiveShadow=this.castShadow=false;this.frustumCulled=true;this._vector=new THREE.Vector3}; @@ -63,23 +63,23 @@ this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position, this.children.indexOf(a);if(b!==-1){a.parent=void 0;this.children.splice(b,1);for(b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__removeObject(a)}},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c=0&&f>=0&&g>=0&&h>=0)return true;if(e<0&&f<0||g<0&&h<0)return false;e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f)));g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h)));if(d=0&&f>=0&&g>=0&&h>=0)return true;if(e<0&&f<0||g<0&&h<0)return false;e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f)));g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h)));if(dg&&h.positionScreen.zg&&h.positionScreen.z0)){ea=k[j-2];I.copy(H.positionScreen);O.copy(ea.positionScreen);if(d(I,O)){I.multiplyScalar(1/I.w);O.multiplyScalar(1/O.w);P=u[r]=u[r]||new THREE.RenderableLine;r++;n=P;n.v1.positionScreen.copy(I); +x.elements.push(l)}}else if(Q instanceof THREE.Line){v.multiply(z,Y);da=Q.geometry.vertices;H=b();H.positionScreen.copy(da[0]);v.multiplyVector4(H.positionScreen);Y=Q.type===THREE.LinePieces?2:1;X=1;for(M=da.length;X0)){ea=j[k-2];I.copy(H.positionScreen);O.copy(ea.positionScreen);if(d(I,O)){I.multiplyScalar(1/I.w);O.multiplyScalar(1/O.w);P=u[r]=u[r]||new THREE.RenderableLine;r++;n=P;n.v1.positionScreen.copy(I); n.v2.positionScreen.copy(O);n.z=Math.max(I.z,O.z);n.material=Q.material;x.elements.push(n)}}}}}a=0;for(i=x.sprites.length;a0&&C.z<1){g=s[y]=s[y]||new THREE.RenderableParticle;y++;t=g;t.x=C.x/C.w;t.y=C.y/C.w;t.z=C.z;t.rotation=Q.rotation.z;t.scale.x=Q.scale.x*Math.abs(t.x-(C.x+e.projectionMatrix.elements[0])/(C.w+e.projectionMatrix.elements[12])); t.scale.y=Q.scale.y*Math.abs(t.y-(C.y+e.projectionMatrix.elements[5])/(C.w+e.projectionMatrix.elements[13]));t.material=Q.material;x.elements.push(t)}}}f&&x.elements.sort(c);return x}};THREE.Quaternion=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1}; THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),f=Math.cos(c),c=Math.sin(c),g=a*b,h=d*e;this.w=g*f-h*c;this.x=g*c+h*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c); this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.elements[0]+a.elements[5]+a.elements[10]))/2;this.x=Math.sqrt(Math.max(0,b+a.elements[0]-a.elements[5]-a.elements[10]))/2;this.y=Math.sqrt(Math.max(0,b-a.elements[0]+a.elements[5]-a.elements[10]))/2;this.z=Math.sqrt(Math.max(0,b-a.elements[0]-a.elements[5]+a.elements[10]))/2;this.x=a.elements[6]-a.elements[9]<0?-Math.abs(this.x): Math.abs(this.x);this.y=a.elements[8]-a.elements[2]<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.elements[1]-a.elements[4]<0?-Math.abs(this.z):Math.abs(this.z);this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x=this.x*-1;this.y=this.y*-1;this.z=this.z*-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a= Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a===0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a}return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y= -c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,j=this.w,k=j*c+g*e-h*d,l=j*d+h*c-f*e,o=j*e+f*d-g*c,c=-f*c-g*d-h*e;b.x=k*j+c*-f+l*-h-o*-g;b.y=l*j+c*-g+o*-f-k*-h;b.z=o*j+c*-h+k*-g-l*-f;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}}; +c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,k=this.w,j=k*c+g*e-h*d,l=k*d+h*c-f*e,o=k*e+f*d-g*c,c=-f*c-g*d-h*e;b.x=j*k+c*-f+l*-h-o*-g;b.y=l*k+c*-g+o*-f-j*-h;b.z=o*k+c*-h+j*-g-l*-f;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}}; THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(e<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;e=-e}else c.copy(b);if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")}; THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3}; THREE.Face3.prototype={constructor:THREE.Face3,clone:function(){var a=new THREE.Face3(this.a,this.b,this.c);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b0){var a;a=this.vertices[0];this.boundingBox.min.copy(a);this.boundingBox.max.copy(a);for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;dc.x)c.x= a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}else{this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a)}this.boundingSphere.radius=b},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g,h;f=0;for(g=this.vertices.length;f0;a--)if(d.indexOf(e["abcd"[a]])!=a){d.splice(a,1);this.faces[f]=new THREE.Face3(d[0],d[1],d[2]);e=0;for(d=this.faceVertexUvs.length;ethis.points.length-2?this.points.length-1:f+1;c[3]=f>this.points.length-3?this.points.length-1: -f+2;k=this.points[c[0]];l=this.points[c[1]];o=this.points[c[2]];m=this.points[c[3]];h=g*g;j=g*h;d.x=b(k.x,l.x,o.x,m.x,g,h,j);d.y=b(k.y,l.y,o.y,m.y,g,h,j);d.z=b(k.z,l.z,o.z,m.z,g,h,j);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;athis.points.length-2?this.points.length-1:f+1;c[3]=f>this.points.length-3?this.points.length-1: +f+2;j=this.points[c[0]];l=this.points[c[1]];o=this.points[c[2]];m=this.points[c[3]];h=g*g;k=g*h;d.x=b(j.x,l.x,o.x,m.x,g,h,k);d.y=b(j.y,l.y,o.y,m.y,g,h,k);d.z=b(j.z,l.z,o.z,m.z,g,h,k);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a1&&(O=new THREE.MeshFaceMaterial); +THREE.SceneLoader.prototype.createScene=function(a,b,c){function d(a,b){return b=="relativeToHTML"?a:j+"/"+a}function e(){var a;for(m in B.objects)if(!M.objects[m]){u=B.objects[m];if(u.geometry!==void 0){if(I=M.geometries[u.geometry]){a=false;O=M.materials[u.materials[0]];(a=O instanceof THREE.ShaderMaterial)&&I.computeTangents();x=u.position;D=u.rotation;C=u.quaternion;z=u.scale;t=u.matrix;C=0;u.materials.length==0&&(O=new THREE.MeshFaceMaterial);u.materials.length>1&&(O=new THREE.MeshFaceMaterial); a=new THREE.Mesh(I,O);a.name=m;if(t){a.matrixAutoUpdate=false;a.matrix.set(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15])}else{a.position.set(x[0],x[1],x[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(D[0],D[1],D[2]);a.scale.set(z[0],z[1],z[2])}a.visible=u.visible;a.doubleSided=u.doubleSided;a.castShadow=u.castShadow;a.receiveShadow=u.receiveShadow;M.scene.add(a);M.objects[m]=a}}else{x=u.position;D=u.rotation;C=u.quaternion; -z=u.scale;C=0;a=new THREE.Object3D;a.name=m;a.position.set(x[0],x[1],x[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(D[0],D[1],D[2]);a.scale.set(z[0],z[1],z[2]);a.visible=u.visible!==void 0?u.visible:false;M.scene.add(a);M.objects[m]=a;M.empties[m]=a}}}function f(a){return function(b){M.geometries[a]=b;e();L=L-1;j.onLoadComplete();h()}}function g(a){return function(b){M.geometries[a]=b}}function h(){j.callbackProgress({totalModels:i,totalTextures:X,loadedModels:i- -L,loadedTextures:X-G},M);j.onLoadProgress();L==0&&G==0&&b(M)}var j=this,k=THREE.Loader.prototype.extractUrlBase(c),l,o,m,p,q,n,r,u,t,y,s,x,D,C,z,v,F,I,O,T,S,B,K,L,G,i,X,M;B=a;c=new THREE.BinaryLoader;K=new THREE.JSONLoader;G=L=0;M={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(B.transform){a=B.transform.position;y=B.transform.rotation;v=B.transform.scale;a&&M.scene.position.set(a[0],a[1],a[2]);y&&M.scene.rotation.set(y[0],y[1], -y[2]);v&&M.scene.scale.set(v[0],v[1],v[2]);if(a||y||v){M.scene.updateMatrix();M.scene.updateMatrixWorld()}}a=function(){G=G-1;h();j.onLoadComplete()};for(q in B.cameras){v=B.cameras[q];v.type=="perspective"?T=new THREE.PerspectiveCamera(v.fov,v.aspect,v.near,v.far):v.type=="ortho"&&(T=new THREE.OrthographicCamera(v.left,v.right,v.top,v.bottom,v.near,v.far));x=v.position;y=v.target;v=v.up;T.position.set(x[0],x[1],x[2]);T.target=new THREE.Vector3(y[0],y[1],y[2]);v&&T.up.set(v[0],v[1],v[2]);M.cameras[q]= +z=u.scale;C=0;a=new THREE.Object3D;a.name=m;a.position.set(x[0],x[1],x[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(D[0],D[1],D[2]);a.scale.set(z[0],z[1],z[2]);a.visible=u.visible!==void 0?u.visible:false;M.scene.add(a);M.objects[m]=a;M.empties[m]=a}}}function f(a){return function(b){M.geometries[a]=b;e();L=L-1;k.onLoadComplete();h()}}function g(a){return function(b){M.geometries[a]=b}}function h(){k.callbackProgress({totalModels:i,totalTextures:X,loadedModels:i- +L,loadedTextures:X-G},M);k.onLoadProgress();L==0&&G==0&&b(M)}var k=this,j=THREE.Loader.prototype.extractUrlBase(c),l,o,m,p,q,n,r,u,t,y,s,x,D,C,z,v,F,I,O,T,S,B,K,L,G,i,X,M;B=a;c=new THREE.BinaryLoader;K=new THREE.JSONLoader;G=L=0;M={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(B.transform){a=B.transform.position;y=B.transform.rotation;v=B.transform.scale;a&&M.scene.position.set(a[0],a[1],a[2]);y&&M.scene.rotation.set(y[0],y[1], +y[2]);v&&M.scene.scale.set(v[0],v[1],v[2]);if(a||y||v){M.scene.updateMatrix();M.scene.updateMatrixWorld()}}a=function(){G=G-1;h();k.onLoadComplete()};for(q in B.cameras){v=B.cameras[q];v.type=="perspective"?T=new THREE.PerspectiveCamera(v.fov,v.aspect,v.near,v.far):v.type=="ortho"&&(T=new THREE.OrthographicCamera(v.left,v.right,v.top,v.bottom,v.near,v.far));x=v.position;y=v.target;v=v.up;T.position.set(x[0],x[1],x[2]);T.target=new THREE.Vector3(y[0],y[1],y[2]);v&&T.up.set(v[0],v[1],v[2]);M.cameras[q]= T}for(p in B.lights){y=B.lights[p];q=y.color!==void 0?y.color:16777215;T=y.intensity!==void 0?y.intensity:1;if(y.type=="directional"){x=y.direction;s=new THREE.DirectionalLight(q,T);s.position.set(x[0],x[1],x[2]);s.position.normalize()}else if(y.type=="point"){x=y.position;s=y.distance;s=new THREE.PointLight(q,T,s);s.position.set(x[0],x[1],x[2])}else y.type=="ambient"&&(s=new THREE.AmbientLight(q));M.scene.add(s);M.lights[p]=s}for(n in B.fogs){p=B.fogs[n];p.type=="linear"?S=new THREE.Fog(0,p.near, -p.far):p.type=="exp2"&&(S=new THREE.FogExp2(0,p.density));v=p.color;S.color.setRGB(v[0],v[1],v[2]);M.fogs[n]=S}if(M.cameras&&B.defaults.camera)M.currentCamera=M.cameras[B.defaults.camera];if(M.fogs&&B.defaults.fog)M.scene.fog=M.fogs[B.defaults.fog];v=B.defaults.bgcolor;M.bgColor=new THREE.Color;M.bgColor.setRGB(v[0],v[1],v[2]);M.bgColorAlpha=B.defaults.bgalpha;for(l in B.geometries){n=B.geometries[l];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){L=L+1;j.onLoadStart()}}i=L;for(l in B.geometries){n= +p.far):p.type=="exp2"&&(S=new THREE.FogExp2(0,p.density));v=p.color;S.color.setRGB(v[0],v[1],v[2]);M.fogs[n]=S}if(M.cameras&&B.defaults.camera)M.currentCamera=M.cameras[B.defaults.camera];if(M.fogs&&B.defaults.fog)M.scene.fog=M.fogs[B.defaults.fog];v=B.defaults.bgcolor;M.bgColor=new THREE.Color;M.bgColor.setRGB(v[0],v[1],v[2]);M.bgColorAlpha=B.defaults.bgalpha;for(l in B.geometries){n=B.geometries[l];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){L=L+1;k.onLoadStart()}}i=L;for(l in B.geometries){n= B.geometries[l];if(n.type=="cube"){I=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides);M.geometries[l]=I}else if(n.type=="plane"){I=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight);M.geometries[l]=I}else if(n.type=="sphere"){I=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight);M.geometries[l]=I}else if(n.type=="cylinder"){I=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs, n.heightSegs);M.geometries[l]=I}else if(n.type=="torus"){I=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT);M.geometries[l]=I}else if(n.type=="icosahedron"){I=new THREE.IcosahedronGeometry(n.radius,n.subdivisions);M.geometries[l]=I}else if(n.type=="bin_mesh")c.load(d(n.url,B.urlBaseType),f(l));else if(n.type=="ascii_mesh")K.load(d(n.url,B.urlBaseType),f(l));else if(n.type=="embedded_mesh"){n=B.embeds[n.id];n.metadata=B.metadata;n&&K.createModel(n,g(l),"")}}for(r in B.textures){l=B.textures[r]; -if(l.url instanceof Array){G=G+l.url.length;for(n=0;n0){c(THREE.NormalBlending);b(1);e("rgba("+Math.floor(r.r*255)+","+Math.floor(r.g*255)+","+Math.floor(r.b* 255)+","+u+")");n.fillRect(Math.floor(Da.getX()),Math.floor(Da.getY()),Math.floor(Da.getWidth()),Math.floor(Da.getHeight()))}Da.empty()}};this.render=function(a,l){function m(a){var b,c,d,e;ka.setRGB(0,0,0);za.setRGB(0,0,0);Na.setRGB(0,0,0);b=0;for(c=a.length;b>1;m=l.height>>1;g=f.scale.x*p;j=f.scale.y*q;i=g*k;h=j*m;xa.set(a.x-i,a.y-h,a.x+i,a.y+h);if($a.intersects(xa)){n.save();n.translate(a.x,a.y);n.rotate(-f.rotation);n.scale(g,-j);n.translate(-k,-m);n.drawImage(l,0,0);n.restore()}}}else if(g instanceof THREE.ParticleCanvasMaterial){i=f.scale.x*p;h=f.scale.y*q;xa.set(a.x-i,a.y-h,a.x+i,a.y+h);if($a.intersects(xa)){d(g.color.getContextStyle()); +Na.g=Na.g+e.g;Na.b=Na.b+e.b}}}function o(a,b,c,d){var e,f,g,i,h,k;e=0;for(f=a.length;e>1;m=l.height>>1;g=f.scale.x*p;k=f.scale.y*q;i=g*j;h=k*m;xa.set(a.x-i,a.y-h,a.x+i,a.y+h);if($a.intersects(xa)){n.save();n.translate(a.x,a.y);n.rotate(-f.rotation);n.scale(g,-k);n.translate(-j,-m);n.drawImage(l,0,0);n.restore()}}}else if(g instanceof THREE.ParticleCanvasMaterial){i=f.scale.x*p;h=f.scale.y*q;xa.set(a.x-i,a.y-h,a.x+i,a.y+h);if($a.intersects(xa)){d(g.color.getContextStyle()); e(g.color.getContextStyle());n.save();n.translate(a.x,a.y);n.rotate(-f.rotation);n.scale(i,h);g.program(n);n.restore()}}}function s(a,e,f,g){b(g.opacity);c(g.blending);n.beginPath();n.moveTo(a.positionScreen.x,a.positionScreen.y);n.lineTo(e.positionScreen.x,e.positionScreen.y);n.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(D!=a)n.lineWidth=D=a;a=g.linecap;if(C!=a)n.lineCap=C=a;a=g.linejoin;if(z!=a)n.lineJoin=z=a;d(g.color.getContextStyle());n.stroke();xa.inflate(g.linewidth* -2)}}function u(a,d,e,g,h,k,m,n){f.info.render.vertices=f.info.render.vertices+3;f.info.render.faces++;b(n.opacity);c(n.blending);B=a.positionScreen.x;K=a.positionScreen.y;L=d.positionScreen.x;G=d.positionScreen.y;i=e.positionScreen.x;X=e.positionScreen.y;x(B,K,L,G,i,X);if(n instanceof THREE.MeshBasicMaterial)if(n.map){if(n.map.mapping instanceof THREE.UVMapping){fb=m.uvs[0];$c(B,K,L,G,i,X,fb[g].u,fb[g].v,fb[h].u,fb[h].v,fb[k].u,fb[k].v,n.map)}}else if(n.envMap){if(n.envMap.mapping instanceof THREE.SphericalReflectionMapping){a= -l.matrixWorldInverse;oa.copy(m.vertexNormalsWorld[g]);Ya=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;Lb=-(oa.x*a.elements[1]+oa.y*a.elements[5]+oa.z*a.elements[9])*0.5+0.5;oa.copy(m.vertexNormalsWorld[h]);mb=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;gb=-(oa.x*a.elements[1]+oa.y*a.elements[5]+oa.z*a.elements[9])*0.5+0.5;oa.copy(m.vertexNormalsWorld[k]);Za=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;Db=-(oa.x*a.elements[1]+oa.y* -a.elements[5]+oa.z*a.elements[9])*0.5+0.5;$c(B,K,L,G,i,X,Ya,Lb,mb,gb,Za,Db,n.envMap)}}else n.wireframe?Nb(n.color,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(n.color);else if(n instanceof THREE.MeshLambertMaterial)if(jb)if(!n.wireframe&&n.shading==THREE.SmoothShading&&m.vertexNormalsWorld.length==3){Y.r=Z.r=P.r=ka.r;Y.g=Z.g=P.g=ka.g;Y.b=Z.b=P.b=ka.b;o(j,m.v1.positionWorld,m.vertexNormalsWorld[0],Y);o(j,m.v2.positionWorld,m.vertexNormalsWorld[1],Z);o(j,m.v3.positionWorld,m.vertexNormalsWorld[2], +2)}}function u(a,d,e,g,h,j,m,n){f.info.render.vertices=f.info.render.vertices+3;f.info.render.faces++;b(n.opacity);c(n.blending);B=a.positionScreen.x;K=a.positionScreen.y;L=d.positionScreen.x;G=d.positionScreen.y;i=e.positionScreen.x;X=e.positionScreen.y;x(B,K,L,G,i,X);if(n instanceof THREE.MeshBasicMaterial)if(n.map){if(n.map.mapping instanceof THREE.UVMapping){fb=m.uvs[0];$c(B,K,L,G,i,X,fb[g].u,fb[g].v,fb[h].u,fb[h].v,fb[j].u,fb[j].v,n.map)}}else if(n.envMap){if(n.envMap.mapping instanceof THREE.SphericalReflectionMapping){a= +l.matrixWorldInverse;oa.copy(m.vertexNormalsWorld[g]);Ya=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;Lb=-(oa.x*a.elements[1]+oa.y*a.elements[5]+oa.z*a.elements[9])*0.5+0.5;oa.copy(m.vertexNormalsWorld[h]);mb=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;gb=-(oa.x*a.elements[1]+oa.y*a.elements[5]+oa.z*a.elements[9])*0.5+0.5;oa.copy(m.vertexNormalsWorld[j]);Za=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;Db=-(oa.x*a.elements[1]+oa.y* +a.elements[5]+oa.z*a.elements[9])*0.5+0.5;$c(B,K,L,G,i,X,Ya,Lb,mb,gb,Za,Db,n.envMap)}}else n.wireframe?Nb(n.color,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(n.color);else if(n instanceof THREE.MeshLambertMaterial)if(jb)if(!n.wireframe&&n.shading==THREE.SmoothShading&&m.vertexNormalsWorld.length==3){Y.r=Z.r=P.r=ka.r;Y.g=Z.g=P.g=ka.g;Y.b=Z.b=P.b=ka.b;o(k,m.v1.positionWorld,m.vertexNormalsWorld[0],Y);o(k,m.v2.positionWorld,m.vertexNormalsWorld[1],Z);o(k,m.v3.positionWorld,m.vertexNormalsWorld[2], P);Y.r=Math.max(0,Math.min(n.color.r*Y.r,1));Y.g=Math.max(0,Math.min(n.color.g*Y.g,1));Y.b=Math.max(0,Math.min(n.color.b*Y.b,1));Z.r=Math.max(0,Math.min(n.color.r*Z.r,1));Z.g=Math.max(0,Math.min(n.color.g*Z.g,1));Z.b=Math.max(0,Math.min(n.color.b*Z.b,1));P.r=Math.max(0,Math.min(n.color.r*P.r,1));P.g=Math.max(0,Math.min(n.color.g*P.g,1));P.b=Math.max(0,Math.min(n.color.b*P.b,1));ga.r=(Z.r+P.r)*0.5;ga.g=(Z.g+P.g)*0.5;ga.b=(Z.b+P.b)*0.5;Sa=Cc(Y,Z,P,ga);ic(B,K,L,G,i,X,0,0,1,0,0,1,Sa)}else{Q.r=ka.r;Q.g= -ka.g;Q.b=ka.b;o(j,m.centroidWorld,m.normalWorld,Q);Q.r=Math.max(0,Math.min(n.color.r*Q.r,1));Q.g=Math.max(0,Math.min(n.color.g*Q.g,1));Q.b=Math.max(0,Math.min(n.color.b*Q.b,1));n.wireframe?Nb(Q,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(Q)}else n.wireframe?Nb(n.color,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(n.color);else if(n instanceof THREE.MeshDepthMaterial){Ma=l.near;Ra=l.far;Y.r=Y.g=Y.b=1-cc(a.positionScreen.z,Ma,Ra);Z.r=Z.g=Z.b=1-cc(d.positionScreen.z, -Ma,Ra);P.r=P.g=P.b=1-cc(e.positionScreen.z,Ma,Ra);ga.r=(Z.r+P.r)*0.5;ga.g=(Z.g+P.g)*0.5;ga.b=(Z.b+P.b)*0.5;Sa=Cc(Y,Z,P,ga);ic(B,K,L,G,i,X,0,0,1,0,0,1,Sa)}else if(n instanceof THREE.MeshNormalMaterial){Q.r=jc(m.normalWorld.x);Q.g=jc(m.normalWorld.y);Q.b=jc(m.normalWorld.z);n.wireframe?Nb(Q,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(Q)}}function t(a,d,e,g,h,k,n,m,p){f.info.render.vertices=f.info.render.vertices+4;f.info.render.faces++;b(m.opacity);c(m.blending);if(m.map||m.envMap){u(a, -d,g,0,1,3,n,m,p);u(h,e,k,1,2,3,n,m,p)}else{B=a.positionScreen.x;K=a.positionScreen.y;L=d.positionScreen.x;G=d.positionScreen.y;i=e.positionScreen.x;X=e.positionScreen.y;M=g.positionScreen.x;da=g.positionScreen.y;H=h.positionScreen.x;ea=h.positionScreen.y;$=k.positionScreen.x;wa=k.positionScreen.y;if(m instanceof THREE.MeshBasicMaterial){y(B,K,L,G,i,X,M,da);m.wireframe?Nb(m.color,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Fb(m.color)}else if(m instanceof THREE.MeshLambertMaterial)if(jb)if(!m.wireframe&& -m.shading==THREE.SmoothShading&&n.vertexNormalsWorld.length==4){Y.r=Z.r=P.r=ga.r=ka.r;Y.g=Z.g=P.g=ga.g=ka.g;Y.b=Z.b=P.b=ga.b=ka.b;o(j,n.v1.positionWorld,n.vertexNormalsWorld[0],Y);o(j,n.v2.positionWorld,n.vertexNormalsWorld[1],Z);o(j,n.v4.positionWorld,n.vertexNormalsWorld[3],P);o(j,n.v3.positionWorld,n.vertexNormalsWorld[2],ga);Y.r=Math.max(0,Math.min(m.color.r*Y.r,1));Y.g=Math.max(0,Math.min(m.color.g*Y.g,1));Y.b=Math.max(0,Math.min(m.color.b*Y.b,1));Z.r=Math.max(0,Math.min(m.color.r*Z.r,1));Z.g= -Math.max(0,Math.min(m.color.g*Z.g,1));Z.b=Math.max(0,Math.min(m.color.b*Z.b,1));P.r=Math.max(0,Math.min(m.color.r*P.r,1));P.g=Math.max(0,Math.min(m.color.g*P.g,1));P.b=Math.max(0,Math.min(m.color.b*P.b,1));ga.r=Math.max(0,Math.min(m.color.r*ga.r,1));ga.g=Math.max(0,Math.min(m.color.g*ga.g,1));ga.b=Math.max(0,Math.min(m.color.b*ga.b,1));Sa=Cc(Y,Z,P,ga);x(B,K,L,G,M,da);ic(B,K,L,G,M,da,0,0,1,0,0,1,Sa);x(H,ea,i,X,$,wa);ic(H,ea,i,X,$,wa,1,0,1,1,0,1,Sa)}else{Q.r=ka.r;Q.g=ka.g;Q.b=ka.b;o(j,n.centroidWorld, +ka.g;Q.b=ka.b;o(k,m.centroidWorld,m.normalWorld,Q);Q.r=Math.max(0,Math.min(n.color.r*Q.r,1));Q.g=Math.max(0,Math.min(n.color.g*Q.g,1));Q.b=Math.max(0,Math.min(n.color.b*Q.b,1));n.wireframe?Nb(Q,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(Q)}else n.wireframe?Nb(n.color,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(n.color);else if(n instanceof THREE.MeshDepthMaterial){Ma=l.near;Ra=l.far;Y.r=Y.g=Y.b=1-cc(a.positionScreen.z,Ma,Ra);Z.r=Z.g=Z.b=1-cc(d.positionScreen.z, +Ma,Ra);P.r=P.g=P.b=1-cc(e.positionScreen.z,Ma,Ra);ga.r=(Z.r+P.r)*0.5;ga.g=(Z.g+P.g)*0.5;ga.b=(Z.b+P.b)*0.5;Sa=Cc(Y,Z,P,ga);ic(B,K,L,G,i,X,0,0,1,0,0,1,Sa)}else if(n instanceof THREE.MeshNormalMaterial){Q.r=jc(m.normalWorld.x);Q.g=jc(m.normalWorld.y);Q.b=jc(m.normalWorld.z);n.wireframe?Nb(Q,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Fb(Q)}}function t(a,d,e,g,h,j,n,m,p){f.info.render.vertices=f.info.render.vertices+4;f.info.render.faces++;b(m.opacity);c(m.blending);if(m.map||m.envMap){u(a, +d,g,0,1,3,n,m,p);u(h,e,j,1,2,3,n,m,p)}else{B=a.positionScreen.x;K=a.positionScreen.y;L=d.positionScreen.x;G=d.positionScreen.y;i=e.positionScreen.x;X=e.positionScreen.y;M=g.positionScreen.x;da=g.positionScreen.y;H=h.positionScreen.x;ea=h.positionScreen.y;$=j.positionScreen.x;wa=j.positionScreen.y;if(m instanceof THREE.MeshBasicMaterial){y(B,K,L,G,i,X,M,da);m.wireframe?Nb(m.color,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Fb(m.color)}else if(m instanceof THREE.MeshLambertMaterial)if(jb)if(!m.wireframe&& +m.shading==THREE.SmoothShading&&n.vertexNormalsWorld.length==4){Y.r=Z.r=P.r=ga.r=ka.r;Y.g=Z.g=P.g=ga.g=ka.g;Y.b=Z.b=P.b=ga.b=ka.b;o(k,n.v1.positionWorld,n.vertexNormalsWorld[0],Y);o(k,n.v2.positionWorld,n.vertexNormalsWorld[1],Z);o(k,n.v4.positionWorld,n.vertexNormalsWorld[3],P);o(k,n.v3.positionWorld,n.vertexNormalsWorld[2],ga);Y.r=Math.max(0,Math.min(m.color.r*Y.r,1));Y.g=Math.max(0,Math.min(m.color.g*Y.g,1));Y.b=Math.max(0,Math.min(m.color.b*Y.b,1));Z.r=Math.max(0,Math.min(m.color.r*Z.r,1));Z.g= +Math.max(0,Math.min(m.color.g*Z.g,1));Z.b=Math.max(0,Math.min(m.color.b*Z.b,1));P.r=Math.max(0,Math.min(m.color.r*P.r,1));P.g=Math.max(0,Math.min(m.color.g*P.g,1));P.b=Math.max(0,Math.min(m.color.b*P.b,1));ga.r=Math.max(0,Math.min(m.color.r*ga.r,1));ga.g=Math.max(0,Math.min(m.color.g*ga.g,1));ga.b=Math.max(0,Math.min(m.color.b*ga.b,1));Sa=Cc(Y,Z,P,ga);x(B,K,L,G,M,da);ic(B,K,L,G,M,da,0,0,1,0,0,1,Sa);x(H,ea,i,X,$,wa);ic(H,ea,i,X,$,wa,1,0,1,1,0,1,Sa)}else{Q.r=ka.r;Q.g=ka.g;Q.b=ka.b;o(k,n.centroidWorld, n.normalWorld,Q);Q.r=Math.max(0,Math.min(m.color.r*Q.r,1));Q.g=Math.max(0,Math.min(m.color.g*Q.g,1));Q.b=Math.max(0,Math.min(m.color.b*Q.b,1));y(B,K,L,G,i,X,M,da);m.wireframe?Nb(Q,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Fb(Q)}else{y(B,K,L,G,i,X,M,da);m.wireframe?Nb(m.color,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Fb(m.color)}else if(m instanceof THREE.MeshNormalMaterial){Q.r=jc(n.normalWorld.x);Q.g=jc(n.normalWorld.y);Q.b=jc(n.normalWorld.z);y(B,K,L,G,i,X, M,da);m.wireframe?Nb(Q,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Fb(Q)}else if(m instanceof THREE.MeshDepthMaterial){Ma=l.near;Ra=l.far;Y.r=Y.g=Y.b=1-cc(a.positionScreen.z,Ma,Ra);Z.r=Z.g=Z.b=1-cc(d.positionScreen.z,Ma,Ra);P.r=P.g=P.b=1-cc(g.positionScreen.z,Ma,Ra);ga.r=ga.g=ga.b=1-cc(e.positionScreen.z,Ma,Ra);Sa=Cc(Y,Z,P,ga);x(B,K,L,G,M,da);ic(B,K,L,G,M,da,0,0,1,0,0,1,Sa);x(H,ea,i,X,$,wa);ic(H,ea,i,X,$,wa,1,0,1,1,0,1,Sa)}}}function x(a,b,c,d,e,f){n.beginPath();n.moveTo(a,b);n.lineTo(c, -d);n.lineTo(e,f);n.lineTo(a,b)}function y(a,b,c,d,e,f,g,i){n.beginPath();n.moveTo(a,b);n.lineTo(c,d);n.lineTo(e,f);n.lineTo(g,i);n.lineTo(a,b)}function Nb(a,b,c,e){if(D!=b)n.lineWidth=D=b;if(C!=c)n.lineCap=C=c;if(z!=e)n.lineJoin=z=e;d(a.getContextStyle());n.stroke();xa.inflate(b*2)}function Fb(a){e(a.getContextStyle());n.fill()}function $c(a,b,c,d,f,g,i,h,j,k,l,m,o){if(o.image.width!=0){if(o.needsUpdate==true||Qa[o.id]==void 0){var p=o.wrapS==THREE.RepeatWrapping,q=o.wrapT==THREE.RepeatWrapping;Qa[o.id]= -n.createPattern(o.image,p&&q?"repeat":p&&!q?"repeat-x":!p&&q?"repeat-y":"no-repeat");o.needsUpdate=false}e(Qa[o.id]);var p=o.offset.x/o.repeat.x,q=o.offset.y/o.repeat.y,bc=o.image.width*o.repeat.x,Mb=o.image.height*o.repeat.y,i=(i+p)*bc,h=(h+q)*Mb,c=c-a,d=d-b,f=f-a,g=g-b,j=(j+p)*bc-i,k=(k+q)*Mb-h,l=(l+p)*bc-i,m=(m+q)*Mb-h,p=j*m-l*k;if(p==0){if(na[o.id]===void 0){b=document.createElement("canvas");b.width=o.image.width;b.height=o.image.height;b=b.getContext("2d");b.drawImage(o.image,0,0);na[o.id]= -b.getImageData(0,0,o.image.width,o.image.height).data}b=na[o.id];i=(Math.floor(i)+Math.floor(h)*o.image.width)*4;Q.setRGB(b[i]/255,b[i+1]/255,b[i+2]/255);Fb(Q)}else{p=1/p;o=(m*c-k*f)*p;k=(m*d-k*g)*p;c=(j*f-l*c)*p;d=(j*g-l*d)*p;a=a-o*i-c*h;i=b-k*i-d*h;n.save();n.transform(o,k,c,d,a,i);n.fill();n.restore()}}}function ic(a,b,c,d,e,f,g,i,h,j,k,l,m){var o,p;o=m.width-1;p=m.height-1;g=g*o;i=i*p;c=c-a;d=d-b;e=e-a;f=f-b;h=h*o-g;j=j*p-i;k=k*o-g;l=l*p-i;p=1/(h*l-k*j);o=(l*c-j*e)*p;j=(l*d-j*f)*p;c=(h*e-k*c)* -p;d=(h*f-k*d)*p;a=a-o*g-c*i;b=b-j*g-d*i;n.save();n.transform(o,j,c,d,a,b);n.clip();n.drawImage(m,0,0);n.restore()}function Cc(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),i=~~(b.g*255),b=~~(b.b*255),h=~~(c.r*255),j=~~(c.g*255),c=~~(c.b*255),k=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);bb[0]=e<0?0:e>255?255:e;bb[1]=f<0?0:f>255?255:f;bb[2]=a<0?0:a>255?255:a;bb[4]=g<0?0:g>255?255:g;bb[5]=i<0?0:i>255?255:i;bb[6]=b<0?0:b>255?255:b;bb[8]=h<0?0:h>255?255:h;bb[9]=j<0?0:j>255?255:j;bb[10]= -c<0?0:c>255?255:c;bb[12]=k<0?0:k>255?255:k;bb[13]=l<0?0:l>255?255:l;bb[14]=d<0?0:d>255?255:d;Eb.putImageData(bc,0,0);Mb.drawImage(ab,0,0);return qc}function cc(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function jc(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function Ob(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;if(e!=0){e=1/Math.sqrt(e);c=c*e;d=d*e;b.x=b.x+c;b.y=b.y+d;a.x=a.x-c;a.y=a.y-d}}var Dc,ad,Ja,hb;this.autoClear?this.clear():n.setTransform(1,0,0,-1,p,q);f.info.render.vertices=0;f.info.render.faces=0;g=k.projectScene(a, -l,this.sortElements);h=g.elements;j=g.lights;(jb=j.length>0)&&m(j);Dc=0;for(ad=h.length;Dc255?255:e;bb[1]=f<0?0:f>255?255:f;bb[2]=a<0?0:a>255?255:a;bb[4]=g<0?0:g>255?255:g;bb[5]=i<0?0:i>255?255:i;bb[6]=b<0?0:b>255?255:b;bb[8]=h<0?0:h>255?255:h;bb[9]=k<0?0:k>255?255:k;bb[10]= +c<0?0:c>255?255:c;bb[12]=j<0?0:j>255?255:j;bb[13]=l<0?0:l>255?255:l;bb[14]=d<0?0:d>255?255:d;Eb.putImageData(bc,0,0);Mb.drawImage(ab,0,0);return qc}function cc(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function jc(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function Ob(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;if(e!=0){e=1/Math.sqrt(e);c=c*e;d=d*e;b.x=b.x+c;b.y=b.y+d;a.x=a.x-c;a.y=a.y-d}}var Dc,ad,Ja,hb;this.autoClear?this.clear():n.setTransform(1,0,0,-1,p,q);f.info.render.vertices=0;f.info.render.faces=0;g=j.projectScene(a, +l,this.sortElements);h=g.elements;k=g.lights;(jb=k.length>0)&&m(k);Dc=0;for(ad=h.length;Dc=0)return a.geometry.materials[b.materialIndex]}function d(a){return a instanceof THREE.MeshBasicMaterial&&!a.envMap||a instanceof THREE.MeshDepthMaterial?false:a&&a.shading!==void 0&&a.shading===THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading}function e(a){return a.map||a.lightMap||a instanceof THREE.ShaderMaterial?true:false}function f(a,b,c){var d,e,f,g,h=a.vertices;g=h.length; -var j=a.colors,k=j.length,l=a.__vertexArray,m=a.__colorArray,n=a.__sortArray,o=a.verticesNeedUpdate,p=a.colorsNeedUpdate,q=a.__webglCustomAttributesList;if(c.sortParticles){jb.copy(xa);jb.multiplySelf(c.matrixWorld);for(d=0;d=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function r(a,b,c,d,e){if(!d.program||d.needsUpdate){G.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(G.maxMorphTargets);for(var f=0,g=G.maxMorphTargets;f=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function r(a,b,c,d,e){if(!d.program||d.needsUpdate){G.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(G.maxMorphTargets);for(var f=0,g=G.maxMorphTargets;f=0&&e.vertexNormalBuffer){i.bindBuffer(i.ARRAY_BUFFER, e.vertexNormalBuffer);i.vertexAttribPointer(a.normal,e.vertexNormalBuffer.itemSize,i.FLOAT,false,0,f[d].index*12)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.vertexUvBuffer);i.vertexAttribPointer(a.uv,e.vertexUvBuffer.itemSize,i.FLOAT,false,0,f[d].index*8);i.enableVertexAttribArray(a.uv)}else i.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.vertexColorBuffer);i.vertexAttribPointer(a.color,e.vertexColorBuffer.itemSize, -i.FLOAT,false,0,f[d].index*16)}i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)}i.drawElements(i.TRIANGLES,f[d].count,i.UNSIGNED_SHORT,f[d].start*2);G.info.render.calls++;G.info.render.vertices=G.info.render.vertices+f[d].count;G.info.render.faces=G.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var h,j,c=r(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==ea){ea=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){i.bindBuffer(i.ARRAY_BUFFER, -e.__webglVertexBuffer);i.vertexAttribPointer(b.position,3,i.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=d.program.attributes;if(f.morphTargetBase!==-1){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}else if(c.position>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){h=0;var k=f.morphTargetForcedOrder;for(j=f.morphTargetInfluences;h< -d.numSupportedMorphTargets&&h0&&n.push(l)}if(n.length>d.numSupportedMorphTargets){n.sort(g); -n.length=d.numSupportedMorphTargets}else n.length>d.numSupportedMorphNormals?n.sort(g):n.length===0&&n.push(0);for(;h=0){i.bindBuffer(i.ARRAY_BUFFER,c.buffer);i.vertexAttribPointer(b[c.buffer.belongsToAttribute], +i.FLOAT,false,0,f[d].index*16)}i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)}i.drawElements(i.TRIANGLES,f[d].count,i.UNSIGNED_SHORT,f[d].start*2);G.info.render.calls++;G.info.render.vertices=G.info.render.vertices+f[d].count;G.info.render.faces=G.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var g,k,c=r(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==ea){ea=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){i.bindBuffer(i.ARRAY_BUFFER, +e.__webglVertexBuffer);i.vertexAttribPointer(b.position,3,i.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=d.program.attributes;if(f.morphTargetBase!==-1){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}else if(c.position>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){var j=0;k=f.morphTargetForcedOrder;for(g=f.morphTargetInfluences;j< +d.numSupportedMorphTargets&&j0&&k.push(l)}if(k.length>d.numSupportedMorphTargets){k.sort(h); +k.length=d.numSupportedMorphTargets}else k.length>d.numSupportedMorphNormals?k.sort(h):k.length===0&&k.push(0);for(j=0;j=0){i.bindBuffer(i.ARRAY_BUFFER,c.buffer);i.vertexAttribPointer(b[c.buffer.belongsToAttribute], c.size,i.FLOAT,false,0,0)}}}if(b.color>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglColorBuffer);i.vertexAttribPointer(b.color,3,i.FLOAT,false,0,0)}if(b.normal>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglNormalBuffer);i.vertexAttribPointer(b.normal,3,i.FLOAT,false,0,0)}if(b.tangent>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglTangentBuffer);i.vertexAttribPointer(b.tangent,4,i.FLOAT,false,0,0)}if(b.uv>=0)if(e.__webglUVBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.__webglUVBuffer);i.vertexAttribPointer(b.uv,2,i.FLOAT, false,0,0);i.enableVertexAttribArray(b.uv)}else i.disableVertexAttribArray(b.uv);if(b.uv2>=0)if(e.__webglUV2Buffer){i.bindBuffer(i.ARRAY_BUFFER,e.__webglUV2Buffer);i.vertexAttribPointer(b.uv2,2,i.FLOAT,false,0,0);i.enableVertexAttribArray(b.uv2)}else i.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinVertexABuffer);i.vertexAttribPointer(b.skinVertexA,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER, e.__webglSkinVertexBBuffer);i.vertexAttribPointer(b.skinVertexB,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinIndicesBuffer);i.vertexAttribPointer(b.skinIndex,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinWeightsBuffer);i.vertexAttribPointer(b.skinWeight,4,i.FLOAT,false,0,0)}}if(f instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==Ya){i.lineWidth(d);Ya=d}a&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer);i.drawElements(i.LINES,e.__webglLineCount, i.UNSIGNED_SHORT,0)}else{a&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer);i.drawElements(i.TRIANGLES,e.__webglFaceCount,i.UNSIGNED_SHORT,0)}G.info.render.calls++;G.info.render.vertices=G.info.render.vertices+e.__webglFaceCount;G.info.render.faces=G.info.render.faces+e.__webglFaceCount/3}else if(f instanceof THREE.Line){f=f.type===THREE.LineStrip?i.LINE_STRIP:i.LINES;d=d.linewidth;if(d!==Ya){i.lineWidth(d);Ya=d}i.drawArrays(f,0,e.__webglLineCount);G.info.render.calls++}else if(f instanceof -THREE.ParticleSystem){i.drawArrays(i.POINTS,0,e.__webglParticleCount);G.info.render.calls++;G.info.render.points=G.info.render.points+e.__webglParticleCount}else if(f instanceof THREE.Ribbon){i.drawArrays(i.TRIANGLE_STRIP,0,e.__webglVertexCount);G.info.render.calls++}}};this.render=function(a,b,c,d){var e,f,g,m,n=a.__lights,o=a.fog;H=-1;Na=true;if(b.parent===void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");a.add(b)}this.autoUpdateScene&&a.updateMatrixWorld();if(!b._viewMatrixArray)b._viewMatrixArray= -new Float32Array(16);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);xa.multiply(b.projectionMatrix,b.matrixWorldInverse);Da.setFromMatrix(xa);this.autoUpdateObjects&&this.initWebGLObjects(a);j(this.renderPluginsPre,a,b);G.info.render.calls=0;G.info.render.vertices=0;G.info.render.faces=0;G.info.render.points= -0;this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);m=a.__webglObjects;d=0;for(e=m.length;d=0){s=q.geometry.materials[s];if(s.transparent){p.transparent= -s;p.opaque=null}else{p.opaque=s;p.transparent=null}}}else if(s)if(s.transparent){p.transparent=s;p.opaque=null}else{p.opaque=s;p.transparent=null}f.render=true;if(this.sortObjects)if(g.renderDepth)f.z=g.renderDepth;else{ka.copy(g.matrixWorld.getPosition());xa.multiplyVector3(ka);f.z=ka.z}}}this.sortObjects&&m.sort(h);m=a.__webglObjectsImmediate;d=0;for(e=m.length;d=0){s=q.geometry.materials[s];if(s.transparent){p.transparent= +s;p.opaque=null}else{p.opaque=s;p.transparent=null}}}else if(s)if(s.transparent){p.transparent=s;p.opaque=null}else{p.opaque=s;p.transparent=null}f.render=true;if(this.sortObjects)if(h.renderDepth)f.z=h.renderDepth;else{ka.copy(h.matrixWorld.getPosition());xa.multiplyVector3(ka);f.z=ka.z}}}this.sortObjects&&m.sort(g);m=a.__webglObjectsImmediate;d=0;for(e=m.length;d65535){B[y].counter=B[y].counter+1;z=B[y].hash+"_"+B[y].counter;r.geometryGroups[z]===void 0&&(r.geometryGroups[z]={faces3:[],faces4:[],materialIndex:v,vertices:0,numMorphTargets:C,numMorphNormals:H})}t instanceof THREE.Face3?r.geometryGroups[z].faces3.push(s):r.geometryGroups[z].faces4.push(s);r.geometryGroups[z].vertices=r.geometryGroups[z].vertices+ -x}r.geometryGroupsList=[];var F=void 0;for(F in r.geometryGroups){r.geometryGroups[F].id=wa++;r.geometryGroupsList.push(r.geometryGroups[F])}}for(j in k.geometryGroups){l=k.geometryGroups[j];if(!l.__webglVertexBuffer){var D=l;D.__webglVertexBuffer=i.createBuffer();D.__webglNormalBuffer=i.createBuffer();D.__webglTangentBuffer=i.createBuffer();D.__webglColorBuffer=i.createBuffer();D.__webglUVBuffer=i.createBuffer();D.__webglUV2Buffer=i.createBuffer();D.__webglSkinVertexABuffer=i.createBuffer();D.__webglSkinVertexBBuffer= +x}r.geometryGroupsList=[];var F=void 0;for(F in r.geometryGroups){r.geometryGroups[F].id=wa++;r.geometryGroupsList.push(r.geometryGroups[F])}}for(k in j.geometryGroups){l=j.geometryGroups[k];if(!l.__webglVertexBuffer){var D=l;D.__webglVertexBuffer=i.createBuffer();D.__webglNormalBuffer=i.createBuffer();D.__webglTangentBuffer=i.createBuffer();D.__webglColorBuffer=i.createBuffer();D.__webglUVBuffer=i.createBuffer();D.__webglUV2Buffer=i.createBuffer();D.__webglSkinVertexABuffer=i.createBuffer();D.__webglSkinVertexBBuffer= i.createBuffer();D.__webglSkinIndicesBuffer=i.createBuffer();D.__webglSkinWeightsBuffer=i.createBuffer();D.__webglFaceBuffer=i.createBuffer();D.__webglLineBuffer=i.createBuffer();var Y=void 0,I=void 0;if(D.numMorphTargets){D.__webglMorphTargetsBuffers=[];Y=0;for(I=D.numMorphTargets;Y0||O.faceVertexUvs.length>0)P.__uvArray=new Float32Array(L*2);if(O.faceUvs.length>1||O.faceVertexUvs.length>1)P.__uv2Array= new Float32Array(L*2)}if(K.geometry.skinWeights.length&&K.geometry.skinIndices.length){P.__skinVertexAArray=new Float32Array(L*4);P.__skinVertexBArray=new Float32Array(L*4);P.__skinIndexArray=new Float32Array(L*4);P.__skinWeightArray=new Float32Array(L*4)}P.__faceArray=new Uint16Array(Z*3);P.__lineArray=new Uint16Array(S*2);var $=void 0,ga=void 0;if(P.numMorphTargets){P.__morphTargetsArrays=[];$=0;for(ga=P.numMorphTargets;$0?"#define VERTEX_TEXTURES": +a.uniforms=THREE.UniformsUtils.clone(h.uniforms);a.vertexShader=h.vertexShader;a.fragmentShader=h.fragmentShader}var k,j,l,m,n;k=m=n=h=0;for(j=b.length;k0?"#define VERTEX_TEXTURES": "",G.gammaInput?"#define GAMMA_INPUT":"",G.gammaOutput?"#define GAMMA_OUTPUT":"",G.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING": "",c.morphTargets?"#define USE_MORPHTARGETS":"",c.morphNormals?"#define USE_MORPHNORMALS":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\n#ifdef USE_MORPHNORMALS\nattribute vec3 morphNormal0;\nattribute vec3 morphNormal1;\nattribute vec3 morphNormal2;\nattribute vec3 morphNormal3;\n#else\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n"); -k=["precision "+v+" float;","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",G.gammaInput?"#define GAMMA_INPUT":"",G.gammaOutput?"#define GAMMA_OUTPUT":"",G.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP": +j=["precision "+v+" float;","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",G.gammaInput?"#define GAMMA_INPUT":"",G.gammaOutput?"#define GAMMA_OUTPUT":"",G.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP": "",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.metal?"#define METAL":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n"); -i.attachShader(r,y("fragment",k+n));i.attachShader(r,y("vertex",d+j));i.linkProgram(r);i.getProgramParameter(r,i.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+i.getProgramParameter(r,i.VALIDATE_STATUS)+", gl error ["+i.getError()+"]");r.uniforms={};r.attributes={};var s,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","boneGlobalMatrices","morphTargetInfluences"];for(s in h)d.push(s);s=d;d=0;for(h=s.length;d=0&&i.enableVertexAttribArray(q.position); q.color>=0&&i.enableVertexAttribArray(q.color);q.normal>=0&&i.enableVertexAttribArray(q.normal);q.tangent>=0&&i.enableVertexAttribArray(q.tangent);if(a.skinning&&q.skinVertexA>=0&&q.skinVertexB>=0&&q.skinIndex>=0&&q.skinWeight>=0){i.enableVertexAttribArray(q.skinVertexA);i.enableVertexAttribArray(q.skinVertexB);i.enableVertexAttribArray(q.skinIndex);i.enableVertexAttribArray(q.skinWeight)}if(a.attributes)for(f in a.attributes)q[f]!==void 0&&q[f]>=0&&i.enableVertexAttribArray(q[f]);if(a.morphTargets){a.numSupportedMorphTargets= 0;r="morphTarget";for(f=0;f=0){i.enableVertexAttribArray(q[s]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;r="morphNormal";for(f=0;f=0){i.enableVertexAttribArray(q[s]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(e in a.uniforms)a.uniformsList.push([a.uniforms[e],e])};this.setFaceCulling=function(a,b){if(a){!b||b==="ccw"?i.frontFace(i.CCW):i.frontFace(i.CW);a==="back"?i.cullFace(i.BACK): @@ -419,31 +419,31 @@ THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.material=null}; THREE.ColorUtils={adjustHSV:function(a,b,c,d){var e=THREE.ColorUtils.__hsv;THREE.ColorUtils.rgbToHsv(a,e);e.h=THREE.Math.clamp(e.h+b,0,1);e.s=THREE.Math.clamp(e.s+c,0,1);e.v=THREE.Math.clamp(e.v+d,0,1);a.setHSV(e.h,e.s,e.v)},rgbToHsv:function(a,b){var c=a.r,d=a.g,e=a.b,f=Math.max(Math.max(c,d),e),g=Math.min(Math.min(c,d),e);if(g===f)g=c=0;else{var h=f-g,g=h/f,c=(c===f?(d-e)/h:d===f?2+(e-c)/h:4+(c-d)/h)/6;c<0&&(c=c+1);c>1&&(c=c-1)}b===void 0&&(b={h:0,s:0,v:0});b.h=c;b.s=g;b.v=f;return b}}; THREE.ColorUtils.__hsv={h:0,s:0,v:0}; -THREE.GeometryUtils={merge:function(a,b){for(var c,d,e=a.vertices.length,f=b instanceof THREE.Mesh?b.geometry:b,g=a.vertices,h=f.vertices,j=a.faces,k=f.faces,l=a.faceVertexUvs[0],o=f.faceVertexUvs[0],m={},p=0;p1){d=1-d;e=1-e}f=1-d-e;g.copy(a);g.multiplyScalar(d);h.copy(b);h.multiplyScalar(e);g.addSelf(h);h.copy(c);h.multiplyScalar(f);g.addSelf(h);return g},randomPointInFace:function(a,b,c){var d,e,f;if(a instanceof THREE.Face3){d=b.vertices[a.a];e=b.vertices[a.b];f=b.vertices[a.c];return THREE.GeometryUtils.randomPointInTriangle(d,e,f)}if(a instanceof THREE.Face4){d=b.vertices[a.a];e=b.vertices[a.b];f=b.vertices[a.c];var b=b.vertices[a.d],g;if(c)if(a._area1&&a._area2){c=a._area1;g=a._area2}else{c=THREE.GeometryUtils.triangleArea(d,e,b);g=THREE.GeometryUtils.triangleArea(e,f,b);a._area1=c;a._area2=g}else{c=THREE.GeometryUtils.triangleArea(d,e,b);g=THREE.GeometryUtils.triangleArea(e,f,b)}return THREE.GeometryUtils.random()* -(c+g)a?b(c,e-1):k[e]a?b(c,e-1):j[e] -b||q>b||m>b){j=a.vertices.length;y=e.clone();s=e.clone();if(p>=q&&p>=m){k=k.clone();k.lerpSelf(l,0.5);y.a=f;y.b=j;y.c=h;s.a=j;s.b=g;s.c=h;if(e.vertexNormals.length===3){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[1],0.5);y.vertexNormals[1].copy(f);s.vertexNormals[0].copy(f)}if(e.vertexColors.length===3){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[1],0.5);y.vertexColors[1].copy(f);s.vertexColors[0].copy(f)}e=0}else if(q>=p&&q>=m){k=l.clone();k.lerpSelf(o,0.5);y.a=f;y.b=g;y.c= -j;s.a=j;s.b=h;s.c=f;if(e.vertexNormals.length===3){f=e.vertexNormals[1].clone();f.lerpSelf(e.vertexNormals[2],0.5);y.vertexNormals[2].copy(f);s.vertexNormals[0].copy(f);s.vertexNormals[1].copy(e.vertexNormals[2]);s.vertexNormals[2].copy(e.vertexNormals[0])}if(e.vertexColors.length===3){f=e.vertexColors[1].clone();f.lerpSelf(e.vertexColors[2],0.5);y.vertexColors[2].copy(f);s.vertexColors[0].copy(f);s.vertexColors[1].copy(e.vertexColors[2]);s.vertexColors[2].copy(e.vertexColors[0])}e=1}else{k=k.clone(); -k.lerpSelf(o,0.5);y.a=f;y.b=g;y.c=j;s.a=j;s.b=g;s.c=h;if(e.vertexNormals.length===3){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[2],0.5);y.vertexNormals[2].copy(f);s.vertexNormals[0].copy(f)}if(e.vertexColors.length===3){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[2],0.5);y.vertexColors[2].copy(f);s.vertexColors[0].copy(f)}e=2}x.push(y,s);a.vertices.push(k);f=0;for(g=a.faceVertexUvs.length;fb||q>b||n>b||r>b){u=a.vertices.length;t=a.vertices.length+1;y=e.clone();s=e.clone();if(p>=q&&p>=n&&p>=r||n>=q&&n>=p&&n>=r){p=k.clone();p.lerpSelf(l,0.5);l=o.clone();l.lerpSelf(m,0.5);y.a=f;y.b=u;y.c=t;y.d=j;s.a=u;s.b=g;s.c=h;s.d=t;if(e.vertexNormals.length===4){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[1],0.5);g=e.vertexNormals[2].clone();g.lerpSelf(e.vertexNormals[3],0.5);y.vertexNormals[1].copy(f); -y.vertexNormals[2].copy(g);s.vertexNormals[0].copy(f);s.vertexNormals[3].copy(g)}if(e.vertexColors.length===4){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[1],0.5);g=e.vertexColors[2].clone();g.lerpSelf(e.vertexColors[3],0.5);y.vertexColors[1].copy(f);y.vertexColors[2].copy(g);s.vertexColors[0].copy(f);s.vertexColors[3].copy(g)}e=0}else{p=l.clone();p.lerpSelf(o,0.5);l=m.clone();l.lerpSelf(k,0.5);y.a=f;y.b=g;y.c=u;y.d=t;s.a=t;s.b=u;s.c=h;s.d=j;if(e.vertexNormals.length===4){f=e.vertexNormals[1].clone(); +c;b++)h[b]=[];b=0;for(c=a.faces.length;b +b||q>b||m>b){k=a.vertices.length;y=e.clone();s=e.clone();if(p>=q&&p>=m){j=j.clone();j.lerpSelf(l,0.5);y.a=f;y.b=k;y.c=h;s.a=k;s.b=g;s.c=h;if(e.vertexNormals.length===3){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[1],0.5);y.vertexNormals[1].copy(f);s.vertexNormals[0].copy(f)}if(e.vertexColors.length===3){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[1],0.5);y.vertexColors[1].copy(f);s.vertexColors[0].copy(f)}e=0}else if(q>=p&&q>=m){j=l.clone();j.lerpSelf(o,0.5);y.a=f;y.b=g;y.c= +k;s.a=k;s.b=h;s.c=f;if(e.vertexNormals.length===3){f=e.vertexNormals[1].clone();f.lerpSelf(e.vertexNormals[2],0.5);y.vertexNormals[2].copy(f);s.vertexNormals[0].copy(f);s.vertexNormals[1].copy(e.vertexNormals[2]);s.vertexNormals[2].copy(e.vertexNormals[0])}if(e.vertexColors.length===3){f=e.vertexColors[1].clone();f.lerpSelf(e.vertexColors[2],0.5);y.vertexColors[2].copy(f);s.vertexColors[0].copy(f);s.vertexColors[1].copy(e.vertexColors[2]);s.vertexColors[2].copy(e.vertexColors[0])}e=1}else{j=j.clone(); +j.lerpSelf(o,0.5);y.a=f;y.b=g;y.c=k;s.a=k;s.b=g;s.c=h;if(e.vertexNormals.length===3){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[2],0.5);y.vertexNormals[2].copy(f);s.vertexNormals[0].copy(f)}if(e.vertexColors.length===3){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[2],0.5);y.vertexColors[2].copy(f);s.vertexColors[0].copy(f)}e=2}x.push(y,s);a.vertices.push(j);f=0;for(g=a.faceVertexUvs.length;fb||q>b||n>b||r>b){u=a.vertices.length;t=a.vertices.length+1;y=e.clone();s=e.clone();if(p>=q&&p>=n&&p>=r||n>=q&&n>=p&&n>=r){p=j.clone();p.lerpSelf(l,0.5);l=o.clone();l.lerpSelf(m,0.5);y.a=f;y.b=u;y.c=t;y.d=k;s.a=u;s.b=g;s.c=h;s.d=t;if(e.vertexNormals.length===4){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[1],0.5);g=e.vertexNormals[2].clone();g.lerpSelf(e.vertexNormals[3],0.5);y.vertexNormals[1].copy(f); +y.vertexNormals[2].copy(g);s.vertexNormals[0].copy(f);s.vertexNormals[3].copy(g)}if(e.vertexColors.length===4){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[1],0.5);g=e.vertexColors[2].clone();g.lerpSelf(e.vertexColors[3],0.5);y.vertexColors[1].copy(f);y.vertexColors[2].copy(g);s.vertexColors[0].copy(f);s.vertexColors[3].copy(g)}e=0}else{p=l.clone();p.lerpSelf(o,0.5);l=m.clone();l.lerpSelf(j,0.5);y.a=f;y.b=g;y.c=u;y.d=t;s.a=t;s.b=u;s.c=h;s.d=k;if(e.vertexNormals.length===4){f=e.vertexNormals[1].clone(); f.lerpSelf(e.vertexNormals[2],0.5);g=e.vertexNormals[3].clone();g.lerpSelf(e.vertexNormals[0],0.5);y.vertexNormals[2].copy(f);y.vertexNormals[3].copy(g);s.vertexNormals[0].copy(g);s.vertexNormals[1].copy(f)}if(e.vertexColors.length===4){f=e.vertexColors[1].clone();f.lerpSelf(e.vertexColors[2],0.5);g=e.vertexColors[3].clone();g.lerpSelf(e.vertexColors[0],0.5);y.vertexColors[2].copy(f);y.vertexColors[3].copy(g);s.vertexColors[0].copy(g);s.vertexColors[1].copy(f)}e=1}x.push(y,s);a.vertices.push(p,l); -f=0;for(g=a.faceVertexUvs.length;fe-1?e-1:o+1,q=l-1<0?0:l-1,n=l+1>d-1?d-1:l+1,r=[],u=[0,0,h[(o*d+l)*4]/255*b];r.push([-1,0,h[(o*d+q)*4]/255*b]);r.push([-1,-1,h[(m*d+q)*4]/255*b]);r.push([0, +b){var c=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);return[a[0]/b,a[1]/b,a[2]/b]},b=b|1,d=a.width,e=a.height,f=document.createElement("canvas");f.width=d;f.height=e;var g=f.getContext("2d");g.drawImage(a,0,0);for(var h=g.getImageData(0,0,d,e).data,k=g.createImageData(d,e),j=k.data,l=0;le-1?e-1:o+1,q=l-1<0?0:l-1,n=l+1>d-1?d-1:l+1,r=[],u=[0,0,h[(o*d+l)*4]/255*b];r.push([-1,0,h[(o*d+q)*4]/255*b]);r.push([-1,-1,h[(m*d+q)*4]/255*b]);r.push([0, -1,h[(m*d+l)*4]/255*b]);r.push([1,-1,h[(m*d+n)*4]/255*b]);r.push([1,0,h[(o*d+n)*4]/255*b]);r.push([1,1,h[(p*d+n)*4]/255*b]);r.push([0,1,h[(p*d+l)*4]/255*b]);r.push([-1,1,h[(p*d+q)*4]/255*b]);m=[];q=r.length;for(p=0;p0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)}; +THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,f;f=b?b:a*c[e-1];for(var g=0,h=e-1,k;g<=h;){d=Math.floor(g+(h-g)/2);k=c[d]-f;if(k<0)g=d+1;else if(k>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)}; THREE.Curve.prototype.getTangent=function(a){var b=a-1.0E-4,a=a+1.0E-4;b<0&&(b=0);a>1&&(a=1);b=this.getPoint(b);return this.getPoint(a).clone().subSelf(b).normalize()};THREE.Curve.prototype.getTangentAt=function(a){return this.getTangent(this.getUtoTmapping(a))};THREE.LineCurve=function(a,b){this.v1=a;this.v2=b};THREE.LineCurve.prototype=new THREE.Curve;THREE.LineCurve.prototype.constructor=THREE.LineCurve; THREE.LineCurve.prototype.getPoint=function(a){var b=this.v2.clone().subSelf(this.v1);b.multiplyScalar(a).addSelf(this.v1);return b};THREE.LineCurve.prototype.getPointAt=function(a){return this.getPoint(a)};THREE.LineCurve.prototype.getTangent=function(){return this.v2.clone().subSelf(this.v1).normalize()};THREE.QuadraticBezierCurve=function(a,b,c){this.v0=a;this.v1=b;this.v2=c};THREE.QuadraticBezierCurve.prototype=new THREE.Curve;THREE.QuadraticBezierCurve.prototype.constructor=THREE.QuadraticBezierCurve; THREE.QuadraticBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(b,a)};THREE.QuadraticBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.y,this.v1.y,this.v2.y);b=new THREE.Vector2(b,a);b.normalize();return b}; @@ -479,10 +479,10 @@ THREE.ClosedSplineCurve3=THREE.Curve.create(function(a){this.points=a==void 0?[] d[c[1]].z,d[c[2]].z,d[c[3]].z,e);return b});THREE.CurvePath=function(){this.curves=[];this.bends=[];this.autoClose=false};THREE.CurvePath.prototype=new THREE.Curve;THREE.CurvePath.prototype.constructor=THREE.CurvePath;THREE.CurvePath.prototype.add=function(a){this.curves.push(a)};THREE.CurvePath.prototype.checkConnection=function(){}; THREE.CurvePath.prototype.closePath=function(){var a=this.curves[0].getPoint(0),b=this.curves[this.curves.length-1].getPoint(1);a.equals(b)||this.curves.push(new THREE.LineCurve(b,a))};THREE.CurvePath.prototype.getPoint=function(a){for(var b=a*this.getLength(),c=this.getCurveLengths(),a=0;a=b){b=c[a]-b;a=this.curves[a];b=1-b/a.getLength();return a.getPointAt(b)}a++}return null};THREE.CurvePath.prototype.getLength=function(){var a=this.getCurveLengths();return a[a.length-1]}; THREE.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length==this.curves.length)return this.cacheLengths;var a=[],b=0,c,d=this.curves.length;for(c=0;cb)b=f.x;else if(f.xc)c=f.y;else if(f.yb)b=f.x;else if(f.xc)c=f.y;else if(f.y0){g=c[c.length-1]; -p=g.x;q=g.y}else{g=this.actions[d-1].args;p=g[g.length-2];q=g[g.length-1]}for(f=1;f<=a;f++){n=f/a;g=THREE.Shape.Utils.b2(n,p,o,h);n=THREE.Shape.Utils.b2(n,q,m,j);c.push(new THREE.Vector2(g,n))}break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];j=f[5];o=f[0];m=f[1];k=f[2];l=f[3];if(c.length>0){g=c[c.length-1];p=g.x;q=g.y}else{g=this.actions[d-1].args;p=g[g.length-2];q=g[g.length-1]}for(f=1;f<=a;f++){n=f/a;g=THREE.Shape.Utils.b3(n,p,o,k,h);n=THREE.Shape.Utils.b3(n,q,m,l,j);c.push(new THREE.Vector2(g, -n))}break;case THREE.PathActions.CSPLINE_THRU:g=this.actions[d-1].args;n=[new THREE.Vector2(g[g.length-2],g[g.length-1])];g=a*f[0].length;n=n.concat(f[0]);n=new THREE.SplineCurve(n);for(f=1;f<=g;f++)c.push(n.getPointAt(f/g));break;case THREE.PathActions.ARC:h=f[0];j=f[1];k=f[2];o=f[3];m=!!f[5];l=f[4]-o;p=a*2;for(f=1;f<=p;f++){n=f/p;m||(n=1-n);n=o+n*l;g=h+k*Math.cos(n);n=j+k*Math.sin(n);c.push(new THREE.Vector2(g,n))}}}d=c[c.length-1];Math.abs(d.x-c[0].x)<1.0E-10&&Math.abs(d.y-c[0].y)<1.0E-10&&c.splice(c.length- -1,1);b&&c.push(c[0]);return c};THREE.Path.prototype.transform=function(a,b){this.getBoundingBox();return this.getWrapPoints(this.getPoints(b),a)};THREE.Path.prototype.nltransform=function(a,b,c,d,e,f){var g=this.getPoints(),h,j,k,l,o;h=0;for(j=g.length;h0){g=c[c.length-1]; +p=g.x;q=g.y}else{g=this.actions[d-1].args;p=g[g.length-2];q=g[g.length-1]}for(f=1;f<=a;f++){n=f/a;g=THREE.Shape.Utils.b2(n,p,o,h);n=THREE.Shape.Utils.b2(n,q,m,k);c.push(new THREE.Vector2(g,n))}break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];k=f[5];o=f[0];m=f[1];j=f[2];l=f[3];if(c.length>0){g=c[c.length-1];p=g.x;q=g.y}else{g=this.actions[d-1].args;p=g[g.length-2];q=g[g.length-1]}for(f=1;f<=a;f++){n=f/a;g=THREE.Shape.Utils.b3(n,p,o,j,h);n=THREE.Shape.Utils.b3(n,q,m,l,k);c.push(new THREE.Vector2(g, +n))}break;case THREE.PathActions.CSPLINE_THRU:g=this.actions[d-1].args;n=[new THREE.Vector2(g[g.length-2],g[g.length-1])];g=a*f[0].length;n=n.concat(f[0]);n=new THREE.SplineCurve(n);for(f=1;f<=g;f++)c.push(n.getPointAt(f/g));break;case THREE.PathActions.ARC:h=f[0];k=f[1];j=f[2];o=f[3];m=!!f[5];l=f[4]-o;p=a*2;for(f=1;f<=p;f++){n=f/p;m||(n=1-n);n=o+n*l;g=h+j*Math.cos(n);n=k+j*Math.sin(n);c.push(new THREE.Vector2(g,n))}}}d=c[c.length-1];Math.abs(d.x-c[0].x)<1.0E-10&&Math.abs(d.y-c[0].y)<1.0E-10&&c.splice(c.length- +1,1);b&&c.push(c[0]);return c};THREE.Path.prototype.transform=function(a,b){this.getBoundingBox();return this.getWrapPoints(this.getPoints(b),a)};THREE.Path.prototype.nltransform=function(a,b,c,d,e,f){var g=this.getPoints(),h,k,j,l,o;h=0;for(k=g.length;h=0?h-1:c.length-1;f=g-1>=0?g-1:k.length-1;var n=[k[g],c[h],c[e]];o=THREE.FontUtils.Triangulate.area(n);var r=[k[g],k[f],c[h]];m=THREE.FontUtils.Triangulate.area(r);p=h;l=g;h=h+1;g=g+ --1;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+k.length);g=g%k.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:k.length-1;n=[k[g],c[h],c[e]];n=THREE.FontUtils.Triangulate.area(n);r=[k[g],k[f],c[h]];r=THREE.FontUtils.Triangulate.area(r);if(o+m>n+r){h=p;g=l;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+k.length);g=g%k.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:k.length-1}o=c.slice(0,h);m=c.slice(h);p=k.slice(g);l=k.slice(0,g);f=[k[g],k[f],c[h]];q.push([k[g],c[h],c[e]]);q.push(f);c=o.concat(p).concat(l).concat(m)}return{shape:c, -isolatedPts:q,allpoints:d}},triangulateShape:function(a,b){var c=THREE.Shape.Utils.removeHoles(a,b),d=c.allpoints,e=c.isolatedPts,c=THREE.FontUtils.Triangulate(c.shape,false),f,g,h,j,k={};f=0;for(g=d.length;f=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;var n=[j[g],c[h],c[e]];o=THREE.FontUtils.Triangulate.area(n);var r=[j[g],j[f],c[h]];m=THREE.FontUtils.Triangulate.area(r);p=h;l=g;h=h+1;g=g+ +-1;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+j.length);g=g%j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;n=[j[g],c[h],c[e]];n=THREE.FontUtils.Triangulate.area(n);r=[j[g],j[f],c[h]];r=THREE.FontUtils.Triangulate.area(r);if(o+m>n+r){h=p;g=l;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+j.length);g=g%j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1}o=c.slice(0,h);m=c.slice(h);p=j.slice(g);l=j.slice(0,g);f=[j[g],j[f],c[h]];q.push([j[g],c[h],c[e]]);q.push(f);c=o.concat(p).concat(l).concat(m)}return{shape:c, +isolatedPts:q,allpoints:d}},triangulateShape:function(a,b){var c=THREE.Shape.Utils.removeHoles(a,b),d=c.allpoints,e=c.isolatedPts,c=THREE.FontUtils.Triangulate(c.shape,false),f,g,h,k,j={};f=0;for(g=d.length;f1){console.log("THREE.Animation.update: Warning! Scale out of bounds:"+d+" on bone "+p);d=d<0?0:1}if(c==="pos"){c=a.position;if(this.interpolationType===THREE.AnimationHandler.LINEAR){c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}else if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType=== +THREE.Animation.prototype.update=function(a){if(this.isPlaying){var b=["pos","rot","scl"],c,d,e,f,g,h,k,j,l=this.data.JIT.hierarchy,o,m;m=this.currentTime=this.currentTime+a*this.timeScale;o=this.currentTime=this.currentTime%this.data.length;j=parseInt(Math.min(o*this.data.fps,this.data.length*this.data.fps),10);for(var p=0,q=this.hierarchy.length;p1){console.log("THREE.Animation.update: Warning! Scale out of bounds:"+d+" on bone "+p);d=d<0?0:1}if(c==="pos"){c=a.position;if(this.interpolationType===THREE.AnimationHandler.LINEAR){c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}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]=e;this.points[2]=f;this.points[3]=this.getNextKeyWith("pos",p,h.index+1).pos;d=d*0.33+0.33;e=this.interpolateCatmullRom(this.points,d);c.x=e[0];c.y=e[1];c.z=e[2];if(this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD){d=this.interpolateCatmullRom(this.points,d*1.01);this.target.set(d[0],d[1],d[2]);this.target.subSelf(c);this.target.y=0;this.target.normalize();d=Math.atan2(this.target.x, -this.target.z);a.rotation.set(0,d,0)}}}else if(c==="rot")THREE.Quaternion.slerp(e,f,a.quaternion,d);else if(c==="scl"){c=a.scale;c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}}}}if(this.JITCompile&&l[0][k]===void 0){this.hierarchy[0].updateMatrixWorld(true);for(p=0;pa.length-2?f:f+1;c[3]=f>a.length-3?f:f+2;f=a[c[0]];h=a[c[1]];j=a[c[2]];k=a[c[3]];c=e*e;g=e*c;d[0]=this.interpolate(f[0],h[0],j[0],k[0],e,c,g);d[1]=this.interpolate(f[1],h[1],j[1],k[1],e,c,g);d[2]=this.interpolate(f[2],h[2],j[2],k[2],e,c,g);return d}; +this.target.z);a.rotation.set(0,d,0)}}}else if(c==="rot")THREE.Quaternion.slerp(e,f,a.quaternion,d);else if(c==="scl"){c=a.scale;c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}}}}if(this.JITCompile&&l[0][j]===void 0){this.hierarchy[0].updateMatrixWorld(true);for(p=0;pa.length-2?f:f+1;c[3]=f>a.length-3?f:f+2;f=a[c[0]];h=a[c[1]];k=a[c[2]];j=a[c[3]];c=e*e;g=e*c;d[0]=this.interpolate(f[0],h[0],k[0],j[0],e,c,g);d[1]=this.interpolate(f[1],h[1],k[1],j[1],e,c,g);d[2]=this.interpolate(f[2],h[2],k[2],j[2],e,c,g);return d}; THREE.Animation.prototype.interpolate=function(a,b,c,d,e,f,g){a=(c-a)*0.5;d=(d-b)*0.5;return(2*(b-c)+a+d)*g+(-3*(b-c)-2*a-d)*f+a*e+b};THREE.Animation.prototype.getNextKeyWith=function(a,b,c){for(var d=this.data.hierarchy[b].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c0?c:0:c>=0?c:c+d.length;c>=0;c--)if(d[c][a]!==void 0)return d[c];return this.data.hierarchy[b].keys[d.length-1]}; THREE.KeyFrameAnimation=function(a,b,c){this.root=a;this.data=THREE.AnimationHandler.get(b);this.hierarchy=THREE.AnimationHandler.parse(a);this.currentTime=0;this.timeScale=0.0010;this.isPlaying=false;this.loop=this.isPaused=true;this.JITCompile=c!==void 0?c:true;a=0;for(b=this.hierarchy.length;a=g?b.interpolate(c,g):b.interpolate(c,c.time)}this.data.hierarchy[a].node.updateMatrix();d.matrixWorldNeedsUpdate=true}}if(this.JITCompile&&f[0][e]===void 0){this.hierarchy[0].updateMatrixWorld(true); +THREE.KeyFrameAnimation.prototype.update=function(a){if(this.isPlaying){var b,c,d,e,f=this.data.JIT.hierarchy,g,h,k;h=this.currentTime=this.currentTime+a*this.timeScale;g=this.currentTime=this.currentTime%this.data.length;if(g=g?b.interpolate(c,g):b.interpolate(c,c.time)}this.data.hierarchy[a].node.updateMatrix();d.matrixWorldNeedsUpdate=true}}if(this.JITCompile&&f[0][e]===void 0){this.hierarchy[0].updateMatrixWorld(true); for(a=0;a=0?c:c+b.length;c>=0;c--)if(b[c].hasTarget(a))return b[c];return b[b.length-1]}; THREE.CubeCamera=function(a,b,c){THREE.Object3D.call(this);var d=new THREE.PerspectiveCamera(90,1,a,b);d.up.set(0,-1,0);d.lookAt(new THREE.Vector3(1,0,0));this.add(d);var e=new THREE.PerspectiveCamera(90,1,a,b);e.up.set(0,-1,0);e.lookAt(new THREE.Vector3(-1,0,0));this.add(e);var f=new THREE.PerspectiveCamera(90,1,a,b);f.up.set(0,0,1);f.lookAt(new THREE.Vector3(0,1,0));this.add(f);var g=new THREE.PerspectiveCamera(90,1,a,b);g.up.set(0,0,-1);g.lookAt(new THREE.Vector3(0,-1,0));this.add(g);var h=new THREE.PerspectiveCamera(90, -1,a,b);h.up.set(0,-1,0);h.lookAt(new THREE.Vector3(0,0,1));this.add(h);var j=new THREE.PerspectiveCamera(90,1,a,b);j.up.set(0,-1,0);j.lookAt(new THREE.Vector3(0,0,-1));this.add(j);this.renderTarget=new THREE.WebGLRenderTargetCube(c,c,{format:THREE.RGBFormat,magFilter:THREE.LinearFilter,minFilter:THREE.LinearFilter});this.updateCubeMap=function(a,b){var c=this.renderTarget,m=c.generateMipmaps;c.generateMipmaps=false;c.activeCubeFace=0;a.render(b,d,c);c.activeCubeFace=1;a.render(b,e,c);c.activeCubeFace= -2;a.render(b,f,c);c.activeCubeFace=3;a.render(b,g,c);c.activeCubeFace=4;a.render(b,h,c);c.generateMipmaps=m;c.activeCubeFace=5;a.render(b,j,c)}};THREE.CubeCamera.prototype=new THREE.Object3D;THREE.CubeCamera.prototype.constructor=THREE.CubeCamera; +1,a,b);h.up.set(0,-1,0);h.lookAt(new THREE.Vector3(0,0,1));this.add(h);var k=new THREE.PerspectiveCamera(90,1,a,b);k.up.set(0,-1,0);k.lookAt(new THREE.Vector3(0,0,-1));this.add(k);this.renderTarget=new THREE.WebGLRenderTargetCube(c,c,{format:THREE.RGBFormat,magFilter:THREE.LinearFilter,minFilter:THREE.LinearFilter});this.updateCubeMap=function(a,b){var c=this.renderTarget,m=c.generateMipmaps;c.generateMipmaps=false;c.activeCubeFace=0;a.render(b,d,c);c.activeCubeFace=1;a.render(b,e,c);c.activeCubeFace= +2;a.render(b,f,c);c.activeCubeFace=3;a.render(b,g,c);c.activeCubeFace=4;a.render(b,h,c);c.generateMipmaps=m;c.activeCubeFace=5;a.render(b,k,c)}};THREE.CubeCamera.prototype=new THREE.Object3D;THREE.CubeCamera.prototype.constructor=THREE.CubeCamera; THREE.CombinedCamera=function(a,b,c,d,e,f,g){THREE.Camera.call(this);this.fov=c;this.left=-a/2;this.right=a/2;this.top=b/2;this.bottom=-b/2;this.cameraO=new THREE.OrthographicCamera(a/-2,a/2,b/2,b/-2,f,g);this.cameraP=new THREE.PerspectiveCamera(c,a/b,d,e);this.zoom=1;this.toPerspective()};THREE.CombinedCamera.prototype=new THREE.Camera;THREE.CombinedCamera.prototype.constructor=THREE.CombinedCamera; THREE.CombinedCamera.prototype.toPerspective=function(){this.near=this.cameraP.near;this.far=this.cameraP.far;this.cameraP.fov=this.fov/this.zoom;this.cameraP.updateProjectionMatrix();this.projectionMatrix=this.cameraP.projectionMatrix;this.inPersepectiveMode=true;this.inOrthographicMode=false}; THREE.CombinedCamera.prototype.toOrthographic=function(){var a=this.cameraP.aspect,b=(this.cameraP.near+this.cameraP.far)/2,b=Math.tan(this.fov/2)*b,a=2*b*a/2,b=b/this.zoom,a=a/this.zoom;this.cameraO.left=-a;this.cameraO.right=a;this.cameraO.top=b;this.cameraO.bottom=-b;this.cameraO.updateProjectionMatrix();this.near=this.cameraO.near;this.far=this.cameraO.far;this.projectionMatrix=this.cameraO.projectionMatrix;this.inPersepectiveMode=false;this.inOrthographicMode=true}; @@ -573,79 +573,79 @@ false;break;case 2:this.moveBackward=false}this.updateRotationVector()};this.upd this.object.matrixWorldNeedsUpdate=true};this.updateMovementVector=function(){var a=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=-a+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",c(this,this.mousemove),false);this.domElement.addEventListener("mousedown",c(this,this.mousedown),false);this.domElement.addEventListener("mouseup", c(this,this.mouseup),false);this.domElement.addEventListener("keydown",c(this,this.keydown),false);this.domElement.addEventListener("keyup",c(this,this.keyup),false);this.updateMovementVector();this.updateRotationVector()}; -THREE.RollControls=function(a,b){this.object=a;this.domElement=b!==void 0?b:document;this.mouseLook=true;this.autoForward=false;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.object.matrixAutoUpdate=false;this.forward=new THREE.Vector3(0,0,1);this.roll=0;var c=new THREE.Vector3,d=new THREE.Vector3,e=new THREE.Vector3,f=new THREE.Matrix4,g=false,h=1,j=0,k=0,l=0,o=0,m=0,p=window.innerWidth/2,q=window.innerHeight/2;this.update=function(a){if(this.mouseLook){var b= -a*this.lookSpeed;this.rotateHorizontally(b*o);this.rotateVertically(b*m)}b=a*this.movementSpeed;this.object.translateZ(-b*(j>0||this.autoForward&&!(j<0)?1:j));this.object.translateX(b*k);this.object.translateY(b*l);if(g)this.roll=this.roll+this.rollSpeed*a*h;if(this.forward.y>this.constrainVertical[1]){this.forward.y=this.constrainVertical[1];this.forward.normalize()}else if(this.forward.y0||this.autoForward&&!(k<0)?1:k));this.object.translateX(b*j);this.object.translateY(b*l);if(g)this.roll=this.roll+this.rollSpeed*a*h;if(this.forward.y>this.constrainVertical[1]){this.forward.y=this.constrainVertical[1];this.forward.normalize()}else if(this.forward.y1?d.normalize():d.z=Math.sqrt(1-e*e);g.copy(c.object.position).subSelf(c.target);e=c.object.up.clone().setLength(d.y);e.addSelf(c.object.up.clone().crossSelf(g).setLength(d.x));e.addSelf(g.setLength(d.z));return e};this.rotateCamera=function(){var a=Math.acos(h.dot(j)/h.length()/j.length());if(a){var b=(new THREE.Vector3).cross(h,j).normalize(),d=new THREE.Quaternion,a=a*c.rotateSpeed; -d.setFromAxisAngle(b,-a);d.multiplyVector3(g);d.multiplyVector3(c.object.up);d.multiplyVector3(j);if(c.staticMoving)h=j;else{d.setFromAxisAngle(b,a*(c.dynamicDampingFactor-1));d.multiplyVector3(h)}}};this.zoomCamera=function(){var a=1+(l.y-k.y)*c.zoomSpeed;if(a!==1&&a>0){g.multiplyScalar(a);c.staticMoving?k=l:k.y=k.y+(l.y-k.y)*this.dynamicDampingFactor}};this.panCamera=function(){var a=m.clone().subSelf(o);if(a.lengthSq()){a.multiplyScalar(g.length()*c.panSpeed);var b=g.clone().crossSelf(c.object.up).setLength(a.x); +this.target=new THREE.Vector3;var d=new THREE.Vector3,e=false,f=-1,g=new THREE.Vector3,h=new THREE.Vector3,k=new THREE.Vector3,j=new THREE.Vector2,l=new THREE.Vector2,o=new THREE.Vector2,m=new THREE.Vector2,p={type:"change"};this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.getMouseOnScreen=function(a,b){return new THREE.Vector2((a-c.screen.offsetLeft)/c.radius*0.5,(b-c.screen.offsetTop)/c.radius*0.5)};this.getMouseProjectionOnBall=function(a,b){var d=new THREE.Vector3((a- +c.screen.width*0.5-c.screen.offsetLeft)/c.radius,(c.screen.height*0.5+c.screen.offsetTop-b)/c.radius,0),e=d.length();e>1?d.normalize():d.z=Math.sqrt(1-e*e);g.copy(c.object.position).subSelf(c.target);e=c.object.up.clone().setLength(d.y);e.addSelf(c.object.up.clone().crossSelf(g).setLength(d.x));e.addSelf(g.setLength(d.z));return e};this.rotateCamera=function(){var a=Math.acos(h.dot(k)/h.length()/k.length());if(a){var b=(new THREE.Vector3).cross(h,k).normalize(),d=new THREE.Quaternion,a=a*c.rotateSpeed; +d.setFromAxisAngle(b,-a);d.multiplyVector3(g);d.multiplyVector3(c.object.up);d.multiplyVector3(k);if(c.staticMoving)h=k;else{d.setFromAxisAngle(b,a*(c.dynamicDampingFactor-1));d.multiplyVector3(h)}}};this.zoomCamera=function(){var a=1+(l.y-j.y)*c.zoomSpeed;if(a!==1&&a>0){g.multiplyScalar(a);c.staticMoving?j=l:j.y=j.y+(l.y-j.y)*this.dynamicDampingFactor}};this.panCamera=function(){var a=m.clone().subSelf(o);if(a.lengthSq()){a.multiplyScalar(g.length()*c.panSpeed);var b=g.clone().crossSelf(c.object.up).setLength(a.x); b.addSelf(c.object.up.clone().setLength(a.y));c.object.position.addSelf(b);c.target.addSelf(b);c.staticMoving?o=m:o.addSelf(a.sub(m,o).multiplyScalar(c.dynamicDampingFactor))}};this.checkDistances=function(){if(!c.noZoom||!c.noPan){c.object.position.lengthSq()>c.maxDistance*c.maxDistance&&c.object.position.setLength(c.maxDistance);g.lengthSq()0){c.dispatchEvent(p);d.copy(c.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousemove",function(a){if(c.enabled){if(e){h=j=c.getMouseProjectionOnBall(a.clientX,a.clientY);k=l=c.getMouseOnScreen(a.clientX,a.clientY);o= -m=c.getMouseOnScreen(a.clientX,a.clientY);e=false}f!==-1&&(f===0&&!c.noRotate?j=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?l=c.getMouseOnScreen(a.clientX,a.clientY):f===2&&!c.noPan&&(m=c.getMouseOnScreen(a.clientX,a.clientY)))}},false);this.domElement.addEventListener("mousedown",function(a){if(c.enabled){a.preventDefault();a.stopPropagation();if(f===-1){f=a.button;f===0&&!c.noRotate?h=j=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?k=l=c.getMouseOnScreen(a.clientX, +c.noRotate||c.rotateCamera();c.noZoom||c.zoomCamera();c.noPan||c.panCamera();c.object.position.add(c.target,g);c.checkDistances();c.object.lookAt(c.target);if(d.distanceTo(c.object.position)>0){c.dispatchEvent(p);d.copy(c.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousemove",function(a){if(c.enabled){if(e){h=k=c.getMouseProjectionOnBall(a.clientX,a.clientY);j=l=c.getMouseOnScreen(a.clientX,a.clientY);o= +m=c.getMouseOnScreen(a.clientX,a.clientY);e=false}f!==-1&&(f===0&&!c.noRotate?k=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?l=c.getMouseOnScreen(a.clientX,a.clientY):f===2&&!c.noPan&&(m=c.getMouseOnScreen(a.clientX,a.clientY)))}},false);this.domElement.addEventListener("mousedown",function(a){if(c.enabled){a.preventDefault();a.stopPropagation();if(f===-1){f=a.button;f===0&&!c.noRotate?h=k=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?j=l=c.getMouseOnScreen(a.clientX, a.clientY):this.noPan||(o=m=c.getMouseOnScreen(a.clientX,a.clientY))}}},false);this.domElement.addEventListener("mouseup",function(a){if(c.enabled){a.preventDefault();a.stopPropagation();f=-1}},false);window.addEventListener("keydown",function(a){if(c.enabled&&f===-1){a.keyCode===c.keys[0]&&!c.noRotate?f=0:a.keyCode===c.keys[1]&&!c.noZoom?f=1:a.keyCode===c.keys[2]&&!c.noPan&&(f=2);f!==-1&&(e=true)}},false);window.addEventListener("keyup",function(){c.enabled&&f!==-1&&(f=-1)},false)}; -THREE.CubeGeometry=function(a,b,c,d,e,f,g,h){function j(a,b,c,g,h,j,l,m){var n,o=d||1,p=e||1,q=h/2,r=j/2,t=k.vertices.length;if(a==="x"&&b==="y"||a==="y"&&b==="x")n="z";else if(a==="x"&&b==="z"||a==="z"&&b==="x"){n="y";p=f||1}else if(a==="z"&&b==="y"||a==="y"&&b==="z"){n="x";o=f||1}var u=o+1,i=p+1,y=h/o,M=j/p,da=new THREE.Vector3;da[n]=l>0?1:-1;for(h=0;h0?1:-1;for(h=0;h0){this.vertices.push(new THREE.Vector3(0, -g,0));for(h=0;h0){this.vertices.push(new THREE.Vector3(0,-g,0));for(h=0;h0){this.vertices.push(new THREE.Vector3(0, +g,0));for(h=0;h0){this.vertices.push(new THREE.Vector3(0,-g,0));for(h=0;ha&&(a=a+Math.PI*2);c=(b+a)/2;a=-Math.cos(c);c=-Math.sin(c);return new THREE.Vector2(a,c)}return d.multiplyScalar(g).addSelf(h).subSelf(a).clone()}function e(c,d){var e,f;for(H=c.length;--H>=0;){e=H;f=H-1;f<0&&(f= -c.length-1);for(var g=0,h=m+l*2,g=0;g=0;B--){L=B/l;G=j*(1-L);K=k*Math.sin(L*Math.PI/2);H=0;for(L=S.length;H=0;B--){L=B/l;G=k*(1-L);K=j*Math.sin(L*Math.PI/2);H=0;for(L=S.length;H0)for(k=0;k2;){if(o--<=0){console.log("Warning, unable to triangulate polygon!");break}j=k;e<=j&&(j=0);k=j+1;e<=k&&(k=0);l=k+1;e<=l&&(l=0);var m;a:{m=a;var p=j,q=k,n=l,r=e,u=g,t=void 0,y=void 0,s=void 0,x=void 0,D=void 0, -C=void 0,z=void 0,v=void 0,F=void 0,y=m[u[p]].x,s=m[u[p]].y,x=m[u[q]].x,D=m[u[q]].y,C=m[u[n]].x,z=m[u[n]].y;if(1.0E-10>(x-y)*(z-s)-(D-s)*(C-y))m=false;else{for(t=0;t=0&&T>=0&&B>=0){m=false;break a}}m=true}}if(m){f.push([a[g[j]], -a[g[k]],a[g[l]]]);h.push([g[j],g[k],g[l]]);j=k;for(l=k+1;l0)for(j=0;j2;){if(o--<=0){console.log("Warning, unable to triangulate polygon!");break}k=j;e<=k&&(k=0);j=k+1;e<=j&&(j=0);l=j+1;e<=l&&(l=0);var m;a:{m=a;var p=k,q=j,n=l,r=e,u=g,t=void 0,y=void 0,s=void 0,x=void 0,D=void 0, +C=void 0,z=void 0,v=void 0,F=void 0,y=m[u[p]].x,s=m[u[p]].y,x=m[u[q]].x,D=m[u[q]].y,C=m[u[n]].x,z=m[u[n]].y;if(1.0E-10>(x-y)*(z-s)-(D-s)*(C-y))m=false;else{for(t=0;t=0&&T>=0&&B>=0){m=false;break a}}m=true}}if(m){f.push([a[g[k]], +a[g[j]],a[g[l]]]);h.push([g[k],g[j],g[l]]);k=j;for(l=j+1;l1.0E-4){h.normalize();d=Math.acos(e[k-1].dot(e[k]));j.makeRotationAxis(h,d).multiplyVector3(f[k])}g[k].cross(e[k],f[k])}if(c){d=Math.acos(f[0].dot(f[b-1]));d=d/(b-1);e[0].dot(h.cross(f[0],f[b-1]))>0&&(d=-d);for(k=1;k1.0E-4){h.normalize();d=Math.acos(e[j-1].dot(e[j]));k.makeRotationAxis(h,d).multiplyVector3(f[j])}g[j].cross(e[j],f[j])}if(c){d=Math.acos(f[0].dot(f[b-1]));d=d/(b-1);e[0].dot(h.cross(f[0],f[b-1]))>0&&(d=-d);for(j=1;j0;)this.smooth(a)}; -THREE.SubdivisionModifier.prototype.smooth=function(a){function b(){m.debug&&console.log.apply(console,arguments)}function c(){console&&console.log.apply(console,arguments)}function d(a,c,d,e,g,h,i){var j=new THREE.Face4(a,c,d,e,null,g.color,g.material);if(m.useOldVertexColors){j.vertexColors=[];for(var k,n,p,q=0;q<4;q++){p=h[q];k=new THREE.Color;k.setRGB(0,0,0);for(var r=0;r=y&&a=y&&a1){var j=h[1];d[j]||(d[j]={start:Infinity,end:-Infinity});h=d[j];if(fh.end)h.end=f;c||(c=j)}}for(j in d){h=d[j];this.createAnimation(j,h.start,h.end,a)}this.firstAnimation=c}; +THREE.MorphBlendMesh.prototype.autoCreateAnimations=function(a){for(var b=/([a-z]+)(\d+)/,c,d={},e=this.geometry,f=0,g=e.morphTargets.length;f1){var k=h[1];d[k]||(d[k]={start:Infinity,end:-Infinity});h=d[k];if(fh.end)h.end=f;c||(c=k)}}for(k in d){h=d[k];this.createAnimation(k,h.start,h.end,a)}this.firstAnimation=c}; THREE.MorphBlendMesh.prototype.setAnimationDirectionForward=function(a){if(a=this.animationsMap[a]){a.direction=1;a.directionBackwards=false}};THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward=function(a){if(a=this.animationsMap[a]){a.direction=-1;a.directionBackwards=true}};THREE.MorphBlendMesh.prototype.setAnimationFPS=function(a,b){var c=this.animationsMap[a];if(c){c.fps=b;c.duration=(c.end-c.start)/c.fps}}; THREE.MorphBlendMesh.prototype.setAnimationDuration=function(a,b){var c=this.animationsMap[a];if(c){c.duration=b;c.fps=(c.end-c.start)/c.duration}};THREE.MorphBlendMesh.prototype.setAnimationWeight=function(a,b){var c=this.animationsMap[a];if(c)c.weight=b};THREE.MorphBlendMesh.prototype.setAnimationTime=function(a,b){var c=this.animationsMap[a];if(c)c.time=b};THREE.MorphBlendMesh.prototype.getAnimationTime=function(a){var b=0;if(a=this.animationsMap[a])b=a.time;return b}; THREE.MorphBlendMesh.prototype.getAnimationDuration=function(a){var b=-1;if(a=this.animationsMap[a])b=a.duration;return b};THREE.MorphBlendMesh.prototype.playAnimation=function(a){var b=this.animationsMap[a];if(b){b.time=0;b.active=true}else console.warn("animation["+a+"] undefined")};THREE.MorphBlendMesh.prototype.stopAnimation=function(a){if(a=this.animationsMap[a])a.active=false}; THREE.MorphBlendMesh.prototype.update=function(a){for(var b=0,c=this.animationsList.length;bd.duration||d.time<0){d.direction=d.direction*-1;if(d.time>d.duration){d.time=d.duration;d.directionBackwards=true}if(d.time<0){d.time=0;d.directionBackwards=false}}}else{d.time=d.time%d.duration;if(d.time<0)d.time=d.time+d.duration}var f=d.startFrame+THREE.Math.clamp(Math.floor(d.time/ e),0,d.length-1),g=d.weight;if(f!==d.currentFrame){this.morphTargetInfluences[d.lastFrame]=0;this.morphTargetInfluences[d.currentFrame]=1*g;this.morphTargetInfluences[f]=0;d.lastFrame=d.currentFrame;d.currentFrame=f}e=d.time%e/e;d.directionBackwards&&(e=1-e);this.morphTargetInfluences[d.currentFrame]=e*g;this.morphTargetInfluences[d.lastFrame]=(1-e)*g}}}; -THREE.LensFlarePlugin=function(){function a(a){var c=b.createProgram(),d=b.createShader(b.FRAGMENT_SHADER),e=b.createShader(b.VERTEX_SHADER);b.shaderSource(d,a.fragmentShader);b.shaderSource(e,a.vertexShader);b.compileShader(d);b.compileShader(e);b.attachShader(c,d);b.attachShader(c,e);b.linkProgram(c);return c}var b,c,d,e,f,g,h,j,k,l,o,m,p;this.init=function(q){b=q.context;c=q;d=new Float32Array(16);e=new Uint16Array(6);q=0;d[q++]=-1;d[q++]=-1;d[q++]=0;d[q++]=0;d[q++]=1;d[q++]=-1;d[q++]=1;d[q++]= -0;d[q++]=1;d[q++]=1;d[q++]=1;d[q++]=1;d[q++]=-1;d[q++]=1;d[q++]=0;d[q++]=1;q=0;e[q++]=0;e[q++]=1;e[q++]=2;e[q++]=0;e[q++]=2;e[q++]=3;f=b.createBuffer();g=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,f);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g);b.bufferData(b.ELEMENT_ARRAY_BUFFER,e,b.STATIC_DRAW);h=b.createTexture();j=b.createTexture();b.bindTexture(b.TEXTURE_2D,h);b.texImage2D(b.TEXTURE_2D,0,b.RGB,16,16,0,b.RGB,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D, -b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);b.bindTexture(b.TEXTURE_2D,j);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,16,16,0,b.RGBA,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST); -b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);if(b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0){k=false;l=a(THREE.ShaderFlares.lensFlare)}else{k=true;l=a(THREE.ShaderFlares.lensFlareVertexTexture)}o={};m={};o.vertex=b.getAttribLocation(l,"position");o.uv=b.getAttribLocation(l,"uv");m.renderType=b.getUniformLocation(l,"renderType");m.map=b.getUniformLocation(l,"map");m.occlusionMap=b.getUniformLocation(l,"occlusionMap");m.opacity=b.getUniformLocation(l,"opacity");m.color=b.getUniformLocation(l, +THREE.LensFlarePlugin=function(){function a(a){var c=b.createProgram(),d=b.createShader(b.FRAGMENT_SHADER),e=b.createShader(b.VERTEX_SHADER);b.shaderSource(d,a.fragmentShader);b.shaderSource(e,a.vertexShader);b.compileShader(d);b.compileShader(e);b.attachShader(c,d);b.attachShader(c,e);b.linkProgram(c);return c}var b,c,d,e,f,g,h,k,j,l,o,m,p;this.init=function(q){b=q.context;c=q;d=new Float32Array(16);e=new Uint16Array(6);q=0;d[q++]=-1;d[q++]=-1;d[q++]=0;d[q++]=0;d[q++]=1;d[q++]=-1;d[q++]=1;d[q++]= +0;d[q++]=1;d[q++]=1;d[q++]=1;d[q++]=1;d[q++]=-1;d[q++]=1;d[q++]=0;d[q++]=1;q=0;e[q++]=0;e[q++]=1;e[q++]=2;e[q++]=0;e[q++]=2;e[q++]=3;f=b.createBuffer();g=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,f);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g);b.bufferData(b.ELEMENT_ARRAY_BUFFER,e,b.STATIC_DRAW);h=b.createTexture();k=b.createTexture();b.bindTexture(b.TEXTURE_2D,h);b.texImage2D(b.TEXTURE_2D,0,b.RGB,16,16,0,b.RGB,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D, +b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);b.bindTexture(b.TEXTURE_2D,k);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,16,16,0,b.RGBA,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST); +b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);if(b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0){j=false;l=a(THREE.ShaderFlares.lensFlare)}else{j=true;l=a(THREE.ShaderFlares.lensFlareVertexTexture)}o={};m={};o.vertex=b.getAttribLocation(l,"position");o.uv=b.getAttribLocation(l,"uv");m.renderType=b.getUniformLocation(l,"renderType");m.map=b.getUniformLocation(l,"map");m.occlusionMap=b.getUniformLocation(l,"occlusionMap");m.opacity=b.getUniformLocation(l,"opacity");m.color=b.getUniformLocation(l, "color");m.scale=b.getUniformLocation(l,"scale");m.rotation=b.getUniformLocation(l,"rotation");m.screenPosition=b.getUniformLocation(l,"screenPosition");p=false};this.render=function(a,d,e,u){var a=a.__webglFlares,t=a.length;if(t){var y=new THREE.Vector3,s=u/e,x=e*0.5,D=u*0.5,C=16/u,z=new THREE.Vector2(C*s,C),v=new THREE.Vector3(1,1,0),F=new THREE.Vector2(1,1),I=m,C=o;b.useProgram(l);if(!p){b.enableVertexAttribArray(o.vertex);b.enableVertexAttribArray(o.uv);p=true}b.uniform1i(I.occlusionMap,0);b.uniform1i(I.map, -1);b.bindBuffer(b.ARRAY_BUFFER,f);b.vertexAttribPointer(C.vertex,2,b.FLOAT,false,16,0);b.vertexAttribPointer(C.uv,2,b.FLOAT,false,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g);b.disable(b.CULL_FACE);b.depthMask(false);var O,T,S,B,K;for(O=0;O0&&F.x0&& -F.y0&&F.x0&& +F.y0.0010&&K.scale>0.0010){v.x=K.x;v.y=K.y;v.z=K.z;C=K.size*K.scale/u;z.x=C*s;z.y=C;b.uniform3f(I.screenPosition,v.x,v.y,v.z);b.uniform2f(I.scale,z.x,z.y);b.uniform1f(I.rotation,K.rotation);b.uniform1f(I.opacity,K.opacity); b.uniform3f(I.color,K.color.r,K.color.g,K.color.b);c.setBlending(K.blending,K.blendEquation,K.blendSrc,K.blendDst);c.setTexture(K.texture,1);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}}; THREE.ShadowMapPlugin=function(){var a,b,c,d,e=new THREE.Frustum,f=new THREE.Matrix4,g=new THREE.Vector3,h=new THREE.Vector3;this.init=function(e){a=e.context;b=e;var e=THREE.ShaderLib.depthRGBA,f=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render= -function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(j,k){var l,o,m,p,q,n,r,u,t,y=[];p=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);b.shadowMapCullFrontFaces?a.cullFace(a.FRONT):a.cullFace(a.BACK);b.setDepthTest(true);l=0;for(o=j.__lights.length;lh.x)h.x=u.x;if(u.yh.y)h.y=u.y;if(u.zh.z)h.z=u.z}p.left=g.x;p.right=h.x;p.top=h.y;p.bottom=g.y;p.updateProjectionMatrix()}p=m.shadowMap;n=m.shadowMatrix;q=m.shadowCamera;q.position.copy(m.matrixWorld.getPosition());q.lookAt(m.target.matrixWorld.getPosition());q.updateMatrixWorld();q.matrixWorldInverse.getInverse(q.matrixWorld); if(m.cameraHelper)m.cameraHelper.lines.visible=m.shadowCameraVisible;m.shadowCameraVisible&&m.cameraHelper.update();n.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);n.multiplySelf(q.projectionMatrix);n.multiplySelf(q.matrixWorldInverse);if(!q._viewMatrixArray)q._viewMatrixArray=new Float32Array(16);if(!q._projectionMatrixArray)q._projectionMatrixArray=new Float32Array(16);q.matrixWorldInverse.flattenToArray(q._viewMatrixArray);q.projectionMatrix.flattenToArray(q._projectionMatrixArray);f.multiply(q.projectionMatrix, -q.matrixWorldInverse);e.setFromMatrix(f);b.setRenderTarget(p);b.clear();t=j.__webglObjects;m=0;for(p=t.length;m - - var i, f, p, q, t; - - if ( v === 0 ) { - - this.r = this.g = this.b = 0; - - } else { - - i = Math.floor( h * 6 ); - f = ( h * 6 ) - i; - p = v * ( 1 - s ); - q = v * ( 1 - ( s * f ) ); - t = v * ( 1 - ( s * ( 1 - f ) ) ); - - switch ( i ) { - - case 1: this.r = q; this.g = v; this.b = p; break; - case 2: this.r = p; this.g = v; this.b = t; break; - case 3: this.r = p; this.g = q; this.b = v; break; - case 4: this.r = t; this.g = p; this.b = v; break; - case 5: this.r = v; this.g = p; this.b = q; break; - case 6: // fall through - case 0: this.r = v; this.g = t; this.b = p; break; - - } - - } - - return this; - - }, - - setHex: function ( hex ) { - - hex = Math.floor( hex ); - - this.r = ( hex >> 16 & 255 ) / 255; - this.g = ( hex >> 8 & 255 ) / 255; - this.b = ( hex & 255 ) / 255; - - return this; - - }, - - lerpSelf: function ( color, alpha ) { - - this.r += ( color.r - this.r ) * alpha; - this.g += ( color.g - this.g ) * alpha; - this.b += ( color.b - this.b ) * alpha; - - return this; - - }, - - getHex: function () { - - return Math.floor( this.r * 255 ) << 16 ^ Math.floor( this.g * 255 ) << 8 ^ Math.floor( this.b * 255 ); - - }, - - getContextStyle: function () { - - return 'rgb(' + Math.floor( this.r * 255 ) + ',' + Math.floor( this.g * 255 ) + ',' + Math.floor( this.b * 255 ) + ')'; - - }, - - clone: function () { - - return new THREE.Color().setRGB( this.r, this.g, this.b ); - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author philogb / http://blog.thejit.org/ - * @author egraether / http://egraether.com/ - * @author zz85 / http://www.lab4games.net/zz85/blog - */ - -THREE.Vector2 = function ( x, y ) { - - this.x = x || 0; - this.y = y || 0; - -}; - -THREE.Vector2.prototype = { - - constructor: THREE.Vector2, - - set: function ( x, y ) { - - this.x = x; - this.y = y; - - return this; - - }, - - copy: function ( v ) { - - this.x = v.x; - this.y = v.y; - - return this; - - }, - - add: function ( a, b ) { - - this.x = a.x + b.x; - this.y = a.y + b.y; - - return this; - - }, - - addSelf: function ( v ) { - - this.x += v.x; - this.y += v.y; - - return this; - - }, - - sub: function ( a, b ) { - - this.x = a.x - b.x; - this.y = a.y - b.y; - - return this; - - }, - - subSelf: function ( v ) { - - this.x -= v.x; - this.y -= v.y; - - return this; - - }, - - multiplyScalar: function ( s ) { - - this.x *= s; - this.y *= s; - - return this; - - }, - - divideScalar: function ( s ) { - - if ( s ) { - - this.x /= s; - this.y /= s; - - } else { - - this.set( 0, 0 ); - - } - - return this; - - }, - - negate: function() { - - return this.multiplyScalar( - 1 ); - - }, - - dot: function ( v ) { - - return this.x * v.x + this.y * v.y; - - }, - - lengthSq: function () { - - return this.x * this.x + this.y * this.y; - - }, - - length: function () { - - return Math.sqrt( this.lengthSq() ); - - }, - - normalize: function () { - - return this.divideScalar( this.length() ); - - }, - - distanceTo: function ( v ) { - - return Math.sqrt( this.distanceToSquared( v ) ); - - }, - - distanceToSquared: function ( v ) { - - var dx = this.x - v.x, dy = this.y - v.y; - return dx * dx + dy * dy; - - }, - - setLength: function ( l ) { - - return this.normalize().multiplyScalar( l ); - - }, - - lerpSelf: function ( v, alpha ) { - - this.x += ( v.x - this.x ) * alpha; - this.y += ( v.y - this.y ) * alpha; - - return this; - - }, - - equals: function( v ) { - - return ( ( v.x === this.x ) && ( v.y === this.y ) ); - - }, - - isZero: function () { - - return ( this.lengthSq() < 0.0001 /* almostZero */ ); - - }, - - clone: function () { - - return new THREE.Vector2( this.x, this.y ); - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author kile / http://kile.stravaganza.org/ - * @author philogb / http://blog.thejit.org/ - * @author mikael emtinger / http://gomo.se/ - * @author egraether / http://egraether.com/ - */ - -THREE.Vector3 = function ( x, y, z ) { - - this.x = x || 0; - this.y = y || 0; - this.z = z || 0; - -}; - - -THREE.Vector3.prototype = { - - constructor: THREE.Vector3, - - set: function ( x, y, z ) { - - this.x = x; - this.y = y; - this.z = z; - - return this; - - }, - - setX: function ( x ) { - - this.x = x; - - return this; - - }, - - setY: function ( y ) { - - this.y = y; - - return this; - - }, - - setZ: function ( z ) { - - this.z = z; - - return this; - - }, - - copy: function ( v ) { - - this.x = v.x; - this.y = v.y; - this.z = v.z; - - return this; - - }, - - add: function ( a, b ) { - - this.x = a.x + b.x; - this.y = a.y + b.y; - this.z = a.z + b.z; - - return this; - - }, - - addSelf: function ( v ) { - - this.x += v.x; - this.y += v.y; - this.z += v.z; - - return this; - - }, - - addScalar: function ( s ) { - - this.x += s; - this.y += s; - this.z += s; - - return this; - - }, - - sub: function ( a, b ) { - - this.x = a.x - b.x; - this.y = a.y - b.y; - this.z = a.z - b.z; - - return this; - - }, - - subSelf: function ( v ) { - - this.x -= v.x; - this.y -= v.y; - this.z -= v.z; - - return this; - - }, - - multiply: function ( a, b ) { - - this.x = a.x * b.x; - this.y = a.y * b.y; - this.z = a.z * b.z; - - return this; - - }, - - multiplySelf: function ( v ) { - - this.x *= v.x; - this.y *= v.y; - this.z *= v.z; - - return this; - - }, - - multiplyScalar: function ( s ) { - - this.x *= s; - this.y *= s; - this.z *= s; - - return this; - - }, - - divideSelf: function ( v ) { - - this.x /= v.x; - this.y /= v.y; - this.z /= v.z; - - return this; - - }, - - divideScalar: function ( s ) { - - if ( s ) { - - this.x /= s; - this.y /= s; - this.z /= s; - - } else { - - this.x = 0; - this.y = 0; - this.z = 0; - - } - - return this; - - }, - - - negate: function() { - - return this.multiplyScalar( - 1 ); - - }, - - dot: function ( v ) { - - return this.x * v.x + this.y * v.y + this.z * v.z; - - }, - - lengthSq: function () { - - return this.x * this.x + this.y * this.y + this.z * this.z; - - }, - - length: function () { - - return Math.sqrt( this.lengthSq() ); - - }, - - lengthManhattan: function () { - - return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ); - - }, - - normalize: function () { - - return this.divideScalar( this.length() ); - - }, - - setLength: function ( l ) { - - return this.normalize().multiplyScalar( l ); - - }, - - lerpSelf: function ( v, alpha ) { - - this.x += ( v.x - this.x ) * alpha; - this.y += ( v.y - this.y ) * alpha; - this.z += ( v.z - this.z ) * alpha; - - return this; - - }, - - cross: function ( a, b ) { - - this.x = a.y * b.z - a.z * b.y; - this.y = a.z * b.x - a.x * b.z; - this.z = a.x * b.y - a.y * b.x; - - return this; - - }, - - crossSelf: function ( v ) { - - var x = this.x, y = this.y, z = this.z; - - this.x = y * v.z - z * v.y; - this.y = z * v.x - x * v.z; - this.z = x * v.y - y * v.x; - - return this; - - }, - - distanceTo: function ( v ) { - - return Math.sqrt( this.distanceToSquared( v ) ); - - }, - - distanceToSquared: function ( v ) { - - return new THREE.Vector3().sub( this, v ).lengthSq(); - - }, - - getPositionFromMatrix: function ( m ) { - - this.x = m.elements[12]; - this.y = m.elements[13]; - this.z = m.elements[14]; - - return this; - - }, - - getRotationFromMatrix: function ( m, scale ) { - - var sx = scale ? scale.x : 1; - var sy = scale ? scale.y : 1; - var sz = scale ? scale.z : 1; - - var m11 = m.elements[0] / sx, m12 = m.elements[4] / sy, m13 = m.elements[8] / sz; - var m21 = m.elements[1] / sx, m22 = m.elements[5] / sy, m23 = m.elements[9] / sz; - var m33 = m.elements[10] / sz; - - this.y = Math.asin( m13 ); - - var cosY = Math.cos( this.y ); - - if ( Math.abs( cosY ) > 0.00001 ) { - - this.x = Math.atan2( - m23 / cosY, m33 / cosY ); - this.z = Math.atan2( - m12 / cosY, m11 / cosY ); - - } else { - - this.x = 0; - this.z = Math.atan2( m21, m22 ); - - } - - return this; - - }, - - /* - - // from http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m - // order XYZ - - getEulerXYZFromQuaternion: function ( q ) { - - this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z ) ); - this.y = Math.asin( 2 * ( q.x * q.z + q.y * q.w ) ); - this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z ) ); - - }, - - // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm - // order YZX (assuming heading == y, attitude == z, bank == x) - - getEulerYZXFromQuaternion: function ( q ) { - - var sqw = q.w * q.w; - var sqx = q.x * q.x; - var sqy = q.y * q.y; - var sqz = q.z * q.z; - var unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor - var test = q.x * q.y + q.z * q.w; - - if ( test > 0.499 * unit ) { // singularity at north pole - - this.y = 2 * Math.atan2( q.x, q.w ); - this.z = Math.PI / 2; - this.x = 0; - - return; - - } - - if ( test < -0.499 * unit ) { // singularity at south pole - - this.y = -2 * Math.atan2( q.x, q.w ); - this.z = -Math.PI / 2; - this.x = 0; - - return; - - } - - this.y = Math.atan2( 2 * q.y * q.w - 2 * q.x * q.z, sqx - sqy - sqz + sqw ); - this.z = Math.asin( 2 * test / unit ); - this.x = Math.atan2( 2 * q.x * q.w - 2 * q.y * q.z, -sqx + sqy - sqz + sqw ); - - }, - - */ - - getScaleFromMatrix: function ( m ) { - - var sx = this.set( m.elements[0], m.elements[1], m.elements[2] ).length(); - var sy = this.set( m.elements[4], m.elements[5], m.elements[6] ).length(); - var sz = this.set( m.elements[8], m.elements[9], m.elements[10] ).length(); - - this.x = sx; - this.y = sy; - this.z = sz; - - }, - - equals: function ( v ) { - - return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) ); - - }, - - isZero: function () { - - return ( this.lengthSq() < 0.0001 /* almostZero */ ); - - }, - - clone: function () { - - return new THREE.Vector3( this.x, this.y, this.z ); - - } - -}; - -/** - * @author supereggbert / http://www.paulbrunt.co.uk/ - * @author philogb / http://blog.thejit.org/ - * @author mikael emtinger / http://gomo.se/ - * @author egraether / http://egraether.com/ - */ - -THREE.Vector4 = function ( x, y, z, w ) { - - this.x = x || 0; - this.y = y || 0; - this.z = z || 0; - this.w = ( w !== undefined ) ? w : 1; - -}; - -THREE.Vector4.prototype = { - - constructor: THREE.Vector4, - - set: function ( x, y, z, w ) { - - this.x = x; - this.y = y; - this.z = z; - this.w = w; - - return this; - - }, - - copy: function ( v ) { - - this.x = v.x; - this.y = v.y; - this.z = v.z; - this.w = ( v.w !== undefined ) ? v.w : 1; - - return this; - - }, - - add: function ( a, b ) { - - this.x = a.x + b.x; - this.y = a.y + b.y; - this.z = a.z + b.z; - this.w = a.w + b.w; - - return this; - - }, - - addSelf: function ( v ) { - - this.x += v.x; - this.y += v.y; - this.z += v.z; - this.w += v.w; - - return this; - - }, - - sub: function ( a, b ) { - - this.x = a.x - b.x; - this.y = a.y - b.y; - this.z = a.z - b.z; - this.w = a.w - b.w; - - return this; - - }, - - subSelf: function ( v ) { - - this.x -= v.x; - this.y -= v.y; - this.z -= v.z; - this.w -= v.w; - - return this; - - }, - - multiplyScalar: function ( s ) { - - this.x *= s; - this.y *= s; - this.z *= s; - this.w *= s; - - return this; - - }, - - divideScalar: function ( s ) { - - if ( s ) { - - this.x /= s; - this.y /= s; - this.z /= s; - this.w /= s; - - } else { - - this.x = 0; - this.y = 0; - this.z = 0; - this.w = 1; - - } - - return this; - - }, - - - negate: function() { - - return this.multiplyScalar( -1 ); - - }, - - dot: function ( v ) { - - return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; - - }, - - lengthSq: function () { - - return this.dot( this ); - - }, - - length: function () { - - return Math.sqrt( this.lengthSq() ); - - }, - - normalize: function () { - - return this.divideScalar( this.length() ); - - }, - - setLength: function ( l ) { - - return this.normalize().multiplyScalar( l ); - - }, - - lerpSelf: function ( v, alpha ) { - - this.x += ( v.x - this.x ) * alpha; - this.y += ( v.y - this.y ) * alpha; - this.z += ( v.z - this.z ) * alpha; - this.w += ( v.w - this.w ) * alpha; - - return this; - - }, - - clone: function () { - - return new THREE.Vector4( this.x, this.y, this.z, this.w ); - - } - -}; -/** - * @author mrdoob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Frustum = function ( ) { - - this.planes = [ - - new THREE.Vector4(), - new THREE.Vector4(), - new THREE.Vector4(), - new THREE.Vector4(), - new THREE.Vector4(), - new THREE.Vector4() - - ]; - -}; - -THREE.Frustum.prototype.setFromMatrix = function ( m ) { - - var i, plane, planes = this.planes; - - var me = m.elements; - var me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; - var me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; - var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; - var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; - - planes[ 0 ].set( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ); - planes[ 1 ].set( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ); - planes[ 2 ].set( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ); - planes[ 3 ].set( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ); - planes[ 4 ].set( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ); - planes[ 5 ].set( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ); - - for ( i = 0; i < 6; i ++ ) { - - plane = planes[ i ]; - plane.divideScalar( Math.sqrt( plane.x * plane.x + plane.y * plane.y + plane.z * plane.z ) ); - - } - -}; - -THREE.Frustum.prototype.contains = function ( object ) { - - var distance, - planes = this.planes, - matrix = object.matrixWorld, - me = matrix.elements, - radius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis(); - - for ( var i = 0; i < 6; i ++ ) { - - distance = planes[ i ].x * me[12] + planes[ i ].y * me[13] + planes[ i ].z * me[14] + planes[ i ].w; - if ( distance <= radius ) return false; - - } - - return true; - -}; - -THREE.Frustum.__v1 = new THREE.Vector3(); -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.Ray = function ( origin, direction ) { - - this.origin = origin || new THREE.Vector3(); - this.direction = direction || new THREE.Vector3(); - - var precision = 0.0001; - - this.setPrecision = function ( value ) { - - precision = value; - - }; - - var a = new THREE.Vector3(); - var b = new THREE.Vector3(); - var c = new THREE.Vector3(); - var d = new THREE.Vector3(); - - var originCopy = new THREE.Vector3(); - var directionCopy = new THREE.Vector3(); - - var vector = new THREE.Vector3(); - var normal = new THREE.Vector3(); - var intersectPoint = new THREE.Vector3() - - this.intersectObject = function ( object ) { - - var intersect, intersects = []; - - if ( object instanceof THREE.Particle ) { - - var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() ); - - if ( distance > object.scale.x ) { - - return []; - - } - - intersect = { - - distance: distance, - point: object.position, - face: null, - object: object - - }; - - intersects.push( intersect ); - - } else if ( object instanceof THREE.Mesh ) { - - // Checking boundingSphere - - var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() ); - var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() ); - - if ( distance > object.geometry.boundingSphere.radius * Math.max( scale.x, Math.max( scale.y, scale.z ) ) ) { - - return intersects; - - } - - // Checking faces - - var f, fl, face, dot, scalar, - geometry = object.geometry, - vertices = geometry.vertices, - objMatrix; - - object.matrixRotationWorld.extractRotation( object.matrixWorld ); - - for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) { - - face = geometry.faces[ f ]; - - originCopy.copy( this.origin ); - directionCopy.copy( this.direction ); - - objMatrix = object.matrixWorld; - - // determine if ray intersects the plane of the face - // note: this works regardless of the direction of the face normal - - vector = objMatrix.multiplyVector3( vector.copy( face.centroid ) ).subSelf( originCopy ); - normal = object.matrixRotationWorld.multiplyVector3( normal.copy( face.normal ) ); - dot = directionCopy.dot( normal ); - - // bail if ray and plane are parallel - - if ( Math.abs( dot ) < precision ) continue; - - // calc distance to plane - - scalar = normal.dot( vector ) / dot; - - // if negative distance, then plane is behind ray - - if ( scalar < 0 ) continue; - - if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) { - - intersectPoint.add( originCopy, directionCopy.multiplyScalar( scalar ) ); - - if ( face instanceof THREE.Face3 ) { - - a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) ); - b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) ); - c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) ); - - if ( pointInFace3( intersectPoint, a, b, c ) ) { - - intersect = { - - distance: originCopy.distanceTo( intersectPoint ), - point: intersectPoint.clone(), - face: face, - object: object - - }; - - intersects.push( intersect ); - - } - - } else if ( face instanceof THREE.Face4 ) { - - a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) ); - b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) ); - c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) ); - d = objMatrix.multiplyVector3( d.copy( vertices[ face.d ] ) ); - - if ( pointInFace3( intersectPoint, a, b, d ) || pointInFace3( intersectPoint, b, c, d ) ) { - - intersect = { - - distance: originCopy.distanceTo( intersectPoint ), - point: intersectPoint.clone(), - face: face, - object: object - - }; - - intersects.push( intersect ); - - } - - } - - } - - } - - } - - return intersects; - - } - - this.intersectObjects = function ( objects ) { - - var intersects = []; - - for ( var i = 0, l = objects.length; i < l; i ++ ) { - - Array.prototype.push.apply( intersects, this.intersectObject( objects[ i ] ) ); - - } - - intersects.sort( function ( a, b ) { return a.distance - b.distance; } ); - - return intersects; - - }; - - var v0 = new THREE.Vector3(), v1 = new THREE.Vector3(), v2 = new THREE.Vector3(); - var dot, intersect, distance; - - function distanceFromIntersection( origin, direction, position ) { - - v0.sub( position, origin ); - dot = v0.dot( direction ); - - intersect = v1.add( origin, v2.copy( direction ).multiplyScalar( dot ) ); - distance = position.distanceTo( intersect ); - - return distance; - - } - - // http://www.blackpawn.com/texts/pointinpoly/default.html - - var dot00, dot01, dot02, dot11, dot12, invDenom, u, v; - - function pointInFace3( p, a, b, c ) { - - v0.sub( c, a ); - v1.sub( b, a ); - v2.sub( p, a ); - - dot00 = v0.dot( v0 ); - dot01 = v0.dot( v1 ); - dot02 = v0.dot( v2 ); - dot11 = v1.dot( v1 ); - dot12 = v1.dot( v2 ); - - invDenom = 1 / ( dot00 * dot11 - dot01 * dot01 ); - u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom; - v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom; - - return ( u >= 0 ) && ( v >= 0 ) && ( u + v < 1 ); - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.Rectangle = function () { - - var _left, _top, _right, _bottom, - _width, _height, _isEmpty = true; - - function resize() { - - _width = _right - _left; - _height = _bottom - _top; - - } - - this.getX = function () { - - return _left; - - }; - - this.getY = function () { - - return _top; - - }; - - this.getWidth = function () { - - return _width; - - }; - - this.getHeight = function () { - - return _height; - - }; - - this.getLeft = function() { - - return _left; - - }; - - this.getTop = function() { - - return _top; - - }; - - this.getRight = function() { - - return _right; - - }; - - this.getBottom = function() { - - return _bottom; - - }; - - this.set = function ( left, top, right, bottom ) { - - _isEmpty = false; - - _left = left; _top = top; - _right = right; _bottom = bottom; - - resize(); - - }; - - this.addPoint = function ( x, y ) { - - if ( _isEmpty ) { - - _isEmpty = false; - _left = x; _top = y; - _right = x; _bottom = y; - - resize(); - - } else { - - _left = _left < x ? _left : x; // Math.min( _left, x ); - _top = _top < y ? _top : y; // Math.min( _top, y ); - _right = _right > x ? _right : x; // Math.max( _right, x ); - _bottom = _bottom > y ? _bottom : y; // Math.max( _bottom, y ); - - resize(); - } - - }; - - this.add3Points = function ( x1, y1, x2, y2, x3, y3 ) { - - if (_isEmpty) { - - _isEmpty = false; - _left = x1 < x2 ? ( x1 < x3 ? x1 : x3 ) : ( x2 < x3 ? x2 : x3 ); - _top = y1 < y2 ? ( y1 < y3 ? y1 : y3 ) : ( y2 < y3 ? y2 : y3 ); - _right = x1 > x2 ? ( x1 > x3 ? x1 : x3 ) : ( x2 > x3 ? x2 : x3 ); - _bottom = y1 > y2 ? ( y1 > y3 ? y1 : y3 ) : ( y2 > y3 ? y2 : y3 ); - - resize(); - - } else { - - _left = x1 < x2 ? ( x1 < x3 ? ( x1 < _left ? x1 : _left ) : ( x3 < _left ? x3 : _left ) ) : ( x2 < x3 ? ( x2 < _left ? x2 : _left ) : ( x3 < _left ? x3 : _left ) ); - _top = y1 < y2 ? ( y1 < y3 ? ( y1 < _top ? y1 : _top ) : ( y3 < _top ? y3 : _top ) ) : ( y2 < y3 ? ( y2 < _top ? y2 : _top ) : ( y3 < _top ? y3 : _top ) ); - _right = x1 > x2 ? ( x1 > x3 ? ( x1 > _right ? x1 : _right ) : ( x3 > _right ? x3 : _right ) ) : ( x2 > x3 ? ( x2 > _right ? x2 : _right ) : ( x3 > _right ? x3 : _right ) ); - _bottom = y1 > y2 ? ( y1 > y3 ? ( y1 > _bottom ? y1 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) ) : ( y2 > y3 ? ( y2 > _bottom ? y2 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) ); - - resize(); - - }; - - }; - - this.addRectangle = function ( r ) { - - if ( _isEmpty ) { - - _isEmpty = false; - _left = r.getLeft(); _top = r.getTop(); - _right = r.getRight(); _bottom = r.getBottom(); - - resize(); - - } else { - - _left = _left < r.getLeft() ? _left : r.getLeft(); // Math.min(_left, r.getLeft() ); - _top = _top < r.getTop() ? _top : r.getTop(); // Math.min(_top, r.getTop() ); - _right = _right > r.getRight() ? _right : r.getRight(); // Math.max(_right, r.getRight() ); - _bottom = _bottom > r.getBottom() ? _bottom : r.getBottom(); // Math.max(_bottom, r.getBottom() ); - - resize(); - - } - - }; - - this.inflate = function ( v ) { - - _left -= v; _top -= v; - _right += v; _bottom += v; - - resize(); - - }; - - this.minSelf = function ( r ) { - - _left = _left > r.getLeft() ? _left : r.getLeft(); // Math.max( _left, r.getLeft() ); - _top = _top > r.getTop() ? _top : r.getTop(); // Math.max( _top, r.getTop() ); - _right = _right < r.getRight() ? _right : r.getRight(); // Math.min( _right, r.getRight() ); - _bottom = _bottom < r.getBottom() ? _bottom : r.getBottom(); // Math.min( _bottom, r.getBottom() ); - - resize(); - - }; - - this.intersects = function ( r ) { - - // http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/ - - if ( _right < r.getLeft() ) return false; - if ( _left > r.getRight() ) return false; - if ( _bottom < r.getTop() ) return false; - if ( _top > r.getBottom() ) return false; - - return true; - - }; - - this.empty = function () { - - _isEmpty = true; - - _left = 0; _top = 0; - _right = 0; _bottom = 0; - - resize(); - - }; - - this.isEmpty = function () { - - return _isEmpty; - - }; - -}; -/** - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Math = { - - // Clamp value to range - - clamp: function ( x, a, b ) { - - return ( x < a ) ? a : ( ( x > b ) ? b : x ); - - }, - - // Clamp value to range to range - - mapLinear: function ( x, a1, a2, b1, b2 ) { - - return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 ); - - }, - - // Random float from <0, 1> with 16 bits of randomness - // (standard Math.random() creates repetitive patterns when applied over larger space) - - random16: function () { - - return ( 65280 * Math.random() + 255 * Math.random() ) / 65535; - - }, - - // Random integer from interval - - randInt: function ( low, high ) { - - return low + Math.floor( Math.random() * ( high - low + 1 ) ); - - }, - - // Random float from interval - - randFloat: function ( low, high ) { - - return low + Math.random() * ( high - low ); - - }, - - // Random float from <-range/2, range/2> interval - - randFloatSpread: function ( range ) { - - return range * ( 0.5 - Math.random() ); - - }, - - sign: function ( x ) { - - return ( x < 0 ) ? -1 : ( ( x > 0 ) ? 1 : 0 ); - - } - -}; -/** - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Matrix3 = function () { - - this.elements = new Float32Array(9); - -}; - -THREE.Matrix3.prototype = { - - constructor: THREE.Matrix3, - - getInverse: function ( matrix ) { - - // input: THREE.Matrix4 - // ( based on http://code.google.com/p/webgl-mjs/ ) - - var me = matrix.elements; - - var a11 = me[10] * me[5] - me[6] * me[9]; - var a21 = - me[10] * me[1] + me[2] * me[9]; - var a31 = me[6] * me[1] - me[2] * me[5]; - var a12 = - me[10] * me[4] + me[6] * me[8]; - var a22 = me[10] * me[0] - me[2] * me[8]; - var a32 = - me[6] * me[0] + me[2] * me[4]; - var a13 = me[9] * me[4] - me[5] * me[8]; - var a23 = - me[9] * me[0] + me[1] * me[8]; - var a33 = me[5] * me[0] - me[1] * me[4]; - - var det = me[0] * a11 + me[1] * a12 + me[2] * a13; - - // no inverse - - if ( det === 0 ) { - - console.warn( "Matrix3.getInverse(): determinant == 0" ); - - } - - var idet = 1.0 / det; - - var m = this.elements; - - m[ 0 ] = idet * a11; m[ 1 ] = idet * a21; m[ 2 ] = idet * a31; - m[ 3 ] = idet * a12; m[ 4 ] = idet * a22; m[ 5 ] = idet * a32; - m[ 6 ] = idet * a13; m[ 7 ] = idet * a23; m[ 8 ] = idet * a33; - - return this; - - }, - - - transpose: function () { - - var tmp, m = this.elements; - - tmp = m[1]; m[1] = m[3]; m[3] = tmp; - tmp = m[2]; m[2] = m[6]; m[6] = tmp; - tmp = m[5]; m[5] = m[7]; m[7] = tmp; - - return this; - - }, - - - transposeIntoArray: function ( r ) { - - var m = this.m; - - r[ 0 ] = m[ 0 ]; - r[ 1 ] = m[ 3 ]; - r[ 2 ] = m[ 6 ]; - r[ 3 ] = m[ 1 ]; - r[ 4 ] = m[ 4 ]; - r[ 5 ] = m[ 7 ]; - r[ 6 ] = m[ 2 ]; - r[ 7 ] = m[ 5 ]; - r[ 8 ] = m[ 8 ]; - - return this; - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author supereggbert / http://www.paulbrunt.co.uk/ - * @author philogb / http://blog.thejit.org/ - * @author jordi_ros / http://plattsoft.com - * @author D1plo1d / http://github.com/D1plo1d - * @author alteredq / http://alteredqualia.com/ - * @author mikael emtinger / http://gomo.se/ - * @author timknip / http://www.floorplanner.com/ - */ - - -THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { - - this.elements = new Float32Array(16); - - this.set( - - ( n11 !== undefined ) ? n11 : 1, n12 || 0, n13 || 0, n14 || 0, - n21 || 0, ( n22 !== undefined ) ? n22 : 1, n23 || 0, n24 || 0, - n31 || 0, n32 || 0, ( n33 !== undefined ) ? n33 : 1, n34 || 0, - n41 || 0, n42 || 0, n43 || 0, ( n44 !== undefined ) ? n44 : 1 - - ); - -}; - -THREE.Matrix4.prototype = { - - constructor: THREE.Matrix4, - - set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { - var te = this.elements; - - te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14; - te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24; - te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34; - te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44; - - return this; - - }, - - identity: function () { - - this.set( - - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - - ); - - return this; - - }, - - copy: function ( m ) { - - var me = m.elements; - - this.set( - - me[0], me[4], me[8], me[12], - me[1], me[5], me[9], me[13], - me[2], me[6], me[10], me[14], - me[3], me[7], me[11], me[15] - - ); - - return this; - - }, - - lookAt: function ( eye, target, up ) { - var te = this.elements; - - var x = THREE.Matrix4.__v1; - var y = THREE.Matrix4.__v2; - var z = THREE.Matrix4.__v3; - - z.sub( eye, target ).normalize(); - - if ( z.length() === 0 ) { - - z.z = 1; - - } - - x.cross( up, z ).normalize(); - - if ( x.length() === 0 ) { - - z.x += 0.0001; - x.cross( up, z ).normalize(); - - } - - y.cross( z, x ); - - - te[0] = x.x; te[4] = y.x; te[8] = z.x; - te[1] = x.y; te[5] = y.y; te[9] = z.y; - te[2] = x.z; te[6] = y.z; te[10] = z.z; - - return this; - - }, - - multiply: function ( a, b ) { - - var ae = a.elements, - be = b.elements, - te = this.elements; - - var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12]; - var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13]; - var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14]; - var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15]; - - var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12]; - var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13]; - var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14]; - var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15]; - - te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; - te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; - te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; - te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; - - te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; - te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; - te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; - te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; - - te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; - te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; - te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; - te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; - - te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; - te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; - te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; - te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; - - return this; - - }, - - multiplySelf: function ( m ) { - - return this.multiply( this, m ); - - }, - - multiplyToArray: function ( a, b, r ) { - - var te = this.elements; - - this.multiply( a, b ); - - r[ 0 ] = te[0]; r[ 1 ] = te[1]; r[ 2 ] = te[2]; r[ 3 ] = te[3]; - r[ 4 ] = te[4]; r[ 5 ] = te[5]; r[ 6 ] = te[6]; r[ 7 ] = te[7]; - r[ 8 ] = te[8]; r[ 9 ] = te[9]; r[ 10 ] = te[10]; r[ 11 ] = te[11]; - r[ 12 ] = te[12]; r[ 13 ] = te[13]; r[ 14 ] = te[14]; r[ 15 ] = te[15]; - - return this; - - }, - - multiplyScalar: function ( s ) { - - var te = this.elements; - - te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s; - te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s; - te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s; - te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s; - - return this; - - }, - - multiplyVector3: function ( v ) { - var te = this.elements; - - var vx = v.x, vy = v.y, vz = v.z; - var d = 1 / ( te[3] * vx + te[7] * vy + te[11] * vz + te[15] ); - - v.x = ( te[0] * vx + te[4] * vy + te[8] * vz + te[12] ) * d; - v.y = ( te[1] * vx + te[5] * vy + te[9] * vz + te[13] ) * d; - v.z = ( te[2] * vx + te[6] * vy + te[10] * vz + te[14] ) * d; - - return v; - - }, - - multiplyVector4: function ( v ) { - - var te = this.elements; - var vx = v.x, vy = v.y, vz = v.z, vw = v.w; - - v.x = te[0] * vx + te[4] * vy + te[8] * vz + te[12] * vw; - v.y = te[1] * vx + te[5] * vy + te[9] * vz + te[13] * vw; - v.z = te[2] * vx + te[6] * vy + te[10] * vz + te[14] * vw; - v.w = te[3] * vx + te[7] * vy + te[11] * vz + te[15] * vw; - - return v; - - }, - - rotateAxis: function ( v ) { - - var te = this.elements; - var vx = v.x, vy = v.y, vz = v.z; - - v.x = vx * te[0] + vy * te[4] + vz * te[8]; - v.y = vx * te[1] + vy * te[5] + vz * te[9]; - v.z = vx * te[2] + vy * te[6] + vz * te[10]; - - v.normalize(); - - return v; - - }, - - crossVector: function ( a ) { - - var te = this.elements; - var v = new THREE.Vector4(); - - v.x = te[0] * a.x + te[4] * a.y + te[8] * a.z + te[12] * a.w; - v.y = te[1] * a.x + te[5] * a.y + te[9] * a.z + te[13] * a.w; - v.z = te[2] * a.x + te[6] * a.y + te[10] * a.z + te[14] * a.w; - - v.w = ( a.w ) ? te[3] * a.x + te[7] * a.y + te[11] * a.z + te[15] * a.w : 1; - - return v; - - }, - - determinant: function () { - - var te = this.elements; - - var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12]; - var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13]; - var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14]; - var n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15]; - - //TODO: make this more efficient - //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm ) - - return ( - n14 * n23 * n32 * n41- - n13 * n24 * n32 * n41- - n14 * n22 * n33 * n41+ - n12 * n24 * n33 * n41+ - - n13 * n22 * n34 * n41- - n12 * n23 * n34 * n41- - n14 * n23 * n31 * n42+ - n13 * n24 * n31 * n42+ - - n14 * n21 * n33 * n42- - n11 * n24 * n33 * n42- - n13 * n21 * n34 * n42+ - n11 * n23 * n34 * n42+ - - n14 * n22 * n31 * n43- - n12 * n24 * n31 * n43- - n14 * n21 * n32 * n43+ - n11 * n24 * n32 * n43+ - - n12 * n21 * n34 * n43- - n11 * n22 * n34 * n43- - n13 * n22 * n31 * n44+ - n12 * n23 * n31 * n44+ - - n13 * n21 * n32 * n44- - n11 * n23 * n32 * n44- - n12 * n21 * n33 * n44+ - n11 * n22 * n33 * n44 - ); - - }, - - transpose: function () { - var te = this.elements; - - var tmp; - - tmp = te[1]; te[1] = te[4]; te[4] = tmp; - tmp = te[2]; te[2] = te[8]; te[8] = tmp; - tmp = te[6]; te[6] = te[9]; te[9] = tmp; - - tmp = te[3]; te[3] = te[12]; te[12] = tmp; - tmp = te[7]; te[7] = te[13]; te[13] = tmp; - tmp = te[11]; te[11] = te[14]; te[14] = tmp; - - return this; - - }, - - flattenToArray: function ( flat ) { - - var te = this.elements; - flat[ 0 ] = te[0]; flat[ 1 ] = te[1]; flat[ 2 ] = te[2]; flat[ 3 ] = te[3]; - flat[ 4 ] = te[4]; flat[ 5 ] = te[5]; flat[ 6 ] = te[6]; flat[ 7 ] = te[7]; - flat[ 8 ] = te[8]; flat[ 9 ] = te[9]; flat[ 10 ] = te[10]; flat[ 11 ] = te[11]; - flat[ 12 ] = te[12]; flat[ 13 ] = te[13]; flat[ 14 ] = te[14]; flat[ 15 ] = te[15]; - - return flat; - - }, - - flattenToArrayOffset: function( flat, offset ) { - - var te = this.elements; - flat[ offset ] = te[0]; - flat[ offset + 1 ] = te[1]; - flat[ offset + 2 ] = te[2]; - flat[ offset + 3 ] = te[3]; - - flat[ offset + 4 ] = te[4]; - flat[ offset + 5 ] = te[5]; - flat[ offset + 6 ] = te[6]; - flat[ offset + 7 ] = te[7]; - - flat[ offset + 8 ] = te[8]; - flat[ offset + 9 ] = te[9]; - flat[ offset + 10 ] = te[10]; - flat[ offset + 11 ] = te[11]; - - flat[ offset + 12 ] = te[12]; - flat[ offset + 13 ] = te[13]; - flat[ offset + 14 ] = te[14]; - flat[ offset + 15 ] = te[15]; - - return flat; - - }, - - getPosition: function () { - var te = this.elements; - - return THREE.Matrix4.__v1.set( te[12], te[13], te[14] ); - - }, - - setPosition: function ( v ) { - var te = this.elements; - te[12] = v.x; - te[13] = v.y; - te[14] = v.z; - - return this; - - }, - - getColumnX: function () { - var te = this.elements; - return THREE.Matrix4.__v1.set( te[0], te[1], te[2] ); - - }, - - getColumnY: function () { - var te = this.elements; - return THREE.Matrix4.__v1.set( te[4], te[5], te[6] ); - - }, - - getColumnZ: function() { - var te = this.elements; - return THREE.Matrix4.__v1.set( te[8], te[9], te[10] ); - - }, - - getInverse: function ( m ) { - - // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm - var te = this.elements; - var me = m.elements; - - var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12]; - var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13]; - var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14]; - var n41 = me[3], n42 = me[7], n43 = me[11], n44 = me[15]; - - te[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44; - te[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44; - te[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44; - te[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34; - te[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44; - te[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44; - te[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44; - te[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34; - te[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44; - te[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44; - te[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44; - te[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34; - te[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43; - te[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43; - te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43; - te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33; - this.multiplyScalar( 1 / m.determinant() ); - - return this; - - }, - - setRotationFromEuler: function( v, order ) { - var te = this.elements; - - var x = v.x, y = v.y, z = v.z; - var a = Math.cos( x ), b = Math.sin( x ); - var c = Math.cos( y ), d = Math.sin( y ); - var e = Math.cos( z ), f = Math.sin( z ); - - switch ( order ) { - - case 'YXZ': - - var ce = c * e, cf = c * f, de = d * e, df = d * f; - - te[0] = ce + df * b; - te[4] = de * b - cf; - te[8] = a * d; - - te[1] = a * f; - te[5] = a * e; - te[9] = - b; - - te[2] = cf * b - de; - te[6] = df + ce * b; - te[10] = a * c; - break; - - case 'ZXY': - - var ce = c * e, cf = c * f, de = d * e, df = d * f; - - te[0] = ce - df * b; - te[4] = - a * f; - te[8] = de + cf * b; - - te[1] = cf + de * b; - te[5] = a * e; - te[9] = df - ce * b; - - te[2] = - a * d; - te[6] = b; - te[10] = a * c; - break; - - case 'ZYX': - - var ae = a * e, af = a * f, be = b * e, bf = b * f; - - te[0] = c * e; - te[4] = be * d - af; - te[8] = ae * d + bf; - - te[1] = c * f; - te[5] = bf * d + ae; - te[9] = af * d - be; - - te[2] = - d; - te[6] = b * c; - te[10] = a * c; - break; - - case 'YZX': - - var ac = a * c, ad = a * d, bc = b * c, bd = b * d; - - te[0] = c * e; - te[4] = bd - ac * f; - te[8] = bc * f + ad; - - te[1] = f; - te[5] = a * e; - te[9] = - b * e; - - te[2] = - d * e; - te[6] = ad * f + bc; - te[10] = ac - bd * f; - break; - - case 'XZY': - - var ac = a * c, ad = a * d, bc = b * c, bd = b * d; - - te[0] = c * e; - te[4] = - f; - te[8] = d * e; - - te[1] = ac * f + bd; - te[5] = a * e; - te[9] = ad * f - bc; - - te[2] = bc * f - ad; - te[6] = b * e; - te[10] = bd * f + ac; - break; - - default: // 'XYZ' - - var ae = a * e, af = a * f, be = b * e, bf = b * f; - - te[0] = c * e; - te[4] = - c * f; - te[8] = d; - - te[1] = af + be * d; - te[5] = ae - bf * d; - te[9] = - b * c; - - te[2] = bf - ae * d; - te[6] = be + af * d; - te[10] = a * c; - break; - - } - - return this; - - }, - - - setRotationFromQuaternion: function( q ) { - var te = this.elements; - - var x = q.x, y = q.y, z = q.z, w = q.w; - var x2 = x + x, y2 = y + y, z2 = z + z; - var xx = x * x2, xy = x * y2, xz = x * z2; - var yy = y * y2, yz = y * z2, zz = z * z2; - var wx = w * x2, wy = w * y2, wz = w * z2; - - te[0] = 1 - ( yy + zz ); - te[4] = xy - wz; - te[8] = xz + wy; - - te[1] = xy + wz; - te[5] = 1 - ( xx + zz ); - te[9] = yz - wx; - - te[2] = xz - wy; - te[6] = yz + wx; - te[10] = 1 - ( xx + yy ); - - return this; - - }, - - compose: function ( translation, rotation, scale ) { - var te = this.elements; - var mRotation = THREE.Matrix4.__m1; - var mScale = THREE.Matrix4.__m2; - - mRotation.identity(); - mRotation.setRotationFromQuaternion( rotation ); - - mScale.makeScale( scale.x, scale.y, scale.z ); - - this.multiply( mRotation, mScale ); - - te[12] = translation.x; - te[13] = translation.y; - te[14] = translation.z; - - return this; - - }, - - decompose: function ( translation, rotation, scale ) { - - // grab the axis vectors - var te = this.elements; - var x = THREE.Matrix4.__v1; - var y = THREE.Matrix4.__v2; - var z = THREE.Matrix4.__v3; - - x.set( te[0], te[1], te[2] ); - y.set( te[4], te[5], te[6] ); - z.set( te[8], te[9], te[10] ); - - translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3(); - rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion(); - scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3(); - - scale.x = x.length(); - scale.y = y.length(); - scale.z = z.length(); - - translation.x = te[12]; - translation.y = te[13]; - translation.z = te[14]; - - // scale the rotation part - - var matrix = THREE.Matrix4.__m1; - - matrix.copy( this ); - - matrix.elements[0] /= scale.x; - matrix.elements[1] /= scale.x; - matrix.elements[2] /= scale.x; - - matrix.elements[4] /= scale.y; - matrix.elements[5] /= scale.y; - matrix.elements[6] /= scale.y; - - matrix.elements[8] /= scale.z; - matrix.elements[9] /= scale.z; - matrix.elements[10] /= scale.z; - - rotation.setFromRotationMatrix( matrix ); - - return [ translation, rotation, scale ]; - - }, - - extractPosition: function ( m ) { - var te = this.elements; - var me = m.elements; - te[12] = me[12]; - te[13] = me[13]; - te[14] = me[14]; - - return this; - - }, - - extractRotation: function ( m ) { - var te = this.elements; - var me = m.elements; - - var vector = THREE.Matrix4.__v1; - - var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length(); - var scaleY = 1 / vector.set( me[4], me[5], me[6] ).length(); - var scaleZ = 1 / vector.set( me[8], me[9], me[10] ).length(); - - te[0] = me[0] * scaleX; - te[1] = me[1] * scaleX; - te[2] = me[2] * scaleX; - - te[4] = me[4] * scaleY; - te[5] = me[5] * scaleY; - te[6] = me[6] * scaleY; - - te[8] = me[8] * scaleZ; - te[9] = me[9] * scaleZ; - te[10] = me[10] * scaleZ; - - return this; - - }, - - // - - translate: function ( v ) { - var te = this.elements; - var x = v.x, y = v.y, z = v.z; - - te[12] = te[0] * x + te[4] * y + te[8] * z + te[12]; - te[13] = te[1] * x + te[5] * y + te[9] * z + te[13]; - te[14] = te[2] * x + te[6] * y + te[10] * z + te[14]; - te[15] = te[3] * x + te[7] * y + te[11] * z + te[15]; - - return this; - - }, - - rotateX: function ( angle ) { - var te = this.elements; - var m12 = te[4]; - var m22 = te[5]; - var m32 = te[6]; - var m42 = te[7]; - var m13 = te[8]; - var m23 = te[9]; - var m33 = te[10]; - var m43 = te[11]; - var c = Math.cos( angle ); - var s = Math.sin( angle ); - - te[4] = c * m12 + s * m13; - te[5] = c * m22 + s * m23; - te[6] = c * m32 + s * m33; - te[7] = c * m42 + s * m43; - - te[8] = c * m13 - s * m12; - te[9] = c * m23 - s * m22; - te[10] = c * m33 - s * m32; - te[11] = c * m43 - s * m42; - - return this; - - }, - - rotateY: function ( angle ) { - var te = this.elements; - var m11 = te[0]; - var m21 = te[1]; - var m31 = te[2]; - var m41 = te[3]; - var m13 = te[8]; - var m23 = te[9]; - var m33 = te[10]; - var m43 = te[11]; - var c = Math.cos( angle ); - var s = Math.sin( angle ); - - te[0] = c * m11 - s * m13; - te[1] = c * m21 - s * m23; - te[2] = c * m31 - s * m33; - te[3] = c * m41 - s * m43; - - te[8] = c * m13 + s * m11; - te[9] = c * m23 + s * m21; - te[10] = c * m33 + s * m31; - te[11] = c * m43 + s * m41; - - return this; - - }, - - rotateZ: function ( angle ) { - var te = this.elements; - var m11 = te[0]; - var m21 = te[1]; - var m31 = te[2]; - var m41 = te[3]; - var m12 = te[4]; - var m22 = te[5]; - var m32 = te[6]; - var m42 = te[7]; - var c = Math.cos( angle ); - var s = Math.sin( angle ); - - te[0] = c * m11 + s * m12; - te[1] = c * m21 + s * m22; - te[2] = c * m31 + s * m32; - te[3] = c * m41 + s * m42; - - te[4] = c * m12 - s * m11; - te[5] = c * m22 - s * m21; - te[6] = c * m32 - s * m31; - te[7] = c * m42 - s * m41; - - return this; - - }, - - rotateByAxis: function ( axis, angle ) { - var te = this.elements; - // optimize by checking axis - - if ( axis.x === 1 && axis.y === 0 && axis.z === 0 ) { - - return this.rotateX( angle ); - - } else if ( axis.x === 0 && axis.y === 1 && axis.z === 0 ) { - - return this.rotateY( angle ); - - } else if ( axis.x === 0 && axis.y === 0 && axis.z === 1 ) { - - return this.rotateZ( angle ); - - } - - var x = axis.x, y = axis.y, z = axis.z; - var n = Math.sqrt(x * x + y * y + z * z); - - x /= n; - y /= n; - z /= n; - - var xx = x * x, yy = y * y, zz = z * z; - var c = Math.cos( angle ); - var s = Math.sin( angle ); - var oneMinusCosine = 1 - c; - var xy = x * y * oneMinusCosine; - var xz = x * z * oneMinusCosine; - var yz = y * z * oneMinusCosine; - var xs = x * s; - var ys = y * s; - var zs = z * s; - - var r11 = xx + (1 - xx) * c; - var r21 = xy + zs; - var r31 = xz - ys; - var r12 = xy - zs; - var r22 = yy + (1 - yy) * c; - var r32 = yz + xs; - var r13 = xz + ys; - var r23 = yz - xs; - var r33 = zz + (1 - zz) * c; - - var m11 = te[0], m21 = te[1], m31 = te[2], m41 = te[3]; - var m12 = te[4], m22 = te[5], m32 = te[6], m42 = te[7]; - var m13 = te[8], m23 = te[9], m33 = te[10], m43 = te[11]; - var m14 = te[12], m24 = te[13], m34 = te[14], m44 = te[15]; - - te[0] = r11 * m11 + r21 * m12 + r31 * m13; - te[1] = r11 * m21 + r21 * m22 + r31 * m23; - te[2] = r11 * m31 + r21 * m32 + r31 * m33; - te[3] = r11 * m41 + r21 * m42 + r31 * m43; - - te[4] = r12 * m11 + r22 * m12 + r32 * m13; - te[5] = r12 * m21 + r22 * m22 + r32 * m23; - te[6] = r12 * m31 + r22 * m32 + r32 * m33; - te[7] = r12 * m41 + r22 * m42 + r32 * m43; - - te[8] = r13 * m11 + r23 * m12 + r33 * m13; - te[9] = r13 * m21 + r23 * m22 + r33 * m23; - te[10] = r13 * m31 + r23 * m32 + r33 * m33; - te[11] = r13 * m41 + r23 * m42 + r33 * m43; - - return this; - - }, - - scale: function ( v ) { - - var te = this.elements; - var x = v.x, y = v.y, z = v.z; - - te[0] *= x; te[4] *= y; te[8] *= z; - te[1] *= x; te[5] *= y; te[9] *= z; - te[2] *= x; te[6] *= y; te[10] *= z; - te[3] *= x; te[7] *= y; te[11] *= z; - - return this; - - }, - - getMaxScaleOnAxis: function () { - - var te = this.elements; - - var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2]; - var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]; - var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]; - - return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) ); - - }, - - // - - makeTranslation: function ( x, y, z ) { - - this.set( - - 1, 0, 0, x, - 0, 1, 0, y, - 0, 0, 1, z, - 0, 0, 0, 1 - - ); - - return this; - - }, - - makeRotationX: function ( theta ) { - - var c = Math.cos( theta ), s = Math.sin( theta ); - - this.set( - - 1, 0, 0, 0, - 0, c, -s, 0, - 0, s, c, 0, - 0, 0, 0, 1 - - ); - - return this; - - }, - - makeRotationY: function ( theta ) { - - var c = Math.cos( theta ), s = Math.sin( theta ); - - this.set( - - c, 0, s, 0, - 0, 1, 0, 0, - -s, 0, c, 0, - 0, 0, 0, 1 - - ); - - return this; - - }, - - makeRotationZ: function ( theta ) { - - var c = Math.cos( theta ), s = Math.sin( theta ); - - this.set( - - c, -s, 0, 0, - s, c, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - - ); - - return this; - - }, - - makeRotationAxis: function ( axis, angle ) { - - // Based on http://www.gamedev.net/reference/articles/article1199.asp - - var c = Math.cos( angle ); - var s = Math.sin( angle ); - var t = 1 - c; - var x = axis.x, y = axis.y, z = axis.z; - var tx = t * x, ty = t * y; - - this.set( - - tx * x + c, tx * y - s * z, tx * z + s * y, 0, - tx * y + s * z, ty * y + c, ty * z - s * x, 0, - tx * z - s * y, ty * z + s * x, t * z * z + c, 0, - 0, 0, 0, 1 - - ); - - return this; - - }, - - makeScale: function ( x, y, z ) { - - this.set( - - x, 0, 0, 0, - 0, y, 0, 0, - 0, 0, z, 0, - 0, 0, 0, 1 - - ); - - return this; - - }, - - makeFrustum: function ( left, right, bottom, top, near, far ) { - var te = this.elements; - var x = 2 * near / ( right - left ); - var y = 2 * near / ( top - bottom ); - - var a = ( right + left ) / ( right - left ); - var b = ( top + bottom ) / ( top - bottom ); - var c = - ( far + near ) / ( far - near ); - var d = - 2 * far * near / ( far - near ); - - te[0] = x; te[4] = 0; te[8] = a; te[12] = 0; - te[1] = 0; te[5] = y; te[9] = b; te[13] = 0; - te[2] = 0; te[6] = 0; te[10] = c; te[14] = d; - te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0; - - return this; - - }, - - makePerspective: function ( fov, aspect, near, far ) { - - var ymax = near * Math.tan( fov * Math.PI / 360 ); - var ymin = - ymax; - var xmin = ymin * aspect; - var xmax = ymax * aspect; - - return this.makeFrustum( xmin, xmax, ymin, ymax, near, far ); - - }, - - makeOrthographic: function ( left, right, top, bottom, near, far ) { - var te = this.elements; - var w = right - left; - var h = top - bottom; - var p = far - near; - - var x = ( right + left ) / w; - var y = ( top + bottom ) / h; - var z = ( far + near ) / p; - - te[0] = 2 / w; te[4] = 0; te[8] = 0; te[12] = -x; - te[1] = 0; te[5] = 2 / h; te[9] = 0; te[13] = -y; - te[2] = 0; te[6] = 0; te[10] = -2 / p; te[14] = -z; - te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1; - - return this; - - }, - - - clone: function () { - var te = this.elements; - return new THREE.Matrix4( - - te[0], te[4], te[8], te[12], - te[1], te[5], te[9], te[13], - te[2], te[6], te[10], te[14], - te[3], te[7], te[11], te[15] - - ); - - } - -}; - -THREE.Matrix4.__v1 = new THREE.Vector3(); -THREE.Matrix4.__v2 = new THREE.Vector3(); -THREE.Matrix4.__v3 = new THREE.Vector3(); - -THREE.Matrix4.__m1 = new THREE.Matrix4(); -THREE.Matrix4.__m2 = new THREE.Matrix4(); -/** - * @author mr.doob / http://mrdoob.com/ - * @author mikael emtinger / http://gomo.se/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Object3D = function () { - - this.id = THREE.Object3DCount ++; - - this.name = ''; - - this.parent = undefined; - this.children = []; - - this.up = new THREE.Vector3( 0, 1, 0 ); - - this.position = new THREE.Vector3(); - this.rotation = new THREE.Vector3(); - this.eulerOrder = 'XYZ'; - this.scale = new THREE.Vector3( 1, 1, 1 ); - - this.doubleSided = false; - this.flipSided = false; - - this.renderDepth = null; - - this.rotationAutoUpdate = true; - - this.matrix = new THREE.Matrix4(); - this.matrixWorld = new THREE.Matrix4(); - this.matrixRotationWorld = new THREE.Matrix4(); - - this.matrixAutoUpdate = true; - this.matrixWorldNeedsUpdate = true; - - this.quaternion = new THREE.Quaternion(); - this.useQuaternion = false; - - this.boundRadius = 0.0; - this.boundRadiusScale = 1.0; - - this.visible = true; - - this.castShadow = false; - this.receiveShadow = false; - - this.frustumCulled = true; - - this._vector = new THREE.Vector3(); - -}; - - -THREE.Object3D.prototype = { - - constructor: THREE.Object3D, - - applyMatrix: function ( matrix ) { - - this.matrix.multiply( matrix, this.matrix ); - - this.scale.getScaleFromMatrix( this.matrix ); - this.rotation.getRotationFromMatrix( this.matrix, this.scale ); - this.position.getPositionFromMatrix( this.matrix ); - - }, - - translate: function ( distance, axis ) { - - this.matrix.rotateAxis( axis ); - this.position.addSelf( axis.multiplyScalar( distance ) ); - - }, - - translateX: function ( distance ) { - - this.translate( distance, this._vector.set( 1, 0, 0 ) ); - - }, - - translateY: function ( distance ) { - - this.translate( distance, this._vector.set( 0, 1, 0 ) ); - - }, - - translateZ: function ( distance ) { - - this.translate( distance, this._vector.set( 0, 0, 1 ) ); - - }, - - lookAt: function ( vector ) { - - // TODO: Add hierarchy support. - - this.matrix.lookAt( vector, this.position, this.up ); - - if ( this.rotationAutoUpdate ) { - - this.rotation.getRotationFromMatrix( this.matrix ); - - } - - }, - - add: function ( object ) { - - if ( object === this ) { - - console.warn( 'THREE.Object3D.add: An object can\'t be added as a child of itself.' ); - return; - - } - - if ( object instanceof THREE.Object3D ) { // && this.children.indexOf( object ) === - 1 - - if ( object.parent !== undefined ) { - - object.parent.remove( object ); - - } - - object.parent = this; - this.children.push( object ); - - // add to scene - - var scene = this; - - while ( scene.parent !== undefined ) { - - scene = scene.parent; - - } - - if ( scene !== undefined && scene instanceof THREE.Scene ) { - - scene.__addObject( object ); - - } - - } - - }, - - remove: function ( object ) { - - var index = this.children.indexOf( object ); - - if ( index !== - 1 ) { - - object.parent = undefined; - this.children.splice( index, 1 ); - - // remove from scene - - var scene = this; - - while ( scene.parent !== undefined ) { - - scene = scene.parent; - - } - - if ( scene !== undefined && scene instanceof THREE.Scene ) { - - scene.__removeObject( object ); - - } - - } - - }, - - getChildByName: function ( name, recursive ) { - - var c, cl, child; - - for ( c = 0, cl = this.children.length; c < cl; c ++ ) { - - child = this.children[ c ]; - - if ( child.name === name ) { - - return child; - - } - - if ( recursive ) { - - child = child.getChildByName( name, recursive ); - - if ( child !== undefined ) { - - return child; - - } - - } - - } - - return undefined; - - }, - - updateMatrix: function () { - - this.matrix.setPosition( this.position ); - - if ( this.useQuaternion ) { - - this.matrix.setRotationFromQuaternion( this.quaternion ); - - } else { - - this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder ); - - } - - if ( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) { - - this.matrix.scale( this.scale ); - this.boundRadiusScale = Math.max( this.scale.x, Math.max( this.scale.y, this.scale.z ) ); - - } - - this.matrixWorldNeedsUpdate = true; - - }, - - updateMatrixWorld: function ( force ) { - - this.matrixAutoUpdate && this.updateMatrix(); - - // update matrixWorld - - if ( this.matrixWorldNeedsUpdate || force ) { - - if ( this.parent ) { - - this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix ); - - } else { - - this.matrixWorld.copy( this.matrix ); - - } - - this.matrixWorldNeedsUpdate = false; - - force = true; - - } - - // update children - - for ( var i = 0, l = this.children.length; i < l; i ++ ) { - - this.children[ i ].updateMatrixWorld( force ); - - } - - } - -}; - -THREE.Object3DCount = 0; -/** - * @author mr.doob / http://mrdoob.com/ - * @author supereggbert / http://www.paulbrunt.co.uk/ - * @author julianwa / https://github.com/julianwa - */ - -THREE.Projector = function() { - - var _object, _objectCount, _objectPool = [], - _vertex, _vertexCount, _vertexPool = [], - _face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [], - _line, _lineCount, _linePool = [], - _particle, _particleCount, _particlePool = [], - - _renderData = { objects: [], sprites: [], lights: [], elements: [] }, - - _vector3 = new THREE.Vector3(), - _vector4 = new THREE.Vector4(), - - _projScreenMatrix = new THREE.Matrix4(), - _projScreenobjectMatrixWorld = new THREE.Matrix4(), - - _frustum = new THREE.Frustum(), - - _clippedVertex1PositionScreen = new THREE.Vector4(), - _clippedVertex2PositionScreen = new THREE.Vector4(), - - _face3VertexNormals; - - this.projectVector = function ( vector, camera ) { - - camera.matrixWorldInverse.getInverse( camera.matrixWorld ); - - _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse ); - _projScreenMatrix.multiplyVector3( vector ); - - return vector; - - }; - - this.unprojectVector = function ( vector, camera ) { - - camera.projectionMatrixInverse.getInverse( camera.projectionMatrix ); - - _projScreenMatrix.multiply( camera.matrixWorld, camera.projectionMatrixInverse ); - _projScreenMatrix.multiplyVector3( vector ); - - return vector; - - }; - - this.pickingRay = function ( vector, camera ) { - - var end, ray, t; - - // set two vectors with opposing z values - vector.z = -1.0; - end = new THREE.Vector3( vector.x, vector.y, 1.0 ); - - this.unprojectVector( vector, camera ); - this.unprojectVector( end, camera ); - - // find direction from vector to end - end.subSelf( vector ).normalize(); - - return new THREE.Ray( vector, end ); - - }; - - this.projectGraph = function ( root, sort ) { - - _objectCount = 0; - - _renderData.objects.length = 0; - _renderData.sprites.length = 0; - _renderData.lights.length = 0; - - var projectObject = function ( object ) { - - if ( object.visible === false ) return; - - if ( ( object instanceof THREE.Mesh || object instanceof THREE.Line ) && - ( object.frustumCulled === false || _frustum.contains( object ) ) ) { - - _vector3.copy( object.matrixWorld.getPosition() ); - _projScreenMatrix.multiplyVector3( _vector3 ); - - _object = getNextObjectInPool(); - _object.object = object; - _object.z = _vector3.z; - - _renderData.objects.push( _object ); - - } else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) { - - _vector3.copy( object.matrixWorld.getPosition() ); - _projScreenMatrix.multiplyVector3( _vector3 ); - - _object = getNextObjectInPool(); - _object.object = object; - _object.z = _vector3.z; - - _renderData.sprites.push( _object ); - - } else if ( object instanceof THREE.Light ) { - - _renderData.lights.push( object ); - - } - - for ( var c = 0, cl = object.children.length; c < cl; c ++ ) { - - projectObject( object.children[ c ] ); - - } - - }; - - projectObject( root ); - - sort && _renderData.objects.sort( painterSort ); - - return _renderData; - - }; - - this.projectScene = function ( scene, camera, sort ) { - - var near = camera.near, far = camera.far, visible = false, - o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object, - objectMatrixWorld, objectMatrixWorldRotation, - geometry, geometryMaterials, vertices, vertex, vertexPositionScreen, - faces, face, faceVertexNormals, normal, faceVertexUvs, uvs, - v1, v2, v3, v4; - - _face3Count = 0; - _face4Count = 0; - _lineCount = 0; - _particleCount = 0; - - _renderData.elements.length = 0; - - if ( camera.parent === undefined ) { - - console.warn( 'DEPRECATED: Camera hasn\'t been added to a Scene. Adding it...' ); - scene.add( camera ); - - } - - scene.updateMatrixWorld(); - - camera.matrixWorldInverse.getInverse( camera.matrixWorld ); - - _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse ); - - _frustum.setFromMatrix( _projScreenMatrix ); - - _renderData = this.projectGraph( scene, false ); - - for ( o = 0, ol = _renderData.objects.length; o < ol; o++ ) { - - object = _renderData.objects[ o ].object; - - objectMatrixWorld = object.matrixWorld; - - _vertexCount = 0; - - if ( object instanceof THREE.Mesh ) { - - geometry = object.geometry; - geometryMaterials = object.geometry.materials; - vertices = geometry.vertices; - faces = geometry.faces; - faceVertexUvs = geometry.faceVertexUvs; - - objectMatrixWorldRotation = object.matrixRotationWorld.extractRotation( objectMatrixWorld ); - - for ( v = 0, vl = vertices.length; v < vl; v ++ ) { - - _vertex = getNextVertexInPool(); - _vertex.positionWorld.copy( vertices[ v ] ); - - objectMatrixWorld.multiplyVector3( _vertex.positionWorld ); - - _vertex.positionScreen.copy( _vertex.positionWorld ); - _projScreenMatrix.multiplyVector4( _vertex.positionScreen ); - - _vertex.positionScreen.x /= _vertex.positionScreen.w; - _vertex.positionScreen.y /= _vertex.positionScreen.w; - - _vertex.visible = _vertex.positionScreen.z > near && _vertex.positionScreen.z < far; - - } - - for ( f = 0, fl = faces.length; f < fl; f ++ ) { - - face = faces[ f ]; - - if ( face instanceof THREE.Face3 ) { - - v1 = _vertexPool[ face.a ]; - v2 = _vertexPool[ face.b ]; - v3 = _vertexPool[ face.c ]; - - if ( v1.visible && v2.visible && v3.visible ) { - - visible = ( ( v3.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) - - ( v3.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0; - - if ( object.doubleSided || visible != object.flipSided ) { - - _face = getNextFace3InPool(); - - _face.v1.copy( v1 ); - _face.v2.copy( v2 ); - _face.v3.copy( v3 ); - - } else { - - continue; - - } - - } else { - - continue; - - } - - } else if ( face instanceof THREE.Face4 ) { - - v1 = _vertexPool[ face.a ]; - v2 = _vertexPool[ face.b ]; - v3 = _vertexPool[ face.c ]; - v4 = _vertexPool[ face.d ]; - - if ( v1.visible && v2.visible && v3.visible && v4.visible ) { - - visible = ( v4.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) - - ( v4.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) < 0 || - ( v2.positionScreen.x - v3.positionScreen.x ) * ( v4.positionScreen.y - v3.positionScreen.y ) - - ( v2.positionScreen.y - v3.positionScreen.y ) * ( v4.positionScreen.x - v3.positionScreen.x ) < 0; - - - if ( object.doubleSided || visible != object.flipSided ) { - - _face = getNextFace4InPool(); - - _face.v1.copy( v1 ); - _face.v2.copy( v2 ); - _face.v3.copy( v3 ); - _face.v4.copy( v4 ); - - } else { - - continue; - - } - - } else { - - continue; - - } - - } - - _face.normalWorld.copy( face.normal ); - if ( !visible && ( object.flipSided || object.doubleSided ) ) _face.normalWorld.negate(); - objectMatrixWorldRotation.multiplyVector3( _face.normalWorld ); - - _face.centroidWorld.copy( face.centroid ); - objectMatrixWorld.multiplyVector3( _face.centroidWorld ); - - _face.centroidScreen.copy( _face.centroidWorld ); - _projScreenMatrix.multiplyVector3( _face.centroidScreen ); - - faceVertexNormals = face.vertexNormals; - - for ( n = 0, nl = faceVertexNormals.length; n < nl; n ++ ) { - - normal = _face.vertexNormalsWorld[ n ]; - normal.copy( faceVertexNormals[ n ] ); - if ( !visible && ( object.flipSided || object.doubleSided ) ) normal.negate(); - objectMatrixWorldRotation.multiplyVector3( normal ); - - } - - for ( c = 0, cl = faceVertexUvs.length; c < cl; c ++ ) { - - uvs = faceVertexUvs[ c ][ f ]; - - if ( !uvs ) continue; - - for ( u = 0, ul = uvs.length; u < ul; u ++ ) { - - _face.uvs[ c ][ u ] = uvs[ u ]; - - } - - } - - _face.material = object.material; - _face.faceMaterial = face.materialIndex !== null ? geometryMaterials[ face.materialIndex ] : null; - - _face.z = _face.centroidScreen.z; - - _renderData.elements.push( _face ); - - } - - } else if ( object instanceof THREE.Line ) { - - _projScreenobjectMatrixWorld.multiply( _projScreenMatrix, objectMatrixWorld ); - - vertices = object.geometry.vertices; - - v1 = getNextVertexInPool(); - v1.positionScreen.copy( vertices[ 0 ] ); - _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen ); - - // Handle LineStrip and LinePieces - var step = object.type === THREE.LinePieces ? 2 : 1; - - for ( v = 1, vl = vertices.length; v < vl; v ++ ) { - - v1 = getNextVertexInPool(); - v1.positionScreen.copy( vertices[ v ] ); - _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen ); - - if ( ( v + 1 ) % step > 0 ) continue; - - v2 = _vertexPool[ _vertexCount - 2 ]; - - _clippedVertex1PositionScreen.copy( v1.positionScreen ); - _clippedVertex2PositionScreen.copy( v2.positionScreen ); - - if ( clipLine( _clippedVertex1PositionScreen, _clippedVertex2PositionScreen ) ) { - - // Perform the perspective divide - _clippedVertex1PositionScreen.multiplyScalar( 1 / _clippedVertex1PositionScreen.w ); - _clippedVertex2PositionScreen.multiplyScalar( 1 / _clippedVertex2PositionScreen.w ); - - _line = getNextLineInPool(); - _line.v1.positionScreen.copy( _clippedVertex1PositionScreen ); - _line.v2.positionScreen.copy( _clippedVertex2PositionScreen ); - - _line.z = Math.max( _clippedVertex1PositionScreen.z, _clippedVertex2PositionScreen.z ); - - _line.material = object.material; - - _renderData.elements.push( _line ); - - } - - } - - } - - } - - for ( o = 0, ol = _renderData.sprites.length; o < ol; o++ ) { - - object = _renderData.sprites[ o ].object; - - objectMatrixWorld = object.matrixWorld; - - if ( object instanceof THREE.Particle ) { - - _vector4.set( objectMatrixWorld.elements[12], objectMatrixWorld.elements[13], objectMatrixWorld.elements[14], 1 ); - _projScreenMatrix.multiplyVector4( _vector4 ); - - _vector4.z /= _vector4.w; - - if ( _vector4.z > 0 && _vector4.z < 1 ) { - - _particle = getNextParticleInPool(); - _particle.x = _vector4.x / _vector4.w; - _particle.y = _vector4.y / _vector4.w; - _particle.z = _vector4.z; - - _particle.rotation = object.rotation.z; - - _particle.scale.x = object.scale.x * Math.abs( _particle.x - ( _vector4.x + camera.projectionMatrix.elements[0] ) / ( _vector4.w + camera.projectionMatrix.elements[12] ) ); - _particle.scale.y = object.scale.y * Math.abs( _particle.y - ( _vector4.y + camera.projectionMatrix.elements[5] ) / ( _vector4.w + camera.projectionMatrix.elements[13] ) ); - - _particle.material = object.material; - - _renderData.elements.push( _particle ); - - } - - } - - } - - sort && _renderData.elements.sort( painterSort ); - - return _renderData; - - }; - - // Pools - - function getNextObjectInPool() { - - var object = _objectPool[ _objectCount ] = _objectPool[ _objectCount ] || new THREE.RenderableObject(); - - _objectCount ++; - - return object; - - } - - function getNextVertexInPool() { - - var vertex = _vertexPool[ _vertexCount ] = _vertexPool[ _vertexCount ] || new THREE.RenderableVertex(); - - _vertexCount ++; - - return vertex; - - } - - function getNextFace3InPool() { - - var face = _face3Pool[ _face3Count ] = _face3Pool[ _face3Count ] || new THREE.RenderableFace3(); - - _face3Count ++; - - return face; - - } - - function getNextFace4InPool() { - - var face = _face4Pool[ _face4Count ] = _face4Pool[ _face4Count ] || new THREE.RenderableFace4(); - - _face4Count ++; - - return face; - - } - - function getNextLineInPool() { - - var line = _linePool[ _lineCount ] = _linePool[ _lineCount ] || new THREE.RenderableLine(); - - _lineCount ++; - - return line; - - } - - function getNextParticleInPool() { - - var particle = _particlePool[ _particleCount ] = _particlePool[ _particleCount ] || new THREE.RenderableParticle(); - _particleCount ++; - return particle; - - } - - // - - function painterSort( a, b ) { - - return b.z - a.z; - - } - - function clipLine( s1, s2 ) { - - var alpha1 = 0, alpha2 = 1, - - // Calculate the boundary coordinate of each vertex for the near and far clip planes, - // Z = -1 and Z = +1, respectively. - bc1near = s1.z + s1.w, - bc2near = s2.z + s2.w, - bc1far = - s1.z + s1.w, - bc2far = - s2.z + s2.w; - - if ( bc1near >= 0 && bc2near >= 0 && bc1far >= 0 && bc2far >= 0 ) { - - // Both vertices lie entirely within all clip planes. - return true; - - } else if ( ( bc1near < 0 && bc2near < 0) || (bc1far < 0 && bc2far < 0 ) ) { - - // Both vertices lie entirely outside one of the clip planes. - return false; - - } else { - - // The line segment spans at least one clip plane. - - if ( bc1near < 0 ) { - - // v1 lies outside the near plane, v2 inside - alpha1 = Math.max( alpha1, bc1near / ( bc1near - bc2near ) ); - - } else if ( bc2near < 0 ) { - - // v2 lies outside the near plane, v1 inside - alpha2 = Math.min( alpha2, bc1near / ( bc1near - bc2near ) ); - - } - - if ( bc1far < 0 ) { - - // v1 lies outside the far plane, v2 inside - alpha1 = Math.max( alpha1, bc1far / ( bc1far - bc2far ) ); - - } else if ( bc2far < 0 ) { - - // v2 lies outside the far plane, v2 inside - alpha2 = Math.min( alpha2, bc1far / ( bc1far - bc2far ) ); - - } - - if ( alpha2 < alpha1 ) { - - // The line segment spans two boundaries, but is outside both of them. - // (This can't happen when we're only clipping against just near/far but good - // to leave the check here for future usage if other clip planes are added.) - return false; - - } else { - - // Update the s1 and s2 vertices to match the clipped line segment. - s1.lerpSelf( s2, alpha1 ); - s2.lerpSelf( s1, 1 - alpha2 ); - - return true; - - } - - } - - } - -}; -/** - * @author mikael emtinger / http://gomo.se/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Quaternion = function( x, y, z, w ) { - - this.x = x || 0; - this.y = y || 0; - this.z = z || 0; - this.w = ( w !== undefined ) ? w : 1; - -}; - -THREE.Quaternion.prototype = { - - constructor: THREE.Quaternion, - - set: function ( x, y, z, w ) { - - this.x = x; - this.y = y; - this.z = z; - this.w = w; - - return this; - - }, - - copy: function ( q ) { - - this.x = q.x; - this.y = q.y; - this.z = q.z; - this.w = q.w; - - return this; - - }, - - setFromEuler: function ( vector ) { - - var c = Math.PI / 360, // 0.5 * Math.PI / 360, // 0.5 is an optimization - x = vector.x * c, - y = vector.y * c, - z = vector.z * c, - - c1 = Math.cos( y ), - s1 = Math.sin( y ), - c2 = Math.cos( -z ), - s2 = Math.sin( -z ), - c3 = Math.cos( x ), - s3 = Math.sin( x ), - - c1c2 = c1 * c2, - s1s2 = s1 * s2; - - this.w = c1c2 * c3 - s1s2 * s3; - this.x = c1c2 * s3 + s1s2 * c3; - this.y = s1 * c2 * c3 + c1 * s2 * s3; - this.z = c1 * s2 * c3 - s1 * c2 * s3; - - return this; - - }, - - setFromAxisAngle: function ( axis, angle ) { - - // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm - // axis have to be normalized - - var halfAngle = angle / 2, - s = Math.sin( halfAngle ); - - this.x = axis.x * s; - this.y = axis.y * s; - this.z = axis.z * s; - this.w = Math.cos( halfAngle ); - - return this; - - }, - - setFromRotationMatrix: function ( m ) { - - // Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm - - function copySign( a, b ) { - - return b < 0 ? -Math.abs( a ) : Math.abs( a ); - - } - - var absQ = Math.pow( m.determinant(), 1.0 / 3.0 ); - this.w = Math.sqrt( Math.max( 0, absQ + m.elements[0] + m.elements[5] + m.elements[10] ) ) / 2; - this.x = Math.sqrt( Math.max( 0, absQ + m.elements[0] - m.elements[5] - m.elements[10] ) ) / 2; - this.y = Math.sqrt( Math.max( 0, absQ - m.elements[0] + m.elements[5] - m.elements[10] ) ) / 2; - this.z = Math.sqrt( Math.max( 0, absQ - m.elements[0] - m.elements[5] + m.elements[10] ) ) / 2; - this.x = copySign( this.x, ( m.elements[6] - m.elements[9] ) ); - this.y = copySign( this.y, ( m.elements[8] - m.elements[2] ) ); - this.z = copySign( this.z, ( m.elements[1] - m.elements[4] ) ); - this.normalize(); - - return this; - - }, - - calculateW : function () { - - this.w = - Math.sqrt( Math.abs( 1.0 - this.x * this.x - this.y * this.y - this.z * this.z ) ); - - return this; - - }, - - inverse: function () { - - this.x *= -1; - this.y *= -1; - this.z *= -1; - - return this; - - }, - - length: function () { - - return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w ); - - }, - - normalize: function () { - - var l = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w ); - - if ( l === 0 ) { - - this.x = 0; - this.y = 0; - this.z = 0; - this.w = 0; - - } else { - - l = 1 / l; - - this.x = this.x * l; - this.y = this.y * l; - this.z = this.z * l; - this.w = this.w * l; - - } - - return this; - - }, - - multiply: function ( a, b ) { - - // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm - - this.x = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x; - this.y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y; - this.z = a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z; - this.w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w; - - return this; - - }, - - multiplySelf: function ( b ) { - - var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w, - qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w; - - this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby; - this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz; - this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx; - this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz; - - return this; - - }, - - multiplyVector3: function ( vector, dest ) { - - if ( !dest ) { dest = vector; } - - var x = vector.x, y = vector.y, z = vector.z, - qx = this.x, qy = this.y, qz = this.z, qw = this.w; - - // calculate quat * vector - - var ix = qw * x + qy * z - qz * y, - iy = qw * y + qz * x - qx * z, - iz = qw * z + qx * y - qy * x, - iw = -qx * x - qy * y - qz * z; - - // calculate result * inverse quat - - dest.x = ix * qw + iw * -qx + iy * -qz - iz * -qy; - dest.y = iy * qw + iw * -qy + iz * -qx - ix * -qz; - dest.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; - - return dest; - - }, - - clone: function () { - - return new THREE.Quaternion( this.x, this.y, this.z, this.w ); - - } - -} - -THREE.Quaternion.slerp = function ( qa, qb, qm, t ) { - - // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/ - - var cosHalfTheta = qa.w * qb.w + qa.x * qb.x + qa.y * qb.y + qa.z * qb.z; - - if (cosHalfTheta < 0) { - qm.w = -qb.w; qm.x = -qb.x; qm.y = -qb.y; qm.z = -qb.z; - cosHalfTheta = -cosHalfTheta; - } else { - qm.copy(qb); - } - - if ( Math.abs( cosHalfTheta ) >= 1.0 ) { - - qm.w = qa.w; qm.x = qa.x; qm.y = qa.y; qm.z = qa.z; - return qm; - - } - - var halfTheta = Math.acos( cosHalfTheta ), - sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta ); - - if ( Math.abs( sinHalfTheta ) < 0.001 ) { - - qm.w = 0.5 * ( qa.w + qb.w ); - qm.x = 0.5 * ( qa.x + qb.x ); - qm.y = 0.5 * ( qa.y + qb.y ); - qm.z = 0.5 * ( qa.z + qb.z ); - - return qm; - - } - - var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta, - ratioB = Math.sin( t * halfTheta ) / sinHalfTheta; - - qm.w = ( qa.w * ratioA + qm.w * ratioB ); - qm.x = ( qa.x * ratioA + qm.x * ratioB ); - qm.y = ( qa.y * ratioA + qm.y * ratioB ); - qm.z = ( qa.z * ratioA + qm.z * ratioB ); - - return qm; - -} -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.Vertex = function () { - - console.warn( 'THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.') - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) { - - this.a = a; - this.b = b; - this.c = c; - - this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3(); - this.vertexNormals = normal instanceof Array ? normal : [ ]; - - this.color = color instanceof THREE.Color ? color : new THREE.Color(); - this.vertexColors = color instanceof Array ? color : []; - - this.vertexTangents = []; - - this.materialIndex = materialIndex; - - this.centroid = new THREE.Vector3(); - -}; - -THREE.Face3.prototype = { - - constructor: THREE.Face3, - - clone: function () { - - var face = new THREE.Face3( this.a, this.b, this.c ); - - face.normal.copy( this.normal ); - face.color.copy( this.color ); - face.centroid.copy( this.centroid ); - - face.materialIndex = this.materialIndex; - - var i, il; - for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone(); - for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone(); - for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone(); - - return face; - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) { - - this.a = a; - this.b = b; - this.c = c; - this.d = d; - - this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3(); - this.vertexNormals = normal instanceof Array ? normal : [ ]; - - this.color = color instanceof THREE.Color ? color : new THREE.Color(); - this.vertexColors = color instanceof Array ? color : []; - - this.vertexTangents = []; - - this.materialIndex = materialIndex; - - this.centroid = new THREE.Vector3(); - -}; - -THREE.Face4.prototype = { - - constructor: THREE.Face4, - - clone: function () { - - var face = new THREE.Face4( this.a, this.b, this.c, this.d ); - - face.normal.copy( this.normal ); - face.color.copy( this.color ); - face.centroid.copy( this.centroid ); - - face.materialIndex = this.materialIndex; - - var i, il; - for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone(); - for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone(); - for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone(); - - return face; - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.UV = function ( u, v ) { - - this.u = u || 0; - this.v = v || 0; - -}; - -THREE.UV.prototype = { - - constructor: THREE.UV, - - set: function ( u, v ) { - - this.u = u; - this.v = v; - - return this; - - }, - - copy: function ( uv ) { - - this.u = uv.u; - this.v = uv.v; - - return this; - - }, - - lerpSelf: function ( uv, alpha ) { - - this.u += ( uv.u - this.u ) * alpha; - this.v += ( uv.v - this.v ) * alpha; - - return this; - - }, - - clone: function () { - - return new THREE.UV( this.u, this.v ); - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author kile / http://kile.stravaganza.org/ - * @author alteredq / http://alteredqualia.com/ - * @author mikael emtinger / http://gomo.se/ - * @author zz85 / http://www.lab4games.net/zz85/blog - */ - -THREE.Geometry = function () { - - this.id = THREE.GeometryCount ++; - - this.vertices = []; - this.colors = []; // one-to-one vertex colors, used in ParticleSystem, Line and Ribbon - - this.materials = []; - - this.faces = []; - - this.faceUvs = [[]]; - this.faceVertexUvs = [[]]; - - this.morphTargets = []; - this.morphColors = []; - this.morphNormals = []; - - this.skinWeights = []; - this.skinIndices = []; - - this.boundingBox = null; - this.boundingSphere = null; - - this.hasTangents = false; - - this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer. - -}; - -THREE.Geometry.prototype = { - - constructor : THREE.Geometry, - - applyMatrix: function ( matrix ) { - - var matrixRotation = new THREE.Matrix4(); - matrixRotation.extractRotation( matrix ); - - for ( var i = 0, il = this.vertices.length; i < il; i ++ ) { - - var vertex = this.vertices[ i ]; - - matrix.multiplyVector3( vertex ); - - } - - for ( var i = 0, il = this.faces.length; i < il; i ++ ) { - - var face = this.faces[ i ]; - - matrixRotation.multiplyVector3( face.normal ); - - for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) { - - matrixRotation.multiplyVector3( face.vertexNormals[ j ] ); - - } - - matrix.multiplyVector3( face.centroid ); - - } - - }, - - computeCentroids: function () { - - var f, fl, face; - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - face.centroid.set( 0, 0, 0 ); - - if ( face instanceof THREE.Face3 ) { - - face.centroid.addSelf( this.vertices[ face.a ] ); - face.centroid.addSelf( this.vertices[ face.b ] ); - face.centroid.addSelf( this.vertices[ face.c ] ); - face.centroid.divideScalar( 3 ); - - } else if ( face instanceof THREE.Face4 ) { - - face.centroid.addSelf( this.vertices[ face.a ] ); - face.centroid.addSelf( this.vertices[ face.b ] ); - face.centroid.addSelf( this.vertices[ face.c ] ); - face.centroid.addSelf( this.vertices[ face.d ] ); - face.centroid.divideScalar( 4 ); - - } - - } - - }, - - computeFaceNormals: function () { - - var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC, - cb = new THREE.Vector3(), ab = new THREE.Vector3(); - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - vA = this.vertices[ face.a ]; - vB = this.vertices[ face.b ]; - vC = this.vertices[ face.c ]; - - cb.sub( vC, vB ); - ab.sub( vA, vB ); - cb.crossSelf( ab ); - - if ( !cb.isZero() ) { - - cb.normalize(); - - } - - face.normal.copy( cb ); - - } - - }, - - computeVertexNormals: function () { - - var v, vl, f, fl, face, vertices; - - // create internal buffers for reuse when calling this method repeatedly - // (otherwise memory allocation / deallocation every frame is big resource hog) - - if ( this.__tmpVertices === undefined ) { - - this.__tmpVertices = new Array( this.vertices.length ); - vertices = this.__tmpVertices; - - for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) { - - vertices[ v ] = new THREE.Vector3(); - - } - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - if ( face instanceof THREE.Face3 ) { - - face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ]; - - } else if ( face instanceof THREE.Face4 ) { - - face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ]; - - } - - } - - } else { - - vertices = this.__tmpVertices; - - for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) { - - vertices[ v ].set( 0, 0, 0 ); - - } - - } - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - if ( face instanceof THREE.Face3 ) { - - vertices[ face.a ].addSelf( face.normal ); - vertices[ face.b ].addSelf( face.normal ); - vertices[ face.c ].addSelf( face.normal ); - - } else if ( face instanceof THREE.Face4 ) { - - vertices[ face.a ].addSelf( face.normal ); - vertices[ face.b ].addSelf( face.normal ); - vertices[ face.c ].addSelf( face.normal ); - vertices[ face.d ].addSelf( face.normal ); - - } - - } - - for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) { - - vertices[ v ].normalize(); - - } - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - if ( face instanceof THREE.Face3 ) { - - face.vertexNormals[ 0 ].copy( vertices[ face.a ] ); - face.vertexNormals[ 1 ].copy( vertices[ face.b ] ); - face.vertexNormals[ 2 ].copy( vertices[ face.c ] ); - - } else if ( face instanceof THREE.Face4 ) { - - face.vertexNormals[ 0 ].copy( vertices[ face.a ] ); - face.vertexNormals[ 1 ].copy( vertices[ face.b ] ); - face.vertexNormals[ 2 ].copy( vertices[ face.c ] ); - face.vertexNormals[ 3 ].copy( vertices[ face.d ] ); - - } - - } - - }, - - computeMorphNormals: function () { - - var i, il, f, fl, face; - - // save original normals - // - create temp variables on first access - // otherwise just copy (for faster repeated calls) - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - if ( ! face.__originalFaceNormal ) { - - face.__originalFaceNormal = face.normal.clone(); - - } else { - - face.__originalFaceNormal.copy( face.normal ); - - } - - if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = []; - - for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) { - - if ( ! face.__originalVertexNormals[ i ] ) { - - face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone(); - - } else { - - face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] ); - - } - - } - - } - - // use temp geometry to compute face and vertex normals for each morph - - var tmpGeo = new THREE.Geometry(); - tmpGeo.faces = this.faces; - - for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) { - - // create on first access - - if ( ! this.morphNormals[ i ] ) { - - this.morphNormals[ i ] = {}; - this.morphNormals[ i ].faceNormals = []; - this.morphNormals[ i ].vertexNormals = []; - - var dstNormalsFace = this.morphNormals[ i ].faceNormals; - var dstNormalsVertex = this.morphNormals[ i ].vertexNormals; - - var faceNormal, vertexNormals; - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - faceNormal = new THREE.Vector3(); - - if ( face instanceof THREE.Face3 ) { - - vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() }; - - } else { - - vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3(), d: new THREE.Vector3() }; - - } - - dstNormalsFace.push( faceNormal ); - dstNormalsVertex.push( vertexNormals ); - - } - - } - - var morphNormals = this.morphNormals[ i ]; - - // set vertices to morph target - - tmpGeo.vertices = this.morphTargets[ i ].vertices; - - // compute morph normals - - tmpGeo.computeFaceNormals(); - tmpGeo.computeVertexNormals(); - - // store morph normals - - var faceNormal, vertexNormals; - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - faceNormal = morphNormals.faceNormals[ f ]; - vertexNormals = morphNormals.vertexNormals[ f ]; - - faceNormal.copy( face.normal ); - - if ( face instanceof THREE.Face3 ) { - - vertexNormals.a.copy( face.vertexNormals[ 0 ] ); - vertexNormals.b.copy( face.vertexNormals[ 1 ] ); - vertexNormals.c.copy( face.vertexNormals[ 2 ] ); - - } else { - - vertexNormals.a.copy( face.vertexNormals[ 0 ] ); - vertexNormals.b.copy( face.vertexNormals[ 1 ] ); - vertexNormals.c.copy( face.vertexNormals[ 2 ] ); - vertexNormals.d.copy( face.vertexNormals[ 3 ] ); - - } - - } - - } - - // restore original normals - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - face.normal = face.__originalFaceNormal; - face.vertexNormals = face.__originalVertexNormals; - - } - - }, - - computeTangents: function () { - - // based on http://www.terathon.com/code/tangent.html - // tangents go to vertices - - var f, fl, v, vl, i, il, vertexIndex, - face, uv, vA, vB, vC, uvA, uvB, uvC, - x1, x2, y1, y2, z1, z2, - s1, s2, t1, t2, r, t, test, - tan1 = [], tan2 = [], - sdir = new THREE.Vector3(), tdir = new THREE.Vector3(), - tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(), - n = new THREE.Vector3(), w; - - for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) { - - tan1[ v ] = new THREE.Vector3(); - tan2[ v ] = new THREE.Vector3(); - - } - - function handleTriangle( context, a, b, c, ua, ub, uc ) { - - vA = context.vertices[ a ]; - vB = context.vertices[ b ]; - vC = context.vertices[ c ]; - - uvA = uv[ ua ]; - uvB = uv[ ub ]; - uvC = uv[ uc ]; - - x1 = vB.x - vA.x; - x2 = vC.x - vA.x; - y1 = vB.y - vA.y; - y2 = vC.y - vA.y; - z1 = vB.z - vA.z; - z2 = vC.z - vA.z; - - s1 = uvB.u - uvA.u; - s2 = uvC.u - uvA.u; - t1 = uvB.v - uvA.v; - t2 = uvC.v - uvA.v; - - r = 1.0 / ( s1 * t2 - s2 * t1 ); - sdir.set( ( t2 * x1 - t1 * x2 ) * r, - ( t2 * y1 - t1 * y2 ) * r, - ( t2 * z1 - t1 * z2 ) * r ); - tdir.set( ( s1 * x2 - s2 * x1 ) * r, - ( s1 * y2 - s2 * y1 ) * r, - ( s1 * z2 - s2 * z1 ) * r ); - - tan1[ a ].addSelf( sdir ); - tan1[ b ].addSelf( sdir ); - tan1[ c ].addSelf( sdir ); - - tan2[ a ].addSelf( tdir ); - tan2[ b ].addSelf( tdir ); - tan2[ c ].addSelf( tdir ); - - } - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents - - if ( face instanceof THREE.Face3 ) { - - handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 ); - - } else if ( face instanceof THREE.Face4 ) { - - handleTriangle( this, face.a, face.b, face.d, 0, 1, 3 ); - handleTriangle( this, face.b, face.c, face.d, 1, 2, 3 ); - - } - - } - - var faceIndex = [ 'a', 'b', 'c', 'd' ]; - - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { - - face = this.faces[ f ]; - - for ( i = 0; i < face.vertexNormals.length; i++ ) { - - n.copy( face.vertexNormals[ i ] ); - - vertexIndex = face[ faceIndex[ i ] ]; - - t = tan1[ vertexIndex ]; - - // Gram-Schmidt orthogonalize - - tmp.copy( t ); - tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize(); - - // Calculate handedness - - tmp2.cross( face.vertexNormals[ i ], t ); - test = tmp2.dot( tan2[ vertexIndex ] ); - w = (test < 0.0) ? -1.0 : 1.0; - - face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w ); - - } - - } - - this.hasTangents = true; - - }, - - computeBoundingBox: function () { - - if ( ! this.boundingBox ) { - - this.boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() }; - - } - - if ( this.vertices.length > 0 ) { - - var position, firstPosition = this.vertices[ 0 ]; - - this.boundingBox.min.copy( firstPosition ); - this.boundingBox.max.copy( firstPosition ); - - var min = this.boundingBox.min, - max = this.boundingBox.max; - - for ( var v = 1, vl = this.vertices.length; v < vl; v ++ ) { - - position = this.vertices[ v ]; - - if ( position.x < min.x ) { - - min.x = position.x; - - } else if ( position.x > max.x ) { - - max.x = position.x; - - } - - if ( position.y < min.y ) { - - min.y = position.y; - - } else if ( position.y > max.y ) { - - max.y = position.y; - - } - - if ( position.z < min.z ) { - - min.z = position.z; - - } else if ( position.z > max.z ) { - - max.z = position.z; - - } - - } - - } else { - - this.boundingBox.min.set( 0, 0, 0 ); - this.boundingBox.max.set( 0, 0, 0 ); - - } - - }, - - computeBoundingSphere: function () { - - if ( ! this.boundingSphere ) this.boundingSphere = { radius: 0 }; - - var radius, maxRadius = 0; - - for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) { - - radius = this.vertices[ v ].length(); - if ( radius > maxRadius ) maxRadius = radius; - - } - - this.boundingSphere.radius = maxRadius; - - }, - - /* - * Checks for duplicate vertices with hashmap. - * Duplicated vertices are removed - * and faces' vertices are updated. - */ - - mergeVertices: function() { - - var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique) - var unique = [], changes = []; - - var v, key; - var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001 - var precision = Math.pow( 10, precisionPoints ); - var i,il, face; - - for ( i = 0, il = this.vertices.length; i < il; i ++ ) { - - v = this.vertices[ i ]; - key = [ Math.round( v.x * precision ), Math.round( v.y * precision ), Math.round( v.z * precision ) ].join( '_' ); - - if ( verticesMap[ key ] === undefined ) { - - verticesMap[ key ] = i; - unique.push( this.vertices[ i ] ); - changes[ i ] = unique.length - 1; - - } else { - - //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]); - changes[ i ] = changes[ verticesMap[ key ] ]; - - } - - }; - - - // Start to patch face indices - - for( i = 0, il = this.faces.length; i < il; i ++ ) { - - face = this.faces[ i ]; - - if ( face instanceof THREE.Face3 ) { - - face.a = changes[ face.a ]; - face.b = changes[ face.b ]; - face.c = changes[ face.c ]; - - } else if ( face instanceof THREE.Face4 ) { - - face.a = changes[ face.a ]; - face.b = changes[ face.b ]; - face.c = changes[ face.c ]; - face.d = changes[ face.d ]; - - } - - } - - // Use unique set of vertices - - this.vertices = unique; - - } - -}; - -THREE.GeometryCount = 0; -/** - * @author mr.doob / http://mrdoob.com/ - * @author mikael emtinger / http://gomo.se/ - */ - -THREE.Camera = function () { - - THREE.Object3D.call( this ); - - this.matrixWorldInverse = new THREE.Matrix4(); - - this.projectionMatrix = new THREE.Matrix4(); - this.projectionMatrixInverse = new THREE.Matrix4(); - -}; - -THREE.Camera.prototype = new THREE.Object3D(); -THREE.Camera.prototype.constructor = THREE.Camera; - -THREE.Camera.prototype.lookAt = function ( vector ) { - - // TODO: Add hierarchy support. - - this.matrix.lookAt( this.position, vector, this.up ); - - if ( this.rotationAutoUpdate ) { - - this.rotation.getRotationFromMatrix( this.matrix ); - - } - -}; -/** - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) { - - THREE.Camera.call( this ); - - this.left = left; - this.right = right; - this.top = top; - this.bottom = bottom; - - this.near = ( near !== undefined ) ? near : 0.1; - this.far = ( far !== undefined ) ? far : 2000; - - this.updateProjectionMatrix(); - -}; - -THREE.OrthographicCamera.prototype = new THREE.Camera(); -THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera; - -THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () { - - this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far ); - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author greggman / http://games.greggman.com/ - * @author zz85 / http://www.lab4games.net/zz85/blog - */ - -THREE.PerspectiveCamera = function ( fov, aspect, near, far ) { - - THREE.Camera.call( this ); - - this.fov = fov !== undefined ? fov : 50; - this.aspect = aspect !== undefined ? aspect : 1; - this.near = near !== undefined ? near : 0.1; - this.far = far !== undefined ? far : 2000; - - this.updateProjectionMatrix(); - -}; - -THREE.PerspectiveCamera.prototype = new THREE.Camera(); -THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera; - - -/** - * Uses Focal Length (in mm) to estimate and set FOV - * 35mm (fullframe) camera is used if frame size is not specified; - * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html - */ - -THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) { - - frameHeight = frameHeight !== undefined ? frameHeight : 24; - - this.fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI ); - this.updateProjectionMatrix(); - -} - - -/** - * Sets an offset in a larger frustum. This is useful for multi-window or - * multi-monitor/multi-machine setups. - * - * For example, if you have 3x2 monitors and each monitor is 1920x1080 and - * the monitors are in grid like this - * - * +---+---+---+ - * | A | B | C | - * +---+---+---+ - * | D | E | F | - * +---+---+---+ - * - * then for each monitor you would call it like this - * - * var w = 1920; - * var h = 1080; - * var fullWidth = w * 3; - * var fullHeight = h * 2; - * - * --A-- - * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); - * --B-- - * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); - * --C-- - * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); - * --D-- - * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); - * --E-- - * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); - * --F-- - * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); - * - * Note there is no reason monitors have to be the same size or in a grid. - */ - -THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) { - - this.fullWidth = fullWidth; - this.fullHeight = fullHeight; - this.x = x; - this.y = y; - this.width = width; - this.height = height; - - this.updateProjectionMatrix(); - -}; - - -THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () { - - if ( this.fullWidth ) { - - var aspect = this.fullWidth / this.fullHeight; - var top = Math.tan( this.fov * Math.PI / 360 ) * this.near; - var bottom = -top; - var left = aspect * bottom; - var right = aspect * top; - var width = Math.abs( right - left ); - var height = Math.abs( top - bottom ); - - this.projectionMatrix.makeFrustum( - left + this.x * width / this.fullWidth, - left + ( this.x + this.width ) * width / this.fullWidth, - top - ( this.y + this.height ) * height / this.fullHeight, - top - this.y * height / this.fullHeight, - this.near, - this.far - ); - - } else { - - this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far ); - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Light = function ( hex ) { - - THREE.Object3D.call( this ); - - this.color = new THREE.Color( hex ); - -}; - -THREE.Light.prototype = new THREE.Object3D(); -THREE.Light.prototype.constructor = THREE.Light; -THREE.Light.prototype.supr = THREE.Object3D.prototype; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.AmbientLight = function ( hex ) { - - THREE.Light.call( this, hex ); - -}; - -THREE.AmbientLight.prototype = new THREE.Light(); -THREE.AmbientLight.prototype.constructor = THREE.AmbientLight; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.DirectionalLight = function ( hex, intensity, distance ) { - - THREE.Light.call( this, hex ); - - this.position = new THREE.Vector3( 0, 1, 0 ); - this.target = new THREE.Object3D(); - - this.intensity = ( intensity !== undefined ) ? intensity : 1; - this.distance = ( distance !== undefined ) ? distance : 0; - - this.castShadow = false; - this.onlyShadow = false; - - // - - this.shadowCameraNear = 50; - this.shadowCameraFar = 5000; - - this.shadowCameraLeft = -500; - this.shadowCameraRight = 500; - this.shadowCameraTop = 500; - this.shadowCameraBottom = -500; - - this.shadowCameraVisible = false; - - this.shadowBias = 0; - this.shadowDarkness = 0.5; - - this.shadowMapWidth = 512; - this.shadowMapHeight = 512; - - // - - this.shadowCascade = false; - - this.shadowCascadeOffset = new THREE.Vector3( 0, 0, -1000 ); - this.shadowCascadeCount = 2; - - this.shadowCascadeBias = [ 0, 0, 0 ]; - this.shadowCascadeWidth = [ 512, 512, 512 ]; - this.shadowCascadeHeight = [ 512, 512, 512 ]; - - this.shadowCascadeNearZ = [ -1.000, 0.990, 0.998 ]; - this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ]; - - this.shadowCascadeArray = []; - - // - - this.shadowMap = null; - this.shadowMapSize = null; - this.shadowCamera = null; - this.shadowMatrix = null; - -}; - -THREE.DirectionalLight.prototype = new THREE.Light(); -THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.PointLight = function ( hex, intensity, distance ) { - - THREE.Light.call( this, hex ); - - this.position = new THREE.Vector3( 0, 0, 0 ); - this.intensity = ( intensity !== undefined ) ? intensity : 1; - this.distance = ( distance !== undefined ) ? distance : 0; - -}; - -THREE.PointLight.prototype = new THREE.Light(); -THREE.PointLight.prototype.constructor = THREE.PointLight; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Material = function ( parameters ) { - - parameters = parameters || {}; - - this.id = THREE.MaterialCount ++; - - this.name = ''; - - this.opacity = parameters.opacity !== undefined ? parameters.opacity : 1; - this.transparent = parameters.transparent !== undefined ? parameters.transparent : false; - - this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending; - - this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor; - this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor; - this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation; - - this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : true; - this.depthWrite = parameters.depthWrite !== undefined ? parameters.depthWrite : true; - - this.polygonOffset = parameters.polygonOffset !== undefined ? parameters.polygonOffset : false; - this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0; - this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0; - - this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0; - - this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer - - this.needsUpdate = true; - -} - -THREE.MaterialCount = 0; - -// shading - -THREE.NoShading = 0; -THREE.FlatShading = 1; -THREE.SmoothShading = 2; - -// colors - -THREE.NoColors = 0; -THREE.FaceColors = 1; -THREE.VertexColors = 2; - -// blending modes - -THREE.NoBlending = 0; -THREE.NormalBlending = 1; -THREE.AdditiveBlending = 2; -THREE.SubtractiveBlending = 3; -THREE.MultiplyBlending = 4; -THREE.AdditiveAlphaBlending = 5; -THREE.CustomBlending = 6; - -// custom blending equations -// (numbers start from 100 not to clash with other -// mappings to OpenGL constants defined in Texture.js) - -THREE.AddEquation = 100; -THREE.SubtractEquation = 101; -THREE.ReverseSubtractEquation = 102; - -// custom blending destination factors - -THREE.ZeroFactor = 200; -THREE.OneFactor = 201; -THREE.SrcColorFactor = 202; -THREE.OneMinusSrcColorFactor = 203; -THREE.SrcAlphaFactor = 204; -THREE.OneMinusSrcAlphaFactor = 205; -THREE.DstAlphaFactor = 206; -THREE.OneMinusDstAlphaFactor = 207; - -// custom blending source factors - -//THREE.ZeroFactor = 200; -//THREE.OneFactor = 201; -//THREE.SrcAlphaFactor = 204; -//THREE.OneMinusSrcAlphaFactor = 205; -//THREE.DstAlphaFactor = 206; -//THREE.OneMinusDstAlphaFactor = 207; -THREE.DstColorFactor = 208; -THREE.OneMinusDstColorFactor = 209; -THREE.SrcAlphaSaturateFactor = 210; - -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * - * parameters = { - * color: , - * opacity: , - * - * blending: THREE.NormalBlending, - * depthTest: , - * - * linewidth: , - * linecap: "round", - * linejoin: "round", - * - * vertexColors: - * - * fog: - * } - */ - -THREE.LineBasicMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - - this.linewidth = parameters.linewidth !== undefined ? parameters.linewidth : 1; - this.linecap = parameters.linecap !== undefined ? parameters.linecap : 'round'; - this.linejoin = parameters.linejoin !== undefined ? parameters.linejoin : 'round'; - - this.vertexColors = parameters.vertexColors ? parameters.vertexColors : false; - - this.fog = parameters.fog !== undefined ? parameters.fog : true; - -}; - -THREE.LineBasicMaterial.prototype = new THREE.Material(); -THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * - * parameters = { - * color: , - * opacity: , - * map: new THREE.Texture( ), - * - * lightMap: new THREE.Texture( ), - * - * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ), - * combine: THREE.Multiply, - * reflectivity: , - * refractionRatio: , - * - * shading: THREE.SmoothShading, - * blending: THREE.NormalBlending, - * depthTest: , - * - * wireframe: , - * wireframeLinewidth: , - * - * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors, - * - * skinning: , - * morphTargets: , - * - * fog: - * } - */ - -THREE.MeshBasicMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - // color property represents emissive for MeshBasicMaterial - - this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - - this.map = parameters.map !== undefined ? parameters.map : null; - - this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null; - - this.envMap = parameters.envMap !== undefined ? parameters.envMap : null; - this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation; - this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1; - this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98; - - this.fog = parameters.fog !== undefined ? parameters.fog : true; - - this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; - - this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false; - this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1; - this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round'; - this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round'; - - this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors; - - this.skinning = parameters.skinning !== undefined ? parameters.skinning : false; - this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false; - -}; - -THREE.MeshBasicMaterial.prototype = new THREE.Material(); -THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * - * parameters = { - * color: , - * ambient: , - * emissive: , - * opacity: , - * - * map: new THREE.Texture( ), - * - * lightMap: new THREE.Texture( ), - * - * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ), - * combine: THREE.Multiply, - * reflectivity: , - * refractionRatio: , - * - * shading: THREE.SmoothShading, - * blending: THREE.NormalBlending, - * depthTest: , - * - * wireframe: , - * wireframeLinewidth: , - * - * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors, - * - * skinning: , - * morphTargets: , - * morphNormals: , - * - * fog: - * } - */ - -THREE.MeshLambertMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - // color property represents diffuse for MeshLambertMaterial - - this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff ); - this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 ); - - this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false; - this.wrapRGB = new THREE.Vector3( 1, 1, 1 ); - - this.map = parameters.map !== undefined ? parameters.map : null; - - this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null; - - this.envMap = parameters.envMap !== undefined ? parameters.envMap : null; - this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation; - this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1; - this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98; - - this.fog = parameters.fog !== undefined ? parameters.fog : true; - - this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; - - this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false; - this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1; - this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round'; - this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round'; - - this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors; - - this.skinning = parameters.skinning !== undefined ? parameters.skinning : false; - this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false; - this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false; - -}; - -THREE.MeshLambertMaterial.prototype = new THREE.Material(); -THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * - * parameters = { - * color: , - * ambient: , - * emissive: , - * specular: , - * shininess: , - * opacity: , - * - * map: new THREE.Texture( ), - * - * lightMap: new THREE.Texture( ), - * - * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ), - * combine: THREE.Multiply, - * reflectivity: , - * refractionRatio: , - * - * shading: THREE.SmoothShading, - * blending: THREE.NormalBlending, - * depthTest: , - * - * wireframe: , - * wireframeLinewidth: , - * - * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors, - * - * skinning: , - * morphTargets: , - * morphNormals: , - * - * fog: - * } - */ - -THREE.MeshPhongMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - // color property represents diffuse for MeshPhongMaterial - - this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff ); - this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 ); - this.specular = parameters.specular !== undefined ? new THREE.Color( parameters.specular ) : new THREE.Color( 0x111111 ); - this.shininess = parameters.shininess !== undefined ? parameters.shininess : 30; - - this.metal = parameters.metal !== undefined ? parameters.metal : false; - this.perPixel = parameters.perPixel !== undefined ? parameters.perPixel : false; - - this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false; - this.wrapRGB = new THREE.Vector3( 1, 1, 1 ); - - this.map = parameters.map !== undefined ? parameters.map : null; - - this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null; - - this.envMap = parameters.envMap !== undefined ? parameters.envMap : null; - this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation; - this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1; - this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98; - - this.fog = parameters.fog !== undefined ? parameters.fog : true; - - this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; - - this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false; - this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1; - this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round'; - this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round'; - - this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors; - - this.skinning = parameters.skinning !== undefined ? parameters.skinning : false; - this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false; - this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false; - -}; - -THREE.MeshPhongMaterial.prototype = new THREE.Material(); -THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * - * parameters = { - * opacity: , - - * blending: THREE.NormalBlending, - * depthTest: , - - * wireframe: , - * wireframeLinewidth: - * } - */ - -THREE.MeshDepthMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; // doesn't really apply here, normals are not used - - this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false; - this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1; - -}; - -THREE.MeshDepthMaterial.prototype = new THREE.Material(); -THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * - * parameters = { - * opacity: , - - * shading: THREE.FlatShading, - * blending: THREE.NormalBlending, - * depthTest: , - - * wireframe: , - * wireframeLinewidth: - * } - */ - -THREE.MeshNormalMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - this.shading = parameters.shading ? parameters.shading : THREE.FlatShading; - - this.wireframe = parameters.wireframe ? parameters.wireframe : false; - this.wireframeLinewidth = parameters.wireframeLinewidth ? parameters.wireframeLinewidth : 1; - -}; - -THREE.MeshNormalMaterial.prototype = new THREE.Material(); -THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.MeshFaceMaterial = function () { - -}; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * - * parameters = { - * color: , - * opacity: , - * map: new THREE.Texture( ), - * - * size: , - * - * blending: THREE.NormalBlending, - * depthTest: , - * - * vertexColors: , - * - * fog: - * } - */ - -THREE.ParticleBasicMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - - this.map = parameters.map !== undefined ? parameters.map : null; - - this.size = parameters.size !== undefined ? parameters.size : 1; - this.sizeAttenuation = parameters.sizeAttenuation !== undefined ? parameters.sizeAttenuation : true; - - this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false; - - this.fog = parameters.fog !== undefined ? parameters.fog : true; - -}; - -THREE.ParticleBasicMaterial.prototype = new THREE.Material(); -THREE.ParticleBasicMaterial.prototype.constructor = THREE.ParticleBasicMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * - * parameters = { - * color: , - * program: , - * opacity: , - * blending: THREE.NormalBlending - * } - */ - -THREE.ParticleCanvasMaterial = function ( parameters ) { - - THREE.Material.call( this, parameters ); - - parameters = parameters || {}; - - this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - this.program = parameters.program !== undefined ? parameters.program : function ( context, color ) {}; - -}; - -THREE.ParticleCanvasMaterial.prototype = new THREE.Material(); -THREE.ParticleCanvasMaterial.prototype.constructor = THREE.ParticleCanvasMaterial; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * @author szimek / https://github.com/szimek/ - */ - -THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type ) { - - this.id = THREE.TextureCount ++; - - this.image = image; - - this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping(); - - this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping; - this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping; - - this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter; - this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter; - - this.format = format !== undefined ? format : THREE.RGBAFormat; - this.type = type !== undefined ? type : THREE.UnsignedByteType; - - this.offset = new THREE.Vector2( 0, 0 ); - this.repeat = new THREE.Vector2( 1, 1 ); - - this.generateMipmaps = true; - this.premultiplyAlpha = false; - - this.needsUpdate = false; - this.onUpdate = null; - -}; - -THREE.Texture.prototype = { - - constructor: THREE.Texture, - - clone: function () { - - var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter, this.format, this.type ); - - clonedTexture.offset.copy( this.offset ); - clonedTexture.repeat.copy( this.repeat ); - - return clonedTexture; - - } - -}; - -THREE.TextureCount = 0; - -THREE.MultiplyOperation = 0; -THREE.MixOperation = 1; - -// Mapping modes - -THREE.UVMapping = function () {}; - -THREE.CubeReflectionMapping = function () {}; -THREE.CubeRefractionMapping = function () {}; - -THREE.SphericalReflectionMapping = function () {}; -THREE.SphericalRefractionMapping = function () {}; - -// Wrapping modes - -THREE.RepeatWrapping = 0; -THREE.ClampToEdgeWrapping = 1; -THREE.MirroredRepeatWrapping = 2; - -// Filters - -THREE.NearestFilter = 3; -THREE.NearestMipMapNearestFilter = 4; -THREE.NearestMipMapLinearFilter = 5; -THREE.LinearFilter = 6; -THREE.LinearMipMapNearestFilter = 7; -THREE.LinearMipMapLinearFilter = 8; - -// Types - -THREE.ByteType = 9; -THREE.UnsignedByteType = 10; -THREE.ShortType = 11; -THREE.UnsignedShortType = 12; -THREE.IntType = 13; -THREE.UnsignedIntType = 14; -THREE.FloatType = 15; - -// Formats - -THREE.AlphaFormat = 16; -THREE.RGBFormat = 17; -THREE.RGBAFormat = 18; -THREE.LuminanceFormat = 19; -THREE.LuminanceAlphaFormat = 20; -/** - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter ) { - - THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type ); - - this.image = { data: data, width: width, height: height }; - -}; - -THREE.DataTexture.prototype = new THREE.Texture(); -THREE.DataTexture.prototype.constructor = THREE.DataTexture; - -THREE.DataTexture.prototype.clone = function () { - - var clonedTexture = new THREE.DataTexture( this.image.data, this.image.width, this.image.height, this.format, this.type, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter ); - - clonedTexture.offset.copy( this.offset ); - clonedTexture.repeat.copy( this.repeat ); - - return clonedTexture; - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.Particle = function ( material ) { - - THREE.Object3D.call( this ); - - this.material = material; - -}; - -THREE.Particle.prototype = new THREE.Object3D(); -THREE.Particle.prototype.constructor = THREE.Particle; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.Line = function ( geometry, material, type ) { - - THREE.Object3D.call( this ); - - this.geometry = geometry; - this.material = ( material !== undefined ) ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } ); - this.type = ( type !== undefined ) ? type : THREE.LineStrip; - - if ( this.geometry ) { - - if ( ! this.geometry.boundingSphere ) { - - this.geometry.computeBoundingSphere(); - - } - - } - -}; - -THREE.LineStrip = 0; -THREE.LinePieces = 1; - -THREE.Line.prototype = new THREE.Object3D(); -THREE.Line.prototype.constructor = THREE.Line; -/** - * @author mr.doob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ - * @author mikael emtinger / http://gomo.se/ - */ - -THREE.Mesh = function ( geometry, material ) { - - THREE.Object3D.call( this ); - - this.geometry = geometry; - this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } ); - - if ( this.geometry ) { - - // calc bound radius - - if( ! this.geometry.boundingSphere ) { - - this.geometry.computeBoundingSphere(); - - } - - this.boundRadius = geometry.boundingSphere.radius; - - - // setup morph targets - - if( this.geometry.morphTargets.length ) { - - this.morphTargetBase = -1; - this.morphTargetForcedOrder = []; - this.morphTargetInfluences = []; - this.morphTargetDictionary = {}; - - for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) { - - this.morphTargetInfluences.push( 0 ); - this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m; - - } - - } - - } - -} - -THREE.Mesh.prototype = new THREE.Object3D(); -THREE.Mesh.prototype.constructor = THREE.Mesh; -THREE.Mesh.prototype.supr = THREE.Object3D.prototype; - - -/* - * Get Morph Target Index by Name - */ - -THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) { - - if ( this.morphTargetDictionary[ name ] !== undefined ) { - - return this.morphTargetDictionary[ name ]; - } - - console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." ); - return 0; - -} -/** - * @author mikael emtinger / http://gomo.se/ - * @author alteredq / http://alteredqualia.com/ - */ - -THREE.Bone = function( belongsToSkin ) { - - THREE.Object3D.call( this ); - - this.skin = belongsToSkin; - this.skinMatrix = new THREE.Matrix4(); - -}; - -THREE.Bone.prototype = new THREE.Object3D(); -THREE.Bone.prototype.constructor = THREE.Bone; -THREE.Bone.prototype.supr = THREE.Object3D.prototype; - - -THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) { - - // update local - - if ( this.matrixAutoUpdate ) { - - forceUpdate |= this.updateMatrix(); - - } - - // update skin matrix - - if ( forceUpdate || this.matrixWorldNeedsUpdate ) { - - if( parentSkinMatrix ) { - - this.skinMatrix.multiply( parentSkinMatrix, this.matrix ); - - } else { - - this.skinMatrix.copy( this.matrix ); - - } - - this.matrixWorldNeedsUpdate = false; - forceUpdate = true; - - } - - // update children - - var child, i, l = this.children.length; - - for ( i = 0; i < l; i ++ ) { - - this.children[ i ].update( this.skinMatrix, forceUpdate ); - - } - -}; - -/** - * @author mikael emtinger / http://gomo.se/ - */ - -THREE.Sprite = function ( parameters ) { - - THREE.Object3D.call( this ); - - this.color = ( parameters.color !== undefined ) ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff ); - this.map = ( parameters.map !== undefined ) ? parameters.map : new THREE.Texture(); - - this.blending = ( parameters.blending !== undefined ) ? parameters.blending : THREE.NormalBlending; - - this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor; - this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor; - this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation; - - this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true; - this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates; - this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates; - this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance; - this.alignment = ( parameters.alignment instanceof THREE.Vector2 ) ? parameters.alignment : THREE.SpriteAlignment.center; - - this.rotation3d = this.rotation; - this.rotation = 0; - this.opacity = 1; - - this.uvOffset = new THREE.Vector2( 0, 0 ); - this.uvScale = new THREE.Vector2( 1, 1 ); - -}; - -THREE.Sprite.prototype = new THREE.Object3D(); -THREE.Sprite.prototype.constructor = THREE.Sprite; - - -/* - * Custom update matrix - */ - -THREE.Sprite.prototype.updateMatrix = function () { - - this.matrix.setPosition( this.position ); - - this.rotation3d.set( 0, 0, this.rotation ); - this.matrix.setRotationFromEuler( this.rotation3d ); - - if ( this.scale.x !== 1 || this.scale.y !== 1 ) { - - this.matrix.scale( this.scale ); - this.boundRadiusScale = Math.max( this.scale.x, this.scale.y ); - - } - - this.matrixWorldNeedsUpdate = true; - -}; - -/* - * Alignment - */ - -THREE.SpriteAlignment = {}; -THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 ); -THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 ); -THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 ); -THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 ); -THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 ); -THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 ); -THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 ); -THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 ); -THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 ); -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.Scene = function () { - - THREE.Object3D.call( this ); - - this.fog = null; - this.overrideMaterial = null; - - this.matrixAutoUpdate = false; - - this.__objects = []; - this.__lights = []; - - this.__objectsAdded = []; - this.__objectsRemoved = []; - -}; - -THREE.Scene.prototype = new THREE.Object3D(); -THREE.Scene.prototype.constructor = THREE.Scene; - -THREE.Scene.prototype.__addObject = function ( object ) { - - if ( object instanceof THREE.Light ) { - - if ( this.__lights.indexOf( object ) === - 1 ) { - - this.__lights.push( object ); - - } - - } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) { - - if ( this.__objects.indexOf( object ) === - 1 ) { - - this.__objects.push( object ); - this.__objectsAdded.push( object ); - - // check if previously removed - - var i = this.__objectsRemoved.indexOf( object ); - - if ( i !== -1 ) { - - this.__objectsRemoved.splice( i, 1 ); - - } - - } - - } - - for ( var c = 0; c < object.children.length; c ++ ) { - - this.__addObject( object.children[ c ] ); - - } - -}; - -THREE.Scene.prototype.__removeObject = function ( object ) { - - if ( object instanceof THREE.Light ) { - - var i = this.__lights.indexOf( object ); - - if ( i !== -1 ) { - - this.__lights.splice( i, 1 ); - - } - - } else if ( !( object instanceof THREE.Camera ) ) { - - var i = this.__objects.indexOf( object ); - - if( i !== -1 ) { - - this.__objects.splice( i, 1 ); - this.__objectsRemoved.push( object ); - - // check if previously added - - var ai = this.__objectsAdded.indexOf( object ); - - if ( ai !== -1 ) { - - this.__objectsAdded.splice( ai, 1 ); - - } - - } - - } - - for ( var c = 0; c < object.children.length; c ++ ) { - - this.__removeObject( object.children[ c ] ); - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.CanvasRenderer = function ( parameters ) { - - console.log( 'THREE.CanvasRenderer', THREE.REVISION ); - - parameters = parameters || {}; - - var _this = this, - _renderData, _elements, _lights, - _projector = new THREE.Projector(), - - _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ), - - _canvasWidth, _canvasHeight, _canvasWidthHalf, _canvasHeightHalf, - _context = _canvas.getContext( '2d' ), - - _clearColor = new THREE.Color( 0x000000 ), - _clearOpacity = 0, - - _contextGlobalAlpha = 1, - _contextGlobalCompositeOperation = 0, - _contextStrokeStyle = null, - _contextFillStyle = null, - _contextLineWidth = null, - _contextLineCap = null, - _contextLineJoin = null, - - _v1, _v2, _v3, _v4, - _v5 = new THREE.RenderableVertex(), - _v6 = new THREE.RenderableVertex(), - - _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, - _v4x, _v4y, _v5x, _v5y, _v6x, _v6y, - - _color = new THREE.Color(), - _color1 = new THREE.Color(), - _color2 = new THREE.Color(), - _color3 = new THREE.Color(), - _color4 = new THREE.Color(), - - _patterns = [], _imagedatas = [], - - _near, _far, - - _image, _uvs, - _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, - - _clipRect = new THREE.Rectangle(), - _clearRect = new THREE.Rectangle(), - _bboxRect = new THREE.Rectangle(), - - _enableLighting = false, - _ambientLight = new THREE.Color(), - _directionalLights = new THREE.Color(), - _pointLights = new THREE.Color(), - - _pi2 = Math.PI * 2, - _vector3 = new THREE.Vector3(), // Needed for PointLight - - _pixelMap, _pixelMapContext, _pixelMapImage, _pixelMapData, - _gradientMap, _gradientMapContext, _gradientMapQuality = 16; - - _pixelMap = document.createElement( 'canvas' ); - _pixelMap.width = _pixelMap.height = 2; - - _pixelMapContext = _pixelMap.getContext( '2d' ); - _pixelMapContext.fillStyle = 'rgba(0,0,0,1)'; - _pixelMapContext.fillRect( 0, 0, 2, 2 ); - - _pixelMapImage = _pixelMapContext.getImageData( 0, 0, 2, 2 ); - _pixelMapData = _pixelMapImage.data; - - _gradientMap = document.createElement( 'canvas' ); - _gradientMap.width = _gradientMap.height = _gradientMapQuality; - - _gradientMapContext = _gradientMap.getContext( '2d' ); - _gradientMapContext.translate( - _gradientMapQuality / 2, - _gradientMapQuality / 2 ); - _gradientMapContext.scale( _gradientMapQuality, _gradientMapQuality ); - - _gradientMapQuality --; // Fix UVs - - this.domElement = _canvas; - - this.autoClear = true; - this.sortObjects = true; - this.sortElements = true; - - this.info = { - - render: { - - vertices: 0, - faces: 0 - - } - - } - - this.setSize = function ( width, height ) { - - _canvasWidth = width; - _canvasHeight = height; - _canvasWidthHalf = Math.floor( _canvasWidth / 2 ); - _canvasHeightHalf = Math.floor( _canvasHeight / 2 ); - - _canvas.width = _canvasWidth; - _canvas.height = _canvasHeight; - - _clipRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf ); - _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf ); - - _contextGlobalAlpha = 1; - _contextGlobalCompositeOperation = 0; - _contextStrokeStyle = null; - _contextFillStyle = null; - _contextLineWidth = null; - _contextLineCap = null; - _contextLineJoin = null; - - }; - - this.setClearColor = function ( color, opacity ) { - - _clearColor.copy( color ); - _clearOpacity = opacity !== undefined ? opacity : 1; - - _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf ); - - }; - - this.setClearColorHex = function ( hex, opacity ) { - - _clearColor.setHex( hex ); - _clearOpacity = opacity !== undefined ? opacity : 1; - - _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf ); - - }; - - this.clear = function () { - - _context.setTransform( 1, 0, 0, - 1, _canvasWidthHalf, _canvasHeightHalf ); - - if ( !_clearRect.isEmpty() ) { - - _clearRect.minSelf( _clipRect ); - _clearRect.inflate( 2 ); - - if ( _clearOpacity < 1 ) { - - _context.clearRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) ); - - } - - if ( _clearOpacity > 0 ) { - - setBlending( THREE.NormalBlending ); - setOpacity( 1 ); - - setFillStyle( 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')' ); - - _context.fillRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) ); - - } - - _clearRect.empty(); - - } - - - }; - - this.render = function ( scene, camera ) { - - var e, el, element, material; - - this.autoClear ? this.clear() : _context.setTransform( 1, 0, 0, - 1, _canvasWidthHalf, _canvasHeightHalf ); - - _this.info.render.vertices = 0; - _this.info.render.faces = 0; - - _renderData = _projector.projectScene( scene, camera, this.sortElements ); - _elements = _renderData.elements; - _lights = _renderData.lights; - - /* DEBUG - _context.fillStyle = 'rgba( 0, 255, 255, 0.5 )'; - _context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() ); - */ - - _enableLighting = _lights.length > 0; - - if ( _enableLighting ) { - - calculateLights( _lights ); - - } - - for ( e = 0, el = _elements.length; e < el; e++ ) { - - element = _elements[ e ]; - - material = element.material; - material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material; - - if ( material == null || material.opacity == 0 ) continue; - - _bboxRect.empty(); - - if ( element instanceof THREE.RenderableParticle ) { - - _v1 = element; - _v1.x *= _canvasWidthHalf; _v1.y *= _canvasHeightHalf; - - renderParticle( _v1, element, material, scene ); - - } else if ( element instanceof THREE.RenderableLine ) { - - _v1 = element.v1; _v2 = element.v2; - - _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf; - _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf; - - _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y ); - _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y ); - - if ( _clipRect.intersects( _bboxRect ) ) { - - renderLine( _v1, _v2, element, material, scene ); - - } - - - } else if ( element instanceof THREE.RenderableFace3 ) { - - _v1 = element.v1; _v2 = element.v2; _v3 = element.v3; - - _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf; - _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf; - _v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf; - - if ( material.overdraw ) { - - expand( _v1.positionScreen, _v2.positionScreen ); - expand( _v2.positionScreen, _v3.positionScreen ); - expand( _v3.positionScreen, _v1.positionScreen ); - - } - - _bboxRect.add3Points( _v1.positionScreen.x, _v1.positionScreen.y, - _v2.positionScreen.x, _v2.positionScreen.y, - _v3.positionScreen.x, _v3.positionScreen.y ); - - if ( _clipRect.intersects( _bboxRect ) ) { - - renderFace3( _v1, _v2, _v3, 0, 1, 2, element, material, scene ); - - } - - } else if ( element instanceof THREE.RenderableFace4 ) { - - _v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4; - - _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf; - _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf; - _v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf; - _v4.positionScreen.x *= _canvasWidthHalf; _v4.positionScreen.y *= _canvasHeightHalf; - - _v5.positionScreen.copy( _v2.positionScreen ); - _v6.positionScreen.copy( _v4.positionScreen ); - - if ( material.overdraw ) { - - expand( _v1.positionScreen, _v2.positionScreen ); - expand( _v2.positionScreen, _v4.positionScreen ); - expand( _v4.positionScreen, _v1.positionScreen ); - - expand( _v3.positionScreen, _v5.positionScreen ); - expand( _v3.positionScreen, _v6.positionScreen ); - - } - - _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y ); - _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y ); - _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y ); - _bboxRect.addPoint( _v4.positionScreen.x, _v4.positionScreen.y ); - - if ( _clipRect.intersects( _bboxRect ) ) { - - renderFace4( _v1, _v2, _v3, _v4, _v5, _v6, element, material, scene ); - - } - - } - - /* - _context.lineWidth = 1; - _context.strokeStyle = 'rgba( 0, 255, 0, 0.5 )'; - _context.strokeRect( _bboxRect.getX(), _bboxRect.getY(), _bboxRect.getWidth(), _bboxRect.getHeight() ); - */ - - _clearRect.addRectangle( _bboxRect ); - - - } - - /* DEBUG - _context.lineWidth = 1; - _context.strokeStyle = 'rgba( 255, 0, 0, 0.5 )'; - _context.strokeRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() ); - */ - - _context.setTransform( 1, 0, 0, 1, 0, 0 ); - - // - - function calculateLights( lights ) { - - var l, ll, light, lightColor; - - _ambientLight.setRGB( 0, 0, 0 ); - _directionalLights.setRGB( 0, 0, 0 ); - _pointLights.setRGB( 0, 0, 0 ); - - for ( l = 0, ll = lights.length; l < ll; l ++ ) { - - light = lights[ l ]; - lightColor = light.color; - - if ( light instanceof THREE.AmbientLight ) { - - _ambientLight.r += lightColor.r; - _ambientLight.g += lightColor.g; - _ambientLight.b += lightColor.b; - - } else if ( light instanceof THREE.DirectionalLight ) { - - // for particles - - _directionalLights.r += lightColor.r; - _directionalLights.g += lightColor.g; - _directionalLights.b += lightColor.b; - - } else if ( light instanceof THREE.PointLight ) { - - // for particles - - _pointLights.r += lightColor.r; - _pointLights.g += lightColor.g; - _pointLights.b += lightColor.b; - - } - - } - - } - - function calculateLight( lights, position, normal, color ) { - - var l, ll, light, lightColor, lightPosition, amount; - - for ( l = 0, ll = lights.length; l < ll; l ++ ) { - - light = lights[ l ]; - lightColor = light.color; - - if ( light instanceof THREE.DirectionalLight ) { - - lightPosition = light.matrixWorld.getPosition(); - - amount = normal.dot( lightPosition ); - - if ( amount <= 0 ) continue; - - amount *= light.intensity; - - color.r += lightColor.r * amount; - color.g += lightColor.g * amount; - color.b += lightColor.b * amount; - - } else if ( light instanceof THREE.PointLight ) { - - lightPosition = light.matrixWorld.getPosition(); - - amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() ); - - if ( amount <= 0 ) continue; - - amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 ); - - if ( amount == 0 ) continue; - - amount *= light.intensity; - - color.r += lightColor.r * amount; - color.g += lightColor.g * amount; - color.b += lightColor.b * amount; - - } - - } - - } - - function renderParticle ( v1, element, material, scene ) { - - setOpacity( material.opacity ); - setBlending( material.blending ); - - var width, height, scaleX, scaleY, - bitmap, bitmapWidth, bitmapHeight; - - if ( material instanceof THREE.ParticleBasicMaterial ) { - - if ( material.map ) { - - bitmap = material.map.image; - bitmapWidth = bitmap.width >> 1; - bitmapHeight = bitmap.height >> 1; - - scaleX = element.scale.x * _canvasWidthHalf; - scaleY = element.scale.y * _canvasHeightHalf; - - width = scaleX * bitmapWidth; - height = scaleY * bitmapHeight; - - // TODO: Rotations break this... - - _bboxRect.set( v1.x - width, v1.y - height, v1.x + width, v1.y + height ); - - if ( !_clipRect.intersects( _bboxRect ) ) { - - return; - - } - - _context.save(); - _context.translate( v1.x, v1.y ); - _context.rotate( - element.rotation ); - _context.scale( scaleX, - scaleY ); - - _context.translate( - bitmapWidth, - bitmapHeight ); - _context.drawImage( bitmap, 0, 0 ); - - _context.restore(); - - } - - /* DEBUG - _context.beginPath(); - _context.moveTo( v1.x - 10, v1.y ); - _context.lineTo( v1.x + 10, v1.y ); - _context.moveTo( v1.x, v1.y - 10 ); - _context.lineTo( v1.x, v1.y + 10 ); - _context.closePath(); - _context.strokeStyle = 'rgb(255,255,0)'; - _context.stroke(); - */ - - } else if ( material instanceof THREE.ParticleCanvasMaterial ) { - - width = element.scale.x * _canvasWidthHalf; - height = element.scale.y * _canvasHeightHalf; - - _bboxRect.set( v1.x - width, v1.y - height, v1.x + width, v1.y + height ); - - if ( !_clipRect.intersects( _bboxRect ) ) { - - return; - - } - - setStrokeStyle( material.color.getContextStyle() ); - setFillStyle( material.color.getContextStyle() ); - - _context.save(); - _context.translate( v1.x, v1.y ); - _context.rotate( - element.rotation ); - _context.scale( width, height ); - - material.program( _context ); - - _context.restore(); - - } - - } - - function renderLine( v1, v2, element, material, scene ) { - - setOpacity( material.opacity ); - setBlending( material.blending ); - - _context.beginPath(); - _context.moveTo( v1.positionScreen.x, v1.positionScreen.y ); - _context.lineTo( v2.positionScreen.x, v2.positionScreen.y ); - _context.closePath(); - - if ( material instanceof THREE.LineBasicMaterial ) { - - setLineWidth( material.linewidth ); - setLineCap( material.linecap ); - setLineJoin( material.linejoin ); - setStrokeStyle( material.color.getContextStyle() ); - - _context.stroke(); - _bboxRect.inflate( material.linewidth * 2 ); - - } - - } - - function renderFace3( v1, v2, v3, uv1, uv2, uv3, element, material, scene ) { - - _this.info.render.vertices += 3; - _this.info.render.faces ++; - - setOpacity( material.opacity ); - setBlending( material.blending ); - - _v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y; - _v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y; - _v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y; - - drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y ); - - if ( material instanceof THREE.MeshBasicMaterial ) { - - if ( material.map/* && !material.wireframe*/ ) { - - if ( material.map.mapping instanceof THREE.UVMapping ) { - - _uvs = element.uvs[ 0 ]; - patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map ); - - } - - - } else if ( material.envMap ) { - - if ( material.envMap.mapping instanceof THREE.SphericalReflectionMapping ) { - - var cameraMatrix = camera.matrixWorldInverse; - - _vector3.copy( element.vertexNormalsWorld[ uv1 ] ); - _uv1x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5; - _uv1y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5; - - _vector3.copy( element.vertexNormalsWorld[ uv2 ] ); - _uv2x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5; - _uv2y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5; - - _vector3.copy( element.vertexNormalsWorld[ uv3 ] ); - _uv3x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5; - _uv3y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5; - - patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap ); - - }/* else if ( material.envMap.mapping == THREE.SphericalRefractionMapping ) { - - - - }*/ - - - } else { - - material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color ); - - } - - } else if ( material instanceof THREE.MeshLambertMaterial ) { - - if ( material.map && !material.wireframe ) { - - if ( material.map.mapping instanceof THREE.UVMapping ) { - - _uvs = element.uvs[ 0 ]; - patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map ); - - } - - setBlending( THREE.SubtractiveBlending ); - - } - - if ( _enableLighting ) { - - if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 3 ) { - - _color1.r = _color2.r = _color3.r = _ambientLight.r; - _color1.g = _color2.g = _color3.g = _ambientLight.g; - _color1.b = _color2.b = _color3.b = _ambientLight.b; - - calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 ); - calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 ); - calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color3 ); - - _color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) ); - _color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) ); - _color1.b = Math.max( 0, Math.min( material.color.b * _color1.b, 1 ) ); - - _color2.r = Math.max( 0, Math.min( material.color.r * _color2.r, 1 ) ); - _color2.g = Math.max( 0, Math.min( material.color.g * _color2.g, 1 ) ); - _color2.b = Math.max( 0, Math.min( material.color.b * _color2.b, 1 ) ); - - _color3.r = Math.max( 0, Math.min( material.color.r * _color3.r, 1 ) ); - _color3.g = Math.max( 0, Math.min( material.color.g * _color3.g, 1 ) ); - _color3.b = Math.max( 0, Math.min( material.color.b * _color3.b, 1 ) ); - - _color4.r = ( _color2.r + _color3.r ) * 0.5; - _color4.g = ( _color2.g + _color3.g ) * 0.5; - _color4.b = ( _color2.b + _color3.b ) * 0.5; - - _image = getGradientTexture( _color1, _color2, _color3, _color4 ); - - clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); - - } else { - - _color.r = _ambientLight.r; - _color.g = _ambientLight.g; - _color.b = _ambientLight.b; - - calculateLight( _lights, element.centroidWorld, element.normalWorld, _color ); - - _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) ); - _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) ); - _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) ); - - material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color ); - - } - - } else { - - material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color ); - - } - - } else if ( material instanceof THREE.MeshDepthMaterial ) { - - _near = camera.near; - _far = camera.far; - - _color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z, _near, _far ); - _color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z, _near, _far ); - _color3.r = _color3.g = _color3.b = 1 - smoothstep( v3.positionScreen.z, _near, _far ); - - _color4.r = ( _color2.r + _color3.r ) * 0.5; - _color4.g = ( _color2.g + _color3.g ) * 0.5; - _color4.b = ( _color2.b + _color3.b ) * 0.5; - - _image = getGradientTexture( _color1, _color2, _color3, _color4 ); - - clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image ); - - } else if ( material instanceof THREE.MeshNormalMaterial ) { - - _color.r = normalToComponent( element.normalWorld.x ); - _color.g = normalToComponent( element.normalWorld.y ); - _color.b = normalToComponent( element.normalWorld.z ); - - material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color ); - - } - - } - - function renderFace4( v1, v2, v3, v4, v5, v6, element, material, scene ) { - - _this.info.render.vertices += 4; - _this.info.render.faces ++; - - setOpacity( material.opacity ); - setBlending( material.blending ); - - if ( material.map || material.envMap ) { - - // Let renderFace3() handle this - - renderFace3( v1, v2, v4, 0, 1, 3, element, material, scene ); - renderFace3( v5, v3, v6, 1, 2, 3, element, material, scene ); - - return; - - } - - _v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y; - _v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y; - _v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y; - _v4x = v4.positionScreen.x; _v4y = v4.positionScreen.y; - _v5x = v5.positionScreen.x; _v5y = v5.positionScreen.y; - _v6x = v6.positionScreen.x; _v6y = v6.positionScreen.y; - - if ( material instanceof THREE.MeshBasicMaterial ) { - - drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); - - material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color ); - - } else if ( material instanceof THREE.MeshLambertMaterial ) { - - if ( _enableLighting ) { - - if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 4 ) { - - _color1.r = _color2.r = _color3.r = _color4.r = _ambientLight.r; - _color1.g = _color2.g = _color3.g = _color4.g = _ambientLight.g; - _color1.b = _color2.b = _color3.b = _color4.b = _ambientLight.b; - - calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 ); - calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 ); - calculateLight( _lights, element.v4.positionWorld, element.vertexNormalsWorld[ 3 ], _color3 ); - calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color4 ); - - _color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) ); - _color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) ); - _color1.b = Math.max( 0, Math.min( material.color.b * _color1.b, 1 ) ); - - _color2.r = Math.max( 0, Math.min( material.color.r * _color2.r, 1 ) ); - _color2.g = Math.max( 0, Math.min( material.color.g * _color2.g, 1 ) ); - _color2.b = Math.max( 0, Math.min( material.color.b * _color2.b, 1 ) ); - - _color3.r = Math.max( 0, Math.min( material.color.r * _color3.r, 1 ) ); - _color3.g = Math.max( 0, Math.min( material.color.g * _color3.g, 1 ) ); - _color3.b = Math.max( 0, Math.min( material.color.b * _color3.b, 1 ) ); - - _color4.r = Math.max( 0, Math.min( material.color.r * _color4.r, 1 ) ); - _color4.g = Math.max( 0, Math.min( material.color.g * _color4.g, 1 ) ); - _color4.b = Math.max( 0, Math.min( material.color.b * _color4.b, 1 ) ); - - _image = getGradientTexture( _color1, _color2, _color3, _color4 ); - - // TODO: UVs are incorrect, v4->v3? - - drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); - clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); - - drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y ); - clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image ); - - } else { - - _color.r = _ambientLight.r; - _color.g = _ambientLight.g; - _color.b = _ambientLight.b; - - calculateLight( _lights, element.centroidWorld, element.normalWorld, _color ); - - _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) ); - _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) ); - _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) ); - - drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); - - material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color ); - - } - - } else { - - drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); - - material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color ); - - } - - } else if ( material instanceof THREE.MeshNormalMaterial ) { - - _color.r = normalToComponent( element.normalWorld.x ); - _color.g = normalToComponent( element.normalWorld.y ); - _color.b = normalToComponent( element.normalWorld.z ); - - drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y ); - - material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color ); - - } else if ( material instanceof THREE.MeshDepthMaterial ) { - - _near = camera.near; - _far = camera.far; - - _color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z, _near, _far ); - _color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z, _near, _far ); - _color3.r = _color3.g = _color3.b = 1 - smoothstep( v4.positionScreen.z, _near, _far ); - _color4.r = _color4.g = _color4.b = 1 - smoothstep( v3.positionScreen.z, _near, _far ); - - _image = getGradientTexture( _color1, _color2, _color3, _color4 ); - - // TODO: UVs are incorrect, v4->v3? - - drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y ); - clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image ); - - drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y ); - clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image ); - - } - - } - - // - - function drawTriangle( x0, y0, x1, y1, x2, y2 ) { - - _context.beginPath(); - _context.moveTo( x0, y0 ); - _context.lineTo( x1, y1 ); - _context.lineTo( x2, y2 ); - _context.lineTo( x0, y0 ); - _context.closePath(); - - } - - function drawQuad( x0, y0, x1, y1, x2, y2, x3, y3 ) { - - _context.beginPath(); - _context.moveTo( x0, y0 ); - _context.lineTo( x1, y1 ); - _context.lineTo( x2, y2 ); - _context.lineTo( x3, y3 ); - _context.lineTo( x0, y0 ); - _context.closePath(); - - } - - function strokePath( color, linewidth, linecap, linejoin ) { - - setLineWidth( linewidth ); - setLineCap( linecap ); - setLineJoin( linejoin ); - setStrokeStyle( color.getContextStyle() ); - - _context.stroke(); - - _bboxRect.inflate( linewidth * 2 ); - - } - - function fillPath( color ) { - - setFillStyle( color.getContextStyle() ); - _context.fill(); - - } - - function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) { - - if ( texture.image.width == 0 ) return; - - if ( texture.needsUpdate == true || _patterns[ texture.id ] == undefined ) { - - var repeatX = texture.wrapS == THREE.RepeatWrapping; - var repeatY = texture.wrapT == THREE.RepeatWrapping; - - _patterns[ texture.id ] = _context.createPattern( texture.image, repeatX && repeatY ? 'repeat' : repeatX && !repeatY ? 'repeat-x' : !repeatX && repeatY ? 'repeat-y' : 'no-repeat' ); - - texture.needsUpdate = false; - - } - - setFillStyle( _patterns[ texture.id ] ); - - // http://extremelysatisfactorytotalitarianism.com/blog/?p=2120 - - var a, b, c, d, e, f, det, idet, - offsetX = texture.offset.x / texture.repeat.x, - offsetY = texture.offset.y / texture.repeat.y, - width = texture.image.width * texture.repeat.x, - height = texture.image.height * texture.repeat.y; - - u0 = ( u0 + offsetX ) * width; - v0 = ( v0 + offsetY ) * height; - - u1 = ( u1 + offsetX ) * width; - v1 = ( v1 + offsetY ) * height; - - u2 = ( u2 + offsetX ) * width; - v2 = ( v2 + offsetY ) * height; - - x1 -= x0; y1 -= y0; - x2 -= x0; y2 -= y0; - - u1 -= u0; v1 -= v0; - u2 -= u0; v2 -= v0; - - det = u1 * v2 - u2 * v1; - - if ( det == 0 ) { - - if ( _imagedatas[ texture.id ] === undefined ) { - - var canvas = document.createElement( 'canvas' ) - canvas.width = texture.image.width; - canvas.height = texture.image.height; - - var context = canvas.getContext( '2d' ); - context.drawImage( texture.image, 0, 0 ); - - _imagedatas[ texture.id ] = context.getImageData( 0, 0, texture.image.width, texture.image.height ).data; - - // variables cannot be deleted in ES5 strict mode - //delete canvas; - - } - - var data = _imagedatas[ texture.id ]; - var index = ( Math.floor( u0 ) + Math.floor( v0 ) * texture.image.width ) * 4; - - _color.setRGB( data[ index ] / 255, data[ index + 1 ] / 255, data[ index + 2 ] / 255 ); - fillPath( _color ); - - return; - - } - - idet = 1 / det; - - a = ( v2 * x1 - v1 * x2 ) * idet; - b = ( v2 * y1 - v1 * y2 ) * idet; - c = ( u1 * x2 - u2 * x1 ) * idet; - d = ( u1 * y2 - u2 * y1 ) * idet; - - e = x0 - a * u0 - c * v0; - f = y0 - b * u0 - d * v0; - - _context.save(); - _context.transform( a, b, c, d, e, f ); - _context.fill(); - _context.restore(); - - } - - function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) { - - // http://extremelysatisfactorytotalitarianism.com/blog/?p=2120 - - var a, b, c, d, e, f, det, idet, - width = image.width - 1, - height = image.height - 1; - - u0 *= width; v0 *= height; - u1 *= width; v1 *= height; - u2 *= width; v2 *= height; - - x1 -= x0; y1 -= y0; - x2 -= x0; y2 -= y0; - - u1 -= u0; v1 -= v0; - u2 -= u0; v2 -= v0; - - det = u1 * v2 - u2 * v1; - - idet = 1 / det; - - a = ( v2 * x1 - v1 * x2 ) * idet; - b = ( v2 * y1 - v1 * y2 ) * idet; - c = ( u1 * x2 - u2 * x1 ) * idet; - d = ( u1 * y2 - u2 * y1 ) * idet; - - e = x0 - a * u0 - c * v0; - f = y0 - b * u0 - d * v0; - - _context.save(); - _context.transform( a, b, c, d, e, f ); - _context.clip(); - _context.drawImage( image, 0, 0 ); - _context.restore(); - - } - - function getGradientTexture( color1, color2, color3, color4 ) { - - // http://mrdoob.com/blog/post/710 - - var c1r = ~~ ( color1.r * 255 ), c1g = ~~ ( color1.g * 255 ), c1b = ~~ ( color1.b * 255 ), - c2r = ~~ ( color2.r * 255 ), c2g = ~~ ( color2.g * 255 ), c2b = ~~ ( color2.b * 255 ), - c3r = ~~ ( color3.r * 255 ), c3g = ~~ ( color3.g * 255 ), c3b = ~~ ( color3.b * 255 ), - c4r = ~~ ( color4.r * 255 ), c4g = ~~ ( color4.g * 255 ), c4b = ~~ ( color4.b * 255 ); - - _pixelMapData[ 0 ] = c1r < 0 ? 0 : c1r > 255 ? 255 : c1r; - _pixelMapData[ 1 ] = c1g < 0 ? 0 : c1g > 255 ? 255 : c1g; - _pixelMapData[ 2 ] = c1b < 0 ? 0 : c1b > 255 ? 255 : c1b; - - _pixelMapData[ 4 ] = c2r < 0 ? 0 : c2r > 255 ? 255 : c2r; - _pixelMapData[ 5 ] = c2g < 0 ? 0 : c2g > 255 ? 255 : c2g; - _pixelMapData[ 6 ] = c2b < 0 ? 0 : c2b > 255 ? 255 : c2b; - - _pixelMapData[ 8 ] = c3r < 0 ? 0 : c3r > 255 ? 255 : c3r; - _pixelMapData[ 9 ] = c3g < 0 ? 0 : c3g > 255 ? 255 : c3g; - _pixelMapData[ 10 ] = c3b < 0 ? 0 : c3b > 255 ? 255 : c3b; - - _pixelMapData[ 12 ] = c4r < 0 ? 0 : c4r > 255 ? 255 : c4r; - _pixelMapData[ 13 ] = c4g < 0 ? 0 : c4g > 255 ? 255 : c4g; - _pixelMapData[ 14 ] = c4b < 0 ? 0 : c4b > 255 ? 255 : c4b; - - _pixelMapContext.putImageData( _pixelMapImage, 0, 0 ); - _gradientMapContext.drawImage( _pixelMap, 0, 0 ); - - return _gradientMap; - - } - - function smoothstep( value, min, max ) { - - var x = ( value - min ) / ( max - min ); - return x * x * ( 3 - 2 * x ); - - } - - function normalToComponent( normal ) { - - var component = ( normal + 1 ) * 0.5; - return component < 0 ? 0 : ( component > 1 ? 1 : component ); - - } - - // Hide anti-alias gaps - - function expand( v1, v2 ) { - - var x = v2.x - v1.x, y = v2.y - v1.y, - det = x * x + y * y, idet; - - if ( det == 0 ) return; - - idet = 1 / Math.sqrt( det ); - - x *= idet; y *= idet; - - v2.x += x; v2.y += y; - v1.x -= x; v1.y -= y; - - } - }; - - // Context cached methods. - - function setOpacity( value ) { - - if ( _contextGlobalAlpha != value ) { - - _context.globalAlpha = _contextGlobalAlpha = value; - - } - - } - - function setBlending( value ) { - - if ( _contextGlobalCompositeOperation != value ) { - - switch ( value ) { - - case THREE.NormalBlending: - - _context.globalCompositeOperation = 'source-over'; - - break; - - case THREE.AdditiveBlending: - - _context.globalCompositeOperation = 'lighter'; - - break; - - case THREE.SubtractiveBlending: - - _context.globalCompositeOperation = 'darker'; - - break; - - } - - _contextGlobalCompositeOperation = value; - - } - - } - - function setLineWidth( value ) { - - if ( _contextLineWidth != value ) { - - _context.lineWidth = _contextLineWidth = value; - - } - - } - - function setLineCap( value ) { - - // "butt", "round", "square" - - if ( _contextLineCap != value ) { - - _context.lineCap = _contextLineCap = value; - - } - - } - - function setLineJoin( value ) { - - // "round", "bevel", "miter" - - if ( _contextLineJoin != value ) { - - _context.lineJoin = _contextLineJoin = value; - - } - - } - - function setStrokeStyle( style ) { - - if ( _contextStrokeStyle != style ) { - - _context.strokeStyle = _contextStrokeStyle = style; - - } - - } - - function setFillStyle( style ) { - - if ( _contextFillStyle != style ) { - - _context.fillStyle = _contextFillStyle = style; - - } - - } - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.RenderableVertex = function () { - - this.positionWorld = new THREE.Vector3(); - this.positionScreen = new THREE.Vector4(); - - this.visible = true; - -}; - -THREE.RenderableVertex.prototype.copy = function ( vertex ) { - - this.positionWorld.copy( vertex.positionWorld ); - this.positionScreen.copy( vertex.positionScreen ); - -} -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.RenderableFace3 = function () { - - this.v1 = new THREE.RenderableVertex(); - this.v2 = new THREE.RenderableVertex(); - this.v3 = new THREE.RenderableVertex(); - - this.centroidWorld = new THREE.Vector3(); - this.centroidScreen = new THREE.Vector3(); - - this.normalWorld = new THREE.Vector3(); - this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ]; - - this.material = null; - this.faceMaterial = null; - this.uvs = [[]]; - - this.z = null; - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.RenderableFace4 = function () { - - this.v1 = new THREE.RenderableVertex(); - this.v2 = new THREE.RenderableVertex(); - this.v3 = new THREE.RenderableVertex(); - this.v4 = new THREE.RenderableVertex(); - - this.centroidWorld = new THREE.Vector3(); - this.centroidScreen = new THREE.Vector3(); - - this.normalWorld = new THREE.Vector3(); - this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ]; - - this.material = null; - this.faceMaterial = null; - this.uvs = [[]]; - - this.z = null; - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.RenderableObject = function () { - - this.object = null; - this.z = null; - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.RenderableParticle = function () { - - this.x = null; - this.y = null; - this.z = null; - - this.rotation = null; - this.scale = new THREE.Vector2(); - - this.material = null; - -}; -/** - * @author mr.doob / http://mrdoob.com/ - */ - -THREE.RenderableLine = function () { - - this.z = null; - - this.v1 = new THREE.RenderableVertex(); - this.v2 = new THREE.RenderableVertex(); - - this.material = null; - -}; -======= // ThreeCanvas.js - http://github.com/mrdoob/three.js 'use strict';var THREE=THREE||{REVISION:"49"};self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array); (function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.001){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")}; +THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(e<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;e=-e}else c.copy(b);if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")}; THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3}; THREE.Face3.prototype={constructor:THREE.Face3,clone:function(){var a=new THREE.Face3(this.a,this.b,this.c);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b>>>>>> dev diff --git a/build/custom/ThreeExtras.js b/build/custom/ThreeExtras.js index e96df7908b..3c4009dbc7 100644 --- a/build/custom/ThreeExtras.js +++ b/build/custom/ThreeExtras.js @@ -107,7 +107,7 @@ this.target.z);b.rotation.set(0,d,0)}}}else if(c==="rot")THREE.Quaternion.slerp( THREE.Animation.prototype.interpolateCatmullRom=function(b,a){var c=[],d=[],e,f,g,h,i,j;e=(b.length-1)*a;f=Math.floor(e);e=e-f;c[0]=f===0?f:f-1;c[1]=f;c[2]=f>b.length-2?f:f+1;c[3]=f>b.length-3?f:f+2;f=b[c[0]];h=b[c[1]];i=b[c[2]];j=b[c[3]];c=e*e;g=e*c;d[0]=this.interpolate(f[0],h[0],i[0],j[0],e,c,g);d[1]=this.interpolate(f[1],h[1],i[1],j[1],e,c,g);d[2]=this.interpolate(f[2],h[2],i[2],j[2],e,c,g);return d}; THREE.Animation.prototype.interpolate=function(b,a,c,d,e,f,g){b=(c-b)*0.5;d=(d-a)*0.5;return(2*(a-c)+b+d)*g+(-3*(a-c)-2*b-d)*f+b*e+a};THREE.Animation.prototype.getNextKeyWith=function(b,a,c){for(var d=this.data.hierarchy[a].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c0?c:0:c>=0?c:c+d.length;c>=0;c--)if(d[c][b]!==void 0)return d[c];return this.data.hierarchy[a].keys[d.length-1]}; -THREE.KeyFrameAnimation=function(b,a,c){this.root=b;this.data=THREE.AnimationHandler.get(a);this.hierarchy=THREE.AnimationHandler.parse(b);this.currentTime=0;this.timeScale=0.001;this.isPlaying=false;this.loop=this.isPaused=true;this.JITCompile=c!==void 0?c:true;b=0;for(a=this.hierarchy.length;b=0?a:a+g;b=this.verticalAngleMap.srcRange;a=this.verticalAngleMap.dstRange; b=THREE.Math.mapLinear(this.phi,b[0],b[1],a[0],a[1]);var d=a[1]-a[0];this.phi=c((b-a[0])/d)*d+a[0];b=this.horizontalAngleMap.srcRange;a=this.horizontalAngleMap.dstRange;b=THREE.Math.mapLinear(this.theta,b[0],b[1],a[0],a[1]);d=a[1]-a[0];this.theta=c((b-a[0])/d)*d+a[0];a=this.target.position;a.x=100*Math.sin(this.phi)*Math.cos(this.theta);a.y=100*Math.cos(this.phi);a.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.object.lookAt(this.target.position)};this.onMouseMove=function(a){if(this.domElement=== document){this.mouseX=a.pageX-this.viewHalfX;this.mouseY=a.pageY-this.viewHalfY}else{this.mouseX=a.pageX-this.domElement.offsetLeft-this.viewHalfX;this.mouseY=a.pageY-this.domElement.offsetTop-this.viewHalfY}};this.init=function(){this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var a=new THREE.MeshLambertMaterial({color:30719}),b=new THREE.MeshLambertMaterial({color:65280}), c=new THREE.CubeGeometry(10,10,20),g=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(c,a);a=new THREE.Mesh(g,b);a.position.set(0,10,0);this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.add(this.object);this.animationParent.add(this.target);this.animationParent.add(a)}else{this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.add(this.target);this.animationParent.add(this.object)}if(this.createDebugPath){var a= this.debugPath,b=this.spline,g=f(b,10),c=f(b,10),h=new THREE.LineBasicMaterial({color:16711680,linewidth:3}),g=new THREE.Line(g,h),c=new THREE.ParticleSystem(c,new THREE.ParticleBasicMaterial({color:16755200,size:3}));g.scale.set(1,1,1);a.add(g);c.scale.set(1,1,1);a.add(c);for(var g=new THREE.SphereGeometry(1,16,8),h=new THREE.MeshBasicMaterial({color:65280}),m=0;m0&&F.x0&& F.y0.001&&D.scale>0.001){w.x=D.x;w.y=D.y;w.z=D.z;z=D.size*D.scale/s;u.x=z*p;u.y=z;a.uniform3f(C.screenPosition,w.x,w.y,w.z);a.uniform2f(C.scale,u.x,u.y);a.uniform1f(C.rotation,D.rotation);a.uniform1f(C.opacity,D.opacity); +a.bindTexture(a.TEXTURE_2D,h);a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0);E.positionScreen.copy(w);E.customUpdateCallback?E.customUpdateCallback(E):E.updateLensFlares();a.uniform1i(C.renderType,2);a.enable(a.BLEND);I=0;for(K=E.lensFlares.length;I0.0010&&D.scale>0.0010){w.x=D.x;w.y=D.y;w.z=D.z;z=D.size*D.scale/s;u.x=z*p;u.y=z;a.uniform3f(C.screenPosition,w.x,w.y,w.z);a.uniform2f(C.scale,u.x,u.y);a.uniform1f(C.rotation,D.rotation);a.uniform1f(C.opacity,D.opacity); a.uniform3f(C.color,D.color.r,D.color.g,D.color.b);c.setBlending(D.blending,D.blendEquation,D.blendSrc,D.blendDst);c.setTexture(D.texture,1);a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0)}}}}a.enable(a.CULL_FACE);a.enable(a.DEPTH_TEST);a.depthMask(true)}}}; THREE.ShadowMapPlugin=function(){var b,a,c,d,e=new THREE.Frustum,f=new THREE.Matrix4,g=new THREE.Vector3,h=new THREE.Vector3;this.init=function(e){b=e.context;a=e;var e=THREE.ShaderLib.depthRGBA,f=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render= function(b,c){a.shadowMapEnabled&&a.shadowMapAutoUpdate&&this.update(b,c)};this.update=function(i,j){var l,n,k,m,o,q,r,s,t,v=[];m=0;b.clearColor(1,1,1,1);b.disable(b.BLEND);b.enable(b.CULL_FACE);a.shadowMapCullFrontFaces?b.cullFace(b.FRONT):b.cullFace(b.BACK);a.setDepthTest(true);l=0;for(n=i.__lights.length;l>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},lerpSelf:function(a,b){this.r=this.r+(a.r-this.r)*b;this.g=this.g+(a.g-this.g)*b;this.b=this.b+(a.b-this.b)*b;return this},getHex:function(){return Math.floor(this.r*255)<<16^Math.floor(this.g*255)<<8^Math.floor(this.b*255)},getContextStyle:function(){return"rgb("+Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}}; THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0}; THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;return this},divideScalar:function(a){if(a){this.x= @@ -13,153 +13,153 @@ THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a; a;this.z=this.z+a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x=this.x*a.x;this.y=this.y*a.y;this.z=this.z*a.z;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;return this},divideSelf:function(a){this.x=this.x/a.x;this.y= this.y/a.y;this.z=this.z/a.z;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a}else this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())}, setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;return this},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this, -a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,f=b?b.z:1,g=a.elements[0]/c,h=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,l=a.elements[9]/f,m=a.elements[10]/f;this.y=Math.asin(a.elements[8]/f);f=Math.cos(this.y);if(Math.abs(f)>1.0E-5){this.x=Math.atan2(-l/f,m/f);this.z=Math.atan2(-h/f,g/f)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b= +a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,e=b?b.z:1,g=a.elements[0]/c,h=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,k=a.elements[9]/e,m=a.elements[10]/e;this.y=Math.asin(a.elements[8]/e);e=Math.cos(this.y);if(Math.abs(e)>1.0E-5){this.x=Math.atan2(-k/e,m/e);this.z=Math.atan2(-h/e,g/e)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b= this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},isZero:function(){return this.lengthSq()<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1}; THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w!==void 0?a.w:1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;this.z=this.z+a.z;this.w=this.w+a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x= this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;this.w=this.w-a.w;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a;this.w=this.w/a}else{this.z=this.y=this.x=0;this.w=1}return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())}, normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;this.w=this.w+(a.w-this.w)*b;return this},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)}};THREE.Frustum=function(){this.planes=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4]}; -THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var f=d[2],g=d[3],h=d[4],l=d[5],m=d[6],j=d[7],i=d[8],o=d[9],k=d[10],u=d[11],r=d[12],n=d[13],p=d[14],d=d[15];c[0].set(g-a,j-h,u-i,d-r);c[1].set(g+a,j+h,u+i,d+r);c[2].set(g+b,j+l,u+o,d+n);c[3].set(g-b,j-l,u-o,d-n);c[4].set(g-f,j-m,u-k,d-p);c[5].set(g+f,j+m,u+k,d+p);for(a=0;a<6;a++){b=c[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}}; -THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=c.elements,c=-a.geometry.boundingSphere.radius*c.getMaxScaleOnAxis(),f=0;f<6;f++){a=b[f].x*d[12]+b[f].y*d[13]+b[f].z*d[14]+b[f].w;if(a<=c)return false}return true};THREE.Frustum.__v1=new THREE.Vector3; -THREE.Ray=function(a,b){function c(a,b,c){r.sub(c,a);w=r.dot(b);q=n.add(a,p.copy(b).multiplyScalar(w));return I=c.distanceTo(q)}function d(a,b,c,d){r.sub(d,b);n.sub(c,b);p.sub(a,b);B=r.dot(r);s=r.dot(n);J=r.dot(p);C=n.dot(n);G=n.dot(p);F=1/(B*C-s*s);P=(C*J-s*G)*F;Q=(B*G-s*J)*F;return P>=0&&Q>=0&&P+Q<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var f=1.0E-4;this.setPrecision=function(a){f=a};var g=new THREE.Vector3,h=new THREE.Vector3,l=new THREE.Vector3,m=new THREE.Vector3, -j=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3,k=new THREE.Vector3,u=new THREE.Vector3;this.intersectObject=function(a){var b,n=[];if(a instanceof THREE.Particle){var r=c(this.origin,this.direction,a.matrixWorld.getPosition());if(r>a.scale.x)return[];b={distance:r,point:a.position,face:null,object:a};n.push(b)}else if(a instanceof THREE.Mesh){var r=c(this.origin,this.direction,a.matrixWorld.getPosition()),p=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(), -a.matrixWorld.getColumnZ().length());if(r>a.geometry.boundingSphere.radius*Math.max(p.x,Math.max(p.y,p.z)))return n;var q,e,w=a.geometry,s=w.vertices,D;a.matrixRotationWorld.extractRotation(a.matrixWorld);r=0;for(p=w.faces.length;r0:q<0))){u.add(j,i.multiplyScalar(e));if(b instanceof THREE.Face3){g=D.multiplyVector3(g.copy(s[b.a]));h=D.multiplyVector3(h.copy(s[b.b]));l=D.multiplyVector3(l.copy(s[b.c]));if(d(u,g,h,l)){b={distance:j.distanceTo(u),point:u.clone(),face:b,object:a};n.push(b)}}else if(b instanceof THREE.Face4){g=D.multiplyVector3(g.copy(s[b.a]));h=D.multiplyVector3(h.copy(s[b.b]));l=D.multiplyVector3(l.copy(s[b.c]));m=D.multiplyVector3(m.copy(s[b.d]));if(d(u,g,h,m)||d(u,h,l,m)){b={distance:j.distanceTo(u),point:u.clone(), -face:b,object:a};n.push(b)}}}}}}return n};this.intersectObjects=function(a){for(var b=[],c=0,d=a.length;cg?d:g;f=f>h? -f:h}a()};this.add3Points=function(g,h,i,o,k,u){if(l){l=false;b=gi?g>k?g:k:i>k?i:k;f=h>o?h>u?h:u:o>u?o:u}else{b=gi?g>k?g>d?g:d:k>d?k:d:i>k?i>d?i:d:k>d?k:d;f=h>o?h>u?h>f?h:f:u>f?u:f:o>u?o>f?o:f:u>f?u:f}a()};this.addRectangle=function(g){if(l){l=false;b=g.getLeft();c=g.getTop();d=g.getRight();f=g.getBottom()}else{b=bg.getRight()?d:g.getRight();f=f>g.getBottom()?f:g.getBottom()}a()};this.inflate=function(g){b=b-g;c=c-g;d=d+g;f=f+g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();c=c>g.getTop()?c:g.getTop();d=da.getRight()||fa.getBottom()?false:true};this.empty=function(){l=true;f=d=c=b=0;a()};this.isEmpty=function(){return l}}; -THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return a0?1:0}};THREE.Matrix3=function(){this.elements=new Float32Array(9)}; -THREE.Matrix3.prototype={constructor:THREE.Matrix3,getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],f=-b[10]*b[4]+b[6]*b[8],g=b[10]*b[0]-b[2]*b[8],h=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],m=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*f+b[2]*l;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,i=this.elements;i[0]=b*a;i[1]=b*c;i[2]=b*d;i[3]=b*f;i[4]=b*g;i[5]=b*h;i[6]=b*l;i[7]=b*m;i[8]=b*j;return this}, -transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,f,g,h,l,m,j,i,o,k,u,r,n){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,f||0,g!==void 0?g:1,h||0,l||0,m||0,j||0,i!==void 0?i:1,o||0,k||0,u||0,r||0,n!==void 0?n:1)}; -THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,f,g,h,l,m,j,i,o,k,u,r,n){var p=this.elements;p[0]=a;p[4]=b;p[8]=c;p[12]=d;p[1]=f;p[5]=g;p[9]=h;p[13]=l;p[2]=m;p[6]=j;p[10]=i;p[14]=o;p[3]=k;p[7]=u;p[11]=r;p[15]=n;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){a=a.elements;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this},lookAt:function(a,b,c){var d=this.elements, -f=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,h=THREE.Matrix4.__v3;h.sub(a,b).normalize();if(h.length()===0)h.z=1;f.cross(c,h).normalize();if(f.length()===0){h.x=h.x+1.0E-4;f.cross(c,h).normalize()}g.cross(h,f);d[0]=f.x;d[4]=g.x;d[8]=h.x;d[1]=f.y;d[5]=g.y;d[9]=h.y;d[2]=f.z;d[6]=g.z;d[10]=h.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,f=this.elements,g=c[0],h=c[4],l=c[8],m=c[12],j=c[1],i=c[5],o=c[9],k=c[13],u=c[2],r=c[6],n=c[10],p=c[14],w=c[3],q=c[7],I=c[11],c=c[15],B=d[0],s=d[4], -J=d[8],C=d[12],G=d[1],F=d[5],P=d[9],Q=d[13],T=d[2],Z=d[6],R=d[10],z=d[14],H=d[3],E=d[7],e=d[11],d=d[15];f[0]=g*B+h*G+l*T+m*H;f[4]=g*s+h*F+l*Z+m*E;f[8]=g*J+h*P+l*R+m*e;f[12]=g*C+h*Q+l*z+m*d;f[1]=j*B+i*G+o*T+k*H;f[5]=j*s+i*F+o*Z+k*E;f[9]=j*J+i*P+o*R+k*e;f[13]=j*C+i*Q+o*z+k*d;f[2]=u*B+r*G+n*T+p*H;f[6]=u*s+r*F+n*Z+p*E;f[10]=u*J+r*P+n*R+p*e;f[14]=u*C+r*Q+n*z+p*d;f[3]=w*B+q*G+I*T+c*H;f[7]=w*s+q*F+I*Z+c*E;f[11]=w*J+q*P+I*R+c*e;f[15]=w*C+q*Q+I*z+c*d;return this},multiplySelf:function(a){return this.multiply(this, +THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var e=d[2],g=d[3],h=d[4],k=d[5],m=d[6],j=d[7],i=d[8],p=d[9],l=d[10],v=d[11],o=d[12],n=d[13],q=d[14],d=d[15];c[0].set(g-a,j-h,v-i,d-o);c[1].set(g+a,j+h,v+i,d+o);c[2].set(g+b,j+k,v+p,d+n);c[3].set(g-b,j-k,v-p,d-n);c[4].set(g-e,j-m,v-l,d-q);c[5].set(g+e,j+m,v+l,d+q);for(a=0;a<6;a++){b=c[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}}; +THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=c.elements,c=-a.geometry.boundingSphere.radius*c.getMaxScaleOnAxis(),e=0;e<6;e++){a=b[e].x*d[12]+b[e].y*d[13]+b[e].z*d[14]+b[e].w;if(a<=c)return false}return true};THREE.Frustum.__v1=new THREE.Vector3; +THREE.Ray=function(a,b){function c(a,b,c){o.sub(c,a);w=o.dot(b);r=n.add(a,q.copy(b).multiplyScalar(w));return D=c.distanceTo(r)}function d(a,b,c,d){o.sub(d,b);n.sub(c,b);q.sub(a,b);C=o.dot(o);s=o.dot(n);L=o.dot(q);A=n.dot(n);G=n.dot(q);I=1/(C*A-s*s);H=(A*L-s*G)*I;P=(C*G-s*L)*I;return H>=0&&P>=0&&H+P<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var e=1.0E-4;this.setPrecision=function(a){e=a};var g=new THREE.Vector3,h=new THREE.Vector3,k=new THREE.Vector3,m=new THREE.Vector3, +j=new THREE.Vector3,i=new THREE.Vector3,p=new THREE.Vector3,l=new THREE.Vector3,v=new THREE.Vector3;this.intersectObject=function(a){var b,n=[];if(a instanceof THREE.Particle){var o=c(this.origin,this.direction,a.matrixWorld.getPosition());if(o>a.scale.x)return[];b={distance:o,point:a.position,face:null,object:a};n.push(b)}else if(a instanceof THREE.Mesh){var o=c(this.origin,this.direction,a.matrixWorld.getPosition()),q=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(), +a.matrixWorld.getColumnZ().length());if(o>a.geometry.boundingSphere.radius*Math.max(q.x,Math.max(q.y,q.z)))return n;var r,w,f=a.geometry,s=f.vertices,F;a.matrixRotationWorld.extractRotation(a.matrixWorld);o=0;for(q=f.faces.length;o0:r<0))){v.add(j,i.multiplyScalar(w));if(b instanceof THREE.Face3){g=F.multiplyVector3(g.copy(s[b.a]));h=F.multiplyVector3(h.copy(s[b.b]));k=F.multiplyVector3(k.copy(s[b.c]));if(d(v,g,h,k)){b={distance:j.distanceTo(v),point:v.clone(),face:b,object:a};n.push(b)}}else if(b instanceof THREE.Face4){g=F.multiplyVector3(g.copy(s[b.a]));h=F.multiplyVector3(h.copy(s[b.b]));k=F.multiplyVector3(k.copy(s[b.c]));m=F.multiplyVector3(m.copy(s[b.d]));if(d(v,g,h,m)||d(v,h,k,m)){b={distance:j.distanceTo(v),point:v.clone(), +face:b,object:a};n.push(b)}}}}}}return n};this.intersectObjects=function(a){for(var b=[],c=0,d=a.length;cg?d:g;e=e>h? +e:h}a()};this.add3Points=function(g,h,i,p,l,v){if(k){k=false;b=gi?g>l?g:l:i>l?i:l;e=h>p?h>v?h:v:p>v?p:v}else{b=gi?g>l?g>d?g:d:l>d?l:d:i>l?i>d?i:d:l>d?l:d;e=h>p?h>v?h>e?h:e:v>e?v:e:p>v?p>e?p:e:v>e?v:e}a()};this.addRectangle=function(g){if(k){k=false;b=g.getLeft();c=g.getTop();d=g.getRight();e=g.getBottom()}else{b=bg.getRight()?d:g.getRight();e=e>g.getBottom()?e:g.getBottom()}a()};this.inflate=function(g){b=b-g;c=c-g;d=d+g;e=e+g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();c=c>g.getTop()?c:g.getTop();d=da.getRight()||ea.getBottom()?false:true};this.empty=function(){k=true;e=d=c=b=0;a()};this.isEmpty=function(){return k}}; +THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return a0?1:0}};THREE.Matrix3=function(){this.elements=new Float32Array(9)}; +THREE.Matrix3.prototype={constructor:THREE.Matrix3,getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*b[4]+b[6]*b[8],g=b[10]*b[0]-b[2]*b[8],h=-b[6]*b[0]+b[2]*b[4],k=b[9]*b[4]-b[5]*b[8],m=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*k;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,i=this.elements;i[0]=b*a;i[1]=b*c;i[2]=b*d;i[3]=b*e;i[4]=b*g;i[5]=b*h;i[6]=b*k;i[7]=b*m;i[8]=b*j;return this}, +transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,g,h,k,m,j,i,p,l,v,o,n){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,g!==void 0?g:1,h||0,k||0,m||0,j||0,i!==void 0?i:1,p||0,l||0,v||0,o||0,n!==void 0?n:1)}; +THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,g,h,k,m,j,i,p,l,v,o,n){var q=this.elements;q[0]=a;q[4]=b;q[8]=c;q[12]=d;q[1]=e;q[5]=g;q[9]=h;q[13]=k;q[2]=m;q[6]=j;q[10]=i;q[14]=p;q[3]=l;q[7]=v;q[11]=o;q[15]=n;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){a=a.elements;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this},lookAt:function(a,b,c){var d=this.elements, +e=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,h=THREE.Matrix4.__v3;h.sub(a,b).normalize();if(h.length()===0)h.z=1;e.cross(c,h).normalize();if(e.length()===0){h.x=h.x+1.0E-4;e.cross(c,h).normalize()}g.cross(h,e);d[0]=e.x;d[4]=g.x;d[8]=h.x;d[1]=e.y;d[5]=g.y;d[9]=h.y;d[2]=e.z;d[6]=g.z;d[10]=h.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,e=this.elements,g=c[0],h=c[4],k=c[8],m=c[12],j=c[1],i=c[5],p=c[9],l=c[13],v=c[2],o=c[6],n=c[10],q=c[14],w=c[3],r=c[7],D=c[11],c=c[15],C=d[0],s=d[4], +L=d[8],A=d[12],G=d[1],I=d[5],H=d[9],P=d[13],U=d[2],Q=d[6],W=d[10],z=d[14],K=d[3],X=d[7],E=d[11],d=d[15];e[0]=g*C+h*G+k*U+m*K;e[4]=g*s+h*I+k*Q+m*X;e[8]=g*L+h*H+k*W+m*E;e[12]=g*A+h*P+k*z+m*d;e[1]=j*C+i*G+p*U+l*K;e[5]=j*s+i*I+p*Q+l*X;e[9]=j*L+i*H+p*W+l*E;e[13]=j*A+i*P+p*z+l*d;e[2]=v*C+o*G+n*U+q*K;e[6]=v*s+o*I+n*Q+q*X;e[10]=v*L+o*H+n*W+q*E;e[14]=v*A+o*P+n*z+q*d;e[3]=w*C+r*G+D*U+c*K;e[7]=w*s+r*I+D*Q+c*X;e[11]=w*L+r*H+D*W+c*E;e[15]=w*A+r*P+D*z+c*d;return this},multiplySelf:function(a){return this.multiply(this, a)},multiplyToArray:function(a,b,c){var d=this.elements;this.multiply(a,b);c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[5]=d[5];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12];c[13]=d[13];c[14]=d[14];c[15]=d[15];return this},multiplyScalar:function(a){var b=this.elements;b[0]=b[0]*a;b[4]=b[4]*a;b[8]=b[8]*a;b[12]=b[12]*a;b[1]=b[1]*a;b[5]=b[5]*a;b[9]=b[9]*a;b[13]=b[13]*a;b[2]=b[2]*a;b[6]=b[6]*a;b[10]=b[10]*a;b[14]=b[14]*a;b[3]=b[3]*a;b[7]=b[7]*a;b[11]=b[11]*a;b[15]= -b[15]*a;return this},multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,f=a.z,g=1/(b[3]*c+b[7]*d+b[11]*f+b[15]);a.x=(b[0]*c+b[4]*d+b[8]*f+b[12])*g;a.y=(b[1]*c+b[5]*d+b[9]*f+b[13])*g;a.z=(b[2]*c+b[6]*d+b[10]*f+b[14])*g;return a},multiplyVector4:function(a){var b=this.elements,c=a.x,d=a.y,f=a.z,g=a.w;a.x=b[0]*c+b[4]*d+b[8]*f+b[12]*g;a.y=b[1]*c+b[5]*d+b[9]*f+b[13]*g;a.z=b[2]*c+b[6]*d+b[10]*f+b[14]*g;a.w=b[3]*c+b[7]*d+b[11]*f+b[15]*g;return a},rotateAxis:function(a){var b=this.elements,c=a.x, -d=a.y,f=a.z;a.x=c*b[0]+d*b[4]+f*b[8];a.y=c*b[1]+d*b[5]+f*b[9];a.z=c*b[2]+d*b[6]+f*b[10];a.normalize();return a},crossVector:function(a){var b=this.elements,c=new THREE.Vector4;c.x=b[0]*a.x+b[4]*a.y+b[8]*a.z+b[12]*a.w;c.y=b[1]*a.x+b[5]*a.y+b[9]*a.z+b[13]*a.w;c.z=b[2]*a.x+b[6]*a.y+b[10]*a.z+b[14]*a.w;c.w=a.w?b[3]*a.x+b[7]*a.y+b[11]*a.z+b[15]*a.w:1;return c},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],f=a[12],g=a[1],h=a[5],l=a[9],m=a[13],j=a[2],i=a[6],o=a[10],k=a[14],u=a[3],r=a[7], -n=a[11],a=a[15];return f*l*i*u-d*m*i*u-f*h*o*u+c*m*o*u+d*h*k*u-c*l*k*u-f*l*j*r+d*m*j*r+f*g*o*r-b*m*o*r-d*g*k*r+b*l*k*r+f*h*j*n-c*m*j*n-f*g*i*n+b*m*i*n+c*g*k*n-b*h*k*n-d*h*j*a+c*l*j*a+d*g*i*a-b*l*i*a-c*g*o*a+b*h*o*a},transpose:function(){var a=this.elements,b;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},flattenToArray:function(a){var b=this.elements;a[0]=b[0];a[1]=b[1];a[2]=b[2]; +b[15]*a;return this},multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,g=1/(b[3]*c+b[7]*d+b[11]*e+b[15]);a.x=(b[0]*c+b[4]*d+b[8]*e+b[12])*g;a.y=(b[1]*c+b[5]*d+b[9]*e+b[13])*g;a.z=(b[2]*c+b[6]*d+b[10]*e+b[14])*g;return a},multiplyVector4:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,g=a.w;a.x=b[0]*c+b[4]*d+b[8]*e+b[12]*g;a.y=b[1]*c+b[5]*d+b[9]*e+b[13]*g;a.z=b[2]*c+b[6]*d+b[10]*e+b[14]*g;a.w=b[3]*c+b[7]*d+b[11]*e+b[15]*g;return a},rotateAxis:function(a){var b=this.elements,c=a.x, +d=a.y,e=a.z;a.x=c*b[0]+d*b[4]+e*b[8];a.y=c*b[1]+d*b[5]+e*b[9];a.z=c*b[2]+d*b[6]+e*b[10];a.normalize();return a},crossVector:function(a){var b=this.elements,c=new THREE.Vector4;c.x=b[0]*a.x+b[4]*a.y+b[8]*a.z+b[12]*a.w;c.y=b[1]*a.x+b[5]*a.y+b[9]*a.z+b[13]*a.w;c.z=b[2]*a.x+b[6]*a.y+b[10]*a.z+b[14]*a.w;c.w=a.w?b[3]*a.x+b[7]*a.y+b[11]*a.z+b[15]*a.w:1;return c},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],e=a[12],g=a[1],h=a[5],k=a[9],m=a[13],j=a[2],i=a[6],p=a[10],l=a[14],v=a[3],o=a[7], +n=a[11],a=a[15];return e*k*i*v-d*m*i*v-e*h*p*v+c*m*p*v+d*h*l*v-c*k*l*v-e*k*j*o+d*m*j*o+e*g*p*o-b*m*p*o-d*g*l*o+b*k*l*o+e*h*j*n-c*m*j*n-e*g*i*n+b*m*i*n+c*g*l*n-b*h*l*n-d*h*j*a+c*k*j*a+d*g*i*a-b*k*i*a-c*g*p*a+b*h*p*a},transpose:function(){var a=this.elements,b;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},flattenToArray:function(a){var b=this.elements;a[0]=b[0];a[1]=b[1];a[2]=b[2]; a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return a},flattenToArrayOffset:function(a,b){var c=this.elements;a[b]=c[0];a[b+1]=c[1];a[b+2]=c[2];a[b+3]=c[3];a[b+4]=c[4];a[b+5]=c[5];a[b+6]=c[6];a[b+7]=c[7];a[b+8]=c[8];a[b+9]=c[9];a[b+10]=c[10];a[b+11]=c[11];a[b+12]=c[12];a[b+13]=c[13];a[b+14]=c[14];a[b+15]=c[15];return a},getPosition:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[12],a[13], -a[14])},setPosition:function(a){var b=this.elements;b[12]=a.x;b[13]=a.y;b[14]=a.z;return this},getColumnX:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[0],a[1],a[2])},getColumnY:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[4],a[5],a[6])},getColumnZ:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[8],a[9],a[10])},getInverse:function(a){var b=this.elements,c=a.elements,d=c[0],f=c[4],g=c[8],h=c[12],l=c[1],m=c[5],j=c[9],i=c[13],o=c[2],k=c[6],u=c[10],r= -c[14],n=c[3],p=c[7],w=c[11],c=c[15];b[0]=j*r*p-i*u*p+i*k*w-m*r*w-j*k*c+m*u*c;b[4]=h*u*p-g*r*p-h*k*w+f*r*w+g*k*c-f*u*c;b[8]=g*i*p-h*j*p+h*m*w-f*i*w-g*m*c+f*j*c;b[12]=h*j*k-g*i*k-h*m*u+f*i*u+g*m*r-f*j*r;b[1]=i*u*n-j*r*n-i*o*w+l*r*w+j*o*c-l*u*c;b[5]=g*r*n-h*u*n+h*o*w-d*r*w-g*o*c+d*u*c;b[9]=h*j*n-g*i*n-h*l*w+d*i*w+g*l*c-d*j*c;b[13]=g*i*o-h*j*o+h*l*u-d*i*u-g*l*r+d*j*r;b[2]=m*r*n-i*k*n+i*o*p-l*r*p-m*o*c+l*k*c;b[6]=h*k*n-f*r*n-h*o*p+d*r*p+f*o*c-d*k*c;b[10]=f*i*n-h*m*n+h*l*p-d*i*p-f*l*c+d*m*c;b[14]=h*m*o- -f*i*o-h*l*k+d*i*k+f*l*r-d*m*r;b[3]=j*k*n-m*u*n-j*o*p+l*u*p+m*o*w-l*k*w;b[7]=f*u*n-g*k*n+g*o*p-d*u*p-f*o*w+d*k*w;b[11]=g*m*n-f*j*n-g*l*p+d*j*p+f*l*w-d*m*w;b[15]=f*j*o-g*m*o+g*l*k-d*j*k-f*l*u+d*m*u;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,f=a.y,g=a.z,h=Math.cos(d),d=Math.sin(d),l=Math.cos(f),f=Math.sin(f),m=Math.cos(g),g=Math.sin(g);switch(b){case "YXZ":var j=l*m,i=l*g,o=f*m,k=f*g;c[0]=j+k*d;c[4]=o*d-i;c[8]=h*f;c[1]=h*g;c[5]=h* -m;c[9]=-d;c[2]=i*d-o;c[6]=k+j*d;c[10]=h*l;break;case "ZXY":j=l*m;i=l*g;o=f*m;k=f*g;c[0]=j-k*d;c[4]=-h*g;c[8]=o+i*d;c[1]=i+o*d;c[5]=h*m;c[9]=k-j*d;c[2]=-h*f;c[6]=d;c[10]=h*l;break;case "ZYX":j=h*m;i=h*g;o=d*m;k=d*g;c[0]=l*m;c[4]=o*f-i;c[8]=j*f+k;c[1]=l*g;c[5]=k*f+j;c[9]=i*f-o;c[2]=-f;c[6]=d*l;c[10]=h*l;break;case "YZX":j=h*l;i=h*f;o=d*l;k=d*f;c[0]=l*m;c[4]=k-j*g;c[8]=o*g+i;c[1]=g;c[5]=h*m;c[9]=-d*m;c[2]=-f*m;c[6]=i*g+o;c[10]=j-k*g;break;case "XZY":j=h*l;i=h*f;o=d*l;k=d*f;c[0]=l*m;c[4]=-g;c[8]=f*m; -c[1]=j*g+k;c[5]=h*m;c[9]=i*g-o;c[2]=o*g-i;c[6]=d*m;c[10]=k*g+j;break;default:j=h*m;i=h*g;o=d*m;k=d*g;c[0]=l*m;c[4]=-l*g;c[8]=f;c[1]=i+o*f;c[5]=j-k*f;c[9]=-d*l;c[2]=k-j*f;c[6]=o+i*f;c[10]=h*l}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,f=a.z,g=a.w,h=c+c,l=d+d,m=f+f,a=c*h,j=c*l,c=c*m,i=d*l,d=d*m,f=f*m,h=g*h,l=g*l,g=g*m;b[0]=1-(i+f);b[4]=j-g;b[8]=c+l;b[1]=j+g;b[5]=1-(a+f);b[9]=d-h;b[2]=c-l;b[6]=d+h;b[10]=1-(a+i);return this},compose:function(a,b,c){var d=this.elements, -f=THREE.Matrix4.__m1,g=THREE.Matrix4.__m2;f.identity();f.setRotationFromQuaternion(b);g.makeScale(c.x,c.y,c.z);this.multiply(f,g);d[12]=a.x;d[13]=a.y;d[14]=a.z;return this},decompose:function(a,b,c){var d=this.elements,f=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,h=THREE.Matrix4.__v3;f.set(d[0],d[1],d[2]);g.set(d[4],d[5],d[6]);h.set(d[8],d[9],d[10]);a=a instanceof THREE.Vector3?a:new THREE.Vector3;b=b instanceof THREE.Quaternion?b:new THREE.Quaternion;c=c instanceof THREE.Vector3?c:new THREE.Vector3; -c.x=f.length();c.y=g.length();c.z=h.length();a.x=d[12];a.y=d[13];a.z=d[14];d=THREE.Matrix4.__m1;d.copy(this);d.elements[0]=d.elements[0]/c.x;d.elements[1]=d.elements[1]/c.x;d.elements[2]=d.elements[2]/c.x;d.elements[4]=d.elements[4]/c.y;d.elements[5]=d.elements[5]/c.y;d.elements[6]=d.elements[6]/c.y;d.elements[8]=d.elements[8]/c.z;d.elements[9]=d.elements[9]/c.z;d.elements[10]=d.elements[10]/c.z;b.setFromRotationMatrix(d);return[a,b,c]},extractPosition:function(a){var b=this.elements,a=a.elements; -b[12]=a[12];b[13]=a[13];b[14]=a[14];return this},extractRotation:function(a){var b=this.elements,a=a.elements,c=THREE.Matrix4.__v1,d=1/c.set(a[0],a[1],a[2]).length(),f=1/c.set(a[4],a[5],a[6]).length(),c=1/c.set(a[8],a[9],a[10]).length();b[0]=a[0]*d;b[1]=a[1]*d;b[2]=a[2]*d;b[4]=a[4]*f;b[5]=a[5]*f;b[6]=a[6]*f;b[8]=a[8]*c;b[9]=a[9]*c;b[10]=a[10]*c;return this},translate:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[12]=b[0]*c+b[4]*d+b[8]*a+b[12];b[13]=b[1]*c+b[5]*d+b[9]*a+b[13];b[14]=b[2]*c+b[6]* -d+b[10]*a+b[14];b[15]=b[3]*c+b[7]*d+b[11]*a+b[15];return this},rotateX:function(a){var b=this.elements,c=b[4],d=b[5],f=b[6],g=b[7],h=b[8],l=b[9],m=b[10],j=b[11],i=Math.cos(a),a=Math.sin(a);b[4]=i*c+a*h;b[5]=i*d+a*l;b[6]=i*f+a*m;b[7]=i*g+a*j;b[8]=i*h-a*c;b[9]=i*l-a*d;b[10]=i*m-a*f;b[11]=i*j-a*g;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],f=b[2],g=b[3],h=b[8],l=b[9],m=b[10],j=b[11],i=Math.cos(a),a=Math.sin(a);b[0]=i*c-a*h;b[1]=i*d-a*l;b[2]=i*f-a*m;b[3]=i*g-a*j;b[8]=i*h+a*c;b[9]= -i*l+a*d;b[10]=i*m+a*f;b[11]=i*j+a*g;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],f=b[2],g=b[3],h=b[4],l=b[5],m=b[6],j=b[7],i=Math.cos(a),a=Math.sin(a);b[0]=i*c+a*h;b[1]=i*d+a*l;b[2]=i*f+a*m;b[3]=i*g+a*j;b[4]=i*h-a*c;b[5]=i*l-a*d;b[6]=i*m-a*f;b[7]=i*j-a*g;return this},rotateByAxis:function(a,b){var c=this.elements;if(a.x===1&&a.y===0&&a.z===0)return this.rotateX(b);if(a.x===0&&a.y===1&&a.z===0)return this.rotateY(b);if(a.x===0&&a.y===0&&a.z===1)return this.rotateZ(b);var d=a.x, -f=a.y,g=a.z,h=Math.sqrt(d*d+f*f+g*g),d=d/h,f=f/h,g=g/h,h=d*d,l=f*f,m=g*g,j=Math.cos(b),i=Math.sin(b),o=1-j,k=d*f*o,u=d*g*o,o=f*g*o,d=d*i,r=f*i,i=g*i,g=h+(1-h)*j,h=k+i,f=u-r,k=k-i,l=l+(1-l)*j,i=o+d,u=u+r,o=o-d,m=m+(1-m)*j,j=c[0],d=c[1],r=c[2],n=c[3],p=c[4],w=c[5],q=c[6],I=c[7],B=c[8],s=c[9],J=c[10],C=c[11];c[0]=g*j+h*p+f*B;c[1]=g*d+h*w+f*s;c[2]=g*r+h*q+f*J;c[3]=g*n+h*I+f*C;c[4]=k*j+l*p+i*B;c[5]=k*d+l*w+i*s;c[6]=k*r+l*q+i*J;c[7]=k*n+l*I+i*C;c[8]=u*j+o*p+m*B;c[9]=u*d+o*w+m*s;c[10]=u*r+o*q+m*J;c[11]= -u*n+o*I+m*C;return this},scale:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[0]=b[0]*c;b[4]=b[4]*d;b[8]=b[8]*a;b[1]=b[1]*c;b[5]=b[5]*d;b[9]=b[9]*a;b[2]=b[2]*c;b[6]=b[6]*d;b[10]=b[10]*a;b[3]=b[3]*c;b[7]=b[7]*d;b[11]=b[11]*a;return this},getMaxScaleOnAxis:function(){var a=this.elements;return Math.sqrt(Math.max(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],Math.max(a[4]*a[4]+a[5]*a[5]+a[6]*a[6],a[8]*a[8]+a[9]*a[9]+a[10]*a[10])))},makeTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this}, -makeRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},makeRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},makeRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),f=1-c,g=a.x,h=a.y,l=a.z,m=f*g,j=f*h;this.set(m*g+c,m*h-d*l,m*l+d*h,0,m*h+d*l,j*h+c,j*l-d*g,0,m*l- -d*h,j*l+d*g,f*l*l+c,0,0,0,0,1);return this},makeScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},makeFrustum:function(a,b,c,d,f,g){var h=this.elements;h[0]=2*f/(b-a);h[4]=0;h[8]=(b+a)/(b-a);h[12]=0;h[1]=0;h[5]=2*f/(d-c);h[9]=(d+c)/(d-c);h[13]=0;h[2]=0;h[6]=0;h[10]=-(g+f)/(g-f);h[14]=-2*g*f/(g-f);h[3]=0;h[7]=0;h[11]=-1;h[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),f=-a;return this.makeFrustum(f*b,a*b,f,a,c,d)},makeOrthographic:function(a, -b,c,d,f,g){var h=this.elements,l=b-a,m=c-d,j=g-f;h[0]=2/l;h[4]=0;h[8]=0;h[12]=-((b+a)/l);h[1]=0;h[5]=2/m;h[9]=0;h[13]=-((c+d)/m);h[2]=0;h[6]=0;h[10]=-2/j;h[14]=-((g+f)/j);h[3]=0;h[7]=0;h[11]=0;h[15]=1;return this},clone:function(){var a=this.elements;return new THREE.Matrix4(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15])}};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;THREE.Matrix4.__m1=new THREE.Matrix4; +a[14])},setPosition:function(a){var b=this.elements;b[12]=a.x;b[13]=a.y;b[14]=a.z;return this},getColumnX:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[0],a[1],a[2])},getColumnY:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[4],a[5],a[6])},getColumnZ:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[8],a[9],a[10])},getInverse:function(a){var b=this.elements,c=a.elements,d=c[0],e=c[4],g=c[8],h=c[12],k=c[1],m=c[5],j=c[9],i=c[13],p=c[2],l=c[6],v=c[10],o= +c[14],n=c[3],q=c[7],w=c[11],c=c[15];b[0]=j*o*q-i*v*q+i*l*w-m*o*w-j*l*c+m*v*c;b[4]=h*v*q-g*o*q-h*l*w+e*o*w+g*l*c-e*v*c;b[8]=g*i*q-h*j*q+h*m*w-e*i*w-g*m*c+e*j*c;b[12]=h*j*l-g*i*l-h*m*v+e*i*v+g*m*o-e*j*o;b[1]=i*v*n-j*o*n-i*p*w+k*o*w+j*p*c-k*v*c;b[5]=g*o*n-h*v*n+h*p*w-d*o*w-g*p*c+d*v*c;b[9]=h*j*n-g*i*n-h*k*w+d*i*w+g*k*c-d*j*c;b[13]=g*i*p-h*j*p+h*k*v-d*i*v-g*k*o+d*j*o;b[2]=m*o*n-i*l*n+i*p*q-k*o*q-m*p*c+k*l*c;b[6]=h*l*n-e*o*n-h*p*q+d*o*q+e*p*c-d*l*c;b[10]=e*i*n-h*m*n+h*k*q-d*i*q-e*k*c+d*m*c;b[14]=h*m*p- +e*i*p-h*k*l+d*i*l+e*k*o-d*m*o;b[3]=j*l*n-m*v*n-j*p*q+k*v*q+m*p*w-k*l*w;b[7]=e*v*n-g*l*n+g*p*q-d*v*q-e*p*w+d*l*w;b[11]=g*m*n-e*j*n-g*k*q+d*j*q+e*k*w-d*m*w;b[15]=e*j*p-g*m*p+g*k*l-d*j*l-e*k*v+d*m*v;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,e=a.y,g=a.z,h=Math.cos(d),d=Math.sin(d),k=Math.cos(e),e=Math.sin(e),m=Math.cos(g),g=Math.sin(g);switch(b){case "YXZ":var j=k*m,i=k*g,p=e*m,l=e*g;c[0]=j+l*d;c[4]=p*d-i;c[8]=h*e;c[1]=h*g;c[5]=h* +m;c[9]=-d;c[2]=i*d-p;c[6]=l+j*d;c[10]=h*k;break;case "ZXY":j=k*m;i=k*g;p=e*m;l=e*g;c[0]=j-l*d;c[4]=-h*g;c[8]=p+i*d;c[1]=i+p*d;c[5]=h*m;c[9]=l-j*d;c[2]=-h*e;c[6]=d;c[10]=h*k;break;case "ZYX":j=h*m;i=h*g;p=d*m;l=d*g;c[0]=k*m;c[4]=p*e-i;c[8]=j*e+l;c[1]=k*g;c[5]=l*e+j;c[9]=i*e-p;c[2]=-e;c[6]=d*k;c[10]=h*k;break;case "YZX":j=h*k;i=h*e;p=d*k;l=d*e;c[0]=k*m;c[4]=l-j*g;c[8]=p*g+i;c[1]=g;c[5]=h*m;c[9]=-d*m;c[2]=-e*m;c[6]=i*g+p;c[10]=j-l*g;break;case "XZY":j=h*k;i=h*e;p=d*k;l=d*e;c[0]=k*m;c[4]=-g;c[8]=e*m; +c[1]=j*g+l;c[5]=h*m;c[9]=i*g-p;c[2]=p*g-i;c[6]=d*m;c[10]=l*g+j;break;default:j=h*m;i=h*g;p=d*m;l=d*g;c[0]=k*m;c[4]=-k*g;c[8]=e;c[1]=i+p*e;c[5]=j-l*e;c[9]=-d*k;c[2]=l-j*e;c[6]=p+i*e;c[10]=h*k}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,g=a.w,h=c+c,k=d+d,m=e+e,a=c*h,j=c*k,c=c*m,i=d*k,d=d*m,e=e*m,h=g*h,k=g*k,g=g*m;b[0]=1-(i+e);b[4]=j-g;b[8]=c+k;b[1]=j+g;b[5]=1-(a+e);b[9]=d-h;b[2]=c-k;b[6]=d+h;b[10]=1-(a+i);return this},compose:function(a,b,c){var d=this.elements, +e=THREE.Matrix4.__m1,g=THREE.Matrix4.__m2;e.identity();e.setRotationFromQuaternion(b);g.makeScale(c.x,c.y,c.z);this.multiply(e,g);d[12]=a.x;d[13]=a.y;d[14]=a.z;return this},decompose:function(a,b,c){var d=this.elements,e=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,h=THREE.Matrix4.__v3;e.set(d[0],d[1],d[2]);g.set(d[4],d[5],d[6]);h.set(d[8],d[9],d[10]);a=a instanceof THREE.Vector3?a:new THREE.Vector3;b=b instanceof THREE.Quaternion?b:new THREE.Quaternion;c=c instanceof THREE.Vector3?c:new THREE.Vector3; +c.x=e.length();c.y=g.length();c.z=h.length();a.x=d[12];a.y=d[13];a.z=d[14];d=THREE.Matrix4.__m1;d.copy(this);d.elements[0]=d.elements[0]/c.x;d.elements[1]=d.elements[1]/c.x;d.elements[2]=d.elements[2]/c.x;d.elements[4]=d.elements[4]/c.y;d.elements[5]=d.elements[5]/c.y;d.elements[6]=d.elements[6]/c.y;d.elements[8]=d.elements[8]/c.z;d.elements[9]=d.elements[9]/c.z;d.elements[10]=d.elements[10]/c.z;b.setFromRotationMatrix(d);return[a,b,c]},extractPosition:function(a){var b=this.elements,a=a.elements; +b[12]=a[12];b[13]=a[13];b[14]=a[14];return this},extractRotation:function(a){var b=this.elements,a=a.elements,c=THREE.Matrix4.__v1,d=1/c.set(a[0],a[1],a[2]).length(),e=1/c.set(a[4],a[5],a[6]).length(),c=1/c.set(a[8],a[9],a[10]).length();b[0]=a[0]*d;b[1]=a[1]*d;b[2]=a[2]*d;b[4]=a[4]*e;b[5]=a[5]*e;b[6]=a[6]*e;b[8]=a[8]*c;b[9]=a[9]*c;b[10]=a[10]*c;return this},translate:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[12]=b[0]*c+b[4]*d+b[8]*a+b[12];b[13]=b[1]*c+b[5]*d+b[9]*a+b[13];b[14]=b[2]*c+b[6]* +d+b[10]*a+b[14];b[15]=b[3]*c+b[7]*d+b[11]*a+b[15];return this},rotateX:function(a){var b=this.elements,c=b[4],d=b[5],e=b[6],g=b[7],h=b[8],k=b[9],m=b[10],j=b[11],i=Math.cos(a),a=Math.sin(a);b[4]=i*c+a*h;b[5]=i*d+a*k;b[6]=i*e+a*m;b[7]=i*g+a*j;b[8]=i*h-a*c;b[9]=i*k-a*d;b[10]=i*m-a*e;b[11]=i*j-a*g;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],g=b[3],h=b[8],k=b[9],m=b[10],j=b[11],i=Math.cos(a),a=Math.sin(a);b[0]=i*c-a*h;b[1]=i*d-a*k;b[2]=i*e-a*m;b[3]=i*g-a*j;b[8]=i*h+a*c;b[9]= +i*k+a*d;b[10]=i*m+a*e;b[11]=i*j+a*g;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],g=b[3],h=b[4],k=b[5],m=b[6],j=b[7],i=Math.cos(a),a=Math.sin(a);b[0]=i*c+a*h;b[1]=i*d+a*k;b[2]=i*e+a*m;b[3]=i*g+a*j;b[4]=i*h-a*c;b[5]=i*k-a*d;b[6]=i*m-a*e;b[7]=i*j-a*g;return this},rotateByAxis:function(a,b){var c=this.elements;if(a.x===1&&a.y===0&&a.z===0)return this.rotateX(b);if(a.x===0&&a.y===1&&a.z===0)return this.rotateY(b);if(a.x===0&&a.y===0&&a.z===1)return this.rotateZ(b);var d=a.x, +e=a.y,g=a.z,h=Math.sqrt(d*d+e*e+g*g),d=d/h,e=e/h,g=g/h,h=d*d,k=e*e,m=g*g,j=Math.cos(b),i=Math.sin(b),p=1-j,l=d*e*p,v=d*g*p,p=e*g*p,d=d*i,o=e*i,i=g*i,g=h+(1-h)*j,h=l+i,e=v-o,l=l-i,k=k+(1-k)*j,i=p+d,v=v+o,p=p-d,m=m+(1-m)*j,j=c[0],d=c[1],o=c[2],n=c[3],q=c[4],w=c[5],r=c[6],D=c[7],C=c[8],s=c[9],L=c[10],A=c[11];c[0]=g*j+h*q+e*C;c[1]=g*d+h*w+e*s;c[2]=g*o+h*r+e*L;c[3]=g*n+h*D+e*A;c[4]=l*j+k*q+i*C;c[5]=l*d+k*w+i*s;c[6]=l*o+k*r+i*L;c[7]=l*n+k*D+i*A;c[8]=v*j+p*q+m*C;c[9]=v*d+p*w+m*s;c[10]=v*o+p*r+m*L;c[11]= +v*n+p*D+m*A;return this},scale:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[0]=b[0]*c;b[4]=b[4]*d;b[8]=b[8]*a;b[1]=b[1]*c;b[5]=b[5]*d;b[9]=b[9]*a;b[2]=b[2]*c;b[6]=b[6]*d;b[10]=b[10]*a;b[3]=b[3]*c;b[7]=b[7]*d;b[11]=b[11]*a;return this},getMaxScaleOnAxis:function(){var a=this.elements;return Math.sqrt(Math.max(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],Math.max(a[4]*a[4]+a[5]*a[5]+a[6]*a[6],a[8]*a[8]+a[9]*a[9]+a[10]*a[10])))},makeTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this}, +makeRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},makeRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},makeRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,h=a.y,k=a.z,m=e*g,j=e*h;this.set(m*g+c,m*h-d*k,m*k+d*h,0,m*h+d*k,j*h+c,j*k-d*g,0,m*k- +d*h,j*k+d*g,e*k*k+c,0,0,0,0,1);return this},makeScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},makeFrustum:function(a,b,c,d,e,g){var h=this.elements;h[0]=2*e/(b-a);h[4]=0;h[8]=(b+a)/(b-a);h[12]=0;h[1]=0;h[5]=2*e/(d-c);h[9]=(d+c)/(d-c);h[13]=0;h[2]=0;h[6]=0;h[10]=-(g+e)/(g-e);h[14]=-2*g*e/(g-e);h[3]=0;h[7]=0;h[11]=-1;h[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),e=-a;return this.makeFrustum(e*b,a*b,e,a,c,d)},makeOrthographic:function(a, +b,c,d,e,g){var h=this.elements,k=b-a,m=c-d,j=g-e;h[0]=2/k;h[4]=0;h[8]=0;h[12]=-((b+a)/k);h[1]=0;h[5]=2/m;h[9]=0;h[13]=-((c+d)/m);h[2]=0;h[6]=0;h[10]=-2/j;h[14]=-((g+e)/j);h[3]=0;h[7]=0;h[11]=0;h[15]=1;return this},clone:function(){var a=this.elements;return new THREE.Matrix4(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15])}};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;THREE.Matrix4.__m1=new THREE.Matrix4; THREE.Matrix4.__m2=new THREE.Matrix4; THREE.Object3D=function(){this.id=THREE.Object3DCount++;this.name="";this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=false;this.renderDepth=null;this.rotationAutoUpdate=true;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate= true;this.quaternion=new THREE.Quaternion;this.useQuaternion=false;this.boundRadius=0;this.boundRadiusScale=1;this.visible=true;this.receiveShadow=this.castShadow=false;this.frustumCulled=true;this._vector=new THREE.Vector3}; THREE.Object3D.prototype={constructor:THREE.Object3D,applyMatrix:function(a){this.matrix.multiply(a,this.matrix);this.scale.getScaleFromMatrix(this.matrix);this.rotation.getRotationFromMatrix(this.matrix,this.scale);this.position.getPositionFromMatrix(this.matrix)},translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a, this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)},add:function(a){if(a===this)console.warn("THREE.Object3D.add: An object can't be added as a child of itself.");else if(a instanceof THREE.Object3D){a.parent!==void 0&&a.parent.remove(a);a.parent=this;this.children.push(a);for(var b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__addObject(a)}},remove:function(a){var b= -this.children.indexOf(a);if(b!==-1){a.parent=void 0;this.children.splice(b,1);for(b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__removeObject(a)}},getChildByName:function(a,b){var c,d,f;c=0;for(d=this.children.length;c=0&&e>=0&&g>=0&&h>=0)return true;if(f<0&&e<0||g<0&&h<0)return false;f<0?c=Math.max(c,f/(f-e)):e<0&&(d=Math.min(d,f/(f-e)));g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h)));if(dh&&l.positionScreen.z0)){ma=j[m-2];Q.copy(S.positionScreen);T.copy(ma.positionScreen);if(d(Q,T)){Q.multiplyScalar(1/Q.w);T.multiplyScalar(1/T.w);Na=w[p]=w[p]||new THREE.RenderableLine; -p++;n=Na;n.v1.positionScreen.copy(Q);n.v2.positionScreen.copy(T);n.z=Math.max(Q.z,T.z);n.material=L.material;s.elements.push(n)}}}}}a=0;for(J=s.sprites.length;a0&&C.z<1){h=B[I]=B[I]||new THREE.RenderableParticle;I++;q=h;q.x=C.x/C.w;q.y=C.y/C.w;q.z=C.z;q.rotation=L.rotation.z;q.scale.x=L.scale.x*Math.abs(q.x-(C.x+f.projectionMatrix.elements[0])/ -(C.w+f.projectionMatrix.elements[12]));q.scale.y=L.scale.y*Math.abs(q.y-(C.y+f.projectionMatrix.elements[5])/(C.w+f.projectionMatrix.elements[13]));q.material=L.material;s.elements.push(q)}}}g&&s.elements.sort(c);return s}};THREE.Quaternion=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1}; -THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),g=Math.cos(c),c=Math.sin(c),h=a*b,l=d*f;this.w=h*g-l*c;this.x=h*c+l*g;this.y=d*b*g+a*f*c;this.z=a*f*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c); +THREE.Projector=function(){function a(){var a=h[g]=h[g]||new THREE.RenderableObject;g++;return a}function b(){var a=j[m]=j[m]||new THREE.RenderableVertex;m++;return a}function c(a,b){return b.z-a.z}function d(a,b){var c=0,d=1,e=a.z+a.w,g=b.z+b.w,f=-a.z+a.w,h=-b.z+b.w;if(e>=0&&g>=0&&f>=0&&h>=0)return true;if(e<0&&g<0||f<0&&h<0)return false;e<0?c=Math.max(c,e/(e-g)):g<0&&(d=Math.min(d,e/(e-g)));f<0?c=Math.max(c,f/(f-h)):h<0&&(d=Math.min(d,f/(f-h)));if(dh&&k.positionScreen.z0)){ga=j[m-2];P.copy(R.positionScreen);U.copy(ga.positionScreen);if(d(P,U)){P.multiplyScalar(1/P.w);U.multiplyScalar(1/U.w);Ra=w[q]=w[q]||new THREE.RenderableLine;q++;n=Ra;n.v1.positionScreen.copy(P); +n.v2.positionScreen.copy(U);n.z=Math.max(P.z,U.z);n.material=S.material;s.elements.push(n)}}}}}a=0;for(f=s.sprites.length;a0&&A.z<1){h=C[D]=C[D]||new THREE.RenderableParticle;D++;r=h;r.x=A.x/A.w;r.y=A.y/A.w;r.z=A.z;r.rotation=S.rotation.z;r.scale.x=S.scale.x*Math.abs(r.x-(A.x+e.projectionMatrix.elements[0])/(A.w+e.projectionMatrix.elements[12])); +r.scale.y=S.scale.y*Math.abs(r.y-(A.y+e.projectionMatrix.elements[5])/(A.w+e.projectionMatrix.elements[13]));r.material=S.material;s.elements.push(r)}}}g&&s.elements.sort(c);return s}};THREE.Quaternion=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1}; +THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),g=Math.cos(c),c=Math.sin(c),h=a*b,k=d*e;this.w=h*g-k*c;this.x=h*c+k*g;this.y=d*b*g+a*e*c;this.z=a*e*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c); this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.elements[0]+a.elements[5]+a.elements[10]))/2;this.x=Math.sqrt(Math.max(0,b+a.elements[0]-a.elements[5]-a.elements[10]))/2;this.y=Math.sqrt(Math.max(0,b-a.elements[0]+a.elements[5]-a.elements[10]))/2;this.z=Math.sqrt(Math.max(0,b-a.elements[0]-a.elements[5]+a.elements[10]))/2;this.x=a.elements[6]-a.elements[9]<0?-Math.abs(this.x): Math.abs(this.x);this.y=a.elements[8]-a.elements[2]<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.elements[1]-a.elements[4]<0?-Math.abs(this.z):Math.abs(this.z);this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x=this.x*-1;this.y=this.y*-1;this.z=this.z*-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a= -Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a===0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a}return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,f=this.w,g=a.x,h=a.y,l=a.z,a=a.w;this.x=b*a+f*g+c*l-d*h;this.y= -c*a+f*h+d*g-b*l;this.z=d*a+f*l+b*h-c*g;this.w=f*a-b*g-c*h-d*l;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,f=a.z,g=this.x,h=this.y,l=this.z,m=this.w,j=m*c+h*f-l*d,i=m*d+l*c-g*f,o=m*f+g*d-h*c,c=-g*c-h*d-l*f;b.x=j*m+c*-g+i*-l-o*-h;b.y=i*m+c*-h+o*-g-j*-l;b.z=o*m+c*-l+j*-h-i*-g;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}}; -THREE.Quaternion.slerp=function(a,b,c,d){var f=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(f<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;f=-f}else c.copy(b);if(Math.abs(f)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var g=Math.acos(f),f=Math.sqrt(1-f*f);if(Math.abs(f)<0.001){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")}; -THREE.Face3=function(a,b,c,d,f,g){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3}; +Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a===0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a}return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,h=a.y,k=a.z,a=a.w;this.x=b*a+e*g+c*k-d*h;this.y= +c*a+e*h+d*g-b*k;this.z=d*a+e*k+b*h-c*g;this.w=e*a-b*g-c*h-d*k;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,h=this.y,k=this.z,m=this.w,j=m*c+h*e-k*d,i=m*d+k*c-g*e,p=m*e+g*d-h*c,c=-g*c-h*d-k*e;b.x=j*m+c*-g+i*-k-p*-h;b.y=i*m+c*-h+p*-g-j*-k;b.z=p*m+c*-k+j*-h-i*-g;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}}; +THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(e<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;e=-e}else c.copy(b);if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var g=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*g)/e;d=Math.sin(d*g)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")}; +THREE.Face3=function(a,b,c,d,e,g){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3}; THREE.Face3.prototype={constructor:THREE.Face3,clone:function(){var a=new THREE.Face3(this.a,this.b,this.c);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b0){var a;a=this.vertices[0];this.boundingBox.min.copy(a);this.boundingBox.max.copy(a);for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,f=this.vertices.length;dc.x)c.x= -a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}else{this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a)}this.boundingSphere.radius=b},mergeVertices:function(){var a={},b=[],c=[],d,f=Math.pow(10,4),g,h,l;g=0;for(h=this.vertices.length;g0;a--)if(d.indexOf(f["abcd"[a]])!=a){d.splice(a,1);this.faces[g]=new THREE.Face3(d[0],d[1],d[2]);f=0;for(d=this.faceVertexUvs.length;fthis.points.length-2?this.points.length-1:g+1;c[3]=g>this.points.length-3?this.points.length-1: -g+2;j=this.points[c[0]];i=this.points[c[1]];o=this.points[c[2]];k=this.points[c[3]];l=h*h;m=h*l;d.x=b(j.x,i.x,o.x,k.x,h,l,m);d.y=b(j.y,i.y,o.y,k.y,h,l,m);d.z=b(j.z,i.z,o.z,k.z,h,l,m);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a0){var a;a=this.vertices[0];this.boundingBox.min.copy(a);this.boundingBox.max.copy(a);for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;dc.x)c.x= +a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}else{this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a)}this.boundingSphere.radius=b},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),g,h,k;g=0;for(h=this.vertices.length;g0;a--)if(d.indexOf(e["abcd"[a]])!=a){d.splice(a,1);this.faces[g]=new THREE.Face3(d[0],d[1],d[2]);e=0;for(d=this.faceVertexUvs.length;ethis.points.length-2?this.points.length-1:g+1;c[3]=g>this.points.length-3?this.points.length-1: +g+2;j=this.points[c[0]];i=this.points[c[1]];p=this.points[c[2]];l=this.points[c[3]];k=h*h;m=h*k;d.x=b(j.x,i.x,p.x,l.x,h,k,m);d.y=b(j.y,i.y,p.y,l.y,h,k,m);d.z=b(j.z,i.z,p.z,l.z,h,k,m);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a1&&(T=new THREE.MeshFaceMaterial); -a=new THREE.Mesh(Q,T);a.name=k;if(q){a.matrixAutoUpdate=false;a.matrix.set(q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10],q[11],q[12],q[13],q[14],q[15])}else{a.position.set(s[0],s[1],s[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(J[0],J[1],J[2]);a.scale.set(G[0],G[1],G[2])}a.visible=w.visible;a.doubleSided=w.doubleSided;a.castShadow=w.castShadow;a.receiveShadow=w.receiveShadow;D.scene.add(a);D.objects[k]=a}}else{s=w.position;J=w.rotation;C=w.quaternion; -G=w.scale;C=0;a=new THREE.Object3D;a.name=k;a.position.set(s[0],s[1],s[2]);if(C){a.quaternion.set(C[0],C[1],C[2],C[3]);a.useQuaternion=true}else a.rotation.set(J[0],J[1],J[2]);a.scale.set(G[0],G[1],G[2]);a.visible=w.visible!==void 0?w.visible:false;D.scene.add(a);D.objects[k]=a;D.empties[k]=a}}}function g(a){return function(b){D.geometries[a]=b;f();E=E-1;m.onLoadComplete();l()}}function h(a){return function(b){D.geometries[a]=b}}function l(){m.callbackProgress({totalModels:Ba,totalTextures:X,loadedModels:Ba- -E,loadedTextures:X-e},D);m.onLoadProgress();E==0&&e==0&&b(D)}var m=this,j=THREE.Loader.prototype.extractUrlBase(c),i,o,k,u,r,n,p,w,q,I,B,s,J,C,G,F,P,Q,T,Z,R,z,H,E,e,Ba,X,D;z=a;c=new THREE.BinaryLoader;H=new THREE.JSONLoader;e=E=0;D={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(z.transform){a=z.transform.position;I=z.transform.rotation;F=z.transform.scale;a&&D.scene.position.set(a[0],a[1],a[2]);I&&D.scene.rotation.set(I[0],I[1], -I[2]);F&&D.scene.scale.set(F[0],F[1],F[2]);if(a||I||F){D.scene.updateMatrix();D.scene.updateMatrixWorld()}}a=function(){e=e-1;l();m.onLoadComplete()};for(r in z.cameras){F=z.cameras[r];F.type=="perspective"?Z=new THREE.PerspectiveCamera(F.fov,F.aspect,F.near,F.far):F.type=="ortho"&&(Z=new THREE.OrthographicCamera(F.left,F.right,F.top,F.bottom,F.near,F.far));s=F.position;I=F.target;F=F.up;Z.position.set(s[0],s[1],s[2]);Z.target=new THREE.Vector3(I[0],I[1],I[2]);F&&Z.up.set(F[0],F[1],F[2]);D.cameras[r]= -Z}for(u in z.lights){I=z.lights[u];r=I.color!==void 0?I.color:16777215;Z=I.intensity!==void 0?I.intensity:1;if(I.type=="directional"){s=I.direction;B=new THREE.DirectionalLight(r,Z);B.position.set(s[0],s[1],s[2]);B.position.normalize()}else if(I.type=="point"){s=I.position;B=I.distance;B=new THREE.PointLight(r,Z,B);B.position.set(s[0],s[1],s[2])}else I.type=="ambient"&&(B=new THREE.AmbientLight(r));D.scene.add(B);D.lights[u]=B}for(n in z.fogs){u=z.fogs[n];u.type=="linear"?R=new THREE.Fog(0,u.near, -u.far):u.type=="exp2"&&(R=new THREE.FogExp2(0,u.density));F=u.color;R.color.setRGB(F[0],F[1],F[2]);D.fogs[n]=R}if(D.cameras&&z.defaults.camera)D.currentCamera=D.cameras[z.defaults.camera];if(D.fogs&&z.defaults.fog)D.scene.fog=D.fogs[z.defaults.fog];F=z.defaults.bgcolor;D.bgColor=new THREE.Color;D.bgColor.setRGB(F[0],F[1],F[2]);D.bgColorAlpha=z.defaults.bgalpha;for(i in z.geometries){n=z.geometries[i];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){E=E+1;m.onLoadStart()}}Ba=E;for(i in z.geometries){n= -z.geometries[i];if(n.type=="cube"){Q=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides);D.geometries[i]=Q}else if(n.type=="plane"){Q=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight);D.geometries[i]=Q}else if(n.type=="sphere"){Q=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight);D.geometries[i]=Q}else if(n.type=="cylinder"){Q=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs, -n.heightSegs);D.geometries[i]=Q}else if(n.type=="torus"){Q=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT);D.geometries[i]=Q}else if(n.type=="icosahedron"){Q=new THREE.IcosahedronGeometry(n.radius,n.subdivisions);D.geometries[i]=Q}else if(n.type=="bin_mesh")c.load(d(n.url,z.urlBaseType),g(i));else if(n.type=="ascii_mesh")H.load(d(n.url,z.urlBaseType),g(i));else if(n.type=="embedded_mesh"){n=z.embeds[n.id];n.metadata=z.metadata;n&&H.createModel(n,h(i),"")}}for(p in z.textures){i=z.textures[p]; -if(i.url instanceof Array){e=e+i.url.length;for(n=0;n1&&(U=new THREE.MeshFaceMaterial); +a=new THREE.Mesh(P,U);a.name=l;if(r){a.matrixAutoUpdate=false;a.matrix.set(r[0],r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11],r[12],r[13],r[14],r[15])}else{a.position.set(s[0],s[1],s[2]);if(A){a.quaternion.set(A[0],A[1],A[2],A[3]);a.useQuaternion=true}else a.rotation.set(L[0],L[1],L[2]);a.scale.set(G[0],G[1],G[2])}a.visible=w.visible;a.doubleSided=w.doubleSided;a.castShadow=w.castShadow;a.receiveShadow=w.receiveShadow;F.scene.add(a);F.objects[l]=a}}else{s=w.position;L=w.rotation;A=w.quaternion; +G=w.scale;A=0;a=new THREE.Object3D;a.name=l;a.position.set(s[0],s[1],s[2]);if(A){a.quaternion.set(A[0],A[1],A[2],A[3]);a.useQuaternion=true}else a.rotation.set(L[0],L[1],L[2]);a.scale.set(G[0],G[1],G[2]);a.visible=w.visible!==void 0?w.visible:false;F.scene.add(a);F.objects[l]=a;F.empties[l]=a}}}function g(a){return function(b){F.geometries[a]=b;e();X=X-1;m.onLoadComplete();k()}}function h(a){return function(b){F.geometries[a]=b}}function k(){m.callbackProgress({totalModels:f,totalTextures:fa,loadedModels:f- +X,loadedTextures:fa-E},F);m.onLoadProgress();X==0&&E==0&&b(F)}var m=this,j=THREE.Loader.prototype.extractUrlBase(c),i,p,l,v,o,n,q,w,r,D,C,s,L,A,G,I,H,P,U,Q,W,z,K,X,E,f,fa,F;z=a;c=new THREE.BinaryLoader;K=new THREE.JSONLoader;E=X=0;F={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(z.transform){a=z.transform.position;D=z.transform.rotation;I=z.transform.scale;a&&F.scene.position.set(a[0],a[1],a[2]);D&&F.scene.rotation.set(D[0],D[1], +D[2]);I&&F.scene.scale.set(I[0],I[1],I[2]);if(a||D||I){F.scene.updateMatrix();F.scene.updateMatrixWorld()}}a=function(){E=E-1;k();m.onLoadComplete()};for(o in z.cameras){I=z.cameras[o];I.type=="perspective"?Q=new THREE.PerspectiveCamera(I.fov,I.aspect,I.near,I.far):I.type=="ortho"&&(Q=new THREE.OrthographicCamera(I.left,I.right,I.top,I.bottom,I.near,I.far));s=I.position;D=I.target;I=I.up;Q.position.set(s[0],s[1],s[2]);Q.target=new THREE.Vector3(D[0],D[1],D[2]);I&&Q.up.set(I[0],I[1],I[2]);F.cameras[o]= +Q}for(v in z.lights){D=z.lights[v];o=D.color!==void 0?D.color:16777215;Q=D.intensity!==void 0?D.intensity:1;if(D.type=="directional"){s=D.direction;C=new THREE.DirectionalLight(o,Q);C.position.set(s[0],s[1],s[2]);C.position.normalize()}else if(D.type=="point"){s=D.position;C=D.distance;C=new THREE.PointLight(o,Q,C);C.position.set(s[0],s[1],s[2])}else D.type=="ambient"&&(C=new THREE.AmbientLight(o));F.scene.add(C);F.lights[v]=C}for(n in z.fogs){v=z.fogs[n];v.type=="linear"?W=new THREE.Fog(0,v.near, +v.far):v.type=="exp2"&&(W=new THREE.FogExp2(0,v.density));I=v.color;W.color.setRGB(I[0],I[1],I[2]);F.fogs[n]=W}if(F.cameras&&z.defaults.camera)F.currentCamera=F.cameras[z.defaults.camera];if(F.fogs&&z.defaults.fog)F.scene.fog=F.fogs[z.defaults.fog];I=z.defaults.bgcolor;F.bgColor=new THREE.Color;F.bgColor.setRGB(I[0],I[1],I[2]);F.bgColorAlpha=z.defaults.bgalpha;for(i in z.geometries){n=z.geometries[i];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){X=X+1;m.onLoadStart()}}f=X;for(i in z.geometries){n= +z.geometries[i];if(n.type=="cube"){P=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides);F.geometries[i]=P}else if(n.type=="plane"){P=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight);F.geometries[i]=P}else if(n.type=="sphere"){P=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight);F.geometries[i]=P}else if(n.type=="cylinder"){P=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs, +n.heightSegs);F.geometries[i]=P}else if(n.type=="torus"){P=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT);F.geometries[i]=P}else if(n.type=="icosahedron"){P=new THREE.IcosahedronGeometry(n.radius,n.subdivisions);F.geometries[i]=P}else if(n.type=="bin_mesh")c.load(d(n.url,z.urlBaseType),g(i));else if(n.type=="ascii_mesh")K.load(d(n.url,z.urlBaseType),g(i));else if(n.type=="embedded_mesh"){n=z.embeds[n.id];n.metadata=z.metadata;n&&K.createModel(n,h(i),"")}}for(q in z.textures){i=z.textures[q]; +if(i.url instanceof Array){E=E+i.url.length;for(n=0;n1){a.matrixWorldInverse.getInverse(a.matrixWorld);a=a.matrixWorldInverse;a=-(a.elements[2]*this.matrixWorld.elements[12]+a.elements[6]*this.matrixWorld.elements[13]+a.elements[10]*this.matrixWorld.elements[14]+a.elements[14]);this.LODs[0].object3D.visible=true;for(var b=1;b=this.LODs[b].visibleAtDistance){this.LODs[b-1].object3D.visible=false;this.LODs[b].object3D.visible=true}else break;for(;b= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\nbool inFrustum = all( inFrustumVec );\n#ifdef SHADOWMAP_CASCADE\ninFrustumCount += int( inFrustum );\nbvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n#else\nbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n#endif\nbool frustumTest = all( frustumTestVec );\nif ( frustumTest ) {\nshadowCoord.z += shadowBias[ i ];\n#ifdef SHADOWMAP_SOFT\nfloat shadow = 0.0;\nconst float shadowDelta = 1.0 / 9.0;\nfloat xPixelOffset = 1.0 / shadowMapSize[ i ].x;\nfloat yPixelOffset = 1.0 / shadowMapSize[ i ].y;\nfloat dx0 = -1.25 * xPixelOffset;\nfloat dy0 = -1.25 * yPixelOffset;\nfloat dx1 = 1.25 * xPixelOffset;\nfloat dy1 = 1.25 * yPixelOffset;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n#else\nvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n#endif\n}\n#ifdef SHADOWMAP_DEBUG\n#ifdef SHADOWMAP_CASCADE\nif ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];\n#else\nif ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];\n#endif\n#endif\n}\n#ifdef GAMMA_OUTPUT\nshadowColor *= shadowColor;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n#endif", shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nuniform mat4 shadowMatrix[ MAX_SHADOWS ];\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\n#ifdef USE_MORPHTARGETS\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( morphed, 1.0 );\n#else\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );\n#endif\n}\n#endif",alphatest_fragment:"#ifdef ALPHATEST\nif ( gl_FragColor.a < ALPHATEST ) discard;\n#endif", linear_to_gamma_fragment:"#ifdef GAMMA_OUTPUT\ngl_FragColor.xyz = sqrt( gl_FragColor.xyz );\n#endif"}; -THREE.UniformsUtils={merge:function(a){var b,c,d,f={};for(b=0;b=0)return a.geometry.materials[b.materialIndex]}function d(a){return a instanceof THREE.MeshBasicMaterial&&!a.envMap||a instanceof THREE.MeshDepthMaterial?false:a&&a.shading!==void 0&&a.shading===THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading}function f(a){return a.map||a.lightMap||a instanceof THREE.ShaderMaterial?true:false}function g(a,b,c){var d,f,g,h,i=a.vertices;h=i.length; -var j=a.colors,k=j.length,l=a.__vertexArray,m=a.__colorArray,n=a.__sortArray,o=a.verticesNeedUpdate,r=a.colorsNeedUpdate,p=a.__webglCustomAttributesList;if(c.sortParticles){Pb.copy(tb);Pb.multiplySelf(c.matrixWorld);for(d=0;d=0;c--)a[c].object=== -b&&a.splice(c,1)}function r(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function n(a,b,c,d,f){if(!d.program||d.needsUpdate){E.initMaterial(d,b,c,f);d.needsUpdate=false}if(d.morphTargets&&!f.__webglMorphTargetInfluences){f.__webglMorphTargetInfluences=new Float32Array(E.maxMorphTargets);for(var g=0,i=E.maxMorphTargets;g0};this.setSize=function(a,b){C.width=a;C.height=b;this.setViewport(0,0,C.width,C.height)};this.setViewport=function(a,b,c,d){Ob=a;Yb=b;Hb=c;ac=d;e.viewport(Ob,Yb,Hb,ac)};this.setScissor=function(a,b,c,d){e.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)};this.setClearColorHex=function(a,b){R.setHex(a);z=b;e.clearColor(R.r,R.g,R.b,z)};this.setClearColor=function(a, -b){R.copy(a);z=b;e.clearColor(R.r,R.g,R.b,z)};this.getClearColor=function(){return R};this.getClearAlpha=function(){return z};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d=d|e.COLOR_BUFFER_BIT;if(b===void 0||b)d=d|e.DEPTH_BUFFER_BIT;if(c===void 0||c)d=d|e.STENCIL_BUFFER_BIT;e.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)}; -this.deallocateObject=function(a){if(a.__webglInit){a.__webglInit=false;delete a._modelViewMatrix;delete a._normalMatrix;delete a._normalMatrixArray;delete a._modelViewMatrixArray;delete a._objectMatrixArray;if(a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];e.deleteBuffer(c.__webglVertexBuffer);e.deleteBuffer(c.__webglNormalBuffer);e.deleteBuffer(c.__webglTangentBuffer);e.deleteBuffer(c.__webglColorBuffer);e.deleteBuffer(c.__webglUVBuffer);e.deleteBuffer(c.__webglUV2Buffer); -e.deleteBuffer(c.__webglSkinVertexABuffer);e.deleteBuffer(c.__webglSkinVertexBBuffer);e.deleteBuffer(c.__webglSkinIndicesBuffer);e.deleteBuffer(c.__webglSkinWeightsBuffer);e.deleteBuffer(c.__webglFaceBuffer);e.deleteBuffer(c.__webglLineBuffer);var d=void 0,f=void 0;if(c.numMorphTargets){d=0;for(f=c.numMorphTargets;d= -0&&f.vertexNormalBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.vertexNormalBuffer);e.vertexAttribPointer(a.normal,f.vertexNormalBuffer.itemSize,e.FLOAT,false,0,g[d].index*12)}if(a.uv>=0&&f.vertexUvBuffer)if(f.vertexUvBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.vertexUvBuffer);e.vertexAttribPointer(a.uv,f.vertexUvBuffer.itemSize,e.FLOAT,false,0,g[d].index*8);e.enableVertexAttribArray(a.uv)}else e.disableVertexAttribArray(a.uv);if(a.color>=0&&f.vertexColorBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.vertexColorBuffer); -e.vertexAttribPointer(a.color,f.vertexColorBuffer.itemSize,e.FLOAT,false,0,g[d].index*16)}e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.vertexIndexBuffer)}e.drawElements(e.TRIANGLES,g[d].count,e.UNSIGNED_SHORT,g[d].start*2);E.info.render.calls++;E.info.render.vertices=E.info.render.vertices+g[d].count;E.info.render.faces=E.info.render.faces+g[d].count/3}}}};this.renderBuffer=function(a,b,c,d,f,g){if(d.visible!==false){var h,i,c=n(a,b,c,d,g),b=c.attributes,a=false,c=f.id*16777215+c.id*2+(d.wireframe?1:0); -if(c!==S){S=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer);e.vertexAttribPointer(b.position,3,e.FLOAT,false,0,0)}}else if(g.morphTargetBase){c=d.program.attributes;if(g.morphTargetBase!==-1){e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[g.morphTargetBase]);e.vertexAttribPointer(c.position,3,e.FLOAT,false,0,0)}else if(c.position>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer);e.vertexAttribPointer(c.position,3,e.FLOAT,false,0, -0)}if(g.morphTargetForcedOrder.length){h=0;var j=g.morphTargetForcedOrder;for(i=g.morphTargetInfluences;hk){l=m;k=i[l]}e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[l]);e.vertexAttribPointer(c["morphTarget"+h],3,e.FLOAT,false,0,0);if(d.morphNormals){e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphNormalsBuffers[l]);e.vertexAttribPointer(c["morphNormal"+h],3,e.FLOAT,false,0,0)}g.__webglMorphTargetInfluences[h]=k;j[l]=1;k=-1;h++}}d.program.uniforms.morphTargetInfluences!== -null&&e.uniform1fv(d.program.uniforms.morphTargetInfluences,g.__webglMorphTargetInfluences)}if(a){if(f.__webglCustomAttributesList){h=0;for(i=f.__webglCustomAttributesList.length;h=0){e.bindBuffer(e.ARRAY_BUFFER,c.buffer);e.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,e.FLOAT,false,0,0)}}}if(b.color>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglColorBuffer);e.vertexAttribPointer(b.color,3,e.FLOAT,false,0,0)}if(b.normal>= -0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglNormalBuffer);e.vertexAttribPointer(b.normal,3,e.FLOAT,false,0,0)}if(b.tangent>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglTangentBuffer);e.vertexAttribPointer(b.tangent,4,e.FLOAT,false,0,0)}if(b.uv>=0)if(f.__webglUVBuffer){e.bindBuffer(e.ARRAY_BUFFER,f.__webglUVBuffer);e.vertexAttribPointer(b.uv,2,e.FLOAT,false,0,0);e.enableVertexAttribArray(b.uv)}else e.disableVertexAttribArray(b.uv);if(b.uv2>=0)if(f.__webglUV2Buffer){e.bindBuffer(e.ARRAY_BUFFER,f.__webglUV2Buffer); -e.vertexAttribPointer(b.uv2,2,e.FLOAT,false,0,0);e.enableVertexAttribArray(b.uv2)}else e.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexABuffer);e.vertexAttribPointer(b.skinVertexA,4,e.FLOAT,false,0,0);e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexBBuffer);e.vertexAttribPointer(b.skinVertexB,4,e.FLOAT,false,0,0);e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinIndicesBuffer);e.vertexAttribPointer(b.skinIndex, -4,e.FLOAT,false,0,0);e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinWeightsBuffer);e.vertexAttribPointer(b.skinWeight,4,e.FLOAT,false,0,0)}}if(g instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==mb){e.lineWidth(d);mb=d}a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglLineBuffer);e.drawElements(e.LINES,f.__webglLineCount,e.UNSIGNED_SHORT,0)}else{a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglFaceBuffer);e.drawElements(e.TRIANGLES,f.__webglFaceCount,e.UNSIGNED_SHORT,0)}E.info.render.calls++; -E.info.render.vertices=E.info.render.vertices+f.__webglFaceCount;E.info.render.faces=E.info.render.faces+f.__webglFaceCount/3}else if(g instanceof THREE.Line){g=g.type===THREE.LineStrip?e.LINE_STRIP:e.LINES;d=d.linewidth;if(d!==mb){e.lineWidth(d);mb=d}e.drawArrays(g,0,f.__webglLineCount);E.info.render.calls++}else if(g instanceof THREE.ParticleSystem){e.drawArrays(e.POINTS,0,f.__webglParticleCount);E.info.render.calls++;E.info.render.points=E.info.render.points+f.__webglParticleCount}else if(g instanceof -THREE.Ribbon){e.drawArrays(e.TRIANGLE_STRIP,0,f.__webglVertexCount);E.info.render.calls++}}};this.render=function(a,b,c,d){var f,g,i,k,n=a.__lights,o=a.fog;la=-1;nb=true;if(b.parent===void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");a.add(b)}this.autoUpdateScene&&a.updateMatrixWorld();if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.matrixWorldInverse.getInverse(b.matrixWorld); -b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);tb.multiply(b.projectionMatrix,b.matrixWorldInverse);Ib.setFromMatrix(tb);this.autoUpdateObjects&&this.initWebGLObjects(a);l(this.renderPluginsPre,a,b);E.info.render.calls=0;E.info.render.vertices=0;E.info.render.faces=0;E.info.render.points=0;this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);k=a.__webglObjects;d=0; -for(f=k.length;d=0){s=q.geometry.materials[s];if(s.transparent){r.transparent=s;r.opaque=null}else{r.opaque=s;r.transparent=null}}}else if(s)if(s.transparent){r.transparent=s;r.opaque=null}else{r.opaque=s;r.transparent= -null}g.render=true;if(this.sortObjects)if(i.renderDepth)g.z=i.renderDepth;else{Pa.copy(i.matrixWorld.getPosition());tb.multiplyVector3(Pa);g.z=Pa.z}}}this.sortObjects&&k.sort(h);k=a.__webglObjectsImmediate;d=0;for(f=k.length;d65535){F[C].counter=F[C].counter+1;D=F[C].hash+"_"+F[C].counter;q.geometryGroups[D]===void 0&&(q.geometryGroups[D]={faces3:[],faces4:[],materialIndex:z,vertices:0,numMorphTargets:I,numMorphNormals:J})}w instanceof THREE.Face3?q.geometryGroups[D].faces3.push(p):q.geometryGroups[D].faces4.push(p);q.geometryGroups[D].vertices=q.geometryGroups[D].vertices+B}q.geometryGroupsList=[];var P=void 0;for(P in q.geometryGroups){q.geometryGroups[P].id=ua++;q.geometryGroupsList.push(q.geometryGroups[P])}}for(l in m.geometryGroups){n= -m.geometryGroups[l];if(!n.__webglVertexBuffer){var H=n;H.__webglVertexBuffer=e.createBuffer();H.__webglNormalBuffer=e.createBuffer();H.__webglTangentBuffer=e.createBuffer();H.__webglColorBuffer=e.createBuffer();H.__webglUVBuffer=e.createBuffer();H.__webglUV2Buffer=e.createBuffer();H.__webglSkinVertexABuffer=e.createBuffer();H.__webglSkinVertexBBuffer=e.createBuffer();H.__webglSkinIndicesBuffer=e.createBuffer();H.__webglSkinWeightsBuffer=e.createBuffer();H.__webglFaceBuffer=e.createBuffer();H.__webglLineBuffer= -e.createBuffer();var L=void 0,Q=void 0;if(H.numMorphTargets){H.__webglMorphTargetsBuffers=[];L=0;for(Q=H.numMorphTargets;L0||S.faceVertexUvs.length>0)G.__uvArray=new Float32Array(X*2);if(S.faceUvs.length>1||S.faceVertexUvs.length>1)G.__uv2Array=new Float32Array(X*2)}if(R.geometry.skinWeights.length&&R.geometry.skinIndices.length){G.__skinVertexAArray=new Float32Array(X*4);G.__skinVertexBArray= -new Float32Array(X*4);G.__skinIndexArray=new Float32Array(X*4);G.__skinWeightArray=new Float32Array(X*4)}G.__faceArray=new Uint16Array(ma*3);G.__lineArray=new Uint16Array(ra*2);var Ca=void 0,Fa=void 0;if(G.numMorphTargets){G.__morphTargetsArrays=[];Ca=0;for(Fa=G.numMorphTargets;Ca0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinVertexABuffer);e.bufferData(e.ARRAY_BUFFER,ga,Ia);e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinVertexBBuffer);e.bufferData(e.ARRAY_BUFFER,ha,Ia);e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinIndicesBuffer);e.bufferData(e.ARRAY_BUFFER,ia,Ia);e.bindBuffer(e.ARRAY_BUFFER,V.__webglSkinWeightsBuffer); -e.bufferData(e.ARRAY_BUFFER,ja,Ia)}}if(cd&&Lc){x=0;for(K=aa.length;x0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglColorBuffer);e.bufferData(e.ARRAY_BUFFER,xa,Ia)}}if(bd&&Ea.hasTangents){x=0;for(K=aa.length;x0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglUVBuffer);e.bufferData(e.ARRAY_BUFFER,jc,Ia)}}if(Uc&&Qc&&$b){x=0;for(K=aa.length;x0){e.bindBuffer(e.ARRAY_BUFFER,V.__webglUV2Buffer);e.bufferData(e.ARRAY_BUFFER,kc,Ia)}}if(Ic){x=0;for(K=aa.length;x0?"#define VERTEX_TEXTURES":"",E.gammaInput?"#define GAMMA_INPUT":"",E.gammaOutput?"#define GAMMA_OUTPUT":"",E.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+ -c.maxShadows,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING":"",c.morphTargets?"#define USE_MORPHTARGETS":"",c.morphNormals?"#define USE_MORPHNORMALS":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT": -"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\n#ifdef USE_MORPHNORMALS\nattribute vec3 morphNormal0;\nattribute vec3 morphNormal1;\nattribute vec3 morphNormal2;\nattribute vec3 morphNormal3;\n#else\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n"); -k=["precision "+G+" float;","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",E.gammaInput?"#define GAMMA_INPUT":"",E.gammaOutput?"#define GAMMA_OUTPUT":"",E.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP": +THREE.WebGLRenderer=function(a){function b(a,b){var c=a.vertices.length,d=b.material;if(d.attributes){if(a.__webglCustomAttributesList===void 0)a.__webglCustomAttributesList=[];for(var e in d.attributes){var g=d.attributes[e];if(!g.__webglInitialized||g.createUniqueBuffers){g.__webglInitialized=true;var h=1;g.type==="v2"?h=2:g.type==="v3"?h=3:g.type==="v4"?h=4:g.type==="c"&&(h=3);g.size=h;g.array=new Float32Array(c*h);g.buffer=f.createBuffer();g.buffer.belongsToAttribute=e;g.needsUpdate=true}a.__webglCustomAttributesList.push(g)}}} +function c(a,b){if(a.material&&!(a.material instanceof THREE.MeshFaceMaterial))return a.material;if(b.materialIndex>=0)return a.geometry.materials[b.materialIndex]}function d(a){return a instanceof THREE.MeshBasicMaterial&&!a.envMap||a instanceof THREE.MeshDepthMaterial?false:a&&a.shading!==void 0&&a.shading===THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading}function e(a){return a.map||a.lightMap||a instanceof THREE.ShaderMaterial?true:false}function g(a,b,c){var d,e,g,h,i=a.vertices;h=i.length; +var j=a.colors,l=j.length,k=a.__vertexArray,m=a.__colorArray,n=a.__sortArray,p=a.verticesNeedUpdate,o=a.colorsNeedUpdate,q=a.__webglCustomAttributesList;if(c.sortParticles){Qb.copy(Ib);Qb.multiplySelf(c.matrixWorld);for(d=0;d=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function q(a,b,c,d,e){if(!d.program||d.needsUpdate){E.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(E.maxMorphTargets);for(var g=0,i=E.maxMorphTargets;g0};this.setSize=function(a,b){G.width=a;G.height=b;this.setViewport(0,0,G.width,G.height)};this.setViewport=function(a,b,c,d){Zb=a;Hb=b;bc=c;Jb=d;f.viewport(Zb,Hb,bc,Jb)};this.setScissor=function(a,b,c,d){f.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?f.enable(f.SCISSOR_TEST):f.disable(f.SCISSOR_TEST)};this.setClearColorHex=function(a,b){z.setHex(a);K=b;f.clearColor(z.r,z.g,z.b,K)};this.setClearColor=function(a, +b){z.copy(a);K=b;f.clearColor(z.r,z.g,z.b,K)};this.getClearColor=function(){return z};this.getClearAlpha=function(){return K};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d=d|f.COLOR_BUFFER_BIT;if(b===void 0||b)d=d|f.DEPTH_BUFFER_BIT;if(c===void 0||c)d=d|f.STENCIL_BUFFER_BIT;f.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)}; +this.deallocateObject=function(a){if(a.__webglInit){a.__webglInit=false;delete a._modelViewMatrix;delete a._normalMatrix;delete a._normalMatrixArray;delete a._modelViewMatrixArray;delete a._objectMatrixArray;if(a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];f.deleteBuffer(c.__webglVertexBuffer);f.deleteBuffer(c.__webglNormalBuffer);f.deleteBuffer(c.__webglTangentBuffer);f.deleteBuffer(c.__webglColorBuffer);f.deleteBuffer(c.__webglUVBuffer);f.deleteBuffer(c.__webglUV2Buffer); +f.deleteBuffer(c.__webglSkinVertexABuffer);f.deleteBuffer(c.__webglSkinVertexBBuffer);f.deleteBuffer(c.__webglSkinIndicesBuffer);f.deleteBuffer(c.__webglSkinWeightsBuffer);f.deleteBuffer(c.__webglFaceBuffer);f.deleteBuffer(c.__webglLineBuffer);var d=void 0,e=void 0;if(c.numMorphTargets){d=0;for(e=c.numMorphTargets;d=0&&e.vertexNormalBuffer){f.bindBuffer(f.ARRAY_BUFFER,e.vertexNormalBuffer);f.vertexAttribPointer(a.normal,e.vertexNormalBuffer.itemSize,f.FLOAT,false,0,g[d].index*12)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){f.bindBuffer(f.ARRAY_BUFFER,e.vertexUvBuffer);f.vertexAttribPointer(a.uv,e.vertexUvBuffer.itemSize,f.FLOAT,false,0,g[d].index*8);f.enableVertexAttribArray(a.uv)}else f.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){f.bindBuffer(f.ARRAY_BUFFER,e.vertexColorBuffer); +f.vertexAttribPointer(a.color,e.vertexColorBuffer.itemSize,f.FLOAT,false,0,g[d].index*16)}f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)}f.drawElements(f.TRIANGLES,g[d].count,f.UNSIGNED_SHORT,g[d].start*2);E.info.render.calls++;E.info.render.vertices=E.info.render.vertices+g[d].count;E.info.render.faces=E.info.render.faces+g[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,g){if(d.visible!==false){var h,i,c=q(a,b,c,d,g),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0); +if(c!==ga){ga=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){f.bindBuffer(f.ARRAY_BUFFER,e.__webglVertexBuffer);f.vertexAttribPointer(b.position,3,f.FLOAT,false,0,0)}}else if(g.morphTargetBase){c=d.program.attributes;if(g.morphTargetBase!==-1){f.bindBuffer(f.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[g.morphTargetBase]);f.vertexAttribPointer(c.position,3,f.FLOAT,false,0,0)}else if(c.position>=0){f.bindBuffer(f.ARRAY_BUFFER,e.__webglVertexBuffer);f.vertexAttribPointer(c.position,3,f.FLOAT,false, +0,0)}if(g.morphTargetForcedOrder.length){var j=0;i=g.morphTargetForcedOrder;for(h=g.morphTargetInfluences;j0&&i.push(l)}if(i.length>d.numSupportedMorphTargets){i.sort(k);i.length=d.numSupportedMorphTargets}else i.length>d.numSupportedMorphNormals?i.sort(k):i.length===0&&i.push(0);for(j=0;j=0){f.bindBuffer(f.ARRAY_BUFFER,c.buffer);f.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,f.FLOAT,false,0,0)}}}if(b.color>=0){f.bindBuffer(f.ARRAY_BUFFER,e.__webglColorBuffer);f.vertexAttribPointer(b.color,3,f.FLOAT,false,0,0)}if(b.normal>=0){f.bindBuffer(f.ARRAY_BUFFER,e.__webglNormalBuffer);f.vertexAttribPointer(b.normal,3,f.FLOAT,false,0,0)}if(b.tangent>=0){f.bindBuffer(f.ARRAY_BUFFER,e.__webglTangentBuffer);f.vertexAttribPointer(b.tangent,4,f.FLOAT, +false,0,0)}if(b.uv>=0)if(e.__webglUVBuffer){f.bindBuffer(f.ARRAY_BUFFER,e.__webglUVBuffer);f.vertexAttribPointer(b.uv,2,f.FLOAT,false,0,0);f.enableVertexAttribArray(b.uv)}else f.disableVertexAttribArray(b.uv);if(b.uv2>=0)if(e.__webglUV2Buffer){f.bindBuffer(f.ARRAY_BUFFER,e.__webglUV2Buffer);f.vertexAttribPointer(b.uv2,2,f.FLOAT,false,0,0);f.enableVertexAttribArray(b.uv2)}else f.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){f.bindBuffer(f.ARRAY_BUFFER, +e.__webglSkinVertexABuffer);f.vertexAttribPointer(b.skinVertexA,4,f.FLOAT,false,0,0);f.bindBuffer(f.ARRAY_BUFFER,e.__webglSkinVertexBBuffer);f.vertexAttribPointer(b.skinVertexB,4,f.FLOAT,false,0,0);f.bindBuffer(f.ARRAY_BUFFER,e.__webglSkinIndicesBuffer);f.vertexAttribPointer(b.skinIndex,4,f.FLOAT,false,0,0);f.bindBuffer(f.ARRAY_BUFFER,e.__webglSkinWeightsBuffer);f.vertexAttribPointer(b.skinWeight,4,f.FLOAT,false,0,0)}}if(g instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==tb){f.lineWidth(d); +tb=d}a&&f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer);f.drawElements(f.LINES,e.__webglLineCount,f.UNSIGNED_SHORT,0)}else{a&&f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer);f.drawElements(f.TRIANGLES,e.__webglFaceCount,f.UNSIGNED_SHORT,0)}E.info.render.calls++;E.info.render.vertices=E.info.render.vertices+e.__webglFaceCount;E.info.render.faces=E.info.render.faces+e.__webglFaceCount/3}else if(g instanceof THREE.Line){g=g.type===THREE.LineStrip?f.LINE_STRIP:f.LINES;d=d.linewidth; +if(d!==tb){f.lineWidth(d);tb=d}f.drawArrays(g,0,e.__webglLineCount);E.info.render.calls++}else if(g instanceof THREE.ParticleSystem){f.drawArrays(f.POINTS,0,e.__webglParticleCount);E.info.render.calls++;E.info.render.points=E.info.render.points+e.__webglParticleCount}else if(g instanceof THREE.Ribbon){f.drawArrays(f.TRIANGLE_STRIP,0,e.__webglVertexCount);E.info.render.calls++}}};this.render=function(a,b,c,d){var e,g,l,k,n=a.__lights,p=a.fog;R=-1;nb=true;if(b.parent===void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it..."); +a.add(b)}this.autoUpdateScene&&a.updateMatrixWorld();if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);Ib.multiply(b.projectionMatrix,b.matrixWorldInverse);Kb.setFromMatrix(Ib);this.autoUpdateObjects&&this.initWebGLObjects(a);m(this.renderPluginsPre, +a,b);E.info.render.calls=0;E.info.render.vertices=0;E.info.render.faces=0;E.info.render.points=0;this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);k=a.__webglObjects;d=0;for(e=k.length;d=0){s=q.geometry.materials[s];if(s.transparent){o.transparent=s;o.opaque=null}else{o.opaque=s;o.transparent=null}}}else if(s)if(s.transparent){o.transparent=s;o.opaque=null}else{o.opaque=s;o.transparent=null}g.render=true;if(this.sortObjects)if(l.renderDepth)g.z=l.renderDepth;else{Na.copy(l.matrixWorld.getPosition());Ib.multiplyVector3(Na);g.z=Na.z}}}this.sortObjects&&k.sort(h);k=a.__webglObjectsImmediate;d=0;for(e=k.length;d65535){F[A].counter=F[A].counter+1;D=F[A].hash+"_"+F[A].counter;r.geometryGroups[D]===void 0&&(r.geometryGroups[D]={faces3:[],faces4:[],materialIndex:z,vertices:0,numMorphTargets:I,numMorphNormals:K})}w instanceof THREE.Face3?r.geometryGroups[D].faces3.push(q):r.geometryGroups[D].faces4.push(q); +r.geometryGroups[D].vertices=r.geometryGroups[D].vertices+C}r.geometryGroupsList=[];var L=void 0;for(L in r.geometryGroups){r.geometryGroups[L].id=Ea++;r.geometryGroupsList.push(r.geometryGroups[L])}}for(j in k.geometryGroups){m=k.geometryGroups[j];if(!m.__webglVertexBuffer){var H=m;H.__webglVertexBuffer=f.createBuffer();H.__webglNormalBuffer=f.createBuffer();H.__webglTangentBuffer=f.createBuffer();H.__webglColorBuffer=f.createBuffer();H.__webglUVBuffer=f.createBuffer();H.__webglUV2Buffer=f.createBuffer(); +H.__webglSkinVertexABuffer=f.createBuffer();H.__webglSkinVertexBBuffer=f.createBuffer();H.__webglSkinIndicesBuffer=f.createBuffer();H.__webglSkinWeightsBuffer=f.createBuffer();H.__webglFaceBuffer=f.createBuffer();H.__webglLineBuffer=f.createBuffer();var P=void 0,Q=void 0;if(H.numMorphTargets){H.__webglMorphTargetsBuffers=[];P=0;for(Q=H.numMorphTargets;P0||S.faceVertexUvs.length>0)G.__uvArray=new Float32Array(R*2);if(S.faceUvs.length>1||S.faceVertexUvs.length> +1)G.__uv2Array=new Float32Array(R*2)}if(U.geometry.skinWeights.length&&U.geometry.skinIndices.length){G.__skinVertexAArray=new Float32Array(R*4);G.__skinVertexBArray=new Float32Array(R*4);G.__skinIndexArray=new Float32Array(R*4);G.__skinWeightArray=new Float32Array(R*4)}G.__faceArray=new Uint16Array(fa*3);G.__lineArray=new Uint16Array(ga*2);var Aa=void 0,Fa=void 0;if(G.numMorphTargets){G.__morphTargetsArrays=[];Aa=0;for(Fa=G.numMorphTargets;Aa0){f.bindBuffer(f.ARRAY_BUFFER,V.__webglSkinVertexABuffer);f.bufferData(f.ARRAY_BUFFER,ja,Ja);f.bindBuffer(f.ARRAY_BUFFER,V.__webglSkinVertexBBuffer); +f.bufferData(f.ARRAY_BUFFER,ka,Ja);f.bindBuffer(f.ARRAY_BUFFER,V.__webglSkinIndicesBuffer);f.bufferData(f.ARRAY_BUFFER,la,Ja);f.bindBuffer(f.ARRAY_BUFFER,V.__webglSkinWeightsBuffer);f.bufferData(f.ARRAY_BUFFER,ma,Ja)}}if(cd&&Lc){x=0;for(J=ba.length;x0){f.bindBuffer(f.ARRAY_BUFFER,V.__webglColorBuffer);f.bufferData(f.ARRAY_BUFFER,wa,Ja)}}if(bd&&Ca.hasTangents){x=0;for(J=ba.length;x< +J;x++){B=qa[ba[x]];ob=B.vertexTangents;Ya=ob[0];Za=ob[1];$a=ob[2];ia[ea]=Ya.x;ia[ea+1]=Ya.y;ia[ea+2]=Ya.z;ia[ea+3]=Ya.w;ia[ea+4]=Za.x;ia[ea+5]=Za.y;ia[ea+6]=Za.z;ia[ea+7]=Za.w;ia[ea+8]=$a.x;ia[ea+9]=$a.y;ia[ea+10]=$a.z;ia[ea+11]=$a.w;ea=ea+12}x=0;for(J=ca.length;x0){f.bindBuffer(f.ARRAY_BUFFER,V.__webglUVBuffer);f.bufferData(f.ARRAY_BUFFER,kc,Ja)}}if(Uc&&Qc&&ac){x=0;for(J=ba.length;x0){f.bindBuffer(f.ARRAY_BUFFER,V.__webglUV2Buffer);f.bufferData(f.ARRAY_BUFFER,lc,Ja)}}if(Jc){x= +0;for(J=ba.length;x0?"#define VERTEX_TEXTURES":"",E.gammaInput?"#define GAMMA_INPUT":"",E.gammaOutput?"#define GAMMA_OUTPUT":"",E.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING": +"","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING":"",c.morphTargets?"#define USE_MORPHTARGETS":"",c.morphNormals?"#define USE_MORPHNORMALS":"",c.perPixel?"#define PHONG_PER_PIXEL":"", +c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\n#ifdef USE_MORPHNORMALS\nattribute vec3 morphNormal0;\nattribute vec3 morphNormal1;\nattribute vec3 morphNormal2;\nattribute vec3 morphNormal3;\n#else\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n"); +k=["precision "+I+" float;","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",E.gammaInput?"#define GAMMA_INPUT":"",E.gammaOutput?"#define GAMMA_OUTPUT":"",E.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP": "",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.metal?"#define METAL":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n"); -e.attachShader(s,q("fragment",k+n));e.attachShader(s,q("vertex",d+j));e.linkProgram(s);e.getProgramParameter(s,e.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+e.getProgramParameter(s,e.VALIDATE_STATUS)+", gl error ["+e.getError()+"]");s.uniforms={};s.attributes={};var u,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","boneGlobalMatrices","morphTargetInfluences"];for(u in i)d.push(u);u=d;d=0;for(i=u.length;d=0&&e.enableVertexAttribArray(p.position); -p.color>=0&&e.enableVertexAttribArray(p.color);p.normal>=0&&e.enableVertexAttribArray(p.normal);p.tangent>=0&&e.enableVertexAttribArray(p.tangent);if(a.skinning&&p.skinVertexA>=0&&p.skinVertexB>=0&&p.skinIndex>=0&&p.skinWeight>=0){e.enableVertexAttribArray(p.skinVertexA);e.enableVertexAttribArray(p.skinVertexB);e.enableVertexAttribArray(p.skinIndex);e.enableVertexAttribArray(p.skinWeight)}if(a.attributes)for(g in a.attributes)p[g]!==void 0&&p[g]>=0&&e.enableVertexAttribArray(p[g]);if(a.morphTargets){a.numSupportedMorphTargets= -0;s="morphTarget";for(g=0;g=0){e.enableVertexAttribArray(p[u]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;s="morphNormal";for(g=0;g=0){e.enableVertexAttribArray(p[u]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(f in a.uniforms)a.uniformsList.push([a.uniforms[f],f])};this.setFaceCulling=function(a,b){if(a){!b||b==="ccw"?e.frontFace(e.CCW):e.frontFace(e.CW);a==="back"?e.cullFace(e.BACK): -a==="front"?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK);e.enable(e.CULL_FACE)}else e.disable(e.CULL_FACE)};this.setObjectFaces=function(a){if(ra!==a.doubleSided){a.doubleSided?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE);ra=a.doubleSided}if(L!==a.flipSided){a.flipSided?e.frontFace(e.CW):e.frontFace(e.CCW);L=a.flipSided}};this.setDepthTest=function(a){if(Oa!==a){a?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST);Oa=a}};this.setDepthWrite=function(a){if(Fa!==a){e.depthMask(a);Fa=a}};this.setBlending= -function(a,b,c,d){if(a!==Aa){switch(a){case THREE.NoBlending:e.disable(e.BLEND);break;case THREE.AdditiveBlending:e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.SRC_ALPHA,e.ONE);break;case THREE.SubtractiveBlending:e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.ZERO,e.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:e.enable(e.BLEND);e.blendEquation(e.FUNC_ADD);e.blendFunc(e.ZERO,e.SRC_COLOR);break;case THREE.CustomBlending:e.enable(e.BLEND);break;default:e.enable(e.BLEND); -e.blendEquationSeparate(e.FUNC_ADD,e.FUNC_ADD);e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}Aa=a}if(a===THREE.CustomBlending){if(b!==Ca){e.blendEquation(J(b));Ca=b}if(c!==Na||d!==Ua){e.blendFunc(J(c),J(d));Na=c;Ua=d}}else Ua=Na=Ca=null};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit){a.__webglInit=true;a.__webglTexture=e.createTexture();E.info.memory.textures++}e.activeTexture(e.TEXTURE0+b);e.bindTexture(e.TEXTURE_2D,a.__webglTexture);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, -a.premultiplyAlpha);var c=a.image,d=(c.width&c.width-1)===0&&(c.height&c.height-1)===0,f=J(a.format),g=J(a.type);I(e.TEXTURE_2D,a,d);a instanceof THREE.DataTexture?e.texImage2D(e.TEXTURE_2D,0,f,c.width,c.height,0,f,g,c.data):e.texImage2D(e.TEXTURE_2D,0,f,f,g,a.image);a.generateMipmaps&&d&&e.generateMipmap(e.TEXTURE_2D);a.needsUpdate=false;if(a.onUpdate)a.onUpdate()}else{e.activeTexture(e.TEXTURE0+b);e.bindTexture(e.TEXTURE_2D,a.__webglTexture)}};this.setRenderTarget=function(a){var b=a instanceof -THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=true;if(a.stencilBuffer===void 0)a.stencilBuffer=true;a.__webglTexture=e.createTexture();var c=(a.width&a.width-1)===0&&(a.height&a.height-1)===0,d=J(a.format),f=J(a.type);if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];e.bindTexture(e.TEXTURE_CUBE_MAP,a.__webglTexture);I(e.TEXTURE_CUBE_MAP,a,c);for(var g=0;g<6;g++){a.__webglFramebuffer[g]=e.createFramebuffer();a.__webglRenderbuffer[g]=e.createRenderbuffer(); -e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,d,a.width,a.height,0,d,f,null);var h=a,i=e.TEXTURE_CUBE_MAP_POSITIVE_X+g;e.bindFramebuffer(e.FRAMEBUFFER,a.__webglFramebuffer[g]);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,i,h.__webglTexture,0);B(a.__webglRenderbuffer[g],a)}c&&e.generateMipmap(e.TEXTURE_CUBE_MAP)}else{a.__webglFramebuffer=e.createFramebuffer();a.__webglRenderbuffer=e.createRenderbuffer();e.bindTexture(e.TEXTURE_2D,a.__webglTexture);I(e.TEXTURE_2D,a,c);e.texImage2D(e.TEXTURE_2D, -0,d,a.width,a.height,0,d,f,null);d=e.TEXTURE_2D;e.bindFramebuffer(e.FRAMEBUFFER,a.__webglFramebuffer);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,d,a.__webglTexture,0);B(a.__webglRenderbuffer,a);c&&e.generateMipmap(e.TEXTURE_2D)}b?e.bindTexture(e.TEXTURE_CUBE_MAP,null):e.bindTexture(e.TEXTURE_2D,null);e.bindRenderbuffer(e.RENDERBUFFER,null);e.bindFramebuffer(e.FRAMEBUFFER,null)}if(a){b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer;c=a.width;a=a.height;f=d=0}else{b=null; -c=Hb;a=ac;d=Ob;f=Yb}if(b!==D){e.bindFramebuffer(e.FRAMEBUFFER,b);e.viewport(d,f,c,a);D=b}sc=c;Zb=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)}; +f.attachShader(q,D("fragment",k+n));f.attachShader(q,D("vertex",d+j));f.linkProgram(q);f.getProgramParameter(q,f.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+f.getProgramParameter(q,f.VALIDATE_STATUS)+", gl error ["+f.getError()+"]");q.uniforms={};q.attributes={};var s,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","boneGlobalMatrices","morphTargetInfluences"];for(s in i)d.push(s);s=d;d=0;for(i=s.length;d=0&&f.enableVertexAttribArray(o.position); +o.color>=0&&f.enableVertexAttribArray(o.color);o.normal>=0&&f.enableVertexAttribArray(o.normal);o.tangent>=0&&f.enableVertexAttribArray(o.tangent);if(a.skinning&&o.skinVertexA>=0&&o.skinVertexB>=0&&o.skinIndex>=0&&o.skinWeight>=0){f.enableVertexAttribArray(o.skinVertexA);f.enableVertexAttribArray(o.skinVertexB);f.enableVertexAttribArray(o.skinIndex);f.enableVertexAttribArray(o.skinWeight)}if(a.attributes)for(g in a.attributes)o[g]!==void 0&&o[g]>=0&&f.enableVertexAttribArray(o[g]);if(a.morphTargets){a.numSupportedMorphTargets= +0;q="morphTarget";for(g=0;g=0){f.enableVertexAttribArray(o[s]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;q="morphNormal";for(g=0;g=0){f.enableVertexAttribArray(o[s]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(e in a.uniforms)a.uniformsList.push([a.uniforms[e],e])};this.setFaceCulling=function(a,b){if(a){!b||b==="ccw"?f.frontFace(f.CCW):f.frontFace(f.CW);a==="back"?f.cullFace(f.BACK): +a==="front"?f.cullFace(f.FRONT):f.cullFace(f.FRONT_AND_BACK);f.enable(f.CULL_FACE)}else f.disable(f.CULL_FACE)};this.setObjectFaces=function(a){if(S!==a.doubleSided){a.doubleSided?f.disable(f.CULL_FACE):f.enable(f.CULL_FACE);S=a.doubleSided}if(za!==a.flipSided){a.flipSided?f.frontFace(f.CW):f.frontFace(f.CCW);za=a.flipSided}};this.setDepthTest=function(a){if(Fa!==a){a?f.enable(f.DEPTH_TEST):f.disable(f.DEPTH_TEST);Fa=a}};this.setDepthWrite=function(a){if(Xa!==a){f.depthMask(a);Xa=a}};this.setBlending= +function(a,b,c,d){if(a!==Ia){switch(a){case THREE.NoBlending:f.disable(f.BLEND);break;case THREE.AdditiveBlending:f.enable(f.BLEND);f.blendEquation(f.FUNC_ADD);f.blendFunc(f.SRC_ALPHA,f.ONE);break;case THREE.SubtractiveBlending:f.enable(f.BLEND);f.blendEquation(f.FUNC_ADD);f.blendFunc(f.ZERO,f.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:f.enable(f.BLEND);f.blendEquation(f.FUNC_ADD);f.blendFunc(f.ZERO,f.SRC_COLOR);break;case THREE.CustomBlending:f.enable(f.BLEND);break;default:f.enable(f.BLEND); +f.blendEquationSeparate(f.FUNC_ADD,f.FUNC_ADD);f.blendFuncSeparate(f.SRC_ALPHA,f.ONE_MINUS_SRC_ALPHA,f.ONE,f.ONE_MINUS_SRC_ALPHA)}Ia=a}if(a===THREE.CustomBlending){if(b!==Ra){f.blendEquation(A(b));Ra=b}if(c!==Sa||d!==Ua){f.blendFunc(A(c),A(d));Sa=c;Ua=d}}else Ua=Sa=Ra=null};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit){a.__webglInit=true;a.__webglTexture=f.createTexture();E.info.memory.textures++}f.activeTexture(f.TEXTURE0+b);f.bindTexture(f.TEXTURE_2D,a.__webglTexture);f.pixelStorei(f.UNPACK_PREMULTIPLY_ALPHA_WEBGL, +a.premultiplyAlpha);var c=a.image,d=(c.width&c.width-1)===0&&(c.height&c.height-1)===0,e=A(a.format),g=A(a.type);C(f.TEXTURE_2D,a,d);a instanceof THREE.DataTexture?f.texImage2D(f.TEXTURE_2D,0,e,c.width,c.height,0,e,g,c.data):f.texImage2D(f.TEXTURE_2D,0,e,e,g,a.image);a.generateMipmaps&&d&&f.generateMipmap(f.TEXTURE_2D);a.needsUpdate=false;if(a.onUpdate)a.onUpdate()}else{f.activeTexture(f.TEXTURE0+b);f.bindTexture(f.TEXTURE_2D,a.__webglTexture)}};this.setRenderTarget=function(a){var b=a instanceof +THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=true;if(a.stencilBuffer===void 0)a.stencilBuffer=true;a.__webglTexture=f.createTexture();var c=(a.width&a.width-1)===0&&(a.height&a.height-1)===0,d=A(a.format),e=A(a.type);if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];f.bindTexture(f.TEXTURE_CUBE_MAP,a.__webglTexture);C(f.TEXTURE_CUBE_MAP,a,c);for(var g=0;g<6;g++){a.__webglFramebuffer[g]=f.createFramebuffer();a.__webglRenderbuffer[g]=f.createRenderbuffer(); +f.texImage2D(f.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,d,a.width,a.height,0,d,e,null);var h=a,i=f.TEXTURE_CUBE_MAP_POSITIVE_X+g;f.bindFramebuffer(f.FRAMEBUFFER,a.__webglFramebuffer[g]);f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,i,h.__webglTexture,0);s(a.__webglRenderbuffer[g],a)}c&&f.generateMipmap(f.TEXTURE_CUBE_MAP)}else{a.__webglFramebuffer=f.createFramebuffer();a.__webglRenderbuffer=f.createRenderbuffer();f.bindTexture(f.TEXTURE_2D,a.__webglTexture);C(f.TEXTURE_2D,a,c);f.texImage2D(f.TEXTURE_2D, +0,d,a.width,a.height,0,d,e,null);d=f.TEXTURE_2D;f.bindFramebuffer(f.FRAMEBUFFER,a.__webglFramebuffer);f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,d,a.__webglTexture,0);s(a.__webglRenderbuffer,a);c&&f.generateMipmap(f.TEXTURE_2D)}b?f.bindTexture(f.TEXTURE_CUBE_MAP,null):f.bindTexture(f.TEXTURE_2D,null);f.bindRenderbuffer(f.RENDERBUFFER,null);f.bindFramebuffer(f.FRAMEBUFFER,null)}if(a){b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer;c=a.width;a=a.height;e=d=0}else{b=null; +c=bc;a=Jb;d=Zb;e=Hb}if(b!==Da){f.bindFramebuffer(f.FRAMEBUFFER,b);f.viewport(d,e,c,a);Da=b}tc=c;$b=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)}; THREE.WebGLRenderTarget=function(a,b,c){this.width=a;this.height=b;c=c||{};this.wrapS=c.wrapS!==void 0?c.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=c.wrapT!==void 0?c.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=c.magFilter!==void 0?c.magFilter:THREE.LinearFilter;this.minFilter=c.minFilter!==void 0?c.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=c.format!==void 0?c.format:THREE.RGBAFormat;this.type=c.type!==void 0?c.type: THREE.UnsignedByteType;this.depthBuffer=c.depthBuffer!==void 0?c.depthBuffer:true;this.stencilBuffer=c.stencilBuffer!==void 0?c.stencilBuffer:true;this.generateMipmaps=true}; THREE.WebGLRenderTarget.prototype.clone=function(){var a=new THREE.WebGLRenderTarget(this.width,this.height);a.wrapS=this.wrapS;a.wrapT=this.wrapT;a.magFilter=this.magFilter;a.minFilter=this.minFilter;a.offset.copy(this.offset);a.repeat.copy(this.repeat);a.format=this.format;a.type=this.type;a.depthBuffer=this.depthBuffer;a.stencilBuffer=this.stencilBuffer;return a};THREE.WebGLRenderTargetCube=function(a,b,c){THREE.WebGLRenderTarget.call(this,a,b,c);this.activeCubeFace=0}; @@ -388,39 +388,39 @@ this.matrixWorldNeedsUpdate=false;a=true}for(var b=0,c=this.children.length;b0&&P.x0&& -P.y0.001&&H.scale>0.001){F.x=H.x;F.y=H.y;F.z=H.z;C=H.size*H.scale/w;G.x=C*B;G.y=C;b.uniform3f(Q.screenPosition,F.x,F.y,F.z);b.uniform2f(Q.scale,G.x,G.y);b.uniform1f(Q.rotation,H.rotation);b.uniform1f(Q.opacity,H.opacity); -b.uniform3f(Q.color,H.color.r,H.color.g,H.color.b);c.setBlending(H.blending,H.blendEquation,H.blendSrc,H.blendDst);c.setTexture(H.texture,1);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}}; -THREE.ShadowMapPlugin=function(){var a,b,c,d,f=new THREE.Frustum,g=new THREE.Matrix4,h=new THREE.Vector3,l=new THREE.Vector3;this.init=function(f){a=f.context;b=f;var f=THREE.ShaderLib.depthRGBA,g=THREE.UniformsUtils.clone(f.uniforms);c=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g});d=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render= -function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(m,j){var i,o,k,u,r,n,p,w,q,I=[];u=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);b.shadowMapCullFrontFaces?a.cullFace(a.FRONT):a.cullFace(a.BACK);b.setDepthTest(true);i=0;for(o=m.__lights.length;il.x)l.x=w.x;if(w.yl.y)l.y=w.y;if(w.zl.z)l.z=w.z}u.left=h.x;u.right=l.x;u.top=l.y;u.bottom=h.y;u.updateProjectionMatrix()}u=k.shadowMap;n=k.shadowMatrix;r=k.shadowCamera;r.position.copy(k.matrixWorld.getPosition());r.lookAt(k.target.matrixWorld.getPosition());r.updateMatrixWorld();r.matrixWorldInverse.getInverse(r.matrixWorld); -if(k.cameraHelper)k.cameraHelper.lines.visible=k.shadowCameraVisible;k.shadowCameraVisible&&k.cameraHelper.update();n.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);n.multiplySelf(r.projectionMatrix);n.multiplySelf(r.matrixWorldInverse);if(!r._viewMatrixArray)r._viewMatrixArray=new Float32Array(16);if(!r._projectionMatrixArray)r._projectionMatrixArray=new Float32Array(16);r.matrixWorldInverse.flattenToArray(r._viewMatrixArray);r.projectionMatrix.flattenToArray(r._projectionMatrixArray);g.multiply(r.projectionMatrix, -r.matrixWorldInverse);f.setFromMatrix(g);b.setRenderTarget(u);b.clear();q=m.__webglObjects;k=0;for(u=q.length;k0&&H.x0&& +H.y0.0010&&K.scale>0.0010){I.x=K.x;I.y=K.y;I.z=K.z;A=K.size*K.scale/w;G.x=A*C;G.y=A;b.uniform3f(P.screenPosition,I.x,I.y,I.z);b.uniform2f(P.scale,G.x,G.y);b.uniform1f(P.rotation,K.rotation);b.uniform1f(P.opacity,K.opacity); +b.uniform3f(P.color,K.color.r,K.color.g,K.color.b);c.setBlending(K.blending,K.blendEquation,K.blendSrc,K.blendDst);c.setTexture(K.texture,1);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}}; +THREE.ShadowMapPlugin=function(){var a,b,c,d,e=new THREE.Frustum,g=new THREE.Matrix4,h=new THREE.Vector3,k=new THREE.Vector3;this.init=function(e){a=e.context;b=e;var e=THREE.ShaderLib.depthRGBA,g=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:g});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:g,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render= +function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(m,j){var i,p,l,v,o,n,q,w,r,D=[];v=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);b.shadowMapCullFrontFaces?a.cullFace(a.FRONT):a.cullFace(a.BACK);b.setDepthTest(true);i=0;for(p=m.__lights.length;ik.x)k.x=w.x;if(w.yk.y)k.y=w.y;if(w.zk.z)k.z=w.z}v.left=h.x;v.right=k.x;v.top=k.y;v.bottom=h.y;v.updateProjectionMatrix()}v=l.shadowMap;n=l.shadowMatrix;o=l.shadowCamera;o.position.copy(l.matrixWorld.getPosition());o.lookAt(l.target.matrixWorld.getPosition());o.updateMatrixWorld();o.matrixWorldInverse.getInverse(o.matrixWorld); +if(l.cameraHelper)l.cameraHelper.lines.visible=l.shadowCameraVisible;l.shadowCameraVisible&&l.cameraHelper.update();n.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);n.multiplySelf(o.projectionMatrix);n.multiplySelf(o.matrixWorldInverse);if(!o._viewMatrixArray)o._viewMatrixArray=new Float32Array(16);if(!o._projectionMatrixArray)o._projectionMatrixArray=new Float32Array(16);o.matrixWorldInverse.flattenToArray(o._viewMatrixArray);o.projectionMatrix.flattenToArray(o._projectionMatrixArray);g.multiply(o.projectionMatrix, +o.matrixWorldInverse);e.setFromMatrix(g);b.setRenderTarget(v);b.clear();r=m.__webglObjects;l=0;for(v=r.length;l 0 ) { + + activeInfluenceIndices.push( i ); - } - - var gonnaUse = []; - - for ( i = 0; i < il; i ++ ) { - candidateInfluence = influences[ i ] - if ( candidateInfluence > 0 ) { - gonnaUse.push(i); } + } - - if ( gonnaUse.length > material.numSupportedMorphTargets){ - gonnaUse.sort(sortNumerical); - gonnaUse.length = material.numSupportedMorphTargets - } else if (gonnaUse.length > material.numSupportedMorphNormals){ - gonnaUse.sort(sortNumerical); - } else if (gonnaUse.length === 0){ - gonnaUse.push(0); - }; + + if ( activeInfluenceIndices.length > material.numSupportedMorphTargets ) { + + activeInfluenceIndices.sort( numericalSort ); + activeInfluenceIndices.length = material.numSupportedMorphTargets; + + } else if ( activeInfluenceIndices.length > material.numSupportedMorphNormals ) { + + activeInfluenceIndices.sort( numericalSort ); + + } else if ( activeInfluenceIndices.length === 0 ) { + + activeInfluenceIndices.push( 0 ); + + }; + + var influenceIndex, m = 0; while ( m < material.numSupportedMorphTargets ) { - /* for ( i = 0; i < il; i ++ ) { + influenceIndex = activeInfluenceIndices[ m ]; + + if ( influenceIndex !== undefined || m === 0 ) { + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ influenceIndex ] ); + + _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 ); - if ( !used[ i ] && influences[ i ] > candidateInfluence ) { + if ( material.morphNormals ) { + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ influenceIndex ] ); + _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 ); + + } + + object.__webglMorphTargetInfluences[ m ] = influences[ influenceIndex ]; + + } else { + + _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 ); - candidate = i; - candidateInfluence = influences[ candidate ]; + if ( material.morphNormals ) { + _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 ); } + object.__webglMorphTargetInfluences[ m ] = 0; + } -*/ - - if (gonnaUse[m] !== undefined || m === 0){ - _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ gonnaUse[m] ] ); - _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 ); - - if ( material.morphNormals ) { - - _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ gonnaUse[m] ] ); - _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 ); - - } - - object.__webglMorphTargetInfluences[ m ] = influences[ gonnaUse[m]]; - } else { - _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 ); - if ( material.morphNormals ) { - _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 ); - } - object.__webglMorphTargetInfluences[ m ] = 0; - } - //used[ candidate ] = 1; - //candidateInfluence = -1; + m ++; } @@ -3321,6 +3318,7 @@ THREE.WebGLRenderer = function ( parameters ) { }; + // Sorting function painterSort ( a, b ) { @@ -3328,6 +3326,13 @@ THREE.WebGLRenderer = function ( parameters ) { }; + function numericalSort( a, b ) { + + return a - b; + + }; + + // Rendering this.render = function ( scene, camera, renderTarget, forceClear ) { -- GitLab