Browse Source

Merge remote-tracking branch 'alteredq/master'

zz85 14 years ago
parent
commit
01dac8249b
55 changed files with 5265 additions and 1540 deletions
  1. 154 151
      build/Three.js
  2. 79 75
      build/custom/ThreeCanvas.js
  3. 46 44
      build/custom/ThreeDOM.js
  4. 9 10
      build/custom/ThreeExtras.js
  5. 65 62
      build/custom/ThreeSVG.js
  6. 127 124
      build/custom/ThreeWebGL.js
  7. 1 1
      examples/canvas_sandbox.html
  8. 1 1
      examples/misc_sound.html
  9. 1 1
      examples/misc_ubiquity_test.html
  10. 12 14
      examples/webgl_collisions_box.html
  11. 13 21
      examples/webgl_collisions_mesh.html
  12. 13 23
      examples/webgl_collisions_normal.html
  13. 22 18
      examples/webgl_collisions_primitives.html
  14. 1 1
      examples/webgl_collisions_reaction.html
  15. 6 9
      examples/webgl_collisions_terrain.html
  16. 3 6
      examples/webgl_collisions_trigger.html
  17. 198 0
      examples/webgl_custom_attributes.html
  18. 58 66
      examples/webgl_flycamera_earth.html
  19. 1 1
      examples/webgl_geometry_dynamic.html
  20. 1 1
      examples/webgl_geometry_minecraft.html
  21. 1 1
      examples/webgl_geometry_minecraft_ao.html
  22. 1 1
      examples/webgl_geometry_terrain.html
  23. 1 1
      examples/webgl_geometry_terrain_fog.html
  24. 4 13
      examples/webgl_materials_normalmap.html
  25. 3 11
      examples/webgl_materials_normalmap2.html
  26. 1 1
      examples/webgl_objconvert_test.html
  27. 1 9
      examples/webgl_postprocessing.html
  28. 2 11
      examples/webgl_postprocessing_dof.html
  29. 1 1
      examples/webgl_sandbox.html
  30. 0 2
      examples/webgl_sprites.html
  31. 11 15
      examples/webgl_trackballcamera_earth.html
  32. 98 34
      src/core/Matrix4.js
  33. 4 1
      src/core/Object3D.js
  34. 6 5
      src/core/Ray.js
  35. 116 61
      src/extras/ShaderUtils.js
  36. 328 0
      src/extras/cameras/FirstPersonCamera.js
  37. 4 325
      src/extras/cameras/QuakeCamera.js
  38. 49 52
      src/extras/geometries/TextGeometry.js
  39. 2 0
      src/extras/io/BinaryLoader.js
  40. 5 3
      src/extras/io/JSONLoader.js
  41. 167 27
      src/extras/io/Loader.js
  42. 111 18
      src/extras/io/SceneLoader.js
  43. 63 12
      src/extras/renderers/AnaglyphWebGLRenderer.js
  44. 3 0
      src/materials/Material.js
  45. 1 0
      src/objects/Sprite.js
  46. 309 142
      src/renderers/WebGLRenderer.js
  47. 99 82
      src/renderers/WebGLShaders.js
  48. 2 0
      src/scenes/Scene.js
  49. 1 1
      utils/build.bat
  50. 2 1
      utils/build.py
  51. 17 3
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/__init__.py
  52. 239 78
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/export_threejs.py
  53. 390 0
      utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/__init__.py
  54. 1781 0
      utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py
  55. 631 0
      utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/import_threejs.py

File diff suppressed because it is too large
+ 154 - 151
build/Three.js


+ 79 - 75
build/custom/ThreeCanvas.js

@@ -1,6 +1,6 @@
 // ThreeCanvas.js r41/ROME - http://github.com/mrdoob/three.js
 var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){this.setHex(a)};
-THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,j;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),j=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=j;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=j;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=j;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
+THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,i;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),i=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=i;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=i;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=i;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
 e,g)},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGB:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},clone:function(){return new THREE.Color(this.hex)}};THREE.Vector2=function(a,b){this.set(a||0,b||0)};
 THREE.Vector2.prototype={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},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;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-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},divideScalar:function(a){a?
 (this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.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(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
@@ -13,55 +13,57 @@ THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
 THREE.Vector4.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},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+=a.x;this.y+=a.y;this.z+=a.z;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-=
 a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,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+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}};THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d;d=c.position.clone().subSelf(a).dot(b);if(d<0)return!1;a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.position.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
-e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,j,k,m,p,l,n,i=a.geometry,
-q=i.vertices,v=[],d=0;for(e=i.faces.length;d<e;d++)if(g=i.faces[d],l=this.origin.clone(),n=this.direction.clone(),k=a.matrixWorld,f=k.multiplyVector3(q[g.a].position.clone()),h=k.multiplyVector3(q[g.b].position.clone()),j=k.multiplyVector3(q[g.c].position.clone()),k=g instanceof THREE.Face4?k.multiplyVector3(q[g.d].position.clone()):null,m=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),p=n.dot(m),a.doubleSided||(a.flipSided?p>0:p<0))if(m=m.dot((new THREE.Vector3).sub(f,l))/p,l=l.addSelf(n.multiplyScalar(m)),
-g instanceof THREE.Face3)c(l,f,h,j)&&(g={distance:this.origin.distanceTo(l),point:l,face:g,object:a},v.push(g));else if(g instanceof THREE.Face4&&(c(l,f,h,k)||c(l,h,j,k)))g={distance:this.origin.distanceTo(l),point:l,face:g,object:a},v.push(g);return v}else return[]}};
-THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,m,p){h=!1;b=f;c=g;d=m;e=p;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
-function(f,g,m,p,l,n){h?(h=!1,b=f<m?f<l?f:l:m<l?m:l,c=g<p?g<n?g:n:p<n?p:n,d=f>m?f>l?f:l:m>l?m:l,e=g>p?g>n?g:n:p>n?p:n):(b=f<m?f<l?f<b?f:b:l<b?l:b:m<l?m<b?m:b:l<b?l:b,c=g<p?g<n?g<c?g:c:n<c?n:c:p<n?p<c?p:c:n<c?n:c,d=f>m?f>l?f>d?f:d:l>d?l:d:m>l?m>d?m:d:l>d?l:d,e=g>p?g>n?g>e?g:e:n>e?n:e:p>n?p>e?p:e:n>e?n:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
+THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
+e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,i,l,m,j,n,o,k=a.geometry,
+q=k.vertices,v=[],d=0;for(e=k.faces.length;d<e;d++)if(g=k.faces[d],n=this.origin.clone(),o=this.direction.clone(),l=a.matrixWorld,f=l.multiplyVector3(q[g.a].position.clone()),h=l.multiplyVector3(q[g.b].position.clone()),i=l.multiplyVector3(q[g.c].position.clone()),l=g instanceof THREE.Face4?l.multiplyVector3(q[g.d].position.clone()):null,m=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),j=o.dot(m),a.doubleSided||(a.flipSided?j>0:j<0))if(m=m.dot((new THREE.Vector3).sub(f,n))/j,n=n.addSelf(o.multiplyScalar(m)),
+g instanceof THREE.Face3)c(n,f,h,i)&&(g={distance:this.origin.distanceTo(n),point:n,face:g,object:a},v.push(g));else if(g instanceof THREE.Face4&&(c(n,f,h,l)||c(n,h,i,l)))g={distance:this.origin.distanceTo(n),point:n,face:g,object:a},v.push(g);return v}else return[]}};
+THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,m,j){h=!1;b=f;c=g;d=m;e=j;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
+function(f,g,m,j,n,o){h?(h=!1,b=f<m?f<n?f:n:m<n?m:n,c=g<j?g<o?g:o:j<o?j:o,d=f>m?f>n?f:n:m>n?m:n,e=g>j?g>o?g:o:j>o?j:o):(b=f<m?f<n?f<b?f:b:n<b?n:b:m<n?m<b?m:b:n<b?n:b,c=g<j?g<o?g<c?g:c:o<c?o:c:j<o?j<c?j:c:o<c?o:c,d=f>m?f>n?f>d?f:d:n>d?n:d:m>n?m>d?m:d:n>d?n:d,e=g>j?g>o?g>e?g:e:o>e?o:e:j>o?j>e?j:e:o>e?o:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
 f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.instersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};THREE.Matrix3=function(){this.m=[]};
-THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;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,f,h,j,k,m,p,l,n,i,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,j||0,k||0,m||1,p||0,l||0,n||0,i||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
-THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,j,k,m,p,l,n,i,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=j;this.n32=k;this.n33=m;this.n34=p;this.n41=l;this.n42=n;this.n43=i;this.n44=q;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){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
+THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;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,f,h,i,l,m,j,n,o,k,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,i||0,l||0,m||1,j||0,n||0,o||0,k||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
+THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,i,l,m,j,n,o,k,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=i;this.n32=l;this.n33=m;this.n34=j;this.n41=n;this.n42=o;this.n43=k;this.n44=q;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){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
 e=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());e.cross(g,d).normalize();this.n11=d.x;this.n12=e.x;this.n13=g.x;this.n21=d.y;this.n22=e.y;this.n23=g.y;this.n31=d.z;this.n32=e.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,e=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*e;a.y=(this.n21*b+this.n22*c+this.n23*
 d+this.n24)*e;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*e;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,e=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*e;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*e;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*e;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*e;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+c*this.n32+d*this.n33;a.normalize();
-return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,k=a.n24,m=a.n31,p=a.n32,l=a.n33,n=a.n34,i=a.n41,q=a.n42,v=a.n43,t=a.n44,G=b.n11,K=b.n12,x=b.n13,B=b.n14,o=b.n21,M=b.n22,
-r=b.n23,u=b.n24,y=b.n31,Q=b.n32,$=b.n33,Z=b.n34;this.n11=c*G+d*o+e*y;this.n12=c*K+d*M+e*Q;this.n13=c*x+d*r+e*$;this.n14=c*B+d*u+e*Z+g;this.n21=f*G+h*o+j*y;this.n22=f*K+h*M+j*Q;this.n23=f*x+h*r+j*$;this.n24=f*B+h*u+j*Z+k;this.n31=m*G+p*o+l*y;this.n32=m*K+p*M+l*Q;this.n33=m*x+p*r+l*$;this.n34=m*B+p*u+l*Z+n;this.n41=i*G+q*o+v*y;this.n42=i*K+q*M+v*Q;this.n43=i*x+q*r+v*$;this.n44=i*B+q*u+v*Z+t;return this},multiplyToArray:function(a,b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=
-this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=
-this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,j=this.n31,k=this.n32,m=this.n33,p=this.n34,l=this.n41,n=this.n42,i=this.n43,q=this.n44;return d*f*k*l-c*h*k*l-d*g*m*l+b*h*m*l+c*g*p*l-b*f*p*l-d*f*j*n+c*h*j*n+d*e*m*n-a*h*m*n-c*e*p*n+a*f*p*n+d*g*j*i-b*h*j*i-d*e*k*i+a*h*k*i+b*e*p*i-a*g*p*i-c*g*j*q+b*f*j*q+c*e*k*q-a*f*k*q-b*e*m*q+a*g*m*q},transpose:function(){var a;a=this.n21;this.n21=this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=
-this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;
-this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=
-this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,
-b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX: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},setRotationY: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},setRotationZ: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},setRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,j=e*g,k=e*f;this.set(j*
-g+c,j*f-d*h,j*h+d*f,0,j*f+d*h,k*f+c,k*h-d*g,0,j*h-d*f,k*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;
-this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a){var b=a.x,c=a.y,d=a.z,a=Math.cos(b),b=Math.sin(b),e=Math.cos(c),c=Math.sin(c),g=Math.cos(d),d=Math.sin(d),f=a*c,h=b*c;this.n11=e*g;this.n12=-e*d;this.n13=c;this.n21=h*g+a*d;this.n22=-h*d+a*g;this.n23=-b*e;this.n31=-f*g+b*d;this.n32=f*d+b*g;this.n33=a*e;return this},
-setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,f=c+c,h=d+d,a=b*g,j=b*f;b*=h;var k=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(k+d);this.n12=j-e;this.n13=b+f;this.n21=j+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+k);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=
-a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
-THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,k=a.n24,m=a.n31,p=a.n32,l=a.n33,n=a.n34,i=a.n41,q=a.n42,v=a.n43,t=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=j*n*q-k*l*q+k*p*v-h*n*v-j*p*t+h*l*t;b.n12=g*l*q-e*n*q-g*p*v+d*n*v+e*p*t-d*l*t;b.n13=e*k*q-g*j*q+g*h*v-d*k*v-e*h*t+d*j*t;b.n14=g*j*p-e*k*p-g*h*l+d*k*l+e*h*n-d*j*n;b.n21=k*l*i-j*n*i-k*m*v+f*n*v+j*m*t-f*l*t;b.n22=e*n*i-g*l*i+g*m*v-c*n*v-e*m*t+c*l*t;b.n23=g*j*i-e*k*i-g*f*v+c*k*v+e*f*t-c*j*t;b.n24=
-e*k*m-g*j*m+g*f*l-c*k*l-e*f*n+c*j*n;b.n31=h*n*i-k*p*i+k*m*q-f*n*q-h*m*t+f*p*t;b.n32=g*p*i-d*n*i-g*m*q+c*n*q+d*m*t-c*p*t;b.n33=e*k*i-g*h*i+g*f*q-c*k*q-d*f*t+c*h*t;b.n34=g*h*m-d*k*m-g*f*p+c*k*p+d*f*n-c*h*n;b.n41=j*p*i-h*l*i-j*m*q+f*l*q+h*m*v-f*p*v;b.n42=d*l*i-e*p*i+e*m*q-c*l*q-d*m*v+c*p*v;b.n43=e*h*i-d*j*i-e*f*q+c*j*q+d*f*v-c*h*v;b.n44=d*j*m-e*h*m+e*f*p-c*j*p-d*f*l+c*h*l;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,j=-a.n32*a.n11+a.n31*a.n12,k=a.n23*a.n12-a.n22*a.n13,m=-a.n23*a.n11+a.n21*a.n13,p=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*k;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*j;c[6]=a*k;c[7]=a*m;c[8]=a*p;return b};
+return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,i=a.n23,l=a.n24,m=a.n31,j=a.n32,n=a.n33,o=a.n34,k=a.n41,q=a.n42,v=a.n43,s=a.n44,J=b.n11,N=b.n12,x=b.n13,B=b.n14,p=b.n21,O=b.n22,
+r=b.n23,u=b.n24,y=b.n31,R=b.n32,$=b.n33,Z=b.n34,C=b.n41,F=b.n42,L=b.n43,D=b.n44;this.n11=c*J+d*p+e*y+g*C;this.n12=c*N+d*O+e*R+g*F;this.n13=c*x+d*r+e*$+g*L;this.n14=c*B+d*u+e*Z+g*D;this.n21=f*J+h*p+i*y+l*C;this.n22=f*N+h*O+i*R+l*F;this.n23=f*x+h*r+i*$+l*L;this.n24=f*B+h*u+i*Z+l*D;this.n31=m*J+j*p+n*y+o*C;this.n32=m*N+j*O+n*R+o*F;this.n33=m*x+j*r+n*$+o*L;this.n34=m*B+j*u+n*Z+o*D;this.n41=k*J+q*p+v*y+s*C;this.n42=k*N+q*O+v*R+s*F;this.n43=k*x+q*r+v*$+s*L;this.n44=k*B+q*u+v*Z+s*D;return this},multiplyToArray:function(a,
+b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
+a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,i=this.n31,l=this.n32,m=this.n33,j=this.n34,n=this.n41,o=this.n42,k=this.n43,q=this.n44;return d*f*l*n-c*h*l*n-d*g*m*n+b*h*m*n+c*g*j*n-b*f*j*n-d*f*i*o+c*h*i*o+d*e*m*o-a*h*m*o-c*e*j*o+a*f*j*o+d*g*i*k-b*h*i*k-d*e*l*k+a*h*l*k+b*e*j*k-a*g*j*k-c*g*i*q+b*f*i*q+c*e*l*q-a*f*l*q-b*e*m*q+a*g*m*q},transpose:function(){var a;a=this.n21;this.n21=
+this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=
+this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=
+this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,
+b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX: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},setRotationY: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},setRotationZ: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},setRotationAxis:function(a,
+b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,i=e*g,l=e*f;this.set(i*g+c,i*f-d*h,i*h+d*f,0,i*f+d*h,l*f+c,l*h-d*g,0,i*h-d*f,l*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);
+return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,e=a.z,g=Math.cos(c),c=Math.sin(c),f=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e);switch(b){case "YXZ":var i=f*h,l=f*e,m=d*h,j=d*e;this.n11=i+j*c;this.n12=
+m*c-l;this.n13=g*d;this.n21=g*e;this.n22=g*h;this.n23=-c;this.n31=l*c-m;this.n32=j+i*c;this.n33=g*f;break;case "ZXY":i=f*h;l=f*e;m=d*h;j=d*e;this.n11=i-j*c;this.n12=-g*e;this.n13=m+l*c;this.n21=l+m*c;this.n22=g*h;this.n23=j-i*c;this.n31=-g*d;this.n32=c;this.n33=g*f;break;case "ZYX":i=g*h;l=g*e;m=c*h;j=c*e;this.n11=f*h;this.n12=m*d-l;this.n13=i*d+j;this.n21=f*e;this.n22=j*d+i;this.n23=l*d-m;this.n31=-d;this.n32=c*f;this.n33=g*f;break;case "YZX":i=g*f;l=g*d;m=c*f;j=c*d;this.n11=f*h;this.n12=j-i*e;this.n13=
+m*e+l;this.n21=e;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=l*e+m;this.n33=i-j*e;break;case "XZY":i=g*f;l=g*d;m=c*f;j=c*d;this.n11=f*h;this.n12=-e;this.n13=d*h;this.n21=i*e+j;this.n22=g*h;this.n23=l*e-m;this.n31=m*e-l;this.n32=c*h;this.n33=j*e+i;break;default:i=g*h,l=g*e,m=c*h,j=c*e,this.n11=f*h,this.n12=-f*e,this.n13=d,this.n21=l+m*d,this.n22=i-j*d,this.n23=-c*f,this.n31=j-i*d,this.n32=m+l*d,this.n33=g*f}return this},setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,
+f=c+c,h=d+d,a=b*g,i=b*f;b*=h;var l=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(l+d);this.n12=i-e;this.n13=b+f;this.n21=i+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+l);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,
+b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
+THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,i=a.n23,l=a.n24,m=a.n31,j=a.n32,n=a.n33,o=a.n34,k=a.n41,q=a.n42,v=a.n43,s=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=i*o*q-l*n*q+l*j*v-h*o*v-i*j*s+h*n*s;b.n12=g*n*q-e*o*q-g*j*v+d*o*v+e*j*s-d*n*s;b.n13=e*l*q-g*i*q+g*h*v-d*l*v-e*h*s+d*i*s;b.n14=g*i*j-e*l*j-g*h*n+d*l*n+e*h*o-d*i*o;b.n21=l*n*k-i*o*k-l*m*v+f*o*v+i*m*s-f*n*s;b.n22=e*o*k-g*n*k+g*m*v-c*o*v-e*m*s+c*n*s;b.n23=g*i*k-e*l*k-g*f*v+c*l*v+e*f*s-c*i*s;b.n24=
+e*l*m-g*i*m+g*f*n-c*l*n-e*f*o+c*i*o;b.n31=h*o*k-l*j*k+l*m*q-f*o*q-h*m*s+f*j*s;b.n32=g*j*k-d*o*k-g*m*q+c*o*q+d*m*s-c*j*s;b.n33=e*l*k-g*h*k+g*f*q-c*l*q-d*f*s+c*h*s;b.n34=g*h*m-d*l*m-g*f*j+c*l*j+d*f*o-c*h*o;b.n41=i*j*k-h*n*k-i*m*q+f*n*q+h*m*v-f*j*v;b.n42=d*n*k-e*j*k+e*m*q-c*n*q-d*m*v+c*j*v;b.n43=e*h*k-d*i*k-e*f*q+c*i*q+d*f*v-c*h*v;b.n44=d*i*m-e*h*m+e*f*j-c*i*j-d*f*n+c*h*n;b.multiplyScalar(1/a.determinant());return b};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,i=-a.n32*a.n11+a.n31*a.n12,l=a.n23*a.n12-a.n22*a.n13,m=-a.n23*a.n11+a.n21*a.n13,j=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*l;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*i;c[6]=a*l;c[7]=a*m;c[8]=a*j;return b};
 THREE.Matrix4.makeFrustum=function(a,b,c,d,e,g){var f;f=new THREE.Matrix4;f.n11=2*e/(b-a);f.n12=0;f.n13=(b+a)/(b-a);f.n14=0;f.n21=0;f.n22=2*e/(d-c);f.n23=(d+c)/(d-c);f.n24=0;f.n31=0;f.n32=0;f.n33=-(g+e)/(g-e);f.n34=-2*g*e/(g-e);f.n41=0;f.n42=0;f.n43=-1;f.n44=0;return f};THREE.Matrix4.makePerspective=function(a,b,c,d){var e,a=c*Math.tan(a*Math.PI/360);e=-a;return THREE.Matrix4.makeFrustum(e*b,a*b,e,a,c,d)};
-THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,j,k;f=new THREE.Matrix4;h=b-a;j=c-d;k=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/j;f.n23=0;f.n24=-((c+d)/j);f.n31=0;f.n32=0;f.n33=-2/k;f.n34=-((g+e)/k);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
-THREE.Object3D=function(){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.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;this.useQuaternion=!1;this.boundRadius=
-0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
+THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,i,l;f=new THREE.Matrix4;h=b-a;i=c-d;l=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/i;f.n23=0;f.n24=-((c+d)/i);f.n31=0;f.n32=0;f.n33=-2/l;f.n34=-((g+e)/l);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
+THREE.Object3D=function(){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=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;
+this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
 THREE.Object3D.prototype={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.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
 -1){a.parent!==void 0&&a.parent.removeChild(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.addChildRecurse(a)}},removeChild:function(a){var b=this.children.indexOf(a);if(b!==-1)a.parent=void 0,this.children.splice(b,1)},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c<d;c++){e=this.children[c];if(e.name===a)return e;if(b&&(e=e.getChildByName(a,b),e!==void 0))return e}},updateMatrix:function(){this.matrix.setPosition(this.position);
-this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation);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=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixRotationWorld.extractRotation(this.matrixWorld,
-this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
+this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):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=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),
+this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
 THREE.Quaternion.prototype={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=0.5*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),f=a*b,h=d*e;this.w=f*g-h*c;this.x=f*c+h*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},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*=-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 a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},
-multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;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},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,j=this.w,k=j*c+f*e-h*d,m=
-j*d+h*c-g*e,p=j*e+g*d-f*c,c=-g*c-f*d-h*e;b.x=k*j+c*-g+m*-h-p*-f;b.y=m*j+c*-f+p*-g-k*-h;b.z=p*j+c*-h+k*-f-m*-g;return b}};
+multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;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},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,i=this.w,l=i*c+f*e-h*d,m=
+i*d+h*c-g*e,j=i*e+g*d-f*c,c=-g*c-f*d-h*e;b.x=l*i+c*-g+m*-h-j*-f;b.y=m*i+c*-f+j*-g-l*-h;b.z=j*i+c*-h+l*-f-m*-g;return b}};
 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(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.0010)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
 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.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
 THREE.Face4=function(a,b,c,d,e,g,f){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=f instanceof Array?f:[f];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.set(a||0,b||0)};
 THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.colors=[];this.faces=[];this.edges=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
 THREE.Geometry.prototype={computeCentroids:function(){var a,b,c;a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c.centroid.set(0,0,0),c instanceof THREE.Face3?(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),c.centroid.divideScalar(3)):c instanceof THREE.Face4&&(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),
-c.centroid.addSelf(this.vertices[c.d].position),c.centroid.divideScalar(4))},computeFaceNormals:function(a){var b,c,d,e,g,f,h=new THREE.Vector3,j=new THREE.Vector3;d=0;for(e=this.faces.length;d<e;d++){g=this.faces[d];if(a&&g.vertexNormals.length){h.set(0,0,0);b=0;for(c=g.vertexNormals.length;b<c;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else b=this.vertices[g.a],c=this.vertices[g.b],f=this.vertices[g.c],h.sub(f.position,c.position),j.sub(b.position,c.position),h.crossSelf(j);h.isZero()||
+c.centroid.addSelf(this.vertices[c.d].position),c.centroid.divideScalar(4))},computeFaceNormals:function(a){var b,c,d,e,g,f,h=new THREE.Vector3,i=new THREE.Vector3;d=0;for(e=this.faces.length;d<e;d++){g=this.faces[d];if(a&&g.vertexNormals.length){h.set(0,0,0);b=0;for(c=g.vertexNormals.length;b<c;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else b=this.vertices[g.a],c=this.vertices[g.b],f=this.vertices[g.c],h.sub(f.position,c.position),i.sub(b.position,c.position),h.crossSelf(i);h.isZero()||
 h.normalize();g.normal.copy(h)}},computeVertexNormals:function(){var a,b,c,d;if(this.__tmpVertices==void 0){d=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)d[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++)if(c=this.faces[a],c instanceof THREE.Face3)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(c instanceof THREE.Face4)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}else{d=
 this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)d[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c instanceof THREE.Face3?(d[c.a].addSelf(c.normal),d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal)):c instanceof THREE.Face4&&(d[c.a].addSelf(c.normal),d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal),d[c.d].addSelf(c.normal));a=0;for(b=this.vertices.length;a<b;a++)d[a].normalize();a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c instanceof THREE.Face3?(c.vertexNormals[0].copy(d[c.a]),
-c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c])):c instanceof THREE.Face4&&(c.vertexNormals[0].copy(d[c.a]),c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c]),c.vertexNormals[3].copy(d[c.d]))},computeTangents:function(){function a(a,b,c,d,e,g,r){h=a.vertices[b].position;j=a.vertices[c].position;k=a.vertices[d].position;m=f[e];p=f[g];l=f[r];n=j.x-h.x;i=k.x-h.x;q=j.y-h.y;v=k.y-h.y;t=j.z-h.z;G=k.z-h.z;K=p.u-m.u;x=l.u-m.u;B=p.v-m.v;o=l.v-m.v;M=1/(K*o-x*B);Q.set((o*n-B*i)*
-M,(o*q-B*v)*M,(o*t-B*G)*M);$.set((K*i-x*n)*M,(K*v-x*q)*M,(K*G-x*t)*M);u[b].addSelf(Q);u[c].addSelf(Q);u[d].addSelf(Q);y[b].addSelf($);y[c].addSelf($);y[d].addSelf($)}var b,c,d,e,g,f,h,j,k,m,p,l,n,i,q,v,t,G,K,x,B,o,M,r,u=[],y=[],Q=new THREE.Vector3,$=new THREE.Vector3,Z=new THREE.Vector3,I=new THREE.Vector3,O=new THREE.Vector3;b=0;for(c=this.vertices.length;b<c;b++)u[b]=new THREE.Vector3,y[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)g=this.faces[b],f=this.faceVertexUvs[0][b],g instanceof
-THREE.Face3?a(this,g.a,g.b,g.c,0,1,2):g instanceof THREE.Face4&&(a(this,g.a,g.b,g.c,0,1,2),a(this,g.a,g.b,g.d,0,1,3));var R=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++)O.copy(g.vertexNormals[d]),e=g[R[d]],r=u[e],Z.copy(r),Z.subSelf(O.multiplyScalar(O.dot(r))).normalize(),I.cross(g.vertexNormals[d],r),e=I.dot(y[e]),e=e<0?-1:1,g.vertexTangents[d]=new THREE.Vector4(Z.x,Z.y,Z.z,e)}this.hasTangents=!0},computeBoundingBox:function(){var a;
+c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c])):c instanceof THREE.Face4&&(c.vertexNormals[0].copy(d[c.a]),c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c]),c.vertexNormals[3].copy(d[c.d]))},computeTangents:function(){function a(a,b,c,d,e,g,r){h=a.vertices[b].position;i=a.vertices[c].position;l=a.vertices[d].position;m=f[e];j=f[g];n=f[r];o=i.x-h.x;k=l.x-h.x;q=i.y-h.y;v=l.y-h.y;s=i.z-h.z;J=l.z-h.z;N=j.u-m.u;x=n.u-m.u;B=j.v-m.v;p=n.v-m.v;O=1/(N*p-x*B);R.set((p*o-B*k)*
+O,(p*q-B*v)*O,(p*s-B*J)*O);$.set((N*k-x*o)*O,(N*v-x*q)*O,(N*J-x*s)*O);u[b].addSelf(R);u[c].addSelf(R);u[d].addSelf(R);y[b].addSelf($);y[c].addSelf($);y[d].addSelf($)}var b,c,d,e,g,f,h,i,l,m,j,n,o,k,q,v,s,J,N,x,B,p,O,r,u=[],y=[],R=new THREE.Vector3,$=new THREE.Vector3,Z=new THREE.Vector3,C=new THREE.Vector3,F=new THREE.Vector3;b=0;for(c=this.vertices.length;b<c;b++)u[b]=new THREE.Vector3,y[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)g=this.faces[b],f=this.faceVertexUvs[0][b],g instanceof
+THREE.Face3?a(this,g.a,g.b,g.c,0,1,2):g instanceof THREE.Face4&&(a(this,g.a,g.b,g.c,0,1,2),a(this,g.a,g.b,g.d,0,1,3));var L=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++)F.copy(g.vertexNormals[d]),e=g[L[d]],r=u[e],Z.copy(r),Z.subSelf(F.multiplyScalar(F.dot(r))).normalize(),C.cross(g.vertexNormals[d],r),e=C.dot(y[e]),e=e<0?-1:1,g.vertexTangents[d]=new THREE.Vector4(Z.x,Z.y,Z.z,e)}this.hasTangents=!0},computeBoundingBox:function(){var a;
 if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,c=this.vertices.length;b<c;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;
 else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;b<c;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},computeEdgeFaces:function(){function a(a,b){return Math.min(a,b)+"_"+Math.max(a,b)}function b(a,b,c){a[b]===
 void 0?(a[b]={set:{},array:[]},a[b].set[c]=1,a[b].array.push(c)):a[b].set[c]===void 0&&(a[b].set[c]=1,a[b].array.push(c))}var c,d,e,g,f,h={};c=0;for(d=this.faces.length;c<d;c++)f=this.faces[c],f instanceof THREE.Face3?(e=a(f.a,f.b),b(h,e,c),e=a(f.b,f.c),b(h,e,c),e=a(f.a,f.c),b(h,e,c)):f instanceof THREE.Face4&&(e=a(f.b,f.d),b(h,e,c),e=a(f.a,f.b),b(h,e,c),e=a(f.a,f.d),b(h,e,c),e=a(f.b,f.c),b(h,e,c),e=a(f.c,f.d),b(h,e,c));c=0;for(d=this.edges.length;c<d;c++){f=this.edges[c];e=f.vertexIndices[0];g=f.vertexIndices[1];
@@ -72,9 +74,11 @@ THREE.Camera.prototype.setViewOffset=function(a,b,c,d,e,g){this.fullWidth=a;this
 THREE.Camera.prototype.update=function(a,b,c){if(this.useTarget)this.matrix.lookAt(this.position,this.target.position,this.up),this.matrix.setPosition(this.position),a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse),b=!0;else if(this.matrixAutoUpdate&&this.updateMatrix(),b||this.matrixWorldNeedsUpdate)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=
 !1,b=!0,THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse);for(a=0;a<this.children.length;a++)this.children[a].update(this.matrixWorld,b,c)};THREE.Light=function(a){THREE.Object3D.call(this);this.color=new THREE.Color(a)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;
 THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b,c,d){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1;this.distance=c||0;this.castShadow=d!==void 0?d:!1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1;this.distance=c||0};
-THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;THREE.Material=function(a){this.id=THREE.MaterialCounter.value++;a=a||{};this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:!1;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.depthTest=a.depthTest!==void 0?a.depthTest:!0};THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;
-THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;THREE.MaterialCounter={value:0};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
-THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:!1};THREE.LineBasicMaterial.prototype=new THREE.Material;THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
+THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;
+THREE.Material=function(a){this.id=THREE.MaterialCounter.value++;a=a||{};this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:!1;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.depthTest=a.depthTest!==void 0?a.depthTest:!0;this.polygonOffset=a.polygonOffset!==void 0?a.polygonOffset:!1;this.polygonOffsetFactor=a.polygonOffsetFactor!==void 0?a.polygonOffsetFactor:0;this.polygonOffsetUnits=a.polygonOffsetUnits!==void 0?a.polygonOffsetUnits:
+0};THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;THREE.MaterialCounter={value:0};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};
+THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:!1};THREE.LineBasicMaterial.prototype=new THREE.Material;
+THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
 THREE.MeshBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.shading=a.shading!==
 void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:!1;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:!1;this.skinning=a.skinning!==void 0?a.skinning:!1;this.morphTargets=a.morphTargets!==void 0?a.morphTargets:!1};
 THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
@@ -102,46 +106,46 @@ b.indexOf(".ogg")!==-1?e="audio/ogg":b.indexOf(".wav")!==-1&&(e="audio/wav"),thi
 THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded)this.removeEventListener("canplay",this.onLoad,!0),a.isLoaded=!0,a.duration=this.duration,a.isPlaying&&a.play()};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded&&(this.domElement.play(),a))this.domElement.currentTime=a%this.duration};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
 THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
 THREE.Sound.prototype.update=function(a,b,c){this.matrixAutoUpdate&&(this.matrix.setPosition(this.position),b=!0);if(b||this.matrixWorldNeedsUpdate)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,b=!0;for(var d=this.children.length,a=0;a<d;a++)this.children[a].update(this.matrixWorld,b,c)};
-THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
+THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.overrideMaterial=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
 THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1)this.objects.push(a),this.__objectsAdded.push(a);for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
 THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else a instanceof THREE.Sound?(b=this.sounds.indexOf(a),b!==-1&&this.sounds.splice(b,1)):a instanceof THREE.Camera||(b=this.objects.indexOf(a),b!==-1&&(this.objects.splice(b,1),this.__objectsRemoved.push(a)));for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
 THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
-THREE.Projector=function(){function a(){var a=j[h]=j[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(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))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,e,g=[],f,h,j=[],k,m,p=[],l,n=[],i,q,v=[],t,G,K=[],x=new THREE.Vector4,B=new THREE.Vector4,
-o=new THREE.Matrix4,M=new THREE.Matrix4,r=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],u=new THREE.Vector4,y=new THREE.Vector4;this.projectVector=function(a,b){o.multiply(b.projectionMatrix,b.matrixWorldInverse);o.multiplyVector3(a);return a};this.unprojectVector=function(a,b){o.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));o.multiplyVector3(a);return a};this.projectObjects=function(a,c,f){var c=[],h,i,l;e=0;i=
-a.objects;a=0;for(h=i.length;a<h;a++){l=i[a];var k;if(!(k=!l.visible))if(k=l instanceof THREE.Mesh){a:{k=void 0;for(var j=l.matrixWorld,n=-l.geometry.boundingSphere.radius*Math.max(l.scale.x,Math.max(l.scale.y,l.scale.z)),m=0;m<6;m++)if(k=r[m].x*j.n14+r[m].y*j.n24+r[m].z*j.n34+r[m].w,k<=n){k=!1;break a}k=!0}k=!k}if(!k)k=g[e]=g[e]||new THREE.RenderableObject,e++,d=k,x.copy(l.position),o.multiplyVector3(x),d.object=l,d.z=x.z,c.push(d)}f&&c.sort(b);return c};this.projectScene=function(d,e,g){var I=[],
-O=e.near,R=e.far,L,D,z,N,w,J,H,S,x,s,E,C,F,T,W,ca,X;G=q=l=m=0;e.matrixAutoUpdate&&e.update(void 0,!0);d.update(void 0,!1,e);o.multiply(e.projectionMatrix,e.matrixWorldInverse);r[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);r[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);r[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);r[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);r[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);r[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+
-o.n33,o.n44+o.n34);for(L=0;L<6;L++)x=r[L],x.divideScalar(Math.sqrt(x.x*x.x+x.y*x.y+x.z*x.z));x=this.projectObjects(d,e,!0);d=0;for(L=x.length;d<L;d++)if(s=x[d].object,s.visible)if(E=s.matrixWorld,C=s.matrixRotationWorld,F=s.materials,T=s.overdraw,h=0,s instanceof THREE.Mesh){W=s.geometry;N=W.vertices;ca=W.faces;W=W.faceVertexUvs;D=0;for(z=N.length;D<z;D++)f=a(),f.positionWorld.copy(N[D].position),E.multiplyVector3(f.positionWorld),f.positionScreen.copy(f.positionWorld),o.multiplyVector4(f.positionScreen),
-f.positionScreen.x/=f.positionScreen.w,f.positionScreen.y/=f.positionScreen.w,f.visible=f.positionScreen.z>O&&f.positionScreen.z<R;N=0;for(D=ca.length;N<D;N++){z=ca[N];if(z instanceof THREE.Face3)if(w=j[z.a],J=j[z.b],H=j[z.c],w.visible&&J.visible&&H.visible&&(s.doubleSided||s.flipSided!=(H.positionScreen.x-w.positionScreen.x)*(J.positionScreen.y-w.positionScreen.y)-(H.positionScreen.y-w.positionScreen.y)*(J.positionScreen.x-w.positionScreen.x)<0))S=p[m]=p[m]||new THREE.RenderableFace3,m++,k=S,k.v1.copy(w),
-k.v2.copy(J),k.v3.copy(H);else continue;else if(z instanceof THREE.Face4)if(w=j[z.a],J=j[z.b],H=j[z.c],S=j[z.d],w.visible&&J.visible&&H.visible&&S.visible&&(s.doubleSided||s.flipSided!=((S.positionScreen.x-w.positionScreen.x)*(J.positionScreen.y-w.positionScreen.y)-(S.positionScreen.y-w.positionScreen.y)*(J.positionScreen.x-w.positionScreen.x)<0||(J.positionScreen.x-H.positionScreen.x)*(S.positionScreen.y-H.positionScreen.y)-(J.positionScreen.y-H.positionScreen.y)*(S.positionScreen.x-H.positionScreen.x)<
-0)))X=n[l]=n[l]||new THREE.RenderableFace4,l++,k=X,k.v1.copy(w),k.v2.copy(J),k.v3.copy(H),k.v4.copy(S);else continue;k.normalWorld.copy(z.normal);C.multiplyVector3(k.normalWorld);k.centroidWorld.copy(z.centroid);E.multiplyVector3(k.centroidWorld);k.centroidScreen.copy(k.centroidWorld);o.multiplyVector3(k.centroidScreen);H=z.vertexNormals;w=0;for(J=H.length;w<J;w++)S=k.vertexNormalsWorld[w],S.copy(H[w]),C.multiplyVector3(S);w=0;for(J=W.length;w<J;w++)if(X=W[w][N]){H=0;for(S=X.length;H<S;H++)k.uvs[w][H]=
-X[H]}k.meshMaterials=F;k.faceMaterials=z.materials;k.overdraw=T;k.z=k.centroidScreen.z;I.push(k)}}else if(s instanceof THREE.Line){M.multiply(o,E);N=s.geometry.vertices;w=a();w.positionScreen.copy(N[0].position);M.multiplyVector4(w.positionScreen);D=1;for(z=N.length;D<z;D++)if(w=a(),w.positionScreen.copy(N[D].position),M.multiplyVector4(w.positionScreen),J=j[h-2],u.copy(w.positionScreen),y.copy(J.positionScreen),c(u,y))u.multiplyScalar(1/u.w),y.multiplyScalar(1/y.w),E=v[q]=v[q]||new THREE.RenderableLine,
-q++,i=E,i.v1.positionScreen.copy(u),i.v2.positionScreen.copy(y),i.z=Math.max(u.z,y.z),i.materials=s.materials,I.push(i)}else if(s instanceof THREE.Particle&&(B.set(s.matrixWorld.n14,s.matrixWorld.n24,s.matrixWorld.n34,1),o.multiplyVector4(B),B.z/=B.w,B.z>0&&B.z<1))E=K[G]=K[G]||new THREE.RenderableParticle,G++,t=E,t.x=B.x/B.w,t.y=B.y/B.w,t.z=B.z,t.rotation=s.rotation.z,t.scale.x=s.scale.x*Math.abs(t.x-(B.x+e.projectionMatrix.n11)/(B.w+e.projectionMatrix.n14)),t.scale.y=s.scale.y*Math.abs(t.y-(B.y+
-e.projectionMatrix.n22)/(B.w+e.projectionMatrix.n24)),t.materials=s.materials,I.push(t);g&&I.sort(b);return I}};
-THREE.CanvasRenderer=function(a){function b(a){if(t!=a)i.globalAlpha=t=a}function c(a){if(G!=a){switch(a){case THREE.NormalBlending:i.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:i.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:i.globalCompositeOperation="darker"}G=a}}function d(a){if(K!=a.hex)K=a.hex,i.strokeStyle="#"+g(K.toString(16))}function e(a){if(x!=a.hex)x=a.hex,i.fillStyle="#"+g(x.toString(16))}function g(a){for(;a.length<6;)a="0"+a;return a}
-var f=this,h=null,j=new THREE.Projector,a=a||{},k=a.canvas!==void 0?a.canvas:document.createElement("canvas"),m,p,l,n,i=k.getContext("2d"),q=new THREE.Color(0),v=0,t=1,G=0,K=null,x=null,B=null,o=null,M=null,r,u,y,Q,$=new THREE.RenderableVertex,Z=new THREE.RenderableVertex,I,O,R,L,D,z,N,w,J,H,S,oa,s=new THREE.Color(0),E=new THREE.Color(0),C=new THREE.Color(0),F=new THREE.Color(0),T=new THREE.Color(0),W,ca,X,aa,Ba,Ca,Da,Ea,Fa,Ga,ka=new THREE.Rectangle,da=new THREE.Rectangle,V=new THREE.Rectangle,ya=
-!1,ba=new THREE.Color,Y=new THREE.Color,sa=new THREE.Color,ta=new THREE.Color,P=new THREE.Vector3,pa,qa,za,ea,ra,ua,a=16;pa=document.createElement("canvas");pa.width=pa.height=2;qa=pa.getContext("2d");qa.fillStyle="rgba(0,0,0,1)";qa.fillRect(0,0,2,2);za=qa.getImageData(0,0,2,2);ea=za.data;ra=document.createElement("canvas");ra.width=ra.height=a;ua=ra.getContext("2d");ua.translate(-a/2,-a/2);ua.scale(a,a);a--;this.domElement=k;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,
-faces:0};this.setSize=function(a,b){m=a;p=b;l=m/2;n=p/2;k.width=m;k.height=p;ka.set(-l,-n,l,n);t=1;G=0;M=o=B=x=K=null};this.setClearColor=function(a,b){q=a;v=b};this.setClearColorHex=function(a,b){q.setHex(a);v=b};this.clear=function(){i.setTransform(1,0,0,-1,l,n);if(!da.isEmpty())da.inflate(1),da.minSelf(ka),q.hex==0&&v==0?i.clearRect(da.getX(),da.getY(),da.getWidth(),da.getHeight()):(c(THREE.NormalBlending),b(1),i.fillStyle="rgba("+Math.floor(q.r*255)+","+Math.floor(q.g*255)+","+Math.floor(q.b*
-255)+","+v+")",i.fillRect(da.getX(),da.getY(),da.getWidth(),da.getHeight())),da.empty()};this.render=function(a,g){function k(a){var b,c,d,e=a.lights;Y.setRGB(0,0,0);sa.setRGB(0,0,0);ta.setRGB(0,0,0);a=0;for(b=e.length;a<b;a++)c=e[a],d=c.color,c instanceof THREE.AmbientLight?(Y.r+=d.r,Y.g+=d.g,Y.b+=d.b):c instanceof THREE.DirectionalLight?(sa.r+=d.r,sa.g+=d.g,sa.b+=d.b):c instanceof THREE.PointLight&&(ta.r+=d.r,ta.g+=d.g,ta.b+=d.b)}function m(a,b,c,d){var e,f,g,h,i=a.lights,a=0;for(e=i.length;a<e;a++)f=
-i[a],g=f.color,f instanceof THREE.DirectionalLight?(h=c.dot(f.position),h<=0||(h*=f.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)):f instanceof THREE.PointLight&&(h=c.dot(P.sub(f.position,b).normalize()),h<=0||(h*=f.distance==0?1:1-Math.min(b.distanceTo(f.position)/f.distance,1),h!=0&&(h*=f.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)))}function p(a,f,g){b(g.opacity);c(g.blending);var h,k,m,j,Aa,o;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)j=g.map.image,Aa=j.width>>1,o=j.height>>1,g=f.scale.x*
-l,m=f.scale.y*n,h=g*Aa,k=m*o,V.set(a.x-h,a.y-k,a.x+h,a.y+k),ka.instersects(V)&&(i.save(),i.translate(a.x,a.y),i.rotate(-f.rotation),i.scale(g,-m),i.translate(-Aa,-o),i.drawImage(j,0,0),i.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=f.scale.x*l,k=f.scale.y*n,V.set(a.x-h,a.y-k,a.x+h,a.y+k),ka.instersects(V)&&(d(g.color),e(g.color),i.save(),i.translate(a.x,a.y),i.rotate(-f.rotation),i.scale(h,k),g.program(i),i.restore()))}function q(a,e,f,g){b(g.opacity);c(g.blending);i.beginPath();
-i.moveTo(a.positionScreen.x,a.positionScreen.y);i.lineTo(e.positionScreen.x,e.positionScreen.y);i.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(B!=a)i.lineWidth=B=a;a=g.linecap;if(o!=a)i.lineCap=o=a;a=g.linejoin;if(M!=a)i.lineJoin=M=a;d(g.color);i.stroke();V.inflate(g.linewidth*2)}}function t(a,d,e,h,k,i,l,j,n){f.data.vertices+=3;f.data.faces++;b(j.opacity);c(j.blending);I=a.positionScreen.x;O=a.positionScreen.y;R=d.positionScreen.x;L=d.positionScreen.y;D=e.positionScreen.x;
-z=e.positionScreen.y;x(I,O,R,L,D,z);if(j instanceof THREE.MeshBasicMaterial)if(j.map)j.map.mapping instanceof THREE.UVMapping&&(aa=l.uvs[0],ga(I,O,R,L,D,z,j.map.image,aa[h].u,aa[h].v,aa[k].u,aa[k].v,aa[i].u,aa[i].v));else if(j.envMap){if(j.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=g.matrixWorldInverse,P.copy(l.vertexNormalsWorld[0]),Ba=(P.x*a.n11+P.y*a.n12+P.z*a.n13)*0.5+0.5,Ca=-(P.x*a.n21+P.y*a.n22+P.z*a.n23)*0.5+0.5,P.copy(l.vertexNormalsWorld[1]),Da=(P.x*a.n11+P.y*a.n12+P.z*
-a.n13)*0.5+0.5,Ea=-(P.x*a.n21+P.y*a.n22+P.z*a.n23)*0.5+0.5,P.copy(l.vertexNormalsWorld[2]),Fa=(P.x*a.n11+P.y*a.n12+P.z*a.n13)*0.5+0.5,Ga=-(P.x*a.n21+P.y*a.n22+P.z*a.n23)*0.5+0.5,ga(I,O,R,L,D,z,j.envMap.image,Ba,Ca,Da,Ea,Fa,Ga)}else j.wireframe?G(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshLambertMaterial)j.map&&!j.wireframe&&(j.map.mapping instanceof THREE.UVMapping&&(aa=l.uvs[0],ga(I,O,R,L,D,z,j.map.image,aa[h].u,aa[h].v,aa[k].u,
-aa[k].v,aa[i].u,aa[i].v)),c(THREE.SubtractiveBlending)),ya?!j.wireframe&&j.shading==THREE.SmoothShading&&l.vertexNormalsWorld.length==3?(E.r=C.r=F.r=Y.r,E.g=C.g=F.g=Y.g,E.b=C.b=F.b=Y.b,m(n,l.v1.positionWorld,l.vertexNormalsWorld[0],E),m(n,l.v2.positionWorld,l.vertexNormalsWorld[1],C),m(n,l.v3.positionWorld,l.vertexNormalsWorld[2],F),T.r=(C.r+F.r)*0.5,T.g=(C.g+F.g)*0.5,T.b=(C.b+F.b)*0.5,X=va(E,C,F,T),ga(I,O,R,L,D,z,X,0,0,1,0,0,1)):(ba.r=Y.r,ba.g=Y.g,ba.b=Y.b,m(n,l.centroidWorld,l.normalWorld,ba),s.r=
-Math.max(0,Math.min(j.color.r*ba.r,1)),s.g=Math.max(0,Math.min(j.color.g*ba.g,1)),s.b=Math.max(0,Math.min(j.color.b*ba.b,1)),s.updateHex(),j.wireframe?G(s,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(s)):j.wireframe?G(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshDepthMaterial)W=g.near,ca=g.far,E.r=E.g=E.b=1-la(a.positionScreen.z,W,ca),C.r=C.g=C.b=1-la(d.positionScreen.z,W,ca),F.r=F.g=F.b=1-la(e.positionScreen.z,
-W,ca),T.r=(C.r+F.r)*0.5,T.g=(C.g+F.g)*0.5,T.b=(C.b+F.b)*0.5,X=va(E,C,F,T),ga(I,O,R,L,D,z,X,0,0,1,0,0,1);else if(j instanceof THREE.MeshNormalMaterial)s.r=ma(l.normalWorld.x),s.g=ma(l.normalWorld.y),s.b=ma(l.normalWorld.z),s.updateHex(),j.wireframe?G(s,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(s)}function v(a,d,e,h,j,l,k,i,n){f.data.vertices+=4;f.data.faces++;b(i.opacity);c(i.blending);if(i.map||i.envMap)t(a,d,h,0,1,3,k,i,n),t(j,e,l,1,2,3,k,i,n);else if(I=a.positionScreen.x,O=
-a.positionScreen.y,R=d.positionScreen.x,L=d.positionScreen.y,D=e.positionScreen.x,z=e.positionScreen.y,N=h.positionScreen.x,w=h.positionScreen.y,J=j.positionScreen.x,H=j.positionScreen.y,S=l.positionScreen.x,oa=l.positionScreen.y,i instanceof THREE.MeshBasicMaterial)K(I,O,R,L,D,z,N,w),i.wireframe?G(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color);else if(i instanceof THREE.MeshLambertMaterial)ya?!i.wireframe&&i.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==
-4?(E.r=C.r=F.r=T.r=Y.r,E.g=C.g=F.g=T.g=Y.g,E.b=C.b=F.b=T.b=Y.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],E),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],C),m(n,k.v4.positionWorld,k.vertexNormalsWorld[3],F),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],T),X=va(E,C,F,T),x(I,O,R,L,N,w),ga(I,O,R,L,N,w,X,0,0,1,0,0,1),x(J,H,D,z,S,oa),ga(J,H,D,z,S,oa,X,1,0,1,1,0,1)):(ba.r=Y.r,ba.g=Y.g,ba.b=Y.b,m(n,k.centroidWorld,k.normalWorld,ba),s.r=Math.max(0,Math.min(i.color.r*ba.r,1)),s.g=Math.max(0,Math.min(i.color.g*
-ba.g,1)),s.b=Math.max(0,Math.min(i.color.b*ba.b,1)),s.updateHex(),K(I,O,R,L,D,z,N,w),i.wireframe?G(s,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(s)):(K(I,O,R,L,D,z,N,w),i.wireframe?G(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color));else if(i instanceof THREE.MeshNormalMaterial)s.r=ma(k.normalWorld.x),s.g=ma(k.normalWorld.y),s.b=ma(k.normalWorld.z),s.updateHex(),K(I,O,R,L,D,z,N,w),i.wireframe?G(s,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):
-ha(s);else if(i instanceof THREE.MeshDepthMaterial)W=g.near,ca=g.far,E.r=E.g=E.b=1-la(a.positionScreen.z,W,ca),C.r=C.g=C.b=1-la(d.positionScreen.z,W,ca),F.r=F.g=F.b=1-la(h.positionScreen.z,W,ca),T.r=T.g=T.b=1-la(e.positionScreen.z,W,ca),X=va(E,C,F,T),x(I,O,R,L,N,w),ga(I,O,R,L,N,w,X,0,0,1,0,0,1),x(J,H,D,z,S,oa),ga(J,H,D,z,S,oa,X,1,0,1,1,0,1)}function x(a,b,c,d,e,f){i.beginPath();i.moveTo(a,b);i.lineTo(c,d);i.lineTo(e,f);i.lineTo(a,b);i.closePath()}function K(a,b,c,d,e,f,g,h){i.beginPath();i.moveTo(a,
-b);i.lineTo(c,d);i.lineTo(e,f);i.lineTo(g,h);i.lineTo(a,b);i.closePath()}function G(a,b,c,e){if(B!=b)i.lineWidth=B=b;if(o!=c)i.lineCap=o=c;if(M!=e)i.lineJoin=M=e;d(a);i.stroke();V.inflate(b*2)}function ha(a){e(a);i.fill()}function ga(a,b,c,d,e,f,g,h,j,k,l,m,n){var o,p;o=g.width-1;p=g.height-1;h*=o;j*=p;k*=o;l*=p;m*=o;n*=p;c-=a;d-=b;e-=a;f-=b;k-=h;l-=j;m-=h;n-=j;o=k*n-m*l;o!=0&&(p=1/o,o=(n*c-l*e)*p,l=(n*d-l*f)*p,c=(k*e-m*c)*p,d=(k*f-m*d)*p,a=a-o*h-c*j,b=b-l*h-d*j,i.save(),i.transform(o,l,c,d,a,b),
-i.clip(),i.drawImage(g,0,0),i.restore())}function va(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),h=~~(b.g*255),b=~~(b.b*255),i=~~(c.r*255),j=~~(c.g*255),c=~~(c.b*255),k=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);ea[0]=e<0?0:e>255?255:e;ea[1]=f<0?0:f>255?255:f;ea[2]=a<0?0:a>255?255:a;ea[4]=g<0?0:g>255?255:g;ea[5]=h<0?0:h>255?255:h;ea[6]=b<0?0:b>255?255:b;ea[8]=i<0?0:i>255?255:i;ea[9]=j<0?0:j>255?255:j;ea[10]=c<0?0:c>255?255:c;ea[12]=k<0?0:k>255?255:k;ea[13]=l<0?0:l>255?255:l;
-ea[14]=d<0?0:d>255?255:d;qa.putImageData(za,0,0);ua.drawImage(pa,0,0);return ra}function la(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function ma(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function ia(a,b){var c=b.x-a.x,d=b.y-a.y,e=1/Math.sqrt(c*c+d*d);c*=e;d*=e;b.x+=c;b.y+=d;a.x-=c;a.y-=d}var wa,Ha,A,fa,ja,na,xa,U;this.autoClear?this.clear():i.setTransform(1,0,0,-1,l,n);f.data.vertices=0;f.data.faces=0;h=j.projectScene(a,g,this.sortElements);(ya=a.lights.length>0)&&k(a);wa=0;for(Ha=h.length;wa<Ha;wa++){A=
-h[wa];V.empty();if(A instanceof THREE.RenderableParticle){r=A;r.x*=l;r.y*=n;fa=0;for(ja=A.materials.length;fa<ja;)U=A.materials[fa++],U.opacity!=0&&p(r,A,U,a)}else if(A instanceof THREE.RenderableLine){if(r=A.v1,u=A.v2,r.positionScreen.x*=l,r.positionScreen.y*=n,u.positionScreen.x*=l,u.positionScreen.y*=n,V.addPoint(r.positionScreen.x,r.positionScreen.y),V.addPoint(u.positionScreen.x,u.positionScreen.y),ka.instersects(V)){fa=0;for(ja=A.materials.length;fa<ja;)U=A.materials[fa++],U.opacity!=0&&q(r,
-u,A,U,a)}}else if(A instanceof THREE.RenderableFace3){if(r=A.v1,u=A.v2,y=A.v3,r.positionScreen.x*=l,r.positionScreen.y*=n,u.positionScreen.x*=l,u.positionScreen.y*=n,y.positionScreen.x*=l,y.positionScreen.y*=n,A.overdraw&&(ia(r.positionScreen,u.positionScreen),ia(u.positionScreen,y.positionScreen),ia(y.positionScreen,r.positionScreen)),V.add3Points(r.positionScreen.x,r.positionScreen.y,u.positionScreen.x,u.positionScreen.y,y.positionScreen.x,y.positionScreen.y),ka.instersects(V)){fa=0;for(ja=A.meshMaterials.length;fa<
-ja;)if(U=A.meshMaterials[fa++],U instanceof THREE.MeshFaceMaterial){na=0;for(xa=A.faceMaterials.length;na<xa;)(U=A.faceMaterials[na++])&&U.opacity!=0&&t(r,u,y,0,1,2,A,U,a)}else U.opacity!=0&&t(r,u,y,0,1,2,A,U,a)}}else if(A instanceof THREE.RenderableFace4&&(r=A.v1,u=A.v2,y=A.v3,Q=A.v4,r.positionScreen.x*=l,r.positionScreen.y*=n,u.positionScreen.x*=l,u.positionScreen.y*=n,y.positionScreen.x*=l,y.positionScreen.y*=n,Q.positionScreen.x*=l,Q.positionScreen.y*=n,$.positionScreen.copy(u.positionScreen),
-Z.positionScreen.copy(Q.positionScreen),A.overdraw&&(ia(r.positionScreen,u.positionScreen),ia(u.positionScreen,Q.positionScreen),ia(Q.positionScreen,r.positionScreen),ia(y.positionScreen,$.positionScreen),ia(y.positionScreen,Z.positionScreen)),V.addPoint(r.positionScreen.x,r.positionScreen.y),V.addPoint(u.positionScreen.x,u.positionScreen.y),V.addPoint(y.positionScreen.x,y.positionScreen.y),V.addPoint(Q.positionScreen.x,Q.positionScreen.y),ka.instersects(V))){fa=0;for(ja=A.meshMaterials.length;fa<
-ja;)if(U=A.meshMaterials[fa++],U instanceof THREE.MeshFaceMaterial){na=0;for(xa=A.faceMaterials.length;na<xa;)(U=A.faceMaterials[na++])&&U.opacity!=0&&v(r,u,y,Q,$,Z,A,U,a)}else U.opacity!=0&&v(r,u,y,Q,$,Z,A,U,a)}da.addRectangle(V)}i.setTransform(1,0,0,1,0,0)}};
+THREE.Projector=function(){function a(){var a=i[h]=i[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(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))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,e,g=[],f,h,i=[],l,m,j=[],n,o=[],k,q,v=[],s,J,N=[],x=new THREE.Vector4,B=new THREE.Vector4,
+p=new THREE.Matrix4,O=new THREE.Matrix4,r=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],u=new THREE.Vector4,y=new THREE.Vector4;this.projectVector=function(a,b){p.multiply(b.projectionMatrix,b.matrixWorldInverse);p.multiplyVector3(a);return a};this.unprojectVector=function(a,b){p.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));p.multiplyVector3(a);return a};this.projectObjects=function(a,c,f){var c=[],h,l,k;e=0;l=
+a.objects;a=0;for(h=l.length;a<h;a++){k=l[a];var i;if(!(i=!k.visible))if(i=k instanceof THREE.Mesh){a:{i=void 0;for(var m=k.matrixWorld,n=-k.geometry.boundingSphere.radius*Math.max(k.scale.x,Math.max(k.scale.y,k.scale.z)),j=0;j<6;j++)if(i=r[j].x*m.n14+r[j].y*m.n24+r[j].z*m.n34+r[j].w,i<=n){i=!1;break a}i=!0}i=!i}if(!i)i=g[e]=g[e]||new THREE.RenderableObject,e++,d=i,x.copy(k.position),p.multiplyVector3(x),d.object=k,d.z=x.z,c.push(d)}f&&c.sort(b);return c};this.projectScene=function(d,e,g){var C=[],
+F=e.near,L=e.far,D,G,z,P,w,M,K,S,x,t,H,E,I,T,W,ca,X;J=q=n=m=0;e.matrixAutoUpdate&&e.update(void 0,!0);d.update(void 0,!1,e);p.multiply(e.projectionMatrix,e.matrixWorldInverse);r[0].set(p.n41-p.n11,p.n42-p.n12,p.n43-p.n13,p.n44-p.n14);r[1].set(p.n41+p.n11,p.n42+p.n12,p.n43+p.n13,p.n44+p.n14);r[2].set(p.n41+p.n21,p.n42+p.n22,p.n43+p.n23,p.n44+p.n24);r[3].set(p.n41-p.n21,p.n42-p.n22,p.n43-p.n23,p.n44-p.n24);r[4].set(p.n41-p.n31,p.n42-p.n32,p.n43-p.n33,p.n44-p.n34);r[5].set(p.n41+p.n31,p.n42+p.n32,p.n43+
+p.n33,p.n44+p.n34);for(D=0;D<6;D++)x=r[D],x.divideScalar(Math.sqrt(x.x*x.x+x.y*x.y+x.z*x.z));x=this.projectObjects(d,e,!0);d=0;for(D=x.length;d<D;d++)if(t=x[d].object,t.visible)if(H=t.matrixWorld,E=t.matrixRotationWorld,I=t.materials,T=t.overdraw,h=0,t instanceof THREE.Mesh){W=t.geometry;P=W.vertices;ca=W.faces;W=W.faceVertexUvs;G=0;for(z=P.length;G<z;G++)f=a(),f.positionWorld.copy(P[G].position),H.multiplyVector3(f.positionWorld),f.positionScreen.copy(f.positionWorld),p.multiplyVector4(f.positionScreen),
+f.positionScreen.x/=f.positionScreen.w,f.positionScreen.y/=f.positionScreen.w,f.visible=f.positionScreen.z>F&&f.positionScreen.z<L;P=0;for(G=ca.length;P<G;P++){z=ca[P];if(z instanceof THREE.Face3)if(w=i[z.a],M=i[z.b],K=i[z.c],w.visible&&M.visible&&K.visible&&(t.doubleSided||t.flipSided!=(K.positionScreen.x-w.positionScreen.x)*(M.positionScreen.y-w.positionScreen.y)-(K.positionScreen.y-w.positionScreen.y)*(M.positionScreen.x-w.positionScreen.x)<0))S=j[m]=j[m]||new THREE.RenderableFace3,m++,l=S,l.v1.copy(w),
+l.v2.copy(M),l.v3.copy(K);else continue;else if(z instanceof THREE.Face4)if(w=i[z.a],M=i[z.b],K=i[z.c],S=i[z.d],w.visible&&M.visible&&K.visible&&S.visible&&(t.doubleSided||t.flipSided!=((S.positionScreen.x-w.positionScreen.x)*(M.positionScreen.y-w.positionScreen.y)-(S.positionScreen.y-w.positionScreen.y)*(M.positionScreen.x-w.positionScreen.x)<0||(M.positionScreen.x-K.positionScreen.x)*(S.positionScreen.y-K.positionScreen.y)-(M.positionScreen.y-K.positionScreen.y)*(S.positionScreen.x-K.positionScreen.x)<
+0)))X=o[n]=o[n]||new THREE.RenderableFace4,n++,l=X,l.v1.copy(w),l.v2.copy(M),l.v3.copy(K),l.v4.copy(S);else continue;l.normalWorld.copy(z.normal);E.multiplyVector3(l.normalWorld);l.centroidWorld.copy(z.centroid);H.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);p.multiplyVector3(l.centroidScreen);K=z.vertexNormals;w=0;for(M=K.length;w<M;w++)S=l.vertexNormalsWorld[w],S.copy(K[w]),E.multiplyVector3(S);w=0;for(M=W.length;w<M;w++)if(X=W[w][P]){K=0;for(S=X.length;K<S;K++)l.uvs[w][K]=
+X[K]}l.meshMaterials=I;l.faceMaterials=z.materials;l.overdraw=T;l.z=l.centroidScreen.z;C.push(l)}}else if(t instanceof THREE.Line){O.multiply(p,H);P=t.geometry.vertices;w=a();w.positionScreen.copy(P[0].position);O.multiplyVector4(w.positionScreen);G=1;for(z=P.length;G<z;G++)if(w=a(),w.positionScreen.copy(P[G].position),O.multiplyVector4(w.positionScreen),M=i[h-2],u.copy(w.positionScreen),y.copy(M.positionScreen),c(u,y))u.multiplyScalar(1/u.w),y.multiplyScalar(1/y.w),H=v[q]=v[q]||new THREE.RenderableLine,
+q++,k=H,k.v1.positionScreen.copy(u),k.v2.positionScreen.copy(y),k.z=Math.max(u.z,y.z),k.materials=t.materials,C.push(k)}else if(t instanceof THREE.Particle&&(B.set(t.matrixWorld.n14,t.matrixWorld.n24,t.matrixWorld.n34,1),p.multiplyVector4(B),B.z/=B.w,B.z>0&&B.z<1))H=N[J]=N[J]||new THREE.RenderableParticle,J++,s=H,s.x=B.x/B.w,s.y=B.y/B.w,s.z=B.z,s.rotation=t.rotation.z,s.scale.x=t.scale.x*Math.abs(s.x-(B.x+e.projectionMatrix.n11)/(B.w+e.projectionMatrix.n14)),s.scale.y=t.scale.y*Math.abs(s.y-(B.y+
+e.projectionMatrix.n22)/(B.w+e.projectionMatrix.n24)),s.materials=t.materials,C.push(s);g&&C.sort(b);return C}};
+THREE.CanvasRenderer=function(a){function b(a){if(s!=a)k.globalAlpha=s=a}function c(a){if(J!=a){switch(a){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}J=a}}function d(a){if(N!=a.hex)N=a.hex,k.strokeStyle="#"+g(N.toString(16))}function e(a){if(x!=a.hex)x=a.hex,k.fillStyle="#"+g(x.toString(16))}function g(a){for(;a.length<6;)a="0"+a;return a}
+var f=this,h=null,i=new THREE.Projector,a=a||{},l=a.canvas!==void 0?a.canvas:document.createElement("canvas"),m,j,n,o,k=l.getContext("2d"),q=new THREE.Color(0),v=0,s=1,J=0,N=null,x=null,B=null,p=null,O=null,r,u,y,R,$=new THREE.RenderableVertex,Z=new THREE.RenderableVertex,C,F,L,D,G,z,P,w,M,K,S,oa,t=new THREE.Color(0),H=new THREE.Color(0),E=new THREE.Color(0),I=new THREE.Color(0),T=new THREE.Color(0),W,ca,X,aa,Ba,Ca,Da,Ea,Fa,Ga,ka=new THREE.Rectangle,da=new THREE.Rectangle,V=new THREE.Rectangle,ya=
+!1,ba=new THREE.Color,Y=new THREE.Color,sa=new THREE.Color,ta=new THREE.Color,Q=new THREE.Vector3,pa,qa,za,ea,ra,ua,a=16;pa=document.createElement("canvas");pa.width=pa.height=2;qa=pa.getContext("2d");qa.fillStyle="rgba(0,0,0,1)";qa.fillRect(0,0,2,2);za=qa.getImageData(0,0,2,2);ea=za.data;ra=document.createElement("canvas");ra.width=ra.height=a;ua=ra.getContext("2d");ua.translate(-a/2,-a/2);ua.scale(a,a);a--;this.domElement=l;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,
+faces:0};this.setSize=function(a,b){m=a;j=b;n=m/2;o=j/2;l.width=m;l.height=j;ka.set(-n,-o,n,o);s=1;J=0;O=p=B=x=N=null};this.setClearColor=function(a,b){q=a;v=b};this.setClearColorHex=function(a,b){q.setHex(a);v=b};this.clear=function(){k.setTransform(1,0,0,-1,n,o);if(!da.isEmpty())da.inflate(1),da.minSelf(ka),q.hex==0&&v==0?k.clearRect(da.getX(),da.getY(),da.getWidth(),da.getHeight()):(c(THREE.NormalBlending),b(1),k.fillStyle="rgba("+Math.floor(q.r*255)+","+Math.floor(q.g*255)+","+Math.floor(q.b*
+255)+","+v+")",k.fillRect(da.getX(),da.getY(),da.getWidth(),da.getHeight())),da.empty()};this.render=function(a,g){function l(a){var b,c,d,e=a.lights;Y.setRGB(0,0,0);sa.setRGB(0,0,0);ta.setRGB(0,0,0);a=0;for(b=e.length;a<b;a++)c=e[a],d=c.color,c instanceof THREE.AmbientLight?(Y.r+=d.r,Y.g+=d.g,Y.b+=d.b):c instanceof THREE.DirectionalLight?(sa.r+=d.r,sa.g+=d.g,sa.b+=d.b):c instanceof THREE.PointLight&&(ta.r+=d.r,ta.g+=d.g,ta.b+=d.b)}function m(a,b,c,d){var e,f,g,h,l=a.lights,a=0;for(e=l.length;a<e;a++)f=
+l[a],g=f.color,f instanceof THREE.DirectionalLight?(h=c.dot(f.position),h<=0||(h*=f.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)):f instanceof THREE.PointLight&&(h=c.dot(Q.sub(f.position,b).normalize()),h<=0||(h*=f.distance==0?1:1-Math.min(b.distanceTo(f.position)/f.distance,1),h!=0&&(h*=f.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)))}function j(a,f,g){b(g.opacity);c(g.blending);var h,l,i,m,Aa,p;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)m=g.map.image,Aa=m.width>>1,p=m.height>>1,g=f.scale.x*
+n,i=f.scale.y*o,h=g*Aa,l=i*p,V.set(a.x-h,a.y-l,a.x+h,a.y+l),ka.instersects(V)&&(k.save(),k.translate(a.x,a.y),k.rotate(-f.rotation),k.scale(g,-i),k.translate(-Aa,-p),k.drawImage(m,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=f.scale.x*n,l=f.scale.y*o,V.set(a.x-h,a.y-l,a.x+h,a.y+l),ka.instersects(V)&&(d(g.color),e(g.color),k.save(),k.translate(a.x,a.y),k.rotate(-f.rotation),k.scale(h,l),g.program(k),k.restore()))}function q(a,e,f,g){b(g.opacity);c(g.blending);k.beginPath();
+k.moveTo(a.positionScreen.x,a.positionScreen.y);k.lineTo(e.positionScreen.x,e.positionScreen.y);k.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(B!=a)k.lineWidth=B=a;a=g.linecap;if(p!=a)k.lineCap=p=a;a=g.linejoin;if(O!=a)k.lineJoin=O=a;d(g.color);k.stroke();V.inflate(g.linewidth*2)}}function s(a,d,e,h,l,i,k,j,n){f.data.vertices+=3;f.data.faces++;b(j.opacity);c(j.blending);C=a.positionScreen.x;F=a.positionScreen.y;L=d.positionScreen.x;D=d.positionScreen.y;G=e.positionScreen.x;
+z=e.positionScreen.y;x(C,F,L,D,G,z);if(j instanceof THREE.MeshBasicMaterial)if(j.map)j.map.mapping instanceof THREE.UVMapping&&(aa=k.uvs[0],ga(C,F,L,D,G,z,j.map.image,aa[h].u,aa[h].v,aa[l].u,aa[l].v,aa[i].u,aa[i].v));else if(j.envMap){if(j.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=g.matrixWorldInverse,Q.copy(k.vertexNormalsWorld[0]),Ba=(Q.x*a.n11+Q.y*a.n12+Q.z*a.n13)*0.5+0.5,Ca=-(Q.x*a.n21+Q.y*a.n22+Q.z*a.n23)*0.5+0.5,Q.copy(k.vertexNormalsWorld[1]),Da=(Q.x*a.n11+Q.y*a.n12+Q.z*
+a.n13)*0.5+0.5,Ea=-(Q.x*a.n21+Q.y*a.n22+Q.z*a.n23)*0.5+0.5,Q.copy(k.vertexNormalsWorld[2]),Fa=(Q.x*a.n11+Q.y*a.n12+Q.z*a.n13)*0.5+0.5,Ga=-(Q.x*a.n21+Q.y*a.n22+Q.z*a.n23)*0.5+0.5,ga(C,F,L,D,G,z,j.envMap.image,Ba,Ca,Da,Ea,Fa,Ga)}else j.wireframe?J(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshLambertMaterial)j.map&&!j.wireframe&&(j.map.mapping instanceof THREE.UVMapping&&(aa=k.uvs[0],ga(C,F,L,D,G,z,j.map.image,aa[h].u,aa[h].v,aa[l].u,
+aa[l].v,aa[i].u,aa[i].v)),c(THREE.SubtractiveBlending)),ya?!j.wireframe&&j.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==3?(H.r=E.r=I.r=Y.r,H.g=E.g=I.g=Y.g,H.b=E.b=I.b=Y.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],H),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],E),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],I),T.r=(E.r+I.r)*0.5,T.g=(E.g+I.g)*0.5,T.b=(E.b+I.b)*0.5,X=va(H,E,I,T),ga(C,F,L,D,G,z,X,0,0,1,0,0,1)):(ba.r=Y.r,ba.g=Y.g,ba.b=Y.b,m(n,k.centroidWorld,k.normalWorld,ba),t.r=
+Math.max(0,Math.min(j.color.r*ba.r,1)),t.g=Math.max(0,Math.min(j.color.g*ba.g,1)),t.b=Math.max(0,Math.min(j.color.b*ba.b,1)),t.updateHex(),j.wireframe?J(t,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(t)):j.wireframe?J(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshDepthMaterial)W=g.near,ca=g.far,H.r=H.g=H.b=1-la(a.positionScreen.z,W,ca),E.r=E.g=E.b=1-la(d.positionScreen.z,W,ca),I.r=I.g=I.b=1-la(e.positionScreen.z,
+W,ca),T.r=(E.r+I.r)*0.5,T.g=(E.g+I.g)*0.5,T.b=(E.b+I.b)*0.5,X=va(H,E,I,T),ga(C,F,L,D,G,z,X,0,0,1,0,0,1);else if(j instanceof THREE.MeshNormalMaterial)t.r=ma(k.normalWorld.x),t.g=ma(k.normalWorld.y),t.b=ma(k.normalWorld.z),t.updateHex(),j.wireframe?J(t,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(t)}function v(a,d,e,h,j,l,k,i,n){f.data.vertices+=4;f.data.faces++;b(i.opacity);c(i.blending);if(i.map||i.envMap)s(a,d,h,0,1,3,k,i,n),s(j,e,l,1,2,3,k,i,n);else if(C=a.positionScreen.x,F=
+a.positionScreen.y,L=d.positionScreen.x,D=d.positionScreen.y,G=e.positionScreen.x,z=e.positionScreen.y,P=h.positionScreen.x,w=h.positionScreen.y,M=j.positionScreen.x,K=j.positionScreen.y,S=l.positionScreen.x,oa=l.positionScreen.y,i instanceof THREE.MeshBasicMaterial)N(C,F,L,D,G,z,P,w),i.wireframe?J(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color);else if(i instanceof THREE.MeshLambertMaterial)ya?!i.wireframe&&i.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==
+4?(H.r=E.r=I.r=T.r=Y.r,H.g=E.g=I.g=T.g=Y.g,H.b=E.b=I.b=T.b=Y.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],H),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],E),m(n,k.v4.positionWorld,k.vertexNormalsWorld[3],I),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],T),X=va(H,E,I,T),x(C,F,L,D,P,w),ga(C,F,L,D,P,w,X,0,0,1,0,0,1),x(M,K,G,z,S,oa),ga(M,K,G,z,S,oa,X,1,0,1,1,0,1)):(ba.r=Y.r,ba.g=Y.g,ba.b=Y.b,m(n,k.centroidWorld,k.normalWorld,ba),t.r=Math.max(0,Math.min(i.color.r*ba.r,1)),t.g=Math.max(0,Math.min(i.color.g*
+ba.g,1)),t.b=Math.max(0,Math.min(i.color.b*ba.b,1)),t.updateHex(),N(C,F,L,D,G,z,P,w),i.wireframe?J(t,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(t)):(N(C,F,L,D,G,z,P,w),i.wireframe?J(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color));else if(i instanceof THREE.MeshNormalMaterial)t.r=ma(k.normalWorld.x),t.g=ma(k.normalWorld.y),t.b=ma(k.normalWorld.z),t.updateHex(),N(C,F,L,D,G,z,P,w),i.wireframe?J(t,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):
+ha(t);else if(i instanceof THREE.MeshDepthMaterial)W=g.near,ca=g.far,H.r=H.g=H.b=1-la(a.positionScreen.z,W,ca),E.r=E.g=E.b=1-la(d.positionScreen.z,W,ca),I.r=I.g=I.b=1-la(h.positionScreen.z,W,ca),T.r=T.g=T.b=1-la(e.positionScreen.z,W,ca),X=va(H,E,I,T),x(C,F,L,D,P,w),ga(C,F,L,D,P,w,X,0,0,1,0,0,1),x(M,K,G,z,S,oa),ga(M,K,G,z,S,oa,X,1,0,1,1,0,1)}function x(a,b,c,d,e,f){k.beginPath();k.moveTo(a,b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(a,b);k.closePath()}function N(a,b,c,d,e,f,g,h){k.beginPath();k.moveTo(a,
+b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(g,h);k.lineTo(a,b);k.closePath()}function J(a,b,c,e){if(B!=b)k.lineWidth=B=b;if(p!=c)k.lineCap=p=c;if(O!=e)k.lineJoin=O=e;d(a);k.stroke();V.inflate(b*2)}function ha(a){e(a);k.fill()}function ga(a,b,c,d,e,f,g,h,i,j,l,m,n){var o,p;o=g.width-1;p=g.height-1;h*=o;i*=p;j*=o;l*=p;m*=o;n*=p;c-=a;d-=b;e-=a;f-=b;j-=h;l-=i;m-=h;n-=i;o=j*n-m*l;o!=0&&(p=1/o,o=(n*c-l*e)*p,l=(n*d-l*f)*p,c=(j*e-m*c)*p,d=(j*f-m*d)*p,a=a-o*h-c*i,b=b-l*h-d*i,k.save(),k.transform(o,l,c,d,a,b),
+k.clip(),k.drawImage(g,0,0),k.restore())}function va(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),h=~~(b.g*255),b=~~(b.b*255),i=~~(c.r*255),j=~~(c.g*255),c=~~(c.b*255),k=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);ea[0]=e<0?0:e>255?255:e;ea[1]=f<0?0:f>255?255:f;ea[2]=a<0?0:a>255?255:a;ea[4]=g<0?0:g>255?255:g;ea[5]=h<0?0:h>255?255:h;ea[6]=b<0?0:b>255?255:b;ea[8]=i<0?0:i>255?255:i;ea[9]=j<0?0:j>255?255:j;ea[10]=c<0?0:c>255?255:c;ea[12]=k<0?0:k>255?255:k;ea[13]=l<0?0:l>255?255:l;
+ea[14]=d<0?0:d>255?255:d;qa.putImageData(za,0,0);ua.drawImage(pa,0,0);return ra}function la(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function ma(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function ia(a,b){var c=b.x-a.x,d=b.y-a.y,e=1/Math.sqrt(c*c+d*d);c*=e;d*=e;b.x+=c;b.y+=d;a.x-=c;a.y-=d}var wa,Ha,A,fa,ja,na,xa,U;this.autoClear?this.clear():k.setTransform(1,0,0,-1,n,o);f.data.vertices=0;f.data.faces=0;h=i.projectScene(a,g,this.sortElements);(ya=a.lights.length>0)&&l(a);wa=0;for(Ha=h.length;wa<Ha;wa++){A=
+h[wa];V.empty();if(A instanceof THREE.RenderableParticle){r=A;r.x*=n;r.y*=o;fa=0;for(ja=A.materials.length;fa<ja;)U=A.materials[fa++],U.opacity!=0&&j(r,A,U,a)}else if(A instanceof THREE.RenderableLine){if(r=A.v1,u=A.v2,r.positionScreen.x*=n,r.positionScreen.y*=o,u.positionScreen.x*=n,u.positionScreen.y*=o,V.addPoint(r.positionScreen.x,r.positionScreen.y),V.addPoint(u.positionScreen.x,u.positionScreen.y),ka.instersects(V)){fa=0;for(ja=A.materials.length;fa<ja;)U=A.materials[fa++],U.opacity!=0&&q(r,
+u,A,U,a)}}else if(A instanceof THREE.RenderableFace3){if(r=A.v1,u=A.v2,y=A.v3,r.positionScreen.x*=n,r.positionScreen.y*=o,u.positionScreen.x*=n,u.positionScreen.y*=o,y.positionScreen.x*=n,y.positionScreen.y*=o,A.overdraw&&(ia(r.positionScreen,u.positionScreen),ia(u.positionScreen,y.positionScreen),ia(y.positionScreen,r.positionScreen)),V.add3Points(r.positionScreen.x,r.positionScreen.y,u.positionScreen.x,u.positionScreen.y,y.positionScreen.x,y.positionScreen.y),ka.instersects(V)){fa=0;for(ja=A.meshMaterials.length;fa<
+ja;)if(U=A.meshMaterials[fa++],U instanceof THREE.MeshFaceMaterial){na=0;for(xa=A.faceMaterials.length;na<xa;)(U=A.faceMaterials[na++])&&U.opacity!=0&&s(r,u,y,0,1,2,A,U,a)}else U.opacity!=0&&s(r,u,y,0,1,2,A,U,a)}}else if(A instanceof THREE.RenderableFace4&&(r=A.v1,u=A.v2,y=A.v3,R=A.v4,r.positionScreen.x*=n,r.positionScreen.y*=o,u.positionScreen.x*=n,u.positionScreen.y*=o,y.positionScreen.x*=n,y.positionScreen.y*=o,R.positionScreen.x*=n,R.positionScreen.y*=o,$.positionScreen.copy(u.positionScreen),
+Z.positionScreen.copy(R.positionScreen),A.overdraw&&(ia(r.positionScreen,u.positionScreen),ia(u.positionScreen,R.positionScreen),ia(R.positionScreen,r.positionScreen),ia(y.positionScreen,$.positionScreen),ia(y.positionScreen,Z.positionScreen)),V.addPoint(r.positionScreen.x,r.positionScreen.y),V.addPoint(u.positionScreen.x,u.positionScreen.y),V.addPoint(y.positionScreen.x,y.positionScreen.y),V.addPoint(R.positionScreen.x,R.positionScreen.y),ka.instersects(V))){fa=0;for(ja=A.meshMaterials.length;fa<
+ja;)if(U=A.meshMaterials[fa++],U instanceof THREE.MeshFaceMaterial){na=0;for(xa=A.faceMaterials.length;na<xa;)(U=A.faceMaterials[na++])&&U.opacity!=0&&v(r,u,y,R,$,Z,A,U,a)}else U.opacity!=0&&v(r,u,y,R,$,Z,A,U,a)}da.addRectangle(V)}k.setTransform(1,0,0,1,0,0)}};
 THREE.SoundRenderer=function(){this.volume=1;this.domElement=document.createElement("div");this.domElement.id="THREESound";this.cameraPosition=new THREE.Vector3;this.soundPosition=new THREE.Vector3;this.render=function(a,b,c){c&&a.update(void 0,!1,b);var c=a.sounds,d,e=c.length;for(d=0;d<e;d++)a=c[d],this.soundPosition.set(a.matrixWorld.n14,a.matrixWorld.n24,a.matrixWorld.n34),this.soundPosition.subSelf(b.position),a.isPlaying&&a.isLoaded&&(a.isAddedToDOM||a.addToDOM(this.domElement),a.calculateVolumeAndPan(this.soundPosition))}};
 THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};
 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.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};

+ 46 - 44
build/custom/ThreeDOM.js

@@ -1,6 +1,6 @@
 // ThreeDOM.js r41/ROME - http://github.com/mrdoob/three.js
 var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){this.setHex(a)};
-THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,i;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),i=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=i;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=i;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=i;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
+THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,j;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),j=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=j;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=j;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=j;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
 e,g)},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGB:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},clone:function(){return new THREE.Color(this.hex)}};THREE.Vector2=function(a,b){this.set(a||0,b||0)};
 THREE.Vector2.prototype={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},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;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-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},divideScalar:function(a){a?
 (this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.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(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
@@ -13,44 +13,46 @@ THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
 THREE.Vector4.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},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+=a.x;this.y+=a.y;this.z+=a.z;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-=
 a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,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+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}};THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d;d=c.position.clone().subSelf(a).dot(b);if(d<0)return!1;a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.position.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
-e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,i,k,l,n,j,m,p=a.geometry,
-q=p.vertices,t=[],d=0;for(e=p.faces.length;d<e;d++)if(g=p.faces[d],j=this.origin.clone(),m=this.direction.clone(),k=a.matrixWorld,f=k.multiplyVector3(q[g.a].position.clone()),h=k.multiplyVector3(q[g.b].position.clone()),i=k.multiplyVector3(q[g.c].position.clone()),k=g instanceof THREE.Face4?k.multiplyVector3(q[g.d].position.clone()):null,l=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),n=m.dot(l),a.doubleSided||(a.flipSided?n>0:n<0))if(l=l.dot((new THREE.Vector3).sub(f,j))/n,j=j.addSelf(m.multiplyScalar(l)),
-g instanceof THREE.Face3)c(j,f,h,i)&&(g={distance:this.origin.distanceTo(j),point:j,face:g,object:a},t.push(g));else if(g instanceof THREE.Face4&&(c(j,f,h,k)||c(j,h,i,k)))g={distance:this.origin.distanceTo(j),point:j,face:g,object:a},t.push(g);return t}else return[]}};
-THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,l,n){h=!1;b=f;c=g;d=l;e=n;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
-function(f,g,l,n,j,m){h?(h=!1,b=f<l?f<j?f:j:l<j?l:j,c=g<n?g<m?g:m:n<m?n:m,d=f>l?f>j?f:j:l>j?l:j,e=g>n?g>m?g:m:n>m?n:m):(b=f<l?f<j?f<b?f:b:j<b?j:b:l<j?l<b?l:b:j<b?j:b,c=g<n?g<m?g<c?g:c:m<c?m:c:n<m?n<c?n:c:m<c?m:c,d=f>l?f>j?f>d?f:d:j>d?j:d:l>j?l>d?l:d:j>d?j:d,e=g>n?g>m?g>e?g:e:m>e?m:e:n>m?n>e?n:e:m>e?m:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
+THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
+e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,j,i,k,l,m,n,p=a.geometry,
+q=p.vertices,t=[],d=0;for(e=p.faces.length;d<e;d++)if(g=p.faces[d],m=this.origin.clone(),n=this.direction.clone(),i=a.matrixWorld,f=i.multiplyVector3(q[g.a].position.clone()),h=i.multiplyVector3(q[g.b].position.clone()),j=i.multiplyVector3(q[g.c].position.clone()),i=g instanceof THREE.Face4?i.multiplyVector3(q[g.d].position.clone()):null,k=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),l=n.dot(k),a.doubleSided||(a.flipSided?l>0:l<0))if(k=k.dot((new THREE.Vector3).sub(f,m))/l,m=m.addSelf(n.multiplyScalar(k)),
+g instanceof THREE.Face3)c(m,f,h,j)&&(g={distance:this.origin.distanceTo(m),point:m,face:g,object:a},t.push(g));else if(g instanceof THREE.Face4&&(c(m,f,h,i)||c(m,h,j,i)))g={distance:this.origin.distanceTo(m),point:m,face:g,object:a},t.push(g);return t}else return[]}};
+THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,k,l){h=!1;b=f;c=g;d=k;e=l;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
+function(f,g,k,l,m,n){h?(h=!1,b=f<k?f<m?f:m:k<m?k:m,c=g<l?g<n?g:n:l<n?l:n,d=f>k?f>m?f:m:k>m?k:m,e=g>l?g>n?g:n:l>n?l:n):(b=f<k?f<m?f<b?f:b:m<b?m:b:k<m?k<b?k:b:m<b?m:b,c=g<l?g<n?g<c?g:c:n<c?n:c:l<n?l<c?l:c:n<c?n:c,d=f>k?f>m?f>d?f:d:m>d?m:d:k>m?k>d?k:d:m>d?m:d,e=g>l?g>n?g>e?g:e:n>e?n:e:l>n?l>e?l:e:n>e?n:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
 f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.instersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};THREE.Matrix3=function(){this.m=[]};
-THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;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,f,h,i,k,l,n,j,m,p,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,i||0,k||0,l||1,n||0,j||0,m||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
-THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,i,k,l,n,j,m,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=i;this.n32=k;this.n33=l;this.n34=n;this.n41=j;this.n42=m;this.n43=p;this.n44=q;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){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
+THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;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,f,h,j,i,k,l,m,n,p,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,j||0,i||0,k||1,l||0,m||0,n||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
+THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,j,i,k,l,m,n,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=j;this.n32=i;this.n33=k;this.n34=l;this.n41=m;this.n42=n;this.n43=p;this.n44=q;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){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
 e=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());e.cross(g,d).normalize();this.n11=d.x;this.n12=e.x;this.n13=g.x;this.n21=d.y;this.n22=e.y;this.n23=g.y;this.n31=d.z;this.n32=e.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,e=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*e;a.y=(this.n21*b+this.n22*c+this.n23*
 d+this.n24)*e;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*e;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,e=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*e;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*e;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*e;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*e;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+c*this.n32+d*this.n33;a.normalize();
-return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,i=a.n23,k=a.n24,l=a.n31,n=a.n32,j=a.n33,m=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44,H=b.n11,K=b.n12,A=b.n13,v=b.n14,o=b.n21,I=b.n22,
-z=b.n23,D=b.n24,E=b.n31,O=b.n32,P=b.n33,Q=b.n34;this.n11=c*H+d*o+e*E;this.n12=c*K+d*I+e*O;this.n13=c*A+d*z+e*P;this.n14=c*v+d*D+e*Q+g;this.n21=f*H+h*o+i*E;this.n22=f*K+h*I+i*O;this.n23=f*A+h*z+i*P;this.n24=f*v+h*D+i*Q+k;this.n31=l*H+n*o+j*E;this.n32=l*K+n*I+j*O;this.n33=l*A+n*z+j*P;this.n34=l*v+n*D+j*Q+m;this.n41=p*H+q*o+t*E;this.n42=p*K+q*I+t*O;this.n43=p*A+q*z+t*P;this.n44=p*v+q*D+t*Q+r;return this},multiplyToArray:function(a,b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=
-this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=
-this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,i=this.n31,k=this.n32,l=this.n33,n=this.n34,j=this.n41,m=this.n42,p=this.n43,q=this.n44;return d*f*k*j-c*h*k*j-d*g*l*j+b*h*l*j+c*g*n*j-b*f*n*j-d*f*i*m+c*h*i*m+d*e*l*m-a*h*l*m-c*e*n*m+a*f*n*m+d*g*i*p-b*h*i*p-d*e*k*p+a*h*k*p+b*e*n*p-a*g*n*p-c*g*i*q+b*f*i*q+c*e*k*q-a*f*k*q-b*e*l*q+a*g*l*q},transpose:function(){var a;a=this.n21;this.n21=this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=
-this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;
-this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=
-this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,
-b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX: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},setRotationY: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},setRotationZ: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},setRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,i=e*g,k=e*f;this.set(i*
-g+c,i*f-d*h,i*h+d*f,0,i*f+d*h,k*f+c,k*h-d*g,0,i*h-d*f,k*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;
-this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a){var b=a.x,c=a.y,d=a.z,a=Math.cos(b),b=Math.sin(b),e=Math.cos(c),c=Math.sin(c),g=Math.cos(d),d=Math.sin(d),f=a*c,h=b*c;this.n11=e*g;this.n12=-e*d;this.n13=c;this.n21=h*g+a*d;this.n22=-h*d+a*g;this.n23=-b*e;this.n31=-f*g+b*d;this.n32=f*d+b*g;this.n33=a*e;return this},
-setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,f=c+c,h=d+d,a=b*g,i=b*f;b*=h;var k=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(k+d);this.n12=i-e;this.n13=b+f;this.n21=i+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+k);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=
-a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
-THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,i=a.n23,k=a.n24,l=a.n31,n=a.n32,j=a.n33,m=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=i*m*q-k*j*q+k*n*t-h*m*t-i*n*r+h*j*r;b.n12=g*j*q-e*m*q-g*n*t+d*m*t+e*n*r-d*j*r;b.n13=e*k*q-g*i*q+g*h*t-d*k*t-e*h*r+d*i*r;b.n14=g*i*n-e*k*n-g*h*j+d*k*j+e*h*m-d*i*m;b.n21=k*j*p-i*m*p-k*l*t+f*m*t+i*l*r-f*j*r;b.n22=e*m*p-g*j*p+g*l*t-c*m*t-e*l*r+c*j*r;b.n23=g*i*p-e*k*p-g*f*t+c*k*t+e*f*r-c*i*r;b.n24=
-e*k*l-g*i*l+g*f*j-c*k*j-e*f*m+c*i*m;b.n31=h*m*p-k*n*p+k*l*q-f*m*q-h*l*r+f*n*r;b.n32=g*n*p-d*m*p-g*l*q+c*m*q+d*l*r-c*n*r;b.n33=e*k*p-g*h*p+g*f*q-c*k*q-d*f*r+c*h*r;b.n34=g*h*l-d*k*l-g*f*n+c*k*n+d*f*m-c*h*m;b.n41=i*n*p-h*j*p-i*l*q+f*j*q+h*l*t-f*n*t;b.n42=d*j*p-e*n*p+e*l*q-c*j*q-d*l*t+c*n*t;b.n43=e*h*p-d*i*p-e*f*q+c*i*q+d*f*t-c*h*t;b.n44=d*i*l-e*h*l+e*f*n-c*i*n-d*f*j+c*h*j;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,i=-a.n32*a.n11+a.n31*a.n12,k=a.n23*a.n12-a.n22*a.n13,l=-a.n23*a.n11+a.n21*a.n13,n=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*k;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*i;c[6]=a*k;c[7]=a*l;c[8]=a*n;return b};
+return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,i=a.n24,k=a.n31,l=a.n32,m=a.n33,n=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44,J=b.n11,M=b.n12,G=b.n13,v=b.n14,o=b.n21,K=b.n22,
+z=b.n23,C=b.n24,D=b.n31,Q=b.n32,R=b.n33,S=b.n34,H=b.n41,T=b.n42,O=b.n43,E=b.n44;this.n11=c*J+d*o+e*D+g*H;this.n12=c*M+d*K+e*Q+g*T;this.n13=c*G+d*z+e*R+g*O;this.n14=c*v+d*C+e*S+g*E;this.n21=f*J+h*o+j*D+i*H;this.n22=f*M+h*K+j*Q+i*T;this.n23=f*G+h*z+j*R+i*O;this.n24=f*v+h*C+j*S+i*E;this.n31=k*J+l*o+m*D+n*H;this.n32=k*M+l*K+m*Q+n*T;this.n33=k*G+l*z+m*R+n*O;this.n34=k*v+l*C+m*S+n*E;this.n41=p*J+q*o+t*D+r*H;this.n42=p*M+q*K+t*Q+r*T;this.n43=p*G+q*z+t*R+r*O;this.n44=p*v+q*C+t*S+r*E;return this},multiplyToArray:function(a,
+b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
+a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,j=this.n31,i=this.n32,k=this.n33,l=this.n34,m=this.n41,n=this.n42,p=this.n43,q=this.n44;return d*f*i*m-c*h*i*m-d*g*k*m+b*h*k*m+c*g*l*m-b*f*l*m-d*f*j*n+c*h*j*n+d*e*k*n-a*h*k*n-c*e*l*n+a*f*l*n+d*g*j*p-b*h*j*p-d*e*i*p+a*h*i*p+b*e*l*p-a*g*l*p-c*g*j*q+b*f*j*q+c*e*i*q-a*f*i*q-b*e*k*q+a*g*k*q},transpose:function(){var a;a=this.n21;this.n21=
+this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=
+this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=
+this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,
+b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX: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},setRotationY: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},setRotationZ: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},setRotationAxis:function(a,
+b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,j=e*g,i=e*f;this.set(j*g+c,j*f-d*h,j*h+d*f,0,j*f+d*h,i*f+c,i*h-d*g,0,j*h-d*f,i*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);
+return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,e=a.z,g=Math.cos(c),c=Math.sin(c),f=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e);switch(b){case "YXZ":var j=f*h,i=f*e,k=d*h,l=d*e;this.n11=j+l*c;this.n12=
+k*c-i;this.n13=g*d;this.n21=g*e;this.n22=g*h;this.n23=-c;this.n31=i*c-k;this.n32=l+j*c;this.n33=g*f;break;case "ZXY":j=f*h;i=f*e;k=d*h;l=d*e;this.n11=j-l*c;this.n12=-g*e;this.n13=k+i*c;this.n21=i+k*c;this.n22=g*h;this.n23=l-j*c;this.n31=-g*d;this.n32=c;this.n33=g*f;break;case "ZYX":j=g*h;i=g*e;k=c*h;l=c*e;this.n11=f*h;this.n12=k*d-i;this.n13=j*d+l;this.n21=f*e;this.n22=l*d+j;this.n23=i*d-k;this.n31=-d;this.n32=c*f;this.n33=g*f;break;case "YZX":j=g*f;i=g*d;k=c*f;l=c*d;this.n11=f*h;this.n12=l-j*e;this.n13=
+k*e+i;this.n21=e;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=i*e+k;this.n33=j-l*e;break;case "XZY":j=g*f;i=g*d;k=c*f;l=c*d;this.n11=f*h;this.n12=-e;this.n13=d*h;this.n21=j*e+l;this.n22=g*h;this.n23=i*e-k;this.n31=k*e-i;this.n32=c*h;this.n33=l*e+j;break;default:j=g*h,i=g*e,k=c*h,l=c*e,this.n11=f*h,this.n12=-f*e,this.n13=d,this.n21=i+k*d,this.n22=j-l*d,this.n23=-c*f,this.n31=l-j*d,this.n32=k+i*d,this.n33=g*f}return this},setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,
+f=c+c,h=d+d,a=b*g,j=b*f;b*=h;var i=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(i+d);this.n12=j-e;this.n13=b+f;this.n21=j+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+i);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,
+b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
+THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,i=a.n24,k=a.n31,l=a.n32,m=a.n33,n=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=j*n*q-i*m*q+i*l*t-h*n*t-j*l*r+h*m*r;b.n12=g*m*q-e*n*q-g*l*t+d*n*t+e*l*r-d*m*r;b.n13=e*i*q-g*j*q+g*h*t-d*i*t-e*h*r+d*j*r;b.n14=g*j*l-e*i*l-g*h*m+d*i*m+e*h*n-d*j*n;b.n21=i*m*p-j*n*p-i*k*t+f*n*t+j*k*r-f*m*r;b.n22=e*n*p-g*m*p+g*k*t-c*n*t-e*k*r+c*m*r;b.n23=g*j*p-e*i*p-g*f*t+c*i*t+e*f*r-c*j*r;b.n24=
+e*i*k-g*j*k+g*f*m-c*i*m-e*f*n+c*j*n;b.n31=h*n*p-i*l*p+i*k*q-f*n*q-h*k*r+f*l*r;b.n32=g*l*p-d*n*p-g*k*q+c*n*q+d*k*r-c*l*r;b.n33=e*i*p-g*h*p+g*f*q-c*i*q-d*f*r+c*h*r;b.n34=g*h*k-d*i*k-g*f*l+c*i*l+d*f*n-c*h*n;b.n41=j*l*p-h*m*p-j*k*q+f*m*q+h*k*t-f*l*t;b.n42=d*m*p-e*l*p+e*k*q-c*m*q-d*k*t+c*l*t;b.n43=e*h*p-d*j*p-e*f*q+c*j*q+d*f*t-c*h*t;b.n44=d*j*k-e*h*k+e*f*l-c*j*l-d*f*m+c*h*m;b.multiplyScalar(1/a.determinant());return b};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,j=-a.n32*a.n11+a.n31*a.n12,i=a.n23*a.n12-a.n22*a.n13,k=-a.n23*a.n11+a.n21*a.n13,l=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*i;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*j;c[6]=a*i;c[7]=a*k;c[8]=a*l;return b};
 THREE.Matrix4.makeFrustum=function(a,b,c,d,e,g){var f;f=new THREE.Matrix4;f.n11=2*e/(b-a);f.n12=0;f.n13=(b+a)/(b-a);f.n14=0;f.n21=0;f.n22=2*e/(d-c);f.n23=(d+c)/(d-c);f.n24=0;f.n31=0;f.n32=0;f.n33=-(g+e)/(g-e);f.n34=-2*g*e/(g-e);f.n41=0;f.n42=0;f.n43=-1;f.n44=0;return f};THREE.Matrix4.makePerspective=function(a,b,c,d){var e,a=c*Math.tan(a*Math.PI/360);e=-a;return THREE.Matrix4.makeFrustum(e*b,a*b,e,a,c,d)};
-THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,i,k;f=new THREE.Matrix4;h=b-a;i=c-d;k=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/i;f.n23=0;f.n24=-((c+d)/i);f.n31=0;f.n32=0;f.n33=-2/k;f.n34=-((g+e)/k);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
-THREE.Object3D=function(){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.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;this.useQuaternion=!1;this.boundRadius=
-0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
+THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,j,i;f=new THREE.Matrix4;h=b-a;j=c-d;i=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/j;f.n23=0;f.n24=-((c+d)/j);f.n31=0;f.n32=0;f.n33=-2/i;f.n34=-((g+e)/i);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
+THREE.Object3D=function(){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=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;
+this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
 THREE.Object3D.prototype={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.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
 -1){a.parent!==void 0&&a.parent.removeChild(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.addChildRecurse(a)}},removeChild:function(a){var b=this.children.indexOf(a);if(b!==-1)a.parent=void 0,this.children.splice(b,1)},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c<d;c++){e=this.children[c];if(e.name===a)return e;if(b&&(e=e.getChildByName(a,b),e!==void 0))return e}},updateMatrix:function(){this.matrix.setPosition(this.position);
-this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation);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=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixRotationWorld.extractRotation(this.matrixWorld,
-this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
+this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):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=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),
+this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
 THREE.Quaternion.prototype={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=0.5*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),f=a*b,h=d*e;this.w=f*g-h*c;this.x=f*c+h*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},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*=-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 a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},
-multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;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},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,i=this.w,k=i*c+f*e-h*d,l=
-i*d+h*c-g*e,n=i*e+g*d-f*c,c=-g*c-f*d-h*e;b.x=k*i+c*-g+l*-h-n*-f;b.y=l*i+c*-f+n*-g-k*-h;b.z=n*i+c*-h+k*-f-l*-g;return b}};
+multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;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},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,j=this.w,i=j*c+f*e-h*d,k=
+j*d+h*c-g*e,l=j*e+g*d-f*c,c=-g*c-f*d-h*e;b.x=i*j+c*-g+k*-h-l*-f;b.y=k*j+c*-f+l*-g-i*-h;b.z=l*j+c*-h+i*-f-k*-g;return b}};
 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(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.0010)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
 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.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
 THREE.Face4=function(a,b,c,d,e,g,f){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=f instanceof Array?f:[f];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.set(a||0,b||0)};
@@ -68,21 +70,21 @@ b.indexOf(".ogg")!==-1?e="audio/ogg":b.indexOf(".wav")!==-1&&(e="audio/wav"),thi
 THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded)this.removeEventListener("canplay",this.onLoad,!0),a.isLoaded=!0,a.duration=this.duration,a.isPlaying&&a.play()};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded&&(this.domElement.play(),a))this.domElement.currentTime=a%this.duration};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
 THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
 THREE.Sound.prototype.update=function(a,b,c){this.matrixAutoUpdate&&(this.matrix.setPosition(this.position),b=!0);if(b||this.matrixWorldNeedsUpdate)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,b=!0;for(var d=this.children.length,a=0;a<d;a++)this.children[a].update(this.matrixWorld,b,c)};
-THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
+THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.overrideMaterial=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
 THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1)this.objects.push(a),this.__objectsAdded.push(a);for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
 THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else a instanceof THREE.Sound?(b=this.sounds.indexOf(a),b!==-1&&this.sounds.splice(b,1)):a instanceof THREE.Camera||(b=this.objects.indexOf(a),b!==-1&&(this.objects.splice(b,1),this.__objectsRemoved.push(a)));for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
 THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
-THREE.Projector=function(){function a(){var a=i[h]=i[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(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))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,e,g=[],f,h,i=[],k,l,n=[],j,m=[],p,q,t=[],r,H,K=[],A=new THREE.Vector4,v=new THREE.Vector4,
-o=new THREE.Matrix4,I=new THREE.Matrix4,z=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],D=new THREE.Vector4,E=new THREE.Vector4;this.projectVector=function(a,b){o.multiply(b.projectionMatrix,b.matrixWorldInverse);o.multiplyVector3(a);return a};this.unprojectVector=function(a,b){o.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));o.multiplyVector3(a);return a};this.projectObjects=function(a,c,f){var c=[],h,k,i;e=0;k=
-a.objects;a=0;for(h=k.length;a<h;a++){i=k[a];var j;if(!(j=!i.visible))if(j=i instanceof THREE.Mesh){a:{j=void 0;for(var l=i.matrixWorld,n=-i.geometry.boundingSphere.radius*Math.max(i.scale.x,Math.max(i.scale.y,i.scale.z)),m=0;m<6;m++)if(j=z[m].x*l.n14+z[m].y*l.n24+z[m].z*l.n34+z[m].w,j<=n){j=!1;break a}j=!0}j=!j}if(!j)j=g[e]=g[e]||new THREE.RenderableObject,e++,d=j,A.copy(i.position),o.multiplyVector3(A),d.object=i,d.z=A.z,c.push(d)}f&&c.sort(b);return c};this.projectScene=function(d,e,g){var A=[],
-V=e.near,W=e.far,M,G,x,C,s,y,w,B,F,u,J,R,T,U,L,S,N;H=q=j=l=0;e.matrixAutoUpdate&&e.update(void 0,!0);d.update(void 0,!1,e);o.multiply(e.projectionMatrix,e.matrixWorldInverse);z[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);z[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);z[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);z[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);z[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);z[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+
-o.n33,o.n44+o.n34);for(M=0;M<6;M++)F=z[M],F.divideScalar(Math.sqrt(F.x*F.x+F.y*F.y+F.z*F.z));F=this.projectObjects(d,e,!0);d=0;for(M=F.length;d<M;d++)if(u=F[d].object,u.visible)if(J=u.matrixWorld,R=u.matrixRotationWorld,T=u.materials,U=u.overdraw,h=0,u instanceof THREE.Mesh){L=u.geometry;C=L.vertices;S=L.faces;L=L.faceVertexUvs;G=0;for(x=C.length;G<x;G++)f=a(),f.positionWorld.copy(C[G].position),J.multiplyVector3(f.positionWorld),f.positionScreen.copy(f.positionWorld),o.multiplyVector4(f.positionScreen),
-f.positionScreen.x/=f.positionScreen.w,f.positionScreen.y/=f.positionScreen.w,f.visible=f.positionScreen.z>V&&f.positionScreen.z<W;C=0;for(G=S.length;C<G;C++){x=S[C];if(x instanceof THREE.Face3)if(s=i[x.a],y=i[x.b],w=i[x.c],s.visible&&y.visible&&w.visible&&(u.doubleSided||u.flipSided!=(w.positionScreen.x-s.positionScreen.x)*(y.positionScreen.y-s.positionScreen.y)-(w.positionScreen.y-s.positionScreen.y)*(y.positionScreen.x-s.positionScreen.x)<0))B=n[l]=n[l]||new THREE.RenderableFace3,l++,k=B,k.v1.copy(s),
-k.v2.copy(y),k.v3.copy(w);else continue;else if(x instanceof THREE.Face4)if(s=i[x.a],y=i[x.b],w=i[x.c],B=i[x.d],s.visible&&y.visible&&w.visible&&B.visible&&(u.doubleSided||u.flipSided!=((B.positionScreen.x-s.positionScreen.x)*(y.positionScreen.y-s.positionScreen.y)-(B.positionScreen.y-s.positionScreen.y)*(y.positionScreen.x-s.positionScreen.x)<0||(y.positionScreen.x-w.positionScreen.x)*(B.positionScreen.y-w.positionScreen.y)-(y.positionScreen.y-w.positionScreen.y)*(B.positionScreen.x-w.positionScreen.x)<
-0)))N=m[j]=m[j]||new THREE.RenderableFace4,j++,k=N,k.v1.copy(s),k.v2.copy(y),k.v3.copy(w),k.v4.copy(B);else continue;k.normalWorld.copy(x.normal);R.multiplyVector3(k.normalWorld);k.centroidWorld.copy(x.centroid);J.multiplyVector3(k.centroidWorld);k.centroidScreen.copy(k.centroidWorld);o.multiplyVector3(k.centroidScreen);w=x.vertexNormals;s=0;for(y=w.length;s<y;s++)B=k.vertexNormalsWorld[s],B.copy(w[s]),R.multiplyVector3(B);s=0;for(y=L.length;s<y;s++)if(N=L[s][C]){w=0;for(B=N.length;w<B;w++)k.uvs[s][w]=
-N[w]}k.meshMaterials=T;k.faceMaterials=x.materials;k.overdraw=U;k.z=k.centroidScreen.z;A.push(k)}}else if(u instanceof THREE.Line){I.multiply(o,J);C=u.geometry.vertices;s=a();s.positionScreen.copy(C[0].position);I.multiplyVector4(s.positionScreen);G=1;for(x=C.length;G<x;G++)if(s=a(),s.positionScreen.copy(C[G].position),I.multiplyVector4(s.positionScreen),y=i[h-2],D.copy(s.positionScreen),E.copy(y.positionScreen),c(D,E))D.multiplyScalar(1/D.w),E.multiplyScalar(1/E.w),J=t[q]=t[q]||new THREE.RenderableLine,
-q++,p=J,p.v1.positionScreen.copy(D),p.v2.positionScreen.copy(E),p.z=Math.max(D.z,E.z),p.materials=u.materials,A.push(p)}else if(u instanceof THREE.Particle&&(v.set(u.matrixWorld.n14,u.matrixWorld.n24,u.matrixWorld.n34,1),o.multiplyVector4(v),v.z/=v.w,v.z>0&&v.z<1))J=K[H]=K[H]||new THREE.RenderableParticle,H++,r=J,r.x=v.x/v.w,r.y=v.y/v.w,r.z=v.z,r.rotation=u.rotation.z,r.scale.x=u.scale.x*Math.abs(r.x-(v.x+e.projectionMatrix.n11)/(v.w+e.projectionMatrix.n14)),r.scale.y=u.scale.y*Math.abs(r.y-(v.y+
-e.projectionMatrix.n22)/(v.w+e.projectionMatrix.n24)),r.materials=u.materials,A.push(r);g&&A.sort(b);return A}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,c,d,e,g;this.domElement=document.createElement("div");this.setSize=function(a,b){c=a;d=b;e=c/2;g=d/2};this.render=function(c,d){var i,k,l,n,j,m,p,q;a=b.projectScene(c,d);i=0;for(k=a.length;i<k;i++)if(j=a[i],j instanceof THREE.RenderableParticle){p=j.x*e+e;q=j.y*g+g;l=0;for(n=j.material.length;l<n;l++)if(m=j.material[l],m instanceof THREE.ParticleDOMMaterial)m=m.domElement,m.style.left=p+"px",m.style.top=q+"px"}}};
+THREE.Projector=function(){function a(){var a=j[h]=j[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(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))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,e,g=[],f,h,j=[],i,k,l=[],m,n=[],p,q,t=[],r,J,M=[],G=new THREE.Vector4,v=new THREE.Vector4,
+o=new THREE.Matrix4,K=new THREE.Matrix4,z=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],C=new THREE.Vector4,D=new THREE.Vector4;this.projectVector=function(a,b){o.multiply(b.projectionMatrix,b.matrixWorldInverse);o.multiplyVector3(a);return a};this.unprojectVector=function(a,b){o.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));o.multiplyVector3(a);return a};this.projectObjects=function(a,c,f){var c=[],h,i,j;e=0;i=
+a.objects;a=0;for(h=i.length;a<h;a++){j=i[a];var k;if(!(k=!j.visible))if(k=j instanceof THREE.Mesh){a:{k=void 0;for(var l=j.matrixWorld,m=-j.geometry.boundingSphere.radius*Math.max(j.scale.x,Math.max(j.scale.y,j.scale.z)),n=0;n<6;n++)if(k=z[n].x*l.n14+z[n].y*l.n24+z[n].z*l.n34+z[n].w,k<=m){k=!1;break a}k=!0}k=!k}if(!k)k=g[e]=g[e]||new THREE.RenderableObject,e++,d=k,G.copy(j.position),o.multiplyVector3(G),d.object=j,d.z=G.z,c.push(d)}f&&c.sort(b);return c};this.projectScene=function(d,e,g){var H=[],
+G=e.near,O=e.far,E,I,x,B,s,y,w,A,F,u,L,U,W,X,N,V,P;J=q=m=k=0;e.matrixAutoUpdate&&e.update(void 0,!0);d.update(void 0,!1,e);o.multiply(e.projectionMatrix,e.matrixWorldInverse);z[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);z[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);z[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);z[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);z[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);z[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+
+o.n33,o.n44+o.n34);for(E=0;E<6;E++)F=z[E],F.divideScalar(Math.sqrt(F.x*F.x+F.y*F.y+F.z*F.z));F=this.projectObjects(d,e,!0);d=0;for(E=F.length;d<E;d++)if(u=F[d].object,u.visible)if(L=u.matrixWorld,U=u.matrixRotationWorld,W=u.materials,X=u.overdraw,h=0,u instanceof THREE.Mesh){N=u.geometry;B=N.vertices;V=N.faces;N=N.faceVertexUvs;I=0;for(x=B.length;I<x;I++)f=a(),f.positionWorld.copy(B[I].position),L.multiplyVector3(f.positionWorld),f.positionScreen.copy(f.positionWorld),o.multiplyVector4(f.positionScreen),
+f.positionScreen.x/=f.positionScreen.w,f.positionScreen.y/=f.positionScreen.w,f.visible=f.positionScreen.z>G&&f.positionScreen.z<O;B=0;for(I=V.length;B<I;B++){x=V[B];if(x instanceof THREE.Face3)if(s=j[x.a],y=j[x.b],w=j[x.c],s.visible&&y.visible&&w.visible&&(u.doubleSided||u.flipSided!=(w.positionScreen.x-s.positionScreen.x)*(y.positionScreen.y-s.positionScreen.y)-(w.positionScreen.y-s.positionScreen.y)*(y.positionScreen.x-s.positionScreen.x)<0))A=l[k]=l[k]||new THREE.RenderableFace3,k++,i=A,i.v1.copy(s),
+i.v2.copy(y),i.v3.copy(w);else continue;else if(x instanceof THREE.Face4)if(s=j[x.a],y=j[x.b],w=j[x.c],A=j[x.d],s.visible&&y.visible&&w.visible&&A.visible&&(u.doubleSided||u.flipSided!=((A.positionScreen.x-s.positionScreen.x)*(y.positionScreen.y-s.positionScreen.y)-(A.positionScreen.y-s.positionScreen.y)*(y.positionScreen.x-s.positionScreen.x)<0||(y.positionScreen.x-w.positionScreen.x)*(A.positionScreen.y-w.positionScreen.y)-(y.positionScreen.y-w.positionScreen.y)*(A.positionScreen.x-w.positionScreen.x)<
+0)))P=n[m]=n[m]||new THREE.RenderableFace4,m++,i=P,i.v1.copy(s),i.v2.copy(y),i.v3.copy(w),i.v4.copy(A);else continue;i.normalWorld.copy(x.normal);U.multiplyVector3(i.normalWorld);i.centroidWorld.copy(x.centroid);L.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);o.multiplyVector3(i.centroidScreen);w=x.vertexNormals;s=0;for(y=w.length;s<y;s++)A=i.vertexNormalsWorld[s],A.copy(w[s]),U.multiplyVector3(A);s=0;for(y=N.length;s<y;s++)if(P=N[s][B]){w=0;for(A=P.length;w<A;w++)i.uvs[s][w]=
+P[w]}i.meshMaterials=W;i.faceMaterials=x.materials;i.overdraw=X;i.z=i.centroidScreen.z;H.push(i)}}else if(u instanceof THREE.Line){K.multiply(o,L);B=u.geometry.vertices;s=a();s.positionScreen.copy(B[0].position);K.multiplyVector4(s.positionScreen);I=1;for(x=B.length;I<x;I++)if(s=a(),s.positionScreen.copy(B[I].position),K.multiplyVector4(s.positionScreen),y=j[h-2],C.copy(s.positionScreen),D.copy(y.positionScreen),c(C,D))C.multiplyScalar(1/C.w),D.multiplyScalar(1/D.w),L=t[q]=t[q]||new THREE.RenderableLine,
+q++,p=L,p.v1.positionScreen.copy(C),p.v2.positionScreen.copy(D),p.z=Math.max(C.z,D.z),p.materials=u.materials,H.push(p)}else if(u instanceof THREE.Particle&&(v.set(u.matrixWorld.n14,u.matrixWorld.n24,u.matrixWorld.n34,1),o.multiplyVector4(v),v.z/=v.w,v.z>0&&v.z<1))L=M[J]=M[J]||new THREE.RenderableParticle,J++,r=L,r.x=v.x/v.w,r.y=v.y/v.w,r.z=v.z,r.rotation=u.rotation.z,r.scale.x=u.scale.x*Math.abs(r.x-(v.x+e.projectionMatrix.n11)/(v.w+e.projectionMatrix.n14)),r.scale.y=u.scale.y*Math.abs(r.y-(v.y+
+e.projectionMatrix.n22)/(v.w+e.projectionMatrix.n24)),r.materials=u.materials,H.push(r);g&&H.sort(b);return H}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,c,d,e,g;this.domElement=document.createElement("div");this.setSize=function(a,b){c=a;d=b;e=c/2;g=d/2};this.render=function(c,d){var j,i,k,l,m,n,p,q;a=b.projectScene(c,d);j=0;for(i=a.length;j<i;j++)if(m=a[j],m instanceof THREE.RenderableParticle){p=m.x*e+e;q=m.y*g+g;k=0;for(l=m.material.length;k<l;k++)if(n=m.material[k],n instanceof THREE.ParticleDOMMaterial)n=n.domElement,n.style.left=p+"px",n.style.top=q+"px"}}};
 THREE.SoundRenderer=function(){this.volume=1;this.domElement=document.createElement("div");this.domElement.id="THREESound";this.cameraPosition=new THREE.Vector3;this.soundPosition=new THREE.Vector3;this.render=function(a,b,c){c&&a.update(void 0,!1,b);var c=a.sounds,d,e=c.length;for(d=0;d<e;d++)a=c[d],this.soundPosition.set(a.matrixWorld.n14,a.matrixWorld.n24,a.matrixWorld.n34),this.soundPosition.subSelf(b.position),a.isPlaying&&a.isLoaded&&(a.isAddedToDOM||a.addToDOM(this.domElement),a.calculateVolumeAndPan(this.soundPosition))}};
 THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};

File diff suppressed because it is too large
+ 9 - 10
build/custom/ThreeExtras.js


+ 65 - 62
build/custom/ThreeSVG.js

@@ -1,6 +1,6 @@
 // ThreeSVG.js r41/ROME - http://github.com/mrdoob/three.js
 var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){this.setHex(a)};
-THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,i;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),i=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=i;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=i;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=i;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
+THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,k;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),k=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=k;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=k;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=k;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
 e,g)},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGB:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},clone:function(){return new THREE.Color(this.hex)}};THREE.Vector2=function(a,b){this.set(a||0,b||0)};
 THREE.Vector2.prototype={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},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;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-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},divideScalar:function(a){a?
 (this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.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(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
@@ -13,55 +13,57 @@ THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
 THREE.Vector4.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},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+=a.x;this.y+=a.y;this.z+=a.z;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-=
 a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,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+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}};THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d;d=c.position.clone().subSelf(a).dot(b);if(d<0)return!1;a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.position.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
-e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,i,l,k,n,j,o,p=a.geometry,
-q=p.vertices,t=[],d=0;for(e=p.faces.length;d<e;d++)if(g=p.faces[d],j=this.origin.clone(),o=this.direction.clone(),l=a.matrixWorld,f=l.multiplyVector3(q[g.a].position.clone()),h=l.multiplyVector3(q[g.b].position.clone()),i=l.multiplyVector3(q[g.c].position.clone()),l=g instanceof THREE.Face4?l.multiplyVector3(q[g.d].position.clone()):null,k=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),n=o.dot(k),a.doubleSided||(a.flipSided?n>0:n<0))if(k=k.dot((new THREE.Vector3).sub(f,j))/n,j=j.addSelf(o.multiplyScalar(k)),
-g instanceof THREE.Face3)c(j,f,h,i)&&(g={distance:this.origin.distanceTo(j),point:j,face:g,object:a},t.push(g));else if(g instanceof THREE.Face4&&(c(j,f,h,l)||c(j,h,i,l)))g={distance:this.origin.distanceTo(j),point:j,face:g,object:a},t.push(g);return t}else return[]}};
-THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,k,n){h=!1;b=f;c=g;d=k;e=n;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
-function(f,g,k,n,j,o){h?(h=!1,b=f<k?f<j?f:j:k<j?k:j,c=g<n?g<o?g:o:n<o?n:o,d=f>k?f>j?f:j:k>j?k:j,e=g>n?g>o?g:o:n>o?n:o):(b=f<k?f<j?f<b?f:b:j<b?j:b:k<j?k<b?k:b:j<b?j:b,c=g<n?g<o?g<c?g:c:o<c?o:c:n<o?n<c?n:c:o<c?o:c,d=f>k?f>j?f>d?f:d:j>d?j:d:k>j?k>d?k:d:j>d?j:d,e=g>n?g>o?g>e?g:e:o>e?o:e:n>o?n>e?n:e:o>e?o:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
+THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
+e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,k,l,i,j,n,o,p=a.geometry,
+q=p.vertices,t=[],d=0;for(e=p.faces.length;d<e;d++)if(g=p.faces[d],n=this.origin.clone(),o=this.direction.clone(),l=a.matrixWorld,f=l.multiplyVector3(q[g.a].position.clone()),h=l.multiplyVector3(q[g.b].position.clone()),k=l.multiplyVector3(q[g.c].position.clone()),l=g instanceof THREE.Face4?l.multiplyVector3(q[g.d].position.clone()):null,i=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),j=o.dot(i),a.doubleSided||(a.flipSided?j>0:j<0))if(i=i.dot((new THREE.Vector3).sub(f,n))/j,n=n.addSelf(o.multiplyScalar(i)),
+g instanceof THREE.Face3)c(n,f,h,k)&&(g={distance:this.origin.distanceTo(n),point:n,face:g,object:a},t.push(g));else if(g instanceof THREE.Face4&&(c(n,f,h,l)||c(n,h,k,l)))g={distance:this.origin.distanceTo(n),point:n,face:g,object:a},t.push(g);return t}else return[]}};
+THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,i,j){h=!1;b=f;c=g;d=i;e=j;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
+function(f,g,i,j,n,o){h?(h=!1,b=f<i?f<n?f:n:i<n?i:n,c=g<j?g<o?g:o:j<o?j:o,d=f>i?f>n?f:n:i>n?i:n,e=g>j?g>o?g:o:j>o?j:o):(b=f<i?f<n?f<b?f:b:n<b?n:b:i<n?i<b?i:b:n<b?n:b,c=g<j?g<o?g<c?g:c:o<c?o:c:j<o?j<c?j:c:o<c?o:c,d=f>i?f>n?f>d?f:d:n>d?n:d:i>n?i>d?i:d:n>d?n:d,e=g>j?g>o?g>e?g:e:o>e?o:e:j>o?j>e?j:e:o>e?o:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
 f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.instersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};THREE.Matrix3=function(){this.m=[]};
-THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;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,f,h,i,l,k,n,j,o,p,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,i||0,l||0,k||1,n||0,j||0,o||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
-THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,i,l,k,n,j,o,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=i;this.n32=l;this.n33=k;this.n34=n;this.n41=j;this.n42=o;this.n43=p;this.n44=q;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){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
+THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;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,f,h,k,l,i,j,n,o,p,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,k||0,l||0,i||1,j||0,n||0,o||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
+THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,k,l,i,j,n,o,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=k;this.n32=l;this.n33=i;this.n34=j;this.n41=n;this.n42=o;this.n43=p;this.n44=q;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){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
 e=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());e.cross(g,d).normalize();this.n11=d.x;this.n12=e.x;this.n13=g.x;this.n21=d.y;this.n22=e.y;this.n23=g.y;this.n31=d.z;this.n32=e.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,e=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*e;a.y=(this.n21*b+this.n22*c+this.n23*
 d+this.n24)*e;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*e;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,e=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*e;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*e;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*e;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*e;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+c*this.n32+d*this.n33;a.normalize();
-return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,i=a.n23,l=a.n24,k=a.n31,n=a.n32,j=a.n33,o=a.n34,p=a.n41,q=a.n42,t=a.n43,u=a.n44,G=b.n11,y=b.n12,E=b.n13,r=b.n14,m=b.n21,z=b.n22,
-A=b.n23,C=b.n24,v=b.n31,L=b.n32,F=b.n33,J=b.n34;this.n11=c*G+d*m+e*v;this.n12=c*y+d*z+e*L;this.n13=c*E+d*A+e*F;this.n14=c*r+d*C+e*J+g;this.n21=f*G+h*m+i*v;this.n22=f*y+h*z+i*L;this.n23=f*E+h*A+i*F;this.n24=f*r+h*C+i*J+l;this.n31=k*G+n*m+j*v;this.n32=k*y+n*z+j*L;this.n33=k*E+n*A+j*F;this.n34=k*r+n*C+j*J+o;this.n41=p*G+q*m+t*v;this.n42=p*y+q*z+t*L;this.n43=p*E+q*A+t*F;this.n44=p*r+q*C+t*J+u;return this},multiplyToArray:function(a,b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=
-this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=
-this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,i=this.n31,l=this.n32,k=this.n33,n=this.n34,j=this.n41,o=this.n42,p=this.n43,q=this.n44;return d*f*l*j-c*h*l*j-d*g*k*j+b*h*k*j+c*g*n*j-b*f*n*j-d*f*i*o+c*h*i*o+d*e*k*o-a*h*k*o-c*e*n*o+a*f*n*o+d*g*i*p-b*h*i*p-d*e*l*p+a*h*l*p+b*e*n*p-a*g*n*p-c*g*i*q+b*f*i*q+c*e*l*q-a*f*l*q-b*e*k*q+a*g*k*q},transpose:function(){var a;a=this.n21;this.n21=this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=
-this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;
-this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=
-this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,
-b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX: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},setRotationY: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},setRotationZ: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},setRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,i=e*g,l=e*f;this.set(i*
-g+c,i*f-d*h,i*h+d*f,0,i*f+d*h,l*f+c,l*h-d*g,0,i*h-d*f,l*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;
-this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a){var b=a.x,c=a.y,d=a.z,a=Math.cos(b),b=Math.sin(b),e=Math.cos(c),c=Math.sin(c),g=Math.cos(d),d=Math.sin(d),f=a*c,h=b*c;this.n11=e*g;this.n12=-e*d;this.n13=c;this.n21=h*g+a*d;this.n22=-h*d+a*g;this.n23=-b*e;this.n31=-f*g+b*d;this.n32=f*d+b*g;this.n33=a*e;return this},
-setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,f=c+c,h=d+d,a=b*g,i=b*f;b*=h;var l=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(l+d);this.n12=i-e;this.n13=b+f;this.n21=i+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+l);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=
-a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
-THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,i=a.n23,l=a.n24,k=a.n31,n=a.n32,j=a.n33,o=a.n34,p=a.n41,q=a.n42,t=a.n43,u=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=i*o*q-l*j*q+l*n*t-h*o*t-i*n*u+h*j*u;b.n12=g*j*q-e*o*q-g*n*t+d*o*t+e*n*u-d*j*u;b.n13=e*l*q-g*i*q+g*h*t-d*l*t-e*h*u+d*i*u;b.n14=g*i*n-e*l*n-g*h*j+d*l*j+e*h*o-d*i*o;b.n21=l*j*p-i*o*p-l*k*t+f*o*t+i*k*u-f*j*u;b.n22=e*o*p-g*j*p+g*k*t-c*o*t-e*k*u+c*j*u;b.n23=g*i*p-e*l*p-g*f*t+c*l*t+e*f*u-c*i*u;b.n24=
-e*l*k-g*i*k+g*f*j-c*l*j-e*f*o+c*i*o;b.n31=h*o*p-l*n*p+l*k*q-f*o*q-h*k*u+f*n*u;b.n32=g*n*p-d*o*p-g*k*q+c*o*q+d*k*u-c*n*u;b.n33=e*l*p-g*h*p+g*f*q-c*l*q-d*f*u+c*h*u;b.n34=g*h*k-d*l*k-g*f*n+c*l*n+d*f*o-c*h*o;b.n41=i*n*p-h*j*p-i*k*q+f*j*q+h*k*t-f*n*t;b.n42=d*j*p-e*n*p+e*k*q-c*j*q-d*k*t+c*n*t;b.n43=e*h*p-d*i*p-e*f*q+c*i*q+d*f*t-c*h*t;b.n44=d*i*k-e*h*k+e*f*n-c*i*n-d*f*j+c*h*j;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,i=-a.n32*a.n11+a.n31*a.n12,l=a.n23*a.n12-a.n22*a.n13,k=-a.n23*a.n11+a.n21*a.n13,n=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*l;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*i;c[6]=a*l;c[7]=a*k;c[8]=a*n;return b};
+return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,k=a.n23,l=a.n24,i=a.n31,j=a.n32,n=a.n33,o=a.n34,p=a.n41,q=a.n42,t=a.n43,u=a.n44,G=b.n11,z=b.n12,E=b.n13,r=b.n14,m=b.n21,A=b.n22,
+B=b.n23,C=b.n24,v=b.n31,M=b.n32,F=b.n33,K=b.n34,x=b.n41,N=b.n42,P=b.n43,J=b.n44;this.n11=c*G+d*m+e*v+g*x;this.n12=c*z+d*A+e*M+g*N;this.n13=c*E+d*B+e*F+g*P;this.n14=c*r+d*C+e*K+g*J;this.n21=f*G+h*m+k*v+l*x;this.n22=f*z+h*A+k*M+l*N;this.n23=f*E+h*B+k*F+l*P;this.n24=f*r+h*C+k*K+l*J;this.n31=i*G+j*m+n*v+o*x;this.n32=i*z+j*A+n*M+o*N;this.n33=i*E+j*B+n*F+o*P;this.n34=i*r+j*C+n*K+o*J;this.n41=p*G+q*m+t*v+u*x;this.n42=p*z+q*A+t*M+u*N;this.n43=p*E+q*B+t*F+u*P;this.n44=p*r+q*C+t*K+u*J;return this},multiplyToArray:function(a,
+b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
+a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,k=this.n31,l=this.n32,i=this.n33,j=this.n34,n=this.n41,o=this.n42,p=this.n43,q=this.n44;return d*f*l*n-c*h*l*n-d*g*i*n+b*h*i*n+c*g*j*n-b*f*j*n-d*f*k*o+c*h*k*o+d*e*i*o-a*h*i*o-c*e*j*o+a*f*j*o+d*g*k*p-b*h*k*p-d*e*l*p+a*h*l*p+b*e*j*p-a*g*j*p-c*g*k*q+b*f*k*q+c*e*l*q-a*f*l*q-b*e*i*q+a*g*i*q},transpose:function(){var a;a=this.n21;this.n21=
+this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=
+this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=
+this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,
+b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX: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},setRotationY: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},setRotationZ: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},setRotationAxis:function(a,
+b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,k=e*g,l=e*f;this.set(k*g+c,k*f-d*h,k*h+d*f,0,k*f+d*h,l*f+c,l*h-d*g,0,k*h-d*f,l*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);
+return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,e=a.z,g=Math.cos(c),c=Math.sin(c),f=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e);switch(b){case "YXZ":var k=f*h,l=f*e,i=d*h,j=d*e;this.n11=k+j*c;this.n12=
+i*c-l;this.n13=g*d;this.n21=g*e;this.n22=g*h;this.n23=-c;this.n31=l*c-i;this.n32=j+k*c;this.n33=g*f;break;case "ZXY":k=f*h;l=f*e;i=d*h;j=d*e;this.n11=k-j*c;this.n12=-g*e;this.n13=i+l*c;this.n21=l+i*c;this.n22=g*h;this.n23=j-k*c;this.n31=-g*d;this.n32=c;this.n33=g*f;break;case "ZYX":k=g*h;l=g*e;i=c*h;j=c*e;this.n11=f*h;this.n12=i*d-l;this.n13=k*d+j;this.n21=f*e;this.n22=j*d+k;this.n23=l*d-i;this.n31=-d;this.n32=c*f;this.n33=g*f;break;case "YZX":k=g*f;l=g*d;i=c*f;j=c*d;this.n11=f*h;this.n12=j-k*e;this.n13=
+i*e+l;this.n21=e;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=l*e+i;this.n33=k-j*e;break;case "XZY":k=g*f;l=g*d;i=c*f;j=c*d;this.n11=f*h;this.n12=-e;this.n13=d*h;this.n21=k*e+j;this.n22=g*h;this.n23=l*e-i;this.n31=i*e-l;this.n32=c*h;this.n33=j*e+k;break;default:k=g*h,l=g*e,i=c*h,j=c*e,this.n11=f*h,this.n12=-f*e,this.n13=d,this.n21=l+i*d,this.n22=k-j*d,this.n23=-c*f,this.n31=j-k*d,this.n32=i+l*d,this.n33=g*f}return this},setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,
+f=c+c,h=d+d,a=b*g,k=b*f;b*=h;var l=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(l+d);this.n12=k-e;this.n13=b+f;this.n21=k+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+l);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,
+b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
+THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,k=a.n23,l=a.n24,i=a.n31,j=a.n32,n=a.n33,o=a.n34,p=a.n41,q=a.n42,t=a.n43,u=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=k*o*q-l*n*q+l*j*t-h*o*t-k*j*u+h*n*u;b.n12=g*n*q-e*o*q-g*j*t+d*o*t+e*j*u-d*n*u;b.n13=e*l*q-g*k*q+g*h*t-d*l*t-e*h*u+d*k*u;b.n14=g*k*j-e*l*j-g*h*n+d*l*n+e*h*o-d*k*o;b.n21=l*n*p-k*o*p-l*i*t+f*o*t+k*i*u-f*n*u;b.n22=e*o*p-g*n*p+g*i*t-c*o*t-e*i*u+c*n*u;b.n23=g*k*p-e*l*p-g*f*t+c*l*t+e*f*u-c*k*u;b.n24=
+e*l*i-g*k*i+g*f*n-c*l*n-e*f*o+c*k*o;b.n31=h*o*p-l*j*p+l*i*q-f*o*q-h*i*u+f*j*u;b.n32=g*j*p-d*o*p-g*i*q+c*o*q+d*i*u-c*j*u;b.n33=e*l*p-g*h*p+g*f*q-c*l*q-d*f*u+c*h*u;b.n34=g*h*i-d*l*i-g*f*j+c*l*j+d*f*o-c*h*o;b.n41=k*j*p-h*n*p-k*i*q+f*n*q+h*i*t-f*j*t;b.n42=d*n*p-e*j*p+e*i*q-c*n*q-d*i*t+c*j*t;b.n43=e*h*p-d*k*p-e*f*q+c*k*q+d*f*t-c*h*t;b.n44=d*k*i-e*h*i+e*f*j-c*k*j-d*f*n+c*h*n;b.multiplyScalar(1/a.determinant());return b};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,k=-a.n32*a.n11+a.n31*a.n12,l=a.n23*a.n12-a.n22*a.n13,i=-a.n23*a.n11+a.n21*a.n13,j=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*l;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*k;c[6]=a*l;c[7]=a*i;c[8]=a*j;return b};
 THREE.Matrix4.makeFrustum=function(a,b,c,d,e,g){var f;f=new THREE.Matrix4;f.n11=2*e/(b-a);f.n12=0;f.n13=(b+a)/(b-a);f.n14=0;f.n21=0;f.n22=2*e/(d-c);f.n23=(d+c)/(d-c);f.n24=0;f.n31=0;f.n32=0;f.n33=-(g+e)/(g-e);f.n34=-2*g*e/(g-e);f.n41=0;f.n42=0;f.n43=-1;f.n44=0;return f};THREE.Matrix4.makePerspective=function(a,b,c,d){var e,a=c*Math.tan(a*Math.PI/360);e=-a;return THREE.Matrix4.makeFrustum(e*b,a*b,e,a,c,d)};
-THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,i,l;f=new THREE.Matrix4;h=b-a;i=c-d;l=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/i;f.n23=0;f.n24=-((c+d)/i);f.n31=0;f.n32=0;f.n33=-2/l;f.n34=-((g+e)/l);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
-THREE.Object3D=function(){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.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;this.useQuaternion=!1;this.boundRadius=
-0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
+THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,k,l;f=new THREE.Matrix4;h=b-a;k=c-d;l=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/k;f.n23=0;f.n24=-((c+d)/k);f.n31=0;f.n32=0;f.n33=-2/l;f.n34=-((g+e)/l);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
+THREE.Object3D=function(){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=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;
+this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
 THREE.Object3D.prototype={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.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
 -1){a.parent!==void 0&&a.parent.removeChild(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.addChildRecurse(a)}},removeChild:function(a){var b=this.children.indexOf(a);if(b!==-1)a.parent=void 0,this.children.splice(b,1)},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c<d;c++){e=this.children[c];if(e.name===a)return e;if(b&&(e=e.getChildByName(a,b),e!==void 0))return e}},updateMatrix:function(){this.matrix.setPosition(this.position);
-this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation);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=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixRotationWorld.extractRotation(this.matrixWorld,
-this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
+this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):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=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),
+this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
 THREE.Quaternion.prototype={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=0.5*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),f=a*b,h=d*e;this.w=f*g-h*c;this.x=f*c+h*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},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*=-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 a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},
-multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;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},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,i=this.w,l=i*c+f*e-h*d,k=
-i*d+h*c-g*e,n=i*e+g*d-f*c,c=-g*c-f*d-h*e;b.x=l*i+c*-g+k*-h-n*-f;b.y=k*i+c*-f+n*-g-l*-h;b.z=n*i+c*-h+l*-f-k*-g;return b}};
+multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;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},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,k=this.w,l=k*c+f*e-h*d,i=
+k*d+h*c-g*e,j=k*e+g*d-f*c,c=-g*c-f*d-h*e;b.x=l*k+c*-g+i*-h-j*-f;b.y=i*k+c*-f+j*-g-l*-h;b.z=j*k+c*-h+l*-f-i*-g;return b}};
 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(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.0010)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
 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.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
 THREE.Face4=function(a,b,c,d,e,g,f){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=f instanceof Array?f:[f];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.set(a||0,b||0)};
 THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.colors=[];this.faces=[];this.edges=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
 THREE.Geometry.prototype={computeCentroids:function(){var a,b,c;a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c.centroid.set(0,0,0),c instanceof THREE.Face3?(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),c.centroid.divideScalar(3)):c instanceof THREE.Face4&&(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),
-c.centroid.addSelf(this.vertices[c.d].position),c.centroid.divideScalar(4))},computeFaceNormals:function(a){var b,c,d,e,g,f,h=new THREE.Vector3,i=new THREE.Vector3;d=0;for(e=this.faces.length;d<e;d++){g=this.faces[d];if(a&&g.vertexNormals.length){h.set(0,0,0);b=0;for(c=g.vertexNormals.length;b<c;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else b=this.vertices[g.a],c=this.vertices[g.b],f=this.vertices[g.c],h.sub(f.position,c.position),i.sub(b.position,c.position),h.crossSelf(i);h.isZero()||
+c.centroid.addSelf(this.vertices[c.d].position),c.centroid.divideScalar(4))},computeFaceNormals:function(a){var b,c,d,e,g,f,h=new THREE.Vector3,k=new THREE.Vector3;d=0;for(e=this.faces.length;d<e;d++){g=this.faces[d];if(a&&g.vertexNormals.length){h.set(0,0,0);b=0;for(c=g.vertexNormals.length;b<c;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else b=this.vertices[g.a],c=this.vertices[g.b],f=this.vertices[g.c],h.sub(f.position,c.position),k.sub(b.position,c.position),h.crossSelf(k);h.isZero()||
 h.normalize();g.normal.copy(h)}},computeVertexNormals:function(){var a,b,c,d;if(this.__tmpVertices==void 0){d=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)d[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++)if(c=this.faces[a],c instanceof THREE.Face3)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(c instanceof THREE.Face4)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}else{d=
 this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)d[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c instanceof THREE.Face3?(d[c.a].addSelf(c.normal),d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal)):c instanceof THREE.Face4&&(d[c.a].addSelf(c.normal),d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal),d[c.d].addSelf(c.normal));a=0;for(b=this.vertices.length;a<b;a++)d[a].normalize();a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c instanceof THREE.Face3?(c.vertexNormals[0].copy(d[c.a]),
-c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c])):c instanceof THREE.Face4&&(c.vertexNormals[0].copy(d[c.a]),c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c]),c.vertexNormals[3].copy(d[c.d]))},computeTangents:function(){function a(a,b,c,d,e,g,D){h=a.vertices[b].position;i=a.vertices[c].position;l=a.vertices[d].position;k=f[e];n=f[g];j=f[D];o=i.x-h.x;p=l.x-h.x;q=i.y-h.y;t=l.y-h.y;u=i.z-h.z;G=l.z-h.z;y=n.u-k.u;E=j.u-k.u;r=n.v-k.v;m=j.v-k.v;z=1/(y*m-E*r);L.set((m*o-r*p)*
-z,(m*q-r*t)*z,(m*u-r*G)*z);F.set((y*p-E*o)*z,(y*t-E*q)*z,(y*G-E*u)*z);C[b].addSelf(L);C[c].addSelf(L);C[d].addSelf(L);v[b].addSelf(F);v[c].addSelf(F);v[d].addSelf(F)}var b,c,d,e,g,f,h,i,l,k,n,j,o,p,q,t,u,G,y,E,r,m,z,A,C=[],v=[],L=new THREE.Vector3,F=new THREE.Vector3,J=new THREE.Vector3,B=new THREE.Vector3,Q=new THREE.Vector3;b=0;for(c=this.vertices.length;b<c;b++)C[b]=new THREE.Vector3,v[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)g=this.faces[b],f=this.faceVertexUvs[0][b],g instanceof
-THREE.Face3?a(this,g.a,g.b,g.c,0,1,2):g instanceof THREE.Face4&&(a(this,g.a,g.b,g.c,0,1,2),a(this,g.a,g.b,g.d,0,1,3));var S=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++)Q.copy(g.vertexNormals[d]),e=g[S[d]],A=C[e],J.copy(A),J.subSelf(Q.multiplyScalar(Q.dot(A))).normalize(),B.cross(g.vertexNormals[d],A),e=B.dot(v[e]),e=e<0?-1:1,g.vertexTangents[d]=new THREE.Vector4(J.x,J.y,J.z,e)}this.hasTangents=!0},computeBoundingBox:function(){var a;
+c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c])):c instanceof THREE.Face4&&(c.vertexNormals[0].copy(d[c.a]),c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c]),c.vertexNormals[3].copy(d[c.d]))},computeTangents:function(){function a(a,b,c,d,e,g,D){h=a.vertices[b].position;k=a.vertices[c].position;l=a.vertices[d].position;i=f[e];j=f[g];n=f[D];o=k.x-h.x;p=l.x-h.x;q=k.y-h.y;t=l.y-h.y;u=k.z-h.z;G=l.z-h.z;z=j.u-i.u;E=n.u-i.u;r=j.v-i.v;m=n.v-i.v;A=1/(z*m-E*r);M.set((m*o-r*p)*
+A,(m*q-r*t)*A,(m*u-r*G)*A);F.set((z*p-E*o)*A,(z*t-E*q)*A,(z*G-E*u)*A);C[b].addSelf(M);C[c].addSelf(M);C[d].addSelf(M);v[b].addSelf(F);v[c].addSelf(F);v[d].addSelf(F)}var b,c,d,e,g,f,h,k,l,i,j,n,o,p,q,t,u,G,z,E,r,m,A,B,C=[],v=[],M=new THREE.Vector3,F=new THREE.Vector3,K=new THREE.Vector3,x=new THREE.Vector3,N=new THREE.Vector3;b=0;for(c=this.vertices.length;b<c;b++)C[b]=new THREE.Vector3,v[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)g=this.faces[b],f=this.faceVertexUvs[0][b],g instanceof
+THREE.Face3?a(this,g.a,g.b,g.c,0,1,2):g instanceof THREE.Face4&&(a(this,g.a,g.b,g.c,0,1,2),a(this,g.a,g.b,g.d,0,1,3));var P=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++)N.copy(g.vertexNormals[d]),e=g[P[d]],B=C[e],K.copy(B),K.subSelf(N.multiplyScalar(N.dot(B))).normalize(),x.cross(g.vertexNormals[d],B),e=x.dot(v[e]),e=e<0?-1:1,g.vertexTangents[d]=new THREE.Vector4(K.x,K.y,K.z,e)}this.hasTangents=!0},computeBoundingBox:function(){var a;
 if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,c=this.vertices.length;b<c;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;
 else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;b<c;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},computeEdgeFaces:function(){function a(a,b){return Math.min(a,b)+"_"+Math.max(a,b)}function b(a,b,c){a[b]===
 void 0?(a[b]={set:{},array:[]},a[b].set[c]=1,a[b].array.push(c)):a[b].set[c]===void 0&&(a[b].set[c]=1,a[b].array.push(c))}var c,d,e,g,f,h={};c=0;for(d=this.faces.length;c<d;c++)f=this.faces[c],f instanceof THREE.Face3?(e=a(f.a,f.b),b(h,e,c),e=a(f.b,f.c),b(h,e,c),e=a(f.a,f.c),b(h,e,c)):f instanceof THREE.Face4&&(e=a(f.b,f.d),b(h,e,c),e=a(f.a,f.b),b(h,e,c),e=a(f.a,f.d),b(h,e,c),e=a(f.b,f.c),b(h,e,c),e=a(f.c,f.d),b(h,e,c));c=0;for(d=this.edges.length;c<d;c++){f=this.edges[c];e=f.vertexIndices[0];g=f.vertexIndices[1];
@@ -72,8 +74,9 @@ THREE.Camera.prototype.setViewOffset=function(a,b,c,d,e,g){this.fullWidth=a;this
 THREE.Camera.prototype.update=function(a,b,c){if(this.useTarget)this.matrix.lookAt(this.position,this.target.position,this.up),this.matrix.setPosition(this.position),a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse),b=!0;else if(this.matrixAutoUpdate&&this.updateMatrix(),b||this.matrixWorldNeedsUpdate)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=
 !1,b=!0,THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse);for(a=0;a<this.children.length;a++)this.children[a].update(this.matrixWorld,b,c)};THREE.Light=function(a){THREE.Object3D.call(this);this.color=new THREE.Color(a)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;
 THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b,c,d){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1;this.distance=c||0;this.castShadow=d!==void 0?d:!1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1;this.distance=c||0};
-THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;THREE.Material=function(a){this.id=THREE.MaterialCounter.value++;a=a||{};this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:!1;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.depthTest=a.depthTest!==void 0?a.depthTest:!0};THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;
-THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;THREE.MaterialCounter={value:0};
+THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;
+THREE.Material=function(a){this.id=THREE.MaterialCounter.value++;a=a||{};this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:!1;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.depthTest=a.depthTest!==void 0?a.depthTest:!0;this.polygonOffset=a.polygonOffset!==void 0?a.polygonOffset:!1;this.polygonOffsetFactor=a.polygonOffsetFactor!==void 0?a.polygonOffsetFactor:0;this.polygonOffsetUnits=a.polygonOffsetUnits!==void 0?a.polygonOffsetUnits:
+0};THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;THREE.MaterialCounter={value:0};
 THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:!1};THREE.LineBasicMaterial.prototype=new THREE.Material;THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
 THREE.MeshBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.shading=a.shading!==
 void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:!1;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:!1;this.skinning=a.skinning!==void 0?a.skinning:!1;this.morphTargets=a.morphTargets!==void 0?a.morphTargets:!1};
@@ -98,34 +101,34 @@ b.indexOf(".ogg")!==-1?e="audio/ogg":b.indexOf(".wav")!==-1&&(e="audio/wav"),thi
 THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded)this.removeEventListener("canplay",this.onLoad,!0),a.isLoaded=!0,a.duration=this.duration,a.isPlaying&&a.play()};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded&&(this.domElement.play(),a))this.domElement.currentTime=a%this.duration};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
 THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
 THREE.Sound.prototype.update=function(a,b,c){this.matrixAutoUpdate&&(this.matrix.setPosition(this.position),b=!0);if(b||this.matrixWorldNeedsUpdate)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,b=!0;for(var d=this.children.length,a=0;a<d;a++)this.children[a].update(this.matrixWorld,b,c)};
-THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
+THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.overrideMaterial=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
 THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1)this.objects.push(a),this.__objectsAdded.push(a);for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
 THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else a instanceof THREE.Sound?(b=this.sounds.indexOf(a),b!==-1&&this.sounds.splice(b,1)):a instanceof THREE.Camera||(b=this.objects.indexOf(a),b!==-1&&(this.objects.splice(b,1),this.__objectsRemoved.push(a)));for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
 THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
-THREE.Projector=function(){function a(){var a=i[h]=i[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(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))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,e,g=[],f,h,i=[],l,k,n=[],j,o=[],p,q,t=[],u,G,y=[],E=new THREE.Vector4,r=new THREE.Vector4,
-m=new THREE.Matrix4,z=new THREE.Matrix4,A=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],C=new THREE.Vector4,v=new THREE.Vector4;this.projectVector=function(a,b){m.multiply(b.projectionMatrix,b.matrixWorldInverse);m.multiplyVector3(a);return a};this.unprojectVector=function(a,b){m.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));m.multiplyVector3(a);return a};this.projectObjects=function(a,c,f){var c=[],h,l,j;e=0;l=
-a.objects;a=0;for(h=l.length;a<h;a++){j=l[a];var i;if(!(i=!j.visible))if(i=j instanceof THREE.Mesh){a:{i=void 0;for(var k=j.matrixWorld,o=-j.geometry.boundingSphere.radius*Math.max(j.scale.x,Math.max(j.scale.y,j.scale.z)),n=0;n<6;n++)if(i=A[n].x*k.n14+A[n].y*k.n24+A[n].z*k.n34+A[n].w,i<=o){i=!1;break a}i=!0}i=!i}if(!i)i=g[e]=g[e]||new THREE.RenderableObject,e++,d=i,E.copy(j.position),m.multiplyVector3(E),d.object=j,d.z=E.z,c.push(d)}f&&c.sort(b);return c};this.projectScene=function(d,e,g){var B=[],
-E=e.near,S=e.far,N,P,H,M,x,I,D,K,O,s,w,U,W,X,R,V,T;G=q=j=k=0;e.matrixAutoUpdate&&e.update(void 0,!0);d.update(void 0,!1,e);m.multiply(e.projectionMatrix,e.matrixWorldInverse);A[0].set(m.n41-m.n11,m.n42-m.n12,m.n43-m.n13,m.n44-m.n14);A[1].set(m.n41+m.n11,m.n42+m.n12,m.n43+m.n13,m.n44+m.n14);A[2].set(m.n41+m.n21,m.n42+m.n22,m.n43+m.n23,m.n44+m.n24);A[3].set(m.n41-m.n21,m.n42-m.n22,m.n43-m.n23,m.n44-m.n24);A[4].set(m.n41-m.n31,m.n42-m.n32,m.n43-m.n33,m.n44-m.n34);A[5].set(m.n41+m.n31,m.n42+m.n32,m.n43+
-m.n33,m.n44+m.n34);for(N=0;N<6;N++)O=A[N],O.divideScalar(Math.sqrt(O.x*O.x+O.y*O.y+O.z*O.z));O=this.projectObjects(d,e,!0);d=0;for(N=O.length;d<N;d++)if(s=O[d].object,s.visible)if(w=s.matrixWorld,U=s.matrixRotationWorld,W=s.materials,X=s.overdraw,h=0,s instanceof THREE.Mesh){R=s.geometry;M=R.vertices;V=R.faces;R=R.faceVertexUvs;P=0;for(H=M.length;P<H;P++)f=a(),f.positionWorld.copy(M[P].position),w.multiplyVector3(f.positionWorld),f.positionScreen.copy(f.positionWorld),m.multiplyVector4(f.positionScreen),
-f.positionScreen.x/=f.positionScreen.w,f.positionScreen.y/=f.positionScreen.w,f.visible=f.positionScreen.z>E&&f.positionScreen.z<S;M=0;for(P=V.length;M<P;M++){H=V[M];if(H instanceof THREE.Face3)if(x=i[H.a],I=i[H.b],D=i[H.c],x.visible&&I.visible&&D.visible&&(s.doubleSided||s.flipSided!=(D.positionScreen.x-x.positionScreen.x)*(I.positionScreen.y-x.positionScreen.y)-(D.positionScreen.y-x.positionScreen.y)*(I.positionScreen.x-x.positionScreen.x)<0))K=n[k]=n[k]||new THREE.RenderableFace3,k++,l=K,l.v1.copy(x),
-l.v2.copy(I),l.v3.copy(D);else continue;else if(H instanceof THREE.Face4)if(x=i[H.a],I=i[H.b],D=i[H.c],K=i[H.d],x.visible&&I.visible&&D.visible&&K.visible&&(s.doubleSided||s.flipSided!=((K.positionScreen.x-x.positionScreen.x)*(I.positionScreen.y-x.positionScreen.y)-(K.positionScreen.y-x.positionScreen.y)*(I.positionScreen.x-x.positionScreen.x)<0||(I.positionScreen.x-D.positionScreen.x)*(K.positionScreen.y-D.positionScreen.y)-(I.positionScreen.y-D.positionScreen.y)*(K.positionScreen.x-D.positionScreen.x)<
-0)))T=o[j]=o[j]||new THREE.RenderableFace4,j++,l=T,l.v1.copy(x),l.v2.copy(I),l.v3.copy(D),l.v4.copy(K);else continue;l.normalWorld.copy(H.normal);U.multiplyVector3(l.normalWorld);l.centroidWorld.copy(H.centroid);w.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);m.multiplyVector3(l.centroidScreen);D=H.vertexNormals;x=0;for(I=D.length;x<I;x++)K=l.vertexNormalsWorld[x],K.copy(D[x]),U.multiplyVector3(K);x=0;for(I=R.length;x<I;x++)if(T=R[x][M]){D=0;for(K=T.length;D<K;D++)l.uvs[x][D]=
-T[D]}l.meshMaterials=W;l.faceMaterials=H.materials;l.overdraw=X;l.z=l.centroidScreen.z;B.push(l)}}else if(s instanceof THREE.Line){z.multiply(m,w);M=s.geometry.vertices;x=a();x.positionScreen.copy(M[0].position);z.multiplyVector4(x.positionScreen);P=1;for(H=M.length;P<H;P++)if(x=a(),x.positionScreen.copy(M[P].position),z.multiplyVector4(x.positionScreen),I=i[h-2],C.copy(x.positionScreen),v.copy(I.positionScreen),c(C,v))C.multiplyScalar(1/C.w),v.multiplyScalar(1/v.w),w=t[q]=t[q]||new THREE.RenderableLine,
-q++,p=w,p.v1.positionScreen.copy(C),p.v2.positionScreen.copy(v),p.z=Math.max(C.z,v.z),p.materials=s.materials,B.push(p)}else if(s instanceof THREE.Particle&&(r.set(s.matrixWorld.n14,s.matrixWorld.n24,s.matrixWorld.n34,1),m.multiplyVector4(r),r.z/=r.w,r.z>0&&r.z<1))w=y[G]=y[G]||new THREE.RenderableParticle,G++,u=w,u.x=r.x/r.w,u.y=r.y/r.w,u.z=r.z,u.rotation=s.rotation.z,u.scale.x=s.scale.x*Math.abs(u.x-(r.x+e.projectionMatrix.n11)/(r.w+e.projectionMatrix.n14)),u.scale.y=s.scale.y*Math.abs(u.y-(r.y+
-e.projectionMatrix.n22)/(r.w+e.projectionMatrix.n24)),u.materials=s.materials,B.push(u);g&&B.sort(b);return B}};
-THREE.SVGRenderer=function(){function a(a,b,c){var d,e,f,g;d=0;for(e=a.lights.length;d<e;d++)f=a.lights[d],f instanceof THREE.DirectionalLight?(g=b.normalWorld.dot(f.position)*f.intensity,g>0&&(c.r+=f.color.r*g,c.g+=f.color.g*g,c.b+=f.color.b*g)):f instanceof THREE.PointLight&&(L.sub(f.position,b.centroidWorld),L.normalize(),g=b.normalWorld.dot(L)*f.intensity,g>0&&(c.r+=f.color.r*g,c.g+=f.color.g*g,c.b+=f.color.b*g))}function b(b,c,h,j,i,k){f.data.vertices+=3;f.data.faces++;B=d(Q++);B.setAttribute("d",
-"M "+b.positionScreen.x+" "+b.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+"z");i instanceof THREE.MeshBasicMaterial?r.hex=i.color.hex:i instanceof THREE.MeshLambertMaterial?E?(m.r=z.r,m.g=z.g,m.b=z.b,a(k,j,m),r.r=Math.max(0,Math.min(i.color.r*m.r,1)),r.g=Math.max(0,Math.min(i.color.g*m.g,1)),r.b=Math.max(0,Math.min(i.color.b*m.b,1)),r.updateHex()):r.hex=i.color.hex:i instanceof THREE.MeshDepthMaterial?(v=1-i.__2near/(i.__farPlusNear-
-j.z*i.__farMinusNear),r.setRGB(v,v,v)):i instanceof THREE.MeshNormalMaterial&&r.setRGB(e(j.normalWorld.x),e(j.normalWorld.y),e(j.normalWorld.z));i.wireframe?B.setAttribute("style","fill: none; stroke: #"+g(r.hex.toString(16))+"; stroke-width: "+i.wireframeLinewidth+"; stroke-opacity: "+i.opacity+"; stroke-linecap: "+i.wireframeLinecap+"; stroke-linejoin: "+i.wireframeLinejoin):B.setAttribute("style","fill: #"+g(r.hex.toString(16))+"; fill-opacity: "+i.opacity);l.appendChild(B)}function c(b,c,h,i,
-j,k,n){f.data.vertices+=4;f.data.faces++;B=d(Q++);B.setAttribute("d","M "+b.positionScreen.x+" "+b.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+" L "+i.positionScreen.x+","+i.positionScreen.y+"z");k instanceof THREE.MeshBasicMaterial?r.hex=k.color.hex:k instanceof THREE.MeshLambertMaterial?E?(m.r=z.r,m.g=z.g,m.b=z.b,a(n,j,m),r.r=Math.max(0,Math.min(k.color.r*m.r,1)),r.g=Math.max(0,Math.min(k.color.g*m.g,1)),r.b=Math.max(0,Math.min(k.color.b*
-m.b,1)),r.updateHex()):r.hex=k.color.hex:k instanceof THREE.MeshDepthMaterial?(v=1-k.__2near/(k.__farPlusNear-j.z*k.__farMinusNear),r.setRGB(v,v,v)):k instanceof THREE.MeshNormalMaterial&&r.setRGB(e(j.normalWorld.x),e(j.normalWorld.y),e(j.normalWorld.z));k.wireframe?B.setAttribute("style","fill: none; stroke: #"+g(r.hex.toString(16))+"; stroke-width: "+k.wireframeLinewidth+"; stroke-opacity: "+k.opacity+"; stroke-linecap: "+k.wireframeLinecap+"; stroke-linejoin: "+k.wireframeLinejoin):B.setAttribute("style",
-"fill: #"+g(r.hex.toString(16))+"; fill-opacity: "+k.opacity);l.appendChild(B)}function d(a){F[a]==null&&(F[a]=document.createElementNS("http://www.w3.org/2000/svg","path"),N==0&&F[a].setAttribute("shape-rendering","crispEdges"));return F[a]}function e(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function g(a){for(;a.length<6;)a="0"+a;return a}var f=this,h=null,i=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,n,j,o,p,q,t,u,G=new THREE.Rectangle,y=new THREE.Rectangle,E=
-!1,r=new THREE.Color(16777215),m=new THREE.Color(16777215),z=new THREE.Color(0),A=new THREE.Color(0),C=new THREE.Color(0),v,L=new THREE.Vector3,F=[],J=[],B,Q,S,N=1;this.domElement=l;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};this.setQuality=function(a){switch(a){case "high":N=1;break;case "low":N=0}};this.setSize=function(a,b){k=a;n=b;j=k/2;o=n/2;l.setAttribute("viewBox",-j+" "+-o+" "+k+" "+n);l.setAttribute("width",k);l.setAttribute("height",n);G.set(-j,-o,
-j,o)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(a,d){var e,k,m,n,r,v,s,w;this.autoClear&&this.clear();f.data.vertices=0;f.data.faces=0;h=i.projectScene(a,d,this.sortElements);S=Q=0;if(E=a.lights.length>0){s=a.lights;z.setRGB(0,0,0);A.setRGB(0,0,0);C.setRGB(0,0,0);e=0;for(k=s.length;e<k;e++)m=s[e],n=m.color,m instanceof THREE.AmbientLight?(z.r+=n.r,z.g+=n.g,z.b+=n.b):m instanceof THREE.DirectionalLight?(A.r+=n.r,A.g+=n.g,A.b+=n.b):m instanceof
-THREE.PointLight&&(C.r+=n.r,C.g+=n.g,C.b+=n.b)}e=0;for(k=h.length;e<k;e++)if(s=h[e],y.empty(),s instanceof THREE.RenderableParticle){p=s;p.x*=j;p.y*=-o;m=0;for(n=s.materials.length;m<n;)m++}else if(s instanceof THREE.RenderableLine){if(p=s.v1,q=s.v2,p.positionScreen.x*=j,p.positionScreen.y*=-o,q.positionScreen.x*=j,q.positionScreen.y*=-o,y.addPoint(p.positionScreen.x,p.positionScreen.y),y.addPoint(q.positionScreen.x,q.positionScreen.y),G.instersects(y)){m=0;for(n=s.materials.length;m<n;)if((w=s.materials[m++])&&
-w.opacity!=0){r=p;v=q;var F=S++;J[F]==null&&(J[F]=document.createElementNS("http://www.w3.org/2000/svg","line"),N==0&&J[F].setAttribute("shape-rendering","crispEdges"));B=J[F];B.setAttribute("x1",r.positionScreen.x);B.setAttribute("y1",r.positionScreen.y);B.setAttribute("x2",v.positionScreen.x);B.setAttribute("y2",v.positionScreen.y);w instanceof THREE.LineBasicMaterial&&(B.setAttribute("style","fill: none; stroke: ##"+g(w.color.hex.toString(16))+"; stroke-width: "+w.linewidth+"; stroke-opacity: "+
-w.opacity+"; stroke-linecap: "+w.linecap+"; stroke-linejoin: "+w.linejoin),l.appendChild(B))}}}else if(s instanceof THREE.RenderableFace3){if(p=s.v1,q=s.v2,t=s.v3,p.positionScreen.x*=j,p.positionScreen.y*=-o,q.positionScreen.x*=j,q.positionScreen.y*=-o,t.positionScreen.x*=j,t.positionScreen.y*=-o,y.addPoint(p.positionScreen.x,p.positionScreen.y),y.addPoint(q.positionScreen.x,q.positionScreen.y),y.addPoint(t.positionScreen.x,t.positionScreen.y),G.instersects(y)){m=0;for(n=s.meshMaterials.length;m<
-n;)if(w=s.meshMaterials[m++],w instanceof THREE.MeshFaceMaterial){r=0;for(v=s.faceMaterials.length;r<v;)(w=s.faceMaterials[r++])&&w.opacity!=0&&b(p,q,t,s,w,a)}else w&&w.opacity!=0&&b(p,q,t,s,w,a)}}else if(s instanceof THREE.RenderableFace4&&(p=s.v1,q=s.v2,t=s.v3,u=s.v4,p.positionScreen.x*=j,p.positionScreen.y*=-o,q.positionScreen.x*=j,q.positionScreen.y*=-o,t.positionScreen.x*=j,t.positionScreen.y*=-o,u.positionScreen.x*=j,u.positionScreen.y*=-o,y.addPoint(p.positionScreen.x,p.positionScreen.y),y.addPoint(q.positionScreen.x,
-q.positionScreen.y),y.addPoint(t.positionScreen.x,t.positionScreen.y),y.addPoint(u.positionScreen.x,u.positionScreen.y),G.instersects(y))){m=0;for(n=s.meshMaterials.length;m<n;)if(w=s.meshMaterials[m++],w instanceof THREE.MeshFaceMaterial){r=0;for(v=s.faceMaterials.length;r<v;)(w=s.faceMaterials[r++])&&w.opacity!=0&&c(p,q,t,u,s,w,a)}else w&&w.opacity!=0&&c(p,q,t,u,s,w,a)}}};
+THREE.Projector=function(){function a(){var a=k[h]=k[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(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))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,e,g=[],f,h,k=[],l,i,j=[],n,o=[],p,q,t=[],u,G,z=[],E=new THREE.Vector4,r=new THREE.Vector4,
+m=new THREE.Matrix4,A=new THREE.Matrix4,B=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],C=new THREE.Vector4,v=new THREE.Vector4;this.projectVector=function(a,b){m.multiply(b.projectionMatrix,b.matrixWorldInverse);m.multiplyVector3(a);return a};this.unprojectVector=function(a,b){m.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));m.multiplyVector3(a);return a};this.projectObjects=function(a,c,f){var c=[],h,l,k;e=0;l=
+a.objects;a=0;for(h=l.length;a<h;a++){k=l[a];var i;if(!(i=!k.visible))if(i=k instanceof THREE.Mesh){a:{i=void 0;for(var j=k.matrixWorld,n=-k.geometry.boundingSphere.radius*Math.max(k.scale.x,Math.max(k.scale.y,k.scale.z)),o=0;o<6;o++)if(i=B[o].x*j.n14+B[o].y*j.n24+B[o].z*j.n34+B[o].w,i<=n){i=!1;break a}i=!0}i=!i}if(!i)i=g[e]=g[e]||new THREE.RenderableObject,e++,d=i,E.copy(k.position),m.multiplyVector3(E),d.object=k,d.z=E.z,c.push(d)}f&&c.sort(b);return c};this.projectScene=function(d,e,g){var x=[],
+E=e.near,P=e.far,J,R,H,O,y,I,D,L,Q,s,w,U,W,X,S,V,T;G=q=n=i=0;e.matrixAutoUpdate&&e.update(void 0,!0);d.update(void 0,!1,e);m.multiply(e.projectionMatrix,e.matrixWorldInverse);B[0].set(m.n41-m.n11,m.n42-m.n12,m.n43-m.n13,m.n44-m.n14);B[1].set(m.n41+m.n11,m.n42+m.n12,m.n43+m.n13,m.n44+m.n14);B[2].set(m.n41+m.n21,m.n42+m.n22,m.n43+m.n23,m.n44+m.n24);B[3].set(m.n41-m.n21,m.n42-m.n22,m.n43-m.n23,m.n44-m.n24);B[4].set(m.n41-m.n31,m.n42-m.n32,m.n43-m.n33,m.n44-m.n34);B[5].set(m.n41+m.n31,m.n42+m.n32,m.n43+
+m.n33,m.n44+m.n34);for(J=0;J<6;J++)Q=B[J],Q.divideScalar(Math.sqrt(Q.x*Q.x+Q.y*Q.y+Q.z*Q.z));Q=this.projectObjects(d,e,!0);d=0;for(J=Q.length;d<J;d++)if(s=Q[d].object,s.visible)if(w=s.matrixWorld,U=s.matrixRotationWorld,W=s.materials,X=s.overdraw,h=0,s instanceof THREE.Mesh){S=s.geometry;O=S.vertices;V=S.faces;S=S.faceVertexUvs;R=0;for(H=O.length;R<H;R++)f=a(),f.positionWorld.copy(O[R].position),w.multiplyVector3(f.positionWorld),f.positionScreen.copy(f.positionWorld),m.multiplyVector4(f.positionScreen),
+f.positionScreen.x/=f.positionScreen.w,f.positionScreen.y/=f.positionScreen.w,f.visible=f.positionScreen.z>E&&f.positionScreen.z<P;O=0;for(R=V.length;O<R;O++){H=V[O];if(H instanceof THREE.Face3)if(y=k[H.a],I=k[H.b],D=k[H.c],y.visible&&I.visible&&D.visible&&(s.doubleSided||s.flipSided!=(D.positionScreen.x-y.positionScreen.x)*(I.positionScreen.y-y.positionScreen.y)-(D.positionScreen.y-y.positionScreen.y)*(I.positionScreen.x-y.positionScreen.x)<0))L=j[i]=j[i]||new THREE.RenderableFace3,i++,l=L,l.v1.copy(y),
+l.v2.copy(I),l.v3.copy(D);else continue;else if(H instanceof THREE.Face4)if(y=k[H.a],I=k[H.b],D=k[H.c],L=k[H.d],y.visible&&I.visible&&D.visible&&L.visible&&(s.doubleSided||s.flipSided!=((L.positionScreen.x-y.positionScreen.x)*(I.positionScreen.y-y.positionScreen.y)-(L.positionScreen.y-y.positionScreen.y)*(I.positionScreen.x-y.positionScreen.x)<0||(I.positionScreen.x-D.positionScreen.x)*(L.positionScreen.y-D.positionScreen.y)-(I.positionScreen.y-D.positionScreen.y)*(L.positionScreen.x-D.positionScreen.x)<
+0)))T=o[n]=o[n]||new THREE.RenderableFace4,n++,l=T,l.v1.copy(y),l.v2.copy(I),l.v3.copy(D),l.v4.copy(L);else continue;l.normalWorld.copy(H.normal);U.multiplyVector3(l.normalWorld);l.centroidWorld.copy(H.centroid);w.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);m.multiplyVector3(l.centroidScreen);D=H.vertexNormals;y=0;for(I=D.length;y<I;y++)L=l.vertexNormalsWorld[y],L.copy(D[y]),U.multiplyVector3(L);y=0;for(I=S.length;y<I;y++)if(T=S[y][O]){D=0;for(L=T.length;D<L;D++)l.uvs[y][D]=
+T[D]}l.meshMaterials=W;l.faceMaterials=H.materials;l.overdraw=X;l.z=l.centroidScreen.z;x.push(l)}}else if(s instanceof THREE.Line){A.multiply(m,w);O=s.geometry.vertices;y=a();y.positionScreen.copy(O[0].position);A.multiplyVector4(y.positionScreen);R=1;for(H=O.length;R<H;R++)if(y=a(),y.positionScreen.copy(O[R].position),A.multiplyVector4(y.positionScreen),I=k[h-2],C.copy(y.positionScreen),v.copy(I.positionScreen),c(C,v))C.multiplyScalar(1/C.w),v.multiplyScalar(1/v.w),w=t[q]=t[q]||new THREE.RenderableLine,
+q++,p=w,p.v1.positionScreen.copy(C),p.v2.positionScreen.copy(v),p.z=Math.max(C.z,v.z),p.materials=s.materials,x.push(p)}else if(s instanceof THREE.Particle&&(r.set(s.matrixWorld.n14,s.matrixWorld.n24,s.matrixWorld.n34,1),m.multiplyVector4(r),r.z/=r.w,r.z>0&&r.z<1))w=z[G]=z[G]||new THREE.RenderableParticle,G++,u=w,u.x=r.x/r.w,u.y=r.y/r.w,u.z=r.z,u.rotation=s.rotation.z,u.scale.x=s.scale.x*Math.abs(u.x-(r.x+e.projectionMatrix.n11)/(r.w+e.projectionMatrix.n14)),u.scale.y=s.scale.y*Math.abs(u.y-(r.y+
+e.projectionMatrix.n22)/(r.w+e.projectionMatrix.n24)),u.materials=s.materials,x.push(u);g&&x.sort(b);return x}};
+THREE.SVGRenderer=function(){function a(a,b,c){var d,e,f,g;d=0;for(e=a.lights.length;d<e;d++)f=a.lights[d],f instanceof THREE.DirectionalLight?(g=b.normalWorld.dot(f.position)*f.intensity,g>0&&(c.r+=f.color.r*g,c.g+=f.color.g*g,c.b+=f.color.b*g)):f instanceof THREE.PointLight&&(M.sub(f.position,b.centroidWorld),M.normalize(),g=b.normalWorld.dot(M)*f.intensity,g>0&&(c.r+=f.color.r*g,c.g+=f.color.g*g,c.b+=f.color.b*g))}function b(b,c,h,k,i,j){f.data.vertices+=3;f.data.faces++;x=d(N++);x.setAttribute("d",
+"M "+b.positionScreen.x+" "+b.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+"z");i instanceof THREE.MeshBasicMaterial?r.hex=i.color.hex:i instanceof THREE.MeshLambertMaterial?E?(m.r=A.r,m.g=A.g,m.b=A.b,a(j,k,m),r.r=Math.max(0,Math.min(i.color.r*m.r,1)),r.g=Math.max(0,Math.min(i.color.g*m.g,1)),r.b=Math.max(0,Math.min(i.color.b*m.b,1)),r.updateHex()):r.hex=i.color.hex:i instanceof THREE.MeshDepthMaterial?(v=1-i.__2near/(i.__farPlusNear-
+k.z*i.__farMinusNear),r.setRGB(v,v,v)):i instanceof THREE.MeshNormalMaterial&&r.setRGB(e(k.normalWorld.x),e(k.normalWorld.y),e(k.normalWorld.z));i.wireframe?x.setAttribute("style","fill: none; stroke: #"+g(r.hex.toString(16))+"; stroke-width: "+i.wireframeLinewidth+"; stroke-opacity: "+i.opacity+"; stroke-linecap: "+i.wireframeLinecap+"; stroke-linejoin: "+i.wireframeLinejoin):x.setAttribute("style","fill: #"+g(r.hex.toString(16))+"; fill-opacity: "+i.opacity);l.appendChild(x)}function c(b,c,h,i,
+k,j,n){f.data.vertices+=4;f.data.faces++;x=d(N++);x.setAttribute("d","M "+b.positionScreen.x+" "+b.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+" L "+i.positionScreen.x+","+i.positionScreen.y+"z");j instanceof THREE.MeshBasicMaterial?r.hex=j.color.hex:j instanceof THREE.MeshLambertMaterial?E?(m.r=A.r,m.g=A.g,m.b=A.b,a(n,k,m),r.r=Math.max(0,Math.min(j.color.r*m.r,1)),r.g=Math.max(0,Math.min(j.color.g*m.g,1)),r.b=Math.max(0,Math.min(j.color.b*
+m.b,1)),r.updateHex()):r.hex=j.color.hex:j instanceof THREE.MeshDepthMaterial?(v=1-j.__2near/(j.__farPlusNear-k.z*j.__farMinusNear),r.setRGB(v,v,v)):j instanceof THREE.MeshNormalMaterial&&r.setRGB(e(k.normalWorld.x),e(k.normalWorld.y),e(k.normalWorld.z));j.wireframe?x.setAttribute("style","fill: none; stroke: #"+g(r.hex.toString(16))+"; stroke-width: "+j.wireframeLinewidth+"; stroke-opacity: "+j.opacity+"; stroke-linecap: "+j.wireframeLinecap+"; stroke-linejoin: "+j.wireframeLinejoin):x.setAttribute("style",
+"fill: #"+g(r.hex.toString(16))+"; fill-opacity: "+j.opacity);l.appendChild(x)}function d(a){F[a]==null&&(F[a]=document.createElementNS("http://www.w3.org/2000/svg","path"),J==0&&F[a].setAttribute("shape-rendering","crispEdges"));return F[a]}function e(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function g(a){for(;a.length<6;)a="0"+a;return a}var f=this,h=null,k=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,j,n,o,p,q,t,u,G=new THREE.Rectangle,z=new THREE.Rectangle,E=
+!1,r=new THREE.Color(16777215),m=new THREE.Color(16777215),A=new THREE.Color(0),B=new THREE.Color(0),C=new THREE.Color(0),v,M=new THREE.Vector3,F=[],K=[],x,N,P,J=1;this.domElement=l;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};this.setQuality=function(a){switch(a){case "high":J=1;break;case "low":J=0}};this.setSize=function(a,b){i=a;j=b;n=i/2;o=j/2;l.setAttribute("viewBox",-n+" "+-o+" "+i+" "+j);l.setAttribute("width",i);l.setAttribute("height",j);G.set(-n,-o,
+n,o)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(a,d){var e,i,j,m,r,v,s,w;this.autoClear&&this.clear();f.data.vertices=0;f.data.faces=0;h=k.projectScene(a,d,this.sortElements);P=N=0;if(E=a.lights.length>0){s=a.lights;A.setRGB(0,0,0);B.setRGB(0,0,0);C.setRGB(0,0,0);e=0;for(i=s.length;e<i;e++)j=s[e],m=j.color,j instanceof THREE.AmbientLight?(A.r+=m.r,A.g+=m.g,A.b+=m.b):j instanceof THREE.DirectionalLight?(B.r+=m.r,B.g+=m.g,B.b+=m.b):j instanceof
+THREE.PointLight&&(C.r+=m.r,C.g+=m.g,C.b+=m.b)}e=0;for(i=h.length;e<i;e++)if(s=h[e],z.empty(),s instanceof THREE.RenderableParticle){p=s;p.x*=n;p.y*=-o;j=0;for(m=s.materials.length;j<m;)j++}else if(s instanceof THREE.RenderableLine){if(p=s.v1,q=s.v2,p.positionScreen.x*=n,p.positionScreen.y*=-o,q.positionScreen.x*=n,q.positionScreen.y*=-o,z.addPoint(p.positionScreen.x,p.positionScreen.y),z.addPoint(q.positionScreen.x,q.positionScreen.y),G.instersects(z)){j=0;for(m=s.materials.length;j<m;)if((w=s.materials[j++])&&
+w.opacity!=0){r=p;v=q;var F=P++;K[F]==null&&(K[F]=document.createElementNS("http://www.w3.org/2000/svg","line"),J==0&&K[F].setAttribute("shape-rendering","crispEdges"));x=K[F];x.setAttribute("x1",r.positionScreen.x);x.setAttribute("y1",r.positionScreen.y);x.setAttribute("x2",v.positionScreen.x);x.setAttribute("y2",v.positionScreen.y);w instanceof THREE.LineBasicMaterial&&(x.setAttribute("style","fill: none; stroke: ##"+g(w.color.hex.toString(16))+"; stroke-width: "+w.linewidth+"; stroke-opacity: "+
+w.opacity+"; stroke-linecap: "+w.linecap+"; stroke-linejoin: "+w.linejoin),l.appendChild(x))}}}else if(s instanceof THREE.RenderableFace3){if(p=s.v1,q=s.v2,t=s.v3,p.positionScreen.x*=n,p.positionScreen.y*=-o,q.positionScreen.x*=n,q.positionScreen.y*=-o,t.positionScreen.x*=n,t.positionScreen.y*=-o,z.addPoint(p.positionScreen.x,p.positionScreen.y),z.addPoint(q.positionScreen.x,q.positionScreen.y),z.addPoint(t.positionScreen.x,t.positionScreen.y),G.instersects(z)){j=0;for(m=s.meshMaterials.length;j<
+m;)if(w=s.meshMaterials[j++],w instanceof THREE.MeshFaceMaterial){r=0;for(v=s.faceMaterials.length;r<v;)(w=s.faceMaterials[r++])&&w.opacity!=0&&b(p,q,t,s,w,a)}else w&&w.opacity!=0&&b(p,q,t,s,w,a)}}else if(s instanceof THREE.RenderableFace4&&(p=s.v1,q=s.v2,t=s.v3,u=s.v4,p.positionScreen.x*=n,p.positionScreen.y*=-o,q.positionScreen.x*=n,q.positionScreen.y*=-o,t.positionScreen.x*=n,t.positionScreen.y*=-o,u.positionScreen.x*=n,u.positionScreen.y*=-o,z.addPoint(p.positionScreen.x,p.positionScreen.y),z.addPoint(q.positionScreen.x,
+q.positionScreen.y),z.addPoint(t.positionScreen.x,t.positionScreen.y),z.addPoint(u.positionScreen.x,u.positionScreen.y),G.instersects(z))){j=0;for(m=s.meshMaterials.length;j<m;)if(w=s.meshMaterials[j++],w instanceof THREE.MeshFaceMaterial){r=0;for(v=s.faceMaterials.length;r<v;)(w=s.faceMaterials[r++])&&w.opacity!=0&&c(p,q,t,u,s,w,a)}else w&&w.opacity!=0&&c(p,q,t,u,s,w,a)}}};
 THREE.SoundRenderer=function(){this.volume=1;this.domElement=document.createElement("div");this.domElement.id="THREESound";this.cameraPosition=new THREE.Vector3;this.soundPosition=new THREE.Vector3;this.render=function(a,b,c){c&&a.update(void 0,!1,b);var c=a.sounds,d,e=c.length;for(d=0;d<e;d++)a=c[d],this.soundPosition.set(a.matrixWorld.n14,a.matrixWorld.n24,a.matrixWorld.n34),this.soundPosition.subSelf(b.position),a.isPlaying&&a.isLoaded&&(a.isAddedToDOM||a.addToDOM(this.domElement),a.calculateVolumeAndPan(this.soundPosition))}};
 THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};
 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.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};

File diff suppressed because it is too large
+ 127 - 124
build/custom/ThreeWebGL.js


+ 1 - 1
examples/canvas_sandbox.html

@@ -90,7 +90,7 @@
 		<script type="text/javascript" src="../src/extras/ShaderUtils.js"></script>
 		<script type="text/javascript" src="../src/extras/animation/AnimationHandler.js"></script>
 		<script type="text/javascript" src="../src/extras/animation/Animation.js"></script>
-		<script type="text/javascript" src="../src/extras/cameras/QuakeCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/cameras/FirstPersonCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/PathCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/FlyCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/RollCamera.js"></script>

+ 1 - 1
examples/misc_sound.html

@@ -70,7 +70,7 @@
 				scene  = new THREE.Scene();
 				scene.fog = new THREE.FogExp2( 0x000000, 0.0035 );
 
-				camera = new THREE.QuakeCamera( {
+				camera = new THREE.FirstPersonCamera( {
 					fov: 50, aspect: window.innerWidth / window.innerHeight, near: 1, far: 10000,
 					movementSpeed: 70, lookSpeed: 0.05, noFly: true, lookVertical: false
 				} );

+ 1 - 1
examples/misc_ubiquity_test.html

@@ -91,7 +91,7 @@
 		<script type="text/javascript" src="../src/extras/ShaderUtils.js"></script>
 		<script type="text/javascript" src="../src/extras/animation/AnimationHandler.js"></script>
 		<script type="text/javascript" src="../src/extras/animation/Animation.js"></script>
-		<script type="text/javascript" src="../src/extras/cameras/QuakeCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/cameras/FirstPersonCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/PathCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/FlyCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/RollCamera.js"></script>

+ 12 - 14
examples/webgl_collisions_box.html

@@ -44,7 +44,8 @@ body {
 
 <script type="text/javascript">
 
-var scene, camera, renderer, info, mouse2d, sun, cube;
+var camera, scene, projector, renderer,
+info, mouse = { x: 0, y: 0 }, sun, cube;
 
 var bounce = 0;
 
@@ -57,10 +58,11 @@ function init() {
 
 	camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
 	camera.position.z = -500;
-	mouse2d = new THREE.Vector3( 0, 0, 1 );
 
 	scene = new THREE.Scene();
 
+	projector = new THREE.Projector();
+
 	renderer = new THREE.WebGLRenderer();
 	renderer.setSize( window.innerWidth, window.innerHeight );
 	container.appendChild(renderer.domElement);
@@ -101,9 +103,8 @@ function createCube( s, p ) {
 function onDocumentMouseMove( event ) {
 
 	event.preventDefault();
-	mouse2d.x = ( event.clientX / window.innerWidth ) * 2 - 1;
-	mouse2d.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
-	mouse2d.z = 1;
+	mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
+	mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
 
 };
 
@@ -111,19 +112,16 @@ function animate() {
 
 	requestAnimationFrame( animate );
 
-	var r = new THREE.Ray();
-	r.origin.copy( mouse2d );
+	info.innerHTML = "";
 
-	var matrix = camera.matrixWorld.clone();
-	matrix.multiplySelf( THREE.Matrix4.makeInvert( camera.projectionMatrix ) );
-	matrix.multiplyVector3( r.origin );
-	r.direction = r.origin.clone().subSelf( camera.position );
+	var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
+	projector.unprojectVector( vector, camera );
 
-	info.innerHTML = "";
+	var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
 
-	var c = THREE.Collisions.rayCastNearest( r );
+	var c = THREE.Collisions.rayCastNearest( ray );
 
-	if( c ) {
+	if ( c ) {
 
 		info.innerHTML += "Found @ distance " + c.distance.toFixed(2);
 		c.mesh.materials[ 0 ].color.setHex( 0xaa0000 );

+ 13 - 21
examples/webgl_collisions_mesh.html

@@ -45,18 +45,15 @@ body {
 
 <script type="text/javascript"> 
 
-var scene, camera, renderer, info, mouse2d, sun, loader, stats;
+var camera, scene, projector, renderer,
+info, mouse = { x: 0, y: 0 }, sun, loader, stats;
+
 var meshes = [];
 
 var theta = 0;
 var camdist = 1500;
 
-var totalFaces = 0;
-var totalColliders = 0;
-
-var ray = new THREE.Ray();
-var matrix = new THREE.Matrix4(),
-	matrix2 = new THREE.Matrix4();
+var totalFaces = 0, totalColliders = 0;
 
 function init() {
 
@@ -67,12 +64,13 @@ function init() {
 	
 	camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
 	camera.position.z = camdist;
-	mouse2d = new THREE.Vector3( 0, 0, 1 );
 	
 	loader = new THREE.JSONLoader(  );
 
 	scene = new THREE.Scene();
 
+	projector = new THREE.Projector();
+
 	renderer = new THREE.WebGLRenderer();
 	renderer.setSize( window.innerWidth, window.innerHeight );
 	container.appendChild( renderer.domElement );
@@ -152,7 +150,7 @@ function loadCube(p) {
 		addCube( new THREE.Vector3(	0, -sy,	-sz*2), geometry );
 		addCube( new THREE.Vector3( sx,-sy,	-sz*2), geometry );
 		
-		//info.innerHTML = "Total colliders: " + totalColliders + " (Faces: " + totalFaces + ")<br>";
+		// info.innerHTML = "Total colliders: " + totalColliders + " (Faces: " + totalFaces + ")<br>";
 	
 	};
 
@@ -186,9 +184,8 @@ function addCube( p, g) {
 function onDocumentMouseMove( event ) {
 
 	event.preventDefault();	
-	mouse2d.x = ( event.clientX / window.innerWidth ) * 2 - 1;
-	mouse2d.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
-	mouse2d.z = 1;
+	mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
+	mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
 
 };
 
@@ -197,15 +194,6 @@ function animate() {
 
 	requestAnimationFrame( animate );
 	
-	ray.origin.copy( mouse2d );
-
-	matrix.copy( camera.matrixWorld );
-	matrix.multiplySelf( THREE.Matrix4.makeInvert( camera.projectionMatrix, matrix2 ) );
-	matrix.multiplyVector3( ray.origin );
-	
-	ray.direction.copy( ray.origin );
-	ray.direction.subSelf( camera.position );
-	
 	if( meshes.length == 0 ) return;
 	
 	var i, l = meshes.length;
@@ -216,6 +204,10 @@ function animate() {
 
 	}
 
+	var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
+	projector.unprojectVector( vector, camera );
+
+	var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
 
 	var c = THREE.Collisions.rayCastNearest( ray );
 	

+ 13 - 23
examples/webgl_collisions_normal.html

@@ -45,18 +45,15 @@ body {
 
 <script type="text/javascript"> 
 
-var scene, camera, renderer, info, mouse2d, sun, loader, stats, line;
+var camera, scene, projector, renderer,
+info, mouse = { x: 0, y: 0 }, sun, loader, stats, line;
+
 var meshes = [];
 
 var theta = 0;
 var camdist = 500;
 
-var totalFaces = 0;
-var totalColliders = 0;
-
-var ray = new THREE.Ray();
-var matrix = new THREE.Matrix4(),
-	matrix2 = new THREE.Matrix4();
+var totalFaces = 0, totalColliders = 0;
 
 function init() {
 
@@ -67,12 +64,13 @@ function init() {
 	
 	camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
 	camera.position.z = camdist;
-	mouse2d = new THREE.Vector3( 0, 0, 1 );
 	
 	loader = new THREE.JSONLoader(  );
 
 	scene = new THREE.Scene();
 
+	projector = new THREE.Projector();
+
 	renderer = new THREE.WebGLRenderer();
 	renderer.setSize( window.innerWidth, window.innerHeight );
 	container.appendChild( renderer.domElement );
@@ -139,9 +137,8 @@ function addCube( p, g) {
 function onDocumentMouseMove( event ) {
 
 	event.preventDefault();	
-	mouse2d.x = ( event.clientX / window.innerWidth ) * 2 - 1;
-	mouse2d.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
-	mouse2d.z = 1;
+	mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
+	mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
 
 };
 
@@ -149,20 +146,13 @@ function onDocumentMouseMove( event ) {
 function animate() {
 
 	requestAnimationFrame( animate );
-	
-	ray.origin.copy( mouse2d );
 
-	matrix.copy( camera.matrixWorld );
-	matrix.multiplySelf( THREE.Matrix4.makeInvert( camera.projectionMatrix, matrix2 ) );
-	matrix.multiplyVector3( ray.origin );
-	
-	ray.direction.copy( ray.origin );
-	ray.direction.subSelf( camera.position );
-	
-	//var ray2 = new THREE.Ray();
-	//ray2.origin = ray.origin.clone();
+	var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
+	projector.unprojectVector( vector, camera );
+
+	var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
 	
-	if( meshes.length == 0 ) return;
+	if ( meshes.length == 0 ) return;
 	
 	var i, l = meshes.length;
 	

+ 22 - 18
examples/webgl_collisions_primitives.html

@@ -48,23 +48,26 @@
 
         <script type="text/javascript">
 
-            var scene, camera, renderer, info, mouse2d, sun;
+            var camera, scene, projector, renderer,
+            info, mouse = { x: 0, y: 0 }, sun;
 
             var theta = 0;
             var camdist = 1500;
             var geoms = [];
 
-            function init(){
+            function init () {
+
                 container = document.createElement('div');
                 document.body.appendChild(container);
 
                 info = document.getElementById("info");
 
                 camera = new THREE.Camera(40, window.innerWidth / window.innerHeight, 1, 10000);
-                mouse2d = new THREE.Vector3(0, 0, 1);
 
                 scene = new THREE.Scene();
 
+                projector = new THREE.Projector();
+
                 renderer = new THREE.WebGLRenderer();
                 renderer.setSize(window.innerWidth, window.innerHeight);
                 container.appendChild(renderer.domElement);
@@ -137,23 +140,23 @@
             }
 
             function onDocumentMouseMove(event){
+
                 event.preventDefault();
-                mouse2d.x = (event.clientX / window.innerWidth) * 2 - 1;
-                mouse2d.y = -(event.clientY / window.innerHeight) * 2 + 1;
-                mouse2d.z = 1;
+                mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
+                mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
+
             }
 
             function animate(){
-                requestAnimationFrame(animate);
 
-                var r = new THREE.Ray();
-                r.origin = mouse2d.clone();
-                var matrix = camera.matrixWorld.clone();
-                matrix.multiplySelf(THREE.Matrix4.makeInvert(camera.projectionMatrix));
-                matrix.multiplyVector3(r.origin);
-                r.direction = r.origin.clone().subSelf(camera.position);
+                requestAnimationFrame( animate );
 
-                for (var i = 0; i < geoms.length; i++) {
+                var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
+                projector.unprojectVector( vector, camera );
+
+                var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
+
+                for ( var i = 0; i < geoms.length; i++) {
                     geoms[i].materials[0].color = new THREE.Color(0x007700);
                 }
 
@@ -162,14 +165,14 @@
                     // Raycast all
 
                     ts = new Date().getTime();
-                    var cs = THREE.Collisions.rayCastAll( r );
+                    var cs = THREE.Collisions.rayCastAll( ray );
                     tt = new Date().getTime() - ts;
 
                     if ( cs.length > 0 ) {
 
                         info.innerHTML = cs.length + " colliders found in " + tt;
 
-                        for ( var i = 0; i < cs.length; i++ ) {
+                        for ( var i = 0; i < cs.length; i ++ ) {
 
                             cs[ i ].mesh.materials[ 0 ].color.setHex( 0xaa0000 );
 
@@ -186,7 +189,7 @@
                     // Raycast nearest
 
                     ts = new Date().getTime();
-                    var c = THREE.Collisions.rayCastNearest( r );
+                    var c = THREE.Collisions.rayCastNearest( ray );
                     tt = new Date().getTime() - ts;
 
                     if ( c ) {
@@ -211,7 +214,8 @@
 
                 renderer.render( scene, camera );
 
-				stats.update();
+                stats.update();
+
             }
 
             function vts(v){

+ 1 - 1
examples/webgl_collisions_reaction.html

@@ -48,7 +48,7 @@
         </script>
         <script type="text/javascript">
 
-            var scene, camera, renderer, info, mouse2d, sun, loader, sphere, debugNormal;
+            var camera, scene, renderer, info, mouse2d, sun, loader, sphere, debugNormal;
 
             var range = 400;
             var speed = 1;

+ 6 - 9
examples/webgl_collisions_terrain.html

@@ -43,15 +43,14 @@ body {
 
 <script type="text/javascript">
 
-var scene, camera, renderer, info, mouse2d, sun, loader, sphere, ray;
+var camera, scene, renderer,
+info, mouse2d, sun, loader, sphere, ray;
 
-var theta = 0;
-var radius = 250;
-var speed = 0.0015;
-var sphereSize = 4;
+var theta = 0, radius = 250, speed = 0.002, sphereSize = 4;
 
 
 function init() {
+
 	container = document.createElement( 'div' );
 	document.body.appendChild( container );
 
@@ -71,7 +70,6 @@ function init() {
 
 	sphere = new THREE.Mesh( new THREE.SphereGeometry( sphereSize, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0xff0000 } ) );
 	scene.addObject(sphere);
-	camera.target = sphere;
 
 	renderer = new THREE.WebGLRenderer();
 	renderer.setSize( window.innerWidth, window.innerHeight );
@@ -123,11 +121,10 @@ function animate() {
 		//info.innerHTML = "No intersection";
 	}
 
-
-
-
 	theta += speed;
 
+	camera.target.position.copy( sphere.position );
+
 	renderer.render( scene, camera );
 }
 

+ 3 - 6
examples/webgl_collisions_trigger.html

@@ -50,14 +50,11 @@
 
         <script type="text/javascript">
 
-            var scene, camera, renderer, info, mouse2d, sun, loader, sphere;
+            var camera, scene, renderer, info, mouse2d, sun, loader, sphere;
 
-            var range = 400;
-            var speed = 1;
-            var sphereSize = 4;
-
-			var cubes = [];
+            var range = 400, speed = 1, sphereSize = 4;
 
+            var cubes = [];
 
             function init(){
                 container = document.createElement('div');

+ 198 - 0
examples/webgl_custom_attributes.html

@@ -0,0 +1,198 @@
+<!doctype html>
+<html>
+	<head>
+		<meta charset="utf-8" />
+		<title>three.js webgl - custom attributes</title>
+		<style>
+			body {
+				color: #ffffff;
+				font-family:Monospace;
+				font-size:13px;
+				text-align:center;
+				font-weight: bold;
+
+				background-color: #000000;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				color: #fff;
+				position: absolute;
+				top: 0px; width: 100%;
+				padding: 5px;
+				z-index:100;
+			}
+			
+		</style>
+	</head>
+
+	<body>
+		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - custom attributes example</div>
+		<div id="container"></div>
+
+		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
+		<script type="text/javascript" src="js/Stats.js"></script>
+
+		<script src="../build/Three.js"></script>
+
+
+		<script type="x-shader/x-vertex" id="vertexshader">
+
+			uniform float amplitude;
+
+			attribute float displacement;
+
+			varying vec3 vNormal;
+			varying vec2 vUv;
+			
+			void main() {
+
+				vNormal = normal;	
+				vUv = ( 0.5 + amplitude ) * uv + vec2( amplitude );
+
+				vec3 newPosition = position + amplitude * normal * vec3( displacement );
+				gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );
+
+			}
+
+		</script>
+	
+		<script type="x-shader/x-fragment" id="fragmentshader">
+	
+			varying vec3 vNormal;
+			varying vec2 vUv;
+			
+			uniform vec3 color;
+			uniform sampler2D texture;
+
+			void main() {
+
+				vec3 light = vec3( 0.5, 0.2, 1.0 );
+				light = normalize( light );
+			
+				float dProd = dot( vNormal, light ) * 0.5 + 0.5;
+
+				vec4 tcolor = texture2D( texture, vUv );
+				vec4 gray = vec4( vec3( tcolor.r * 0.3 + tcolor.g * 0.59 + tcolor.b * 0.11 ), 1.0 );
+				
+				gl_FragColor = gray * vec4( vec3( dProd ) * vec3( color ), 1.0 );
+
+			}
+
+		</script>
+		
+		
+		<script type="text/javascript">
+	
+		var renderer, scene, camera, stats;
+
+		var sphere, uniforms, attributes;
+
+		var WIDTH = window.innerWidth,
+			HEIGHT = window.innerHeight;	
+		
+		init();
+		animate();
+
+		function init() {
+
+			camera = new THREE.Camera( 30, WIDTH / HEIGHT, 1, 10000 );
+			camera.position.z = 300;
+			
+			scene = new THREE.Scene();	
+		
+			attributes = {
+
+				displacement: {	type: 'f', value: [] }
+
+			};
+			
+			uniforms = {
+				
+				amplitude: { type: "f", value: 1.0 },
+				color:     { type: "c", value: new THREE.Color( 0xff2200 ) },
+				texture:   { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "textures/water.jpg" ) },
+
+			};
+
+			uniforms.texture.texture.wrapS = uniforms.texture.texture.wrapT = THREE.RepeatWrapping;
+
+			var shaderMaterial = new THREE.MeshShaderMaterial( {
+			
+				uniforms: 		uniforms,
+				attributes:     attributes,
+				vertexShader:   document.getElementById( 'vertexshader' ).textContent,
+				fragmentShader: document.getElementById( 'fragmentshader' ).textContent			
+
+			});
+		
+		
+			var radius = 50, segments = 128, rings = 64;
+			var geometry = new THREE.SphereGeometry( radius, segments, rings );
+			
+			sphere = new THREE.Mesh( geometry, shaderMaterial );
+			sphere.dynamic = true;
+
+			var vertices = sphere.geometry.vertices;
+			var values = attributes.displacement.value;
+
+			for( var v = 0; v < vertices.length; v++ ) {
+
+				values[ v ] = Math.random() * 5;
+
+			}
+		
+			scene.addChild( sphere );
+		
+			renderer = new THREE.WebGLRenderer( { clearColor: 0x050505, clearAlpha: 1 } );
+			renderer.setSize( WIDTH, HEIGHT );
+			
+			var container = document.getElementById( 'container' );
+			container.appendChild( renderer.domElement );
+		
+			stats = new Stats();
+			stats.domElement.style.position = 'absolute';
+			stats.domElement.style.top = '0px';
+			container.appendChild( stats.domElement );
+			
+		}
+	
+		var i, value;
+	
+		function animate() {
+
+			requestAnimationFrame( animate );
+
+			render();
+			stats.update();
+
+		}
+
+		function render() {
+		
+			sphere.rotation.y += 0.01;
+			sphere.rotation.z += 0.01;
+			
+			uniforms.amplitude.value = 2.5 * Math.sin( sphere.rotation.y * 0.125 );
+			THREE.ColorUtils.adjustHSV( uniforms.color.value, 0.0005, 0, 0 );
+			
+			for( i = 0; i < attributes.displacement.value.length; i++ ) {
+
+				value = attributes.displacement.value[ i ];
+				value[ i ] += 0.5 * ( 0.5 - Math.random() );
+				if ( value[ i ] < -5 ) value[ i ] = -5;
+				if ( value[ i ] > 5 ) value[ i ] = 5;
+
+			}
+			attributes.displacement.needsUpdate = true;
+
+			renderer.render( scene, camera );
+
+		}
+
+
+	</script>
+
+</body>
+
+</html>

+ 58 - 66
examples/webgl_flycamera_earth.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 	<title>three.js webgl - fly camera - earth</title>
-	<style type="text/css"> 
+	<style type="text/css">
 	body {
 		background:#000;
 		color: #eee;
@@ -26,14 +26,14 @@
 
 		color: #0080ff;
 	}
-	
+
 	b { color:orange }
-	
-	</style> 
 
-	<script type="text/javascript" src="../build/Three.js"></script> 
+	</style>
+
+	<script type="text/javascript" src="../build/Three.js"></script>
 	<script type="text/javascript" src="js/Detector.js"></script>
-	<script type="text/javascript" src="js/RequestAnimationFrame.js"></script> 
+	<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
 	<script type="text/javascript" src="js/Stats.js"></script>
 
 </head>
@@ -58,11 +58,11 @@
 	var MARGIN = 0;
 	var SCREEN_HEIGHT = window.innerHeight - MARGIN * 2;
 	var SCREEN_WIDTH  = window.innerWidth;
-	
+
 	var ENABLE_LENSFLARES = false;
 
 	var lensFlare, lensFlareRotate;
-	
+
 	var container, stats;
 	var camera, scene, sceneCube, renderer;
 	var geometry, meshPlanet, meshClouds, meshMoon;
@@ -72,18 +72,18 @@
 	var t, d, dPlanet, dMoon, dMoonVec = new THREE.Vector3();
 
 	var postprocessing = { enabled : true, bloom: false };
-	
+
 	init();
 	animate();
 
 	function init() {
-		
+
 		container = document.createElement( 'div' );
-        document.body.appendChild( container ); 
+        document.body.appendChild( container );
 
         camera = new THREE.FlyCamera({
-		
-			fov: 25, 
+
+			fov: 25,
 			aspect: SCREEN_WIDTH / SCREEN_HEIGHT,
 			movementSpeed: 1000,
 			domElement: container,
@@ -99,7 +99,7 @@
 
         scene = new THREE.Scene();
 		scene.fog = new THREE.FogExp2( 0x000000, 0.00000025 );
-		
+
         dirLight = new THREE.DirectionalLight( 0xffffff );
         dirLight.position.set( -1, 0, 1 );
         dirLight.position.normalize();
@@ -108,7 +108,7 @@
         pointLight = new THREE.PointLight( 0x000000 );
         pointLight.position.set( -5000, 0, 5000 );
         //scene.addLight( pointLight );
-		
+
 		ambientLight = new THREE.AmbientLight( 0x000000 );
 		scene.addLight( ambientLight );
 
@@ -132,34 +132,26 @@
 		uniforms[ "enableDiffuse" ].value = true;
 		uniforms[ "enableSpecular" ].value = true;
 
-		uniforms[ "uDirLightPos" ].value = dirLight.position;
-		uniforms[ "uDirLightColor" ].value = dirLight.color;
-
-		uniforms[ "uPointLightPos" ].value = pointLight.position;
-		uniforms[ "uPointLightColor" ].value = pointLight.color;
-
-		uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
-
 		uniforms[ "uDiffuseColor" ].value.setHex( 0xffffff );
 		uniforms[ "uSpecularColor" ].value.setHex( 0xaaaaaa );
 		uniforms[ "uAmbientColor" ].value.setHex( 0x000000 );
 
 		uniforms[ "uShininess" ].value = 30;
 
-		var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms };
+		var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
 		var materialNormalMap = new THREE.MeshShaderMaterial( parameters );
 
-		// planet		
-		
+		// planet
+
         geometry = new THREE.SphereGeometry( radius, 100, 50 );
-		geometry.computeTangents();		
+		geometry.computeTangents();
 
         meshPlanet = new THREE.Mesh( geometry, materialNormalMap );
 		meshPlanet.rotation.y = 1.3;
 		meshPlanet.rotation.z = tilt;
         scene.addObject( meshPlanet );
 
-		// clouds		
+		// clouds
 
         var materialClouds = new THREE.MeshLambertMaterial( { color: 0xffffff, map: cloudsTexture, transparent:true } );
 
@@ -171,17 +163,17 @@
 		// moon
 
         var materialMoon = new THREE.MeshPhongMaterial( { color: 0xffffff, map: moonTexture } );
-		
+
         meshMoon = new THREE.Mesh( geometry, materialMoon );
 		meshMoon.position.set( radius * 5, 0, 0 );
 		meshMoon.scale.set( moonScale, moonScale, moonScale );
         scene.addObject( meshMoon );
 
 		// stars
-		
+
 		var i, r = radius,
 			starsGeometry = [ new THREE.Geometry(), new THREE.Geometry() ];
- 
+
 		for ( i = 0; i < 250; ++i ) {
 
 			vector1 = new THREE.Vector3( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
@@ -208,49 +200,49 @@
 							   new THREE.ParticleBasicMaterial( { color: 0x1a1a1a, size: 2, sizeAttenuation: false } ),
 							   new THREE.ParticleBasicMaterial( { color: 0x1a1a1a, size: 1, sizeAttenuation: false } )
 							];
-		
+
 		for ( i = 10; i < 30; i ++) {
-		
+
 			stars = new THREE.ParticleSystem( starsGeometry[ i % 2 ], starsMaterials[ i % 6 ] );
 			stars.rotation.x = Math.random() * 6;
 			stars.rotation.y = Math.random() * 6;
 			stars.rotation.z = Math.random() * 6;
-			
+
 			s = i * 10;
 			stars.scale.set( s, s, s );
-			
+
 			stars.matrixAutoUpdate = false;
 			stars.updateMatrix();
-			
+
 			scene.addObject( stars );
-			
+
 		}
 
 		if ( ENABLE_LENSFLARES ) {
-		
+
 			lensFlare = new THREE.LensFlare( THREE.ImageUtils.loadTexture( "textures/lensflare/lensflare0.png" ), 700, 0.0, THREE.AdditiveBlending );
-			
+
 			lensFlare.add( THREE.ImageUtils.loadTexture( "textures/lensflare/lensflare2.png" ), 512, 0.0, THREE.AdditiveBlending );
 			lensFlare.add( lensFlare.lensFlares[ 1 ].texture, 512, 0.0, THREE.AdditiveBlending );
 			lensFlare.add( lensFlare.lensFlares[ 1 ].texture, 512, 0.0, THREE.AdditiveBlending );
-			
+
 			lensFlare.add( THREE.ImageUtils.loadTexture( "textures/lensflare/lensflare3.png" ), 60, 0.6, THREE.AdditiveBlending );
 			lensFlare.add( lensFlare.lensFlares[ 4 ].texture, 70, 0.7, THREE.AdditiveBlending );
 			lensFlare.add( lensFlare.lensFlares[ 4 ].texture, 120, 0.9, THREE.AdditiveBlending );
 			lensFlare.add( lensFlare.lensFlares[ 4 ].texture, 70, 1.0, THREE.AdditiveBlending );
-			
+
 			lensFlare.customUpdateCallback = lensFlareUpdateCallback;
 			lensFlare.position.set( 0, 0, -99000 );
-			
-			
+
+
 			lensFlareRotate = new THREE.Object3D();
 			lensFlareRotate.addChild( lensFlare );
-			
+
 			scene.addChild( lensFlareRotate );
-			
+
 			lensFlareRotate.rotation.x = Math.PI;
 			lensFlareRotate.rotation.y = Math.PI / 2;
-			
+
 		}
 
         renderer = new THREE.WebGLRenderer( { clearAlpha: 1, clearColor: 0x000000 } );
@@ -351,28 +343,28 @@
 	};
 
 	function cap_bottom( val, bottom ) {
-	
+
 		return val < bottom ? bottom : val;
 
 	};
-	
+
 	function lensFlareUpdateCallback( object ) {
 
 		var f, fl = object.lensFlares.length;
 		var flare;
 		var vecX = -object.positionScreen.x * 2;
-		var vecY = -object.positionScreen.y * 2; 
+		var vecY = -object.positionScreen.y * 2;
 
 
 		for( f = 0; f < fl; f++ ) {
-			   
+
 			   flare = object.lensFlares[ f ];
-			   
+
 			   flare.x = object.positionScreen.x + vecX * flare.distance;
 			   flare.y = object.positionScreen.y + vecY * flare.distance;
 
 			   flare.rotation = 0;
-			   
+
 			   flare.opacity = cap_bottom( 1 - 0.01 * d / radius, 0 );
 
 		}
@@ -387,15 +379,15 @@
 	function animate() {
 
 		requestAnimationFrame( animate );
- 
+
         render();
         stats.update();
 
 	};
 
-	
+
 	function cap( val, bottom ) {
-	
+
 		return val > bottom ? val : bottom;
 
 	};
@@ -406,34 +398,34 @@
 
 		t = this.getFrametime();
 
-        meshPlanet.rotation.y += rotationSpeed * t; 
+        meshPlanet.rotation.y += rotationSpeed * t;
 		meshClouds.rotation.y += 1.25 * rotationSpeed * t;
-		
+
 		// slow down as we approach the surface
 
 		dPlanet = camera.position.length();
 
 		dMoonVec.sub( camera.position, meshMoon.position );
 		dMoon = dMoonVec.length();
-		
+
 		if ( dMoon < dPlanet ) {
 
 			d = ( dMoon - radius * moonScale * 1.01 );
 
 		} else {
-		
+
 			d = ( dPlanet - radius * 1.01 );
 
 		}
-		
+
         camera.movementSpeed = 0.33 * d;
 
 		if ( ENABLE_LENSFLARES ) {
-		
+
 			lensFlareRotate.position.set( camera.position.x, camera.position.y, camera.position.z );
-			
+
 		}
-		
+
 		if ( postprocessing.enabled ) {
 
 			renderer.clear();
@@ -443,7 +435,7 @@
 			renderer.render( scene, camera, postprocessing.rtTexture1, true );
 
 			if ( postprocessing.bloom ) {
-			
+
 				// Render quad with blured scene into texture (convolution pass 1)
 
 				postprocessing.quad.materials = [ postprocessing.materialConvolution ];
@@ -470,7 +462,7 @@
 				renderer.render( postprocessing.scene, postprocessing.camera, postprocessing.rtTexture1, false );
 
 			}
-			
+
 			// Render to screen
 
 			postprocessing.materialFilm.uniforms.time.value += 0.01;
@@ -487,7 +479,7 @@
 		}
 
 	};
-	
+
 	function getFrametime() {
 
         var now = new Date().getTime();

+ 1 - 1
examples/webgl_geometry_dynamic.html

@@ -70,7 +70,7 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.QuakeCamera( {
+				camera = new THREE.FirstPersonCamera( {
 
 					fov: 60, aspect: window.innerWidth / window.innerHeight, near: 1, far: 20000,
 					movementSpeed: 500, lookSpeed: 0.1, noFly: false, lookVertical: true

+ 1 - 1
examples/webgl_geometry_minecraft.html

@@ -75,7 +75,7 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.QuakeCamera( {
+				camera = new THREE.FirstPersonCamera( {
 
 					fov: 60, aspect: window.innerWidth / window.innerHeight, near: 1, far: 20000,
 					movementSpeed: 1000, lookSpeed: 0.125, noFly: false, lookVertical: true

+ 1 - 1
examples/webgl_geometry_minecraft_ao.html

@@ -83,7 +83,7 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.QuakeCamera( {
+				camera = new THREE.FirstPersonCamera( {
 
 					fov: 50, aspect: window.innerWidth / window.innerHeight, near: 1, far: 20000,
 					constrainVertical: true, verticalMin: 1.1, verticalMax: 2.2,

+ 1 - 1
examples/webgl_geometry_terrain.html

@@ -67,7 +67,7 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.QuakeCamera( {
+				camera = new THREE.FirstPersonCamera( {
 
 					fov: 60, aspect: window.innerWidth / window.innerHeight, near: 1, far: 20000,
 					movementSpeed: 1000, lookSpeed: 0.1, noFly: false, lookVertical: true

+ 1 - 1
examples/webgl_geometry_terrain_fog.html

@@ -66,7 +66,7 @@
 
 				container = document.getElementById( 'container' );
 
-				camera = new THREE.QuakeCamera( {
+				camera = new THREE.FirstPersonCamera( {
 
 					fov: 60, aspect: window.innerWidth / window.innerHeight, near: 1, far: 10000,
 					movementSpeed: 150, lookSpeed: 0.1, noFly: false, lookVertical: true

+ 4 - 13
examples/webgl_materials_normalmap.html

@@ -54,7 +54,6 @@
 		</div>
 
 		<script type="text/javascript" src="../build/Three.js"></script>
-
 		<script type="text/javascript" src="js/Detector.js"></script>
 		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
 		<script type="text/javascript" src="js/Stats.js"></script>
@@ -89,8 +88,8 @@
 
 			function init() {
 
-				container = document.createElement('div');
-				document.body.appendChild(container);
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
 
 				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
 				camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -10000, 10000 );
@@ -141,22 +140,14 @@
 				uniforms[ "tDisplacement" ].texture = THREE.ImageUtils.loadTexture( "textures/normal/ninja/displacement.jpg" );
 				uniforms[ "uDisplacementBias" ].value = - 0.428408 * scale;
 				uniforms[ "uDisplacementScale" ].value = 2.436143 * scale;
-
-				uniforms[ "uPointLightPos" ].value = pointLight.position;
-				uniforms[ "uPointLightColor" ].value = pointLight.color;
-
-				uniforms[ "uDirLightPos" ].value = directionalLight.position;
-				uniforms[ "uDirLightColor" ].value = directionalLight.color;
-
-				uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
-
+				
 				uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
 				uniforms[ "uSpecularColor" ].value.setHex( specular );
 				uniforms[ "uAmbientColor" ].value.setHex( ambient );
 
 				uniforms[ "uShininess" ].value = shininess;
 
-				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms };
+				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
 				var material1 = new THREE.MeshShaderMaterial( parameters );
 
 				var material2 = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess } );

+ 3 - 11
examples/webgl_materials_normalmap2.html

@@ -84,8 +84,8 @@
 
 			function init() {
 
-				container = document.createElement('div');
-				document.body.appendChild(container);
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
 
 				camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
 				camera.position.z = 900;
@@ -125,21 +125,13 @@
 				uniforms[ "enableDiffuse" ].value = true;
 				uniforms[ "enableSpecular" ].value = false;
 
-				uniforms[ "uPointLightPos" ].value = pointLight.position;
-				uniforms[ "uPointLightColor" ].value = pointLight.color;
-
-				uniforms[ "uDirLightPos" ].value = directionalLight.position;
-				uniforms[ "uDirLightColor" ].value = directionalLight.color;
-
-				uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
-
 				uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
 				uniforms[ "uSpecularColor" ].value.setHex( specular );
 				uniforms[ "uAmbientColor" ].value.setHex( ambient );
 
 				uniforms[ "uShininess" ].value = shininess;
 
-				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms };
+				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
 				var material = new THREE.MeshShaderMaterial( parameters );
 
 				loader = new THREE.JSONLoader( true );

+ 1 - 1
examples/webgl_objconvert_test.html

@@ -16,7 +16,7 @@
 			a { color:skyblue }
 			canvas { pointer-events:none; z-index:10; }
 			#log { position:absolute; top:0; display:block; text-align:left; z-index:1000; pointer-events:none; }
-			#d { text-align:center; margin:1em 0 -15.7em 0; z-index:0; position:relative; display:block }
+			#d { text-align:center; margin:1em 0 -9.2em 0; z-index:0; position:relative; display:block }
 			.button { background:#000; color:#fff; padding:0.2em 0.5em; cursor:pointer }
 			.inactive { background:#999; color:#eee }
 		</style>

+ 1 - 9
examples/webgl_postprocessing.html

@@ -222,21 +222,13 @@
 				uniforms[ "enableAO" ].value = false;
 				uniforms[ "enableDiffuse" ].value = true;
 
-				uniforms[ "uPointLightPos" ].value = new THREE.Vector3(0,0,0);
-				uniforms[ "uPointLightColor" ].value = new THREE.Color(1,0,0);
-
-				uniforms[ "uDirLightPos" ].value = directionalLight.position;
-				uniforms[ "uDirLightColor" ].value = directionalLight.color;
-
-				uniforms[ "uAmbientLightColor" ].value = new THREE.Color(0,0,0);
-
 				uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
 				uniforms[ "uSpecularColor" ].value.setHex( specular );
 				uniforms[ "uAmbientColor" ].value.setHex( ambient );
 
 				uniforms[ "uShininess" ].value = shininess;
 
-				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms };
+				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
 				var mat2 = new THREE.MeshShaderMaterial( parameters );
 
 				mesh = new THREE.Mesh( geometry, mat2 );

+ 2 - 11
examples/webgl_postprocessing_dof.html

@@ -299,21 +299,12 @@
 
 					// Render scene into texture
 
-					if ( singleMaterial )
-						zmaterial[ 0 ] = cubeMaterial;
-					else
-						for( i = 0; i < nobjects; i++ ) objects[ i ].materials[ 0 ] = materials[ i ];
-
-
+					scene.overrideMaterial = null;
 					renderer.render( scene, camera, postprocessing.rtTextureColor, true );
 
 					// Render depth into texture
 
-					if ( singleMaterial )
-						zmaterial[ 0 ] = material_depth;
-					else
-						for( i = 0; i < nobjects; i++ ) objects[i].materials[ 0 ] = material_depth;
-
+					scene.overrideMaterial = material_depth;
 					renderer.render( scene, camera, postprocessing.rtTextureDepth, true );
 
 					// Render bokeh composite

+ 1 - 1
examples/webgl_sandbox.html

@@ -109,7 +109,7 @@
 		<script type="text/javascript" src="../src/extras/ShaderUtils.js"></script>
 		<script type="text/javascript" src="../src/extras/animation/AnimationHandler.js"></script>
 		<script type="text/javascript" src="../src/extras/animation/Animation.js"></script>
-		<script type="text/javascript" src="../src/extras/cameras/QuakeCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/cameras/FirstPersonCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/PathCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/FlyCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/RollCamera.js"></script>

+ 0 - 2
examples/webgl_sprites.html

@@ -46,7 +46,6 @@
 
 				scene = new THREE.Scene();
 
-
 				// create sprites
 
 				var amount = 200;
@@ -99,7 +98,6 @@
 				renderer = new THREE.WebGLRenderer();
 				renderer.setClearColorHex( 0x000000, 1 );
 				renderer.setSize( window.innerWidth, window.innerHeight );
-				renderer.sortObjects = true;
 
 				container.appendChild( renderer.domElement );
 

+ 11 - 15
examples/webgl_trackballcamera_earth.html

@@ -28,7 +28,7 @@
 		a { color: green; }
 		b { color: green; }
 
-	</style> 
+	</style>
 
 	<script type="text/javascript" src="../build/Three.js"></script>
 	<script type="text/javascript" src="js/Detector.js"></script>
@@ -81,7 +81,7 @@
 	function init() {
 
 		container = document.createElement( 'div' );
-		document.body.appendChild( container ); 
+		document.body.appendChild( container );
 
 
 		scene = new THREE.Scene();
@@ -96,7 +96,7 @@
 
 		camera = new THREE.TrackballCamera({
 
-			fov: 25, 
+			fov: 25,
 			aspect: width / height,
 			near: 50,
 			far: 1e7,
@@ -150,11 +150,6 @@
 		uniforms[ "enableDiffuse" ].value = true;
 		uniforms[ "enableSpecular" ].value = true;
 
-		uniforms[ "uDirLightPos" ].value = dirLight.position;
-		uniforms[ "uDirLightColor" ].value = dirLight.color;
-
-		uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
-
 		uniforms[ "uDiffuseColor" ].value.setHex( 0xffffff );
 		uniforms[ "uSpecularColor" ].value.setHex( 0xaaaaaa );
 		uniforms[ "uAmbientColor" ].value.setHex( 0x000000 );
@@ -162,11 +157,12 @@
 		uniforms[ "uShininess" ].value = 30;
 
 		var materialNormalMap = new THREE.MeshShaderMaterial({
-			fragmentShader: shader.fragmentShader, 
-			vertexShader: shader.vertexShader, 
-			uniforms: uniforms 
+			fragmentShader: shader.fragmentShader,
+			vertexShader: shader.vertexShader,
+			uniforms: uniforms,
+			lights: true
 		});
-		
+
 
 		// planet
 
@@ -215,7 +211,7 @@
 		}
 
 		var stars,
-		starsMaterials = [ 
+		starsMaterials = [
 			new THREE.ParticleBasicMaterial( { color: 0x555555, size: 2, sizeAttenuation: false } ),
 			new THREE.ParticleBasicMaterial( { color: 0x555555, size: 1, sizeAttenuation: false } ),
 			new THREE.ParticleBasicMaterial( { color: 0x333333, size: 2, sizeAttenuation: false } ),
@@ -272,7 +268,7 @@
 	function animate() {
 
 		requestAnimationFrame( animate );
- 
+
 		render();
 		stats.update();
 
@@ -284,7 +280,7 @@
 		dt = ( t - time ) / 1000;
 		time = t;
 
-		meshPlanet.rotation.y += rotationSpeed * dt; 
+		meshPlanet.rotation.y += rotationSpeed * dt;
 		meshClouds.rotation.y += 1.25 * rotationSpeed * dt;
 
 		var angle = dt * rotationSpeed;

+ 98 - 34
src/core/Matrix4.js

@@ -165,27 +165,6 @@ THREE.Matrix4.prototype = {
 		b31 = b.n31, b32 = b.n32, b33 = b.n33, b34 = b.n34,
 		b41 = b.n41, b42 = b.n42, b43 = b.n43, b44 = b.n44;
 
-		this.n11 = a11 * b11 + a12 * b21 + a13 * b31;
-		this.n12 = a11 * b12 + a12 * b22 + a13 * b32;
-		this.n13 = a11 * b13 + a12 * b23 + a13 * b33;
-		this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14;
-
-		this.n21 = a21 * b11 + a22 * b21 + a23 * b31;
-		this.n22 = a21 * b12 + a22 * b22 + a23 * b32;
-		this.n23 = a21 * b13 + a22 * b23 + a23 * b33;
-		this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24;
-
-		this.n31 = a31 * b11 + a32 * b21 + a33 * b31;
-		this.n32 = a31 * b12 + a32 * b22 + a33 * b32;
-		this.n33 = a31 * b13 + a32 * b23 + a33 * b33;
-		this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34;
-
-		this.n41 = a41 * b11 + a42 * b21 + a43 * b31;
-		this.n42 = a41 * b12 + a42 * b22 + a43 * b32;
-		this.n43 = a41 * b13 + a42 * b23 + a43 * b33;
-		this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44;
-
-		/*
 		this.n11 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
 		this.n12 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
 		this.n13 = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
@@ -205,7 +184,6 @@ THREE.Matrix4.prototype = {
 		this.n42 = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
 		this.n43 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
 		this.n44 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
-		*/
 
 		return this;
 
@@ -532,30 +510,116 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setRotationFromEuler: function( v ) {
+	setRotationFromEuler: function( v, order ) {
 
 		var x = v.x, y = v.y, z = v.z,
 		a = Math.cos( x ), b = Math.sin( x ),
 		c = Math.cos( y ), d = Math.sin( y ),
-		e = Math.cos( z ), f = Math.sin( z ),
-		ad = a * d, bd = b * d;
+		e = Math.cos( z ), f = Math.sin( z );
 
-		this.n11 = c * e;
-		this.n12 = - c * f;
-		this.n13 = d;
+		switch ( order ) {
+			case 'YXZ':
+				var ce = c * e, cf = c * f, de = d * e, df = d * f;
 
-		this.n21 = bd * e + a * f;
-		this.n22 = - bd * f + a * e;
-		this.n23 = - b * c;
+				this.n11 = ce + df * b;
+				this.n12 = de * b - cf;
+				this.n13 = a * d;
 
-		this.n31 = - ad * e + b * f;
-		this.n32 = ad * f + b * e;
-		this.n33 = a * c;
+				this.n21 = a * f;
+				this.n22 = a * e;
+				this.n23 = - b;
+
+				this.n31 = cf * b - de;
+				this.n32 = df + ce * b;
+				this.n33 = a * c;
+				break;
+
+			case 'ZXY':
+				var ce = c * e, cf = c * f, de = d * e, df = d * f;
+
+				this.n11 = ce - df * b;
+				this.n12 = - a * f;
+				this.n13 = de + cf * b;
+
+				this.n21 = cf + de * b;
+				this.n22 = a * e;
+				this.n23 = df - ce * b;
+
+				this.n31 = - a * d;
+				this.n32 = b;
+				this.n33 = a * c;
+				break;
+
+			case 'ZYX':
+				var ae = a * e, af = a * f, be = b * e, bf = b * f;
+
+				this.n11 = c * e;
+				this.n12 = be * d - af;
+				this.n13 = ae * d + bf;
+
+				this.n21 = c * f;
+				this.n22 = bf * d + ae;
+				this.n23 = af * d - be;
+
+				this.n31 = - d;
+				this.n32 = b * c;
+				this.n33 = a * c;
+				break;
+
+			case 'YZX':
+				var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
+
+				this.n11 = c * e;
+				this.n12 = bd - ac * f;
+				this.n13 = bc * f + ad;
+
+				this.n21 = f;
+				this.n22 = a * e;
+				this.n23 = - b * e;
+
+				this.n31 = - d * e;
+				this.n32 = ad * f + bc;
+				this.n33 = ac - bd * f;
+				break;
+
+			case 'XZY':
+				var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
+
+				this.n11 = c * e;
+				this.n12 = - f;
+				this.n13 = d * e;
+
+				this.n21 = ac * f + bd;
+				this.n22 = a * e;
+				this.n23 = ad * f - bc;
+
+				this.n31 = bc * f - ad;
+				this.n32 = b * e;
+				this.n33 = bd * f + ac;
+				break;
+
+			default: // 'XYZ'
+				var ae = a * e, af = a * f, be = b * e, bf = b * f;
+
+				this.n11 = c * e;
+				this.n12 = - c * f;
+				this.n13 = d;
+
+				this.n21 = af + be * d;
+				this.n22 = ae - bf * d;
+				this.n23 = - b * c;
+
+				this.n31 = bf - ae * d;
+				this.n32 = be + af * d;
+				this.n33 = a * c;
+				break;
+		}
 
 		return this;
 
 	},
 
+
 	setRotationFromQuaternion: function( q ) {
 
 		var x = q.x, y = q.y, z = q.z, w = q.w,

+ 4 - 1
src/core/Object3D.js

@@ -13,6 +13,7 @@ THREE.Object3D = function() {
 
 	this.position = new THREE.Vector3();
 	this.rotation = new THREE.Vector3();
+	this.eulerOrder = 'XYZ';
 	this.scale = new THREE.Vector3( 1, 1, 1 );
 
 	this.dynamic = false; // when true it retains arrays so they can be updated with __dirty*
@@ -20,6 +21,8 @@ THREE.Object3D = function() {
 	this.doubleSided = false;
 	this.flipSided = false;
 
+	this.renderDepth = null;
+
 	this.rotationAutoUpdate = true;
 
 	this.matrix = new THREE.Matrix4();
@@ -173,7 +176,7 @@ THREE.Object3D.prototype = {
 
 		} else {
 
-			this.matrix.setRotationFromEuler( this.rotation );
+			this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder );
 
 		}
 

+ 6 - 5
src/core/Ray.js

@@ -150,16 +150,17 @@ THREE.Ray.prototype = {
 
 		function distanceFromIntersection( origin, direction, object ) {
 
-			var vector, dot, intersect, distance;
+			var vector, dot, intersect, distance,
+			position = object.matrixWorld.getPosition();
 
-			vector = object.position.clone().subSelf( origin );
+			vector = position.clone().subSelf( origin );
 			dot = vector.dot( direction );
 
-			if ( dot < 0 ) return false; // Object is behind origin
-
 			intersect = origin.clone().addSelf( direction.clone().multiplyScalar( dot ) );
-			distance = object.position.distanceTo( intersect );
+			distance = position.distanceTo( intersect );
 
+			// TODO: Check if distance is negative (object behind camera).			
+			
 			return distance;
 
 		}

+ 116 - 61
src/extras/ShaderUtils.js

@@ -3,6 +3,8 @@
  * @author mr.doob / http://mrdoob.com/
  */
 
+if ( THREE.WebGLRenderer ) {
+
 THREE.ShaderUtils = {
 
 	lib: {
@@ -86,12 +88,16 @@ THREE.ShaderUtils = {
 		//	Normal map shader
 		//		- Blinn-Phong
 		//		- normal + diffuse + specular + AO + displacement maps
-		//		- 1 point and 1 directional lights
+		//		- point and directional lights (use with "lights: true" material option)
 		 ------------------------------------------------------------------------- */
 
 		'normal' : {
 
-			uniforms: {
+			uniforms: THREE.UniformsUtils.merge( [
+
+				THREE.UniformsLib[ "lights" ],
+
+				{
 
 				"enableAO"		: { type: "i", value: 0 },
 				"enableDiffuse"	: { type: "i", value: 0 },
@@ -105,36 +111,26 @@ THREE.ShaderUtils = {
 				"uNormalScale": { type: "f", value: 1.0 },
 
 				"tDisplacement": { type: "t", value: 5, texture: null },
-				"uDisplacementBias": { type: "f", value: -0.5 },
-				"uDisplacementScale": { type: "f", value: 2.5 },
-
-				"uPointLightPos": { type: "v3", value: new THREE.Vector3() },
-				"uPointLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
-
-				"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
-				"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
-
-				"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
+				"uDisplacementBias": { type: "f", value: 0.0 },
+				"uDisplacementScale": { type: "f", value: 1.0 },
 
 				"uDiffuseColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
 				"uSpecularColor": { type: "c", value: new THREE.Color( 0x111111 ) },
 				"uAmbientColor": { type: "c", value: new THREE.Color( 0x050505 ) },
-				"uShininess": { type: "f", value: 30 }
+				"uShininess": { type: "f", value: 30 },
+				"uOpacity": { type: "f", value: 1 }
 
-			},
-
-			fragmentShader: [
+				}
 
-				"uniform vec3 uDirLightPos;",
+			] ),
 
-				"uniform vec3 uAmbientLightColor;",
-				"uniform vec3 uDirLightColor;",
-				"uniform vec3 uPointLightColor;",
+			fragmentShader: [
 
 				"uniform vec3 uAmbientColor;",
 				"uniform vec3 uDiffuseColor;",
 				"uniform vec3 uSpecularColor;",
 				"uniform float uShininess;",
+				"uniform float uOpacity;",
 
 				"uniform bool enableDiffuse;",
 				"uniform bool enableSpecular;",
@@ -152,24 +148,38 @@ THREE.ShaderUtils = {
 				"varying vec3 vNormal;",
 				"varying vec2 vUv;",
 
-				"varying vec3 vPointLightVector;",
+				"uniform vec3 ambientLightColor;",
+
+				"#if MAX_DIR_LIGHTS > 0",
+					"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
+					"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
+				"#endif",
+
+				"#if MAX_POINT_LIGHTS > 0",
+					"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
+					"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
+				"#endif",
+
 				"varying vec3 vViewPosition;",
 
 				"void main() {",
 
-					"vec3 diffuseTex = vec3( 1.0, 1.0, 1.0 );",
-					"vec3 aoTex = vec3( 1.0, 1.0, 1.0 );",
-					"vec3 specularTex = vec3( 1.0, 1.0, 1.0 );",
+					"gl_FragColor = vec4( 1.0 );",
+
+					"vec4 mColor = vec4( uDiffuseColor, uOpacity );",
+					"vec4 mSpecular = vec4( uSpecularColor, uOpacity );",
+
+					"vec3 specularTex = vec3( 1.0 );",
 
 					"vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
 					"normalTex.xy *= uNormalScale;",
 					"normalTex = normalize( normalTex );",
 
 					"if( enableDiffuse )",
-						"diffuseTex = texture2D( tDiffuse, vUv ).xyz;",
+						"gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
 
 					"if( enableAO )",
-						"aoTex = texture2D( tAO, vUv ).xyz;",
+						"gl_FragColor = gl_FragColor * texture2D( tAO, vUv );",
 
 					"if( enableSpecular )",
 						"specularTex = texture2D( tSpecular, vUv ).xyz;",
@@ -180,51 +190,70 @@ THREE.ShaderUtils = {
 					"vec3 normal = normalize( finalNormal );",
 					"vec3 viewPosition = normalize( vViewPosition );",
 
-					// point light
+					// point lights
+
+					"#if MAX_POINT_LIGHTS > 0",
 
-					"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );",
-					"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );",
+						"vec4 pointTotal  = vec4( 0.0 );",
 
-					"vec3 pointVector = normalize( vPointLightVector );",
-					"vec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );",
+						"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
-					"float pointDotNormalHalf = dot( normal, pointHalfVector );",
-					"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
+							"vec3 pointVector = normalize( vPointLight[ i ].xyz );",
+							"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + vViewPosition );",
+							"float pointDistance = vPointLight[ i ].w;",
+
+							"float pointDotNormalHalf = dot( normal, pointHalfVector );",
+							"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
+
+							"float pointSpecularWeight = 0.0;",
+							"if ( pointDotNormalHalf >= 0.0 )",
+								"pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );",
+
+							"pointTotal  += pointDistance * vec4( pointLightColor[ i ], 1.0 ) * ( mColor * pointDiffuseWeight + mSpecular * pointSpecularWeight * pointDiffuseWeight );",
+
+						"}",
+
+					"#endif",
 
-					"float pointSpecularWeight = 0.0;",
-					"if ( pointDotNormalHalf >= 0.0 )",
-						"pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );",
+					// directional lights
 
-					"pointDiffuse  += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;",
-					"pointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight * pointDiffuseWeight;",
+					"#if MAX_DIR_LIGHTS > 0",
 
-					// directional light
+						"vec4 dirTotal  = vec4( 0.0 );",
 
-					"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );",
-					"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );",
+						"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
 
-					"vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );",
+							"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
 
-					"vec3 dirVector = normalize( lDirection.xyz );",
-					"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
+							"vec3 dirVector = normalize( lDirection.xyz );",
+							"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
 
-					"float dirDotNormalHalf = dot( normal, dirHalfVector );",
-					"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
+							"float dirDotNormalHalf = dot( normal, dirHalfVector );",
+							"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
 
-					"float dirSpecularWeight = 0.0;",
-					"if ( dirDotNormalHalf >= 0.0 )",
-						"dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );",
+							"float dirSpecularWeight = 0.0;",
+							"if ( dirDotNormalHalf >= 0.0 )",
+								"dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );",
 
-					"dirDiffuse  += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;",
-					"dirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight * dirDiffuseWeight;",
+							"dirTotal  += vec4( directionalLightColor[ i ], 1.0 ) * ( mColor * dirDiffuseWeight + mSpecular * dirSpecularWeight * dirDiffuseWeight );",
+
+						"}",
+
+					"#endif",
 
 					// all lights contribution summation
 
-					"vec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );",
-					"totalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );",
-					"totalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );",
+					"vec4 totalLight = vec4( ambientLightColor * uAmbientColor, uOpacity );",
+
+					"#if MAX_DIR_LIGHTS > 0",
+						"totalLight += dirTotal;",
+					"#endif",
+
+					"#if MAX_POINT_LIGHTS > 0",
+						"totalLight += pointTotal;",
+					"#endif",
 
-					"gl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );",
+					"gl_FragColor = gl_FragColor * totalLight;",
 
 				"}"
 
@@ -234,8 +263,6 @@ THREE.ShaderUtils = {
 
 				"attribute vec4 tangent;",
 
-				"uniform vec3 uPointLightPos;",
-
 				"#ifdef VERTEX_TEXTURES",
 
 					"uniform sampler2D tDisplacement;",
@@ -249,7 +276,15 @@ THREE.ShaderUtils = {
 				"varying vec3 vNormal;",
 				"varying vec2 vUv;",
 
-				"varying vec3 vPointLightVector;",
+				"#if MAX_POINT_LIGHTS > 0",
+
+					"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
+					"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
+
+					"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
+
+				"#endif",
+
 				"varying vec3 vViewPosition;",
 
 				"void main() {",
@@ -269,10 +304,28 @@ THREE.ShaderUtils = {
 
 					"vUv = uv;",
 
-					// point light
+					// point lights
+
+					"#if MAX_POINT_LIGHTS > 0",
+
+						"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {",
+
+							"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
+
+							"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
+
+							"float lDistance = 1.0;",
 
-					"vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );",
-					"vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );",
+							"if ( pointLightDistance[ i ] > 0.0 )",
+								"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
+
+							"lVector = normalize( lVector );",
+
+							"vPointLight[ i ] = vec4( lVector, lDistance );",
+
+						"}",
+
+					"#endif",
 
 					// displacement mapping
 
@@ -604,3 +657,5 @@ THREE.ShaderUtils = {
 	}
 
 };
+
+};

+ 328 - 0
src/extras/cameras/FirstPersonCamera.js

@@ -0,0 +1,328 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ * @author paulirish / http://paulirish.com/
+ *
+ * parameters = {
+ *  fov: <float>,
+ *  aspect: <float>,
+ *  near: <float>,
+ *  far: <float>,
+ *  target: <THREE.Object3D>,
+
+ *  movementSpeed: <float>,
+ *  lookSpeed: <float>,
+
+ *  noFly: <bool>,
+ *  lookVertical: <bool>,
+ *  autoForward: <bool>,
+
+ *  constrainVertical: <bool>,
+ *  verticalMin: <float>,
+ *  verticalMax: <float>,
+
+ *  heightSpeed: <bool>,
+ *  heightCoef: <float>,
+ *  heightMin: <float>,
+ *  heightMax: <float>,
+
+ *  domElement: <HTMLElement>,
+ * }
+ */
+
+THREE.FirstPersonCamera = function ( parameters ) {
+
+	THREE.Camera.call( this, parameters.fov, parameters.aspect, parameters.near, parameters.far, parameters.target );
+
+	this.movementSpeed = 1.0;
+	this.lookSpeed = 0.005;
+
+	this.noFly = false;
+	this.lookVertical = true;
+	this.autoForward = false;
+
+	this.activeLook = true;
+
+	this.heightSpeed = false;
+	this.heightCoef = 1.0;
+	this.heightMin = 0.0;
+
+	this.constrainVertical = false;
+	this.verticalMin = 0;
+	this.verticalMax = 3.14;
+
+	this.domElement = document;
+
+	this.lastUpdate = new Date().getTime();
+	this.tdiff = 0;
+
+	if ( parameters ) {
+
+		if ( parameters.movementSpeed !== undefined ) this.movementSpeed = parameters.movementSpeed;
+		if ( parameters.lookSpeed !== undefined ) this.lookSpeed  = parameters.lookSpeed;
+		if ( parameters.noFly !== undefined ) this.noFly = parameters.noFly;
+		if ( parameters.lookVertical !== undefined ) this.lookVertical = parameters.lookVertical;
+
+		if ( parameters.autoForward !== undefined ) this.autoForward = parameters.autoForward;
+
+		if ( parameters.activeLook !== undefined ) this.activeLook = parameters.activeLook;
+
+		if ( parameters.heightSpeed !== undefined ) this.heightSpeed = parameters.heightSpeed;
+		if ( parameters.heightCoef !== undefined ) this.heightCoef = parameters.heightCoef;
+		if ( parameters.heightMin !== undefined ) this.heightMin = parameters.heightMin;
+		if ( parameters.heightMax !== undefined ) this.heightMax = parameters.heightMax;
+
+		if ( parameters.constrainVertical !== undefined ) this.constrainVertical = parameters.constrainVertical;
+		if ( parameters.verticalMin !== undefined ) this.verticalMin = parameters.verticalMin;
+		if ( parameters.verticalMax !== undefined ) this.verticalMax = parameters.verticalMax;
+
+		if ( parameters.domElement !== undefined ) this.domElement = parameters.domElement;
+
+	}
+
+	this.autoSpeedFactor = 0.0;
+
+	this.mouseX = 0;
+	this.mouseY = 0;
+
+	this.lat = 0;
+	this.lon = 0;
+	this.phi = 0;
+	this.theta = 0;
+
+	this.moveForward = false;
+	this.moveBackward = false;
+	this.moveLeft = false;
+	this.moveRight = false;
+	this.freeze = false;
+
+	this.mouseDragOn = false;
+
+	this.windowHalfX = window.innerWidth / 2;
+	this.windowHalfY = window.innerHeight / 2;
+
+	this.onMouseDown = function ( event ) {
+
+		event.preventDefault();
+		event.stopPropagation();
+
+		if ( this.activeLook ) {
+
+			switch ( event.button ) {
+
+				case 0: this.moveForward = true; break;
+				case 2: this.moveBackward = true; break;
+
+			}
+
+		}
+
+		this.mouseDragOn = true;
+
+	};
+
+	this.onMouseUp = function ( event ) {
+
+		event.preventDefault();
+		event.stopPropagation();
+
+		if ( this.activeLook ) {
+
+			switch ( event.button ) {
+
+				case 0: this.moveForward = false; break;
+				case 2: this.moveBackward = false; break;
+
+			}
+
+		}
+
+		this.mouseDragOn = false;
+
+	};
+
+	this.onMouseMove = function ( event ) {
+
+		this.mouseX = event.clientX - this.windowHalfX;
+		this.mouseY = event.clientY - this.windowHalfY;
+
+	};
+
+	this.onKeyDown = function ( event ) {
+
+		switch( event.keyCode ) {
+
+			case 38: /*up*/
+			case 87: /*W*/ this.moveForward = true; break;
+
+			case 37: /*left*/
+			case 65: /*A*/ this.moveLeft = true; break;
+
+			case 40: /*down*/
+			case 83: /*S*/ this.moveBackward = true; break;
+
+			case 39: /*right*/
+			case 68: /*D*/ this.moveRight = true; break;
+
+			case 81: this.freeze = !this.freeze; break;
+
+		}
+
+	};
+
+	this.onKeyUp = function ( event ) {
+
+		switch( event.keyCode ) {
+
+			case 38: /*up*/
+			case 87: /*W*/ this.moveForward = false; break;
+
+			case 37: /*left*/
+			case 65: /*A*/ this.moveLeft = false; break;
+
+			case 40: /*down*/
+			case 83: /*S*/ this.moveBackward = false; break;
+
+			case 39: /*right*/
+			case 68: /*D*/ this.moveRight = false; break;
+
+		}
+
+	};
+
+	this.update = function() {
+
+		var now = new Date().getTime();
+		this.tdiff = ( now - this.lastUpdate ) / 1000;
+		this.lastUpdate = now;
+		
+		if ( !this.freeze ) {
+
+
+			if ( this.heightSpeed ) {
+
+				var y = clamp( this.position.y, this.heightMin, this.heightMax ),
+					delta = y - this.heightMin;
+
+				this.autoSpeedFactor = this.tdiff * ( delta * this.heightCoef );
+
+			} else {
+
+				this.autoSpeedFactor = 0.0;
+
+			}
+
+			var actualMoveSpeed = this.tdiff * this.movementSpeed;
+
+			if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
+			if ( this.moveBackward ) this.translateZ( actualMoveSpeed );
+			if ( this.moveLeft ) this.translateX( - actualMoveSpeed );
+			if ( this.moveRight ) this.translateX( actualMoveSpeed );
+
+			var actualLookSpeed = this.tdiff * this.lookSpeed;
+
+			if ( !this.activeLook ) {
+
+				actualLookSpeed = 0;
+
+			}
+
+			this.lon += this.mouseX * actualLookSpeed;
+			if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
+
+			this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
+			this.phi = ( 90 - this.lat ) * Math.PI / 180;
+			this.theta = this.lon * Math.PI / 180;
+
+			var targetPosition = this.target.position,
+				position = this.position;
+
+			targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
+			targetPosition.y = position.y + 100 * Math.cos( this.phi );
+			targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
+
+		}
+
+		this.lon += this.mouseX * actualLookSpeed;
+		if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
+
+		this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
+		this.phi = ( 90 - this.lat ) * Math.PI / 180;
+		this.theta = this.lon * Math.PI / 180;
+
+		if ( this.constrainVertical ) {
+
+			this.phi = map_linear( this.phi, 0, 3.14, this.verticalMin, this.verticalMax );
+
+		}
+
+		var targetPosition = this.target.position,
+			position = this.position;
+
+		targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
+		targetPosition.y = position.y + 100 * Math.cos( this.phi );
+		targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
+
+		this.supr.update.call( this );
+
+	};
+
+
+	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+
+	this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false );
+	this.domElement.addEventListener( 'mousedown', bind( this, this.onMouseDown ), false );
+	this.domElement.addEventListener( 'mouseup', bind( this, this.onMouseUp ), false );
+	this.domElement.addEventListener( 'keydown', bind( this, this.onKeyDown ), false );
+	this.domElement.addEventListener( 'keyup', bind( this, this.onKeyUp ), false );
+
+	function bind( scope, fn ) {
+
+		return function () {
+
+			fn.apply( scope, arguments );
+
+		};
+
+	};
+
+	function map_linear( x, sa, sb, ea, eb ) {
+
+		return ( x  - sa ) * ( eb - ea ) / ( sb - sa ) + ea;
+
+	};
+
+	function clamp_bottom( x, a ) {
+
+		return x < a ? a : x;
+
+	};
+
+	function clamp( x, a, b ) {
+
+		return x < a ? a : ( x > b ? b : x );
+
+	};
+
+};
+
+
+THREE.FirstPersonCamera.prototype = new THREE.Camera();
+THREE.FirstPersonCamera.prototype.constructor = THREE.FirstPersonCamera;
+THREE.FirstPersonCamera.prototype.supr = THREE.Camera.prototype;
+
+
+THREE.FirstPersonCamera.prototype.translate = function ( distance, axis ) {
+
+	this.matrix.rotateAxis( axis );
+
+	if ( this.noFly ) {
+
+		axis.y = 0;
+
+	}
+
+	this.position.addSelf( axis.multiplyScalar( distance ) );
+	this.target.position.addSelf( axis.multiplyScalar( distance ) );
+
+};

+ 4 - 325
src/extras/cameras/QuakeCamera.js

@@ -1,328 +1,7 @@
 /**
- * @author mrdoob / http://mrdoob.com/
- * @author alteredq / http://alteredqualia.com/
- * @author paulirish / http://paulirish.com/
+ * @author chriskillpack / http://chriskillpack.com/
  *
- * parameters = {
- *  fov: <float>,
- *  aspect: <float>,
- *  near: <float>,
- *  far: <float>,
- *  target: <THREE.Object3D>,
-
- *  movementSpeed: <float>,
- *  lookSpeed: <float>,
-
- *  noFly: <bool>,
- *  lookVertical: <bool>,
- *  autoForward: <bool>,
-
- *  constrainVertical: <bool>,
- *  verticalMin: <float>,
- *  verticalMax: <float>,
-
- *  heightSpeed: <bool>,
- *  heightCoef: <float>,
- *  heightMin: <float>,
- *  heightMax: <float>,
-
- *  domElement: <HTMLElement>,
- * }
+ * QuakeCamera has been renamed FirstPersonCamera. This property exists for backwards
+ * compatibility only.
  */
-
-THREE.QuakeCamera = function ( parameters ) {
-
-	THREE.Camera.call( this, parameters.fov, parameters.aspect, parameters.near, parameters.far, parameters.target );
-
-	this.movementSpeed = 1.0;
-	this.lookSpeed = 0.005;
-
-	this.noFly = false;
-	this.lookVertical = true;
-	this.autoForward = false;
-
-	this.activeLook = true;
-
-	this.heightSpeed = false;
-	this.heightCoef = 1.0;
-	this.heightMin = 0.0;
-
-	this.constrainVertical = false;
-	this.verticalMin = 0;
-	this.verticalMax = 3.14;
-
-	this.domElement = document;
-
-	this.lastUpdate = new Date().getTime();
-	this.tdiff = 0;
-
-	if ( parameters ) {
-
-		if ( parameters.movementSpeed !== undefined ) this.movementSpeed = parameters.movementSpeed;
-		if ( parameters.lookSpeed !== undefined ) this.lookSpeed  = parameters.lookSpeed;
-		if ( parameters.noFly !== undefined ) this.noFly = parameters.noFly;
-		if ( parameters.lookVertical !== undefined ) this.lookVertical = parameters.lookVertical;
-
-		if ( parameters.autoForward !== undefined ) this.autoForward = parameters.autoForward;
-
-		if ( parameters.activeLook !== undefined ) this.activeLook = parameters.activeLook;
-
-		if ( parameters.heightSpeed !== undefined ) this.heightSpeed = parameters.heightSpeed;
-		if ( parameters.heightCoef !== undefined ) this.heightCoef = parameters.heightCoef;
-		if ( parameters.heightMin !== undefined ) this.heightMin = parameters.heightMin;
-		if ( parameters.heightMax !== undefined ) this.heightMax = parameters.heightMax;
-
-		if ( parameters.constrainVertical !== undefined ) this.constrainVertical = parameters.constrainVertical;
-		if ( parameters.verticalMin !== undefined ) this.verticalMin = parameters.verticalMin;
-		if ( parameters.verticalMax !== undefined ) this.verticalMax = parameters.verticalMax;
-
-		if ( parameters.domElement !== undefined ) this.domElement = parameters.domElement;
-
-	}
-
-	this.autoSpeedFactor = 0.0;
-
-	this.mouseX = 0;
-	this.mouseY = 0;
-
-	this.lat = 0;
-	this.lon = 0;
-	this.phi = 0;
-	this.theta = 0;
-
-	this.moveForward = false;
-	this.moveBackward = false;
-	this.moveLeft = false;
-	this.moveRight = false;
-	this.freeze = false;
-
-	this.mouseDragOn = false;
-
-	this.windowHalfX = window.innerWidth / 2;
-	this.windowHalfY = window.innerHeight / 2;
-
-	this.onMouseDown = function ( event ) {
-
-		event.preventDefault();
-		event.stopPropagation();
-
-		if ( this.activeLook ) {
-
-			switch ( event.button ) {
-
-				case 0: this.moveForward = true; break;
-				case 2: this.moveBackward = true; break;
-
-			}
-
-		}
-
-		this.mouseDragOn = true;
-
-	};
-
-	this.onMouseUp = function ( event ) {
-
-		event.preventDefault();
-		event.stopPropagation();
-
-		if ( this.activeLook ) {
-
-			switch ( event.button ) {
-
-				case 0: this.moveForward = false; break;
-				case 2: this.moveBackward = false; break;
-
-			}
-
-		}
-
-		this.mouseDragOn = false;
-
-	};
-
-	this.onMouseMove = function ( event ) {
-
-		this.mouseX = event.clientX - this.windowHalfX;
-		this.mouseY = event.clientY - this.windowHalfY;
-
-	};
-
-	this.onKeyDown = function ( event ) {
-
-		switch( event.keyCode ) {
-
-			case 38: /*up*/
-			case 87: /*W*/ this.moveForward = true; break;
-
-			case 37: /*left*/
-			case 65: /*A*/ this.moveLeft = true; break;
-
-			case 40: /*down*/
-			case 83: /*S*/ this.moveBackward = true; break;
-
-			case 39: /*right*/
-			case 68: /*D*/ this.moveRight = true; break;
-
-			case 81: this.freeze = !this.freeze; break;
-
-		}
-
-	};
-
-	this.onKeyUp = function ( event ) {
-
-		switch( event.keyCode ) {
-
-			case 38: /*up*/
-			case 87: /*W*/ this.moveForward = false; break;
-
-			case 37: /*left*/
-			case 65: /*A*/ this.moveLeft = false; break;
-
-			case 40: /*down*/
-			case 83: /*S*/ this.moveBackward = false; break;
-
-			case 39: /*right*/
-			case 68: /*D*/ this.moveRight = false; break;
-
-		}
-
-	};
-
-	this.update = function() {
-
-		var now = new Date().getTime();
-		this.tdiff = ( now - this.lastUpdate ) / 1000;
-		this.lastUpdate = now;
-		
-		if ( !this.freeze ) {
-
-
-			if ( this.heightSpeed ) {
-
-				var y = clamp( this.position.y, this.heightMin, this.heightMax ),
-					delta = y - this.heightMin;
-
-				this.autoSpeedFactor = this.tdiff * ( delta * this.heightCoef );
-
-			} else {
-
-				this.autoSpeedFactor = 0.0;
-
-			}
-
-			var actualMoveSpeed = this.tdiff * this.movementSpeed;
-
-			if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
-			if ( this.moveBackward ) this.translateZ( actualMoveSpeed );
-			if ( this.moveLeft ) this.translateX( - actualMoveSpeed );
-			if ( this.moveRight ) this.translateX( actualMoveSpeed );
-
-			var actualLookSpeed = this.tdiff * this.lookSpeed;
-
-			if ( !this.activeLook ) {
-
-				actualLookSpeed = 0;
-
-			}
-
-			this.lon += this.mouseX * actualLookSpeed;
-			if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
-
-			this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
-			this.phi = ( 90 - this.lat ) * Math.PI / 180;
-			this.theta = this.lon * Math.PI / 180;
-
-			var targetPosition = this.target.position,
-				position = this.position;
-
-			targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
-			targetPosition.y = position.y + 100 * Math.cos( this.phi );
-			targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
-
-		}
-
-		this.lon += this.mouseX * actualLookSpeed;
-		if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
-
-		this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
-		this.phi = ( 90 - this.lat ) * Math.PI / 180;
-		this.theta = this.lon * Math.PI / 180;
-
-		if ( this.constrainVertical ) {
-
-			this.phi = map_linear( this.phi, 0, 3.14, this.verticalMin, this.verticalMax );
-
-		}
-
-		var targetPosition = this.target.position,
-			position = this.position;
-
-		targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
-		targetPosition.y = position.y + 100 * Math.cos( this.phi );
-		targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
-
-		this.supr.update.call( this );
-
-	};
-
-
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
-
-	this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false );
-	this.domElement.addEventListener( 'mousedown', bind( this, this.onMouseDown ), false );
-	this.domElement.addEventListener( 'mouseup', bind( this, this.onMouseUp ), false );
-	this.domElement.addEventListener( 'keydown', bind( this, this.onKeyDown ), false );
-	this.domElement.addEventListener( 'keyup', bind( this, this.onKeyUp ), false );
-
-	function bind( scope, fn ) {
-
-		return function () {
-
-			fn.apply( scope, arguments );
-
-		};
-
-	};
-
-	function map_linear( x, sa, sb, ea, eb ) {
-
-		return ( x  - sa ) * ( eb - ea ) / ( sb - sa ) + ea;
-
-	};
-
-	function clamp_bottom( x, a ) {
-
-		return x < a ? a : x;
-
-	};
-
-	function clamp( x, a, b ) {
-
-		return x < a ? a : ( x > b ? b : x );
-
-	};
-
-};
-
-
-THREE.QuakeCamera.prototype = new THREE.Camera();
-THREE.QuakeCamera.prototype.constructor = THREE.QuakeCamera;
-THREE.QuakeCamera.prototype.supr = THREE.Camera.prototype;
-
-
-THREE.QuakeCamera.prototype.translate = function ( distance, axis ) {
-
-	this.matrix.rotateAxis( axis );
-
-	if ( this.noFly ) {
-
-		axis.y = 0;
-
-	}
-
-	this.position.addSelf( axis.multiplyScalar( distance ) );
-	this.target.position.addSelf( axis.multiplyScalar( distance ) );
-
-};
+THREE.QuakeCamera = THREE.FirstPersonCamera;

+ 49 - 52
src/extras/geometries/TextGeometry.js

@@ -77,8 +77,6 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
 
 	var data = THREE.FontUtils.drawText( text );
 
-	//console.log("data", data);
-
 	var vertices = data.points;
 	var faces = data.faces;
 	var contour = data.contour;
@@ -89,8 +87,6 @@ THREE.TextGeometry.prototype.set = function ( text, parameters ) {
 	scope.vertices = [];
 	scope.faces = [];
 
-	//console.log(this);
-
 	var i, 
 		vert, vlen = vertices.length, 
 		face, flen = faces.length,
@@ -300,11 +296,11 @@ THREE.FontUtils = {
 	},
 
 
-	extractPoints : function( points, characters ) {
+	extractPoints : function( allPoints, charactersPoints ) {
 
 		// Quick exit
 
-		if ( points.length < 3 ) {
+		if ( allPoints.length < 3 ) {
 
 			//throw "not valid polygon";
 
@@ -312,7 +308,7 @@ THREE.FontUtils = {
 
 			return {
 
-				points: points,
+				points: allPoints,
 				faces: []
 
 			};
@@ -323,22 +319,22 @@ THREE.FontUtils = {
 
 		var p, point, shape,
 			all,
+			ch, singleCharPoints,
 			isolatedShapes = [];
 
 		// Use a quick hashmap for locating duplicates
 
-		for ( var c in characters ) {
-
-			points = characters[ c ];
+		for ( var c = 0; c < charactersPoints.length; c ++ ) {
 
+			singleCharPoints = charactersPoints[ c ];
 
 			all = [];
 
 			// Use a quick hashmap for locating duplicates
 
-			for ( var p in points ) {
+			for ( var p = 0; p < singleCharPoints.length; p ++ ) {
 
-				point = points[ p ];
+				point = singleCharPoints[ p ];
 				all.push( point.x + "," + point.y );
 
 			}
@@ -348,10 +344,10 @@ THREE.FontUtils = {
 			// We check the first loop whether its CW or CCW direction to determine
 			// whether its shapes or holes first
 
-			endPt = all.slice(1).indexOf( all[0] );
-			var shapesFirst = this.Triangulate.area( points.slice( 0, endPt + 1 ) ) < 0;
+			endPt = all.slice( 1 ).indexOf( all[ 0 ] );
+			var shapesFirst = this.Triangulate.area( singleCharPoints.slice( 0, endPt + 1 ) ) < 0;
 
-			//console.log(points.length, "shapesFirst",shapesFirst);
+			//console.log( singleCharPoints.length, "shapesFirst", shapesFirst );
 
 			holes = [];
 			endPt = -1;
@@ -364,7 +360,7 @@ THREE.FontUtils = {
 
 				if ( endPt <= firstIndex ) break; 
 
-				var contours = points.slice( firstIndex, endPt + 1 );
+				var contours = singleCharPoints.slice( firstIndex, endPt + 1 );
 
 				if ( shapesFirst ) {
 
@@ -393,7 +389,7 @@ THREE.FontUtils = {
 
 					if ( this.Triangulate.area( contours ) < 0 ) {
 
-						isolatedShapes.push( {shape: contours, holes: holes } );
+						isolatedShapes.push( { shape: contours, holes: holes } );
 						holes = [];
 
 					} else {
@@ -568,8 +564,8 @@ THREE.FontUtils = {
 
 		}
 	
-		var points = [];
-		var triangulatedVertices = [];
+		var triangulatedPoints = [];
+		var triangulatedFaces = [];
 		var lastTriangles = 0;
 
 		for ( shapeId = 0; shapeId < isolatedShapes.length; shapeId ++ ) {
@@ -577,7 +573,7 @@ THREE.FontUtils = {
 			shapeGroup = isolatedShapes[ shapeId ];
 
 			shape = shapeGroup.shape;
-			points = points.concat( shape );
+			triangulatedPoints = triangulatedPoints.concat( shape );
 
 			var triangles = THREE.FontUtils.Triangulate( shape, true );
 
@@ -593,7 +589,7 @@ THREE.FontUtils = {
 
 			}
 
-			triangulatedVertices = triangulatedVertices.concat( triangles );
+			triangulatedFaces = triangulatedFaces.concat( triangles );
 			lastTriangles += shape.length;
 
 		}
@@ -613,11 +609,11 @@ THREE.FontUtils = {
 
 				found = false;
 
-				for ( j=0; j < points.length && !found; j++ ) {
+				for ( j = 0; j < triangulatedPoints.length && !found; j++ ) {
 
 					l = v * 3 + k;
 
-					if ( points[ j ].equals( verts[ l ] ) ) {
+					if ( triangulatedPoints[ j ].equals( verts[ l ] ) ) {
 
 						face.push( j );
 						found = true;
@@ -630,8 +626,8 @@ THREE.FontUtils = {
 
 				if ( !found ) {
 
-					points.push( verts[ l ] );
-					face.push( points.length - 1 );
+					triangulatedPoints.push( verts[ l ] );
+					face.push( triangulatedPoints.length - 1 );
 
 					console.log( "not found" )
 
@@ -639,17 +635,17 @@ THREE.FontUtils = {
 
 			}
 
-			triangulatedVertices.push( face );
+			triangulatedFaces.push( face );
 
 		}
 
 
-		//console.log("triangles", triangulatedVertices.length, "points", points);
+		//console.log( "triangles", triangulatedFaces.length, "points", triangulatedPoints );
 
 		return {
 
-			points: points,
-			faces: triangulatedVertices
+			points: triangulatedPoints,
+			faces: triangulatedFaces
 
 		};
 
@@ -657,7 +653,7 @@ THREE.FontUtils = {
 
 	drawText : function( text ) {
 
-		var characterpts = [], pts = [];
+		var characterPts = [], allPts = [];
 
 		// RenderText
 
@@ -672,8 +668,8 @@ THREE.FontUtils = {
 
 			var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset );
 			offset += ret.offset;
-			characterpts.push(ret.points);
-			pts = pts.concat(ret.points);
+			characterPts.push( ret.points );
+			allPts = allPts.concat( ret.points );
 
 		}
 
@@ -681,29 +677,28 @@ THREE.FontUtils = {
 
 		var width = offset / 2;
 
-		for ( p = 0; p < pts.length; p++ ) {
+		for ( p = 0; p < allPts.length; p++ ) {
 
-			pts[ p ].x -= width;
+			allPts[ p ].x -= width;
 
 		}
 
-		var extract = this.extractPoints( pts, characterpts );
-
-		extract.contour = pts;
+		var extract = this.extractPoints( allPts, characterPts );
+		extract.contour = allPts;
 
 		var bezelPoints = [];
 
 		var centroids = [], forCentroids = [], expandOutwards = [], sum = new THREE.Vector2(), lastV;
 
-		i = pts.length;
+		i = allPts.length;
 
 		while ( --i >= 0 ) {
 
 			if ( !lastV ) {
 
-				lastV = pts[ i ];
+				lastV = allPts[ i ];
 
-			} else if ( lastV.equals( pts[ i ] ) ) {
+			} else if ( lastV.equals( allPts[ i ] ) ) {
 
 				// We reached the last point of a closed loop
 
@@ -719,23 +714,23 @@ THREE.FontUtils = {
 
 			}
 
-			sum.addSelf( pts[ i ] );
-			forCentroids.push( pts[ i ] );
+			sum.addSelf( allPts[ i ] );
+			forCentroids.push( allPts[ i ] );
 
 		}
 
 
-		i = pts.length;
+		i = allPts.length;
 		p = 0;
 		var pt, centroid ;
 		var dirV, adj;
 
 		while ( --i >= 0 ) {
 
-			pt = pts[ i ];
-			centroid = centroids[p];
+			pt = allPts[ i ];
+			centroid = centroids[ p ];
 
-			dirV = pt.clone().subSelf( centroid) ;
+			dirV = pt.clone().subSelf( centroid );
 			adj = this.bezelSize / dirV.length();
 
 			if ( expandOutwards[ p ] ) {
@@ -754,9 +749,9 @@ THREE.FontUtils = {
 
 			if ( !lastV ) {
 
-				lastV = pts[ i ];
+				lastV = allPts[ i ];
 
-			} else if ( lastV.equals( pts[ i ] ) ) {
+			} else if ( lastV.equals( allPts[ i ] ) ) {
 
 				// We reached the last point of a closed loop
 
@@ -770,11 +765,13 @@ THREE.FontUtils = {
 
 
 		/*
-		for ( p = 0; p < pts.length; p++ ) {
-			pt = pts[ p ];
-			bezelPoints.push (new THREE.Vector2(pt.x + this.bezelSize, pt.y + this.bezelSize));
+		for ( p = 0; p < allPts.length; p++ ) {
+
+			pt = allPts[ p ];
+			bezelPoints.push( new THREE.Vector2( pt.x + this.bezelSize, pt.y + this.bezelSize ) );
 
-		}*/
+		}
+		*/
 
 		extract.bezel = bezelPoints;
 

+ 2 - 0
src/extras/io/BinaryLoader.js

@@ -227,6 +227,8 @@ THREE.BinaryLoader.prototype = {
 			this.computeCentroids();
 			this.computeFaceNormals();
 
+			if ( THREE.Loader.prototype.hasNormals( this ) ) this.computeTangents();
+
 			//var e = (new Date).getTime();
 
 			//log( "binary data parse time: " + (e-s) + " ms" );

+ 5 - 3
src/extras/io/JSONLoader.js

@@ -26,7 +26,7 @@ THREE.JSONLoader.prototype.load = function ( parameters ) {
 
 	var scope = this,
 		url = parameters.model,
-		callback = parameters.callback, 
+		callback = parameters.callback,
 		texture_path = parameters.texture_path ? parameters.texture_path : this.extractUrlbase( url ),
 		worker = new Worker( url );
 
@@ -59,6 +59,8 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texture_path
 	geometry.computeCentroids();
 	geometry.computeFaceNormals();
 
+	if ( this.hasNormals( geometry ) ) geometry.computeTangents();
+
 	// geometry.computeEdgeFaces();
 
 	function parseModel( scale ) {
@@ -351,7 +353,7 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texture_path
 
 				}
 
-			} 
+			}
 
 		}
 
@@ -376,7 +378,7 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texture_path
 
 				}
 
-			} 
+			}
 
 		}
 

+ 167 - 27
src/extras/io/Loader.js

@@ -19,15 +19,15 @@ THREE.Loader.prototype = {
 
 		var e = document.createElement( "div" );
 
-		e.style.position = "absolute"; 
-		e.style.right = "0px"; 
-		e.style.top = "0px"; 
-		e.style.fontSize = "0.8em"; 
+		e.style.position = "absolute";
+		e.style.right = "0px";
+		e.style.top = "0px";
+		e.style.fontSize = "0.8em";
 		e.style.textAlign = "left";
-		e.style.background = "rgba(0,0,0,0.25)"; 
-		e.style.color = "#fff"; 
-		e.style.width = "120px"; 
-		e.style.padding = "0.5em 0.5em 0.5em 0.5em"; 
+		e.style.background = "rgba(0,0,0,0.25)";
+		e.style.color = "#fff";
+		e.style.width = "120px";
+		e.style.padding = "0.5em 0.5em 0.5em 0.5em";
 		e.style.zIndex = 1000;
 
 		e.innerHTML = "Loading ...";
@@ -75,6 +75,22 @@ THREE.Loader.prototype = {
 
 	},
 
+	hasNormals: function( scope ) {
+
+		var m, i, il = scope.materials.length;
+
+		for( i = 0; i < il; i++ ) {
+
+			m = scope.materials[ i ][ 0 ];
+
+			if ( m instanceof THREE.MeshShaderMaterial ) return true;
+
+		}
+
+		return false;
+
+	},
+
 	createMaterial: function ( m, texture_path ) {
 
 		function is_pow2( n ) {
@@ -120,7 +136,53 @@ THREE.Loader.prototype = {
 
 		}
 
-		var material, mtype, mpars, texture, color, vertexColors;
+		function create_texture( where, name, sourceFile, repeat, offset, wrap ) {
+
+			var texture = document.createElement( 'canvas' );
+
+			where[ name ] = new THREE.Texture( texture );
+			where[ name ].sourceFile = sourceFile;
+
+			if( repeat ) {
+
+				where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
+
+				if ( repeat[ 0 ] != 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
+				if ( repeat[ 1 ] != 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
+
+			}
+
+			if( offset ) {
+
+				where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
+
+			}
+
+			if( wrap ) {
+
+				var wrapMap = {
+				"repeat" 	: THREE.RepeatWrapping,
+				"mirror"	: THREE.MirroredRepeatWrapping
+				}
+
+				if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
+				if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
+
+			}
+
+			load_image( where[ name ], texture_path + "/" + sourceFile );
+
+		}
+
+		function rgb2hex( rgb ) {
+
+			return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
+
+		}
+
+		var material, mtype, mpars,
+			color, specular, ambient,
+			vertexColors;
 
 		// defaults
 
@@ -128,7 +190,7 @@ THREE.Loader.prototype = {
 
 		// vertexColors
 
-		mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, wireframe: m.wireframe };
+		mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, wireframe: m.wireframe };
 
 		// parameters from model file
 
@@ -173,39 +235,117 @@ THREE.Loader.prototype = {
 
 		}
 
-		if ( m.mapDiffuse && texture_path ) {
+		// colors
 
-			texture = document.createElement( 'canvas' );
+		if ( m.colorDiffuse ) {
 
-			mpars.map = new THREE.Texture( texture );
-			mpars.map.sourceFile = m.mapDiffuse;
+			mpars.color = rgb2hex( m.colorDiffuse );
 
-			load_image( mpars.map, texture_path + "/" + m.mapDiffuse );
+		} else if ( m.DbgColor ) {
 
-		} else if ( m.colorDiffuse ) {
+			mpars.color = m.DbgColor;
 
-			color = ( m.colorDiffuse[0] * 255 << 16 ) + ( m.colorDiffuse[1] * 255 << 8 ) + m.colorDiffuse[2] * 255;
-			mpars.color = color;
-			mpars.opacity =  m.transparency;
+		}
 
-		} else if ( m.DbgColor ) {
+		if ( m.colorSpecular ) {
 
-			mpars.color = m.DbgColor;
+			mpars.specular = rgb2hex( m.colorSpecular );
 
 		}
 
-		if ( m.mapLightmap && texture_path ) {
+		if ( m.colorAmbient ) {
+
+			mpars.ambient = rgb2hex( m.colorAmbient );
 
-			texture = document.createElement( 'canvas' );
+		}
 
-			mpars.lightMap = new THREE.Texture( texture );
-			mpars.lightMap.sourceFile = m.mapLightmap;
+		// modifiers
 
-			load_image( mpars.lightMap, texture_path + "/" + m.mapLightmap );
+		if ( m.transparency ) {
+
+			mpars.opacity = m.transparency;
 
 		}
 
-		material = new THREE[ mtype ]( mpars );
+		if ( m.specularCoef ) {
+
+			mpars.shininess = m.specularCoef;
+
+		}
+
+		// textures
+
+		if ( m.mapDiffuse && texture_path ) {
+
+			create_texture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
+
+		}
+
+		if ( m.mapLight && texture_path ) {
+
+			create_texture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
+
+		}
+
+		if ( m.mapNormal && texture_path ) {
+
+			create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
+
+		}
+
+		// special case for normal mapped material
+
+		if ( m.mapNormal ) {
+
+			var shader = THREE.ShaderUtils.lib[ "normal" ];
+			var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+
+			var diffuse = mpars.color;
+			var specular = mpars.specular;
+			var ambient = mpars.ambient;
+			var shininess = mpars.shininess;
+
+			uniforms[ "tNormal" ].texture = mpars.normalMap;
+
+			if ( m.mapNormalFactor ) {
+
+				uniforms[ "uNormalScale" ].value = m.mapNormalFactor;
+
+			}
+
+			if ( mpars.map ) {
+
+				uniforms[ "tDiffuse" ].texture = mpars.map;
+				uniforms[ "enableDiffuse" ].value = true;
+
+			}
+
+			// for the moment don't handle specular, AO and displacement textures
+
+			uniforms[ "enableAO" ].value = false;
+			uniforms[ "enableSpecular" ].value = false;
+
+			uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
+			uniforms[ "uSpecularColor" ].value.setHex( specular );
+			uniforms[ "uAmbientColor" ].value.setHex( ambient );
+
+			uniforms[ "uShininess" ].value = shininess;
+
+			if ( mpars.opacity ) {
+
+				uniforms[ "uOpacity" ].value = mpars.opacity;
+
+			}
+
+			var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
+
+			material = new THREE.MeshShaderMaterial( parameters );
+
+		} else {
+
+			material = new THREE[ mtype ]( mpars );
+
+		}
 
 		return material;
 

+ 111 - 18
src/extras/io/SceneLoader.js

@@ -30,7 +30,7 @@ THREE.SceneLoader.prototype = {
 				g, o, m, l, p, c, t, f, tt, pp,
 				geometry, material, camera, fog,
 				texture, images,
-				materials,
+				materials, light,
 				data, binLoader, jsonLoader,
 				counter_models, counter_textures,
 				total_models, total_textures,
@@ -132,11 +132,21 @@ THREE.SceneLoader.prototype = {
 
 							if ( geometry ) {
 
+								var hasNormals = false;
+
 								materials = [];
 								for( i = 0; i < o.materials.length; i++ ) {
 
 									materials[ i ] = result.materials[ o.materials[i] ];
 
+									hasNormals = materials[ i ] instanceof THREE.MeshShaderMaterial;
+
+								}
+
+								if ( hasNormals ) {
+
+									geometry.computeTangents();
+
 								}
 
 								p = o.position;
@@ -193,26 +203,26 @@ THREE.SceneLoader.prototype = {
 								}
 
 								if ( o.castsShadow ) {
-									
+
 									//object.visible = true;
 									//object.materials = [ new THREE.MeshBasicMaterial( { color: 0xff0000 } ) ];
 
 									var shadow = new THREE.ShadowVolume( geometry )
 									result.scene.addChild( shadow );
-									
+
 									shadow.position = object.position;
 									shadow.rotation = object.rotation;
 									shadow.scale = object.scale;
 
 								}
-								
+
 								if ( o.trigger && o.trigger.toLowerCase() != "none" ) {
-									
+
 									var trigger = {
 									"type" 		: o.trigger,
 									"object"	: o
 									};
-									
+
 									result.triggers[ object.name ] = trigger;
 
 								}
@@ -255,14 +265,13 @@ THREE.SceneLoader.prototype = {
 							result.objects[ dd ] = object;
 							result.empties[ dd ] = object;
 
-								
 							if ( o.trigger && o.trigger.toLowerCase() != "none" ) {
-								
+
 								var trigger = {
 								"type" 		: o.trigger,
 								"object"	: o
 								};
-								
+
 								result.triggers[ object.name ] = trigger;
 
 							}
@@ -289,7 +298,7 @@ THREE.SceneLoader.prototype = {
 					handle_mesh( geo, id );
 
 					counter_models -= 1;
-					
+
 					scope.onLoadComplete();
 
 					async_callback_gate();
@@ -320,7 +329,7 @@ THREE.SceneLoader.prototype = {
 				};
 
 				scope.callbackProgress( progress, result );
-				
+
 				scope.onLoadProgress();
 
 				if( counter_models == 0 && counter_textures == 0 ) {
@@ -390,10 +399,15 @@ THREE.SceneLoader.prototype = {
 				} else if ( l.type == "point" ) {
 
 					p = l.position;
+					d = l.distance;
 
-					light = new THREE.PointLight( hex, intensity );
+					light = new THREE.PointLight( hex, intensity, d );
 					light.position.set( p[0], p[1], p[2] );
 
+				} else if ( l.type == "ambient" ) {
+
+					light = new THREE.AmbientLight( hex );
+
 				}
 
 				result.scene.addLight( light );
@@ -458,7 +472,7 @@ THREE.SceneLoader.prototype = {
 				if ( g.type == "bin_mesh" || g.type == "ascii_mesh" ) {
 
 					counter_models += 1;
-					
+
 					scope.onLoadStart();
 
 				}
@@ -539,9 +553,9 @@ THREE.SceneLoader.prototype = {
 				if( tt.url instanceof Array ) {
 
 					counter_textures += tt.url.length;
-					
+
 					for( var n = 0; n < tt.url.length; n ++ ) {
-						
+
 						scope.onLoadStart();
 
 					}
@@ -590,6 +604,36 @@ THREE.SceneLoader.prototype = {
 					if ( THREE[ tt.magFilter ] != undefined )
 						texture.magFilter = THREE[ tt.magFilter ];
 
+
+					if ( tt.repeat ) {
+
+						texture.repeat.set( tt.repeat[ 0 ], tt.repeat[ 1 ] );
+
+						if ( tt.repeat[ 0 ] != 1 ) texture.wrapS = THREE.RepeatWrapping;
+						if ( tt.repeat[ 1 ] != 1 ) texture.wrapT = THREE.RepeatWrapping;
+
+					}
+
+					if ( tt.offset ) {
+
+						texture.offset.set( tt.offset[ 0 ], tt.offset[ 1 ] );
+
+					}
+
+					// handle wrap after repeat so that default repeat can be overriden
+
+					if ( tt.wrap ) {
+
+						var wrapMap = {
+						"repeat" 	: THREE.RepeatWrapping,
+						"mirror"	: THREE.MirroredRepeatWrapping
+						}
+
+						if ( wrapMap[ tt.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ tt.wrap[ 0 ] ];
+						if ( wrapMap[ tt.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ tt.wrap[ 1 ] ];
+
+					}
+
 				}
 
 				result.textures[ dt ] = texture;
@@ -639,12 +683,61 @@ THREE.SceneLoader.prototype = {
 				}
 
 				if ( m.parameters.opacity !== undefined && m.parameters.opacity < 1.0 ) {
-					
+
 					m.parameters.transparent = true;
 
 				}
-				
-				material = new THREE[ m.type ]( m.parameters );
+
+				if ( m.parameters.normalMap ) {
+
+					var shader = THREE.ShaderUtils.lib[ "normal" ];
+					var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+
+					var diffuse = m.parameters.color;
+					var specular = m.parameters.specular;
+					var ambient = m.parameters.ambient;
+					var shininess = m.parameters.shininess;
+
+					uniforms[ "tNormal" ].texture = result.textures[ m.parameters.normalMap ];
+
+					if ( m.parameters.normalMapFactor ) {
+
+						uniforms[ "uNormalScale" ].value = m.parameters.normalMapFactor;
+
+					}
+
+					if ( m.parameters.map ) {
+
+						uniforms[ "tDiffuse" ].texture = m.parameters.map;
+						uniforms[ "enableDiffuse" ].value = true;
+
+					}
+
+					uniforms[ "enableAO" ].value = false;
+					uniforms[ "enableSpecular" ].value = false;
+
+					uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
+					uniforms[ "uSpecularColor" ].value.setHex( specular );
+					uniforms[ "uAmbientColor" ].value.setHex( ambient );
+
+					uniforms[ "uShininess" ].value = shininess;
+
+					if ( m.parameters.opacity ) {
+
+						uniforms[ "uOpacity" ].value = m.parameters.opacity;
+
+					}
+
+					var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
+
+					material = new THREE.MeshShaderMaterial( parameters );
+
+				} else {
+
+					material = new THREE[ m.type ]( m.parameters );
+
+				}
+
 				result.materials[ dm ] = material;
 
 			}

+ 63 - 12
src/extras/renderers/AnaglyphWebGLRenderer.js

@@ -1,15 +1,23 @@
 /**
  * @author mrdoob / http://mrdoob.com/
+ * @author marklundin / http://mark-lundin.com/
  */
 
 if ( THREE.WebGLRenderer ) {
 
-	THREE.AnaglyphWebGLRenderer = function ( parameters ) {
+	THREE.AnaglyphWebGLRenderer = function ( parameters ) {	
 
 		THREE.WebGLRenderer.call( this, parameters );
 
 		var _this = this, _setSize = this.setSize, _render = this.render;
 		var _cameraL = new THREE.Camera(), _cameraR = new THREE.Camera();
+		var eyeRight = new THREE.Matrix4(),
+			eyeLeft = new THREE.Matrix4(),
+			focalLength = 125,
+			aspect, near, fov;
+	
+		_cameraL.useTarget = _cameraR.useTarget = false;
+		_cameraL.matrixAutoUpdate = _cameraR.matrixAutoUpdate = false;
 
 		var _params = { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
 		var _renderTargetL = new THREE.WebGLRenderTarget( 512, 512, _params ), _renderTargetR = new THREE.WebGLRenderTarget( 512, 512, _params );
@@ -76,21 +84,64 @@ if ( THREE.WebGLRenderer ) {
 
 		};
 
-		this.render = function ( scene, camera, renderTarget, forceClear ) {
-
-			_cameraL.projectionMatrix = camera.projectionMatrix;
+		/*
+		 * Renderer now uses an asymmetric perspective projection (http://paulbourke.net/miscellaneous/stereographics/stereorender/). 
+		 * Each camera is offset by the eye seperation and its projection matrix is also skewed asymetrically back to converge on the same
+		 * projection plane. Added a focal length parameter to, this is where the parallax is equal to 0. 
+		 */
+		this.render = function ( scene, camera, renderTarget, forceClear ) {	
+		
+		
+			camera.update( null, true );
+		
+			var hasCameraChanged = 	aspect !== camera.aspect || near !== camera.near || fov !== camera.fov;
+								
+			if( hasCameraChanged ) {
+		
+				aspect = camera.aspect;
+				near = camera.near;
+				fov = camera.fov;	
+		
+				var projectionMatrix = camera.projectionMatrix.clone(),
+					eyeSep = focalLength / 30 * 0.5,
+					eyeSepOnProjection = eyeSep * near / focalLength,
+					ymax = near * Math.tan( fov * Math.PI / 360 ),
+					xmin, xmax;
+
+				//translate xOffset
+				eyeRight.n14 = eyeSep;
+				eyeLeft.n14 = -eyeSep;
+	
+				//For left eye
+				xmin = -ymax * aspect + eyeSepOnProjection;
+				xmax = ymax * aspect + eyeSepOnProjection;
+				projectionMatrix.n11 = 2 * near / ( xmax - xmin );
+				projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin );
+				_cameraL.projectionMatrix = projectionMatrix.clone();
+			
+				//for right eye		
+				xmin = -ymax * aspect - eyeSepOnProjection;
+				xmax = ymax * aspect - eyeSepOnProjection;
+				projectionMatrix.n11 = 2 * near / ( xmax - xmin );
+				projectionMatrix.n13 = ( xmax + xmin ) / ( xmax - xmin );
+				_cameraR.projectionMatrix = projectionMatrix.clone();
+				
+			}	
+		
+			_cameraL.matrix = camera.matrixWorld.clone().multiplySelf( eyeLeft );
+			_cameraL.update(null, true);
 			_cameraL.position.copy( camera.position );
-			_cameraL.target.position.copy( camera.target.position );
-			_cameraL.translateX( - 10 );
+			_cameraL.near = near;
+			_cameraL.far = camera.far;
+			_render.call( _this, scene, _cameraL, _renderTargetL, true );
 
-			_cameraR.projectionMatrix = camera.projectionMatrix;
+			_cameraR.matrix = camera.matrixWorld.clone().multiplySelf( eyeRight );
+			_cameraR.update(null, true);
 			_cameraR.position.copy( camera.position );
-			_cameraR.target.position.copy( camera.target.position );
-			_cameraR.translateX( 10 );
-
-			_render.call( _this, scene, _cameraL, _renderTargetL, true );
+			_cameraR.near = near;
+			_cameraR.far = camera.far;
 			_render.call( _this, scene, _cameraR, _renderTargetR, true );
-
+		
 			_render.call( _this, _scene, _camera );
 
 		};

+ 3 - 0
src/materials/Material.js

@@ -14,6 +14,9 @@ THREE.Material = function ( parameters ) {
 	this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
 	this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : 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;
 
 }
 

+ 1 - 0
src/objects/Sprite.js

@@ -23,6 +23,7 @@ THREE.Sprite = function( parameters ) {
 	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;

+ 309 - 142
src/renderers/WebGLRenderer.js

@@ -32,6 +32,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 	_oldFlipSided = null,
 	_oldBlending = null,
 	_oldDepth = null,
+	_oldPolygonOffset = null,
+	_oldPolygonOffsetFactor = null,
+	_oldPolygonOffsetUnits = null,
 	_cullEnabled = true,
 
 	_viewportX = 0,
@@ -176,6 +179,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		_stencilShadow.vertexLocation     = _gl.getAttribLocation ( _stencilShadow.program, "position"         );
 		_stencilShadow.projectionLocation = _gl.getUniformLocation( _stencilShadow.program, "projectionMatrix" );
 		_stencilShadow.darknessLocation   = _gl.getUniformLocation( _stencilShadow.program, "darkness"         );
+
 	}
 
 
@@ -190,10 +194,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 	i = 0;
 	_lensFlare.vertices[ i++ ] = -1; _lensFlare.vertices[ i++ ] = -1;	// vertex
 	_lensFlare.vertices[ i++ ] = 0;  _lensFlare.vertices[ i++ ] = 0;	// uv... etc.
+
 	_lensFlare.vertices[ i++ ] = 1;  _lensFlare.vertices[ i++ ] = -1;
 	_lensFlare.vertices[ i++ ] = 1;  _lensFlare.vertices[ i++ ] = 0;
+
 	_lensFlare.vertices[ i++ ] = 1;  _lensFlare.vertices[ i++ ] = 1;
 	_lensFlare.vertices[ i++ ] = 1;  _lensFlare.vertices[ i++ ] = 1;
+
 	_lensFlare.vertices[ i++ ] = -1; _lensFlare.vertices[ i++ ] = 1;
 	_lensFlare.vertices[ i++ ] = 0;  _lensFlare.vertices[ i++ ] = 1;
 
@@ -265,21 +272,25 @@ THREE.WebGLRenderer = function ( parameters ) {
 	var _lensFlareAttributesEnabled = false;
 
 	// prepare sprites
-	
-	_sprite = {};
+
+	var _sprite = {};
 
 	_sprite.vertices = new Float32Array( 8 + 8 );
 	_sprite.faces    = new Uint16Array( 6 );
 
 	i = 0;
-	_sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = -1;	// vertex
-	_sprite.vertices[ i++ ] = 0;  _sprite.vertices[ i++ ] = 0;	// uv... etc.
-	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = -1;
-	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = 0;
-	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = 1;
-	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = 1;
-	_sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = 1;
-	_sprite.vertices[ i++ ] = 0;  _sprite.vertices[ i++ ] = 1;
+
+	_sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = -1;	// vertex 0
+	_sprite.vertices[ i++ ] = 0;  _sprite.vertices[ i++ ] = 1;	// uv 0
+
+	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = -1;	// vertex 1
+	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = 1;	// uv 1
+
+	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = 1;	// vertex 2
+	_sprite.vertices[ i++ ] = 1;  _sprite.vertices[ i++ ] = 0;	// uv 2
+
+	_sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = 1;	// vertex 3
+	_sprite.vertices[ i++ ] = 0;  _sprite.vertices[ i++ ] = 0;	// uv 3
 
 	i = 0;
 	_sprite.faces[ i++ ] = 0; _sprite.faces[ i++ ] = 1; _sprite.faces[ i++ ] = 2;
@@ -526,7 +537,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		if ( geometryGroup.numMorphTargets ) {
 
 			var m, ml;
-			geometryGroup.__webglMorphTargetsBuffers = []; 
+			geometryGroup.__webglMorphTargetsBuffers = [];
 
 			for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m++ ) {
 
@@ -582,8 +593,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 		uvType,
 		vertexColorType,
 		normalType,
-		materials,
-		attribute,
+		materials, material,
+		attribute, property, originalAttribute,
 
 		geometry = object.geometry,
 		obj_faces = geometry.faces,
@@ -612,6 +623,14 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		materials = unrollGroupMaterials( geometryGroup, object );
 
+		// this will not work if materials would change in run-time
+		// it should be refreshed every frame
+		// but need to do unrollGroupMaterials
+		// more properly without push to array
+		// like unrollBufferMaterials
+
+		geometryGroup.__materials = materials;
+
 		uvType = bufferGuessUVType( materials, geometryGroup, object );
 		normalType = bufferGuessNormalType( materials, geometryGroup, object );
 		vertexColorType = bufferGuessVertexColorType( materials, geometryGroup, object );
@@ -668,7 +687,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		if ( geometryGroup.numMorphTargets ) {
 
-			geometryGroup.__morphTargetsArrays = []; 
+			geometryGroup.__morphTargetsArrays = [];
 
 			for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m++ ) {
 
@@ -692,17 +711,25 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		for ( m = 0, ml = materials.length; m < ml; m ++ ) {
 
-			if ( materials[ m ].attributes ) {
+			material = materials[ m ];
+
+			if ( material.attributes ) {
 
 				geometryGroup.__webglCustomAttributes = {};
 
-				for ( a in materials[ m ].attributes ) {
+				for ( a in material.attributes ) {
+
+					// Do a shallow copy of the attribute object so different geometryGroup chunks use different
+					// attribute buffers which are correctly indexed in the setMeshBuffers function
+
+					originalAttribute = material.attributes[ a ];
 
-                    // Do a shallow copy of the attribute object so different geometryGroup chunks use different
-                    // attribute buffers which are correctly indexed in the setMeshBuffers function
 					attribute = {};
-					for (prop in materials[ m ].attributes[ a ] ) {
-						attribute [ prop ] = materials[ m ].attributes[ a ][ prop ];
+
+					for ( property in originalAttribute ) {
+
+						attribute[ property ] = originalAttribute[ property ];
+
 					}
 
 					if( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
@@ -717,11 +744,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 						else if( attribute.type === "c"  ) size = 3;
 
 						attribute.size = size;
-						attribute.needsUpdate = true;
 						attribute.array = new Float32Array( nvertices * size );
 						attribute.buffer = _gl.createBuffer();
 						attribute.buffer.belongsToAttribute = a;
 
+						originalAttribute.needsUpdate = true;
+						attribute.__original = originalAttribute;
+
 					}
 
 					geometryGroup.__webglCustomAttributes[ a ] = attribute;
@@ -897,7 +926,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 						customAttribute = customAttributes[ a ];
 
-						if ( customAttribute.needsUpdate ) {
+						if ( customAttribute.__original.needsUpdate ) {
 
 							offset_custom = customAttribute.offset;
 							offset_customSrc = customAttribute.offsetSrc;
@@ -1328,7 +1357,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 						customAttribute = customAttributes[ a ];
 
-						if ( customAttribute.needsUpdate ) {
+						if ( customAttribute.__original.needsUpdate ) {
 
 							offset_custom = customAttribute.offset;
 							offset_customSrc = customAttribute.offsetSrc;
@@ -1826,13 +1855,11 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				customAttribute = customAttributes[ a ];
 
-				if ( customAttribute.needsUpdate ) {
+				if ( customAttribute.__original.needsUpdate ) {
 
 					_gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
 					_gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
 
-					customAttribute.needsUpdate = false;
-
 				}
 
 			}
@@ -2162,10 +2189,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		uniforms.diffuse.value = material.color;
 		uniforms.opacity.value = material.opacity;
-		
+
 		uniforms.map.texture = material.map;
 		if ( material.map ) {
-			
+
 			uniforms.offsetRepeat.value.set( material.map.offset.x, material.map.offset.y, material.map.repeat.x, material.map.repeat.y );
 
 		}
@@ -2290,7 +2317,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		maxBones = allocateBones( object );
 
 		parameters = {
-			map: !!material.map, envMap: !!material.envMap, lightMap: !!material.lightMap, 
+			map: !!material.map, envMap: !!material.envMap, lightMap: !!material.lightMap,
 			vertexColors: material.vertexColors,
 			fog: fog, sizeAttenuation: material.sizeAttenuation,
 			skinning: material.skinning,
@@ -2321,13 +2348,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 		}
 
 		if ( material.attributes ) {
-			
+
 			for ( a in material.attributes ) {
-	
+
 				if( attributes[ a ] !== undefined && attributes[ a ] >= 0 ) _gl.enableVertexAttribArray( attributes[ a ] );
-	
+
 			}
-			
+
 		}
 
 
@@ -2496,9 +2523,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 			 material.envMap ) {
 
 			if( p_uniforms.cameraPosition !== null ) {
-				
+
 				_gl.uniform3f( p_uniforms.cameraPosition, camera.position.x, camera.position.y, camera.position.z );
-				
+
 			}
 
 		}
@@ -2508,9 +2535,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 			 material.skinning ) {
 
 			if ( p_uniforms.objectMatrix !== null ) {
-				
+
 				_gl.uniformMatrix4fv( p_uniforms.objectMatrix, false, object._objectMatrixArray );
-				
+
 			}
 
 		}
@@ -2521,10 +2548,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 			 material.skinning ) {
 
 			if( p_uniforms.viewMatrix !== null ) {
-				
+
 				_gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, _viewMatrixArray );
-				
-			} 
+
+			}
 
 		}
 
@@ -2578,7 +2605,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		// custom attributes
 
-        // Use the per-geometryGroup custom attribute arrays which are setup in initMeshBuffers
+		// Use the per-geometryGroup custom attribute arrays which are setup in initMeshBuffers
+
 		if ( geometryGroup.__webglCustomAttributes ) {
 
 			for( a in geometryGroup.__webglCustomAttributes ) {
@@ -2606,7 +2634,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 					attribute = material.attributes[ a ];
 
 					if( attribute.buffer ) {
-						
+
 						_gl.bindBuffer( _gl.ARRAY_BUFFER, attribute.buffer );
 						_gl.vertexAttribPointer( attributes[ a ], attribute.size, _gl.FLOAT, false, 0, 0 );
 
@@ -2837,9 +2865,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 		// load updated influences uniform
 
 		if( material.program.uniforms.morphTargetInfluences !== null ) {
-			
+
 			_gl.uniform1fv( material.program.uniforms.morphTargetInfluences, object.__webglMorphTargetInfluences );
-			
+
 		}
 
 	}
@@ -2890,15 +2918,15 @@ THREE.WebGLRenderer = function ( parameters ) {
 					ny = ( nay + nby + ncy ) / 3;
 					nz = ( naz + nbz + ncz ) / 3;
 
-					normalArray[ i ] 	 = nx; 
+					normalArray[ i ] 	 = nx;
 					normalArray[ i + 1 ] = ny;
 					normalArray[ i + 2 ] = nz;
 
-					normalArray[ i + 3 ] = nx; 
+					normalArray[ i + 3 ] = nx;
 					normalArray[ i + 4 ] = ny;
 					normalArray[ i + 5 ] = nz;
 
-					normalArray[ i + 6 ] = nx; 
+					normalArray[ i + 6 ] = nx;
 					normalArray[ i + 7 ] = ny;
 					normalArray[ i + 8 ] = nz;
 
@@ -2974,6 +3002,35 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	};
 
+	function setPolygonOffset ( polygonoffset, factor, units ) {
+
+		if ( _oldPolygonOffset != polygonoffset ) {
+
+			if ( polygonoffset ) {
+
+				_gl.enable( _gl.POLYGON_OFFSET_FILL );
+
+			} else {
+
+				_gl.disable( _gl.POLYGON_OFFSET_FILL );
+
+			}
+
+			_oldPolygonOffset = polygonoffset;
+
+		}
+
+		if ( polygonoffset && ( _oldPolygonOffsetFactor != factor || _oldPolygonOffsetUnits != units ) ) {
+
+			_gl.polygonOffset( factor, units );
+
+			_oldPolygonOffsetFactor = factor;
+			_oldPolygonOffsetUnits = units;
+
+		}
+
+	};
+
 	function computeFrustum( m ) {
 
 		_frustum[ 0 ].set( m.n41 - m.n11, m.n42 - m.n12, m.n43 - m.n13, m.n44 - m.n14 );
@@ -3132,10 +3189,18 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					if ( this.sortObjects ) {
 
-						_vector3.copy( object.position );
-						_projScreenMatrix.multiplyVector3( _vector3 );
+						if ( webglObject.object.renderDepth ) {
+
+							webglObject.z = webglObject.object.renderDepth;
 
-						webglObject.z = _vector3.z;
+						} else {
+
+							_vector3.copy( object.position );
+							_projScreenMatrix.multiplyVector3( _vector3 );
+
+							webglObject.z = _vector3.z;
+
+						}
 
 					}
 
@@ -3182,114 +3247,160 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
-		// opaque pass
+		if ( scene.overrideMaterial ) {
 
-		setBlending( THREE.NormalBlending );
+			setDepthTest( scene.overrideMaterial.depthTest );
+			setBlending( scene.overrideMaterial.blending );
 
-		for ( o = 0; o < ol; o ++ ) {
+			for ( o = 0; o < ol; o ++ ) {
 
-			webglObject = scene.__webglObjects[ o ];
+				webglObject = scene.__webglObjects[ o ];
+
+				if ( webglObject.render ) {
+
+					object = webglObject.object;
+					buffer = webglObject.buffer;
+
+					setObjectFaces( object );
+
+					renderBuffer( camera, lights, fog, scene.overrideMaterial, buffer, object );
+
+				}
+
+			}
 
-			if ( webglObject.render ) {
+			for ( o = 0; o < oil; o++ ) {
 
+				webglObject = scene.__webglObjectsImmediate[ o ];
 				object = webglObject.object;
-				buffer = webglObject.buffer;
-				opaque = webglObject.opaque;
 
-				setObjectFaces( object );
+				if ( object.visible ) {
+
+					setObjectFaces( object );
+
+					program = setProgram( camera, lights, fog, scene.overrideMaterial, object );
+					object.render( function( object ) { renderBufferImmediate( object, program, scene.overrideMaterial.shading ); } );
+
+				}
+
+			}
+
+		} else {
+
+			// opaque pass
+
+			setBlending( THREE.NormalBlending );
+
+			for ( o = 0; o < ol; o ++ ) {
+
+				webglObject = scene.__webglObjects[ o ];
+
+				if ( webglObject.render ) {
+
+					object = webglObject.object;
+					buffer = webglObject.buffer;
+					opaque = webglObject.opaque;
 
-				for ( i = 0; i < opaque.count; i ++ ) {
+					setObjectFaces( object );
 
-					material = opaque.list[ i ];
+					for ( i = 0; i < opaque.count; i ++ ) {
 
-					setDepthTest( material.depthTest );
-					renderBuffer( camera, lights, fog, material, buffer, object );
+						material = opaque.list[ i ];
+
+						setDepthTest( material.depthTest );
+						setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
+						renderBuffer( camera, lights, fog, material, buffer, object );
+
+					}
 
 				}
 
 			}
 
-		}
+			// opaque pass (immediate simulator)
 
-		// opaque pass (immediate simulator)
+			for ( o = 0; o < oil; o++ ) {
 
-		for ( o = 0; o < oil; o++ ) {
+				webglObject = scene.__webglObjectsImmediate[ o ];
+				object = webglObject.object;
 
-			webglObject = scene.__webglObjectsImmediate[ o ];
-			object = webglObject.object;
+				if ( object.visible ) {
 
-			if ( object.visible ) {
+					opaque = webglObject.opaque;
 
-				opaque = webglObject.opaque;
+					setObjectFaces( object );
 
-				setObjectFaces( object );
+					for( i = 0; i < opaque.count; i++ ) {
 
-				for( i = 0; i < opaque.count; i++ ) {
+						material = opaque.list[ i ];
 
-					material = opaque.list[ i ];
+						setDepthTest( material.depthTest );
+						setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
 
-					setDepthTest( material.depthTest );
+						program = setProgram( camera, lights, fog, material, object );
+						object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
 
-					program = setProgram( camera, lights, fog, material, object );
-					object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
+					}
 
 				}
 
 			}
 
-		}
+			// transparent pass
 
-		// transparent pass
+			for ( o = 0; o < ol; o ++ ) {
 
-		for ( o = 0; o < ol; o ++ ) {
+				webglObject = scene.__webglObjects[ o ];
 
-			webglObject = scene.__webglObjects[ o ];
+				if ( webglObject.render ) {
 
-			if ( webglObject.render ) {
+					object = webglObject.object;
+					buffer = webglObject.buffer;
+					transparent = webglObject.transparent;
 
-				object = webglObject.object;
-				buffer = webglObject.buffer;
-				transparent = webglObject.transparent;
+					setObjectFaces( object );
 
-				setObjectFaces( object );
+					for ( i = 0; i < transparent.count; i ++ ) {
 
-				for ( i = 0; i < transparent.count; i ++ ) {
+						material = transparent.list[ i ];
 
-					material = transparent.list[ i ];
+						setBlending( material.blending );
+						setDepthTest( material.depthTest );
+						setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
 
-					setBlending( material.blending );
-					setDepthTest( material.depthTest );
+						renderBuffer( camera, lights, fog, material, buffer, object );
 
-					renderBuffer( camera, lights, fog, material, buffer, object );
+					}
 
 				}
 
 			}
 
-		}
+			// transparent pass (immediate simulator)
 
-		// transparent pass (immediate simulator)
+			for ( o = 0; o < oil; o++ ) {
 
-		for ( o = 0; o < oil; o++ ) {
+				webglObject = scene.__webglObjectsImmediate[ o ];
+				object = webglObject.object;
 
-			webglObject = scene.__webglObjectsImmediate[ o ];
-			object = webglObject.object;
+				if ( object.visible ) {
 
-			if ( object.visible ) {
+					transparent = webglObject.transparent;
 
-				transparent = webglObject.transparent;
+					setObjectFaces( object );
 
-				setObjectFaces( object );
+					for ( i = 0; i < transparent.count; i ++ ) {
 
-				for ( i = 0; i < transparent.count; i ++ ) {
+						material = transparent.list[ i ];
 
-					material = transparent.list[ i ];
+						setBlending( material.blending );
+						setDepthTest( material.depthTest );
+						setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
 
-					setBlending( material.blending );
-					setDepthTest( material.depthTest );
+						program = setProgram( camera, lights, fog, material, object );
+						object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
 
-					program = setProgram( camera, lights, fog, material, object );
-					object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
+					}
 
 				}
 
@@ -3340,10 +3451,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 	/*
 	 * Stencil Shadows
 	 * method: we're rendering the world in light, then the shadow
-	 *         volumes into the stencil and last a big darkening 
+	 *         volumes into the stencil and last a big darkening
 	 *         quad over the whole thing. This is not how "you're
 	 *	       supposed to" do stencil shadows but is much faster
-	 * 
+	 *
 	 */
 
 	function renderStencilShadows( scene ) {
@@ -3396,7 +3507,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 					if ( !material.program ) _this.initMaterial( material, lights, undefined, object );
 
 					program = material.program,
-		  			p_uniforms = program.uniforms,
+					p_uniforms = program.uniforms,
 					m_uniforms = material.uniforms,
 					attributes = program.attributes;
 
@@ -3476,7 +3587,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	/*
 	 * Render sprites
-	 * 
+	 *
 	 */
 
 	function renderSprites( scene, camera ) {
@@ -3556,9 +3667,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 					if ( object.useScreenCoordinates ) {
 
 						_gl.uniform1i( uniforms.useScreenCoordinates, 1 );
-						_gl.uniform3f( uniforms.screenPosition, ( object.position.x - halfViewportWidth  ) / halfViewportWidth, 
-														        ( halfViewportHeight - object.position.y ) / halfViewportHeight,
-														          Math.max( 0, Math.min( 1, object.position.z )));
+						_gl.uniform3f( uniforms.screenPosition, ( object.position.x - halfViewportWidth  ) / halfViewportWidth,
+																( halfViewportHeight - object.position.y ) / halfViewportHeight,
+																  Math.max( 0, Math.min( 1, object.position.z )));
 
 					} else {
 
@@ -3570,7 +3681,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					}
 
-					size = object.map.image.width / ( object.affectedByDistance ? 1 : _viewportHeight );
+					size = object.map.image.width / ( object.scaleByViewport ? _viewportHeight : 1 );
 					scale[ 0 ] = size * invAspect * object.scale.x;
 					scale[ 1 ] = size * object.scale.y;
 
@@ -3628,11 +3739,11 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	/*
 	 * Render lens flares
-	 * Method: renders 16x16 0xff00ff-colored points scattered over the light source area, 
-	 *         reads these back and calculates occlusion.  
-	 *         Then LensFlare.updateLensFlares() is called to re-position and 
+	 * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
+	 *         reads these back and calculates occlusion.
+	 *         Then LensFlare.updateLensFlares() is called to re-position and
 	 *         update transparency of flares. Then they are rendered.
-	 * 
+	 *
 	 */
 
 	function renderLensFlares( scene, camera ) {
@@ -3664,10 +3775,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		if ( ! _lensFlareAttributesEnabled ) {
-		
+
 			_gl.enableVertexAttribArray( _lensFlare.attributes.vertex );
 			_gl.enableVertexAttribArray( _lensFlare.attributes.uv );
-			
+
 			_lensFlareAttributesEnabled = true;
 
 		}
@@ -3716,7 +3827,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			screenPositionPixels[ 1 ] = screenPosition[ 1 ] * halfViewportHeight + halfViewportHeight;
 
 
-			// screen cull 
+			// screen cull
 
 			if ( _lensFlare.hasVertexTexture || ( screenPositionPixels[ 0 ] > 0 &&
 				screenPositionPixels[ 0 ] < _viewportWidth &&
@@ -4013,6 +4124,57 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	};
 
+	function areCustomAttributesDirty( geometryGroup ) {
+
+		var a, m, ml, material, materials;
+
+		materials = geometryGroup.__materials;
+
+		for ( m = 0, ml = materials.length; m < ml; m ++ ) {
+
+			material = materials[ m ];
+
+			if ( material.attributes ) {
+
+				for ( a in material.attributes ) {
+
+					if ( material.attributes[ a ].needsUpdate ) return true;
+
+				}
+
+			}
+
+		}
+
+
+		return false;
+
+	};
+
+	function clearCustomAttributes( geometryGroup ) {
+
+		var a, m, ml, material, materials;
+
+		materials = geometryGroup.__materials;
+
+		for ( m = 0, ml = materials.length; m < ml; m ++ ) {
+
+			material = materials[ m ];
+
+			if ( material.attributes ) {
+
+				for ( a in material.attributes ) {
+
+					material.attributes[ a ].needsUpdate = false;
+
+				}
+
+			}
+
+		}
+
+	};
+
 	function updateObject( object, scene ) {
 
 		var g, geometry, geometryGroup, a, customAttributeDirty;
@@ -4027,22 +4189,11 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				geometryGroup = geometry.geometryGroups[ g ];
 
-				customAttributeDirty = false;
-
-				for ( a in geometryGroup.__webglCustomAttributes ) {
-
-					if( geometryGroup.__webglCustomAttributes[ a ].needsUpdate ) {
-
-						customAttributeDirty = true;
-						break;
-
-					}
-
-				}
+				customAttributeDirty = areCustomAttributesDirty( geometryGroup );
 
 				if ( geometry.__dirtyVertices || geometry.__dirtyMorphTargets || geometry.__dirtyElements ||
-					geometry.__dirtyUvs || geometry.__dirtyNormals ||
-					geometry.__dirtyColors || geometry.__dirtyTangents || customAttributeDirty ) {
+					 geometry.__dirtyUvs || geometry.__dirtyNormals ||
+					 geometry.__dirtyColors || geometry.__dirtyTangents || customAttributeDirty ) {
 
 					setMeshBuffers( geometryGroup, object, _gl.DYNAMIC_DRAW );
 
@@ -4058,6 +4209,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 			geometry.__dirtyTangents = false;
 			geometry.__dirtyColors = false;
 
+			clearCustomAttributes( geometryGroup );
+
 		} else if ( object instanceof THREE.Ribbon ) {
 
 			geometry = object.geometry;
@@ -4129,6 +4282,22 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	};
 
+	function removeInstancesDirect( objlist, object ) {
+
+		var o, ol;
+
+		for ( o = objlist.length - 1; o >= 0; o -- ) {
+
+			if ( objlist[ o ] == object ) {
+
+				objlist.splice( o, 1 );
+
+			}
+
+		}
+
+	};
+
 	function removeObject( object, scene ) {
 
 		// must check as shadow volume before mesh (as they are also meshes)
@@ -4140,13 +4309,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 		} else if ( object instanceof THREE.Mesh  ||
 			 object instanceof THREE.ParticleSystem ||
 			 object instanceof THREE.Ribbon ||
-		     object instanceof THREE.Line ) {
+			 object instanceof THREE.Line ) {
 
 			removeInstances( scene.__webglObjects, object );
 
 		} else if ( object instanceof THREE.Sprite ) {
 
-			removeInstances( scene.__webglSprites, object );
+			removeInstancesDirect( scene.__webglSprites, object );
 
 		} else if ( object instanceof THREE.LensFlare ) {
 
@@ -4378,7 +4547,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		].join("\n");
 
 		var prefix_vertex = [
-			
+
 			_supportsVertexTextures ? "#define VERTEX_TEXTURES" : "",
 
 			"#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
@@ -4663,7 +4832,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	function setTexture( texture, slot ) {
 
-		/*
 		if ( texture.needsUpdate ) {
 
 			if ( !texture.__webglInit ) {
@@ -4690,10 +4858,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
-		_gl.activeTexture( _gl.TEXTURE0 + slot );
-		_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
-		*/
-
+		/*
 		if ( texture.needsUpdate ) {
 
 			if ( texture.__webglTexture ) {
@@ -4714,10 +4879,12 @@ THREE.WebGLRenderer = function ( parameters ) {
 			texture.needsUpdate = false;
 
 		}
+		*/
 
 		_gl.activeTexture( _gl.TEXTURE0 + slot );
 		_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
 
+
 	};
 
 	function setCubeTexture( texture, slot ) {
@@ -4800,7 +4967,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 				_gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTexture.width, renderTexture.height );
 				_gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTexture.__webglRenderbuffer );
 
-			/* For some reason this is not working. Defaulting to RGBA4.	
+			/* For some reason this is not working. Defaulting to RGBA4.
 			} else if( !renderTexture.depthBuffer && renderTexture.stencilBuffer ) {
 
 				_gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTexture.width, renderTexture.height );
@@ -4928,7 +5095,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			case THREE.LinearFilter:
 			case THREE.LinearMipMapNearestFilter:
-			case THREE.LinearMipMapLinearFilter: 
+			case THREE.LinearMipMapLinearFilter:
 			default:
 
 				return _gl.LINEAR; break;

+ 99 - 82
src/renderers/WebGLShaders.js

@@ -629,7 +629,7 @@ THREE.UniformsLib = {
 THREE.ShaderLib = {
 
 	'lensFlareVertexTexture': {
-		
+
 		vertexShader: [
 
 			"uniform 	vec3 	screenPosition;",
@@ -643,74 +643,78 @@ THREE.ShaderLib = {
 			"attribute  vec2	UV;",
 			"varying	vec2	vUV;",
 			"varying	float	vVisibility;",
-	
-			"void main(void)",
-			"{",
+
+			"void main() {",
+
 				"vUV = UV;",
 
 				"vec2 pos = position;",
-				
+
 				"if( renderType == 2 ) {",
 
-					"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 )) +",
-									  "texture2D( occlusionMap, vec2( 0.5, 0.1 )) +",
-									  "texture2D( occlusionMap, vec2( 0.9, 0.1 )) +",
-									  "texture2D( occlusionMap, vec2( 0.9, 0.5 )) +",
-									  "texture2D( occlusionMap, vec2( 0.9, 0.9 )) +",
-									  "texture2D( occlusionMap, vec2( 0.5, 0.9 )) +",
-									  "texture2D( occlusionMap, vec2( 0.1, 0.9 )) +",
-									  "texture2D( occlusionMap, vec2( 0.1, 0.5 )) +",
-									  "texture2D( occlusionMap, vec2( 0.5, 0.5 ));",
+					"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +",
+									  "texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
 
 					"vVisibility = (       visibility.r / 9.0 ) *",
-					              "( 1.0 - visibility.g / 9.0 ) *",
-					              "(       visibility.b / 9.0 ) *", 
-					              "( 1.0 - visibility.a / 9.0 );",
+								  "( 1.0 - visibility.g / 9.0 ) *",
+								  "(       visibility.b / 9.0 ) *", 
+								  "( 1.0 - visibility.a / 9.0 );",
 
 					"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
 					"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
+
 				"}",
-				
-				"gl_Position = vec4(( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
+
+				"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
+
 			"}"
 
 		].join( "\n" ),
-		
+
 		fragmentShader: [
-		
+
 			"#ifdef GL_ES",
 				"precision highp float;",
-			"#endif",		
+			"#endif",
 
 			"uniform	sampler2D	map;",
 			"uniform	float		opacity;",
 			"uniform    int         renderType;",
-			
+
 			"varying	vec2		vUV;",
 			"varying	float		vVisibility;",
-	
-			"void main( void )",
-			"{",
+
+			"void main() {",
+
 				// pink square
-			
+
 				"if( renderType == 0 ) {",
-							
+
 					"gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
-				
+
 				// restore
-				
+
 				"} else if( renderType == 1 ) {",
 
 					"gl_FragColor = texture2D( map, vUV );",
-				
+
 				// flare
-				
+
 				"} else {",
-				
+
 					"vec4 color = texture2D( map, vUV );",
 					"color.a *= opacity * vVisibility;",
 					"gl_FragColor = color;",
+
 				"}",
+
 			"}"
 		].join( "\n" )
 
@@ -718,7 +722,7 @@ THREE.ShaderLib = {
 
 
 	'lensFlare': {
-		
+
 		vertexShader: [
 
 			"uniform 	vec3 	screenPosition;",
@@ -730,74 +734,80 @@ THREE.ShaderLib = {
 			"attribute  vec2	UV;",
 
 			"varying	vec2	vUV;",
-	
-			"void main(void)",
-			"{",
+
+			"void main() {",
+
 				"vUV = UV;",
 
 				"vec2 pos = position;",
-				
+
 				"if( renderType == 2 ) {",
 
 					"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
 					"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
+
 				"}",
-				
-				"gl_Position = vec4(( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
+
+				"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
+
 			"}"
 
 		].join( "\n" ),
-		
+
 		fragmentShader: [
-		
+
 			"#ifdef GL_ES",
 				"precision highp float;",
-			"#endif",		
+			"#endif",
 
 			"uniform	sampler2D	map;",
 			"uniform	sampler2D	occlusionMap;",
 			"uniform	float		opacity;",
 			"uniform    int         renderType;",
-			
+
 			"varying	vec2		vUV;",
-	
-			"void main( void )",
-			"{",
+
+			"void main() {",
+
 				// pink square
-			
+
 				"if( renderType == 0 ) {",
-							
+
 					"gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
-				
+
 				// restore
-				
+
 				"} else if( renderType == 1 ) {",
 
 					"gl_FragColor = texture2D( map, vUV );",
-				
+
 				// flare
-				
+
 				"} else {",
 
-					"float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 )).a +",
-								  	   "texture2D( occlusionMap, vec2( 0.9, 0.5 )).a +",
-									   "texture2D( occlusionMap, vec2( 0.5, 0.9 )).a +",
-									   "texture2D( occlusionMap, vec2( 0.1, 0.5 )).a;",
-					
-	                "visibility = ( 1.0 - visibility / 4.0 );",
+					"float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +",
+									   "texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +",
+									   "texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +",
+									   "texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
+
+					"visibility = ( 1.0 - visibility / 4.0 );",
 
 					"vec4 color = texture2D( map, vUV );",
 					"color.a *= opacity * visibility;",
 					"gl_FragColor = color;",
+
 				"}",
+
 			"}"
+
 		].join( "\n" )
 
 	},
 
 	'sprite': {
-		
+
 		vertexShader: [
+
 			"uniform	int		useScreenCoordinates;",
 			"uniform    int     affectedByDistance;",
 			"uniform	vec3	screenPosition;",
@@ -813,53 +823,56 @@ THREE.ShaderLib = {
 			"attribute  vec2	uv;",
 
 			"varying	vec2	vUV;",
-	
-			"void main(void)",
-			"{",
+
+			"void main() {",
+
+				//"vUV = uvOffset + vec2( uv.x, 1.0 - uv.y ) * uvScale;",
 				"vUV = uvOffset + uv * uvScale;",
 
 				"vec2 alignedPosition = position + alignment;",
-			
+
 				"vec2 rotatedPosition;",
 				"rotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;",
 				"rotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;",
 
 				"vec4 finalPosition;",
-				
+
 				"if( useScreenCoordinates != 0 ) {",
-				
+
 					"finalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );",
-				
+
 				"} else {",
-				
+
 					"finalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );",
 					"finalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );",
 
 				"}",
 
 				"gl_Position = finalPosition;",
+
 			"}"
 
 		].join( "\n" ),
-		
+
 		fragmentShader: [
-		
+
 			"#ifdef GL_ES",
 				"precision highp float;",
-			"#endif",		
+			"#endif",
 
 			"uniform	sampler2D	map;",
 			"uniform	float		opacity;",
-			
+
 			"varying	vec2		vUV;",
-	
-			"void main( void )",
-			"{",
+
+			"void main() {",
+
 				"vec4 color = texture2D( map, vUV );",
 				"color.a *= opacity;",
 				"gl_FragColor = color;",
-//				"gl_FragColor = vec4( 1.0, 0.0, 1.0, 1.0 );",
+
 			"}"
+
 		].join( "\n" )
 
 	},
@@ -873,9 +886,10 @@ THREE.ShaderLib = {
 			"uniform 	mat4 	projectionMatrix;",
 			"attribute 	vec3 	position;",
 
-			"void main(void)",
-			"{",
+			"void main() {",
+
 				"gl_Position = projectionMatrix * vec4( position, 1.0 );",
+
 			"}"
 
 		].join( "\n" ),
@@ -884,13 +898,14 @@ THREE.ShaderLib = {
 
 			"#ifdef GL_ES",
 				"precision highp float;",
-			"#endif",		
+			"#endif",
 
 			"uniform 	float 	darkness;",
 
-			"void main( void )",
-			"{",
+			"void main() {",
+
 				"gl_FragColor = vec4( 0, 0, 0, darkness );",
+
 			"}"
 
 		].join( "\n" )
@@ -910,9 +925,10 @@ THREE.ShaderLib = {
 
 				"vec4 pos      = objectMatrix * vec4( position, 1.0 );",
 				"vec3 norm     = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;",
-				"vec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm )), 0.0 );",
+				"vec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm ) ), 0.0 );",
 
 				"gl_Position   = projectionMatrix * viewMatrix * ( pos + extruded );",
+
 			"}"
 
 		].join( "\n" ),
@@ -926,6 +942,7 @@ THREE.ShaderLib = {
 			"}"
 
 		].join( "\n" )
+
 	},
 
 

+ 2 - 0
src/scenes/Scene.js

@@ -11,6 +11,8 @@ THREE.Scene = function () {
 
 	this.fog = null;
 
+	this.overrideMaterial = null;
+
 	this.collisions = null;
 
 	this.objects = [];

+ 1 - 1
utils/build.bat

@@ -1 +1 @@
-python build.py --common --minified
+python build.py --common --minified --includes

+ 2 - 1
utils/build.py

@@ -89,11 +89,12 @@ EXTRAS_FILES = [
 'extras/ShaderUtils.js',
 'extras/animation/AnimationHandler.js',
 'extras/animation/Animation.js',
-'extras/cameras/QuakeCamera.js',
+'extras/cameras/FirstPersonCamera.js',
 'extras/cameras/PathCamera.js',
 'extras/cameras/FlyCamera.js',
 'extras/cameras/RollCamera.js',
 'extras/cameras/TrackballCamera.js',
+'extras/cameras/QuakeCamera.js',
 'extras/geometries/CubeGeometry.js',
 'extras/geometries/CylinderGeometry.js',
 'extras/geometries/IcosahedronGeometry.js',

+ 17 - 3
utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/__init__.py

@@ -25,8 +25,8 @@
 
 bl_info = {
     "name": "three.js format",
-    "author": "mrdoob, kikko, alteredq, remoe",
-    "version": (1, 0),
+    "author": "mrdoob, kikko, alteredq, remoe, pxf",
+    "version": (1, 0, 1),
     "blender": (2, 5, 7),
     "api": 35622,
     "location": "File > Import-Export",
@@ -175,6 +175,8 @@ def save_settings_export(properties):
     settings = {
     "option_export_scene" : properties.option_export_scene,
     "option_embed_meshes" : properties.option_embed_meshes,
+    "option_url_base_html" : properties.option_url_base_html,
+    "option_copy_textures" : properties.option_copy_textures,
     
     "option_lights" : properties.option_lights,
     "option_cameras" : properties.option_cameras,
@@ -225,6 +227,8 @@ def restore_settings_export(properties):
 
     properties.option_export_scene = settings.get("option_export_scene", False)
     properties.option_embed_meshes = settings.get("option_embed_meshes", True)
+    properties.option_url_base_html = settings.get("option_url_base_html", False)
+    properties.option_copy_textures = settings.get("option_copy_textures", False)
 
     properties.option_lights = settings.get("option_lights", False)
     properties.option_cameras = settings.get("option_cameras", False)
@@ -263,7 +267,9 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
 
     option_export_scene = BoolProperty(name = "Scene", description = "Export scene", default = False)
     option_embed_meshes = BoolProperty(name = "Embed", description = "Embed meshes", default = True)
-    
+    option_copy_textures = BoolProperty(name = "Copy textures", description = "Copy textures", default = False)
+    option_url_base_html = BoolProperty(name = "HTML as url base", description = "Use HTML as url base ", default = False)
+
     option_lights = BoolProperty(name = "Lights", description = "Export default scene lights", default = False)
     option_cameras = BoolProperty(name = "Cameras", description = "Export default scene cameras", default = False)
 
@@ -284,6 +290,7 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
         save_settings_export(self.properties)
 
         filepath = self.filepath
+
         import io_mesh_threejs.export_threejs
         return io_mesh_threejs.export_threejs.save(self, context, **self.properties)
 
@@ -341,11 +348,18 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
 
         row = layout.row()
         row.prop(self.properties, "option_export_scene")
+
+        row = layout.row()
         row.prop(self.properties, "option_lights")
         row.prop(self.properties, "option_cameras")
 
         row = layout.row()
         row.prop(self.properties, "option_embed_meshes")
+        row.prop(self.properties, "option_copy_textures")
+        
+        row = layout.row()
+        row.prop(self.properties, "option_url_base_html")
+
         layout.separator()
 
 

+ 239 - 78
utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -20,14 +20,13 @@
 Blender exporter for Three.js (ASCII JSON format).
 
 TODO
-    - export scene
-    - copy used images to folder where exported file goes
     - binary format
 """
 
 import bpy
 import mathutils
 
+import shutil
 import os
 import os.path
 import math
@@ -92,7 +91,7 @@ TEMPLATE_SCENE_ASCII = """\
 var scene = {
 
 "type" : "scene",
-"urlBaseType" : "relativeToScene",
+"urlBaseType" : %(basetype)s,
 
 %(sections)s
 
@@ -162,7 +161,7 @@ TEMPLATE_GEOMETRY_EMBED = """\
 
 TEMPLATE_TEXTURE = """\
     %(texture_id)s : {
-        "url": %(texture_file)s
+        "url": %(texture_file)s%(extras)s
     }"""
 
 TEMPLATE_MATERIAL_SCENE = """\
@@ -694,6 +693,8 @@ def value2string(v):
         return '"%s"' % v
     elif type(v) == bool:
         return str(v).lower()
+    elif type(v) == list:
+        return "[%s]" % (", ".join(value2string(x) for x in v))
     return str(v)
 
 def generate_materials(mtl, materials, draw_type):
@@ -722,7 +723,7 @@ def generate_materials(mtl, materials, draw_type):
 
     return ",\n\n".join([m for i,m in sorted(mtl_array)]), len(mtl_array)
 
-def extract_materials(mesh, scene, option_colors):
+def extract_materials(mesh, scene, option_colors, option_copy_textures, filepath):
     world = scene.world
 
     materials = {}
@@ -750,16 +751,16 @@ def extract_materials(mesh, scene, option_colors):
             material['transparency'] = m.alpha
 
             # not sure about mapping values to Blinn-Phong shader
-            # Blender uses INT from [1,511] with default 0
+            # Blender uses INT from [1, 511] with default 0
             # http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.types.Material.html#bpy.types.Material.specular_hardness
 
             material["specularCoef"] = m.specular_hardness
 
-            if m.active_texture and m.active_texture.type == 'IMAGE' and m.active_texture.image:
-                fn = bpy.path.abspath(m.active_texture.image.filepath)
-                fn = os.path.normpath(fn)
-                fn_strip = os.path.basename(fn)
-                material['mapDiffuse'] = fn_strip
+            textures = guess_material_textures(m)
+
+            handle_texture('diffuse', textures, material, filepath, option_copy_textures)
+            handle_texture('light', textures, material, filepath, option_copy_textures)
+            handle_texture('normal', textures, material, filepath, option_copy_textures)
 
             material["vertexColors"] = m.THREE_useVertexColors and option_colors
 
@@ -769,12 +770,12 @@ def extract_materials(mesh, scene, option_colors):
             #    material['shading'] = "Phong"
             #else:
             #    material['shading'] = "Lambert"
-            
+
             material['shading'] = m.THREE_materialType
 
     return materials
 
-def generate_materials_string(mesh, scene, option_colors, draw_type):
+def generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath):
 
     random.seed(42) # to get well defined color order for debug materials
 
@@ -796,10 +797,45 @@ def generate_materials_string(mesh, scene, option_colors, draw_type):
 
     # extract real materials from the mesh
 
-    mtl.update(extract_materials(mesh, scene, option_colors))
+    mtl.update(extract_materials(mesh, scene, option_colors, option_copy_textures, filepath))
 
     return generate_materials(mtl, materials, draw_type)
 
+def handle_texture(id, textures, material, filepath, option_copy_textures):
+
+    if textures[id]:
+        texName     = 'map%s'       % id.capitalize()
+        repeatName  = 'map%sRepeat' % id.capitalize()
+        wrapName    = 'map%sWrap'   % id.capitalize()
+
+        slot = textures[id]['slot']
+        texture = textures[id]['texture']
+        image = texture.image
+        fname = extract_texture_filename(image)
+        material[texName] = fname
+
+        if option_copy_textures:
+            save_image(image, fname, filepath)
+
+        if texture.repeat_x != 1 or texture.repeat_y != 1:
+            material[repeatName] = [texture.repeat_x, texture.repeat_y]
+
+        if texture.extension == "REPEAT":
+            wrap_x = "repeat"
+            wrap_y = "repeat"
+
+            if texture.use_mirror_x:
+                wrap_x = "mirror" 
+            if texture.use_mirror_y:
+                wrap_y = "mirror"
+
+            material[wrapName] = [wrap_x, wrap_y]
+            
+        if slot.use_map_normal:
+            if slot.normal_factor != 1.0:
+                material['mapNormalFactor'] = slot.normal_factor
+
+
 # #####################################################
 # ASCII model generator
 # #####################################################
@@ -816,7 +852,9 @@ def generate_ascii_model(mesh, scene,
                          align_model,
                          flipyz,
                          option_scale,
-                         draw_type):
+                         draw_type,
+                         option_copy_textures,
+                         filepath):
 
     vertices = mesh.vertices[:]
 
@@ -838,7 +876,7 @@ def generate_ascii_model(mesh, scene,
     nedges = 0
 
     if option_materials:
-        materials_string, nmaterial = generate_materials_string(mesh, scene, option_colors, draw_type)
+        materials_string, nmaterial = generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath)
 
     if option_edges:
         nedges = len(mesh.edges)
@@ -892,7 +930,9 @@ def generate_mesh_string(obj, scene,
                 align_model,
                 flipyz,
                 option_scale,
-                export_single_model):
+                export_single_model,
+                option_copy_textures,
+                filepath):
 
     # collapse modifiers into mesh
 
@@ -932,6 +972,10 @@ def generate_mesh_string(obj, scene,
         if not active_col_layer:
             option_colors = False
 
+    option_copy_textures_model = False
+    if export_single_model and option_copy_textures:
+        option_copy_textures_model = True
+        
     text, model_string = generate_ascii_model(mesh, scene,
                                 option_vertices,
                                 option_vertices_truncate,
@@ -944,7 +988,9 @@ def generate_mesh_string(obj, scene,
                                 align_model,
                                 flipyz,
                                 option_scale,
-                                obj.draw_type)
+                                obj.draw_type,
+                                option_copy_textures_model,
+                                filepath)
     # remove temp mesh
 
     bpy.data.meshes.remove(mesh)
@@ -963,7 +1009,8 @@ def export_mesh(obj, scene, filepath,
                 align_model,
                 flipyz,
                 option_scale,
-                export_single_model):
+                export_single_model,
+                option_copy_textures):
 
     """Export single mesh"""
 
@@ -979,7 +1026,9 @@ def export_mesh(obj, scene, filepath,
                 align_model,
                 flipyz,
                 option_scale,
-                export_single_model)
+                export_single_model,
+                option_copy_textures,
+                filepath)
 
     write_file(filepath, text)
 
@@ -1080,7 +1129,7 @@ def generate_objects(data):
                 visible = False
 
             geometry_string = generate_string(geometry_id)
-                
+
             object_string = TEMPLATE_OBJECT % {
             "object_id"   : generate_string(object_id),
             "geometry_id" : geometry_string,
@@ -1098,7 +1147,7 @@ def generate_objects(data):
             "visible"      : generate_bool_property(visible)
             }
             chunks.append(object_string)
-            
+
         elif obj.type == "EMPTY" or (obj.type == "MESH" and not obj.THREE_exportGeometry):
 
             object_id = obj.name
@@ -1182,16 +1231,40 @@ def generate_textures_scene(data):
 
     # TODO: extract just textures actually used by some objects in the scene
 
-    for img in bpy.data.images:
+    for texture in bpy.data.textures:
 
-        texture_id = img.name
-        texture_file = extract_texture_filename(img)
+        if texture.type == 'IMAGE' and texture.image:
 
-        texture_string = TEMPLATE_TEXTURE % {
-        "texture_id"   : generate_string(texture_id),
-        "texture_file" : generate_string(texture_file)
-        }
-        chunks.append(texture_string)
+            img = texture.image
+
+            texture_id = img.name
+            texture_file = extract_texture_filename(img)
+
+            if data["copy_textures"]:
+                save_image(img, texture_file, data["filepath"])
+
+            extras = ""
+
+            if texture.repeat_x != 1 or texture.repeat_y != 1:
+                extras += ',\n        "repeat": [%f, %f]' % (texture.repeat_x, texture.repeat_y)
+
+            if texture.extension == "REPEAT":
+                wrap_x = "repeat"
+                wrap_y = "repeat"
+
+                if texture.use_mirror_x:
+                    wrap_x = "mirror" 
+                if texture.use_mirror_y:
+                    wrap_y = "mirror"
+
+                extras += ',\n        "wrap": ["%s", "%s"]' % (wrap_x, wrap_y)
+
+            texture_string = TEMPLATE_TEXTURE % {
+            "texture_id"   : generate_string(texture_id),
+            "texture_file" : generate_string(texture_file),
+            "extras"       : extras
+            }
+            chunks.append(texture_string)
 
     return ",\n\n".join(chunks), len(chunks)
 
@@ -1201,6 +1274,19 @@ def extract_texture_filename(image):
     fn_strip = os.path.basename(fn)
     return fn_strip
 
+def save_image(img, name, fpath):
+    dst_dir = os.path.dirname(fpath)
+    dst_path = os.path.join(dst_dir, name)
+
+    ensure_folder_exist(dst_dir)
+
+    if img.packed_file:
+        img.save_render(dst_path)
+
+    else:
+        src_path = bpy.path.abspath(img.filepath)
+        shutil.copy(src_path, dst_dir)
+
 # #####################################################
 # Scene exporter - materials
 # #####################################################
@@ -1234,40 +1320,60 @@ def extract_material_data(m, option_colors):
 
     material["specularCoef"] = m.specular_hardness
 
+    material["vertexColors"] = m.THREE_useVertexColors and option_colors
+
     material['mapDiffuse'] = ""
     material['mapLight'] = ""
     material['mapNormal'] = ""
+    material['mapNormalFactor'] = 1.0
+
+    textures = guess_material_textures(m)
+
+    if textures['diffuse']:
+        material['mapDiffuse'] = textures['diffuse']['texture'].image.name
+
+    if textures['light']:
+        material['mapLight'] = textures['light']['texture'].image.name
+
+    if textures['normal']:
+        material['mapNormal'] = textures['normal']['texture'].image.name
+        if textures['normal']['slot'].use_map_normal:
+            material['mapNormalFactor'] = textures['normal']['slot'].normal_factor
+
+    material['shading'] = m.THREE_materialType
+
+    return material
+
+def guess_material_textures(material):
+    textures = { 
+        'diffuse' : None,
+        'light'   : None,
+        'normal'  : None 
+    }
 
-    material["vertexColors"] = m.THREE_useVertexColors and option_colors
-    
     # just take first textures of each, for the moment three.js materials can't handle more
+    # assume diffuse comes before lightmap, normalmap has checked flag
 
-    for i in range(len(m.texture_slots)):
-        ts = m.texture_slots[i]
-        if ts:
-            t = ts.texture
-            if ts.use and t.type == 'IMAGE':
-                name = t.image.name
+    for i in range(len(material.texture_slots)):
+        slot = material.texture_slots[i]
+        if slot:
+            texture = slot.texture
+            if slot.use and texture.type == 'IMAGE':
+
+                if texture.use_normal_map:
+                    textures['normal'] = { "texture": texture, "slot": slot }
 
-                if t.use_normal_map:
-                    material['mapNormal'] = name
                 else:
-                    if not material['mapDiffuse']:
-                        material['mapDiffuse'] = name
+                    if not textures['diffuse']:
+                        textures['diffuse'] = { "texture": texture, "slot": slot }
+
                     else:
-                        material['mapLight'] = name
+                        textures['light'] = { "texture": texture, "slot": slot }
 
-                if material['mapDiffuse'] and material['mapNormal'] and material['mapLight']:
+                if textures['diffuse'] and textures['normal'] and textures['light']:
                     break
 
-    #if m.specular_intensity > 0.0 and (m.specular_color[0] > 0 or m.specular_color[1] > 0 or m.specular_color[2] > 0):
-    #    material['shading'] = "Phong"
-    #else:
-    #    material['shading'] = "Lambert"
-
-    material['shading'] = m.THREE_materialType
-
-    return material
+    return textures
 
 def generate_material_string(material):
     type_map = {
@@ -1290,6 +1396,7 @@ def generate_material_string(material):
     colorMap = material['mapDiffuse']
     lightMap = material['mapLight']
     normalMap = material['mapNormal']
+    normalMapFactor = material['mapNormalFactor']
 
     if colorMap:
         parameters += ', "map": %s' % generate_string(colorMap)
@@ -1297,6 +1404,8 @@ def generate_material_string(material):
         parameters += ', "lightMap": %s' % generate_string(lightMap)
     if normalMap:
         parameters += ', "normalMap": %s' % generate_string(normalMap)
+    if normalMapFactor != 1.0:
+        parameters += ', "normalMapFactor": %f' % normalMapFactor
 
     if material['vertexColors']:
         parameters += ', "vertexColors": "vertex"'
@@ -1328,14 +1437,13 @@ def generate_materials_scene(data):
 def generate_cameras(data):
     if data["use_cameras"]:
 
-        cameras = data.get("cameras", [])
-        
-        if not cameras:
-            cameras.append(DEFAULTS["camera"])
+        cams = bpy.data.objects
+        cams = [ob for ob in cams if (ob.type == 'CAMERA' and ob.select)]
 
         chunks = []
 
-        for camera in cameras:
+        if not cams:
+            camera = DEFAULTS["camera"]
 
             if camera["type"] == "perspective":
 
@@ -1365,6 +1473,29 @@ def generate_cameras(data):
 
             chunks.append(camera_string)
 
+        else:
+
+            for cameraobj in cams:
+                camera = bpy.data.cameras[cameraobj.name]
+
+                # TODO:
+                #   Support more than perspective camera
+                #   Calculate a target/lookat
+                #   Get correct aspect ratio
+                if camera.id_data.type == "PERSP":
+
+                    camera_string = TEMPLATE_CAMERA_PERSPECTIVE % {
+                    "camera_id" : generate_string(camera.name),
+                    "fov"       : (camera.angle / 3.14) * 180.0,
+                    "aspect"    : 1.333,
+                    "near"      : camera.clip_start,
+                    "far"       : camera.clip_end,
+                    "position"  : generate_vec3([cameraobj.location[0], -cameraobj.location[1], cameraobj.location[2]]),
+                    "target"    : generate_vec3([0, 0, 0])
+                    }
+
+                chunks.append(camera_string)
+
         return ",\n\n".join(chunks)
 
     return ""
@@ -1443,6 +1574,13 @@ def generate_ascii_scene(data):
 
     embeds = generate_embeds(data)
 
+    basetype = "relativeTo"
+
+    if data["base_html"]:
+        basetype += "HTML"
+    else:
+        basetype += "Scene"
+
     sections = [
     ["objects",    objects],
     ["geometries", geometries],
@@ -1462,7 +1600,11 @@ def generate_ascii_scene(data):
 
     default_camera = ""
     if data["use_cameras"]:
-        default_camera = generate_string("default_camera")
+        cams = [ob for ob in bpy.data.objects if (ob.type == 'CAMERA' and ob.select)]
+        if not cams:
+            default_camera = "default_camera"
+        else:
+            default_camera = cams[0].name
 
     parameters = {
     "fname"     : data["source_file"],
@@ -1476,6 +1618,7 @@ def generate_ascii_scene(data):
     "nobjects"      : nobjects,
     "ngeometries"   : ngeometries,
     "ntextures"     : ntextures,
+    "basetype"      : generate_string(basetype),
     "nmaterials"    : nmaterials,
 
     "position"      : generate_vec3(DEFAULTS["position"]),
@@ -1487,22 +1630,24 @@ def generate_ascii_scene(data):
 
     return text
 
-def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds):
+def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds, option_url_base_html, option_copy_textures):
 
     source_file = os.path.basename(bpy.data.filepath)
 
     scene_text = ""
     data = {
-    "scene"       : scene,
-    "objects"     : scene.objects,
-    "embeds"      : embeds,
-    "source_file" : source_file,
-    "filepath"    : filepath,
-    "flipyz"      : flipyz,
-    "use_colors"  : option_colors,
-    "use_lights"  : option_lights, 
-    "use_cameras" : option_cameras,
-    "embed_meshes": option_embed_meshes
+    "scene"        : scene,
+    "objects"      : scene.objects,
+    "embeds"       : embeds,
+    "source_file"  : source_file,
+    "filepath"     : filepath,
+    "flipyz"       : flipyz,
+    "use_colors"   : option_colors,
+    "use_lights"   : option_lights, 
+    "use_cameras"  : option_cameras,
+    "embed_meshes" : option_embed_meshes,
+    "base_html"    : option_url_base_html,
+    "copy_textures": option_copy_textures
     }
     scene_text += generate_ascii_scene(data)
 
@@ -1527,7 +1672,11 @@ def save(operator, context, filepath = "",
          option_lights = False,
          option_cameras = False,
          option_scale = 1.0,
-         option_embed_meshes = True):
+         option_embed_meshes = True,
+         option_url_base_html = False,
+         option_copy_textures = False):
+
+    #print("URL TYPE", option_url_base_html)
 
     filepath = ensure_extension(filepath, '.js')
 
@@ -1568,17 +1717,20 @@ def save(operator, context, filepath = "",
                                                         option_uv_coords,
                                                         option_materials,
                                                         option_colors,
-                                                        False,
+                                                        False,          # align_model
                                                         option_flip_yz,
                                                         option_scale,
-                                                        False)
+                                                        False,          # export_single_model
+                                                        False,          # option_copy_textures
+                                                        filepath)
                         
                         embeds[name] = model_string
 
                     else:
 
                         fname = generate_mesh_filename(name, filepath)
-                        export_mesh(obj, scene, fname,
+                        export_mesh(obj, scene,
+                                    fname,
                                     option_vertices,
                                     option_vertices_truncate,
                                     option_faces,
@@ -1587,14 +1739,23 @@ def save(operator, context, filepath = "",
                                     option_uv_coords,
                                     option_materials,
                                     option_colors,
-                                    False,
+                                    False,          # align_model
                                     option_flip_yz,
                                     option_scale,
-                                    False)
+                                    False,          # export_single_model
+                                    option_copy_textures)
 
                     geo_set.add(name)
 
-        export_scene(scene, filepath, option_flip_yz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds)
+        export_scene(scene, filepath, 
+                     option_flip_yz, 
+                     option_colors, 
+                     option_lights, 
+                     option_cameras, 
+                     option_embed_meshes, 
+                     embeds, 
+                     option_url_base_html, 
+                     option_copy_textures)
 
     else:
 
@@ -1614,7 +1775,7 @@ def save(operator, context, filepath = "",
                     align_model,
                     option_flip_yz,
                     option_scale,
-                    True)
-
+                    True,            # export_single_model
+                    option_copy_textures)
 
     return {'FINISHED'}

+ 390 - 0
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/__init__.py

@@ -0,0 +1,390 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# ################################################################
+# Init
+# ################################################################
+
+
+bl_info = {
+    "name": "three.js format",
+    "author": "mrdoob, kikko, alteredq, remoe, pxf",
+    "version": (1, 0, 2),
+    "blender": (2, 5, 7),
+    "api": 35622,
+    "location": "File > Import-Export",
+    "description": "Import-Export three.js meshes",
+    "warning": "",
+    "wiki_url": "https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender",
+    "tracker_url": "https://github.com/mrdoob/three.js/issues",
+    "category": "Import-Export"}
+
+# To support reload properly, try to access a package var,
+# if it's there, reload everything
+
+import bpy
+
+if "bpy" in locals():
+    import imp
+    if "export_threejs" in locals():
+        imp.reload(export_threejs)
+    if "import_threejs" in locals():
+        imp.reload(import_threejs)
+
+from bpy.props import *
+from bpy_extras.io_utils import ExportHelper, ImportHelper
+
+# ################################################################
+# Custom properties
+# ################################################################
+
+bpy.types.Object.THREE_castsShadow = bpy.props.BoolProperty()
+bpy.types.Object.THREE_meshCollider = bpy.props.BoolProperty()
+bpy.types.Object.THREE_exportGeometry = bpy.props.BoolProperty(default = True)
+
+THREE_trigger_types = [("None", "None", "None"), ("Small", "Small", "Small"), ("Large", "Large", "Large")]
+bpy.types.Object.THREE_triggerType = EnumProperty(name = "Trigger type", description = "Trigger type", items = THREE_trigger_types, default = "None")
+
+bpy.types.Material.THREE_useVertexColors = bpy.props.BoolProperty()
+
+THREE_material_types = [("Basic", "Basic", "Basic"), ("Phong", "Phong", "Phong"), ("Lambert", "Lambert", "Lambert")]
+bpy.types.Material.THREE_materialType = EnumProperty(name = "Material type", description = "Material type", items = THREE_material_types, default = "Lambert")
+
+class OBJECT_PT_hello( bpy.types.Panel ):
+
+    bl_label = "THREE"
+    bl_space_type = "PROPERTIES"
+    bl_region_type = "WINDOW"
+    bl_context = "object"
+
+    def draw(self, context):
+        layout = self.layout
+        obj = context.object
+
+        row = layout.row()
+        row.label(text="Selected object: " + obj.name )
+
+        row = layout.row()
+        row.prop( obj, "THREE_exportGeometry", text="Export geometry" )
+
+        row = layout.row()
+        row.prop( obj, "THREE_castsShadow", text="Casts shadow" )
+
+        row = layout.row()
+        row.prop( obj, "THREE_meshCollider", text="Mesh collider" )
+
+        row = layout.row()
+        row.prop( obj, "THREE_triggerType", text="Trigger type" )
+
+
+class MATERIAL_PT_hello( bpy.types.Panel ):
+
+    bl_label = "THREE"
+    bl_space_type = "PROPERTIES"
+    bl_region_type = "WINDOW"
+    bl_context = "material"
+
+    def draw(self, context):
+        layout = self.layout
+        mat = context.material
+
+        row = layout.row()
+        row.label(text="Selected material: " + mat.name )
+
+        row = layout.row()
+        row.prop( mat, "THREE_materialType", text="Material type" )
+
+        row = layout.row()
+        row.prop( mat, "THREE_useVertexColors", text="Use vertex colors" )
+
+
+# ################################################################
+# Importer
+# ################################################################
+
+class ImportTHREEJS(bpy.types.Operator, ImportHelper):
+    '''Load a Three.js ASCII JSON model'''
+
+    bl_idname = "import.threejs"
+    bl_label = "Import Three.js"
+
+    filename_ext = ".js"
+    filter_glob = StringProperty(default="*.js", options={'HIDDEN'})
+
+    option_flip_yz = BoolProperty(name="Flip YZ", description="Flip YZ", default=True)
+    recalculate_normals = BoolProperty(name="Recalculate normals", description="Recalculate vertex normals", default=True)
+
+    def execute(self, context):
+        import io_mesh_threejs.import_threejs
+        return io_mesh_threejs.import_threejs.load(self, context, **self.properties)
+
+
+    def draw(self, context):
+        layout = self.layout
+
+        row = layout.row()
+        row.prop(self.properties, "option_flip_yz")
+
+        row = layout.row()
+        row.prop(self.properties, "recalculate_normals")
+
+
+# ################################################################
+# Exporter - settings
+# ################################################################
+
+SETTINGS_FILE_EXPORT = "threejs_settings_export.js"
+
+import os
+import json
+
+def file_exists(filename):
+    """Return true if file exists and accessible for reading.
+
+    Should be safer than just testing for existence due to links and
+    permissions magic on Unix filesystems.
+
+    @rtype: boolean
+    """
+
+    try:
+        f = open(filename, 'r')
+        f.close()
+        return True
+    except IOError:
+        return False
+
+def get_settings_fullpath():
+    return os.path.join(bpy.app.tempdir, SETTINGS_FILE_EXPORT)
+
+def save_settings_export(properties):
+
+    settings = {
+    "option_export_scene" : properties.option_export_scene,
+    "option_embed_meshes" : properties.option_embed_meshes,
+    "option_url_base_html" : properties.option_url_base_html,
+    "option_copy_textures" : properties.option_copy_textures,
+
+    "option_lights" : properties.option_lights,
+    "option_cameras" : properties.option_cameras,
+
+    "option_flip_yz"      : properties.option_flip_yz,
+
+    "option_materials"       : properties.option_materials,
+    "option_normals"         : properties.option_normals,
+    "option_colors"          : properties.option_colors,
+    "option_uv_coords"       : properties.option_uv_coords,
+    "option_edges"           : properties.option_edges,
+    "option_faces"           : properties.option_faces,
+    "option_vertices"        : properties.option_vertices,
+
+    "option_vertices_truncate" : properties.option_vertices_truncate,
+    "option_scale"        : properties.option_scale,
+
+    "align_model"         : properties.align_model
+    }
+
+    fname = get_settings_fullpath()
+    f = open(fname, "w")
+    json.dump(settings, f)
+
+def restore_settings_export(properties):
+
+    settings = {}
+
+    fname = get_settings_fullpath()
+    if file_exists(fname):
+        f = open(fname, "r")
+        settings = json.load(f)
+
+    properties.option_vertices = settings.get("option_vertices", True)
+    properties.option_vertices_truncate = settings.get("option_vertices_truncate", False)
+    properties.option_faces = settings.get("option_faces", True)
+    properties.option_normals = settings.get("option_normals", True)
+    properties.option_edges = settings.get("option_edges", False)
+
+    properties.option_colors = settings.get("option_colors", True)
+    properties.option_uv_coords = settings.get("option_uv_coords", True)
+    properties.option_materials = settings.get("option_materials", True)
+
+    properties.align_model = settings.get("align_model", "None")
+
+    properties.option_scale = settings.get("option_scale", 1.0)
+    properties.option_flip_yz = settings.get("option_flip_yz", True)
+
+    properties.option_export_scene = settings.get("option_export_scene", False)
+    properties.option_embed_meshes = settings.get("option_embed_meshes", True)
+    properties.option_url_base_html = settings.get("option_url_base_html", False)
+    properties.option_copy_textures = settings.get("option_copy_textures", False)
+
+    properties.option_lights = settings.get("option_lights", False)
+    properties.option_cameras = settings.get("option_cameras", False)
+
+# ################################################################
+# Exporter
+# ################################################################
+
+class ExportTHREEJS(bpy.types.Operator, ExportHelper):
+    '''Export selected object / scene for Three.js (ASCII JSON format).'''
+
+    bl_idname = "export.threejs"
+    bl_label = "Export Three.js"
+
+    filename_ext = ".js"
+
+    option_vertices = BoolProperty(name = "Vertices", description = "Export vertices", default = True)
+    option_vertices_deltas = BoolProperty(name = "Deltas", description = "Delta vertices", default = False)
+    option_vertices_truncate = BoolProperty(name = "Truncate", description = "Truncate vertices", default = False)
+
+    option_faces = BoolProperty(name = "Faces", description = "Export faces", default = True)
+    option_faces_deltas = BoolProperty(name = "Deltas", description = "Delta faces", default = False)
+
+    option_normals = BoolProperty(name = "Normals", description = "Export normals", default = True)
+    option_edges = BoolProperty(name = "Edges", description = "Export edges", default = False)
+
+    option_colors = BoolProperty(name = "Colors", description = "Export vertex colors", default = True)
+    option_uv_coords = BoolProperty(name = "UVs", description = "Export texture coordinates", default = True)
+    option_materials = BoolProperty(name = "Materials", description = "Export materials", default = True)
+
+    align_types = [("None","None","None"), ("Center","Center","Center"), ("Bottom","Bottom","Bottom"), ("Top","Top","Top")]
+    align_model = EnumProperty(name = "Align model", description = "Align model", items = align_types, default = "None")
+
+    option_scale = FloatProperty(name = "Scale", description = "Scale vertices", min = 0.01, max = 1000.0, soft_min = 0.01, soft_max = 1000.0, default = 1.0)
+    option_flip_yz = BoolProperty(name = "Flip YZ", description = "Flip YZ", default = True)
+
+    option_export_scene = BoolProperty(name = "Scene", description = "Export scene", default = False)
+    option_embed_meshes = BoolProperty(name = "Embed", description = "Embed meshes", default = True)
+    option_copy_textures = BoolProperty(name = "Copy textures", description = "Copy textures", default = False)
+    option_url_base_html = BoolProperty(name = "HTML as url base", description = "Use HTML as url base ", default = False)
+
+    option_lights = BoolProperty(name = "Lights", description = "Export default scene lights", default = False)
+    option_cameras = BoolProperty(name = "Cameras", description = "Export default scene cameras", default = False)
+
+    def invoke(self, context, event):
+        restore_settings_export(self.properties)
+        return ExportHelper.invoke(self, context, event)
+
+    @classmethod
+    def poll(cls, context):
+        return context.active_object != None
+
+    def execute(self, context):
+        print("Selected: " + context.active_object.name)
+
+        if not self.properties.filepath:
+            raise Exception("filename not set")
+
+        save_settings_export(self.properties)
+
+        filepath = self.filepath
+
+        import io_mesh_threejs.export_threejs
+        return io_mesh_threejs.export_threejs.save(self, context, **self.properties)
+
+    def draw(self, context):
+        layout = self.layout
+
+        row = layout.row()
+        row.label(text="Geometry:")
+
+        row = layout.row()
+        row.prop(self.properties, "option_vertices")
+        # row = layout.row()
+        # row.enabled = self.properties.option_vertices
+        # row.prop(self.properties, "option_vertices_deltas")
+        row.prop(self.properties, "option_vertices_truncate")
+        layout.separator()
+
+        row = layout.row()
+        row.prop(self.properties, "option_faces")
+        row = layout.row()
+        row.enabled = self.properties.option_faces
+        # row.prop(self.properties, "option_faces_deltas")
+        layout.separator()
+
+        row = layout.row()
+        row.prop(self.properties, "option_normals")
+        layout.separator()
+
+        row = layout.row()
+        row.prop(self.properties, "option_edges")
+        layout.separator()
+
+        row = layout.row()
+        row.label(text="Materials:")
+
+        row = layout.row()
+        row.prop(self.properties, "option_uv_coords")
+        row.prop(self.properties, "option_colors")
+        row = layout.row()
+        row.prop(self.properties, "option_materials")
+        layout.separator()
+
+        row = layout.row()
+        row.label(text="Settings:")
+
+        row = layout.row()
+        row.prop(self.properties, "align_model")
+        row = layout.row()
+        row.prop(self.properties, "option_flip_yz")
+        row.prop(self.properties, "option_scale")
+        layout.separator()
+
+        row = layout.row()
+        row.label(text="Beta:")
+
+        row = layout.row()
+        row.prop(self.properties, "option_export_scene")
+
+        row = layout.row()
+        row.prop(self.properties, "option_lights")
+        row.prop(self.properties, "option_cameras")
+
+        row = layout.row()
+        row.prop(self.properties, "option_embed_meshes")
+        row.prop(self.properties, "option_copy_textures")
+
+        row = layout.row()
+        row.prop(self.properties, "option_url_base_html")
+
+        layout.separator()
+
+
+# ################################################################
+# Common
+# ################################################################
+
+def menu_func_export(self, context):
+    default_path = bpy.data.filepath.replace(".blend", ".js")
+    self.layout.operator(ExportTHREEJS.bl_idname, text="Three.js (.js)").filepath = default_path
+
+def menu_func_import(self, context):
+    self.layout.operator(ImportTHREEJS.bl_idname, text="Three.js (.js)")
+
+def register():
+    bpy.utils.register_module(__name__)
+    bpy.types.INFO_MT_file_export.append(menu_func_export)
+    bpy.types.INFO_MT_file_import.append(menu_func_import)
+
+def unregister():
+    bpy.utils.unregister_module(__name__)
+    bpy.types.INFO_MT_file_export.remove(menu_func_export)
+    bpy.types.INFO_MT_file_import.remove(menu_func_import)
+
+if __name__ == "__main__":
+    register()

+ 1781 - 0
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -0,0 +1,1781 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+"""
+Blender exporter for Three.js (ASCII JSON format).
+
+TODO
+    - binary format
+"""
+
+import bpy
+import mathutils
+
+import shutil
+import os
+import os.path
+import math
+import operator
+import random
+
+# #####################################################
+# Configuration
+# #####################################################
+
+DEFAULTS = {
+"bgcolor" : [0, 0, 0],
+"bgalpha" : 1.0,
+
+"position" : [0, 0, 0],
+"rotation" : [-math.pi/2, 0, 0],
+"scale"    : [1, 1, 1],
+
+"camera"  :
+    {
+        "name" : "default_camera",
+        "type" : "perspective",
+        "near" : 1,
+        "far"  : 10000,
+        "fov"  : 60,
+        "aspect": 1.333,
+        "position" : [0, 0, 10],
+        "target"   : [0, 0, 0]
+    },
+
+"light" :
+ {
+    "name"       : "default_light",
+    "type"       : "directional",
+    "direction"  : [0, 1, 1],
+    "color"      : [1, 1, 1],
+    "intensity"  : 0.8
+ }
+}
+
+# default colors for debugging (each material gets one distinct color):
+# white, red, green, blue, yellow, cyan, magenta
+COLORS = [0xeeeeee, 0xee0000, 0x00ee00, 0x0000ee, 0xeeee00, 0x00eeee, 0xee00ee]
+
+
+# #####################################################
+# Templates - scene
+# #####################################################
+
+TEMPLATE_SCENE_ASCII = """\
+/* Converted from: %(fname)s
+ *
+ * File generated with Blender 2.58 Exporter
+ * https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender/
+ *
+ * objects:    %(nobjects)s
+ * geometries: %(ngeometries)s
+ * materials:  %(nmaterials)s
+ * textures:   %(ntextures)s
+ */
+
+var scene = {
+
+"type" : "scene",
+"urlBaseType" : %(basetype)s,
+
+%(sections)s
+
+"transform" :
+{
+    "position"  : %(position)s,
+    "rotation"  : %(rotation)s,
+    "scale"     : %(scale)s
+},
+
+"defaults" :
+{
+    "bgcolor" : %(bgcolor)s,
+    "bgalpha" : %(bgalpha)f,
+    "camera"  : %(defcamera)s
+}
+
+}
+
+postMessage( scene );
+close();
+"""
+
+TEMPLATE_SECTION = """
+"%s" :
+{
+%s
+},
+"""
+
+TEMPLATE_OBJECT = """\
+    %(object_id)s : {
+        "geometry"  : %(geometry_id)s,
+        "groups"    : [ %(group_id)s ],
+        "materials" : [ %(material_id)s ],
+        "position"  : %(position)s,
+        "rotation"  : %(rotation)s,
+        "quaternion": %(quaternion)s,
+        "scale"     : %(scale)s,
+        "visible"       : %(visible)s,
+        "castsShadow"   : %(castsShadow)s,
+        "meshCollider"  : %(meshCollider)s,
+        "trigger"       : %(trigger)s
+    }"""
+
+TEMPLATE_EMPTY = """\
+    %(object_id)s : {
+        "groups"    : [ %(group_id)s ],
+        "position"  : %(position)s,
+        "rotation"  : %(rotation)s,
+        "quaternion": %(quaternion)s,
+        "scale"     : %(scale)s,
+        "trigger"   : %(trigger)s
+    }"""
+
+TEMPLATE_GEOMETRY_LINK = """\
+    %(geometry_id)s : {
+        "type" : "ascii_mesh",
+        "url"  : %(model_file)s
+    }"""
+
+TEMPLATE_GEOMETRY_EMBED = """\
+    %(geometry_id)s : {
+        "type" : "embedded_mesh",
+        "id"  : %(embed_id)s
+    }"""
+
+TEMPLATE_TEXTURE = """\
+    %(texture_id)s : {
+        "url": %(texture_file)s%(extras)s
+    }"""
+
+TEMPLATE_MATERIAL_SCENE = """\
+    %(material_id)s : {
+        "type": %(type)s,
+        "parameters": { %(parameters)s }
+    }"""
+
+TEMPLATE_CAMERA_PERSPECTIVE = """\
+    %(camera_id)s : {
+        "type"  : "perspective",
+        "fov"   : %(fov)f,
+        "aspect": %(aspect)f,
+        "near"  : %(near)f,
+        "far"   : %(far)f,
+        "position": %(position)s,
+        "target"  : %(target)s
+    }"""
+
+TEMPLATE_CAMERA_ORTHO = """\
+    %(camera_id)s: {
+        "type"  : "ortho",
+        "left"  : %(left)f,
+        "right" : %(right)f,
+        "top"   : %(top)f,
+        "bottom": %(bottom)f,
+        "near"  : %(near)f,
+        "far"   : %(far)f,
+        "position": %(position)s,
+        "target"  : %(target)s
+    }"""
+
+TEMPLATE_LIGHT_DIRECTIONAL = """\
+    %(light_id)s: {
+        "type"		 : "directional",
+        "direction"	 : %(direction)s,
+        "color" 	 : %(color)d,
+        "intensity"	 : %(intensity).2f
+    }"""
+
+TEMPLATE_LIGHT_POINT = """\
+    %(light_id)s: {
+        "type"	     : "point",
+        "position"   : %(position)s,
+        "color"      : %(color)d,
+        "intensity"	 : %(intensity).3f
+    }"""
+
+TEMPLATE_VEC4 = '[ %f, %f, %f, %f ]'
+TEMPLATE_VEC3 = '[ %f, %f, %f ]'
+TEMPLATE_VEC2 = '[ %f, %f ]'
+TEMPLATE_STRING = '"%s"'
+TEMPLATE_HEX = "0x%06x"
+
+# #####################################################
+# Templates - model
+# #####################################################
+
+TEMPLATE_FILE_ASCII = """\
+/*
+ * File generated with Blender 2.58 Exporter
+ * https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender/
+ *
+ * vertices: %(nvertex)d
+ * faces: %(nface)d
+ * normals: %(nnormal)d
+ * uvs: %(nuv)d
+ * colors: %(ncolor)d
+ * materials: %(nmaterial)d
+ * edges: %(nedges)d
+ *
+ */
+
+var model = {
+
+%(model)s
+
+};
+
+postMessage( model );
+close();
+"""
+
+TEMPLATE_MODEL_ASCII = """\
+    "version" : 2,
+
+    "scale" : %(scale)f,
+
+    "materials": [%(materials)s],
+
+    "vertices": [%(vertices)s],
+
+    "morphTargets": [],
+
+    "normals": [%(normals)s],
+
+    "colors": [%(colors)s],
+
+    "uvs": [[%(uvs)s]],
+
+    "faces": [%(faces)s],
+
+    "edges" : [%(edges)s]
+"""
+
+TEMPLATE_VERTEX = "%f,%f,%f"
+TEMPLATE_VERTEX_TRUNCATE = "%d,%d,%d"
+
+TEMPLATE_N = "%f,%f,%f"
+TEMPLATE_UV = "%f,%f"
+#TEMPLATE_C = "0x%06x"
+TEMPLATE_C = "%d"
+TEMPLATE_EDGE = "%d,%d"
+
+# #####################################################
+# Utils
+# #####################################################
+
+def veckey3(x,y,z):
+    return round(x, 6), round(y, 6), round(z, 6)
+
+def veckey3d(v):
+    return veckey3(v.x, v.y, v.z)
+
+def veckey2d(v):
+    return round(v[0], 6), round(v[1], 6)
+
+def get_normal_indices(v, normals, mesh):
+    n = []
+    mv = mesh.vertices
+
+    for i in v:
+        normal = mv[i].normal
+        key = veckey3d(normal)
+
+        n.append( normals[key] )
+
+    return n
+
+def get_uv_indices(face_index, uvs, mesh):
+    uv = []
+    uv_layer = mesh.uv_textures.active.data
+    for i in uv_layer[face_index].uv:
+        uv.append( uvs[veckey2d(i)] )
+    return uv
+
+def get_color_indices(face_index, colors, mesh):
+    c = []
+    color_layer = mesh.vertex_colors.active.data
+    face_colors = color_layer[face_index]
+    face_colors = face_colors.color1, face_colors.color2, face_colors.color3, face_colors.color4
+    for i in face_colors:
+        c.append( colors[hexcolor(i)] )
+    return c
+
+def rgb2int(rgb):
+    color = (int(rgb[0]*255) << 16) + (int(rgb[1]*255) << 8) + int(rgb[2]*255);
+    return color
+
+# #####################################################
+# Utils - files
+# #####################################################
+
+def write_file(fname, content):
+    out = open(fname, "w")
+    out.write(content)
+    out.close()
+
+def ensure_folder_exist(foldername):
+    """Create folder (with whole path) if it doesn't exist yet."""
+
+    if not os.access(foldername, os.R_OK|os.W_OK|os.X_OK):
+        os.makedirs(foldername)
+
+def ensure_extension(filepath, extension):
+    if not filepath.lower().endswith(extension):
+        filepath += extension
+    return filepath
+
+def generate_mesh_filename(meshname, filepath):
+    normpath = os.path.normpath(filepath)
+    path, ext = os.path.splitext(normpath)
+    return "%s.%s%s" % (path, meshname, ext)
+
+
+# #####################################################
+# Utils - alignment
+# #####################################################
+
+def bbox(vertices):
+    """Compute bounding box of vertex array.
+    """
+
+    if len(vertices)>0:
+        minx = maxx = vertices[0].co.x
+        miny = maxy = vertices[0].co.y
+        minz = maxz = vertices[0].co.z
+
+        for v in vertices[1:]:
+            if v.co.x < minx:
+                minx = v.co.x
+            elif v.co.x > maxx:
+                maxx = v.co.x
+
+            if v.co.y < miny:
+                miny = v.co.y
+            elif v.co.y > maxy:
+                maxy = v.co.y
+
+            if v.co.z < minz:
+                minz = v.co.z
+            elif v.co.z > maxz:
+                maxz = v.co.z
+
+        return { 'x':[minx,maxx], 'y':[miny,maxy], 'z':[minz,maxz] }
+
+    else:
+        return { 'x':[0,0], 'y':[0,0], 'z':[0,0] }
+
+def translate(vertices, t):
+    """Translate array of vertices by vector t.
+    """
+
+    for i in range(len(vertices)):
+        vertices[i].co.x += t[0]
+        vertices[i].co.y += t[1]
+        vertices[i].co.z += t[2]
+
+def center(vertices):
+    """Center model (middle of bounding box).
+    """
+
+    bb = bbox(vertices)
+
+    cx = bb['x'][0] + (bb['x'][1] - bb['x'][0])/2.0
+    cy = bb['y'][0] + (bb['y'][1] - bb['y'][0])/2.0
+    cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
+
+    translate(vertices, [-cx,-cy,-cz])
+
+def top(vertices):
+    """Align top of the model with the floor (Y-axis) and center it around X and Z.
+    """
+
+    bb = bbox(vertices)
+
+    cx = bb['x'][0] + (bb['x'][1] - bb['x'][0])/2.0
+    cy = bb['y'][1]
+    cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
+
+    translate(vertices, [-cx,-cy,-cz])
+
+def bottom(vertices):
+    """Align bottom of the model with the floor (Y-axis) and center it around X and Z.
+    """
+
+    bb = bbox(vertices)
+
+    cx = bb['x'][0] + (bb['x'][1] - bb['x'][0])/2.0
+    cy = bb['y'][0]
+    cz = bb['z'][0] + (bb['z'][1] - bb['z'][0])/2.0
+
+    translate(vertices, [-cx,-cy,-cz])
+
+# #####################################################
+# Elements rendering
+# #####################################################
+
+def hexcolor(c):
+    return ( int(c[0] * 255) << 16  ) + ( int(c[1] * 255) << 8 ) + int(c[2] * 255)
+
+def generate_vertices(vertices, option_vertices_truncate, option_vertices):
+    if not option_vertices:
+        return ""
+
+    return ",".join(generate_vertex(v, option_vertices_truncate) for v in vertices)
+
+def generate_vertex(v, option_vertices_truncate):
+    if not option_vertices_truncate:
+        return TEMPLATE_VERTEX % (v.co.x, v.co.y, v.co.z)
+    else:
+        return TEMPLATE_VERTEX_TRUNCATE % (v.co.x, v.co.y, v.co.z)
+
+def generate_normal(n):
+    return TEMPLATE_N % (n[0], n[1], n[2])
+
+def generate_vertex_color(c):
+    return TEMPLATE_C % c
+
+def generate_uv(uv):
+    return TEMPLATE_UV % (uv[0], 1.0 - uv[1])
+
+def generate_edge(e):
+    return TEMPLATE_EDGE % (e.vertices[0], e.vertices[1])
+
+# #####################################################
+# Model exporter - faces
+# #####################################################
+
+def setBit(value, position, on):
+    if on:
+        mask = 1 << position
+        return (value | mask)
+    else:
+        mask = ~(1 << position)
+        return (value & mask)
+
+def generate_faces(normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz, option_faces):
+    if not option_faces:
+        return ""
+
+    return ",".join(generate_face(f, i, normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz) for i, f in enumerate(mesh.faces))
+
+def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz):
+    isTriangle = ( len(f.vertices) == 3 )
+
+    if isTriangle:
+        nVertices = 3
+    else:
+        nVertices = 4
+
+    hasMaterial = option_materials
+
+    hasFaceUvs = False # not supported in Blender
+    hasFaceVertexUvs = option_uv_coords
+
+    hasFaceNormals = False # don't export any face normals (as they are computed in engine)
+    hasFaceVertexNormals = option_normals
+
+    hasFaceColors = False       # not supported in Blender
+    hasFaceVertexColors = option_colors
+
+    faceType = 0
+    faceType = setBit(faceType, 0, not isTriangle)
+    faceType = setBit(faceType, 1, hasMaterial)
+    faceType = setBit(faceType, 2, hasFaceUvs)
+    faceType = setBit(faceType, 3, hasFaceVertexUvs)
+    faceType = setBit(faceType, 4, hasFaceNormals)
+    faceType = setBit(faceType, 5, hasFaceVertexNormals)
+    faceType = setBit(faceType, 6, hasFaceColors)
+    faceType = setBit(faceType, 7, hasFaceVertexColors)
+
+    faceData = []
+
+    # order is important, must match order in JSONLoader
+
+    # face type
+    # vertex indices
+    # material index
+    # face uvs index
+    # face vertex uvs indices
+    # face color index
+    # face vertex colors indices
+
+    faceData.append(faceType)
+
+    # must clamp in case on polygons bigger than quads
+
+    for i in range(nVertices):
+        index = f.vertices[i]
+        faceData.append(index)
+
+    if hasMaterial:
+        faceData.append( f.material_index )
+
+    if hasFaceVertexUvs:
+        uv = get_uv_indices(faceIndex, uvs, mesh)
+        for i in range(nVertices):
+            index = uv[i]
+            faceData.append(index)
+
+    if hasFaceVertexNormals:
+        n = get_normal_indices(f.vertices, normals, mesh)
+        for i in range(nVertices):
+            index = n[i]
+            faceData.append(index)
+
+    if hasFaceVertexColors:
+        c = get_color_indices(faceIndex, colors, mesh)
+        for i in range(nVertices):
+            index = c[i]
+            faceData.append(index)
+
+    return ",".join( map(str, faceData) )
+
+
+# #####################################################
+# Model exporter - normals
+# #####################################################
+
+def extract_vertex_normals(mesh, option_normals):
+    if not option_normals:
+        return {}, 0
+
+    count = 0
+    normals = {}
+
+    for f in mesh.faces:
+        for v in f.vertices:
+
+            normal = mesh.vertices[v].normal
+            key = veckey3d(normal)
+
+            if key not in normals:
+                normals[key] = count
+                count += 1
+
+    return normals, count
+
+def generate_normals(normals, option_normals):
+    if not option_normals:
+        return ""
+
+    chunks = []
+    for key, index in sorted(normals.items(), key = operator.itemgetter(1)):
+        chunks.append(key)
+
+    return ",".join(generate_normal(n) for n in chunks)
+
+# #####################################################
+# Model exporter - vertex colors
+# #####################################################
+
+def extract_vertex_colors(mesh, option_colors):
+
+    if not option_colors:
+        return {}, 0
+
+    count = 0
+    colors = {}
+
+    color_layer = mesh.vertex_colors.active.data
+
+    for face_index, face in enumerate(mesh.faces):
+
+        face_colors = color_layer[face_index]
+        face_colors = face_colors.color1, face_colors.color2, face_colors.color3, face_colors.color4
+
+        for c in face_colors:
+            key = hexcolor(c)
+            if key not in colors:
+                colors[key] = count
+                count += 1
+
+    return colors, count
+
+def generate_vertex_colors(colors, option_colors):
+    if not option_colors:
+        return ""
+
+    chunks = []
+    for key, index in sorted(colors.items(), key=operator.itemgetter(1)):
+        chunks.append(key)
+
+    return ",".join(generate_vertex_color(c) for c in chunks)
+
+# #####################################################
+# Model exporter - UVs
+# #####################################################
+
+def extract_uvs(mesh, option_uv_coords):
+
+    if not option_uv_coords:
+        return {}, 0
+
+    count = 0
+    uvs = {}
+
+    uv_layer = mesh.uv_textures.active.data
+
+    for face_index, face in enumerate(mesh.faces):
+
+        for uv_index, uv in enumerate(uv_layer[face_index].uv):
+
+            key = veckey2d(uv)
+            if key not in uvs:
+                uvs[key] = count
+                count += 1
+
+    return uvs, count
+
+def generate_uvs(uvs, option_uv_coords):
+    if not option_uv_coords:
+        return ""
+
+    chunks = []
+    for key, index in sorted(uvs.items(), key=operator.itemgetter(1)):
+        chunks.append(key)
+
+    return ",".join(generate_uv(n) for n in chunks)
+
+# #####################################################
+# Model exporter - materials
+# #####################################################
+
+def generate_color(i):
+    """Generate hex color corresponding to integer.
+
+    Colors should have well defined ordering.
+    First N colors are hardcoded, then colors are random
+    (must seed random number  generator with deterministic value
+    before getting colors).
+    """
+
+    if i < len(COLORS):
+        #return "0x%06x" % COLORS[i]
+        return COLORS[i]
+    else:
+        #return "0x%06x" % int(0xffffff * random.random())
+        return int(0xffffff * random.random())
+
+def generate_mtl(materials):
+    """Generate dummy materials.
+    """
+
+    mtl = {}
+    for m in materials:
+        index = materials[m]
+        mtl[m] = {
+            "DbgName": m,
+            "DbgIndex": index,
+            "DbgColor": generate_color(index),
+            "vertexColors" : False
+        }
+    return mtl
+
+def value2string(v):
+    if type(v) == str and v[0:2] != "0x":
+        return '"%s"' % v
+    elif type(v) == bool:
+        return str(v).lower()
+    elif type(v) == list:
+        return "[%s]" % (", ".join(value2string(x) for x in v))
+    return str(v)
+
+def generate_materials(mtl, materials, draw_type):
+    """Generate JS array of materials objects
+    """
+
+    mtl_array = []
+    for m in mtl:
+        index = materials[m]
+
+        # add debug information
+        #  materials should be sorted according to how
+        #  they appeared in OBJ file (for the first time)
+        #  this index is identifier used in face definitions
+        mtl[m]['DbgName'] = m
+        mtl[m]['DbgIndex'] = index
+        mtl[m]['DbgColor'] = generate_color(index)
+
+        if draw_type in [ "BOUNDS", "WIRE" ]:
+            mtl[m]['wireframe'] = True
+            mtl[m]['DbgColor'] = 0xff0000
+
+        mtl_raw = ",\n".join(['\t"%s" : %s' % (n, value2string(v)) for n,v in sorted(mtl[m].items())])
+        mtl_string = "\t{\n%s\n\t}" % mtl_raw
+        mtl_array.append([index, mtl_string])
+
+    return ",\n\n".join([m for i,m in sorted(mtl_array)]), len(mtl_array)
+
+def extract_materials(mesh, scene, option_colors, option_copy_textures, filepath):
+    world = scene.world
+
+    materials = {}
+    for m in mesh.materials:
+        if m:
+            materials[m.name] = {}
+            material = materials[m.name]
+
+            material['colorDiffuse'] = [m.diffuse_intensity * m.diffuse_color[0],
+                                        m.diffuse_intensity * m.diffuse_color[1],
+                                        m.diffuse_intensity * m.diffuse_color[2]]
+
+            material['colorSpecular'] = [m.specular_intensity * m.specular_color[0],
+                                         m.specular_intensity * m.specular_color[1],
+                                         m.specular_intensity * m.specular_color[2]]
+
+            world_ambient_color = [0, 0, 0]
+            if world:
+                world_ambient_color = world.ambient_color
+
+            material['colorAmbient'] = [m.ambient * world_ambient_color[0],
+                                        m.ambient * world_ambient_color[1],
+                                        m.ambient * world_ambient_color[2]]
+
+            material['transparency'] = m.alpha
+
+            # not sure about mapping values to Blinn-Phong shader
+            # Blender uses INT from [1, 511] with default 0
+            # http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.types.Material.html#bpy.types.Material.specular_hardness
+
+            material["specularCoef"] = m.specular_hardness
+
+            textures = guess_material_textures(m)
+
+            handle_texture('diffuse', textures, material, filepath, option_copy_textures)
+            handle_texture('light', textures, material, filepath, option_copy_textures)
+            handle_texture('normal', textures, material, filepath, option_copy_textures)
+
+            material["vertexColors"] = m.THREE_useVertexColors and option_colors
+
+            # can't really use this reliably to tell apart Phong from Lambert
+            # as Blender defaults to non-zero specular color
+            #if m.specular_intensity > 0.0 and (m.specular_color[0] > 0 or m.specular_color[1] > 0 or m.specular_color[2] > 0):
+            #    material['shading'] = "Phong"
+            #else:
+            #    material['shading'] = "Lambert"
+
+            material['shading'] = m.THREE_materialType
+
+    return materials
+
+def generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath):
+
+    random.seed(42) # to get well defined color order for debug materials
+
+    materials = {}
+    if mesh.materials:
+        for i, m in enumerate(mesh.materials):
+            if m:
+                materials[m.name] = i
+            else:
+                materials["undefined_dummy_%0d" % i] = i
+
+
+    if not materials:
+        materials = { 'default':0 }
+
+    # default dummy materials
+
+    mtl = generate_mtl(materials)
+
+    # extract real materials from the mesh
+
+    mtl.update(extract_materials(mesh, scene, option_colors, option_copy_textures, filepath))
+
+    return generate_materials(mtl, materials, draw_type)
+
+def handle_texture(id, textures, material, filepath, option_copy_textures):
+
+    if textures[id]:
+        texName     = 'map%s'       % id.capitalize()
+        repeatName  = 'map%sRepeat' % id.capitalize()
+        wrapName    = 'map%sWrap'   % id.capitalize()
+
+        slot = textures[id]['slot']
+        texture = textures[id]['texture']
+        image = texture.image
+        fname = extract_texture_filename(image)
+        material[texName] = fname
+
+        if option_copy_textures:
+            save_image(image, fname, filepath)
+
+        if texture.repeat_x != 1 or texture.repeat_y != 1:
+            material[repeatName] = [texture.repeat_x, texture.repeat_y]
+
+        if texture.extension == "REPEAT":
+            wrap_x = "repeat"
+            wrap_y = "repeat"
+
+            if texture.use_mirror_x:
+                wrap_x = "mirror"
+            if texture.use_mirror_y:
+                wrap_y = "mirror"
+
+            material[wrapName] = [wrap_x, wrap_y]
+
+        if slot.use_map_normal:
+            if slot.normal_factor != 1.0:
+                material['mapNormalFactor'] = slot.normal_factor
+
+
+# #####################################################
+# ASCII model generator
+# #####################################################
+
+def generate_ascii_model(mesh, scene,
+                         option_vertices,
+                         option_vertices_truncate,
+                         option_faces,
+                         option_normals,
+                         option_edges,
+                         option_uv_coords,
+                         option_materials,
+                         option_colors,
+                         align_model,
+                         flipyz,
+                         option_scale,
+                         draw_type,
+                         option_copy_textures,
+                         filepath):
+
+    vertices = mesh.vertices[:]
+
+    if align_model == 1:
+        center(vertices)
+    elif align_model == 2:
+        bottom(vertices)
+    elif align_model == 3:
+        top(vertices)
+
+    normals, nnormal = extract_vertex_normals(mesh, option_normals)
+    colors, ncolor = extract_vertex_colors(mesh, option_colors)
+    uvs, nuv = extract_uvs(mesh, option_uv_coords)
+
+    materials_string = ""
+    nmaterial = 0
+
+    edges_string = ""
+    nedges = 0
+
+    if option_materials:
+        materials_string, nmaterial = generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath)
+
+    if option_edges:
+        nedges = len(mesh.edges)
+        edges_string  = ",".join(generate_edge(e) for e in mesh.edges)
+
+    model_string = TEMPLATE_MODEL_ASCII % {
+    "scale" : option_scale,
+
+    "uvs"       : generate_uvs(uvs, option_uv_coords),
+    "normals"   : generate_normals(normals, option_normals),
+    "colors"    : generate_vertex_colors(colors, option_colors),
+
+    "materials" : materials_string,
+
+    "vertices" : generate_vertices(vertices, option_vertices_truncate, option_vertices),
+
+    "faces"    : generate_faces(normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz, option_faces),
+
+    "edges"    : edges_string
+    }
+
+    text = TEMPLATE_FILE_ASCII % {
+    "nvertex"   : len(mesh.vertices),
+    "nface"     : len(mesh.faces),
+    "nuv"       : nuv,
+    "nnormal"   : nnormal,
+    "ncolor"    : ncolor,
+    "nmaterial" : nmaterial,
+    "nedges"    : nedges,
+
+    "model"     : model_string
+    }
+
+
+    return text, model_string
+
+
+# #####################################################
+# Model exporter - export single mesh
+# #####################################################
+
+def generate_mesh_string(obj, scene,
+                option_vertices,
+                option_vertices_truncate,
+                option_faces,
+                option_normals,
+                option_edges,
+                option_uv_coords,
+                option_materials,
+                option_colors,
+                align_model,
+                flipyz,
+                option_scale,
+                export_single_model,
+                option_copy_textures,
+                filepath):
+
+    # collapse modifiers into mesh
+
+    mesh = obj.to_mesh(scene, True, 'RENDER')
+
+    if not mesh:
+        raise Exception("Error, could not get mesh data from object [%s]" % obj.name)
+
+    # that's what Blender's native export_obj.py does
+    # to flip YZ
+
+    if export_single_model:
+        X_ROT = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')
+        mesh.transform(X_ROT * obj.matrix_world)
+
+    mesh.calc_normals()
+
+    mesh.transform(mathutils.Matrix.Scale(option_scale, 4))
+
+    faceUV = (len(mesh.uv_textures) > 0)
+    vertexUV = (len(mesh.sticky) > 0)
+    vertexColors = len(mesh.vertex_colors) > 0
+
+    if not vertexColors:
+        option_colors = False
+
+    if (not faceUV) and (not vertexUV):
+        option_uv_coords = False
+
+    if faceUV:
+        active_uv_layer = mesh.uv_textures.active
+        if not active_uv_layer:
+            option_uv_coords = False
+
+    if vertexColors:
+        active_col_layer = mesh.vertex_colors.active
+        if not active_col_layer:
+            option_colors = False
+
+    option_copy_textures_model = False
+    if export_single_model and option_copy_textures:
+        option_copy_textures_model = True
+
+    text, model_string = generate_ascii_model(mesh, scene,
+                                option_vertices,
+                                option_vertices_truncate,
+                                option_faces,
+                                option_normals,
+                                option_edges,
+                                option_uv_coords,
+                                option_materials,
+                                option_colors,
+                                align_model,
+                                flipyz,
+                                option_scale,
+                                obj.draw_type,
+                                option_copy_textures_model,
+                                filepath)
+    # remove temp mesh
+
+    bpy.data.meshes.remove(mesh)
+
+    return text, model_string
+
+def export_mesh(obj, scene, filepath,
+                option_vertices,
+                option_vertices_truncate,
+                option_faces,
+                option_normals,
+                option_edges,
+                option_uv_coords,
+                option_materials,
+                option_colors,
+                align_model,
+                flipyz,
+                option_scale,
+                export_single_model,
+                option_copy_textures):
+
+    """Export single mesh"""
+
+    text, model_string = generate_mesh_string(obj, scene,
+                option_vertices,
+                option_vertices_truncate,
+                option_faces,
+                option_normals,
+                option_edges,
+                option_uv_coords,
+                option_materials,
+                option_colors,
+                align_model,
+                flipyz,
+                option_scale,
+                export_single_model,
+                option_copy_textures,
+                filepath)
+
+    write_file(filepath, text)
+
+    print("writing", filepath, "done")
+
+
+# #####################################################
+# Scene exporter - render elements
+# #####################################################
+
+def generate_vec4(vec):
+    return TEMPLATE_VEC4 % (vec[0], vec[1], vec[2], vec[3])
+
+def generate_vec3(vec):
+    return TEMPLATE_VEC3 % (vec[0], vec[1], vec[2])
+
+def generate_vec2(vec):
+    return TEMPLATE_VEC2 % (vec[0], vec[1])
+
+def generate_hex(number):
+    return TEMPLATE_HEX % number
+
+def generate_string(s):
+    return TEMPLATE_STRING % s
+
+def generate_string_list(src_list):
+    return ", ".join(generate_string(item) for item in src_list)
+
+def generate_section(label, content):
+    return TEMPLATE_SECTION % (label, content)
+
+def get_mesh_filename(mesh):
+    object_id = mesh["data"]["name"]
+    filename = "%s.js" % sanitize(object_id)
+    return filename
+
+def generate_material_id_list(materials):
+    chunks = []
+    for material in materials:
+        chunks.append(material.name)
+
+    return chunks
+
+def generate_group_id_list(obj):
+    chunks = []
+
+    for group in bpy.data.groups:
+        if obj.name in group.objects:
+            chunks.append(group.name)
+
+    return chunks
+
+def generate_bool_property(property):
+    if property:
+        return "true"
+    return "false"
+
+# #####################################################
+# Scene exporter - objects
+# #####################################################
+
+def generate_objects(data):
+    chunks = []
+
+    for obj in data["objects"]:
+
+        if obj.type == "MESH" and obj.THREE_exportGeometry:
+            object_id = obj.name
+
+            if len(obj.modifiers) > 0:
+                geo_name = obj.name
+            else:
+                geo_name = obj.data.name
+
+            geometry_id = "geo_%s" % geo_name
+
+            material_ids = generate_material_id_list(obj.material_slots)
+            group_ids = generate_group_id_list(obj)
+
+            position, quaternion, scale = obj.matrix_world.decompose()
+            rotation = quaternion.to_euler("XYZ")
+
+            material_string = ""
+            if len(material_ids) > 0:
+                material_string = generate_string_list(material_ids)
+
+            group_string = ""
+            if len(group_ids) > 0:
+                group_string = generate_string_list(group_ids)
+
+            castsShadow = obj.THREE_castsShadow
+            meshCollider = obj.THREE_meshCollider
+            triggerType = obj.THREE_triggerType
+
+            visible = True
+            #if obj.draw_type in ["BOUNDS", "WIRE"] and (meshCollider or castsShadow):
+            if meshCollider or castsShadow:
+                visible = False
+
+            geometry_string = generate_string(geometry_id)
+
+            object_string = TEMPLATE_OBJECT % {
+            "object_id"   : generate_string(object_id),
+            "geometry_id" : geometry_string,
+            "group_id"    : group_string,
+            "material_id" : material_string,
+
+            "position"    : generate_vec3(position),
+            "rotation"    : generate_vec3(rotation),
+            "quaternion"  : generate_vec4(quaternion),
+            "scale"       : generate_vec3(scale),
+
+            "castsShadow"  : generate_bool_property(castsShadow),
+            "meshCollider" : generate_bool_property(meshCollider),
+            "trigger" 	   : generate_string(triggerType),
+            "visible"      : generate_bool_property(visible)
+            }
+            chunks.append(object_string)
+
+        elif obj.type == "EMPTY" or (obj.type == "MESH" and not obj.THREE_exportGeometry):
+
+            object_id = obj.name
+            group_ids = generate_group_id_list(obj)
+
+            position, quaternion, scale = obj.matrix_world.decompose()
+            rotation = quaternion.to_euler("XYZ")
+
+            group_string = ""
+            if len(group_ids) > 0:
+                group_string = generate_string_list(group_ids)
+
+            triggerType = obj.THREE_triggerType
+
+            object_string = TEMPLATE_EMPTY % {
+            "object_id"   : generate_string(object_id),
+            "group_id"    : group_string,
+
+            "position"    : generate_vec3(position),
+            "rotation"    : generate_vec3(rotation),
+            "quaternion"  : generate_vec4(quaternion),
+            "scale"       : generate_vec3(scale),
+
+            "trigger" 	   : generate_string(triggerType),
+            }
+            chunks.append(object_string)
+
+    return ",\n\n".join(chunks), len(chunks)
+
+# #####################################################
+# Scene exporter - geometries
+# #####################################################
+
+def generate_geometries(data):
+    chunks = []
+
+    geo_set = set()
+
+    for obj in data["objects"]:
+        if obj.type == "MESH" and obj.THREE_exportGeometry:
+
+            if len(obj.modifiers) > 0:
+                name = obj.name
+            else:
+                name = obj.data.name
+
+            if name not in geo_set:
+
+                geometry_id = "geo_%s" % name
+
+                if data["embed_meshes"]:
+
+                    embed_id = "emb_%s" % name
+
+                    geometry_string = TEMPLATE_GEOMETRY_EMBED % {
+                    "geometry_id" : generate_string(geometry_id),
+                    "embed_id"  : generate_string(embed_id)
+                    }
+
+                else:
+
+                    model_filename = os.path.basename(generate_mesh_filename(name, data["filepath"]))
+
+                    geometry_string = TEMPLATE_GEOMETRY_LINK % {
+                    "geometry_id" : generate_string(geometry_id),
+                    "model_file"  : generate_string(model_filename)
+                    }
+
+                chunks.append(geometry_string)
+
+                geo_set.add(name)
+
+    return ",\n\n".join(chunks), len(chunks)
+
+# #####################################################
+# Scene exporter - textures
+# #####################################################
+
+def generate_textures_scene(data):
+    chunks = []
+
+    # TODO: extract just textures actually used by some objects in the scene
+
+    for texture in bpy.data.textures:
+
+        if texture.type == 'IMAGE' and texture.image:
+
+            img = texture.image
+
+            texture_id = img.name
+            texture_file = extract_texture_filename(img)
+
+            if data["copy_textures"]:
+                save_image(img, texture_file, data["filepath"])
+
+            extras = ""
+
+            if texture.repeat_x != 1 or texture.repeat_y != 1:
+                extras += ',\n        "repeat": [%f, %f]' % (texture.repeat_x, texture.repeat_y)
+
+            if texture.extension == "REPEAT":
+                wrap_x = "repeat"
+                wrap_y = "repeat"
+
+                if texture.use_mirror_x:
+                    wrap_x = "mirror"
+                if texture.use_mirror_y:
+                    wrap_y = "mirror"
+
+                extras += ',\n        "wrap": ["%s", "%s"]' % (wrap_x, wrap_y)
+
+            texture_string = TEMPLATE_TEXTURE % {
+            "texture_id"   : generate_string(texture_id),
+            "texture_file" : generate_string(texture_file),
+            "extras"       : extras
+            }
+            chunks.append(texture_string)
+
+    return ",\n\n".join(chunks), len(chunks)
+
+def extract_texture_filename(image):
+    fn = bpy.path.abspath(image.filepath)
+    fn = os.path.normpath(fn)
+    fn_strip = os.path.basename(fn)
+    return fn_strip
+
+def save_image(img, name, fpath):
+    dst_dir = os.path.dirname(fpath)
+    dst_path = os.path.join(dst_dir, name)
+
+    ensure_folder_exist(dst_dir)
+
+    if img.packed_file:
+        img.save_render(dst_path)
+
+    else:
+        src_path = bpy.path.abspath(img.filepath)
+        shutil.copy(src_path, dst_dir)
+
+# #####################################################
+# Scene exporter - materials
+# #####################################################
+
+def extract_material_data(m, option_colors):
+    world = bpy.context.scene.world
+
+    material = { 'name': m.name }
+
+    material['colorDiffuse'] = [m.diffuse_intensity * m.diffuse_color[0],
+                                m.diffuse_intensity * m.diffuse_color[1],
+                                m.diffuse_intensity * m.diffuse_color[2]]
+
+    material['colorSpecular'] = [m.specular_intensity * m.specular_color[0],
+                                 m.specular_intensity * m.specular_color[1],
+                                 m.specular_intensity * m.specular_color[2]]
+
+    world_ambient_color = [0, 0, 0]
+    if world:
+        world_ambient_color = world.ambient_color
+
+    material['colorAmbient'] = [m.ambient * world_ambient_color[0],
+                                m.ambient * world_ambient_color[1],
+                                m.ambient * world_ambient_color[2]]
+
+    material['transparency'] = m.alpha
+
+    # not sure about mapping values to Blinn-Phong shader
+    # Blender uses INT from [1,511] with default 0
+    # http://www.blender.org/documentation/blender_python_api_2_54_0/bpy.types.Material.html#bpy.types.Material.specular_hardness
+
+    material["specularCoef"] = m.specular_hardness
+
+    material["vertexColors"] = m.THREE_useVertexColors and option_colors
+
+    material['mapDiffuse'] = ""
+    material['mapLight'] = ""
+    material['mapNormal'] = ""
+    material['mapNormalFactor'] = 1.0
+
+    textures = guess_material_textures(m)
+
+    if textures['diffuse']:
+        material['mapDiffuse'] = textures['diffuse']['texture'].image.name
+
+    if textures['light']:
+        material['mapLight'] = textures['light']['texture'].image.name
+
+    if textures['normal']:
+        material['mapNormal'] = textures['normal']['texture'].image.name
+        if textures['normal']['slot'].use_map_normal:
+            material['mapNormalFactor'] = textures['normal']['slot'].normal_factor
+
+    material['shading'] = m.THREE_materialType
+
+    return material
+
+def guess_material_textures(material):
+    textures = {
+        'diffuse' : None,
+        'light'   : None,
+        'normal'  : None
+    }
+
+    # just take first textures of each, for the moment three.js materials can't handle more
+    # assume diffuse comes before lightmap, normalmap has checked flag
+
+    for i in range(len(material.texture_slots)):
+        slot = material.texture_slots[i]
+        if slot:
+            texture = slot.texture
+            if slot.use and texture.type == 'IMAGE':
+
+                if texture.use_normal_map:
+                    textures['normal'] = { "texture": texture, "slot": slot }
+
+                else:
+                    if not textures['diffuse']:
+                        textures['diffuse'] = { "texture": texture, "slot": slot }
+
+                    else:
+                        textures['light'] = { "texture": texture, "slot": slot }
+
+                if textures['diffuse'] and textures['normal'] and textures['light']:
+                    break
+
+    return textures
+
+def generate_material_string(material):
+    type_map = {
+    "Lambert"   : "MeshLambertMaterial",
+    "Phong"     : "MeshPhongMaterial"
+    }
+
+    material_id = material["name"]
+    shading = material.get("shading", "Lambert")
+    material_type = type_map.get(shading, "MeshBasicMaterial")
+
+    parameters = '"color": %d' % rgb2int(material["colorDiffuse"])
+    parameters += ', "opacity": %.2g' % material["transparency"]
+
+    if shading == "Phong":
+        parameters += ', "ambient": %d' % rgb2int(material["colorAmbient"])
+        parameters += ', "specular": %d' % rgb2int(material["colorSpecular"])
+        parameters += ', "shininess": %.1g' % material["specularCoef"]
+
+    colorMap = material['mapDiffuse']
+    lightMap = material['mapLight']
+    normalMap = material['mapNormal']
+    normalMapFactor = material['mapNormalFactor']
+
+    if colorMap:
+        parameters += ', "map": %s' % generate_string(colorMap)
+    if lightMap:
+        parameters += ', "lightMap": %s' % generate_string(lightMap)
+    if normalMap:
+        parameters += ', "normalMap": %s' % generate_string(normalMap)
+    if normalMapFactor != 1.0:
+        parameters += ', "normalMapFactor": %f' % normalMapFactor
+
+    if material['vertexColors']:
+        parameters += ', "vertexColors": "vertex"'
+
+    material_string = TEMPLATE_MATERIAL_SCENE % {
+    "material_id" : generate_string(material_id),
+    "type"        : generate_string(material_type),
+    "parameters"  : parameters
+    }
+
+    return material_string
+
+def generate_materials_scene(data):
+    chunks = []
+
+    # TODO: extract just materials actually used by some objects in the scene
+
+    for m in bpy.data.materials:
+        material = extract_material_data(m, data["use_colors"])
+        material_string = generate_material_string(material)
+        chunks.append(material_string)
+
+    return ",\n\n".join(chunks), len(chunks)
+
+# #####################################################
+# Scene exporter - cameras
+# #####################################################
+
+def generate_cameras(data):
+    if data["use_cameras"]:
+
+        cams = bpy.data.objects
+        cams = [ob for ob in cams if (ob.type == 'CAMERA' and ob.select)]
+
+        chunks = []
+
+        if not cams:
+            camera = DEFAULTS["camera"]
+
+            if camera["type"] == "perspective":
+
+                camera_string = TEMPLATE_CAMERA_PERSPECTIVE % {
+                "camera_id" : generate_string(camera["name"]),
+                "fov"       : camera["fov"],
+                "aspect"    : camera["aspect"],
+                "near"      : camera["near"],
+                "far"       : camera["far"],
+                "position"  : generate_vec3(camera["position"]),
+                "target"    : generate_vec3(camera["target"])
+                }
+
+            elif camera["type"] == "ortho":
+
+                camera_string = TEMPLATE_CAMERA_ORTHO % {
+                "camera_id" : generate_string(camera["name"]),
+                "left"      : camera["left"],
+                "right"     : camera["right"],
+                "top"       : camera["top"],
+                "bottom"    : camera["bottom"],
+                "near"      : camera["near"],
+                "far"       : camera["far"],
+                "position"  : generate_vec3(camera["position"]),
+                "target"    : generate_vec3(camera["target"])
+                }
+
+            chunks.append(camera_string)
+
+        else:
+
+            for cameraobj in cams:
+                camera = bpy.data.cameras[cameraobj.name]
+
+                # TODO:
+                #   Support more than perspective camera
+                #   Calculate a target/lookat
+                #   Get correct aspect ratio
+                if camera.id_data.type == "PERSP":
+
+                    camera_string = TEMPLATE_CAMERA_PERSPECTIVE % {
+                    "camera_id" : generate_string(camera.name),
+                    "fov"       : (camera.angle / 3.14) * 180.0,
+                    "aspect"    : 1.333,
+                    "near"      : camera.clip_start,
+                    "far"       : camera.clip_end,
+                    "position"  : generate_vec3([cameraobj.location[0], -cameraobj.location[1], cameraobj.location[2]]),
+                    "target"    : generate_vec3([0, 0, 0])
+                    }
+
+                chunks.append(camera_string)
+
+        return ",\n\n".join(chunks)
+
+    return ""
+
+# #####################################################
+# Scene exporter - lights
+# #####################################################
+
+def generate_lights(data):
+
+    if data["use_lights"]:
+
+        lights = data.get("lights", [])
+        if not lights:
+            lights.append(DEFAULTS["light"])
+
+        chunks = []
+        for light in lights:
+
+            if light["type"] == "directional":
+                light_string = TEMPLATE_LIGHT_DIRECTIONAL % {
+                "light_id"      : generate_string(light["name"]),
+                "direction"     : generate_vec3(light["direction"]),
+                #"color"         : generate_hex(rgb2int(light["color"])),
+                "color"         : rgb2int(light["color"]),
+                "intensity"     : light["intensity"]
+                }
+
+            elif light["type"] == "point":
+                light_string = TEMPLATE_LIGHT_POINT % {
+                "light_id"      : generate_string(light["name"]),
+                "position"      : generate_vec3(light["position"]),
+                #"color"         : generate_hex(rgb2int(light["color"])),
+                "color"         : rgb2int(light["color"]),
+                "intensity"     : light["intensity"]
+                }
+
+            chunks.append(light_string)
+
+        return ",\n\n".join(chunks)
+
+    return ""
+
+# #####################################################
+# Scene exporter - embedded meshes
+# #####################################################
+
+def generate_embeds(data):
+
+    if data["embed_meshes"]:
+
+        chunks = []
+
+        for e in data["embeds"]:
+
+            embed = '"emb_%s": {%s}' % (e, data["embeds"][e])
+            chunks.append(embed)
+
+        return ",\n\n".join(chunks)
+
+    return ""
+
+# #####################################################
+# Scene exporter - generate ASCII scene
+# #####################################################
+
+def generate_ascii_scene(data):
+
+    objects, nobjects = generate_objects(data)
+    geometries, ngeometries = generate_geometries(data)
+    textures, ntextures = generate_textures_scene(data)
+    materials, nmaterials = generate_materials_scene(data)
+
+    cameras = generate_cameras(data)
+    lights = generate_lights(data)
+
+    embeds = generate_embeds(data)
+
+    basetype = "relativeTo"
+
+    if data["base_html"]:
+        basetype += "HTML"
+    else:
+        basetype += "Scene"
+
+    sections = [
+    ["objects",    objects],
+    ["geometries", geometries],
+    ["textures",   textures],
+    ["materials",  materials],
+    ["cameras",    cameras],
+    ["lights",     lights],
+    ["embeds",     embeds]
+    ]
+
+    chunks = []
+    for label, content in sections:
+        if content:
+            chunks.append(generate_section(label, content))
+
+    sections_string = "\n".join(chunks)
+
+    default_camera = ""
+    if data["use_cameras"]:
+        cams = [ob for ob in bpy.data.objects if (ob.type == 'CAMERA' and ob.select)]
+        if not cams:
+            default_camera = "default_camera"
+        else:
+            default_camera = cams[0].name
+
+    parameters = {
+    "fname"     : data["source_file"],
+
+    "sections"  : sections_string,
+
+    "bgcolor"   : generate_vec3(DEFAULTS["bgcolor"]),
+    "bgalpha"   : DEFAULTS["bgalpha"],
+    "defcamera" :  generate_string(default_camera),
+
+    "nobjects"      : nobjects,
+    "ngeometries"   : ngeometries,
+    "ntextures"     : ntextures,
+    "basetype"      : generate_string(basetype),
+    "nmaterials"    : nmaterials,
+
+    "position"      : generate_vec3(DEFAULTS["position"]),
+    "rotation"      : generate_vec3(DEFAULTS["rotation"]),
+    "scale"         : generate_vec3(DEFAULTS["scale"])
+    }
+
+    text = TEMPLATE_SCENE_ASCII % parameters
+
+    return text
+
+def export_scene(scene, filepath, flipyz, option_colors, option_lights, option_cameras, option_embed_meshes, embeds, option_url_base_html, option_copy_textures):
+
+    source_file = os.path.basename(bpy.data.filepath)
+
+    scene_text = ""
+    data = {
+    "scene"        : scene,
+    "objects"      : scene.objects,
+    "embeds"       : embeds,
+    "source_file"  : source_file,
+    "filepath"     : filepath,
+    "flipyz"       : flipyz,
+    "use_colors"   : option_colors,
+    "use_lights"   : option_lights,
+    "use_cameras"  : option_cameras,
+    "embed_meshes" : option_embed_meshes,
+    "base_html"    : option_url_base_html,
+    "copy_textures": option_copy_textures
+    }
+    scene_text += generate_ascii_scene(data)
+
+    write_file(filepath, scene_text)
+
+# #####################################################
+# Main
+# #####################################################
+
+def save(operator, context, filepath = "",
+         option_flip_yz = True,
+         option_vertices = True,
+         option_vertices_truncate = False,
+         option_faces = True,
+         option_normals = True,
+         option_edges = False,
+         option_uv_coords = True,
+         option_materials = True,
+         option_colors = True,
+         align_model = 0,
+         option_export_scene = False,
+         option_lights = False,
+         option_cameras = False,
+         option_scale = 1.0,
+         option_embed_meshes = True,
+         option_url_base_html = False,
+         option_copy_textures = False):
+
+    #print("URL TYPE", option_url_base_html)
+
+    filepath = ensure_extension(filepath, '.js')
+
+    scene = context.scene
+
+    if scene.objects.active:
+        bpy.ops.object.mode_set(mode='OBJECT')
+
+    if option_export_scene:
+
+        geo_set = set()
+        embeds = {}
+
+        for obj in scene.objects:
+            if obj.type == "MESH" and obj.THREE_exportGeometry:
+
+                # create extra copy of geometry with applied modifiers
+                # (if they exist)
+
+                if len(obj.modifiers) > 0:
+                    name = obj.name
+
+                # otherwise can share geometry
+
+                else:
+                    name = obj.data.name
+
+                if name not in geo_set:
+
+                    if option_embed_meshes:
+
+                        text, model_string = generate_mesh_string(obj, scene,
+                                                        option_vertices,
+                                                        option_vertices_truncate,
+                                                        option_faces,
+                                                        option_normals,
+                                                        option_edges,
+                                                        option_uv_coords,
+                                                        option_materials,
+                                                        option_colors,
+                                                        False,          # align_model
+                                                        option_flip_yz,
+                                                        option_scale,
+                                                        False,          # export_single_model
+                                                        False,          # option_copy_textures
+                                                        filepath)
+
+                        embeds[name] = model_string
+
+                    else:
+
+                        fname = generate_mesh_filename(name, filepath)
+                        export_mesh(obj, scene,
+                                    fname,
+                                    option_vertices,
+                                    option_vertices_truncate,
+                                    option_faces,
+                                    option_normals,
+                                    option_edges,
+                                    option_uv_coords,
+                                    option_materials,
+                                    option_colors,
+                                    False,          # align_model
+                                    option_flip_yz,
+                                    option_scale,
+                                    False,          # export_single_model
+                                    option_copy_textures)
+
+                    geo_set.add(name)
+
+        export_scene(scene, filepath,
+                     option_flip_yz,
+                     option_colors,
+                     option_lights,
+                     option_cameras,
+                     option_embed_meshes,
+                     embeds,
+                     option_url_base_html,
+                     option_copy_textures)
+
+    else:
+
+        obj = context.object
+        if not obj:
+            raise Exception("Error, Select 1 active object or select 'export scene'")
+
+        export_mesh(obj, scene, filepath,
+                    option_vertices,
+                    option_vertices_truncate,
+                    option_faces,
+                    option_normals,
+                    option_edges,
+                    option_uv_coords,
+                    option_materials,
+                    option_colors,
+                    align_model,
+                    option_flip_yz,
+                    option_scale,
+                    True,            # export_single_model
+                    option_copy_textures)
+
+    return {'FINISHED'}

+ 631 - 0
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/import_threejs.py

@@ -0,0 +1,631 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+"""
+Blender importer for Three.js (ASCII JSON format).
+
+"""
+
+import os
+import time
+import json
+import bpy
+import mathutils
+from mathutils.geometry import tesselate_polygon
+from io_utils import load_image, unpack_list, unpack_face_list
+
+# #####################################################
+# Generators
+# #####################################################
+def setColor(c, t):
+    c.r = t[0]
+    c.g = t[1]
+    c.b = t[2]
+
+def create_texture(filename, modelpath):
+    name = filename
+    texture = bpy.data.textures.new(name, type='IMAGE')
+    
+    image = load_image(filename, modelpath)
+    has_data = False
+
+    if image:
+        texture.image = image
+        has_data = image.has_data
+    
+    return texture
+    
+def create_materials(data, modelpath):
+    materials = []
+    materials_data = data.get("materials", [])
+    
+    for i, m in enumerate(materials_data):
+
+        name = m.get("DbgName", "material_%d" % i)
+        
+        colorAmbient = m.get("colorAmbient", None)
+        colorDiffuse = m.get("colorDiffuse", None)
+        colorSpecular = m.get("colorSpecular", None)
+        alpha = m.get("transparency", 1.0)
+        specular_hardness = m.get("specularCoef", 0)
+        
+        mapDiffuse = m.get("mapDiffuse", None)
+        mapLightmap = m.get("mapLightmap", None)
+        
+        vertexColorsType = m.get("vertexColors", False)
+        
+        useVertexColors = False
+        if vertexColorsType:
+            useVertexColors = True
+        
+        material = bpy.data.materials.new(name)
+        
+        material.THREE_useVertexColors = useVertexColors
+        
+        if colorDiffuse:
+            setColor(material.diffuse_color, colorDiffuse)
+            material.diffuse_intensity = 1.0
+
+        if colorSpecular:
+            setColor(material.specular_color, colorSpecular)
+            material.specular_intensity = 1.0
+            
+        if alpha < 1.0:
+            material.alpha = alpha
+            material.use_transparency = True
+            
+        if specular_hardness:
+            material.specular_hardness = specular_hardness
+            
+        if mapDiffuse:
+            texture = create_texture(mapDiffuse, modelpath)
+            mtex = material.texture_slots.add()
+            mtex.texture = texture
+            mtex.texture_coords = 'UV'
+            mtex.use = True
+            mtex.use_map_color_diffuse = True
+            
+            material.active_texture = texture
+
+        materials.append(material)
+        
+    return materials
+    
+def create_mesh_object(name, vertices, materials, face_data, flipYZ, recalculate_normals):
+
+    faces         = face_data["faces"]
+    vertexNormals = face_data["vertexNormals"]
+    vertexColors  = face_data["vertexColors"]
+    vertexUVs     = face_data["vertexUVs"]
+    faceMaterials = face_data["materials"]
+    faceColors    = face_data["faceColors"]
+    
+    edges = []
+    
+    # Create a new mesh
+    
+    me = bpy.data.meshes.new(name)
+    me.from_pydata(vertices, edges, faces)
+    
+    # Handle normals
+    
+    if not recalculate_normals:
+        me.update(calc_edges = True)
+    
+    if face_data["hasVertexNormals"]:
+        
+        print("setting vertex normals")
+        
+        for fi in range(len(faces)):
+
+            if vertexNormals[fi]:
+
+                #print("setting face %i with %i vertices" % (fi, len(normals[fi])))
+
+                # if me.update() is called after setting vertex normals
+                # setting face.use_smooth overrides these normals
+                #  - this fixes weird shading artefacts (seems to come from sharing 
+                #    of vertices between faces, didn't find a way how to set vertex normals
+                #    per face use of vertex as opposed to per vertex), 
+                #  - probably this just overrides all custom vertex normals
+                #  - to preserve vertex normals from the original data
+                #    call me.update() before setting them
+                
+                me.faces[fi].use_smooth = True
+                
+                if not recalculate_normals:
+                    for j in range(len(vertexNormals[fi])):
+                        
+                        vertexNormal = vertexNormals[fi][j]
+                    
+                        x = vertexNormal[0]
+                        y = vertexNormal[1]
+                        z = vertexNormal[2]
+                        
+                        if flipYZ:
+                            tmp = y
+                            y = -z
+                            z = tmp
+
+                            # flip normals (this make them look consistent with the original before export)
+
+                            #x = -x
+                            #y = -y
+                            #z = -z
+
+                        vi = me.faces[fi].vertices[j]
+                        
+                        me.vertices[vi].normal.x = x
+                        me.vertices[vi].normal.y = y
+                        me.vertices[vi].normal.z = z
+      
+    if recalculate_normals:
+        me.update(calc_edges = True)
+
+    # Handle colors
+    
+    if face_data["hasVertexColors"]:
+
+        print("setting vertex colors")
+
+        me.vertex_colors.new("vertex_color_layer_0")
+        
+        for fi in range(len(faces)):
+
+            if vertexColors[fi]:
+                
+                face_colors = me.vertex_colors[0].data[fi]
+                face_colors = face_colors.color1, face_colors.color2, face_colors.color3, face_colors.color4
+                
+                for vi in range(len(vertexColors[fi])):
+                    
+                    r = vertexColors[fi][vi][0]
+                    g = vertexColors[fi][vi][1]
+                    b = vertexColors[fi][vi][2]
+                
+                    face_colors[vi].r = r
+                    face_colors[vi].g = g
+                    face_colors[vi].b = b
+                    
+    elif face_data["hasFaceColors"]:
+
+        print("setting vertex colors from face colors")
+
+        me.vertex_colors.new("vertex_color_layer_0")
+        
+        for fi in range(len(faces)):
+
+            if faceColors[fi]:
+
+                r = faceColors[fi][0]
+                g = faceColors[fi][1]
+                b = faceColors[fi][2]
+
+                face_colors = me.vertex_colors[0].data[fi]
+                face_colors = face_colors.color1, face_colors.color2, face_colors.color3, face_colors.color4
+                
+                for vi in range(len(faces[fi])):
+                
+                    face_colors[vi].r = r
+                    face_colors[vi].g = g
+                    face_colors[vi].b = b
+
+    # Handle uvs
+    
+    if face_data["hasVertexUVs"]:
+
+        print("setting vertex uvs")
+        
+        for li, layer in enumerate(vertexUVs):
+
+            me.uv_textures.new("uv_layer_%d" % li)
+
+            for fi in range(len(faces)):
+
+                if layer[fi]:
+                    
+                    uv_face = me.uv_textures[li].data[fi]
+                    face_uvs = uv_face.uv1, uv_face.uv2, uv_face.uv3, uv_face.uv4
+                    
+                    for vi in range(len(layer[fi])):
+                        
+                        u = layer[fi][vi][0]
+                        v = layer[fi][vi][1]
+                    
+                        face_uvs[vi].x = u
+                        face_uvs[vi].y = 1.0 - v
+                        
+                    active_texture = materials[faceMaterials[fi]].active_texture
+                    
+                    if active_texture:
+                        uv_face.use_image = True
+                        uv_face.image = active_texture.image
+
+
+    # Handle materials # 1
+    
+    if face_data["hasMaterials"]:
+        
+
+        print("setting materials (mesh)")
+    
+        for m in materials:
+            
+            me.materials.append(m)
+
+        print("setting materials (faces)")    
+
+        for fi in range(len(faces)):
+            
+            if faceMaterials[fi] >= 0:
+                
+                me.faces[fi].material_index = faceMaterials[fi]
+
+    # Create a new object
+    
+    ob = bpy.data.objects.new(name, me) 
+    ob.data = me                                # link the mesh data to the object
+
+
+    scene = bpy.context.scene                   # get the current scene
+    scene.objects.link(ob)                      # link the object into the scene
+
+    ob.location = scene.cursor_location         # position object at 3d-cursor
+    
+    
+# #####################################################
+# Faces
+# #####################################################
+
+def extract_faces(data):
+    
+    result = {
+    "faces"         : [],
+    "materials"     : [],
+    "faceUVs"       : [],
+    "vertexUVs"     : [],
+    "faceNormals"   : [],
+    "vertexNormals" : [],
+    "faceColors"    : [],
+    "vertexColors"  : [],
+    
+    "hasVertexNormals"  : False,
+    "hasVertexUVs"      : False,
+    "hasVertexColors"   : False,
+    "hasFaceColors"     : False,
+    "hasMaterials"      : False
+    }
+    
+    faces = data.get("faces", [])
+    normals = data.get("normals", [])
+    colors = data.get("colors", [])
+
+    offset = 0
+    zLength = len(faces)
+
+    # disregard empty arrays
+
+    nUvLayers = 0
+
+    for layer in data["uvs"]:
+
+        if len(layer) > 0:
+            nUvLayers += 1
+            result["faceUVs"].append([])
+            result["vertexUVs"].append([])
+
+
+    while ( offset < zLength ):
+
+        type = faces[ offset ]
+        offset += 1
+
+        isQuad          	= isBitSet( type, 0 )
+        hasMaterial         = isBitSet( type, 1 )
+        hasFaceUv           = isBitSet( type, 2 )
+        hasFaceVertexUv     = isBitSet( type, 3 )
+        hasFaceNormal       = isBitSet( type, 4 )
+        hasFaceVertexNormal = isBitSet( type, 5 )
+        hasFaceColor	    = isBitSet( type, 6 )
+        hasFaceVertexColor  = isBitSet( type, 7 )
+
+        #print("type", type, "bits", isQuad, hasMaterial, hasFaceUv, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor)
+
+        result["hasVertexUVs"] = result["hasVertexUVs"] or hasFaceVertexUv
+        result["hasVertexNormals"] = result["hasVertexNormals"] or hasFaceVertexNormal
+        result["hasVertexColors"] = result["hasVertexColors"] or hasFaceVertexColor
+        result["hasFaceColors"] = result["hasFaceColors"] or hasFaceColor
+        result["hasMaterials"] = result["hasMaterials"] or hasMaterial
+        
+        # vertices
+        
+        if isQuad:
+
+            a = faces[ offset ]
+            offset += 1
+            
+            b = faces[ offset ]
+            offset += 1
+            
+            c = faces[ offset ]
+            offset += 1
+            
+            d = faces[ offset ]
+            offset += 1
+            
+            face = [a, b, c, d]
+
+            nVertices = 4
+
+        else:
+
+            a = faces[ offset ]
+            offset += 1
+            
+            b = faces[ offset ]
+            offset += 1
+            
+            c = faces[ offset ]
+            offset += 1
+
+            face = [a, b, c]
+            
+            nVertices = 3
+
+        result["faces"].append(face)
+
+        # material
+        
+        if hasMaterial:
+
+            materialIndex = faces[ offset ]
+            offset += 1
+        
+        else:
+
+            materialIndex = -1
+
+        result["materials"].append(materialIndex)
+
+        # uvs
+
+        for i in range(nUvLayers):
+
+            faceUv = None
+            
+            if hasFaceUv:
+                
+                uvLayer = data["uvs"][ i ]
+
+                uvIndex = faces[ offset ]
+                offset += 1
+
+                u = uvLayer[ uvIndex * 2 ]
+                v = uvLayer[ uvIndex * 2 + 1 ]
+
+                faceUv = [u, v]
+                
+            result["faceUVs"][i].append(faceUv)
+
+
+            if hasFaceVertexUv:
+
+                uvLayer = data["uvs"][ i ]
+
+                vertexUvs = []
+
+                for j in range(nVertices):
+
+                    uvIndex = faces[ offset ]
+                    offset += 1
+
+                    u = uvLayer[ uvIndex * 2 ]
+                    v = uvLayer[ uvIndex * 2 + 1 ]
+
+                    vertexUvs.append([u, v])
+
+            result["vertexUVs"][i].append(vertexUvs)
+
+
+        if hasFaceNormal:
+
+            normalIndex = faces[ offset ] * 3
+            offset += 1
+
+            x = normals[ normalIndex ]
+            y = normals[ normalIndex + 1 ]
+            z = normals[ normalIndex + 2 ]
+
+            faceNormal = [x, y, z]
+            
+        else:
+
+            faceNormal = None
+        
+        result["faceNormals"].append(faceNormal)
+
+
+        if hasFaceVertexNormal:
+
+            vertexNormals = []
+            
+            for j in range(nVertices):
+
+                normalIndex = faces[ offset ] * 3
+                offset += 1
+
+                x = normals[ normalIndex ]
+                y = normals[ normalIndex + 1 ]
+                z = normals[ normalIndex + 2 ]
+                
+                vertexNormals.append( [x, y, z] )
+
+
+        else:
+
+            vertexNormals = None
+        
+        result["vertexNormals"].append(vertexNormals)
+
+
+        if hasFaceColor:
+
+            colorIndex = faces[ offset ]
+            offset += 1
+            
+            faceColor = hexToTuple( colors[ colorIndex ] )
+
+        else:
+            
+            faceColor = None
+
+        result["faceColors"].append(faceColor)
+
+
+        if hasFaceVertexColor:
+
+            vertexColors = []
+
+            for j in range(nVertices):
+
+                colorIndex = faces[ offset ]
+                offset += 1
+
+                color = hexToTuple( colors[ colorIndex ] )
+                vertexColors.append( color )
+
+        else:
+            
+            vertexColors = None
+            
+        result["vertexColors"].append(vertexColors)
+
+
+    return result
+    
+# #####################################################
+# Utils
+# #####################################################
+
+def hexToTuple( hexColor ):
+    r = (( hexColor >> 16 ) & 0xff) / 255.0
+    g = (( hexColor >> 8 ) & 0xff) / 255.0
+    b = ( hexColor & 0xff) / 255.0
+    return (r, g, b)
+    
+def isBitSet(value, position):
+    return value & ( 1 << position )
+    
+def splitArray(data, chunkSize):
+    result = []
+    chunk = []
+    for i in range(len(data)):
+        if i > 0 and i % chunkSize == 0:
+            result.append(chunk)
+            chunk = []
+        chunk.append(data[i])
+    result.append(chunk)
+    return result
+
+
+def extract_json_string(text):
+    marker_begin = "var model ="
+    marker_end = "postMessage"
+    
+    start = text.find(marker_begin) + len(marker_begin)
+    end = text.find(marker_end)
+    end = text.rfind("}", start, end)
+    return text[start:end+1].strip()
+
+def get_name(filepath):
+    return os.path.splitext(os.path.basename(filepath))[0]
+
+def get_path(filepath):
+    return os.path.dirname(filepath)
+
+# #####################################################
+# Parser
+# #####################################################
+
+def load(operator, context, filepath, option_flip_yz = True, recalculate_normals = True):
+    
+    print('\nimporting %r' % filepath)
+
+    time_main = time.time()
+
+    print("\tparsing JSON file...")
+    
+    time_sub = time.time()
+
+    file = open(filepath, 'rU')
+    rawcontent = file.read()
+    file.close()
+
+    json_string = extract_json_string(rawcontent)
+    data = json.loads( json_string )
+    
+    time_new = time.time()
+
+    print('parsing %.4f sec' % (time_new - time_sub))
+    
+    time_sub = time_new
+
+    # flip YZ
+    
+    vertices = splitArray(data["vertices"], 3)
+    
+    if option_flip_yz:
+        vertices[:] = [(v[0], -v[2], v[1]) for v in vertices]        
+
+    # extract faces
+    
+    face_data = extract_faces(data)
+    
+    # deselect all
+
+    bpy.ops.object.select_all(action='DESELECT')
+
+    nfaces = len(face_data["faces"])
+    nvertices = len(vertices)
+    nnormals = len(data.get("normals", [])) / 3
+    ncolors = len(data.get("colors", [])) / 3
+    nuvs = len(data.get("uvs", [])) / 2
+    nmaterials = len(data.get("materials", []))
+    
+    print('\tbuilding geometry...\n\tfaces:%i, vertices:%i, vertex normals: %i, vertex uvs: %i, vertex colors: %i, materials: %i ...' % ( 
+        nfaces, nvertices, nnormals, nuvs, ncolors, nmaterials ))
+
+    # Create materials
+    
+    materials = create_materials(data, get_path(filepath))
+    
+    # Create new obj
+    
+    create_mesh_object(get_name(filepath), vertices, materials, face_data, option_flip_yz, recalculate_normals)
+
+    scene = bpy.context.scene 
+    scene.update()
+
+    time_new = time.time()
+
+    print('finished importing: %r in %.4f sec.' % (filepath, (time_new - time_main)))
+    return {'FINISHED'}
+
+
+if __name__ == "__main__":
+    register()

Some files were not shown because too many files changed in this diff