Browse Source

Merging with @alteredq's branch.

Mr.doob 14 years ago
parent
commit
176d0f2884
40 changed files with 1646 additions and 1042 deletions
  1. 145 145
      build/Three.js
  2. 2 2
      build/custom/ThreeCanvas.js
  3. 2 2
      build/custom/ThreeDOM.js
  4. 9 10
      build/custom/ThreeExtras.js
  5. 2 2
      build/custom/ThreeSVG.js
  6. 164 166
      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. 58 66
      examples/webgl_flycamera_earth.html
  11. 1 1
      examples/webgl_geometry_dynamic.html
  12. 1 1
      examples/webgl_geometry_minecraft.html
  13. 1 1
      examples/webgl_geometry_minecraft_ao.html
  14. 1 1
      examples/webgl_geometry_terrain.html
  15. 1 1
      examples/webgl_geometry_terrain_fog.html
  16. 4 13
      examples/webgl_materials_normalmap.html
  17. 3 11
      examples/webgl_materials_normalmap2.html
  18. 4 4
      examples/webgl_objconvert_test.html
  19. 1 9
      examples/webgl_postprocessing.html
  20. 2 11
      examples/webgl_postprocessing_dof.html
  21. 1 1
      examples/webgl_sandbox.html
  22. 11 15
      examples/webgl_trackballcamera_earth.html
  23. 116 61
      src/extras/ShaderUtils.js
  24. 5 5
      src/extras/cameras/FirstPersonCamera.js
  25. 2 2
      src/extras/cameras/QuakeCamera.js
  26. 49 52
      src/extras/geometries/TextGeometry.js
  27. 2 0
      src/extras/io/BinaryLoader.js
  28. 5 3
      src/extras/io/JSONLoader.js
  29. 153 39
      src/extras/io/Loader.js
  30. 106 20
      src/extras/io/SceneLoader.js
  31. 4 4
      src/materials/Material.js
  32. 1 1
      src/objects/Sprite.js
  33. 191 141
      src/renderers/WebGLRenderer.js
  34. 99 82
      src/renderers/WebGLShaders.js
  35. 2 0
      src/scenes/Scene.js
  36. 1 1
      utils/build.py
  37. 17 3
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/__init__.py
  38. 219 70
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/export_threejs.py
  39. 23 7
      utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/__init__.py
  40. 235 86
      utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py

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


+ 2 - 2
build/custom/ThreeCanvas.js

@@ -53,7 +53,7 @@ THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;thi
 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,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.001)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.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};
@@ -106,7 +106,7 @@ 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;

+ 2 - 2
build/custom/ThreeDOM.js

@@ -53,7 +53,7 @@ THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;thi
 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,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.001)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.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.Camera=function(a,b,c,d,e){THREE.Object3D.call(this);this.fov=a||50;this.aspect=b||1;this.near=c||0.1;this.far=d||2E3;this.target=e||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};THREE.Camera.prototype=new THREE.Object3D;THREE.Camera.prototype.constructor=THREE.Camera;
@@ -70,7 +70,7 @@ 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;

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


+ 2 - 2
build/custom/ThreeSVG.js

@@ -53,7 +53,7 @@ THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;thi
 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,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.001)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.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};
@@ -101,7 +101,7 @@ 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;

+ 164 - 166
build/custom/ThreeWebGL.js

@@ -14,33 +14,33 @@ THREE.Vector4.prototype={set:function(b,e,d,f){this.x=b;this.y=e;this.z=d;this.w
 b.x;this.y-=b.y;this.z-=b.z;this.w-=b.w;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;this.z*=b;this.w*=b;return this},divideScalar:function(b){b?(this.x/=b,this.y/=b,this.z/=b,this.w/=b):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z+this.w*b.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
 setLength:function(b){return this.normalize().multiplyScalar(b)},lerpSelf:function(b,e){this.x+=(b.x-this.x)*e;this.y+=(b.y-this.y)*e;this.z+=(b.z-this.z)*e;this.w+=(b.w-this.w)*e;return this}};THREE.Ray=function(b,e){this.origin=b||new THREE.Vector3;this.direction=e||new THREE.Vector3};
 THREE.Ray.prototype={intersectScene:function(b){return this.intersectObjects(b.objects)},intersectObjects:function(b){var e,d,f=[];e=0;for(d=b.length;e<d;e++)f=f.concat(this.intersectObject(b[e]));f.sort(function(b,e){return b.distance-e.distance});return f},intersectObject:function(b){function e(b,e,d){var f,d=d.matrixWorld.getPosition();f=d.clone().subSelf(b).dot(e);b=b.clone().addSelf(e.clone().multiplyScalar(f));return d.distanceTo(b)}function d(b,e,d,f){var f=f.clone().subSelf(e),d=d.clone().subSelf(e),
-h=b.clone().subSelf(e),b=f.dot(f),e=f.dot(d),f=f.dot(h),g=d.dot(d),d=d.dot(h),h=1/(b*g-e*e),g=(g*f-e*d)*h,b=(b*d-e*f)*h;return g>0&&b>0&&g+b<1}if(b instanceof THREE.Particle){var f=e(this.origin,this.direction,b);if(!f||f>b.scale.x)return[];return[{distance:f,point:b.position,face:null,object:b}]}else if(b instanceof THREE.Mesh){f=e(this.origin,this.direction,b);if(!f||f>b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)))return[];var h,i,g,j,k,o,p,n,q,w,y=b.geometry,
-D=y.vertices,z=[],f=0;for(h=y.faces.length;f<h;f++)if(i=y.faces[f],q=this.origin.clone(),w=this.direction.clone(),o=b.matrixWorld,g=o.multiplyVector3(D[i.a].position.clone()),j=o.multiplyVector3(D[i.b].position.clone()),k=o.multiplyVector3(D[i.c].position.clone()),o=i instanceof THREE.Face4?o.multiplyVector3(D[i.d].position.clone()):null,p=b.matrixRotationWorld.multiplyVector3(i.normal.clone()),n=w.dot(p),b.doubleSided||(b.flipSided?n>0:n<0))if(p=p.dot((new THREE.Vector3).sub(g,q))/n,q=q.addSelf(w.multiplyScalar(p)),
-i instanceof THREE.Face3)d(q,g,j,k)&&(i={distance:this.origin.distanceTo(q),point:q,face:i,object:b},z.push(i));else if(i instanceof THREE.Face4&&(d(q,g,j,o)||d(q,j,k,o)))i={distance:this.origin.distanceTo(q),point:q,face:i,object:b},z.push(i);return z}else return[]}};
-THREE.Rectangle=function(){function b(){i=f-e;g=h-d}var e,d,f,h,i,g,j=!0;this.getX=function(){return e};this.getY=function(){return d};this.getWidth=function(){return i};this.getHeight=function(){return g};this.getLeft=function(){return e};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return h};this.set=function(g,i,p,n){j=!1;e=g;d=i;f=p;h=n;b()};this.addPoint=function(g,i){j?(j=!1,e=g,d=i,f=g,h=i):(e=e<g?e:g,d=d<i?d:i,f=f>g?f:g,h=h>i?h:i);b()};this.add3Points=
-function(g,i,p,n,q,w){j?(j=!1,e=g<p?g<q?g:q:p<q?p:q,d=i<n?i<w?i:w:n<w?n:w,f=g>p?g>q?g:q:p>q?p:q,h=i>n?i>w?i:w:n>w?n:w):(e=g<p?g<q?g<e?g:e:q<e?q:e:p<q?p<e?p:e:q<e?q:e,d=i<n?i<w?i<d?i:d:w<d?w:d:n<w?n<d?n:d:w<d?w:d,f=g>p?g>q?g>f?g:f:q>f?q:f:p>q?p>f?p:f:q>f?q:f,h=i>n?i>w?i>h?i:h:w>h?w:h:n>w?n>h?n:h:w>h?w:h);b()};this.addRectangle=function(g){j?(j=!1,e=g.getLeft(),d=g.getTop(),f=g.getRight(),h=g.getBottom()):(e=e<g.getLeft()?e:g.getLeft(),d=d<g.getTop()?d:g.getTop(),f=f>g.getRight()?f:g.getRight(),h=h>
+h=b.clone().subSelf(e),b=f.dot(f),e=f.dot(d),f=f.dot(h),g=d.dot(d),d=d.dot(h),h=1/(b*g-e*e),g=(g*f-e*d)*h,b=(b*d-e*f)*h;return g>0&&b>0&&g+b<1}if(b instanceof THREE.Particle){var f=e(this.origin,this.direction,b);if(!f||f>b.scale.x)return[];return[{distance:f,point:b.position,face:null,object:b}]}else if(b instanceof THREE.Mesh){f=e(this.origin,this.direction,b);if(!f||f>b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)))return[];var h,i,g,j,k,o,q,n,t,u,z=b.geometry,
+D=z.vertices,E=[],f=0;for(h=z.faces.length;f<h;f++)if(i=z.faces[f],t=this.origin.clone(),u=this.direction.clone(),o=b.matrixWorld,g=o.multiplyVector3(D[i.a].position.clone()),j=o.multiplyVector3(D[i.b].position.clone()),k=o.multiplyVector3(D[i.c].position.clone()),o=i instanceof THREE.Face4?o.multiplyVector3(D[i.d].position.clone()):null,q=b.matrixRotationWorld.multiplyVector3(i.normal.clone()),n=u.dot(q),b.doubleSided||(b.flipSided?n>0:n<0))if(q=q.dot((new THREE.Vector3).sub(g,t))/n,t=t.addSelf(u.multiplyScalar(q)),
+i instanceof THREE.Face3)d(t,g,j,k)&&(i={distance:this.origin.distanceTo(t),point:t,face:i,object:b},E.push(i));else if(i instanceof THREE.Face4&&(d(t,g,j,o)||d(t,j,k,o)))i={distance:this.origin.distanceTo(t),point:t,face:i,object:b},E.push(i);return E}else return[]}};
+THREE.Rectangle=function(){function b(){i=f-e;g=h-d}var e,d,f,h,i,g,j=!0;this.getX=function(){return e};this.getY=function(){return d};this.getWidth=function(){return i};this.getHeight=function(){return g};this.getLeft=function(){return e};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return h};this.set=function(g,i,q,n){j=!1;e=g;d=i;f=q;h=n;b()};this.addPoint=function(g,i){j?(j=!1,e=g,d=i,f=g,h=i):(e=e<g?e:g,d=d<i?d:i,f=f>g?f:g,h=h>i?h:i);b()};this.add3Points=
+function(g,i,q,n,t,u){j?(j=!1,e=g<q?g<t?g:t:q<t?q:t,d=i<n?i<u?i:u:n<u?n:u,f=g>q?g>t?g:t:q>t?q:t,h=i>n?i>u?i:u:n>u?n:u):(e=g<q?g<t?g<e?g:e:t<e?t:e:q<t?q<e?q:e:t<e?t:e,d=i<n?i<u?i<d?i:d:u<d?u:d:n<u?n<d?n:d:u<d?u:d,f=g>q?g>t?g>f?g:f:t>f?t:f:q>t?q>f?q:f:t>f?t:f,h=i>n?i>u?i>h?i:h:u>h?u:h:n>u?n>h?n:h:u>h?u:h);b()};this.addRectangle=function(g){j?(j=!1,e=g.getLeft(),d=g.getTop(),f=g.getRight(),h=g.getBottom()):(e=e<g.getLeft()?e:g.getLeft(),d=d<g.getTop()?d:g.getTop(),f=f>g.getRight()?f:g.getRight(),h=h>
 g.getBottom()?h:g.getBottom());b()};this.inflate=function(g){e-=g;d-=g;f+=g;h+=g;b()};this.minSelf=function(g){e=e>g.getLeft()?e:g.getLeft();d=d>g.getTop()?d:g.getTop();f=f<g.getRight()?f:g.getRight();h=h<g.getBottom()?h:g.getBottom();b()};this.instersects=function(b){return Math.min(f,b.getRight())-Math.max(e,b.getLeft())>=0&&Math.min(h,b.getBottom())-Math.max(d,b.getTop())>=0};this.empty=function(){j=!0;h=f=d=e=0;b()};this.isEmpty=function(){return j}};THREE.Matrix3=function(){this.m=[]};
-THREE.Matrix3.prototype={transpose:function(){var b,e=this.m;b=e[1];e[1]=e[3];e[3]=b;b=e[2];e[2]=e[6];e[6]=b;b=e[5];e[5]=e[7];e[7]=b;return this},transposeIntoArray:function(b){var e=this.m;b[0]=e[0];b[1]=e[3];b[2]=e[6];b[3]=e[1];b[4]=e[4];b[5]=e[7];b[6]=e[2];b[7]=e[5];b[8]=e[8];return this}};THREE.Matrix4=function(b,e,d,f,h,i,g,j,k,o,p,n,q,w,y,D){this.set(b||1,e||0,d||0,f||0,h||0,i||1,g||0,j||0,k||0,o||0,p||1,n||0,q||0,w||0,y||0,D||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
-THREE.Matrix4.prototype={set:function(b,e,d,f,h,i,g,j,k,o,p,n,q,w,y,D){this.n11=b;this.n12=e;this.n13=d;this.n14=f;this.n21=h;this.n22=i;this.n23=g;this.n24=j;this.n31=k;this.n32=o;this.n33=p;this.n34=n;this.n41=q;this.n42=w;this.n43=y;this.n44=D;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(b){this.set(b.n11,b.n12,b.n13,b.n14,b.n21,b.n22,b.n23,b.n24,b.n31,b.n32,b.n33,b.n34,b.n41,b.n42,b.n43,b.n44);return this},lookAt:function(b,e,d){var f=THREE.Matrix4.__v1,
+THREE.Matrix3.prototype={transpose:function(){var b,e=this.m;b=e[1];e[1]=e[3];e[3]=b;b=e[2];e[2]=e[6];e[6]=b;b=e[5];e[5]=e[7];e[7]=b;return this},transposeIntoArray:function(b){var e=this.m;b[0]=e[0];b[1]=e[3];b[2]=e[6];b[3]=e[1];b[4]=e[4];b[5]=e[7];b[6]=e[2];b[7]=e[5];b[8]=e[8];return this}};THREE.Matrix4=function(b,e,d,f,h,i,g,j,k,o,q,n,t,u,z,D){this.set(b||1,e||0,d||0,f||0,h||0,i||1,g||0,j||0,k||0,o||0,q||1,n||0,t||0,u||0,z||0,D||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
+THREE.Matrix4.prototype={set:function(b,e,d,f,h,i,g,j,k,o,q,n,t,u,z,D){this.n11=b;this.n12=e;this.n13=d;this.n14=f;this.n21=h;this.n22=i;this.n23=g;this.n24=j;this.n31=k;this.n32=o;this.n33=q;this.n34=n;this.n41=t;this.n42=u;this.n43=z;this.n44=D;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(b){this.set(b.n11,b.n12,b.n13,b.n14,b.n21,b.n22,b.n23,b.n24,b.n31,b.n32,b.n33,b.n34,b.n41,b.n42,b.n43,b.n44);return this},lookAt:function(b,e,d){var f=THREE.Matrix4.__v1,
 h=THREE.Matrix4.__v2,i=THREE.Matrix4.__v3;i.sub(b,e).normalize();if(i.length()===0)i.z=1;f.cross(d,i).normalize();f.length()===0&&(i.x+=1.0E-4,f.cross(d,i).normalize());h.cross(i,f).normalize();this.n11=f.x;this.n12=h.x;this.n13=i.x;this.n21=f.y;this.n22=h.y;this.n23=i.y;this.n31=f.z;this.n32=h.z;this.n33=i.z;return this},multiplyVector3:function(b){var e=b.x,d=b.y,f=b.z,h=1/(this.n41*e+this.n42*d+this.n43*f+this.n44);b.x=(this.n11*e+this.n12*d+this.n13*f+this.n14)*h;b.y=(this.n21*e+this.n22*d+this.n23*
 f+this.n24)*h;b.z=(this.n31*e+this.n32*d+this.n33*f+this.n34)*h;return b},multiplyVector4:function(b){var e=b.x,d=b.y,f=b.z,h=b.w;b.x=this.n11*e+this.n12*d+this.n13*f+this.n14*h;b.y=this.n21*e+this.n22*d+this.n23*f+this.n24*h;b.z=this.n31*e+this.n32*d+this.n33*f+this.n34*h;b.w=this.n41*e+this.n42*d+this.n43*f+this.n44*h;return b},rotateAxis:function(b){var e=b.x,d=b.y,f=b.z;b.x=e*this.n11+d*this.n12+f*this.n13;b.y=e*this.n21+d*this.n22+f*this.n23;b.z=e*this.n31+d*this.n32+f*this.n33;b.normalize();
-return b},crossVector:function(b){var e=new THREE.Vector4;e.x=this.n11*b.x+this.n12*b.y+this.n13*b.z+this.n14*b.w;e.y=this.n21*b.x+this.n22*b.y+this.n23*b.z+this.n24*b.w;e.z=this.n31*b.x+this.n32*b.y+this.n33*b.z+this.n34*b.w;e.w=b.w?this.n41*b.x+this.n42*b.y+this.n43*b.z+this.n44*b.w:1;return e},multiply:function(b,e){var d=b.n11,f=b.n12,h=b.n13,i=b.n14,g=b.n21,j=b.n22,k=b.n23,o=b.n24,p=b.n31,n=b.n32,q=b.n33,w=b.n34,y=b.n41,D=b.n42,z=b.n43,C=b.n44,ga=e.n11,aa=e.n12,O=e.n13,F=e.n14,v=e.n21,M=e.n22,
-B=e.n23,$=e.n24,K=e.n31,na=e.n32,U=e.n33,R=e.n34,c=e.n41,ha=e.n42,S=e.n43,ka=e.n44;this.n11=d*ga+f*v+h*K+i*c;this.n12=d*aa+f*M+h*na+i*ha;this.n13=d*O+f*B+h*U+i*S;this.n14=d*F+f*$+h*R+i*ka;this.n21=g*ga+j*v+k*K+o*c;this.n22=g*aa+j*M+k*na+o*ha;this.n23=g*O+j*B+k*U+o*S;this.n24=g*F+j*$+k*R+o*ka;this.n31=p*ga+n*v+q*K+w*c;this.n32=p*aa+n*M+q*na+w*ha;this.n33=p*O+n*B+q*U+w*S;this.n34=p*F+n*$+q*R+w*ka;this.n41=y*ga+D*v+z*K+C*c;this.n42=y*aa+D*M+z*na+C*ha;this.n43=y*O+D*B+z*U+C*S;this.n44=y*F+D*$+z*R+C*ka;
-return this},multiplyToArray:function(b,e,d){this.multiply(b,e);d[0]=this.n11;d[1]=this.n21;d[2]=this.n31;d[3]=this.n41;d[4]=this.n12;d[5]=this.n22;d[6]=this.n32;d[7]=this.n42;d[8]=this.n13;d[9]=this.n23;d[10]=this.n33;d[11]=this.n43;d[12]=this.n14;d[13]=this.n24;d[14]=this.n34;d[15]=this.n44;return this},multiplySelf:function(b){this.multiply(this,b);return this},multiplyScalar:function(b){this.n11*=b;this.n12*=b;this.n13*=b;this.n14*=b;this.n21*=b;this.n22*=b;this.n23*=b;this.n24*=b;this.n31*=b;
-this.n32*=b;this.n33*=b;this.n34*=b;this.n41*=b;this.n42*=b;this.n43*=b;this.n44*=b;return this},determinant:function(){var b=this.n11,e=this.n12,d=this.n13,f=this.n14,h=this.n21,i=this.n22,g=this.n23,j=this.n24,k=this.n31,o=this.n32,p=this.n33,n=this.n34,q=this.n41,w=this.n42,y=this.n43,D=this.n44;return f*g*o*q-d*j*o*q-f*i*p*q+e*j*p*q+d*i*n*q-e*g*n*q-f*g*k*w+d*j*k*w+f*h*p*w-b*j*p*w-d*h*n*w+b*g*n*w+f*i*k*y-e*j*k*y-f*h*o*y+b*j*o*y+e*h*n*y-b*i*n*y-d*i*k*D+e*g*k*D+d*h*o*D-b*g*o*D-e*h*p*D+b*i*p*D},transpose:function(){var b;
-b=this.n21;this.n21=this.n12;this.n12=b;b=this.n31;this.n31=this.n13;this.n13=b;b=this.n32;this.n32=this.n23;this.n23=b;b=this.n41;this.n41=this.n14;this.n14=b;b=this.n42;this.n42=this.n24;this.n24=b;b=this.n43;this.n43=this.n34;this.n43=b;return this},clone:function(){var b=new THREE.Matrix4;b.n11=this.n11;b.n12=this.n12;b.n13=this.n13;b.n14=this.n14;b.n21=this.n21;b.n22=this.n22;b.n23=this.n23;b.n24=this.n24;b.n31=this.n31;b.n32=this.n32;b.n33=this.n33;b.n34=this.n34;b.n41=this.n41;b.n42=this.n42;
-b.n43=this.n43;b.n44=this.n44;return b},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(b){b[0]=this.n11;b[1]=this.n21;b[2]=this.n31;
-b[3]=this.n41;b[4]=this.n12;b[5]=this.n22;b[6]=this.n32;b[7]=this.n42;b[8]=this.n13;b[9]=this.n23;b[10]=this.n33;b[11]=this.n43;b[12]=this.n14;b[13]=this.n24;b[14]=this.n34;b[15]=this.n44;return b},flattenToArrayOffset:function(b,e){b[e]=this.n11;b[e+1]=this.n21;b[e+2]=this.n31;b[e+3]=this.n41;b[e+4]=this.n12;b[e+5]=this.n22;b[e+6]=this.n32;b[e+7]=this.n42;b[e+8]=this.n13;b[e+9]=this.n23;b[e+10]=this.n33;b[e+11]=this.n43;b[e+12]=this.n14;b[e+13]=this.n24;b[e+14]=this.n34;b[e+15]=this.n44;return b},
-setTranslation:function(b,e,d){this.set(1,0,0,b,0,1,0,e,0,0,1,d,0,0,0,1);return this},setScale:function(b,e,d){this.set(b,0,0,0,0,e,0,0,0,0,d,0,0,0,0,1);return this},setRotationX:function(b){var e=Math.cos(b),b=Math.sin(b);this.set(1,0,0,0,0,e,-b,0,0,b,e,0,0,0,0,1);return this},setRotationY:function(b){var e=Math.cos(b),b=Math.sin(b);this.set(e,0,b,0,0,1,0,0,-b,0,e,0,0,0,0,1);return this},setRotationZ:function(b){var e=Math.cos(b),b=Math.sin(b);this.set(e,-b,0,0,b,e,0,0,0,0,1,0,0,0,0,1);return this},
-setRotationAxis:function(b,e){var d=Math.cos(e),f=Math.sin(e),h=1-d,i=b.x,g=b.y,j=b.z,k=h*i,o=h*g;this.set(k*i+d,k*g-f*j,k*j+f*g,0,k*g+f*j,o*g+d,o*j-f*i,0,k*j-f*g,o*j+f*i,h*j*j+d,0,0,0,0,1);return this},setPosition:function(b){this.n14=b.x;this.n24=b.y;this.n34=b.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(b,e){var d=b.x,f=b.y,h=b.z,i=Math.cos(d),d=Math.sin(d),g=Math.cos(f),f=Math.sin(f),j=Math.cos(h),h=Math.sin(h);switch(e){case "YXZ":var k=g*j,o=g*h,p=f*j,n=f*h;
-this.n11=k+n*d;this.n12=p*d-o;this.n13=i*f;this.n21=i*h;this.n22=i*j;this.n23=-d;this.n31=o*d-p;this.n32=n+k*d;this.n33=i*g;break;case "ZXY":k=g*j;o=g*h;p=f*j;n=f*h;this.n11=k-n*d;this.n12=-i*h;this.n13=p+o*d;this.n21=o+p*d;this.n22=i*j;this.n23=n-k*d;this.n31=-i*f;this.n32=d;this.n33=i*g;break;case "ZYX":k=i*j;o=i*h;p=d*j;n=d*h;this.n11=g*j;this.n12=p*f-o;this.n13=k*f+n;this.n21=g*h;this.n22=n*f+k;this.n23=o*f-p;this.n31=-f;this.n32=d*g;this.n33=i*g;break;case "YZX":k=i*g;o=i*f;p=d*g;n=d*f;this.n11=
-g*j;this.n12=n-k*h;this.n13=p*h+o;this.n21=h;this.n22=i*j;this.n23=-d*j;this.n31=-f*j;this.n32=o*h+p;this.n33=k-n*h;break;case "XZY":k=i*g;o=i*f;p=d*g;n=d*f;this.n11=g*j;this.n12=-h;this.n13=f*j;this.n21=k*h+n;this.n22=i*j;this.n23=o*h-p;this.n31=p*h-o;this.n32=d*j;this.n33=n*h+k;break;default:k=i*j,o=i*h,p=d*j,n=d*h,this.n11=g*j,this.n12=-g*h,this.n13=f,this.n21=o+p*f,this.n22=k-n*f,this.n23=-d*g,this.n31=n-k*f,this.n32=p+o*f,this.n33=i*g}return this},setRotationFromQuaternion:function(b){var e=
+return b},crossVector:function(b){var e=new THREE.Vector4;e.x=this.n11*b.x+this.n12*b.y+this.n13*b.z+this.n14*b.w;e.y=this.n21*b.x+this.n22*b.y+this.n23*b.z+this.n24*b.w;e.z=this.n31*b.x+this.n32*b.y+this.n33*b.z+this.n34*b.w;e.w=b.w?this.n41*b.x+this.n42*b.y+this.n43*b.z+this.n44*b.w:1;return e},multiply:function(b,e){var d=b.n11,f=b.n12,h=b.n13,i=b.n14,g=b.n21,j=b.n22,k=b.n23,o=b.n24,q=b.n31,n=b.n32,t=b.n33,u=b.n34,z=b.n41,D=b.n42,E=b.n43,C=b.n44,N=e.n11,ea=e.n12,S=e.n13,H=e.n14,y=e.n21,aa=e.n22,
+P=e.n23,Q=e.n24,B=e.n31,ua=e.n32,K=e.n33,L=e.n34,c=e.n41,sa=e.n42,la=e.n43,ha=e.n44;this.n11=d*N+f*y+h*B+i*c;this.n12=d*ea+f*aa+h*ua+i*sa;this.n13=d*S+f*P+h*K+i*la;this.n14=d*H+f*Q+h*L+i*ha;this.n21=g*N+j*y+k*B+o*c;this.n22=g*ea+j*aa+k*ua+o*sa;this.n23=g*S+j*P+k*K+o*la;this.n24=g*H+j*Q+k*L+o*ha;this.n31=q*N+n*y+t*B+u*c;this.n32=q*ea+n*aa+t*ua+u*sa;this.n33=q*S+n*P+t*K+u*la;this.n34=q*H+n*Q+t*L+u*ha;this.n41=z*N+D*y+E*B+C*c;this.n42=z*ea+D*aa+E*ua+C*sa;this.n43=z*S+D*P+E*K+C*la;this.n44=z*H+D*Q+E*
+L+C*ha;return this},multiplyToArray:function(b,e,d){this.multiply(b,e);d[0]=this.n11;d[1]=this.n21;d[2]=this.n31;d[3]=this.n41;d[4]=this.n12;d[5]=this.n22;d[6]=this.n32;d[7]=this.n42;d[8]=this.n13;d[9]=this.n23;d[10]=this.n33;d[11]=this.n43;d[12]=this.n14;d[13]=this.n24;d[14]=this.n34;d[15]=this.n44;return this},multiplySelf:function(b){this.multiply(this,b);return this},multiplyScalar:function(b){this.n11*=b;this.n12*=b;this.n13*=b;this.n14*=b;this.n21*=b;this.n22*=b;this.n23*=b;this.n24*=b;this.n31*=
+b;this.n32*=b;this.n33*=b;this.n34*=b;this.n41*=b;this.n42*=b;this.n43*=b;this.n44*=b;return this},determinant:function(){var b=this.n11,e=this.n12,d=this.n13,f=this.n14,h=this.n21,i=this.n22,g=this.n23,j=this.n24,k=this.n31,o=this.n32,q=this.n33,n=this.n34,t=this.n41,u=this.n42,z=this.n43,D=this.n44;return f*g*o*t-d*j*o*t-f*i*q*t+e*j*q*t+d*i*n*t-e*g*n*t-f*g*k*u+d*j*k*u+f*h*q*u-b*j*q*u-d*h*n*u+b*g*n*u+f*i*k*z-e*j*k*z-f*h*o*z+b*j*o*z+e*h*n*z-b*i*n*z-d*i*k*D+e*g*k*D+d*h*o*D-b*g*o*D-e*h*q*D+b*i*q*D},
+transpose:function(){var b;b=this.n21;this.n21=this.n12;this.n12=b;b=this.n31;this.n31=this.n13;this.n13=b;b=this.n32;this.n32=this.n23;this.n23=b;b=this.n41;this.n41=this.n14;this.n14=b;b=this.n42;this.n42=this.n24;this.n24=b;b=this.n43;this.n43=this.n34;this.n43=b;return this},clone:function(){var b=new THREE.Matrix4;b.n11=this.n11;b.n12=this.n12;b.n13=this.n13;b.n14=this.n14;b.n21=this.n21;b.n22=this.n22;b.n23=this.n23;b.n24=this.n24;b.n31=this.n31;b.n32=this.n32;b.n33=this.n33;b.n34=this.n34;
+b.n41=this.n41;b.n42=this.n42;b.n43=this.n43;b.n44=this.n44;return b},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(b){b[0]=this.n11;
+b[1]=this.n21;b[2]=this.n31;b[3]=this.n41;b[4]=this.n12;b[5]=this.n22;b[6]=this.n32;b[7]=this.n42;b[8]=this.n13;b[9]=this.n23;b[10]=this.n33;b[11]=this.n43;b[12]=this.n14;b[13]=this.n24;b[14]=this.n34;b[15]=this.n44;return b},flattenToArrayOffset:function(b,e){b[e]=this.n11;b[e+1]=this.n21;b[e+2]=this.n31;b[e+3]=this.n41;b[e+4]=this.n12;b[e+5]=this.n22;b[e+6]=this.n32;b[e+7]=this.n42;b[e+8]=this.n13;b[e+9]=this.n23;b[e+10]=this.n33;b[e+11]=this.n43;b[e+12]=this.n14;b[e+13]=this.n24;b[e+14]=this.n34;
+b[e+15]=this.n44;return b},setTranslation:function(b,e,d){this.set(1,0,0,b,0,1,0,e,0,0,1,d,0,0,0,1);return this},setScale:function(b,e,d){this.set(b,0,0,0,0,e,0,0,0,0,d,0,0,0,0,1);return this},setRotationX:function(b){var e=Math.cos(b),b=Math.sin(b);this.set(1,0,0,0,0,e,-b,0,0,b,e,0,0,0,0,1);return this},setRotationY:function(b){var e=Math.cos(b),b=Math.sin(b);this.set(e,0,b,0,0,1,0,0,-b,0,e,0,0,0,0,1);return this},setRotationZ:function(b){var e=Math.cos(b),b=Math.sin(b);this.set(e,-b,0,0,b,e,0,0,
+0,0,1,0,0,0,0,1);return this},setRotationAxis:function(b,e){var d=Math.cos(e),f=Math.sin(e),h=1-d,i=b.x,g=b.y,j=b.z,k=h*i,o=h*g;this.set(k*i+d,k*g-f*j,k*j+f*g,0,k*g+f*j,o*g+d,o*j-f*i,0,k*j-f*g,o*j+f*i,h*j*j+d,0,0,0,0,1);return this},setPosition:function(b){this.n14=b.x;this.n24=b.y;this.n34=b.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(b,e){var d=b.x,f=b.y,h=b.z,i=Math.cos(d),d=Math.sin(d),g=Math.cos(f),f=Math.sin(f),j=Math.cos(h),h=Math.sin(h);switch(e){case "YXZ":var k=
+g*j,o=g*h,q=f*j,n=f*h;this.n11=k+n*d;this.n12=q*d-o;this.n13=i*f;this.n21=i*h;this.n22=i*j;this.n23=-d;this.n31=o*d-q;this.n32=n+k*d;this.n33=i*g;break;case "ZXY":k=g*j;o=g*h;q=f*j;n=f*h;this.n11=k-n*d;this.n12=-i*h;this.n13=q+o*d;this.n21=o+q*d;this.n22=i*j;this.n23=n-k*d;this.n31=-i*f;this.n32=d;this.n33=i*g;break;case "ZYX":k=i*j;o=i*h;q=d*j;n=d*h;this.n11=g*j;this.n12=q*f-o;this.n13=k*f+n;this.n21=g*h;this.n22=n*f+k;this.n23=o*f-q;this.n31=-f;this.n32=d*g;this.n33=i*g;break;case "YZX":k=i*g;o=
+i*f;q=d*g;n=d*f;this.n11=g*j;this.n12=n-k*h;this.n13=q*h+o;this.n21=h;this.n22=i*j;this.n23=-d*j;this.n31=-f*j;this.n32=o*h+q;this.n33=k-n*h;break;case "XZY":k=i*g;o=i*f;q=d*g;n=d*f;this.n11=g*j;this.n12=-h;this.n13=f*j;this.n21=k*h+n;this.n22=i*j;this.n23=o*h-q;this.n31=q*h-o;this.n32=d*j;this.n33=n*h+k;break;default:k=i*j,o=i*h,q=d*j,n=d*h,this.n11=g*j,this.n12=-g*h,this.n13=f,this.n21=o+q*f,this.n22=k-n*f,this.n23=-d*g,this.n31=n-k*f,this.n32=q+o*f,this.n33=i*g}return this},setRotationFromQuaternion:function(b){var e=
 b.x,d=b.y,f=b.z,h=b.w,i=e+e,g=d+d,j=f+f,b=e*i,k=e*g;e*=j;var o=d*g;d*=j;f*=j;i*=h;g*=h;h*=j;this.n11=1-(o+f);this.n12=k-h;this.n13=e+g;this.n21=k+h;this.n22=1-(b+f);this.n23=d-i;this.n31=e-g;this.n32=d+i;this.n33=1-(b+o);return this},scale:function(b){var e=b.x,d=b.y,b=b.z;this.n11*=e;this.n12*=d;this.n13*=b;this.n21*=e;this.n22*=d;this.n23*=b;this.n31*=e;this.n32*=d;this.n33*=b;this.n41*=e;this.n42*=d;this.n43*=b;return this},extractPosition:function(b){this.n14=b.n14;this.n24=b.n24;this.n34=b.n34},
 extractRotation:function(b,e){var d=1/e.x,f=1/e.y,h=1/e.z;this.n11=b.n11*d;this.n21=b.n21*d;this.n31=b.n31*d;this.n12=b.n12*f;this.n22=b.n22*f;this.n32=b.n32*f;this.n13=b.n13*h;this.n23=b.n23*h;this.n33=b.n33*h}};
-THREE.Matrix4.makeInvert=function(b,e){var d=b.n11,f=b.n12,h=b.n13,i=b.n14,g=b.n21,j=b.n22,k=b.n23,o=b.n24,p=b.n31,n=b.n32,q=b.n33,w=b.n34,y=b.n41,D=b.n42,z=b.n43,C=b.n44;e===void 0&&(e=new THREE.Matrix4);e.n11=k*w*D-o*q*D+o*n*z-j*w*z-k*n*C+j*q*C;e.n12=i*q*D-h*w*D-i*n*z+f*w*z+h*n*C-f*q*C;e.n13=h*o*D-i*k*D+i*j*z-f*o*z-h*j*C+f*k*C;e.n14=i*k*n-h*o*n-i*j*q+f*o*q+h*j*w-f*k*w;e.n21=o*q*y-k*w*y-o*p*z+g*w*z+k*p*C-g*q*C;e.n22=h*w*y-i*q*y+i*p*z-d*w*z-h*p*C+d*q*C;e.n23=i*k*y-h*o*y-i*g*z+d*o*z+h*g*C-d*k*C;e.n24=
-h*o*p-i*k*p+i*g*q-d*o*q-h*g*w+d*k*w;e.n31=j*w*y-o*n*y+o*p*D-g*w*D-j*p*C+g*n*C;e.n32=i*n*y-f*w*y-i*p*D+d*w*D+f*p*C-d*n*C;e.n33=h*o*y-i*j*y+i*g*D-d*o*D-f*g*C+d*j*C;e.n34=i*j*p-f*o*p-i*g*n+d*o*n+f*g*w-d*j*w;e.n41=k*n*y-j*q*y-k*p*D+g*q*D+j*p*z-g*n*z;e.n42=f*q*y-h*n*y+h*p*D-d*q*D-f*p*z+d*n*z;e.n43=h*j*y-f*k*y-h*g*D+d*k*D+f*g*z-d*j*z;e.n44=f*k*p-h*j*p+h*g*n-d*k*n-f*g*q+d*j*q;e.multiplyScalar(1/b.determinant());return e};
-THREE.Matrix4.makeInvert3x3=function(b){var e=b.m33,d=e.m,f=b.n33*b.n22-b.n32*b.n23,h=-b.n33*b.n21+b.n31*b.n23,i=b.n32*b.n21-b.n31*b.n22,g=-b.n33*b.n12+b.n32*b.n13,j=b.n33*b.n11-b.n31*b.n13,k=-b.n32*b.n11+b.n31*b.n12,o=b.n23*b.n12-b.n22*b.n13,p=-b.n23*b.n11+b.n21*b.n13,n=b.n22*b.n11-b.n21*b.n12,b=b.n11*f+b.n21*g+b.n31*o;b==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");b=1/b;d[0]=b*f;d[1]=b*h;d[2]=b*i;d[3]=b*g;d[4]=b*j;d[5]=b*k;d[6]=b*o;d[7]=b*p;d[8]=b*n;return e};
+THREE.Matrix4.makeInvert=function(b,e){var d=b.n11,f=b.n12,h=b.n13,i=b.n14,g=b.n21,j=b.n22,k=b.n23,o=b.n24,q=b.n31,n=b.n32,t=b.n33,u=b.n34,z=b.n41,D=b.n42,E=b.n43,C=b.n44;e===void 0&&(e=new THREE.Matrix4);e.n11=k*u*D-o*t*D+o*n*E-j*u*E-k*n*C+j*t*C;e.n12=i*t*D-h*u*D-i*n*E+f*u*E+h*n*C-f*t*C;e.n13=h*o*D-i*k*D+i*j*E-f*o*E-h*j*C+f*k*C;e.n14=i*k*n-h*o*n-i*j*t+f*o*t+h*j*u-f*k*u;e.n21=o*t*z-k*u*z-o*q*E+g*u*E+k*q*C-g*t*C;e.n22=h*u*z-i*t*z+i*q*E-d*u*E-h*q*C+d*t*C;e.n23=i*k*z-h*o*z-i*g*E+d*o*E+h*g*C-d*k*C;e.n24=
+h*o*q-i*k*q+i*g*t-d*o*t-h*g*u+d*k*u;e.n31=j*u*z-o*n*z+o*q*D-g*u*D-j*q*C+g*n*C;e.n32=i*n*z-f*u*z-i*q*D+d*u*D+f*q*C-d*n*C;e.n33=h*o*z-i*j*z+i*g*D-d*o*D-f*g*C+d*j*C;e.n34=i*j*q-f*o*q-i*g*n+d*o*n+f*g*u-d*j*u;e.n41=k*n*z-j*t*z-k*q*D+g*t*D+j*q*E-g*n*E;e.n42=f*t*z-h*n*z+h*q*D-d*t*D-f*q*E+d*n*E;e.n43=h*j*z-f*k*z-h*g*D+d*k*D+f*g*E-d*j*E;e.n44=f*k*q-h*j*q+h*g*n-d*k*n-f*g*t+d*j*t;e.multiplyScalar(1/b.determinant());return e};
+THREE.Matrix4.makeInvert3x3=function(b){var e=b.m33,d=e.m,f=b.n33*b.n22-b.n32*b.n23,h=-b.n33*b.n21+b.n31*b.n23,i=b.n32*b.n21-b.n31*b.n22,g=-b.n33*b.n12+b.n32*b.n13,j=b.n33*b.n11-b.n31*b.n13,k=-b.n32*b.n11+b.n31*b.n12,o=b.n23*b.n12-b.n22*b.n13,q=-b.n23*b.n11+b.n21*b.n13,n=b.n22*b.n11-b.n21*b.n12,b=b.n11*f+b.n21*g+b.n31*o;b==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");b=1/b;d[0]=b*f;d[1]=b*h;d[2]=b*i;d[3]=b*g;d[4]=b*j;d[5]=b*k;d[6]=b*o;d[7]=b*q;d[8]=b*n;return e};
 THREE.Matrix4.makeFrustum=function(b,e,d,f,h,i){var g;g=new THREE.Matrix4;g.n11=2*h/(e-b);g.n12=0;g.n13=(e+b)/(e-b);g.n14=0;g.n21=0;g.n22=2*h/(f-d);g.n23=(f+d)/(f-d);g.n24=0;g.n31=0;g.n32=0;g.n33=-(i+h)/(i-h);g.n34=-2*i*h/(i-h);g.n41=0;g.n42=0;g.n43=-1;g.n44=0;return g};THREE.Matrix4.makePerspective=function(b,e,d,f){var h,b=d*Math.tan(b*Math.PI/360);h=-b;return THREE.Matrix4.makeFrustum(h*e,b*e,h,b,d,f)};
 THREE.Matrix4.makeOrtho=function(b,e,d,f,h,i){var g,j,k,o;g=new THREE.Matrix4;j=e-b;k=d-f;o=i-h;g.n11=2/j;g.n12=0;g.n13=0;g.n14=-((e+b)/j);g.n21=0;g.n22=2/k;g.n23=0;g.n24=-((d+f)/k);g.n31=0;g.n32=0;g.n33=-2/o;g.n34=-((i+h)/o);g.n41=0;g.n42=0;g.n43=0;g.n44=1;return g};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;
@@ -51,9 +51,9 @@ this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.m
 this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,e=!0;for(var b=0,f=this.children.length;b<f;b++)this.children[b].update(this.matrixWorld,e,d)}};THREE.Quaternion=function(b,e,d,f){this.set(b||0,e||0,d||0,f!==void 0?f:1)};
 THREE.Quaternion.prototype={set:function(b,e,d,f){this.x=b;this.y=e;this.z=d;this.w=f;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},setFromEuler:function(b){var e=0.5*Math.PI/360,d=b.x*e,f=b.y*e,h=b.z*e,b=Math.cos(f),f=Math.sin(f),e=Math.cos(-h),h=Math.sin(-h),i=Math.cos(d),d=Math.sin(d),g=b*e,j=f*h;this.w=g*i-j*d;this.x=g*d+j*i;this.y=f*e*i+b*h*d;this.z=b*h*i-f*e*d;return this},setFromAxisAngle:function(b,e){var d=e/2,f=Math.sin(d);this.x=b.x*f;this.y=b.y*
 f;this.z=b.z*f;this.w=Math.cos(d);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 b=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);b==0?this.w=this.z=this.y=this.x=0:(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},
-multiplySelf:function(b){var e=this.x,d=this.y,f=this.z,h=this.w,i=b.x,g=b.y,j=b.z,b=b.w;this.x=e*b+h*i+d*j-f*g;this.y=d*b+h*g+f*i-e*j;this.z=f*b+h*j+e*g-d*i;this.w=h*b-e*i-d*g-f*j;return this},multiply:function(b,e){this.x=b.x*e.w+b.y*e.z-b.z*e.y+b.w*e.x;this.y=-b.x*e.z+b.y*e.w+b.z*e.x+b.w*e.y;this.z=b.x*e.y-b.y*e.x+b.z*e.w+b.w*e.z;this.w=-b.x*e.x-b.y*e.y-b.z*e.z+b.w*e.w;return this},multiplyVector3:function(b,e){e||(e=b);var d=b.x,f=b.y,h=b.z,i=this.x,g=this.y,j=this.z,k=this.w,o=k*d+g*h-j*f,p=
-k*f+j*d-i*h,n=k*h+i*f-g*d,d=-i*d-g*f-j*h;e.x=o*k+d*-i+p*-j-n*-g;e.y=p*k+d*-g+n*-i-o*-j;e.z=n*k+d*-j+o*-g-p*-i;return e}};
-THREE.Quaternion.slerp=function(b,e,d,f){var h=b.w*e.w+b.x*e.x+b.y*e.y+b.z*e.z;if(Math.abs(h)>=1)return d.w=b.w,d.x=b.x,d.y=b.y,d.z=b.z,d;var i=Math.acos(h),g=Math.sqrt(1-h*h);if(Math.abs(g)<0.001)return d.w=0.5*(b.w+e.w),d.x=0.5*(b.x+e.x),d.y=0.5*(b.y+e.y),d.z=0.5*(b.z+e.z),d;h=Math.sin((1-f)*i)/g;f=Math.sin(f*i)/g;d.w=b.w*h+e.w*f;d.x=b.x*h+e.x*f;d.y=b.y*h+e.y*f;d.z=b.z*h+e.z*f;return d};THREE.Vertex=function(b){this.position=b||new THREE.Vector3};
+multiplySelf:function(b){var e=this.x,d=this.y,f=this.z,h=this.w,i=b.x,g=b.y,j=b.z,b=b.w;this.x=e*b+h*i+d*j-f*g;this.y=d*b+h*g+f*i-e*j;this.z=f*b+h*j+e*g-d*i;this.w=h*b-e*i-d*g-f*j;return this},multiply:function(b,e){this.x=b.x*e.w+b.y*e.z-b.z*e.y+b.w*e.x;this.y=-b.x*e.z+b.y*e.w+b.z*e.x+b.w*e.y;this.z=b.x*e.y-b.y*e.x+b.z*e.w+b.w*e.z;this.w=-b.x*e.x-b.y*e.y-b.z*e.z+b.w*e.w;return this},multiplyVector3:function(b,e){e||(e=b);var d=b.x,f=b.y,h=b.z,i=this.x,g=this.y,j=this.z,k=this.w,o=k*d+g*h-j*f,q=
+k*f+j*d-i*h,n=k*h+i*f-g*d,d=-i*d-g*f-j*h;e.x=o*k+d*-i+q*-j-n*-g;e.y=q*k+d*-g+n*-i-o*-j;e.z=n*k+d*-j+o*-g-q*-i;return e}};
+THREE.Quaternion.slerp=function(b,e,d,f){var h=b.w*e.w+b.x*e.x+b.y*e.y+b.z*e.z;if(Math.abs(h)>=1)return d.w=b.w,d.x=b.x,d.y=b.y,d.z=b.z,d;var i=Math.acos(h),g=Math.sqrt(1-h*h);if(Math.abs(g)<0.0010)return d.w=0.5*(b.w+e.w),d.x=0.5*(b.x+e.x),d.y=0.5*(b.y+e.y),d.z=0.5*(b.z+e.z),d;h=Math.sin((1-f)*i)/g;f=Math.sin(f*i)/g;d.w=b.w*h+e.w*f;d.x=b.x*h+e.x*f;d.y=b.y*h+e.y*f;d.z=b.z*h+e.z*f;return d};THREE.Vertex=function(b){this.position=b||new THREE.Vector3};
 THREE.Face3=function(b,e,d,f,h,i){this.a=b;this.b=e;this.c=d;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=h instanceof THREE.Color?h:new THREE.Color;this.vertexColors=h instanceof Array?h:[];this.vertexTangents=[];this.materials=i instanceof Array?i:[i];this.centroid=new THREE.Vector3};
 THREE.Face4=function(b,e,d,f,h,i,g){this.a=b;this.b=e;this.c=d;this.d=f;this.normal=h instanceof THREE.Vector3?h:new THREE.Vector3;this.vertexNormals=h instanceof Array?h:[];this.color=i instanceof THREE.Color?i:new THREE.Color;this.vertexColors=i instanceof Array?i:[];this.vertexTangents=[];this.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};THREE.UV=function(b,e){this.set(b||0,e||0)};
 THREE.UV.prototype={set:function(b,e){this.u=b;this.v=e;return this},copy:function(b){this.set(b.u,b.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};
@@ -61,15 +61,15 @@ THREE.Geometry.prototype={computeCentroids:function(){var b,e,d;b=0;for(e=this.f
 d.centroid.addSelf(this.vertices[d.d].position),d.centroid.divideScalar(4))},computeFaceNormals:function(b){var e,d,f,h,i,g,j=new THREE.Vector3,k=new THREE.Vector3;f=0;for(h=this.faces.length;f<h;f++){i=this.faces[f];if(b&&i.vertexNormals.length){j.set(0,0,0);e=0;for(d=i.vertexNormals.length;e<d;e++)j.addSelf(i.vertexNormals[e]);j.divideScalar(3)}else e=this.vertices[i.a],d=this.vertices[i.b],g=this.vertices[i.c],j.sub(g.position,d.position),k.sub(e.position,d.position),j.crossSelf(k);j.isZero()||
 j.normalize();i.normal.copy(j)}},computeVertexNormals:function(){var b,e,d,f;if(this.__tmpVertices==void 0){f=this.__tmpVertices=Array(this.vertices.length);b=0;for(e=this.vertices.length;b<e;b++)f[b]=new THREE.Vector3;b=0;for(e=this.faces.length;b<e;b++)if(d=this.faces[b],d instanceof THREE.Face3)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(d instanceof THREE.Face4)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}else{f=
 this.__tmpVertices;b=0;for(e=this.vertices.length;b<e;b++)f[b].set(0,0,0)}b=0;for(e=this.faces.length;b<e;b++)d=this.faces[b],d instanceof THREE.Face3?(f[d.a].addSelf(d.normal),f[d.b].addSelf(d.normal),f[d.c].addSelf(d.normal)):d instanceof THREE.Face4&&(f[d.a].addSelf(d.normal),f[d.b].addSelf(d.normal),f[d.c].addSelf(d.normal),f[d.d].addSelf(d.normal));b=0;for(e=this.vertices.length;b<e;b++)f[b].normalize();b=0;for(e=this.faces.length;b<e;b++)d=this.faces[b],d instanceof THREE.Face3?(d.vertexNormals[0].copy(f[d.a]),
-d.vertexNormals[1].copy(f[d.b]),d.vertexNormals[2].copy(f[d.c])):d instanceof THREE.Face4&&(d.vertexNormals[0].copy(f[d.a]),d.vertexNormals[1].copy(f[d.b]),d.vertexNormals[2].copy(f[d.c]),d.vertexNormals[3].copy(f[d.d]))},computeTangents:function(){function b(b,c,e,d,f,h,i){j=b.vertices[c].position;k=b.vertices[e].position;o=b.vertices[d].position;p=g[f];n=g[h];q=g[i];w=k.x-j.x;y=o.x-j.x;D=k.y-j.y;z=o.y-j.y;C=k.z-j.z;ga=o.z-j.z;aa=n.u-p.u;O=q.u-p.u;F=n.v-p.v;v=q.v-p.v;M=1/(aa*v-O*F);na.set((v*w-F*
-y)*M,(v*D-F*z)*M,(v*C-F*ga)*M);U.set((aa*y-O*w)*M,(aa*z-O*D)*M,(aa*ga-O*C)*M);$[c].addSelf(na);$[e].addSelf(na);$[d].addSelf(na);K[c].addSelf(U);K[e].addSelf(U);K[d].addSelf(U)}var e,d,f,h,i,g,j,k,o,p,n,q,w,y,D,z,C,ga,aa,O,F,v,M,B,$=[],K=[],na=new THREE.Vector3,U=new THREE.Vector3,R=new THREE.Vector3,c=new THREE.Vector3,ha=new THREE.Vector3;e=0;for(d=this.vertices.length;e<d;e++)$[e]=new THREE.Vector3,K[e]=new THREE.Vector3;e=0;for(d=this.faces.length;e<d;e++)i=this.faces[e],g=this.faceVertexUvs[0][e],
-i instanceof THREE.Face3?b(this,i.a,i.b,i.c,0,1,2):i instanceof THREE.Face4&&(b(this,i.a,i.b,i.c,0,1,2),b(this,i.a,i.b,i.d,0,1,3));var S=["a","b","c","d"];e=0;for(d=this.faces.length;e<d;e++){i=this.faces[e];for(f=0;f<i.vertexNormals.length;f++)ha.copy(i.vertexNormals[f]),h=i[S[f]],B=$[h],R.copy(B),R.subSelf(ha.multiplyScalar(ha.dot(B))).normalize(),c.cross(i.vertexNormals[f],B),h=c.dot(K[h]),h=h<0?-1:1,i.vertexTangents[f]=new THREE.Vector4(R.x,R.y,R.z,h)}this.hasTangents=!0},computeBoundingBox:function(){var b;
+d.vertexNormals[1].copy(f[d.b]),d.vertexNormals[2].copy(f[d.c])):d instanceof THREE.Face4&&(d.vertexNormals[0].copy(f[d.a]),d.vertexNormals[1].copy(f[d.b]),d.vertexNormals[2].copy(f[d.c]),d.vertexNormals[3].copy(f[d.d]))},computeTangents:function(){function b(b,c,e,d,f,h,i){j=b.vertices[c].position;k=b.vertices[e].position;o=b.vertices[d].position;q=g[f];n=g[h];t=g[i];u=k.x-j.x;z=o.x-j.x;D=k.y-j.y;E=o.y-j.y;C=k.z-j.z;N=o.z-j.z;ea=n.u-q.u;S=t.u-q.u;H=n.v-q.v;y=t.v-q.v;aa=1/(ea*y-S*H);ua.set((y*u-H*
+z)*aa,(y*D-H*E)*aa,(y*C-H*N)*aa);K.set((ea*z-S*u)*aa,(ea*E-S*D)*aa,(ea*N-S*C)*aa);Q[c].addSelf(ua);Q[e].addSelf(ua);Q[d].addSelf(ua);B[c].addSelf(K);B[e].addSelf(K);B[d].addSelf(K)}var e,d,f,h,i,g,j,k,o,q,n,t,u,z,D,E,C,N,ea,S,H,y,aa,P,Q=[],B=[],ua=new THREE.Vector3,K=new THREE.Vector3,L=new THREE.Vector3,c=new THREE.Vector3,sa=new THREE.Vector3;e=0;for(d=this.vertices.length;e<d;e++)Q[e]=new THREE.Vector3,B[e]=new THREE.Vector3;e=0;for(d=this.faces.length;e<d;e++)i=this.faces[e],g=this.faceVertexUvs[0][e],
+i instanceof THREE.Face3?b(this,i.a,i.b,i.c,0,1,2):i instanceof THREE.Face4&&(b(this,i.a,i.b,i.c,0,1,2),b(this,i.a,i.b,i.d,0,1,3));var la=["a","b","c","d"];e=0;for(d=this.faces.length;e<d;e++){i=this.faces[e];for(f=0;f<i.vertexNormals.length;f++)sa.copy(i.vertexNormals[f]),h=i[la[f]],P=Q[h],L.copy(P),L.subSelf(sa.multiplyScalar(sa.dot(P))).normalize(),c.cross(i.vertexNormals[f],P),h=c.dot(B[h]),h=h<0?-1:1,i.vertexTangents[f]=new THREE.Vector4(L.x,L.y,L.z,h)}this.hasTangents=!0},computeBoundingBox:function(){var b;
 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 e=1,d=this.vertices.length;e<d;e++){b=this.vertices[e];if(b.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=b.position.x;else if(b.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=b.position.x;if(b.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=b.position.y;
 else if(b.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=b.position.y;if(b.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=b.position.z;else if(b.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=b.position.z}}},computeBoundingSphere:function(){for(var b=0,e=0,d=this.vertices.length;e<d;e++)b=Math.max(b,this.vertices[e].position.length());this.boundingSphere={radius:b}},computeEdgeFaces:function(){function b(b,e){return Math.min(b,e)+"_"+Math.max(b,e)}function e(b,e,d){b[e]===
 void 0?(b[e]={set:{},array:[]},b[e].set[d]=1,b[e].array.push(d)):b[e].set[d]===void 0&&(b[e].set[d]=1,b[e].array.push(d))}var d,f,h,i,g,j={};d=0;for(f=this.faces.length;d<f;d++)g=this.faces[d],g instanceof THREE.Face3?(h=b(g.a,g.b),e(j,h,d),h=b(g.b,g.c),e(j,h,d),h=b(g.a,g.c),e(j,h,d)):g instanceof THREE.Face4&&(h=b(g.b,g.d),e(j,h,d),h=b(g.a,g.b),e(j,h,d),h=b(g.a,g.d),e(j,h,d),h=b(g.b,g.c),e(j,h,d),h=b(g.c,g.d),e(j,h,d));d=0;for(f=this.edges.length;d<f;d++){g=this.edges[d];h=g.vertexIndices[0];i=g.vertexIndices[1];
 g.faceIndices=j[b(h,i)].array;for(h=0;h<g.faceIndices.length;h++)i=g.faceIndices[h],g.faces.push(this.faces[i])}}};THREE.GeometryIdCounter=0;
-THREE.Spline=function(b){function e(b,e,d,f,h,g,i){b=(d-b)*0.5;f=(f-e)*0.5;return(2*(e-d)+b+f)*i+(-3*(e-d)-2*b-f)*g+b*h+e}this.points=b;var d=[],f={x:0,y:0,z:0},h,i,g,j,k,o,p,n,q;this.initFromArray=function(b){this.points=[];for(var e=0;e<b.length;e++)this.points[e]={x:b[e][0],y:b[e][1],z:b[e][2]}};this.getPoint=function(b){h=(this.points.length-1)*b;i=Math.floor(h);g=h-i;d[0]=i==0?i:i-1;d[1]=i;d[2]=i>this.points.length-2?i:i+1;d[3]=i>this.points.length-3?i:i+2;o=this.points[d[0]];p=this.points[d[1]];
-n=this.points[d[2]];q=this.points[d[3]];j=g*g;k=g*j;f.x=e(o.x,p.x,n.x,q.x,g,j,k);f.y=e(o.y,p.y,n.y,q.y,g,j,k);f.z=e(o.z,p.z,n.z,q.z,g,j,k);return f};this.getControlPointsArray=function(){var b,e,d=this.points.length,f=[];for(b=0;b<d;b++)e=this.points[b],f[b]=[e.x,e.y,e.z];return f};this.getLength=function(b){var e,d,f=e=e=0,h=new THREE.Vector3,g=new THREE.Vector3,i=[],j=0;i[0]=0;b||(b=100);d=this.points.length*b;h.copy(this.points[0]);for(b=1;b<d;b++)e=b/d,position=this.getPoint(e),g.copy(position),
+THREE.Spline=function(b){function e(b,e,d,f,h,g,i){b=(d-b)*0.5;f=(f-e)*0.5;return(2*(e-d)+b+f)*i+(-3*(e-d)-2*b-f)*g+b*h+e}this.points=b;var d=[],f={x:0,y:0,z:0},h,i,g,j,k,o,q,n,t;this.initFromArray=function(b){this.points=[];for(var e=0;e<b.length;e++)this.points[e]={x:b[e][0],y:b[e][1],z:b[e][2]}};this.getPoint=function(b){h=(this.points.length-1)*b;i=Math.floor(h);g=h-i;d[0]=i==0?i:i-1;d[1]=i;d[2]=i>this.points.length-2?i:i+1;d[3]=i>this.points.length-3?i:i+2;o=this.points[d[0]];q=this.points[d[1]];
+n=this.points[d[2]];t=this.points[d[3]];j=g*g;k=g*j;f.x=e(o.x,q.x,n.x,t.x,g,j,k);f.y=e(o.y,q.y,n.y,t.y,g,j,k);f.z=e(o.z,q.z,n.z,t.z,g,j,k);return f};this.getControlPointsArray=function(){var b,e,d=this.points.length,f=[];for(b=0;b<d;b++)e=this.points[b],f[b]=[e.x,e.y,e.z];return f};this.getLength=function(b){var e,d,f=e=e=0,h=new THREE.Vector3,g=new THREE.Vector3,i=[],j=0;i[0]=0;b||(b=100);d=this.points.length*b;h.copy(this.points[0]);for(b=1;b<d;b++)e=b/d,position=this.getPoint(e),g.copy(position),
 j+=g.distanceTo(h),h.copy(position),e*=this.points.length-1,e=Math.floor(e),e!=f&&(i[e]=j,f=e);i[i.length]=j;return{chunks:i,total:j}};this.reparametrizeByArcLength=function(b){var e,d,f,h,g,i,j=[],o=new THREE.Vector3,k=this.getLength();j.push(o.copy(this.points[0]).clone());for(e=1;e<this.points.length;e++){d=k.chunks[e]-k.chunks[e-1];i=Math.ceil(b*d/k.total);h=(e-1)/(this.points.length-1);g=e/(this.points.length-1);for(d=1;d<i-1;d++)f=h+d*(1/i)*(g-h),position=this.getPoint(f),j.push(o.copy(position).clone());
 j.push(o.copy(this.points[e]).clone())}this.points=j}};THREE.Edge=function(b,e,d,f){this.vertices=[b,e];this.vertexIndices=[d,f];this.faces=[];this.faceIndices=[]};THREE.Camera=function(b,e,d,f,h){THREE.Object3D.call(this);this.fov=b||50;this.aspect=e||1;this.near=d||0.1;this.far=f||2E3;this.target=h||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};THREE.Camera.prototype=new THREE.Object3D;
 THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.supr=THREE.Object3D.prototype;THREE.Camera.prototype.translate=function(b,e){this.matrix.rotateAxis(e);e.multiplyScalar(b);this.position.addSelf(e);this.target.position.addSelf(e)};
@@ -128,32 +128,32 @@ THREE.LOD.prototype.supr=THREE.Object3D.prototype;THREE.LOD.prototype.add=functi
 THREE.LOD.prototype.update=function(b,e,d){this.matrixAutoUpdate&&(e|=this.updateMatrix());if(e||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,e=!0;if(this.LODs.length>1){b=d.matrixWorldInverse;b=-(b.n31*this.position.x+b.n32*this.position.y+b.n33*this.position.z+b.n34);this.LODs[0].object3D.visible=!0;for(var f=1;f<this.LODs.length;f++)if(b>=this.LODs[f].visibleAtDistance)this.LODs[f-1].object3D.visible=!1,
 this.LODs[f].object3D.visible=!0;else break;for(;f<this.LODs.length;f++)this.LODs[f].object3D.visible=!1}for(b=0;b<this.children.length;b++)this.children[b].update(this.matrixWorld,e,d)};THREE.ShadowVolume=function(b,e){b instanceof THREE.Mesh?(THREE.Mesh.call(this,b.geometry,e?[new THREE.ShadowVolumeDynamicMaterial]:[new THREE.ShadowVolumeDynamicMaterial]),b.addChild(this)):THREE.Mesh.call(this,b,e?[new THREE.ShadowVolumeDynamicMaterial]:[new THREE.ShadowVolumeDynamicMaterial]);this.calculateShadowVolumeGeometry()};
 THREE.ShadowVolume.prototype=new THREE.Mesh;THREE.ShadowVolume.prototype.constructor=THREE.ShadowVolume;THREE.ShadowVolume.prototype.supr=THREE.Mesh.prototype;
-THREE.ShadowVolume.prototype.calculateShadowVolumeGeometry=function(){if(this.geometry.edges&&this.geometry.edges.length){var b,e,d,f,h,i,g,j,k,o,p,n,q,w,y=new THREE.Geometry;y.vertices=this.geometry.vertices;f=y.faces=this.geometry.faces;var D=y.egdes=this.geometry.edges,z=y.edgeFaces=[];h=0;var C=[];b=0;for(e=f.length;b<e;b++)if(d=f[b],C.push(h),h+=d instanceof THREE.Face3?3:4,d.vertexNormals[0]=d.normal,d.vertexNormals[1]=d.normal,d.vertexNormals[2]=d.normal,d instanceof THREE.Face4)d.vertexNormals[3]=
-d.normal;b=0;for(e=D.length;b<e;b++)j=D[b],d=j.faces[0],f=j.faces[1],h=j.faceIndices[0],i=j.faceIndices[1],g=j.vertexIndices[0],j=j.vertexIndices[1],d.a===g?(k="a",p=C[h]+0):d.b===g?(k="b",p=C[h]+1):d.c===g?(k="c",p=C[h]+2):d.d===g&&(k="d",p=C[h]+3),d.a===j?(k+="a",n=C[h]+0):d.b===j?(k+="b",n=C[h]+1):d.c===j?(k+="c",n=C[h]+2):d.d===j&&(k+="d",n=C[h]+3),f.a===g?(o="a",q=C[i]+0):f.b===g?(o="b",q=C[i]+1):f.c===g?(o="c",q=C[i]+2):f.d===g&&(o="d",q=C[i]+3),f.a===j?(o+="a",w=C[i]+0):f.b===j?(o+="b",w=C[i]+
-1):f.c===j?(o+="c",w=C[i]+2):f.d===j&&(o+="d",w=C[i]+3),k==="ac"||k==="ad"||k==="ca"||k==="da"?p>n&&(d=p,p=n,n=d):p<n&&(d=p,p=n,n=d),o==="ac"||o==="ad"||o==="ca"||o==="da"?q>w&&(d=q,q=w,w=d):q<w&&(d=q,q=w,w=d),d=new THREE.Face4(p,n,q,w),d.normal.set(1,0,0),z.push(d);this.geometry=y}else this.calculateShadowVolumeGeometryWithoutEdgeInfo(this.geometry)};
-THREE.ShadowVolume.prototype.calculateShadowVolumeGeometryWithoutEdgeInfo=function(b){this.geometry=new THREE.Geometry;this.geometry.boundingSphere=b.boundingSphere;this.geometry.edgeFaces=[];var e=this.geometry.vertices,d=this.geometry.faces,f=this.geometry.edgeFaces,h=b.faces,b=b.vertices,i=h.length,g,j,k,o,p,n=["a","b","c","d"];for(k=0;k<i;k++){j=e.length;g=h[k];g instanceof THREE.Face4?(o=4,j=new THREE.Face4(j,j+1,j+2,j+3)):(o=3,j=new THREE.Face3(j,j+1,j+2));j.normal.copy(g.normal);d.push(j);
-for(j=0;j<o;j++)p=b[g[n[j]]],e.push(new THREE.Vertex(p.position.clone()))}for(i=0;i<h.length-1;i++){b=d[i];for(g=i+1;g<h.length;g++)j=d[g],j=this.facesShareEdge(e,b,j),j!==void 0&&(j=new THREE.Face4(j.indices[0],j.indices[3],j.indices[2],j.indices[1]),j.normal.set(1,0,0),f.push(j))}};
-THREE.ShadowVolume.prototype.facesShareEdge=function(b,e,d){var f,h,i,g,j,k,o,p,n,q,w,y,D,z=0,C=["a","b","c","d"];f=e instanceof THREE.Face4?4:3;h=d instanceof THREE.Face4?4:3;for(y=0;y<f;y++){i=e[C[y]];j=b[i];for(D=0;D<h;D++)if(g=d[C[D]],k=b[g],Math.abs(j.position.x-k.position.x)<1.0E-4&&Math.abs(j.position.y-k.position.y)<1.0E-4&&Math.abs(j.position.z-k.position.z)<1.0E-4&&(z++,z===1&&(o=j,p=k,n=i,q=g,w=C[y]),z===2))return w+=C[y],w==="ad"||w==="ac"?{faces:[e,d],vertices:[o,p,k,j],indices:[n,q,
-g,i],vertexTypes:[1,2,2,1],extrudable:!0}:{faces:[e,d],vertices:[o,j,k,p],indices:[n,i,g,q],vertexTypes:[1,1,2,2],extrudable:!0}}};
+THREE.ShadowVolume.prototype.calculateShadowVolumeGeometry=function(){if(this.geometry.edges&&this.geometry.edges.length){var b,e,d,f,h,i,g,j,k,o,q,n,t,u,z=new THREE.Geometry;z.vertices=this.geometry.vertices;f=z.faces=this.geometry.faces;var D=z.egdes=this.geometry.edges,E=z.edgeFaces=[];h=0;var C=[];b=0;for(e=f.length;b<e;b++)if(d=f[b],C.push(h),h+=d instanceof THREE.Face3?3:4,d.vertexNormals[0]=d.normal,d.vertexNormals[1]=d.normal,d.vertexNormals[2]=d.normal,d instanceof THREE.Face4)d.vertexNormals[3]=
+d.normal;b=0;for(e=D.length;b<e;b++)j=D[b],d=j.faces[0],f=j.faces[1],h=j.faceIndices[0],i=j.faceIndices[1],g=j.vertexIndices[0],j=j.vertexIndices[1],d.a===g?(k="a",q=C[h]+0):d.b===g?(k="b",q=C[h]+1):d.c===g?(k="c",q=C[h]+2):d.d===g&&(k="d",q=C[h]+3),d.a===j?(k+="a",n=C[h]+0):d.b===j?(k+="b",n=C[h]+1):d.c===j?(k+="c",n=C[h]+2):d.d===j&&(k+="d",n=C[h]+3),f.a===g?(o="a",t=C[i]+0):f.b===g?(o="b",t=C[i]+1):f.c===g?(o="c",t=C[i]+2):f.d===g&&(o="d",t=C[i]+3),f.a===j?(o+="a",u=C[i]+0):f.b===j?(o+="b",u=C[i]+
+1):f.c===j?(o+="c",u=C[i]+2):f.d===j&&(o+="d",u=C[i]+3),k==="ac"||k==="ad"||k==="ca"||k==="da"?q>n&&(d=q,q=n,n=d):q<n&&(d=q,q=n,n=d),o==="ac"||o==="ad"||o==="ca"||o==="da"?t>u&&(d=t,t=u,u=d):t<u&&(d=t,t=u,u=d),d=new THREE.Face4(q,n,t,u),d.normal.set(1,0,0),E.push(d);this.geometry=z}else this.calculateShadowVolumeGeometryWithoutEdgeInfo(this.geometry)};
+THREE.ShadowVolume.prototype.calculateShadowVolumeGeometryWithoutEdgeInfo=function(b){this.geometry=new THREE.Geometry;this.geometry.boundingSphere=b.boundingSphere;this.geometry.edgeFaces=[];var e=this.geometry.vertices,d=this.geometry.faces,f=this.geometry.edgeFaces,h=b.faces,b=b.vertices,i=h.length,g,j,k,o,q,n=["a","b","c","d"];for(k=0;k<i;k++){j=e.length;g=h[k];g instanceof THREE.Face4?(o=4,j=new THREE.Face4(j,j+1,j+2,j+3)):(o=3,j=new THREE.Face3(j,j+1,j+2));j.normal.copy(g.normal);d.push(j);
+for(j=0;j<o;j++)q=b[g[n[j]]],e.push(new THREE.Vertex(q.position.clone()))}for(i=0;i<h.length-1;i++){b=d[i];for(g=i+1;g<h.length;g++)j=d[g],j=this.facesShareEdge(e,b,j),j!==void 0&&(j=new THREE.Face4(j.indices[0],j.indices[3],j.indices[2],j.indices[1]),j.normal.set(1,0,0),f.push(j))}};
+THREE.ShadowVolume.prototype.facesShareEdge=function(b,e,d){var f,h,i,g,j,k,o,q,n,t,u,z,D,E=0,C=["a","b","c","d"];f=e instanceof THREE.Face4?4:3;h=d instanceof THREE.Face4?4:3;for(z=0;z<f;z++){i=e[C[z]];j=b[i];for(D=0;D<h;D++)if(g=d[C[D]],k=b[g],Math.abs(j.position.x-k.position.x)<1.0E-4&&Math.abs(j.position.y-k.position.y)<1.0E-4&&Math.abs(j.position.z-k.position.z)<1.0E-4&&(E++,E===1&&(o=j,q=k,n=i,t=g,u=C[z]),E===2))return u+=C[z],u==="ad"||u==="ac"?{faces:[e,d],vertices:[o,q,k,j],indices:[n,t,
+g,i],vertexTypes:[1,2,2,1],extrudable:!0}:{faces:[e,d],vertices:[o,j,k,q],indices:[n,i,g,t],vertexTypes:[1,1,2,2],extrudable:!0}}};
 THREE.Sprite=function(b){THREE.Object3D.call(this);if(b.material!==void 0)this.material=b.material,this.map=void 0,this.blending=material.blending;else if(b.map!==void 0)this.map=b.map instanceof THREE.Texture?b.map:THREE.ImageUtils.loadTexture(b.map),this.material=void 0,this.blending=b.blending!==void 0?b.blending:THREE.NormalBlending;this.useScreenCoordinates=b.useScreenCoordinates!==void 0?b.useScreenCoordinates:!0;this.mergeWith3D=b.mergeWith3D!==void 0?b.mergeWith3D:!this.useScreenCoordinates;
 this.affectedByDistance=b.affectedByDistance!==void 0?b.affectedByDistance:!this.useScreenCoordinates;this.scaleByViewport=b.scaleByViewport!==void 0?b.scaleByViewport:!this.affectedByDistance;this.alignment=b.alignment instanceof THREE.Vector2?b.alignment:THREE.SpriteAlignment.center;this.rotation3d=this.rotation;this.rotation=0;this.opacity=1;this.uvOffset=new THREE.Vector2(0,0);this.uvScale=new THREE.Vector2(1,1)};THREE.Sprite.prototype=new THREE.Object3D;THREE.Sprite.prototype.constructor=THREE.Sprite;
 THREE.Sprite.prototype.supr=THREE.Object3D.prototype;THREE.Sprite.prototype.updateMatrix=function(){this.matrix.setPosition(this.position);this.rotation3d.set(0,0,this.rotation);this.matrix.setRotationFromEuler(this.rotation3d);if(this.scale.x!==1||this.scale.y!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,this.scale.y);this.matrixWorldNeedsUpdate=!0};THREE.SpriteAlignment={};THREE.SpriteAlignment.topLeft=new THREE.Vector2(1,-1);
 THREE.SpriteAlignment.topCenter=new THREE.Vector2(0,-1);THREE.SpriteAlignment.topRight=new THREE.Vector2(-1,-1);THREE.SpriteAlignment.centerLeft=new THREE.Vector2(1,0);THREE.SpriteAlignment.center=new THREE.Vector2(0,0);THREE.SpriteAlignment.centerRight=new THREE.Vector2(-1,0);THREE.SpriteAlignment.bottomLeft=new THREE.Vector2(1,1);THREE.SpriteAlignment.bottomCenter=new THREE.Vector2(0,1);THREE.SpriteAlignment.bottomRight=new THREE.Vector2(-1,1);
-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(b){this.supr.addChild.call(this,b);this.addChildRecurse(b)};
+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(b){this.supr.addChild.call(this,b);this.addChildRecurse(b)};
 THREE.Scene.prototype.addChildRecurse=function(b){if(b instanceof THREE.Light)this.lights.indexOf(b)===-1&&this.lights.push(b);else if(b instanceof THREE.Sound)this.sounds.indexOf(b)===-1&&this.sounds.push(b);else if(!(b instanceof THREE.Camera||b instanceof THREE.Bone)&&this.objects.indexOf(b)===-1)this.objects.push(b),this.__objectsAdded.push(b);for(var e=0;e<b.children.length;e++)this.addChildRecurse(b.children[e])};
 THREE.Scene.prototype.removeChild=function(b){this.supr.removeChild.call(this,b);this.removeChildRecurse(b)};THREE.Scene.prototype.removeChildRecurse=function(b){if(b instanceof THREE.Light){var e=this.lights.indexOf(b);e!==-1&&this.lights.splice(e,1)}else b instanceof THREE.Sound?(e=this.sounds.indexOf(b),e!==-1&&this.sounds.splice(e,1)):b instanceof THREE.Camera||(e=this.objects.indexOf(b),e!==-1&&(this.objects.splice(e,1),this.__objectsRemoved.push(b)));for(e=0;e<b.children.length;e++)this.removeChildRecurse(b.children[e])};
 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.Fog=function(b,e,d){this.color=new THREE.Color(b);this.near=e||1;this.far=d||1E3};THREE.FogExp2=function(b,e){this.color=new THREE.Color(b);this.density=e!==void 0?e:2.5E-4};
-THREE.Projector=function(){function b(){var b=k[j]=k[j]||new THREE.RenderableVertex;j++;return b}function e(b,e){return e.z-b.z}function d(b,e){var d=0,c=1,f=b.z+b.w,h=e.z+e.w,g=-b.z+b.w,i=-e.z+e.w;return f>=0&&h>=0&&g>=0&&i>=0?!0:f<0&&h<0||g<0&&i<0?!1:(f<0?d=Math.max(d,f/(f-h)):h<0&&(c=Math.min(c,f/(f-h))),g<0?d=Math.max(d,g/(g-i)):i<0&&(c=Math.min(c,g/(g-i))),c<d?!1:(b.lerpSelf(e,d),e.lerpSelf(b,1-c),!0))}var f,h,i=[],g,j,k=[],o,p,n=[],q,w=[],y,D,z=[],C,ga,aa=[],O=new THREE.Vector4,F=new THREE.Vector4,
-v=new THREE.Matrix4,M=new THREE.Matrix4,B=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],$=new THREE.Vector4,K=new THREE.Vector4;this.projectVector=function(b,e){v.multiply(e.projectionMatrix,e.matrixWorldInverse);v.multiplyVector3(b);return b};this.unprojectVector=function(b,e){v.multiply(e.matrixWorld,THREE.Matrix4.makeInvert(e.projectionMatrix));v.multiplyVector3(b);return b};this.projectObjects=function(b,d,g){var d=[],c,j,o;h=0;j=
-b.objects;b=0;for(c=j.length;b<c;b++){o=j[b];var k;if(!(k=!o.visible))if(k=o instanceof THREE.Mesh){a:{k=void 0;for(var p=o.matrixWorld,n=-o.geometry.boundingSphere.radius*Math.max(o.scale.x,Math.max(o.scale.y,o.scale.z)),q=0;q<6;q++)if(k=B[q].x*p.n14+B[q].y*p.n24+B[q].z*p.n34+B[q].w,k<=n){k=!1;break a}k=!0}k=!k}if(!k)k=i[h]=i[h]||new THREE.RenderableObject,h++,f=k,O.copy(o.position),v.multiplyVector3(O),f.object=o,f.z=O.z,d.push(f)}g&&d.sort(e);return d};this.projectScene=function(f,h,i){var c=[],
-O=h.near,S=h.far,ka,Q,J,la,E,L,G,N,ma,u,t,pa,ra,Ca,ua,Aa,za;ga=D=q=p=0;h.matrixAutoUpdate&&h.update(void 0,!0);f.update(void 0,!1,h);v.multiply(h.projectionMatrix,h.matrixWorldInverse);B[0].set(v.n41-v.n11,v.n42-v.n12,v.n43-v.n13,v.n44-v.n14);B[1].set(v.n41+v.n11,v.n42+v.n12,v.n43+v.n13,v.n44+v.n14);B[2].set(v.n41+v.n21,v.n42+v.n22,v.n43+v.n23,v.n44+v.n24);B[3].set(v.n41-v.n21,v.n42-v.n22,v.n43-v.n23,v.n44-v.n24);B[4].set(v.n41-v.n31,v.n42-v.n32,v.n43-v.n33,v.n44-v.n34);B[5].set(v.n41+v.n31,v.n42+
-v.n32,v.n43+v.n33,v.n44+v.n34);for(ka=0;ka<6;ka++)ma=B[ka],ma.divideScalar(Math.sqrt(ma.x*ma.x+ma.y*ma.y+ma.z*ma.z));ma=this.projectObjects(f,h,!0);f=0;for(ka=ma.length;f<ka;f++)if(u=ma[f].object,u.visible)if(t=u.matrixWorld,pa=u.matrixRotationWorld,ra=u.materials,Ca=u.overdraw,j=0,u instanceof THREE.Mesh){ua=u.geometry;la=ua.vertices;Aa=ua.faces;ua=ua.faceVertexUvs;Q=0;for(J=la.length;Q<J;Q++)g=b(),g.positionWorld.copy(la[Q].position),t.multiplyVector3(g.positionWorld),g.positionScreen.copy(g.positionWorld),
-v.multiplyVector4(g.positionScreen),g.positionScreen.x/=g.positionScreen.w,g.positionScreen.y/=g.positionScreen.w,g.visible=g.positionScreen.z>O&&g.positionScreen.z<S;la=0;for(Q=Aa.length;la<Q;la++){J=Aa[la];if(J instanceof THREE.Face3)if(E=k[J.a],L=k[J.b],G=k[J.c],E.visible&&L.visible&&G.visible&&(u.doubleSided||u.flipSided!=(G.positionScreen.x-E.positionScreen.x)*(L.positionScreen.y-E.positionScreen.y)-(G.positionScreen.y-E.positionScreen.y)*(L.positionScreen.x-E.positionScreen.x)<0))N=n[p]=n[p]||
-new THREE.RenderableFace3,p++,o=N,o.v1.copy(E),o.v2.copy(L),o.v3.copy(G);else continue;else if(J instanceof THREE.Face4)if(E=k[J.a],L=k[J.b],G=k[J.c],N=k[J.d],E.visible&&L.visible&&G.visible&&N.visible&&(u.doubleSided||u.flipSided!=((N.positionScreen.x-E.positionScreen.x)*(L.positionScreen.y-E.positionScreen.y)-(N.positionScreen.y-E.positionScreen.y)*(L.positionScreen.x-E.positionScreen.x)<0||(L.positionScreen.x-G.positionScreen.x)*(N.positionScreen.y-G.positionScreen.y)-(L.positionScreen.y-G.positionScreen.y)*
-(N.positionScreen.x-G.positionScreen.x)<0)))za=w[q]=w[q]||new THREE.RenderableFace4,q++,o=za,o.v1.copy(E),o.v2.copy(L),o.v3.copy(G),o.v4.copy(N);else continue;o.normalWorld.copy(J.normal);pa.multiplyVector3(o.normalWorld);o.centroidWorld.copy(J.centroid);t.multiplyVector3(o.centroidWorld);o.centroidScreen.copy(o.centroidWorld);v.multiplyVector3(o.centroidScreen);G=J.vertexNormals;E=0;for(L=G.length;E<L;E++)N=o.vertexNormalsWorld[E],N.copy(G[E]),pa.multiplyVector3(N);E=0;for(L=ua.length;E<L;E++)if(za=
-ua[E][la]){G=0;for(N=za.length;G<N;G++)o.uvs[E][G]=za[G]}o.meshMaterials=ra;o.faceMaterials=J.materials;o.overdraw=Ca;o.z=o.centroidScreen.z;c.push(o)}}else if(u instanceof THREE.Line){M.multiply(v,t);la=u.geometry.vertices;E=b();E.positionScreen.copy(la[0].position);M.multiplyVector4(E.positionScreen);Q=1;for(J=la.length;Q<J;Q++)if(E=b(),E.positionScreen.copy(la[Q].position),M.multiplyVector4(E.positionScreen),L=k[j-2],$.copy(E.positionScreen),K.copy(L.positionScreen),d($,K))$.multiplyScalar(1/$.w),
-K.multiplyScalar(1/K.w),t=z[D]=z[D]||new THREE.RenderableLine,D++,y=t,y.v1.positionScreen.copy($),y.v2.positionScreen.copy(K),y.z=Math.max($.z,K.z),y.materials=u.materials,c.push(y)}else if(u instanceof THREE.Particle&&(F.set(u.matrixWorld.n14,u.matrixWorld.n24,u.matrixWorld.n34,1),v.multiplyVector4(F),F.z/=F.w,F.z>0&&F.z<1))t=aa[ga]=aa[ga]||new THREE.RenderableParticle,ga++,C=t,C.x=F.x/F.w,C.y=F.y/F.w,C.z=F.z,C.rotation=u.rotation.z,C.scale.x=u.scale.x*Math.abs(C.x-(F.x+h.projectionMatrix.n11)/(F.w+
-h.projectionMatrix.n14)),C.scale.y=u.scale.y*Math.abs(C.y-(F.y+h.projectionMatrix.n22)/(F.w+h.projectionMatrix.n24)),C.materials=u.materials,c.push(C);i&&c.sort(e);return c}};
+THREE.Projector=function(){function b(){var b=k[j]=k[j]||new THREE.RenderableVertex;j++;return b}function e(b,e){return e.z-b.z}function d(b,e){var d=0,c=1,f=b.z+b.w,h=e.z+e.w,g=-b.z+b.w,i=-e.z+e.w;return f>=0&&h>=0&&g>=0&&i>=0?!0:f<0&&h<0||g<0&&i<0?!1:(f<0?d=Math.max(d,f/(f-h)):h<0&&(c=Math.min(c,f/(f-h))),g<0?d=Math.max(d,g/(g-i)):i<0&&(c=Math.min(c,g/(g-i))),c<d?!1:(b.lerpSelf(e,d),e.lerpSelf(b,1-c),!0))}var f,h,i=[],g,j,k=[],o,q,n=[],t,u=[],z,D,E=[],C,N,ea=[],S=new THREE.Vector4,H=new THREE.Vector4,
+y=new THREE.Matrix4,aa=new THREE.Matrix4,P=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],Q=new THREE.Vector4,B=new THREE.Vector4;this.projectVector=function(b,e){y.multiply(e.projectionMatrix,e.matrixWorldInverse);y.multiplyVector3(b);return b};this.unprojectVector=function(b,e){y.multiply(e.matrixWorld,THREE.Matrix4.makeInvert(e.projectionMatrix));y.multiplyVector3(b);return b};this.projectObjects=function(b,d,g){var d=[],c,j,o;h=0;
+j=b.objects;b=0;for(c=j.length;b<c;b++){o=j[b];var k;if(!(k=!o.visible))if(k=o instanceof THREE.Mesh){a:{k=void 0;for(var q=o.matrixWorld,n=-o.geometry.boundingSphere.radius*Math.max(o.scale.x,Math.max(o.scale.y,o.scale.z)),t=0;t<6;t++)if(k=P[t].x*q.n14+P[t].y*q.n24+P[t].z*q.n34+P[t].w,k<=n){k=!1;break a}k=!0}k=!k}if(!k)k=i[h]=i[h]||new THREE.RenderableObject,h++,f=k,S.copy(o.position),y.multiplyVector3(S),f.object=o,f.z=S.z,d.push(f)}g&&d.sort(e);return d};this.projectScene=function(f,h,i){var c=
+[],S=h.near,la=h.far,ha,ma,M,na,F,$,T,R,pa,G,xa,va,qa,ra,ia,ta,ya;N=D=t=q=0;h.matrixAutoUpdate&&h.update(void 0,!0);f.update(void 0,!1,h);y.multiply(h.projectionMatrix,h.matrixWorldInverse);P[0].set(y.n41-y.n11,y.n42-y.n12,y.n43-y.n13,y.n44-y.n14);P[1].set(y.n41+y.n11,y.n42+y.n12,y.n43+y.n13,y.n44+y.n14);P[2].set(y.n41+y.n21,y.n42+y.n22,y.n43+y.n23,y.n44+y.n24);P[3].set(y.n41-y.n21,y.n42-y.n22,y.n43-y.n23,y.n44-y.n24);P[4].set(y.n41-y.n31,y.n42-y.n32,y.n43-y.n33,y.n44-y.n34);P[5].set(y.n41+y.n31,
+y.n42+y.n32,y.n43+y.n33,y.n44+y.n34);for(ha=0;ha<6;ha++)pa=P[ha],pa.divideScalar(Math.sqrt(pa.x*pa.x+pa.y*pa.y+pa.z*pa.z));pa=this.projectObjects(f,h,!0);f=0;for(ha=pa.length;f<ha;f++)if(G=pa[f].object,G.visible)if(xa=G.matrixWorld,va=G.matrixRotationWorld,qa=G.materials,ra=G.overdraw,j=0,G instanceof THREE.Mesh){ia=G.geometry;na=ia.vertices;ta=ia.faces;ia=ia.faceVertexUvs;ma=0;for(M=na.length;ma<M;ma++)g=b(),g.positionWorld.copy(na[ma].position),xa.multiplyVector3(g.positionWorld),g.positionScreen.copy(g.positionWorld),
+y.multiplyVector4(g.positionScreen),g.positionScreen.x/=g.positionScreen.w,g.positionScreen.y/=g.positionScreen.w,g.visible=g.positionScreen.z>S&&g.positionScreen.z<la;na=0;for(ma=ta.length;na<ma;na++){M=ta[na];if(M instanceof THREE.Face3)if(F=k[M.a],$=k[M.b],T=k[M.c],F.visible&&$.visible&&T.visible&&(G.doubleSided||G.flipSided!=(T.positionScreen.x-F.positionScreen.x)*($.positionScreen.y-F.positionScreen.y)-(T.positionScreen.y-F.positionScreen.y)*($.positionScreen.x-F.positionScreen.x)<0))R=n[q]=
+n[q]||new THREE.RenderableFace3,q++,o=R,o.v1.copy(F),o.v2.copy($),o.v3.copy(T);else continue;else if(M instanceof THREE.Face4)if(F=k[M.a],$=k[M.b],T=k[M.c],R=k[M.d],F.visible&&$.visible&&T.visible&&R.visible&&(G.doubleSided||G.flipSided!=((R.positionScreen.x-F.positionScreen.x)*($.positionScreen.y-F.positionScreen.y)-(R.positionScreen.y-F.positionScreen.y)*($.positionScreen.x-F.positionScreen.x)<0||($.positionScreen.x-T.positionScreen.x)*(R.positionScreen.y-T.positionScreen.y)-($.positionScreen.y-
+T.positionScreen.y)*(R.positionScreen.x-T.positionScreen.x)<0)))ya=u[t]=u[t]||new THREE.RenderableFace4,t++,o=ya,o.v1.copy(F),o.v2.copy($),o.v3.copy(T),o.v4.copy(R);else continue;o.normalWorld.copy(M.normal);va.multiplyVector3(o.normalWorld);o.centroidWorld.copy(M.centroid);xa.multiplyVector3(o.centroidWorld);o.centroidScreen.copy(o.centroidWorld);y.multiplyVector3(o.centroidScreen);T=M.vertexNormals;F=0;for($=T.length;F<$;F++)R=o.vertexNormalsWorld[F],R.copy(T[F]),va.multiplyVector3(R);F=0;for($=
+ia.length;F<$;F++)if(ya=ia[F][na]){T=0;for(R=ya.length;T<R;T++)o.uvs[F][T]=ya[T]}o.meshMaterials=qa;o.faceMaterials=M.materials;o.overdraw=ra;o.z=o.centroidScreen.z;c.push(o)}}else if(G instanceof THREE.Line){aa.multiply(y,xa);na=G.geometry.vertices;F=b();F.positionScreen.copy(na[0].position);aa.multiplyVector4(F.positionScreen);ma=1;for(M=na.length;ma<M;ma++)if(F=b(),F.positionScreen.copy(na[ma].position),aa.multiplyVector4(F.positionScreen),$=k[j-2],Q.copy(F.positionScreen),B.copy($.positionScreen),
+d(Q,B))Q.multiplyScalar(1/Q.w),B.multiplyScalar(1/B.w),xa=E[D]=E[D]||new THREE.RenderableLine,D++,z=xa,z.v1.positionScreen.copy(Q),z.v2.positionScreen.copy(B),z.z=Math.max(Q.z,B.z),z.materials=G.materials,c.push(z)}else if(G instanceof THREE.Particle&&(H.set(G.matrixWorld.n14,G.matrixWorld.n24,G.matrixWorld.n34,1),y.multiplyVector4(H),H.z/=H.w,H.z>0&&H.z<1))xa=ea[N]=ea[N]||new THREE.RenderableParticle,N++,C=xa,C.x=H.x/H.w,C.y=H.y/H.w,C.z=H.z,C.rotation=G.rotation.z,C.scale.x=G.scale.x*Math.abs(C.x-
+(H.x+h.projectionMatrix.n11)/(H.w+h.projectionMatrix.n14)),C.scale.y=G.scale.y*Math.abs(C.y-(H.y+h.projectionMatrix.n22)/(H.w+h.projectionMatrix.n24)),C.materials=G.materials,c.push(C);i&&c.sort(e);return c}};
 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(b,e,d){d&&b.update(void 0,!1,e);var d=b.sounds,f,h=d.length;for(f=0;f<h;f++)b=d[f],this.soundPosition.set(b.matrixWorld.n14,b.matrixWorld.n24,b.matrixWorld.n34),this.soundPosition.subSelf(e.position),b.isPlaying&&b.isLoaded&&(b.isAddedToDOM||b.addToDOM(this.domElement),b.calculateVolumeAndPan(this.soundPosition))}};
 THREE.ShaderChunk={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",
 envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube envMap;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( envMap, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refractionRatio;\nuniform bool useRefract;\n#endif",
@@ -168,12 +168,12 @@ default_vertex:"#ifndef USE_MORPHTARGETS\n#ifndef USE_SKINNING\ngl_Position = pr
 THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:2,texture:null},envMap:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",
 value:new THREE.Color(16777215)},morphTargetInfluences:{type:"f",value:0}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightDistance:{type:"fv1",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},scale:{type:"f",value:1},
 map:{type:"t",value:0,texture:null},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}}};
-THREE.ShaderLib={lensFlareVertexTexture:{vertexShader:"uniform \tvec3 \tscreenPosition;\nuniform\tvec2\tscale;\nuniform\tfloat\trotation;\nuniform    int     renderType;\nuniform\tsampler2D\tocclusionMap;\nattribute \tvec2 \tposition;\nattribute  vec2\tUV;\nvarying\tvec2\tvUV;\nvarying\tfloat\tvVisibility;\nvoid main(void)\n{\nvUV = UV;\nvec2 pos = position;\nif( renderType == 2 ) {\nvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 )) +\ntexture2D( occlusionMap, vec2( 0.5, 0.1 )) +\ntexture2D( occlusionMap, vec2( 0.9, 0.1 )) +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 )) +\ntexture2D( occlusionMap, vec2( 0.9, 0.9 )) +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 )) +\ntexture2D( occlusionMap, vec2( 0.1, 0.9 )) +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 )) +\ntexture2D( occlusionMap, vec2( 0.5, 0.5 ));\nvVisibility = (       visibility.r / 9.0 ) *\n( 1.0 - visibility.g / 9.0 ) *\n(       visibility.b / 9.0 ) *\n( 1.0 - visibility.a / 9.0 );\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4(( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform\tsampler2D\tmap;\nuniform\tfloat\t\topacity;\nuniform    int         renderType;\nvarying\tvec2\t\tvUV;\nvarying\tfloat\t\tvVisibility;\nvoid main( void )\n{\nif( renderType == 0 ) {\ngl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity * vVisibility;\ngl_FragColor = color;\n}\n}"},
-lensFlare:{vertexShader:"uniform \tvec3 \tscreenPosition;\nuniform\tvec2\tscale;\nuniform\tfloat\trotation;\nuniform    int     renderType;\nattribute \tvec2 \tposition;\nattribute  vec2\tUV;\nvarying\tvec2\tvUV;\nvoid main(void)\n{\nvUV = UV;\nvec2 pos = position;\nif( renderType == 2 ) {\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4(( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",
-fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform\tsampler2D\tmap;\nuniform\tsampler2D\tocclusionMap;\nuniform\tfloat\t\topacity;\nuniform    int         renderType;\nvarying\tvec2\t\tvUV;\nvoid main( void )\n{\nif( renderType == 0 ) {\ngl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nfloat visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 )).a +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 )).a +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 )).a +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 )).a;\nvisibility = ( 1.0 - visibility / 4.0 );\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity * visibility;\ngl_FragColor = color;\n}\n}"},
-sprite:{vertexShader:"uniform\tint\t\tuseScreenCoordinates;\nuniform    int     affectedByDistance;\nuniform\tvec3\tscreenPosition;\nuniform \tmat4 \tmodelViewMatrix;\nuniform \tmat4 \tprojectionMatrix;\nuniform    float   rotation;\nuniform    vec2    scale;\nuniform    vec2    alignment;\nuniform    vec2    uvOffset;\nuniform\tvec2    uvScale;\nattribute \tvec2 \tposition;\nattribute  vec2\tuv;\nvarying\tvec2\tvUV;\nvoid main(void)\n{\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",
-fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform\tsampler2D\tmap;\nuniform\tfloat\t\topacity;\nvarying\tvec2\t\tvUV;\nvoid main( void )\n{\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity;\ngl_FragColor = color;\n}"},shadowPost:{vertexShader:"uniform \tmat4 \tprojectionMatrix;\nattribute \tvec3 \tposition;\nvoid main(void)\n{\ngl_Position = projectionMatrix * vec4( position, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform \tfloat \tdarkness;\nvoid main( void )\n{\ngl_FragColor = vec4( 0, 0, 0, darkness );\n}"},
-shadowVolumeDynamic:{uniforms:{directionalLightDirection:{type:"fv",value:[]}},vertexShader:"uniform \tvec3 \tdirectionalLightDirection;\nvoid main() {\nvec4 pos      = objectMatrix * vec4( position, 1.0 );\nvec3 norm     = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm )), 0.0 );\ngl_Position   = projectionMatrix * viewMatrix * ( pos + extruded );\n}",fragmentShader:"void main() {\ngl_FragColor = vec4( 1.0 );\n}"},
+THREE.ShaderLib={lensFlareVertexTexture:{vertexShader:"uniform \tvec3 \tscreenPosition;\nuniform\tvec2\tscale;\nuniform\tfloat\trotation;\nuniform    int     renderType;\nuniform\tsampler2D\tocclusionMap;\nattribute \tvec2 \tposition;\nattribute  vec2\tUV;\nvarying\tvec2\tvUV;\nvarying\tfloat\tvVisibility;\nvoid main() {\nvUV = UV;\nvec2 pos = position;\nif( renderType == 2 ) {\nvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.5 ) );\nvVisibility = (       visibility.r / 9.0 ) *\n( 1.0 - visibility.g / 9.0 ) *\n(       visibility.b / 9.0 ) *\n( 1.0 - visibility.a / 9.0 );\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform\tsampler2D\tmap;\nuniform\tfloat\t\topacity;\nuniform    int         renderType;\nvarying\tvec2\t\tvUV;\nvarying\tfloat\t\tvVisibility;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity * vVisibility;\ngl_FragColor = color;\n}\n}"},
+lensFlare:{vertexShader:"uniform \tvec3 \tscreenPosition;\nuniform\tvec2\tscale;\nuniform\tfloat\trotation;\nuniform    int     renderType;\nattribute \tvec2 \tposition;\nattribute  vec2\tUV;\nvarying\tvec2\tvUV;\nvoid main() {\nvUV = UV;\nvec2 pos = position;\nif( renderType == 2 ) {\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",
+fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform\tsampler2D\tmap;\nuniform\tsampler2D\tocclusionMap;\nuniform\tfloat\t\topacity;\nuniform    int         renderType;\nvarying\tvec2\t\tvUV;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nfloat visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;\nvisibility = ( 1.0 - visibility / 4.0 );\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity * visibility;\ngl_FragColor = color;\n}\n}"},
+sprite:{vertexShader:"uniform\tint\t\tuseScreenCoordinates;\nuniform    int     affectedByDistance;\nuniform\tvec3\tscreenPosition;\nuniform \tmat4 \tmodelViewMatrix;\nuniform \tmat4 \tprojectionMatrix;\nuniform    float   rotation;\nuniform    vec2    scale;\nuniform    vec2    alignment;\nuniform    vec2    uvOffset;\nuniform\tvec2    uvScale;\nattribute \tvec2 \tposition;\nattribute  vec2\tuv;\nvarying\tvec2\tvUV;\nvoid main() {\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",
+fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform\tsampler2D\tmap;\nuniform\tfloat\t\topacity;\nvarying\tvec2\t\tvUV;\nvoid main() {\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity;\ngl_FragColor = color;\n}"},shadowPost:{vertexShader:"uniform \tmat4 \tprojectionMatrix;\nattribute \tvec3 \tposition;\nvoid main() {\ngl_Position = projectionMatrix * vec4( position, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform \tfloat \tdarkness;\nvoid main() {\ngl_FragColor = vec4( 0, 0, 0, darkness );\n}"},
+shadowVolumeDynamic:{uniforms:{directionalLightDirection:{type:"fv",value:[]}},vertexShader:"uniform \tvec3 \tdirectionalLightDirection;\nvoid main() {\nvec4 pos      = objectMatrix * vec4( position, 1.0 );\nvec3 norm     = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm ) ), 0.0 );\ngl_Position   = projectionMatrix * viewMatrix * ( pos + extruded );\n}",fragmentShader:"void main() {\ngl_FragColor = vec4( 1.0 );\n}"},
 depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},fragmentShader:"uniform float mNear;\nuniform float mFar;\nuniform float opacity;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), opacity );\n}",vertexShader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{opacity:{type:"f",value:1}},
 fragmentShader:"uniform float opacity;\nvarying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n}",vertexShader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"},basic:{uniforms:THREE.UniformsLib.common,fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,
 THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:[THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.color_pars_vertex,
@@ -186,121 +186,119 @@ THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.Shade
 "void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",THREE.ShaderChunk.lights_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,
 THREE.ShaderChunk.default_vertex,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsLib.particle,fragmentShader:["uniform vec3 psColor;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_particle_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.ShaderChunk.map_particle_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["uniform float size;\nuniform float scale;",
 THREE.ShaderChunk.color_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n#ifdef USE_SIZEATTENUATION\ngl_PointSize = size * ( scale / length( mvPosition.xyz ) );\n#else\ngl_PointSize = size;\n#endif\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")}};
-THREE.WebGLRenderer=function(b){function e(b,e,d){var f,h,g,i=b.vertices,j=i.length,k=b.colors,o=k.length,r=b.__vertexArray,P=b.__colorArray,p=b.__sortArray,n=b.__dirtyVertices,q=b.__dirtyColors;if(d.sortParticles){_projScreenMatrix.multiplySelf(d.matrixWorld);for(f=0;f<j;f++)h=i[f].position,_vector3.copy(h),_projScreenMatrix.multiplyVector3(_vector3),p[f]=[_vector3.z,f];p.sort(function(b,c){return c[0]-b[0]});for(f=0;f<j;f++)h=i[p[f][1]].position,g=f*3,r[g]=h.x,r[g+1]=h.y,r[g+2]=h.z;for(f=0;f<o;f++)g=
-f*3,color=k[p[f][1]],P[g]=color.r,P[g+1]=color.g,P[g+2]=color.b}else{if(n)for(f=0;f<j;f++)h=i[f].position,g=f*3,r[g]=h.x,r[g+1]=h.y,r[g+2]=h.z;if(q)for(f=0;f<o;f++)color=k[f],g=f*3,P[g]=color.r,P[g+1]=color.g,P[g+2]=color.b}if(n||d.sortParticles)c.bindBuffer(c.ARRAY_BUFFER,b.__webglVertexBuffer),c.bufferData(c.ARRAY_BUFFER,r,e);if(q||d.sortParticles)c.bindBuffer(c.ARRAY_BUFFER,b.__webglColorBuffer),c.bufferData(c.ARRAY_BUFFER,P,e)}function d(b,e,d,f,h){f.program||R.initMaterial(f,e,d,h);var g=f.program,
-i=g.uniforms,j=f.uniforms;g!=S&&(c.useProgram(g),S=g);c.uniformMatrix4fv(i.projectionMatrix,!1,_projectionMatrixArray);if(d&&(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial||f instanceof THREE.LineBasicMaterial||f instanceof THREE.ParticleBasicMaterial||f.fog))if(j.fogColor.value=d.color,d instanceof THREE.Fog)j.fogNear.value=d.near,j.fogFar.value=d.far;else if(d instanceof THREE.FogExp2)j.fogDensity.value=d.density;if(f instanceof
-THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f.lights){var k,o,r=0,P=0,p=0,n,q,w,t,v=_lights,u=v.directional.colors,C=v.directional.positions,y=v.point.colors,D=v.point.positions,H=v.point.distances,z=0,s=0,d=o=t=0;for(k=e.length;d<k;d++)if(o=e[d],n=o.color,q=o.position,w=o.intensity,t=o.distance,o instanceof THREE.AmbientLight)r+=n.r,P+=n.g,p+=n.b;else if(o instanceof THREE.DirectionalLight)t=z*3,u[t]=n.r*w,u[t+1]=n.g*w,u[t+2]=n.b*w,C[t]=q.x,C[t+1]=q.y,C[t+2]=q.z,z+=1;else if(o instanceof
-THREE.PointLight)o=s*3,y[o]=n.r*w,y[o+1]=n.g*w,y[o+2]=n.b*w,D[o]=q.x,D[o+1]=q.y,D[o+2]=q.z,H[s]=t,s+=1;for(d=z*3;d<u.length;d++)u[d]=0;for(d=s*3;d<y.length;d++)y[d]=0;v.point.length=s;v.directional.length=z;v.ambient[0]=r;v.ambient[1]=P;v.ambient[2]=p;d=_lights;j.enableLighting.value=d.directional.length+d.point.length;j.ambientLightColor.value=d.ambient;j.directionalLightColor.value=d.directional.colors;j.directionalLightDirection.value=d.directional.positions;j.pointLightColor.value=d.point.colors;
-j.pointLightPosition.value=d.point.positions;j.pointLightDistance.value=d.point.distances}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial)j.diffuse.value=f.color,j.opacity.value=f.opacity,(j.map.texture=f.map)&&j.offsetRepeat.value.set(f.map.offset.x,f.map.offset.y,f.map.repeat.x,f.map.repeat.y),j.lightMap.texture=f.lightMap,j.envMap.texture=f.envMap,j.reflectivity.value=f.reflectivity,j.refractionRatio.value=f.refractionRatio,
-j.combine.value=f.combine,j.useRefract.value=f.envMap&&f.envMap.mapping instanceof THREE.CubeRefractionMapping;if(f instanceof THREE.LineBasicMaterial)j.diffuse.value=f.color,j.opacity.value=f.opacity;else if(f instanceof THREE.ParticleBasicMaterial)j.psColor.value=f.color,j.opacity.value=f.opacity,j.size.value=f.size,j.scale.value=_canvas.height/2,j.map.texture=f.map;else if(f instanceof THREE.MeshPhongMaterial)j.ambient.value=f.ambient,j.specular.value=f.specular,j.shininess.value=f.shininess;else if(f instanceof
-THREE.MeshDepthMaterial)j.mNear.value=b.near,j.mFar.value=b.far,j.opacity.value=f.opacity;else if(f instanceof THREE.MeshNormalMaterial)j.opacity.value=f.opacity;for(var A in j)if(P=g.uniforms[A])if(k=j[A],r=k.type,d=k.value,r=="i")c.uniform1i(P,d);else if(r=="f")c.uniform1f(P,d);else if(r=="fv1")c.uniform1fv(P,d);else if(r=="fv")c.uniform3fv(P,d);else if(r=="v2")c.uniform2f(P,d.x,d.y);else if(r=="v3")c.uniform3f(P,d.x,d.y,d.z);else if(r=="v4")c.uniform4f(P,d.x,d.y,d.z,d.w);else if(r=="c")c.uniform3f(P,
-d.r,d.g,d.b);else if(r=="t"&&(c.uniform1i(P,d),k=k.texture))if(k.image instanceof Array&&k.image.length==6){if(k.image.length==6){if(k.needsUpdate){if(k.__webglInit){c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webglTextureCube);for(r=0;r<6;++r)c.texSubImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+r,0,0,0,c.RGBA,c.UNSIGNED_BYTE,k.image[r])}else{k.image.__webglTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webglTextureCube);for(r=0;r<6;++r)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+
-r,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image[r]);k.__webglInit=!0}M(c.TEXTURE_CUBE_MAP,k,k.image[0]);c.bindTexture(c.TEXTURE_CUBE_MAP,null);k.needsUpdate=!1}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webglTextureCube)}}else B(k,d);c.uniformMatrix4fv(i.modelViewMatrix,!1,h._modelViewMatrixArray);c.uniformMatrix3fv(i.normalMatrix,!1,h._normalMatrixArray);(f instanceof THREE.MeshShaderMaterial||f instanceof THREE.MeshPhongMaterial||f.envMap)&&i.cameraPosition!==null&&c.uniform3f(i.cameraPosition,
-b.position.x,b.position.y,b.position.z);(f instanceof THREE.MeshShaderMaterial||f.envMap||f.skinning)&&i.objectMatrix!==null&&c.uniformMatrix4fv(i.objectMatrix,!1,h._objectMatrixArray);(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshShaderMaterial||f.skinning)&&i.viewMatrix!==null&&c.uniformMatrix4fv(i.viewMatrix,!1,_viewMatrixArray);if(f instanceof THREE.ShadowVolumeDynamicMaterial)b=j.directionalLightDirection.value,b[0]=-e[1].position.x,b[1]=
--e[1].position.y,b[2]=-e[1].position.z,c.uniform3fv(i.directionalLightDirection,b),c.uniformMatrix4fv(i.objectMatrix,!1,h._objectMatrixArray),c.uniformMatrix4fv(i.viewMatrix,!1,_viewMatrixArray);f.skinning&&(c.uniformMatrix4fv(i.cameraInverseMatrix,!1,_viewMatrixArray),c.uniformMatrix4fv(i.boneGlobalMatrices,!1,h.boneMatrices));return g}function f(b,e,f,h,g,i){if(h.opacity!=0){var j,b=d(b,e,f,h,i).attributes;if(!h.morphTargets&&b.position>=0)c.bindBuffer(c.ARRAY_BUFFER,g.__webglVertexBuffer),c.vertexAttribPointer(b.position,
-3,c.FLOAT,!1,0,0);else{e=h.program.attributes;i.morphTargetBase!==-1?(c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[i.morphTargetBase]),c.vertexAttribPointer(e.position,3,c.FLOAT,!1,0,0)):e.position>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglVertexBuffer),c.vertexAttribPointer(e.position,3,c.FLOAT,!1,0,0));if(i.morphTargetForcedOrder.length)for(var f=0,k=i.morphTargetForcedOrder,o=i.morphTargetInfluences;f<h.numSupportedMorphTargets&&f<k.length;)c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[k[f]]),
-c.vertexAttribPointer(e["morphTarget"+f],3,c.FLOAT,!1,0,0),i.__webglMorphTargetInfluences[f]=o[k[f]],f++;else{var k=[],p=-1,r=0,o=i.morphTargetInfluences,P,n=o.length,f=0;for(i.morphTargetBase!==-1&&(k[i.morphTargetBase]=!0);f<h.numSupportedMorphTargets;){for(P=0;P<n;P++)!k[P]&&o[P]>p&&(r=P,p=o[r]);c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[r]);c.vertexAttribPointer(e["morphTarget"+f],3,c.FLOAT,!1,0,0);i.__webglMorphTargetInfluences[f]=p;k[r]=1;p=-1;f++}}h.program.uniforms.morphTargetInfluences!==
-null&&c.uniform1fv(h.program.uniforms.morphTargetInfluences,i.__webglMorphTargetInfluences)}if(g.__webglCustomAttributes)for(j in g.__webglCustomAttributes)b[j]>=0&&(e=g.__webglCustomAttributes[j],c.bindBuffer(c.ARRAY_BUFFER,e.buffer),c.vertexAttribPointer(b[j],e.size,c.FLOAT,!1,0,0));b.color>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglColorBuffer),c.vertexAttribPointer(b.color,3,c.FLOAT,!1,0,0));b.normal>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglNormalBuffer),c.vertexAttribPointer(b.normal,3,c.FLOAT,
-!1,0,0));b.tangent>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglTangentBuffer),c.vertexAttribPointer(b.tangent,4,c.FLOAT,!1,0,0));b.uv>=0&&(g.__webglUVBuffer?(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUVBuffer),c.vertexAttribPointer(b.uv,2,c.FLOAT,!1,0,0),c.enableVertexAttribArray(b.uv)):c.disableVertexAttribArray(b.uv));b.uv2>=0&&(g.__webglUV2Buffer?(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUV2Buffer),c.vertexAttribPointer(b.uv2,2,c.FLOAT,!1,0,0),c.enableVertexAttribArray(b.uv2)):c.disableVertexAttribArray(b.uv2));
-h.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexABuffer),c.vertexAttribPointer(b.skinVertexA,4,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexBBuffer),c.vertexAttribPointer(b.skinVertexB,4,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinIndicesBuffer),c.vertexAttribPointer(b.skinIndex,4,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinWeightsBuffer),c.vertexAttribPointer(b.skinWeight,
-4,c.FLOAT,!1,0,0));i instanceof THREE.Mesh?(h.wireframe?(c.lineWidth(h.wireframeLinewidth),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglLineBuffer),c.drawElements(c.LINES,g.__webglLineCount,c.UNSIGNED_SHORT,0)):(c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglFaceBuffer),c.drawElements(c.TRIANGLES,g.__webglFaceCount,c.UNSIGNED_SHORT,0)),R.data.vertices+=g.__webglFaceCount,R.data.faces+=g.__webglFaceCount/3,R.data.drawCalls++):i instanceof THREE.Line?(i=i.type==THREE.LineStrip?c.LINE_STRIP:c.LINES,c.lineWidth(h.linewidth),
-c.drawArrays(i,0,g.__webglLineCount),R.data.drawCalls++):i instanceof THREE.ParticleSystem?(c.drawArrays(c.POINTS,0,g.__webglParticleCount),R.data.drawCalls++):i instanceof THREE.Ribbon&&(c.drawArrays(c.TRIANGLE_STRIP,0,g.__webglVertexCount),R.data.drawCalls++)}}function h(b,e,d){if(!b.__webglVertexBuffer)b.__webglVertexBuffer=c.createBuffer();if(!b.__webglNormalBuffer)b.__webglNormalBuffer=c.createBuffer();b.hasPos&&(c.bindBuffer(c.ARRAY_BUFFER,b.__webglVertexBuffer),c.bufferData(c.ARRAY_BUFFER,
-b.positionArray,c.DYNAMIC_DRAW),c.enableVertexAttribArray(e.attributes.position),c.vertexAttribPointer(e.attributes.position,3,c.FLOAT,!1,0,0));if(b.hasNormal){c.bindBuffer(c.ARRAY_BUFFER,b.__webglNormalBuffer);if(d==THREE.FlatShading){var f,h,g,i,j,k,o,r,p,n,q=b.count*3;for(n=0;n<q;n+=9)d=b.normalArray,f=d[n],h=d[n+1],g=d[n+2],i=d[n+3],k=d[n+4],r=d[n+5],j=d[n+6],o=d[n+7],p=d[n+8],f=(f+i+j)/3,h=(h+k+o)/3,g=(g+r+p)/3,d[n]=f,d[n+1]=h,d[n+2]=g,d[n+3]=f,d[n+4]=h,d[n+5]=g,d[n+6]=f,d[n+7]=h,d[n+8]=g}c.bufferData(c.ARRAY_BUFFER,
-b.normalArray,c.DYNAMIC_DRAW);c.enableVertexAttribArray(e.attributes.normal);c.vertexAttribPointer(e.attributes.normal,3,c.FLOAT,!1,0,0)}c.drawArrays(c.TRIANGLES,0,b.count);b.count=0}function i(b){if(J!=b.doubleSided)b.doubleSided?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE),J=b.doubleSided;if(la!=b.flipSided)b.flipSided?c.frontFace(c.CW):c.frontFace(c.CCW),la=b.flipSided}function g(b){L!=b&&(b?c.enable(c.DEPTH_TEST):c.disable(c.DEPTH_TEST),L=b)}function j(b,e,d){G!=b&&(b?c.enable(c.POLYGON_OFFSET_FILL):
-c.disable(c.POLYGON_OFFSET_FILL),G=b);if(b&&(_oldPolygonOffsetFactor!=e||_oldPolygonOffsetUnits!=d))c.polygonOffset(e,d),_oldPolygonOffsetFactor=e,_oldPolygonOffsetUnits=d}function k(b){_frustum[0].set(b.n41-b.n11,b.n42-b.n12,b.n43-b.n13,b.n44-b.n14);_frustum[1].set(b.n41+b.n11,b.n42+b.n12,b.n43+b.n13,b.n44+b.n14);_frustum[2].set(b.n41+b.n21,b.n42+b.n22,b.n43+b.n23,b.n44+b.n24);_frustum[3].set(b.n41-b.n21,b.n42-b.n22,b.n43-b.n23,b.n44-b.n24);_frustum[4].set(b.n41-b.n31,b.n42-b.n32,b.n43-b.n33,b.n44-
-b.n34);_frustum[5].set(b.n41+b.n31,b.n42+b.n32,b.n43+b.n33,b.n44+b.n34);for(var c,b=0;b<6;b++)c=_frustum[b],c.divideScalar(Math.sqrt(c.x*c.x+c.y*c.y+c.z*c.z))}function o(b){for(var c=b.matrixWorld,e=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),d=0;d<6;d++)if(b=_frustum[d].x*c.n14+_frustum[d].y*c.n24+_frustum[d].z*c.n34+_frustum[d].w,b<=e)return!1;return!0}function p(b,c){b.list[b.count]=c;b.count+=1}function n(b){var c,e,d=b.object,f=b.opaque,h=b.transparent;
-h.count=0;b=f.count=0;for(c=d.materials.length;b<c;b++)e=d.materials[b],e.transparent?p(h,e):p(f,e)}function q(b){var c,e,d,f,h=b.object,g=b.buffer,i=b.opaque,j=b.transparent;j.count=0;b=i.count=0;for(d=h.materials.length;b<d;b++)if(c=h.materials[b],c instanceof THREE.MeshFaceMaterial){c=0;for(e=g.materials.length;c<e;c++)(f=g.materials[c])&&(f.transparent?p(j,f):p(i,f))}else(f=c)&&(f.transparent?p(j,f):p(i,f))}function w(b,c){return c.z-b.z}function y(b){c.enable(c.POLYGON_OFFSET_FILL);c.polygonOffset(0.1,
-1);c.enable(c.STENCIL_TEST);c.enable(c.DEPTH_TEST);c.depthMask(!1);c.colorMask(!1,!1,!1,!1);c.stencilFunc(c.ALWAYS,1,255);c.stencilOpSeparate(c.BACK,c.KEEP,c.INCR,c.KEEP);c.stencilOpSeparate(c.FRONT,c.KEEP,c.DECR,c.KEEP);var e,d=b.lights.length,f,h=b.lights,g=[],i,j,k,o,r,n=b.__webglShadowVolumes.length;for(e=0;e<d;e++)if(f=b.lights[e],f instanceof THREE.DirectionalLight&&f.castShadow){g[0]=-f.position.x;g[1]=-f.position.y;g[2]=-f.position.z;for(r=0;r<n;r++)f=b.__webglShadowVolumes[r].object,i=b.__webglShadowVolumes[r].buffer,
-j=f.materials[0],j.program||R.initMaterial(j,h,void 0,f),j=j.program,k=j.uniforms,o=j.attributes,S!==j&&(c.useProgram(j),S=j,c.uniformMatrix4fv(k.projectionMatrix,!1,_projectionMatrixArray),c.uniformMatrix4fv(k.viewMatrix,!1,_viewMatrixArray),c.uniform3fv(k.directionalLightDirection,g)),f.matrixWorld.flattenToArray(f._objectMatrixArray),c.uniformMatrix4fv(k.objectMatrix,!1,f._objectMatrixArray),c.bindBuffer(c.ARRAY_BUFFER,i.__webglVertexBuffer),c.vertexAttribPointer(o.position,3,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,
-i.__webglNormalBuffer),c.vertexAttribPointer(o.normal,3,c.FLOAT,!1,0,0),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,i.__webglFaceBuffer),c.cullFace(c.FRONT),c.drawElements(c.TRIANGLES,i.__webglFaceCount,c.UNSIGNED_SHORT,0),c.cullFace(c.BACK),c.drawElements(c.TRIANGLES,i.__webglFaceCount,c.UNSIGNED_SHORT,0)}c.disable(c.POLYGON_OFFSET_FILL);c.colorMask(!0,!0,!0,!0);c.stencilFunc(c.NOTEQUAL,0,255);c.stencilOp(c.KEEP,c.KEEP,c.KEEP);c.disable(c.DEPTH_TEST);E=-1;S=u.program;c.useProgram(u.program);c.uniformMatrix4fv(u.projectionLocation,
-!1,_projectionMatrixArray);c.uniform1f(u.darknessLocation,u.darkness);c.bindBuffer(c.ARRAY_BUFFER,u.vertexBuffer);c.vertexAttribPointer(u.vertexLocation,3,c.FLOAT,!1,0,0);c.enableVertexAttribArray(u.vertexLocation);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.blendEquation(c.FUNC_ADD);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,u.elementBuffer);c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0);c.disable(c.STENCIL_TEST);c.enable(c.DEPTH_TEST);c.depthMask(Q)}function D(b,e){var d,f,h;d=_sprite.attributes;var g=
-_sprite.uniforms,i=_viewportHeight/_viewportWidth,j,k=[],o=_viewportWidth*0.5,r=_viewportHeight*0.5,n=!0;c.useProgram(_sprite.program);S=_sprite.program;E=-1;ra||(c.enableVertexAttribArray(_sprite.attributes.position),c.enableVertexAttribArray(_sprite.attributes.uv),ra=!0);c.disable(c.CULL_FACE);c.enable(c.BLEND);c.depthMask(!0);c.bindBuffer(c.ARRAY_BUFFER,_sprite.vertexBuffer);c.vertexAttribPointer(d.position,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(d.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
-_sprite.elementBuffer);c.uniformMatrix4fv(g.projectionMatrix,!1,_projectionMatrixArray);c.activeTexture(c.TEXTURE0);c.uniform1i(g.map,0);d=0;for(f=b.__webglSprites.length;d<f;d++)h=b.__webglSprites[d],h.useScreenCoordinates?h.z=-h.position.z:(h._modelViewMatrix.multiplyToArray(e.matrixWorldInverse,h.matrixWorld,h._modelViewMatrixArray),h.z=-h._modelViewMatrix.n34);b.__webglSprites.sort(w);d=0;for(f=b.__webglSprites.length;d<f;d++)h=b.__webglSprites[d],h.material===void 0&&h.map&&h.map.image&&h.map.image.width&&
-(h.useScreenCoordinates?(c.uniform1i(g.useScreenCoordinates,1),c.uniform3f(g.screenPosition,(h.position.x-o)/o,(r-h.position.y)/r,Math.max(0,Math.min(1,h.position.z)))):(c.uniform1i(g.useScreenCoordinates,0),c.uniform1i(g.affectedByDistance,h.affectedByDistance?1:0),c.uniformMatrix4fv(g.modelViewMatrix,!1,h._modelViewMatrixArray)),j=h.map.image.width/(h.scaleByViewport?_viewportHeight:1),k[0]=j*i*h.scale.x,k[1]=j*h.scale.y,c.uniform2f(g.uvScale,h.uvScale.x,h.uvScale.y),c.uniform2f(g.uvOffset,h.uvOffset.x,
-h.uvOffset.y),c.uniform2f(g.alignment,h.alignment.x,h.alignment.y),c.uniform1f(g.opacity,h.opacity),c.uniform1f(g.rotation,h.rotation),c.uniform2fv(g.scale,k),h.mergeWith3D&&!n?(c.enable(c.DEPTH_TEST),n=!0):!h.mergeWith3D&&n&&(c.disable(c.DEPTH_TEST),n=!1),v(h.blending),B(h.map,0),c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0));c.enable(c.CULL_FACE);c.enable(c.DEPTH_TEST);c.depthMask(Q)}function z(b,e){var d,f,h=b.__webglLensFlares.length,g,i,j,k=new THREE.Vector3,o=_viewportHeight/_viewportWidth,
-r=_viewportWidth*0.5,n=_viewportHeight*0.5,p=16/_viewportHeight,q=[p*o,p],w=[1,1,0],u=[1,1],y=t.uniforms;d=t.attributes;c.useProgram(t.program);S=t.program;E=-1;pa||(c.enableVertexAttribArray(t.attributes.vertex),c.enableVertexAttribArray(t.attributes.uv),pa=!0);c.uniform1i(y.occlusionMap,0);c.uniform1i(y.map,1);c.bindBuffer(c.ARRAY_BUFFER,t.vertexBuffer);c.vertexAttribPointer(d.vertex,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(d.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,t.elementBuffer);
-c.disable(c.CULL_FACE);c.depthMask(!1);c.activeTexture(c.TEXTURE0);c.bindTexture(c.TEXTURE_2D,t.occlusionTexture);c.activeTexture(c.TEXTURE1);for(f=0;f<h;f++)if(d=b.__webglLensFlares[f].object,k.set(d.matrixWorld.n14,d.matrixWorld.n24,d.matrixWorld.n34),e.matrixWorldInverse.multiplyVector3(k),e.projectionMatrix.multiplyVector3(k),w[0]=k.x,w[1]=k.y,w[2]=k.z,u[0]=w[0]*r+r,u[1]=w[1]*n+n,t.hasVertexTexture||u[0]>0&&u[0]<_viewportWidth&&u[1]>0&&u[1]<_viewportHeight){c.bindTexture(c.TEXTURE_2D,t.tempTexture);
-c.copyTexImage2D(c.TEXTURE_2D,0,c.RGB,u[0]-8,u[1]-8,16,16,0);c.uniform1i(y.renderType,0);c.uniform2fv(y.scale,q);c.uniform3fv(y.screenPosition,w);c.disable(c.BLEND);c.enable(c.DEPTH_TEST);c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0);c.bindTexture(c.TEXTURE_2D,t.occlusionTexture);c.copyTexImage2D(c.TEXTURE_2D,0,c.RGBA,u[0]-8,u[1]-8,16,16,0);c.uniform1i(y.renderType,1);c.disable(c.DEPTH_TEST);c.bindTexture(c.TEXTURE_2D,t.tempTexture);c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0);d.positionScreen.x=
-w[0];d.positionScreen.y=w[1];d.positionScreen.z=w[2];d.customUpdateCallback?d.customUpdateCallback(d):d.updateLensFlares();c.uniform1i(y.renderType,2);c.enable(c.BLEND);g=0;for(i=d.lensFlares.length;g<i;g++)if(j=d.lensFlares[g],j.opacity>0.001&&j.scale>0.001)w[0]=j.x,w[1]=j.y,w[2]=j.z,p=j.size*j.scale/_viewportHeight,q[0]=p*o,q[1]=p,c.uniform3fv(y.screenPosition,w),c.uniform2fv(y.scale,q),c.uniform1f(y.rotation,j.rotation),c.uniform1f(y.opacity,j.opacity),v(j.blending),B(j.texture,1),c.drawElements(c.TRIANGLES,
-6,c.UNSIGNED_SHORT,0)}c.enable(c.CULL_FACE);c.enable(c.DEPTH_TEST);c.depthMask(Q)}function C(b,c){b._modelViewMatrix.multiplyToArray(c.matrixWorldInverse,b.matrixWorld,b._modelViewMatrixArray);THREE.Matrix4.makeInvert3x3(b._modelViewMatrix).transposeIntoArray(b._normalMatrixArray)}function ga(b){var d,f,h,g;if(b instanceof THREE.Mesh){f=b.geometry;for(d in f.geometryGroups){h=f.geometryGroups[d];a:{for(var i=g=void 0,j=void 0,k=void 0,o=void 0,o=h.__materials,i=0,j=o.length;i<j;i++)if(k=o[i],k.attributes)for(g in k.attributes)if(k.attributes[g].needsUpdate){g=
-!0;break a}g=!1}if(f.__dirtyVertices||f.__dirtyMorphTargets||f.__dirtyElements||f.__dirtyUvs||f.__dirtyNormals||f.__dirtyColors||f.__dirtyTangents||g)if(g=h,i=b,j=c.DYNAMIC_DRAW,g.__inittedArrays){var n=o=k=void 0,r=void 0,p=n=void 0,q=void 0,w=void 0,t=void 0,u=void 0,v=void 0,y=void 0,C=void 0,D=void 0,z=void 0,I=void 0,H=void 0,E=void 0,s=r=t=r=w=q=void 0,A=void 0,m=A=s=q=void 0,F=void 0,K=m=A=s=n=n=p=t=r=m=A=s=F=m=A=s=F=m=A=s=void 0,B=0,G=0,R=0,U=0,J=0,L=0,T=0,M=0,ca=0,x=0,da=0,A=s=0,ea=g.__vertexArray,
-$=g.__uvArray,aa=g.__uv2Array,O=g.__normalArray,V=g.__tangentArray,fa=g.__colorArray,W=g.__skinVertexAArray,X=g.__skinVertexBArray,Y=g.__skinIndexArray,Z=g.__skinWeightArray,ga=g.__morphTargetsArrays,S=g.__webglCustomAttributes,m=void 0,N=g.__faceArray,Q=g.__lineArray,la=g.__needsSmoothNormals,v=g.__vertexColorType,u=g.__uvType,y=g.__normalType,ia=i.geometry,ka=ia.__dirtyVertices,ma=ia.__dirtyElements,ha=ia.__dirtyUvs,na=ia.__dirtyNormals,pa=ia.__dirtyTangents,ra=ia.__dirtyColors,Ba=ia.__dirtyMorphTargets,
-va=ia.vertices,Da=g.faces,Ga=ia.faces,Ea=ia.faceVertexUvs[0],Fa=ia.faceVertexUvs[1],wa=ia.skinVerticesA,xa=ia.skinVerticesB,ya=ia.skinIndices,sa=ia.skinWeights,ta=i instanceof THREE.ShadowVolume?ia.edgeFaces:void 0,qa=ia.morphTargets;if(S)for(K in S)S[K].offset=0,S[K].offsetSrc=0;k=0;for(o=Da.length;k<o;k++)if(n=Da[k],r=Ga[n],Ea&&(C=Ea[n]),Fa&&(D=Fa[n]),n=r.vertexNormals,p=r.normal,q=r.vertexColors,w=r.color,t=r.vertexTangents,r instanceof THREE.Face3){if(ka)z=va[r.a].position,I=va[r.b].position,
-H=va[r.c].position,ea[G]=z.x,ea[G+1]=z.y,ea[G+2]=z.z,ea[G+3]=I.x,ea[G+4]=I.y,ea[G+5]=I.z,ea[G+6]=H.x,ea[G+7]=H.y,ea[G+8]=H.z,G+=9;if(S)for(K in S)if(m=S[K],m.__original.needsUpdate)s=m.offset,A=m.offsetSrc,m.size===1?(m.boundTo===void 0||m.boundTo==="vertices"?(m.array[s+0]=m.value[r.a],m.array[s+1]=m.value[r.b],m.array[s+2]=m.value[r.c]):m.boundTo==="faces"?(m.array[s+0]=m.value[A],m.array[s+1]=m.value[A],m.array[s+2]=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(m.array[s+0]=m.value[A+
-0],m.array[s+1]=m.value[A+1],m.array[s+2]=m.value[A+2],m.offsetSrc+=3),m.offset+=3):(m.boundTo===void 0||m.boundTo==="vertices"?(z=m.value[r.a],I=m.value[r.b],H=m.value[r.c]):m.boundTo==="faces"?(z=m.value[A],I=m.value[A],H=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(z=m.value[A+0],I=m.value[A+1],H=m.value[A+2],m.offsetSrc+=3),m.size===2?(m.array[s+0]=z.x,m.array[s+1]=z.y,m.array[s+2]=I.x,m.array[s+3]=I.y,m.array[s+4]=H.x,m.array[s+5]=H.y,m.offset+=6):m.size===3?(m.type==="c"?(m.array[s+
-0]=z.r,m.array[s+1]=z.g,m.array[s+2]=z.b,m.array[s+3]=I.r,m.array[s+4]=I.g,m.array[s+5]=I.b,m.array[s+6]=H.r,m.array[s+7]=H.g,m.array[s+8]=H.b):(m.array[s+0]=z.x,m.array[s+1]=z.y,m.array[s+2]=z.z,m.array[s+3]=I.x,m.array[s+4]=I.y,m.array[s+5]=I.z,m.array[s+6]=H.x,m.array[s+7]=H.y,m.array[s+8]=H.z),m.offset+=9):(m.array[s+0]=z.x,m.array[s+1]=z.y,m.array[s+2]=z.z,m.array[s+3]=z.w,m.array[s+4]=I.x,m.array[s+5]=I.y,m.array[s+6]=I.z,m.array[s+7]=I.w,m.array[s+8]=H.x,m.array[s+9]=H.y,m.array[s+10]=H.z,
-m.array[s+11]=H.w,m.offset+=12));if(Ba){s=0;for(A=qa.length;s<A;s++)z=qa[s].vertices[r.a].position,I=qa[s].vertices[r.b].position,H=qa[s].vertices[r.c].position,m=ga[s],m[da+0]=z.x,m[da+1]=z.y,m[da+2]=z.z,m[da+3]=I.x,m[da+4]=I.y,m[da+5]=I.z,m[da+6]=H.x,m[da+7]=H.y,m[da+8]=H.z;da+=9}if(sa.length)s=sa[r.a],A=sa[r.b],m=sa[r.c],Z[x]=s.x,Z[x+1]=s.y,Z[x+2]=s.z,Z[x+3]=s.w,Z[x+4]=A.x,Z[x+5]=A.y,Z[x+6]=A.z,Z[x+7]=A.w,Z[x+8]=m.x,Z[x+9]=m.y,Z[x+10]=m.z,Z[x+11]=m.w,s=ya[r.a],A=ya[r.b],m=ya[r.c],Y[x]=s.x,Y[x+
-1]=s.y,Y[x+2]=s.z,Y[x+3]=s.w,Y[x+4]=A.x,Y[x+5]=A.y,Y[x+6]=A.z,Y[x+7]=A.w,Y[x+8]=m.x,Y[x+9]=m.y,Y[x+10]=m.z,Y[x+11]=m.w,s=wa[r.a],A=wa[r.b],m=wa[r.c],W[x]=s.x,W[x+1]=s.y,W[x+2]=s.z,W[x+3]=1,W[x+4]=A.x,W[x+5]=A.y,W[x+6]=A.z,W[x+7]=1,W[x+8]=m.x,W[x+9]=m.y,W[x+10]=m.z,W[x+11]=1,s=xa[r.a],A=xa[r.b],m=xa[r.c],X[x]=s.x,X[x+1]=s.y,X[x+2]=s.z,X[x+3]=1,X[x+4]=A.x,X[x+5]=A.y,X[x+6]=A.z,X[x+7]=1,X[x+8]=m.x,X[x+9]=m.y,X[x+10]=m.z,X[x+11]=1,x+=12;if(ra&&v)q.length==3&&v==THREE.VertexColors?(r=q[0],s=q[1],A=q[2]):
-A=s=r=w,fa[ca]=r.r,fa[ca+1]=r.g,fa[ca+2]=r.b,fa[ca+3]=s.r,fa[ca+4]=s.g,fa[ca+5]=s.b,fa[ca+6]=A.r,fa[ca+7]=A.g,fa[ca+8]=A.b,ca+=9;if(pa&&ia.hasTangents)q=t[0],w=t[1],r=t[2],V[T]=q.x,V[T+1]=q.y,V[T+2]=q.z,V[T+3]=q.w,V[T+4]=w.x,V[T+5]=w.y,V[T+6]=w.z,V[T+7]=w.w,V[T+8]=r.x,V[T+9]=r.y,V[T+10]=r.z,V[T+11]=r.w,T+=12;if(na&&y)if(n.length==3&&la)for(t=0;t<3;t++)p=n[t],O[L]=p.x,O[L+1]=p.y,O[L+2]=p.z,L+=3;else for(t=0;t<3;t++)O[L]=p.x,O[L+1]=p.y,O[L+2]=p.z,L+=3;if(ha&&C!==void 0&&u)for(t=0;t<3;t++)n=C[t],$[R]=
-n.u,$[R+1]=n.v,R+=2;if(ha&&D!==void 0&&u)for(t=0;t<3;t++)n=D[t],aa[U]=n.u,aa[U+1]=n.v,U+=2;ma&&(N[J]=B,N[J+1]=B+1,N[J+2]=B+2,J+=3,Q[M]=B,Q[M+1]=B+1,Q[M+2]=B,Q[M+3]=B+2,Q[M+4]=B+1,Q[M+5]=B+2,M+=6,B+=3)}else if(r instanceof THREE.Face4){if(ka)z=va[r.a].position,I=va[r.b].position,H=va[r.c].position,E=va[r.d].position,ea[G]=z.x,ea[G+1]=z.y,ea[G+2]=z.z,ea[G+3]=I.x,ea[G+4]=I.y,ea[G+5]=I.z,ea[G+6]=H.x,ea[G+7]=H.y,ea[G+8]=H.z,ea[G+9]=E.x,ea[G+10]=E.y,ea[G+11]=E.z,G+=12;if(S)for(K in S)if(m=S[K],m.__original.needsUpdate)s=
-m.offset,A=m.offsetSrc,m.size===1?(m.boundTo===void 0||m.boundTo==="vertices"?(m.array[s+0]=m.value[r.a],m.array[s+1]=m.value[r.b],m.array[s+2]=m.value[r.c],m.array[s+3]=m.value[r.d]):m.boundTo==="faces"?(m.array[s+0]=m.value[A],m.array[s+1]=m.value[A],m.array[s+2]=m.value[A],m.array[s+3]=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(m.array[s+0]=m.value[A+0],m.array[s+1]=m.value[A+1],m.array[s+2]=m.value[A+2],m.array[s+3]=m.value[A+3],m.offsetSrc+=4),m.offset+=4):(m.boundTo===void 0||m.boundTo===
-"vertices"?(z=m.value[r.a],I=m.value[r.b],H=m.value[r.c],E=m.value[r.d]):m.boundTo==="faces"?(z=m.value[A],I=m.value[A],H=m.value[A],E=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(z=m.value[A+0],I=m.value[A+1],H=m.value[A+2],E=m.value[A+3],m.offsetSrc+=4),m.size===2?(m.array[s+0]=z.x,m.array[s+1]=z.y,m.array[s+2]=I.x,m.array[s+3]=I.y,m.array[s+4]=H.x,m.array[s+5]=H.y,m.array[s+6]=E.x,m.array[s+7]=E.y,m.offset+=8):m.size===3?(m.type==="c"?(m.array[s+0]=z.r,m.array[s+1]=z.g,m.array[s+2]=z.b,
-m.array[s+3]=I.r,m.array[s+4]=I.g,m.array[s+5]=I.b,m.array[s+6]=H.r,m.array[s+7]=H.g,m.array[s+8]=H.b,m.array[s+9]=E.r,m.array[s+10]=E.g,m.array[s+11]=E.b):(m.array[s+0]=z.x,m.array[s+1]=z.y,m.array[s+2]=z.z,m.array[s+3]=I.x,m.array[s+4]=I.y,m.array[s+5]=I.z,m.array[s+6]=H.x,m.array[s+7]=H.y,m.array[s+8]=H.z,m.array[s+9]=E.x,m.array[s+10]=E.y,m.array[s+11]=E.z),m.offset+=12):(m.array[s+0]=z.x,m.array[s+1]=z.y,m.array[s+2]=z.z,m.array[s+3]=z.w,m.array[s+4]=I.x,m.array[s+5]=I.y,m.array[s+6]=I.z,m.array[s+
-7]=I.w,m.array[s+8]=H.x,m.array[s+9]=H.y,m.array[s+10]=H.z,m.array[s+11]=H.w,m.array[s+12]=E.x,m.array[s+13]=E.y,m.array[s+14]=E.z,m.array[s+15]=E.w,m.offset+=16));if(Ba){s=0;for(A=qa.length;s<A;s++)z=qa[s].vertices[r.a].position,I=qa[s].vertices[r.b].position,H=qa[s].vertices[r.c].position,E=qa[s].vertices[r.d].position,m=ga[s],m[da+0]=z.x,m[da+1]=z.y,m[da+2]=z.z,m[da+3]=I.x,m[da+4]=I.y,m[da+5]=I.z,m[da+6]=H.x,m[da+7]=H.y,m[da+8]=H.z,m[da+9]=E.x,m[da+10]=E.y,m[da+11]=E.z;da+=12}if(sa.length)s=sa[r.a],
-A=sa[r.b],m=sa[r.c],F=sa[r.d],Z[x]=s.x,Z[x+1]=s.y,Z[x+2]=s.z,Z[x+3]=s.w,Z[x+4]=A.x,Z[x+5]=A.y,Z[x+6]=A.z,Z[x+7]=A.w,Z[x+8]=m.x,Z[x+9]=m.y,Z[x+10]=m.z,Z[x+11]=m.w,Z[x+12]=F.x,Z[x+13]=F.y,Z[x+14]=F.z,Z[x+15]=F.w,s=ya[r.a],A=ya[r.b],m=ya[r.c],F=ya[r.d],Y[x]=s.x,Y[x+1]=s.y,Y[x+2]=s.z,Y[x+3]=s.w,Y[x+4]=A.x,Y[x+5]=A.y,Y[x+6]=A.z,Y[x+7]=A.w,Y[x+8]=m.x,Y[x+9]=m.y,Y[x+10]=m.z,Y[x+11]=m.w,Y[x+12]=F.x,Y[x+13]=F.y,Y[x+14]=F.z,Y[x+15]=F.w,s=wa[r.a],A=wa[r.b],m=wa[r.c],F=wa[r.d],W[x]=s.x,W[x+1]=s.y,W[x+2]=s.z,
-W[x+3]=1,W[x+4]=A.x,W[x+5]=A.y,W[x+6]=A.z,W[x+7]=1,W[x+8]=m.x,W[x+9]=m.y,W[x+10]=m.z,W[x+11]=1,W[x+12]=F.x,W[x+13]=F.y,W[x+14]=F.z,W[x+15]=1,s=xa[r.a],A=xa[r.b],m=xa[r.c],r=xa[r.d],X[x]=s.x,X[x+1]=s.y,X[x+2]=s.z,X[x+3]=1,X[x+4]=A.x,X[x+5]=A.y,X[x+6]=A.z,X[x+7]=1,X[x+8]=m.x,X[x+9]=m.y,X[x+10]=m.z,X[x+11]=1,X[x+12]=r.x,X[x+13]=r.y,X[x+14]=r.z,X[x+15]=1,x+=16;if(ra&&v)q.length==4&&v==THREE.VertexColors?(r=q[0],s=q[1],A=q[2],q=q[3]):q=A=s=r=w,fa[ca]=r.r,fa[ca+1]=r.g,fa[ca+2]=r.b,fa[ca+3]=s.r,fa[ca+4]=
-s.g,fa[ca+5]=s.b,fa[ca+6]=A.r,fa[ca+7]=A.g,fa[ca+8]=A.b,fa[ca+9]=q.r,fa[ca+10]=q.g,fa[ca+11]=q.b,ca+=12;if(pa&&ia.hasTangents)q=t[0],w=t[1],r=t[2],t=t[3],V[T]=q.x,V[T+1]=q.y,V[T+2]=q.z,V[T+3]=q.w,V[T+4]=w.x,V[T+5]=w.y,V[T+6]=w.z,V[T+7]=w.w,V[T+8]=r.x,V[T+9]=r.y,V[T+10]=r.z,V[T+11]=r.w,V[T+12]=t.x,V[T+13]=t.y,V[T+14]=t.z,V[T+15]=t.w,T+=16;if(na&&y)if(n.length==4&&la)for(t=0;t<4;t++)p=n[t],O[L]=p.x,O[L+1]=p.y,O[L+2]=p.z,L+=3;else for(t=0;t<4;t++)O[L]=p.x,O[L+1]=p.y,O[L+2]=p.z,L+=3;if(ha&&C!==void 0&&
-u)for(t=0;t<4;t++)n=C[t],$[R]=n.u,$[R+1]=n.v,R+=2;if(ha&&D!==void 0&&u)for(t=0;t<4;t++)n=D[t],aa[U]=n.u,aa[U+1]=n.v,U+=2;ma&&(N[J]=B,N[J+1]=B+1,N[J+2]=B+3,N[J+3]=B+1,N[J+4]=B+2,N[J+5]=B+3,J+=6,Q[M]=B,Q[M+1]=B+1,Q[M+2]=B,Q[M+3]=B+3,Q[M+4]=B+1,Q[M+5]=B+2,Q[M+6]=B+2,Q[M+7]=B+3,M+=8,B+=4)}if(ta){k=0;for(o=ta.length;k<o;k++)N[J]=ta[k].a,N[J+1]=ta[k].b,N[J+2]=ta[k].c,N[J+3]=ta[k].a,N[J+4]=ta[k].c,N[J+5]=ta[k].d,J+=6}ka&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglVertexBuffer),c.bufferData(c.ARRAY_BUFFER,ea,
-j));if(S)for(K in S)m=S[K],m.__original.needsUpdate&&(c.bindBuffer(c.ARRAY_BUFFER,m.buffer),c.bufferData(c.ARRAY_BUFFER,m.array,j));if(Ba){s=0;for(A=qa.length;s<A;s++)c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[s]),c.bufferData(c.ARRAY_BUFFER,ga[s],j)}ra&&ca>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglColorBuffer),c.bufferData(c.ARRAY_BUFFER,fa,j));na&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglNormalBuffer),c.bufferData(c.ARRAY_BUFFER,O,j));pa&&ia.hasTangents&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglTangentBuffer),
-c.bufferData(c.ARRAY_BUFFER,V,j));ha&&R>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUVBuffer),c.bufferData(c.ARRAY_BUFFER,$,j));ha&&U>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUV2Buffer),c.bufferData(c.ARRAY_BUFFER,aa,j));ma&&(c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglFaceBuffer),c.bufferData(c.ELEMENT_ARRAY_BUFFER,N,j),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglLineBuffer),c.bufferData(c.ELEMENT_ARRAY_BUFFER,Q,j));x>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexABuffer),c.bufferData(c.ARRAY_BUFFER,
+THREE.WebGLRenderer=function(b){function e(b,e,d){var f,h,g,i=b.vertices,j=i.length,k=b.colors,o=k.length,p=b.__vertexArray,O=b.__colorArray,q=b.__sortArray,n=b.__dirtyVertices,t=b.__dirtyColors;if(d.sortParticles){ia.multiplySelf(d.matrixWorld);for(f=0;f<j;f++)h=i[f].position,Da.copy(h),ia.multiplyVector3(Da),q[f]=[Da.z,f];q.sort(function(b,c){return c[0]-b[0]});for(f=0;f<j;f++)h=i[q[f][1]].position,g=f*3,p[g]=h.x,p[g+1]=h.y,p[g+2]=h.z;for(f=0;f<o;f++)g=f*3,color=k[q[f][1]],O[g]=color.r,O[g+1]=color.g,
+O[g+2]=color.b}else{if(n)for(f=0;f<j;f++)h=i[f].position,g=f*3,p[g]=h.x,p[g+1]=h.y,p[g+2]=h.z;if(t)for(f=0;f<o;f++)color=k[f],g=f*3,O[g]=color.r,O[g+1]=color.g,O[g+2]=color.b}if(n||d.sortParticles)c.bindBuffer(c.ARRAY_BUFFER,b.__webglVertexBuffer),c.bufferData(c.ARRAY_BUFFER,p,e);if(t||d.sortParticles)c.bindBuffer(c.ARRAY_BUFFER,b.__webglColorBuffer),c.bufferData(c.ARRAY_BUFFER,O,e)}function d(b,e,d,f,h){f.program||L.initMaterial(f,e,d,h);var g=f.program,i=g.uniforms,j=f.uniforms;g!=la&&(c.useProgram(g),
+la=g);c.uniformMatrix4fv(i.projectionMatrix,!1,ta);if(d&&(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial||f instanceof THREE.LineBasicMaterial||f instanceof THREE.ParticleBasicMaterial||f.fog))if(j.fogColor.value=d.color,d instanceof THREE.Fog)j.fogNear.value=d.near,j.fogFar.value=d.far;else if(d instanceof THREE.FogExp2)j.fogDensity.value=d.density;if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||
+f.lights){var k,o,p=0,O=0,q=0,n,t,u,y,v=Ga,r=v.directional.colors,C=v.directional.positions,z=v.point.colors,D=v.point.positions,I=v.point.distances,x=0,s=0,d=o=y=0;for(k=e.length;d<k;d++)if(o=e[d],n=o.color,t=o.position,u=o.intensity,y=o.distance,o instanceof THREE.AmbientLight)p+=n.r,O+=n.g,q+=n.b;else if(o instanceof THREE.DirectionalLight)y=x*3,r[y]=n.r*u,r[y+1]=n.g*u,r[y+2]=n.b*u,C[y]=t.x,C[y+1]=t.y,C[y+2]=t.z,x+=1;else if(o instanceof THREE.PointLight)o=s*3,z[o]=n.r*u,z[o+1]=n.g*u,z[o+2]=n.b*
+u,D[o]=t.x,D[o+1]=t.y,D[o+2]=t.z,I[s]=y,s+=1;for(d=x*3;d<r.length;d++)r[d]=0;for(d=s*3;d<z.length;d++)z[d]=0;v.point.length=s;v.directional.length=x;v.ambient[0]=p;v.ambient[1]=O;v.ambient[2]=q;d=Ga;j.enableLighting.value=d.directional.length+d.point.length;j.ambientLightColor.value=d.ambient;j.directionalLightColor.value=d.directional.colors;j.directionalLightDirection.value=d.directional.positions;j.pointLightColor.value=d.point.colors;j.pointLightPosition.value=d.point.positions;j.pointLightDistance.value=
+d.point.distances}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial)j.diffuse.value=f.color,j.opacity.value=f.opacity,(j.map.texture=f.map)&&j.offsetRepeat.value.set(f.map.offset.x,f.map.offset.y,f.map.repeat.x,f.map.repeat.y),j.lightMap.texture=f.lightMap,j.envMap.texture=f.envMap,j.reflectivity.value=f.reflectivity,j.refractionRatio.value=f.refractionRatio,j.combine.value=f.combine,j.useRefract.value=f.envMap&&f.envMap.mapping instanceof
+THREE.CubeRefractionMapping;if(f instanceof THREE.LineBasicMaterial)j.diffuse.value=f.color,j.opacity.value=f.opacity;else if(f instanceof THREE.ParticleBasicMaterial)j.psColor.value=f.color,j.opacity.value=f.opacity,j.size.value=f.size,j.scale.value=wa.height/2,j.map.texture=f.map;else if(f instanceof THREE.MeshPhongMaterial)j.ambient.value=f.ambient,j.specular.value=f.specular,j.shininess.value=f.shininess;else if(f instanceof THREE.MeshDepthMaterial)j.mNear.value=b.near,j.mFar.value=b.far,j.opacity.value=
+f.opacity;else if(f instanceof THREE.MeshNormalMaterial)j.opacity.value=f.opacity;for(var A in j)if(O=g.uniforms[A])if(k=j[A],p=k.type,d=k.value,p=="i")c.uniform1i(O,d);else if(p=="f")c.uniform1f(O,d);else if(p=="fv1")c.uniform1fv(O,d);else if(p=="fv")c.uniform3fv(O,d);else if(p=="v2")c.uniform2f(O,d.x,d.y);else if(p=="v3")c.uniform3f(O,d.x,d.y,d.z);else if(p=="v4")c.uniform4f(O,d.x,d.y,d.z,d.w);else if(p=="c")c.uniform3f(O,d.r,d.g,d.b);else if(p=="t"&&(c.uniform1i(O,d),k=k.texture))if(k.image instanceof
+Array&&k.image.length==6){if(k.image.length==6){if(k.needsUpdate){if(k.__webglInit){c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webglTextureCube);for(p=0;p<6;++p)c.texSubImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,0,0,c.RGBA,c.UNSIGNED_BYTE,k.image[p])}else{k.image.__webglTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webglTextureCube);for(p=0;p<6;++p)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image[p]);k.__webglInit=!0}aa(c.TEXTURE_CUBE_MAP,
+k,k.image[0]);c.bindTexture(c.TEXTURE_CUBE_MAP,null);k.needsUpdate=!1}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webglTextureCube)}}else P(k,d);c.uniformMatrix4fv(i.modelViewMatrix,!1,h._modelViewMatrixArray);c.uniformMatrix3fv(i.normalMatrix,!1,h._normalMatrixArray);(f instanceof THREE.MeshShaderMaterial||f instanceof THREE.MeshPhongMaterial||f.envMap)&&i.cameraPosition!==null&&c.uniform3f(i.cameraPosition,b.position.x,b.position.y,b.position.z);(f instanceof THREE.MeshShaderMaterial||
+f.envMap||f.skinning)&&i.objectMatrix!==null&&c.uniformMatrix4fv(i.objectMatrix,!1,h._objectMatrixArray);(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshShaderMaterial||f.skinning)&&i.viewMatrix!==null&&c.uniformMatrix4fv(i.viewMatrix,!1,ya);if(f instanceof THREE.ShadowVolumeDynamicMaterial)b=j.directionalLightDirection.value,b[0]=-e[1].position.x,b[1]=-e[1].position.y,b[2]=-e[1].position.z,c.uniform3fv(i.directionalLightDirection,b),c.uniformMatrix4fv(i.objectMatrix,
+!1,h._objectMatrixArray),c.uniformMatrix4fv(i.viewMatrix,!1,ya);f.skinning&&(c.uniformMatrix4fv(i.cameraInverseMatrix,!1,ya),c.uniformMatrix4fv(i.boneGlobalMatrices,!1,h.boneMatrices));return g}function f(b,e,f,h,g,i){if(h.opacity!=0){var j,b=d(b,e,f,h,i).attributes;if(!h.morphTargets&&b.position>=0)c.bindBuffer(c.ARRAY_BUFFER,g.__webglVertexBuffer),c.vertexAttribPointer(b.position,3,c.FLOAT,!1,0,0);else{e=h.program.attributes;i.morphTargetBase!==-1?(c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[i.morphTargetBase]),
+c.vertexAttribPointer(e.position,3,c.FLOAT,!1,0,0)):e.position>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglVertexBuffer),c.vertexAttribPointer(e.position,3,c.FLOAT,!1,0,0));if(i.morphTargetForcedOrder.length)for(var f=0,k=i.morphTargetForcedOrder,o=i.morphTargetInfluences;f<h.numSupportedMorphTargets&&f<k.length;)c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[k[f]]),c.vertexAttribPointer(e["morphTarget"+f],3,c.FLOAT,!1,0,0),i.__webglMorphTargetInfluences[f]=o[k[f]],f++;else{var k=[],q=-1,
+p=0,o=i.morphTargetInfluences,O,n=o.length,f=0;for(i.morphTargetBase!==-1&&(k[i.morphTargetBase]=!0);f<h.numSupportedMorphTargets;){for(O=0;O<n;O++)!k[O]&&o[O]>q&&(p=O,q=o[p]);c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[p]);c.vertexAttribPointer(e["morphTarget"+f],3,c.FLOAT,!1,0,0);i.__webglMorphTargetInfluences[f]=q;k[p]=1;q=-1;f++}}h.program.uniforms.morphTargetInfluences!==null&&c.uniform1fv(h.program.uniforms.morphTargetInfluences,i.__webglMorphTargetInfluences)}if(g.__webglCustomAttributes)for(j in g.__webglCustomAttributes)b[j]>=
+0&&(e=g.__webglCustomAttributes[j],c.bindBuffer(c.ARRAY_BUFFER,e.buffer),c.vertexAttribPointer(b[j],e.size,c.FLOAT,!1,0,0));b.color>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglColorBuffer),c.vertexAttribPointer(b.color,3,c.FLOAT,!1,0,0));b.normal>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglNormalBuffer),c.vertexAttribPointer(b.normal,3,c.FLOAT,!1,0,0));b.tangent>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglTangentBuffer),c.vertexAttribPointer(b.tangent,4,c.FLOAT,!1,0,0));b.uv>=0&&(g.__webglUVBuffer?(c.bindBuffer(c.ARRAY_BUFFER,
+g.__webglUVBuffer),c.vertexAttribPointer(b.uv,2,c.FLOAT,!1,0,0),c.enableVertexAttribArray(b.uv)):c.disableVertexAttribArray(b.uv));b.uv2>=0&&(g.__webglUV2Buffer?(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUV2Buffer),c.vertexAttribPointer(b.uv2,2,c.FLOAT,!1,0,0),c.enableVertexAttribArray(b.uv2)):c.disableVertexAttribArray(b.uv2));h.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexABuffer),c.vertexAttribPointer(b.skinVertexA,4,
+c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexBBuffer),c.vertexAttribPointer(b.skinVertexB,4,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinIndicesBuffer),c.vertexAttribPointer(b.skinIndex,4,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinWeightsBuffer),c.vertexAttribPointer(b.skinWeight,4,c.FLOAT,!1,0,0));i instanceof THREE.Mesh?(h.wireframe?(c.lineWidth(h.wireframeLinewidth),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglLineBuffer),c.drawElements(c.LINES,g.__webglLineCount,
+c.UNSIGNED_SHORT,0)):(c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglFaceBuffer),c.drawElements(c.TRIANGLES,g.__webglFaceCount,c.UNSIGNED_SHORT,0)),L.data.vertices+=g.__webglFaceCount,L.data.faces+=g.__webglFaceCount/3,L.data.drawCalls++):i instanceof THREE.Line?(i=i.type==THREE.LineStrip?c.LINE_STRIP:c.LINES,c.lineWidth(h.linewidth),c.drawArrays(i,0,g.__webglLineCount),L.data.drawCalls++):i instanceof THREE.ParticleSystem?(c.drawArrays(c.POINTS,0,g.__webglParticleCount),L.data.drawCalls++):i instanceof
+THREE.Ribbon&&(c.drawArrays(c.TRIANGLE_STRIP,0,g.__webglVertexCount),L.data.drawCalls++)}}function h(b,e,d){if(!b.__webglVertexBuffer)b.__webglVertexBuffer=c.createBuffer();if(!b.__webglNormalBuffer)b.__webglNormalBuffer=c.createBuffer();b.hasPos&&(c.bindBuffer(c.ARRAY_BUFFER,b.__webglVertexBuffer),c.bufferData(c.ARRAY_BUFFER,b.positionArray,c.DYNAMIC_DRAW),c.enableVertexAttribArray(e.attributes.position),c.vertexAttribPointer(e.attributes.position,3,c.FLOAT,!1,0,0));if(b.hasNormal){c.bindBuffer(c.ARRAY_BUFFER,
+b.__webglNormalBuffer);if(d==THREE.FlatShading){var f,h,g,i,j,k,o,p,q,n,t=b.count*3;for(n=0;n<t;n+=9)d=b.normalArray,f=d[n],h=d[n+1],g=d[n+2],i=d[n+3],k=d[n+4],p=d[n+5],j=d[n+6],o=d[n+7],q=d[n+8],f=(f+i+j)/3,h=(h+k+o)/3,g=(g+p+q)/3,d[n]=f,d[n+1]=h,d[n+2]=g,d[n+3]=f,d[n+4]=h,d[n+5]=g,d[n+6]=f,d[n+7]=h,d[n+8]=g}c.bufferData(c.ARRAY_BUFFER,b.normalArray,c.DYNAMIC_DRAW);c.enableVertexAttribArray(e.attributes.normal);c.vertexAttribPointer(e.attributes.normal,3,c.FLOAT,!1,0,0)}c.drawArrays(c.TRIANGLES,
+0,b.count);b.count=0}function i(b){if(M!=b.doubleSided)b.doubleSided?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE),M=b.doubleSided;if(na!=b.flipSided)b.flipSided?c.frontFace(c.CW):c.frontFace(c.CCW),na=b.flipSided}function g(b){$!=b&&(b?c.enable(c.DEPTH_TEST):c.disable(c.DEPTH_TEST),$=b)}function j(b,e,d){T!=b&&(b?c.enable(c.POLYGON_OFFSET_FILL):c.disable(c.POLYGON_OFFSET_FILL),T=b);if(b&&(R!=e||pa!=d))c.polygonOffset(e,d),R=e,pa=d}function k(b){ra[0].set(b.n41-b.n11,b.n42-b.n12,b.n43-b.n13,b.n44-
+b.n14);ra[1].set(b.n41+b.n11,b.n42+b.n12,b.n43+b.n13,b.n44+b.n14);ra[2].set(b.n41+b.n21,b.n42+b.n22,b.n43+b.n23,b.n44+b.n24);ra[3].set(b.n41-b.n21,b.n42-b.n22,b.n43-b.n23,b.n44-b.n24);ra[4].set(b.n41-b.n31,b.n42-b.n32,b.n43-b.n33,b.n44-b.n34);ra[5].set(b.n41+b.n31,b.n42+b.n32,b.n43+b.n33,b.n44+b.n34);for(var c,b=0;b<6;b++)c=ra[b],c.divideScalar(Math.sqrt(c.x*c.x+c.y*c.y+c.z*c.z))}function o(b){for(var c=b.matrixWorld,e=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),
+d=0;d<6;d++)if(b=ra[d].x*c.n14+ra[d].y*c.n24+ra[d].z*c.n34+ra[d].w,b<=e)return!1;return!0}function q(b,c){b.list[b.count]=c;b.count+=1}function n(b){var c,e,d=b.object,f=b.opaque,h=b.transparent;h.count=0;b=f.count=0;for(c=d.materials.length;b<c;b++)e=d.materials[b],e.transparent?q(h,e):q(f,e)}function t(b){var c,e,d,f,h=b.object,g=b.buffer,i=b.opaque,j=b.transparent;j.count=0;b=i.count=0;for(d=h.materials.length;b<d;b++)if(c=h.materials[b],c instanceof THREE.MeshFaceMaterial){c=0;for(e=g.materials.length;c<
+e;c++)(f=g.materials[c])&&(f.transparent?q(j,f):q(i,f))}else(f=c)&&(f.transparent?q(j,f):q(i,f))}function u(b,c){return c.z-b.z}function z(b){c.enable(c.POLYGON_OFFSET_FILL);c.polygonOffset(0.1,1);c.enable(c.STENCIL_TEST);c.enable(c.DEPTH_TEST);c.depthMask(!1);c.colorMask(!1,!1,!1,!1);c.stencilFunc(c.ALWAYS,1,255);c.stencilOpSeparate(c.BACK,c.KEEP,c.INCR,c.KEEP);c.stencilOpSeparate(c.FRONT,c.KEEP,c.DECR,c.KEEP);var e,d=b.lights.length,f,h=b.lights,g=[],i,j,k,o,p,n=b.__webglShadowVolumes.length;for(e=
+0;e<d;e++)if(f=b.lights[e],f instanceof THREE.DirectionalLight&&f.castShadow){g[0]=-f.position.x;g[1]=-f.position.y;g[2]=-f.position.z;for(p=0;p<n;p++)f=b.__webglShadowVolumes[p].object,i=b.__webglShadowVolumes[p].buffer,j=f.materials[0],j.program||L.initMaterial(j,h,void 0,f),j=j.program,k=j.uniforms,o=j.attributes,la!==j&&(c.useProgram(j),la=j,c.uniformMatrix4fv(k.projectionMatrix,!1,ta),c.uniformMatrix4fv(k.viewMatrix,!1,ya),c.uniform3fv(k.directionalLightDirection,g)),f.matrixWorld.flattenToArray(f._objectMatrixArray),
+c.uniformMatrix4fv(k.objectMatrix,!1,f._objectMatrixArray),c.bindBuffer(c.ARRAY_BUFFER,i.__webglVertexBuffer),c.vertexAttribPointer(o.position,3,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,i.__webglNormalBuffer),c.vertexAttribPointer(o.normal,3,c.FLOAT,!1,0,0),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,i.__webglFaceBuffer),c.cullFace(c.FRONT),c.drawElements(c.TRIANGLES,i.__webglFaceCount,c.UNSIGNED_SHORT,0),c.cullFace(c.BACK),c.drawElements(c.TRIANGLES,i.__webglFaceCount,c.UNSIGNED_SHORT,0)}c.disable(c.POLYGON_OFFSET_FILL);
+c.colorMask(!0,!0,!0,!0);c.stencilFunc(c.NOTEQUAL,0,255);c.stencilOp(c.KEEP,c.KEEP,c.KEEP);c.disable(c.DEPTH_TEST);F=-1;la=x.program;c.useProgram(x.program);c.uniformMatrix4fv(x.projectionLocation,!1,ta);c.uniform1f(x.darknessLocation,x.darkness);c.bindBuffer(c.ARRAY_BUFFER,x.vertexBuffer);c.vertexAttribPointer(x.vertexLocation,3,c.FLOAT,!1,0,0);c.enableVertexAttribArray(x.vertexLocation);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.blendEquation(c.FUNC_ADD);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.elementBuffer);
+c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0);c.disable(c.STENCIL_TEST);c.enable(c.DEPTH_TEST);c.depthMask(ma)}function D(b,e){var d,f,h;d=r.attributes;var g=r.uniforms,i=qa/va,j,k=[],o=va*0.5,p=qa*0.5,n=!0;c.useProgram(r.program);la=r.program;F=-1;Ha||(c.enableVertexAttribArray(r.attributes.position),c.enableVertexAttribArray(r.attributes.uv),Ha=!0);c.disable(c.CULL_FACE);c.enable(c.BLEND);c.depthMask(!0);c.bindBuffer(c.ARRAY_BUFFER,r.vertexBuffer);c.vertexAttribPointer(d.position,2,c.FLOAT,!1,
+16,0);c.vertexAttribPointer(d.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,r.elementBuffer);c.uniformMatrix4fv(g.projectionMatrix,!1,ta);c.activeTexture(c.TEXTURE0);c.uniform1i(g.map,0);d=0;for(f=b.__webglSprites.length;d<f;d++)h=b.__webglSprites[d],h.useScreenCoordinates?h.z=-h.position.z:(h._modelViewMatrix.multiplyToArray(e.matrixWorldInverse,h.matrixWorld,h._modelViewMatrixArray),h.z=-h._modelViewMatrix.n34);b.__webglSprites.sort(u);d=0;for(f=b.__webglSprites.length;d<f;d++)h=b.__webglSprites[d],
+h.material===void 0&&h.map&&h.map.image&&h.map.image.width&&(h.useScreenCoordinates?(c.uniform1i(g.useScreenCoordinates,1),c.uniform3f(g.screenPosition,(h.position.x-o)/o,(p-h.position.y)/p,Math.max(0,Math.min(1,h.position.z)))):(c.uniform1i(g.useScreenCoordinates,0),c.uniform1i(g.affectedByDistance,h.affectedByDistance?1:0),c.uniformMatrix4fv(g.modelViewMatrix,!1,h._modelViewMatrixArray)),j=h.map.image.width/(h.scaleByViewport?qa:1),k[0]=j*i*h.scale.x,k[1]=j*h.scale.y,c.uniform2f(g.uvScale,h.uvScale.x,
+h.uvScale.y),c.uniform2f(g.uvOffset,h.uvOffset.x,h.uvOffset.y),c.uniform2f(g.alignment,h.alignment.x,h.alignment.y),c.uniform1f(g.opacity,h.opacity),c.uniform1f(g.rotation,h.rotation),c.uniform2fv(g.scale,k),h.mergeWith3D&&!n?(c.enable(c.DEPTH_TEST),n=!0):!h.mergeWith3D&&n&&(c.disable(c.DEPTH_TEST),n=!1),y(h.blending),P(h.map,0),c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0));c.enable(c.CULL_FACE);c.enable(c.DEPTH_TEST);c.depthMask(ma)}function E(b,e){var d,f,h=b.__webglLensFlares.length,g,i,j,
+k=new THREE.Vector3,o=qa/va,p=va*0.5,n=qa*0.5,q=16/qa,t=[q*o,q],u=[1,1,0],r=[1,1],z=v.uniforms;d=v.attributes;c.useProgram(v.program);la=v.program;F=-1;Ia||(c.enableVertexAttribArray(v.attributes.vertex),c.enableVertexAttribArray(v.attributes.uv),Ia=!0);c.uniform1i(z.occlusionMap,0);c.uniform1i(z.map,1);c.bindBuffer(c.ARRAY_BUFFER,v.vertexBuffer);c.vertexAttribPointer(d.vertex,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(d.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,v.elementBuffer);c.disable(c.CULL_FACE);
+c.depthMask(!1);c.activeTexture(c.TEXTURE0);c.bindTexture(c.TEXTURE_2D,v.occlusionTexture);c.activeTexture(c.TEXTURE1);for(f=0;f<h;f++)if(d=b.__webglLensFlares[f].object,k.set(d.matrixWorld.n14,d.matrixWorld.n24,d.matrixWorld.n34),e.matrixWorldInverse.multiplyVector3(k),e.projectionMatrix.multiplyVector3(k),u[0]=k.x,u[1]=k.y,u[2]=k.z,r[0]=u[0]*p+p,r[1]=u[1]*n+n,v.hasVertexTexture||r[0]>0&&r[0]<va&&r[1]>0&&r[1]<qa){c.bindTexture(c.TEXTURE_2D,v.tempTexture);c.copyTexImage2D(c.TEXTURE_2D,0,c.RGB,r[0]-
+8,r[1]-8,16,16,0);c.uniform1i(z.renderType,0);c.uniform2fv(z.scale,t);c.uniform3fv(z.screenPosition,u);c.disable(c.BLEND);c.enable(c.DEPTH_TEST);c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0);c.bindTexture(c.TEXTURE_2D,v.occlusionTexture);c.copyTexImage2D(c.TEXTURE_2D,0,c.RGBA,r[0]-8,r[1]-8,16,16,0);c.uniform1i(z.renderType,1);c.disable(c.DEPTH_TEST);c.bindTexture(c.TEXTURE_2D,v.tempTexture);c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0);d.positionScreen.x=u[0];d.positionScreen.y=u[1];d.positionScreen.z=
+u[2];d.customUpdateCallback?d.customUpdateCallback(d):d.updateLensFlares();c.uniform1i(z.renderType,2);c.enable(c.BLEND);g=0;for(i=d.lensFlares.length;g<i;g++)if(j=d.lensFlares[g],j.opacity>0.0010&&j.scale>0.0010)u[0]=j.x,u[1]=j.y,u[2]=j.z,q=j.size*j.scale/qa,t[0]=q*o,t[1]=q,c.uniform3fv(z.screenPosition,u),c.uniform2fv(z.scale,t),c.uniform1f(z.rotation,j.rotation),c.uniform1f(z.opacity,j.opacity),y(j.blending),P(j.texture,1),c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0)}c.enable(c.CULL_FACE);
+c.enable(c.DEPTH_TEST);c.depthMask(ma)}function C(b,c){b._modelViewMatrix.multiplyToArray(c.matrixWorldInverse,b.matrixWorld,b._modelViewMatrixArray);THREE.Matrix4.makeInvert3x3(b._modelViewMatrix).transposeIntoArray(b._normalMatrixArray)}function N(b){var d,f,h,g;if(b instanceof THREE.Mesh){f=b.geometry;for(d in f.geometryGroups){h=f.geometryGroups[d];a:{for(var i=g=void 0,j=void 0,k=void 0,o=void 0,o=h.__materials,i=0,j=o.length;i<j;i++)if(k=o[i],k.attributes)for(g in k.attributes)if(k.attributes[g].needsUpdate){g=
+!0;break a}g=!1}if(f.__dirtyVertices||f.__dirtyMorphTargets||f.__dirtyElements||f.__dirtyUvs||f.__dirtyNormals||f.__dirtyColors||f.__dirtyTangents||g)if(g=h,i=b,j=c.DYNAMIC_DRAW,g.__inittedArrays){var n=o=k=void 0,p=void 0,q=n=void 0,t=void 0,u=void 0,r=void 0,y=void 0,v=void 0,z=void 0,C=void 0,D=void 0,x=void 0,J=void 0,I=void 0,E=void 0,s=p=r=p=u=t=void 0,A=void 0,m=A=s=t=void 0,F=void 0,H=m=A=s=n=n=q=r=p=m=A=s=F=m=A=s=F=m=A=s=void 0,B=0,G=0,P=0,T=0,L=0,K=0,U=0,M=0,ca=0,w=0,da=0,A=s=0,fa=g.__vertexArray,
+$=g.__uvArray,aa=g.__uv2Array,Q=g.__normalArray,V=g.__tangentArray,ga=g.__colorArray,W=g.__skinVertexAArray,X=g.__skinVertexBArray,Y=g.__skinIndexArray,Z=g.__skinWeightArray,ea=g.__morphTargetsArrays,S=g.__webglCustomAttributes,m=void 0,N=g.__faceArray,R=g.__lineArray,la=g.__needsSmoothNormals,v=g.__vertexColorType,y=g.__uvType,z=g.__normalType,ja=i.geometry,ma=ja.__dirtyVertices,na=ja.__dirtyElements,ha=ja.__dirtyUvs,pa=ja.__dirtyNormals,qa=ja.__dirtyTangents,ra=ja.__dirtyColors,sa=ja.__dirtyMorphTargets,
+ia=ja.vertices,ua=g.faces,xa=ja.faces,va=ja.faceVertexUvs[0],ya=ja.faceVertexUvs[1],oa=ja.skinVerticesA,ta=ja.skinVerticesB,wa=ja.skinIndices,Ba=ja.skinWeights,Ca=i instanceof THREE.ShadowVolume?ja.edgeFaces:void 0,Aa=ja.morphTargets;if(S)for(H in S)S[H].offset=0,S[H].offsetSrc=0;k=0;for(o=ua.length;k<o;k++)if(n=ua[k],p=xa[n],va&&(C=va[n]),ya&&(D=ya[n]),n=p.vertexNormals,q=p.normal,t=p.vertexColors,u=p.color,r=p.vertexTangents,p instanceof THREE.Face3){if(ma)x=ia[p.a].position,J=ia[p.b].position,
+I=ia[p.c].position,fa[G]=x.x,fa[G+1]=x.y,fa[G+2]=x.z,fa[G+3]=J.x,fa[G+4]=J.y,fa[G+5]=J.z,fa[G+6]=I.x,fa[G+7]=I.y,fa[G+8]=I.z,G+=9;if(S)for(H in S)if(m=S[H],m.__original.needsUpdate)s=m.offset,A=m.offsetSrc,m.size===1?(m.boundTo===void 0||m.boundTo==="vertices"?(m.array[s+0]=m.value[p.a],m.array[s+1]=m.value[p.b],m.array[s+2]=m.value[p.c]):m.boundTo==="faces"?(m.array[s+0]=m.value[A],m.array[s+1]=m.value[A],m.array[s+2]=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(m.array[s+0]=m.value[A+
+0],m.array[s+1]=m.value[A+1],m.array[s+2]=m.value[A+2],m.offsetSrc+=3),m.offset+=3):(m.boundTo===void 0||m.boundTo==="vertices"?(x=m.value[p.a],J=m.value[p.b],I=m.value[p.c]):m.boundTo==="faces"?(x=m.value[A],J=m.value[A],I=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(x=m.value[A+0],J=m.value[A+1],I=m.value[A+2],m.offsetSrc+=3),m.size===2?(m.array[s+0]=x.x,m.array[s+1]=x.y,m.array[s+2]=J.x,m.array[s+3]=J.y,m.array[s+4]=I.x,m.array[s+5]=I.y,m.offset+=6):m.size===3?(m.type==="c"?(m.array[s+
+0]=x.r,m.array[s+1]=x.g,m.array[s+2]=x.b,m.array[s+3]=J.r,m.array[s+4]=J.g,m.array[s+5]=J.b,m.array[s+6]=I.r,m.array[s+7]=I.g,m.array[s+8]=I.b):(m.array[s+0]=x.x,m.array[s+1]=x.y,m.array[s+2]=x.z,m.array[s+3]=J.x,m.array[s+4]=J.y,m.array[s+5]=J.z,m.array[s+6]=I.x,m.array[s+7]=I.y,m.array[s+8]=I.z),m.offset+=9):(m.array[s+0]=x.x,m.array[s+1]=x.y,m.array[s+2]=x.z,m.array[s+3]=x.w,m.array[s+4]=J.x,m.array[s+5]=J.y,m.array[s+6]=J.z,m.array[s+7]=J.w,m.array[s+8]=I.x,m.array[s+9]=I.y,m.array[s+10]=I.z,
+m.array[s+11]=I.w,m.offset+=12));if(sa){s=0;for(A=Aa.length;s<A;s++)x=Aa[s].vertices[p.a].position,J=Aa[s].vertices[p.b].position,I=Aa[s].vertices[p.c].position,m=ea[s],m[da+0]=x.x,m[da+1]=x.y,m[da+2]=x.z,m[da+3]=J.x,m[da+4]=J.y,m[da+5]=J.z,m[da+6]=I.x,m[da+7]=I.y,m[da+8]=I.z;da+=9}if(Ba.length)s=Ba[p.a],A=Ba[p.b],m=Ba[p.c],Z[w]=s.x,Z[w+1]=s.y,Z[w+2]=s.z,Z[w+3]=s.w,Z[w+4]=A.x,Z[w+5]=A.y,Z[w+6]=A.z,Z[w+7]=A.w,Z[w+8]=m.x,Z[w+9]=m.y,Z[w+10]=m.z,Z[w+11]=m.w,s=wa[p.a],A=wa[p.b],m=wa[p.c],Y[w]=s.x,Y[w+
+1]=s.y,Y[w+2]=s.z,Y[w+3]=s.w,Y[w+4]=A.x,Y[w+5]=A.y,Y[w+6]=A.z,Y[w+7]=A.w,Y[w+8]=m.x,Y[w+9]=m.y,Y[w+10]=m.z,Y[w+11]=m.w,s=oa[p.a],A=oa[p.b],m=oa[p.c],W[w]=s.x,W[w+1]=s.y,W[w+2]=s.z,W[w+3]=1,W[w+4]=A.x,W[w+5]=A.y,W[w+6]=A.z,W[w+7]=1,W[w+8]=m.x,W[w+9]=m.y,W[w+10]=m.z,W[w+11]=1,s=ta[p.a],A=ta[p.b],m=ta[p.c],X[w]=s.x,X[w+1]=s.y,X[w+2]=s.z,X[w+3]=1,X[w+4]=A.x,X[w+5]=A.y,X[w+6]=A.z,X[w+7]=1,X[w+8]=m.x,X[w+9]=m.y,X[w+10]=m.z,X[w+11]=1,w+=12;if(ra&&v)t.length==3&&v==THREE.VertexColors?(p=t[0],s=t[1],A=t[2]):
+A=s=p=u,ga[ca]=p.r,ga[ca+1]=p.g,ga[ca+2]=p.b,ga[ca+3]=s.r,ga[ca+4]=s.g,ga[ca+5]=s.b,ga[ca+6]=A.r,ga[ca+7]=A.g,ga[ca+8]=A.b,ca+=9;if(qa&&ja.hasTangents)t=r[0],u=r[1],p=r[2],V[U]=t.x,V[U+1]=t.y,V[U+2]=t.z,V[U+3]=t.w,V[U+4]=u.x,V[U+5]=u.y,V[U+6]=u.z,V[U+7]=u.w,V[U+8]=p.x,V[U+9]=p.y,V[U+10]=p.z,V[U+11]=p.w,U+=12;if(pa&&z)if(n.length==3&&la)for(r=0;r<3;r++)q=n[r],Q[K]=q.x,Q[K+1]=q.y,Q[K+2]=q.z,K+=3;else for(r=0;r<3;r++)Q[K]=q.x,Q[K+1]=q.y,Q[K+2]=q.z,K+=3;if(ha&&C!==void 0&&y)for(r=0;r<3;r++)n=C[r],$[P]=
+n.u,$[P+1]=n.v,P+=2;if(ha&&D!==void 0&&y)for(r=0;r<3;r++)n=D[r],aa[T]=n.u,aa[T+1]=n.v,T+=2;na&&(N[L]=B,N[L+1]=B+1,N[L+2]=B+2,L+=3,R[M]=B,R[M+1]=B+1,R[M+2]=B,R[M+3]=B+2,R[M+4]=B+1,R[M+5]=B+2,M+=6,B+=3)}else if(p instanceof THREE.Face4){if(ma)x=ia[p.a].position,J=ia[p.b].position,I=ia[p.c].position,E=ia[p.d].position,fa[G]=x.x,fa[G+1]=x.y,fa[G+2]=x.z,fa[G+3]=J.x,fa[G+4]=J.y,fa[G+5]=J.z,fa[G+6]=I.x,fa[G+7]=I.y,fa[G+8]=I.z,fa[G+9]=E.x,fa[G+10]=E.y,fa[G+11]=E.z,G+=12;if(S)for(H in S)if(m=S[H],m.__original.needsUpdate)s=
+m.offset,A=m.offsetSrc,m.size===1?(m.boundTo===void 0||m.boundTo==="vertices"?(m.array[s+0]=m.value[p.a],m.array[s+1]=m.value[p.b],m.array[s+2]=m.value[p.c],m.array[s+3]=m.value[p.d]):m.boundTo==="faces"?(m.array[s+0]=m.value[A],m.array[s+1]=m.value[A],m.array[s+2]=m.value[A],m.array[s+3]=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(m.array[s+0]=m.value[A+0],m.array[s+1]=m.value[A+1],m.array[s+2]=m.value[A+2],m.array[s+3]=m.value[A+3],m.offsetSrc+=4),m.offset+=4):(m.boundTo===void 0||m.boundTo===
+"vertices"?(x=m.value[p.a],J=m.value[p.b],I=m.value[p.c],E=m.value[p.d]):m.boundTo==="faces"?(x=m.value[A],J=m.value[A],I=m.value[A],E=m.value[A],m.offsetSrc++):m.boundTo==="faceVertices"&&(x=m.value[A+0],J=m.value[A+1],I=m.value[A+2],E=m.value[A+3],m.offsetSrc+=4),m.size===2?(m.array[s+0]=x.x,m.array[s+1]=x.y,m.array[s+2]=J.x,m.array[s+3]=J.y,m.array[s+4]=I.x,m.array[s+5]=I.y,m.array[s+6]=E.x,m.array[s+7]=E.y,m.offset+=8):m.size===3?(m.type==="c"?(m.array[s+0]=x.r,m.array[s+1]=x.g,m.array[s+2]=x.b,
+m.array[s+3]=J.r,m.array[s+4]=J.g,m.array[s+5]=J.b,m.array[s+6]=I.r,m.array[s+7]=I.g,m.array[s+8]=I.b,m.array[s+9]=E.r,m.array[s+10]=E.g,m.array[s+11]=E.b):(m.array[s+0]=x.x,m.array[s+1]=x.y,m.array[s+2]=x.z,m.array[s+3]=J.x,m.array[s+4]=J.y,m.array[s+5]=J.z,m.array[s+6]=I.x,m.array[s+7]=I.y,m.array[s+8]=I.z,m.array[s+9]=E.x,m.array[s+10]=E.y,m.array[s+11]=E.z),m.offset+=12):(m.array[s+0]=x.x,m.array[s+1]=x.y,m.array[s+2]=x.z,m.array[s+3]=x.w,m.array[s+4]=J.x,m.array[s+5]=J.y,m.array[s+6]=J.z,m.array[s+
+7]=J.w,m.array[s+8]=I.x,m.array[s+9]=I.y,m.array[s+10]=I.z,m.array[s+11]=I.w,m.array[s+12]=E.x,m.array[s+13]=E.y,m.array[s+14]=E.z,m.array[s+15]=E.w,m.offset+=16));if(sa){s=0;for(A=Aa.length;s<A;s++)x=Aa[s].vertices[p.a].position,J=Aa[s].vertices[p.b].position,I=Aa[s].vertices[p.c].position,E=Aa[s].vertices[p.d].position,m=ea[s],m[da+0]=x.x,m[da+1]=x.y,m[da+2]=x.z,m[da+3]=J.x,m[da+4]=J.y,m[da+5]=J.z,m[da+6]=I.x,m[da+7]=I.y,m[da+8]=I.z,m[da+9]=E.x,m[da+10]=E.y,m[da+11]=E.z;da+=12}if(Ba.length)s=Ba[p.a],
+A=Ba[p.b],m=Ba[p.c],F=Ba[p.d],Z[w]=s.x,Z[w+1]=s.y,Z[w+2]=s.z,Z[w+3]=s.w,Z[w+4]=A.x,Z[w+5]=A.y,Z[w+6]=A.z,Z[w+7]=A.w,Z[w+8]=m.x,Z[w+9]=m.y,Z[w+10]=m.z,Z[w+11]=m.w,Z[w+12]=F.x,Z[w+13]=F.y,Z[w+14]=F.z,Z[w+15]=F.w,s=wa[p.a],A=wa[p.b],m=wa[p.c],F=wa[p.d],Y[w]=s.x,Y[w+1]=s.y,Y[w+2]=s.z,Y[w+3]=s.w,Y[w+4]=A.x,Y[w+5]=A.y,Y[w+6]=A.z,Y[w+7]=A.w,Y[w+8]=m.x,Y[w+9]=m.y,Y[w+10]=m.z,Y[w+11]=m.w,Y[w+12]=F.x,Y[w+13]=F.y,Y[w+14]=F.z,Y[w+15]=F.w,s=oa[p.a],A=oa[p.b],m=oa[p.c],F=oa[p.d],W[w]=s.x,W[w+1]=s.y,W[w+2]=s.z,
+W[w+3]=1,W[w+4]=A.x,W[w+5]=A.y,W[w+6]=A.z,W[w+7]=1,W[w+8]=m.x,W[w+9]=m.y,W[w+10]=m.z,W[w+11]=1,W[w+12]=F.x,W[w+13]=F.y,W[w+14]=F.z,W[w+15]=1,s=ta[p.a],A=ta[p.b],m=ta[p.c],p=ta[p.d],X[w]=s.x,X[w+1]=s.y,X[w+2]=s.z,X[w+3]=1,X[w+4]=A.x,X[w+5]=A.y,X[w+6]=A.z,X[w+7]=1,X[w+8]=m.x,X[w+9]=m.y,X[w+10]=m.z,X[w+11]=1,X[w+12]=p.x,X[w+13]=p.y,X[w+14]=p.z,X[w+15]=1,w+=16;if(ra&&v)t.length==4&&v==THREE.VertexColors?(p=t[0],s=t[1],A=t[2],t=t[3]):t=A=s=p=u,ga[ca]=p.r,ga[ca+1]=p.g,ga[ca+2]=p.b,ga[ca+3]=s.r,ga[ca+4]=
+s.g,ga[ca+5]=s.b,ga[ca+6]=A.r,ga[ca+7]=A.g,ga[ca+8]=A.b,ga[ca+9]=t.r,ga[ca+10]=t.g,ga[ca+11]=t.b,ca+=12;if(qa&&ja.hasTangents)t=r[0],u=r[1],p=r[2],r=r[3],V[U]=t.x,V[U+1]=t.y,V[U+2]=t.z,V[U+3]=t.w,V[U+4]=u.x,V[U+5]=u.y,V[U+6]=u.z,V[U+7]=u.w,V[U+8]=p.x,V[U+9]=p.y,V[U+10]=p.z,V[U+11]=p.w,V[U+12]=r.x,V[U+13]=r.y,V[U+14]=r.z,V[U+15]=r.w,U+=16;if(pa&&z)if(n.length==4&&la)for(r=0;r<4;r++)q=n[r],Q[K]=q.x,Q[K+1]=q.y,Q[K+2]=q.z,K+=3;else for(r=0;r<4;r++)Q[K]=q.x,Q[K+1]=q.y,Q[K+2]=q.z,K+=3;if(ha&&C!==void 0&&
+y)for(r=0;r<4;r++)n=C[r],$[P]=n.u,$[P+1]=n.v,P+=2;if(ha&&D!==void 0&&y)for(r=0;r<4;r++)n=D[r],aa[T]=n.u,aa[T+1]=n.v,T+=2;na&&(N[L]=B,N[L+1]=B+1,N[L+2]=B+3,N[L+3]=B+1,N[L+4]=B+2,N[L+5]=B+3,L+=6,R[M]=B,R[M+1]=B+1,R[M+2]=B,R[M+3]=B+3,R[M+4]=B+1,R[M+5]=B+2,R[M+6]=B+2,R[M+7]=B+3,M+=8,B+=4)}if(Ca){k=0;for(o=Ca.length;k<o;k++)N[L]=Ca[k].a,N[L+1]=Ca[k].b,N[L+2]=Ca[k].c,N[L+3]=Ca[k].a,N[L+4]=Ca[k].c,N[L+5]=Ca[k].d,L+=6}ma&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglVertexBuffer),c.bufferData(c.ARRAY_BUFFER,fa,
+j));if(S)for(H in S)m=S[H],m.__original.needsUpdate&&(c.bindBuffer(c.ARRAY_BUFFER,m.buffer),c.bufferData(c.ARRAY_BUFFER,m.array,j));if(sa){s=0;for(A=Aa.length;s<A;s++)c.bindBuffer(c.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[s]),c.bufferData(c.ARRAY_BUFFER,ea[s],j)}ra&&ca>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglColorBuffer),c.bufferData(c.ARRAY_BUFFER,ga,j));pa&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglNormalBuffer),c.bufferData(c.ARRAY_BUFFER,Q,j));qa&&ja.hasTangents&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglTangentBuffer),
+c.bufferData(c.ARRAY_BUFFER,V,j));ha&&P>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUVBuffer),c.bufferData(c.ARRAY_BUFFER,$,j));ha&&T>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglUV2Buffer),c.bufferData(c.ARRAY_BUFFER,aa,j));na&&(c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglFaceBuffer),c.bufferData(c.ELEMENT_ARRAY_BUFFER,N,j),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webglLineBuffer),c.bufferData(c.ELEMENT_ARRAY_BUFFER,R,j));w>0&&(c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexABuffer),c.bufferData(c.ARRAY_BUFFER,
 W,j),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinVertexBBuffer),c.bufferData(c.ARRAY_BUFFER,X,j),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinIndicesBuffer),c.bufferData(c.ARRAY_BUFFER,Y,j),c.bindBuffer(c.ARRAY_BUFFER,g.__webglSkinWeightsBuffer),c.bufferData(c.ARRAY_BUFFER,Z,j));i.dynamic||(delete g.__inittedArrays,delete g.__colorArray,delete g.__normalArray,delete g.__tangentArray,delete g.__uvArray,delete g.__uv2Array,delete g.__faceArray,delete g.__vertexArray,delete g.__lineArray,delete g.__skinVertexAArray,
-delete g.__skinVertexBArray,delete g.__skinIndexArray,delete g.__skinWeightArray)}}f.__dirtyVertices=!1;f.__dirtyMorphTargets=!1;f.__dirtyElements=!1;f.__dirtyUvs=!1;f.__dirtyNormals=!1;f.__dirtyTangents=!1;f.__dirtyColors=!1;var ja;h=h.__materials;f=0;for(b=h.length;f<b;f++)if(d=h[f],d.attributes)for(ja in d.attributes)d.attributes[ja].needsUpdate=!1}else if(b instanceof THREE.Ribbon){f=b.geometry;if(f.__dirtyVertices||f.__dirtyColors){ja=f;b=c.DYNAMIC_DRAW;o=ja.vertices;h=ja.colors;u=o.length;g=
-h.length;v=ja.__vertexArray;i=ja.__colorArray;y=ja.__dirtyColors;if(ja.__dirtyVertices){for(j=0;j<u;j++)k=o[j].position,d=j*3,v[d]=k.x,v[d+1]=k.y,v[d+2]=k.z;c.bindBuffer(c.ARRAY_BUFFER,ja.__webglVertexBuffer);c.bufferData(c.ARRAY_BUFFER,v,b)}if(y){for(j=0;j<g;j++)color=h[j],d=j*3,i[d]=color.r,i[d+1]=color.g,i[d+2]=color.b;c.bindBuffer(c.ARRAY_BUFFER,ja.__webglColorBuffer);c.bufferData(c.ARRAY_BUFFER,i,b)}}f.__dirtyVertices=!1;f.__dirtyColors=!1}else if(b instanceof THREE.Line){f=b.geometry;if(f.__dirtyVertices||
-f.__dirtyColors){ja=f;b=c.DYNAMIC_DRAW;o=ja.vertices;h=ja.colors;u=o.length;g=h.length;v=ja.__vertexArray;i=ja.__colorArray;y=ja.__dirtyColors;if(ja.__dirtyVertices){for(j=0;j<u;j++)k=o[j].position,d=j*3,v[d]=k.x,v[d+1]=k.y,v[d+2]=k.z;c.bindBuffer(c.ARRAY_BUFFER,ja.__webglVertexBuffer);c.bufferData(c.ARRAY_BUFFER,v,b)}if(y){for(j=0;j<g;j++)color=h[j],d=j*3,i[d]=color.r,i[d+1]=color.g,i[d+2]=color.b;c.bindBuffer(c.ARRAY_BUFFER,ja.__webglColorBuffer);c.bufferData(c.ARRAY_BUFFER,i,b)}}f.__dirtyVertices=
-!1;f.__dirtyColors=!1}else if(b instanceof THREE.ParticleSystem)f=b.geometry,(f.__dirtyVertices||f.__dirtyColors||b.sortParticles)&&e(f,c.DYNAMIC_DRAW,b),f.__dirtyVertices=!1,f.__dirtyColors=!1}function aa(b,c){var d;for(d=b.length-1;d>=0;d--)b[d].object==c&&b.splice(d,1)}function O(b){function c(b){var f=[];d=0;for(e=b.length;d<e;d++)b[d]==void 0?f.push("undefined"):f.push(b[d].id);return f.join("_")}var d,e,f,g,h,i,j,k,r={},o=b.morphTargets!==void 0?b.morphTargets.length:0;b.geometryGroups={};f=
-0;for(g=b.faces.length;f<g;f++)h=b.faces[f],i=h.materials,j=c(i),r[j]==void 0&&(r[j]={hash:j,counter:0}),k=r[j].hash+"_"+r[j].counter,b.geometryGroups[k]==void 0&&(b.geometryGroups[k]={faces:[],materials:i,vertices:0,numMorphTargets:o}),h=h instanceof THREE.Face3?3:4,b.geometryGroups[k].vertices+h>65535&&(r[j].counter+=1,k=r[j].hash+"_"+r[j].counter,b.geometryGroups[k]==void 0&&(b.geometryGroups[k]={faces:[],materials:i,vertices:0,numMorphTargets:o})),b.geometryGroups[k].faces.push(f),b.geometryGroups[k].vertices+=
-h}function F(b,c,d){b.push({buffer:c,object:d,opaque:{list:[],count:0},transparent:{list:[],count:0}})}function v(b){if(b!=E){switch(b){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.SRC_ALPHA,c.ONE);break;case THREE.SubtractiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ZERO,c.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ZERO,c.SRC_COLOR);break;default:c.blendEquationSeparate(c.FUNC_ADD,c.FUNC_ADD),c.blendFuncSeparate(c.SRC_ALPHA,
-c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA)}E=b}}function M(b,d,e){(e.width&e.width-1)==0&&(e.height&e.height-1)==0?(c.texParameteri(b,c.TEXTURE_WRAP_S,U(d.wrapS)),c.texParameteri(b,c.TEXTURE_WRAP_T,U(d.wrapT)),c.texParameteri(b,c.TEXTURE_MAG_FILTER,U(d.magFilter)),c.texParameteri(b,c.TEXTURE_MIN_FILTER,U(d.minFilter)),c.generateMipmap(b)):(c.texParameteri(b,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(b,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texParameteri(b,c.TEXTURE_MAG_FILTER,na(d.magFilter)),
-c.texParameteri(b,c.TEXTURE_MIN_FILTER,na(d.minFilter)))}function B(b,d){if(b.needsUpdate)b.__webglInit?(c.bindTexture(c.TEXTURE_2D,b.__webglTexture),c.texSubImage2D(c.TEXTURE_2D,0,0,0,c.RGBA,c.UNSIGNED_BYTE,b.image)):(b.__webglTexture=c.createTexture(),c.bindTexture(c.TEXTURE_2D,b.__webglTexture),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,b.image),b.__webglInit=!0),M(c.TEXTURE_2D,b,b.image),c.bindTexture(c.TEXTURE_2D,null),b.needsUpdate=!1;c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,
-b.__webglTexture)}function $(b){if(b&&!b.__webglFramebuffer){if(b.depthBuffer===void 0)b.depthBuffer=!0;if(b.stencilBuffer===void 0)b.stencilBuffer=!0;b.__webglFramebuffer=c.createFramebuffer();b.__webglRenderbuffer=c.createRenderbuffer();b.__webglTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,b.__webglTexture);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,U(b.wrapS));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,U(b.wrapT));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,U(b.magFilter));
-c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,U(b.minFilter));c.texImage2D(c.TEXTURE_2D,0,U(b.format),b.width,b.height,0,U(b.format),U(b.type),null);c.bindRenderbuffer(c.RENDERBUFFER,b.__webglRenderbuffer);c.bindFramebuffer(c.FRAMEBUFFER,b.__webglFramebuffer);c.framebufferTexture2D(c.FRAMEBUFFER,c.COLOR_ATTACHMENT0,c.TEXTURE_2D,b.__webglTexture,0);b.depthBuffer&&!b.stencilBuffer?(c.renderbufferStorage(c.RENDERBUFFER,c.DEPTH_COMPONENT16,b.width,b.height),c.framebufferRenderbuffer(c.FRAMEBUFFER,
+delete g.__skinVertexBArray,delete g.__skinIndexArray,delete g.__skinWeightArray)}}f.__dirtyVertices=!1;f.__dirtyMorphTargets=!1;f.__dirtyElements=!1;f.__dirtyUvs=!1;f.__dirtyNormals=!1;f.__dirtyTangents=!1;f.__dirtyColors=!1;var ka;h=h.__materials;f=0;for(b=h.length;f<b;f++)if(d=h[f],d.attributes)for(ka in d.attributes)d.attributes[ka].needsUpdate=!1}else if(b instanceof THREE.Ribbon){f=b.geometry;if(f.__dirtyVertices||f.__dirtyColors){ka=f;b=c.DYNAMIC_DRAW;o=ka.vertices;h=ka.colors;y=o.length;g=
+h.length;v=ka.__vertexArray;i=ka.__colorArray;z=ka.__dirtyColors;if(ka.__dirtyVertices){for(j=0;j<y;j++)k=o[j].position,d=j*3,v[d]=k.x,v[d+1]=k.y,v[d+2]=k.z;c.bindBuffer(c.ARRAY_BUFFER,ka.__webglVertexBuffer);c.bufferData(c.ARRAY_BUFFER,v,b)}if(z){for(j=0;j<g;j++)color=h[j],d=j*3,i[d]=color.r,i[d+1]=color.g,i[d+2]=color.b;c.bindBuffer(c.ARRAY_BUFFER,ka.__webglColorBuffer);c.bufferData(c.ARRAY_BUFFER,i,b)}}f.__dirtyVertices=!1;f.__dirtyColors=!1}else if(b instanceof THREE.Line){f=b.geometry;if(f.__dirtyVertices||
+f.__dirtyColors){ka=f;b=c.DYNAMIC_DRAW;o=ka.vertices;h=ka.colors;y=o.length;g=h.length;v=ka.__vertexArray;i=ka.__colorArray;z=ka.__dirtyColors;if(ka.__dirtyVertices){for(j=0;j<y;j++)k=o[j].position,d=j*3,v[d]=k.x,v[d+1]=k.y,v[d+2]=k.z;c.bindBuffer(c.ARRAY_BUFFER,ka.__webglVertexBuffer);c.bufferData(c.ARRAY_BUFFER,v,b)}if(z){for(j=0;j<g;j++)color=h[j],d=j*3,i[d]=color.r,i[d+1]=color.g,i[d+2]=color.b;c.bindBuffer(c.ARRAY_BUFFER,ka.__webglColorBuffer);c.bufferData(c.ARRAY_BUFFER,i,b)}}f.__dirtyVertices=
+!1;f.__dirtyColors=!1}else if(b instanceof THREE.ParticleSystem)f=b.geometry,(f.__dirtyVertices||f.__dirtyColors||b.sortParticles)&&e(f,c.DYNAMIC_DRAW,b),f.__dirtyVertices=!1,f.__dirtyColors=!1}function ea(b,c){var d;for(d=b.length-1;d>=0;d--)b[d].object==c&&b.splice(d,1)}function S(b){function c(b){var f=[];d=0;for(e=b.length;d<e;d++)b[d]==void 0?f.push("undefined"):f.push(b[d].id);return f.join("_")}var d,e,f,g,h,i,j,k,p={},o=b.morphTargets!==void 0?b.morphTargets.length:0;b.geometryGroups={};f=
+0;for(g=b.faces.length;f<g;f++)h=b.faces[f],i=h.materials,j=c(i),p[j]==void 0&&(p[j]={hash:j,counter:0}),k=p[j].hash+"_"+p[j].counter,b.geometryGroups[k]==void 0&&(b.geometryGroups[k]={faces:[],materials:i,vertices:0,numMorphTargets:o}),h=h instanceof THREE.Face3?3:4,b.geometryGroups[k].vertices+h>65535&&(p[j].counter+=1,k=p[j].hash+"_"+p[j].counter,b.geometryGroups[k]==void 0&&(b.geometryGroups[k]={faces:[],materials:i,vertices:0,numMorphTargets:o})),b.geometryGroups[k].faces.push(f),b.geometryGroups[k].vertices+=
+h}function H(b,c,d){b.push({buffer:c,object:d,opaque:{list:[],count:0},transparent:{list:[],count:0}})}function y(b){if(b!=F){switch(b){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.SRC_ALPHA,c.ONE);break;case THREE.SubtractiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ZERO,c.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ZERO,c.SRC_COLOR);break;default:c.blendEquationSeparate(c.FUNC_ADD,c.FUNC_ADD),c.blendFuncSeparate(c.SRC_ALPHA,
+c.ONE_MINUS_SRC_ALPHA,c.ONE,c.ONE_MINUS_SRC_ALPHA)}F=b}}function aa(b,d,e){(e.width&e.width-1)==0&&(e.height&e.height-1)==0?(c.texParameteri(b,c.TEXTURE_WRAP_S,K(d.wrapS)),c.texParameteri(b,c.TEXTURE_WRAP_T,K(d.wrapT)),c.texParameteri(b,c.TEXTURE_MAG_FILTER,K(d.magFilter)),c.texParameteri(b,c.TEXTURE_MIN_FILTER,K(d.minFilter)),c.generateMipmap(b)):(c.texParameteri(b,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(b,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texParameteri(b,c.TEXTURE_MAG_FILTER,ua(d.magFilter)),
+c.texParameteri(b,c.TEXTURE_MIN_FILTER,ua(d.minFilter)))}function P(b,d){if(b.needsUpdate)b.__webglInit?(c.bindTexture(c.TEXTURE_2D,b.__webglTexture),c.texSubImage2D(c.TEXTURE_2D,0,0,0,c.RGBA,c.UNSIGNED_BYTE,b.image)):(b.__webglTexture=c.createTexture(),c.bindTexture(c.TEXTURE_2D,b.__webglTexture),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,b.image),b.__webglInit=!0),aa(c.TEXTURE_2D,b,b.image),c.bindTexture(c.TEXTURE_2D,null),b.needsUpdate=!1;c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,
+b.__webglTexture)}function Q(b){if(b&&!b.__webglFramebuffer){if(b.depthBuffer===void 0)b.depthBuffer=!0;if(b.stencilBuffer===void 0)b.stencilBuffer=!0;b.__webglFramebuffer=c.createFramebuffer();b.__webglRenderbuffer=c.createRenderbuffer();b.__webglTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,b.__webglTexture);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,K(b.wrapS));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,K(b.wrapT));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,K(b.magFilter));
+c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,K(b.minFilter));c.texImage2D(c.TEXTURE_2D,0,K(b.format),b.width,b.height,0,K(b.format),K(b.type),null);c.bindRenderbuffer(c.RENDERBUFFER,b.__webglRenderbuffer);c.bindFramebuffer(c.FRAMEBUFFER,b.__webglFramebuffer);c.framebufferTexture2D(c.FRAMEBUFFER,c.COLOR_ATTACHMENT0,c.TEXTURE_2D,b.__webglTexture,0);b.depthBuffer&&!b.stencilBuffer?(c.renderbufferStorage(c.RENDERBUFFER,c.DEPTH_COMPONENT16,b.width,b.height),c.framebufferRenderbuffer(c.FRAMEBUFFER,
 c.DEPTH_ATTACHMENT,c.RENDERBUFFER,b.__webglRenderbuffer)):b.depthBuffer&&b.stencilBuffer?(c.renderbufferStorage(c.RENDERBUFFER,c.DEPTH_STENCIL,b.width,b.height),c.framebufferRenderbuffer(c.FRAMEBUFFER,c.DEPTH_STENCIL_ATTACHMENT,c.RENDERBUFFER,b.__webglRenderbuffer)):c.renderbufferStorage(c.RENDERBUFFER,c.RGBA4,b.width,b.height);c.bindTexture(c.TEXTURE_2D,null);c.bindRenderbuffer(c.RENDERBUFFER,null);c.bindFramebuffer(c.FRAMEBUFFER,null)}var d,e;b?(d=b.__webglFramebuffer,e=b.width,b=b.height):(d=null,
-e=_viewportWidth,b=_viewportHeight);d!=ka&&(c.bindFramebuffer(c.FRAMEBUFFER,d),c.viewport(_viewportX,_viewportY,e,b),ka=d)}function K(b,d){var e;b=="fragment"?e=c.createShader(c.FRAGMENT_SHADER):b=="vertex"&&(e=c.createShader(c.VERTEX_SHADER));c.shaderSource(e,d);c.compileShader(e);if(!c.getShaderParameter(e,c.COMPILE_STATUS))return console.error(c.getShaderInfoLog(e)),console.error(d),null;return e}function na(b){switch(b){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return c.NEAREST;
-default:return c.LINEAR}}function U(b){switch(b){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR;
+e=va,b=qa);d!=ha&&(c.bindFramebuffer(c.FRAMEBUFFER,d),c.viewport(G,xa,e,b),ha=d)}function B(b,d){var e;b=="fragment"?e=c.createShader(c.FRAGMENT_SHADER):b=="vertex"&&(e=c.createShader(c.VERTEX_SHADER));c.shaderSource(e,d);c.compileShader(e);if(!c.getShaderParameter(e,c.COMPILE_STATUS))return console.error(c.getShaderInfoLog(e)),console.error(d),null;return e}function ua(b){switch(b){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return c.NEAREST;
+default:return c.LINEAR}}function K(b){switch(b){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR;
 case THREE.ByteType:return c.BYTE;case THREE.UnsignedByteType:return c.UNSIGNED_BYTE;case THREE.ShortType:return c.SHORT;case THREE.UnsignedShortType:return c.UNSIGNED_SHORT;case THREE.IntType:return c.INT;case THREE.UnsignedShortType:return c.UNSIGNED_INT;case THREE.FloatType:return c.FLOAT;case THREE.AlphaFormat:return c.ALPHA;case THREE.RGBFormat:return c.RGB;case THREE.RGBAFormat:return c.RGBA;case THREE.LuminanceFormat:return c.LUMINANCE;case THREE.LuminanceAlphaFormat:return c.LUMINANCE_ALPHA}return 0}
-var R=this,c,ha=[],S=null,ka=null,Q=!0,J=null,la=null,E=null,L=null,G=null;_oldPolygonOffsetUnits=_oldPolygonOffsetFactor=null;_cullEnabled=!0;_viewportHeight=_viewportWidth=_viewportY=_viewportX=0;_frustum=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4];_projScreenMatrix=new THREE.Matrix4;_projectionMatrixArray=new Float32Array(16);_viewMatrixArray=new Float32Array(16);_vector3=new THREE.Vector4;_lights={ambient:[0,0,0],directional:{length:0,
-colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]}};b=b||{};_canvas=b.canvas!==void 0?b.canvas:document.createElement("canvas");_stencil=b.stencil!==void 0?b.stencil:!0;_antialias=b.antialias!==void 0?b.antialias:!1;_clearColor=b.clearColor!==void 0?new THREE.Color(b.clearColor):new THREE.Color(0);_clearAlpha=b.clearAlpha!==void 0?b.clearAlpha:0;this.data={vertices:0,faces:0,drawCalls:0};this.maxMorphTargets=8;this.domElement=_canvas;this.sortObjects=this.autoClear=!0;try{if(!(c=
-_canvas.getContext("experimental-webgl",{antialias:_antialias,stencil:_stencil})))throw"Error creating WebGL context.";}catch(N){console.error(N)}console.log(navigator.userAgent+" | "+c.getParameter(c.VERSION)+" | "+c.getParameter(c.VENDOR)+" | "+c.getParameter(c.RENDERER)+" | "+c.getParameter(c.SHADING_LANGUAGE_VERSION));c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendEquation(c.FUNC_ADD);
-c.blendFunc(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA);c.clearColor(_clearColor.r,_clearColor.g,_clearColor.b,_clearAlpha);_cullEnabled=!0;this.context=c;var ma=c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;if(_stencil){var u={};u.vertices=new Float32Array(12);u.faces=new Uint16Array(6);u.darkness=0.5;u.vertices[0]=-20;u.vertices[1]=-20;u.vertices[2]=-1;u.vertices[3]=20;u.vertices[4]=-20;u.vertices[5]=-1;u.vertices[6]=20;u.vertices[7]=20;u.vertices[8]=-1;u.vertices[9]=-20;u.vertices[10]=20;u.vertices[11]=
--1;u.faces[0]=0;u.faces[1]=1;u.faces[2]=2;u.faces[3]=0;u.faces[4]=2;u.faces[5]=3;u.vertexBuffer=c.createBuffer();u.elementBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,u.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,u.vertices,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,u.elementBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,u.faces,c.STATIC_DRAW);u.program=c.createProgram();c.attachShader(u.program,K("fragment",THREE.ShaderLib.shadowPost.fragmentShader));c.attachShader(u.program,K("vertex",
-THREE.ShaderLib.shadowPost.vertexShader));c.linkProgram(u.program);u.vertexLocation=c.getAttribLocation(u.program,"position");u.projectionLocation=c.getUniformLocation(u.program,"projectionMatrix");u.darknessLocation=c.getUniformLocation(u.program,"darkness")}var t={};t.vertices=new Float32Array(16);t.faces=new Uint16Array(6);b=0;t.vertices[b++]=-1;t.vertices[b++]=-1;t.vertices[b++]=0;t.vertices[b++]=0;t.vertices[b++]=1;t.vertices[b++]=-1;t.vertices[b++]=1;t.vertices[b++]=0;t.vertices[b++]=1;t.vertices[b++]=
-1;t.vertices[b++]=1;t.vertices[b++]=1;t.vertices[b++]=-1;t.vertices[b++]=1;t.vertices[b++]=0;t.vertices[b++]=1;b=0;t.faces[b++]=0;t.faces[b++]=1;t.faces[b++]=2;t.faces[b++]=0;t.faces[b++]=2;t.faces[b++]=3;t.vertexBuffer=c.createBuffer();t.elementBuffer=c.createBuffer();t.tempTexture=c.createTexture();t.occlusionTexture=c.createTexture();c.bindBuffer(c.ARRAY_BUFFER,t.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,t.vertices,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,t.elementBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,
-t.faces,c.STATIC_DRAW);c.bindTexture(c.TEXTURE_2D,t.tempTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGB,16,16,0,c.RGB,c.UNSIGNED_BYTE,null);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST);c.bindTexture(c.TEXTURE_2D,t.occlusionTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,16,16,0,c.RGBA,c.UNSIGNED_BYTE,null);
-c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST);c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0?(t.hasVertexTexture=!1,t.program=c.createProgram(),c.attachShader(t.program,K("fragment",THREE.ShaderLib.lensFlare.fragmentShader)),c.attachShader(t.program,K("vertex",THREE.ShaderLib.lensFlare.vertexShader))):
-(t.hasVertexTexture=!0,t.program=c.createProgram(),c.attachShader(t.program,K("fragment",THREE.ShaderLib.lensFlareVertexTexture.fragmentShader)),c.attachShader(t.program,K("vertex",THREE.ShaderLib.lensFlareVertexTexture.vertexShader)));c.linkProgram(t.program);t.attributes={};t.uniforms={};t.attributes.vertex=c.getAttribLocation(t.program,"position");t.attributes.uv=c.getAttribLocation(t.program,"UV");t.uniforms.renderType=c.getUniformLocation(t.program,"renderType");t.uniforms.map=c.getUniformLocation(t.program,
-"map");t.uniforms.occlusionMap=c.getUniformLocation(t.program,"occlusionMap");t.uniforms.opacity=c.getUniformLocation(t.program,"opacity");t.uniforms.scale=c.getUniformLocation(t.program,"scale");t.uniforms.rotation=c.getUniformLocation(t.program,"rotation");t.uniforms.screenPosition=c.getUniformLocation(t.program,"screenPosition");var pa=!1;_sprite={};_sprite.vertices=new Float32Array(16);_sprite.faces=new Uint16Array(6);b=0;_sprite.vertices[b++]=-1;_sprite.vertices[b++]=-1;_sprite.vertices[b++]=
-0;_sprite.vertices[b++]=0;_sprite.vertices[b++]=1;_sprite.vertices[b++]=-1;_sprite.vertices[b++]=1;_sprite.vertices[b++]=0;_sprite.vertices[b++]=1;_sprite.vertices[b++]=1;_sprite.vertices[b++]=1;_sprite.vertices[b++]=1;_sprite.vertices[b++]=-1;_sprite.vertices[b++]=1;_sprite.vertices[b++]=0;_sprite.vertices[b++]=1;b=0;_sprite.faces[b++]=0;_sprite.faces[b++]=1;_sprite.faces[b++]=2;_sprite.faces[b++]=0;_sprite.faces[b++]=2;_sprite.faces[b++]=3;_sprite.vertexBuffer=c.createBuffer();_sprite.elementBuffer=
-c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,_sprite.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,_sprite.vertices,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,_sprite.elementBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,_sprite.faces,c.STATIC_DRAW);_sprite.program=c.createProgram();c.attachShader(_sprite.program,K("fragment",THREE.ShaderLib.sprite.fragmentShader));c.attachShader(_sprite.program,K("vertex",THREE.ShaderLib.sprite.vertexShader));c.linkProgram(_sprite.program);_sprite.attributes={};
-_sprite.uniforms={};_sprite.attributes.position=c.getAttribLocation(_sprite.program,"position");_sprite.attributes.uv=c.getAttribLocation(_sprite.program,"uv");_sprite.uniforms.uvOffset=c.getUniformLocation(_sprite.program,"uvOffset");_sprite.uniforms.uvScale=c.getUniformLocation(_sprite.program,"uvScale");_sprite.uniforms.rotation=c.getUniformLocation(_sprite.program,"rotation");_sprite.uniforms.scale=c.getUniformLocation(_sprite.program,"scale");_sprite.uniforms.alignment=c.getUniformLocation(_sprite.program,
-"alignment");_sprite.uniforms.map=c.getUniformLocation(_sprite.program,"map");_sprite.uniforms.opacity=c.getUniformLocation(_sprite.program,"opacity");_sprite.uniforms.useScreenCoordinates=c.getUniformLocation(_sprite.program,"useScreenCoordinates");_sprite.uniforms.affectedByDistance=c.getUniformLocation(_sprite.program,"affectedByDistance");_sprite.uniforms.screenPosition=c.getUniformLocation(_sprite.program,"screenPosition");_sprite.uniforms.modelViewMatrix=c.getUniformLocation(_sprite.program,
-"modelViewMatrix");_sprite.uniforms.projectionMatrix=c.getUniformLocation(_sprite.program,"projectionMatrix");var ra=!1;this.setSize=function(b,c){_canvas.width=b;_canvas.height=c;this.setViewport(0,0,_canvas.width,_canvas.height)};this.setViewport=function(b,d,e,f){_viewportX=b;_viewportY=d;_viewportWidth=e;_viewportHeight=f;c.viewport(_viewportX,_viewportY,_viewportWidth,_viewportHeight)};this.setScissor=function(b,d,e,f){c.scissor(b,d,e,f)};this.enableScissorTest=function(b){b?c.enable(c.SCISSOR_TEST):
-c.disable(c.SCISSOR_TEST)};this.enableDepthBufferWrite=function(b){Q=b;c.depthMask(b)};this.setClearColorHex=function(b,d){_clearColor.setHex(b);_clearAlpha=d;c.clearColor(_clearColor.r,_clearColor.g,_clearColor.b,_clearAlpha)};this.setClearColor=function(b,d){_clearColor.copy(b);_clearAlpha=d;c.clearColor(_clearColor.r,_clearColor.g,_clearColor.b,_clearAlpha)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT|c.STENCIL_BUFFER_BIT)};this.setStencilShadowDarkness=function(b){u.darkness=
-b};this.getContext=function(){return c};this.initMaterial=function(b,d,e,f){var g,h,i;b instanceof THREE.MeshDepthMaterial?i="depth":b instanceof THREE.ShadowVolumeDynamicMaterial?i="shadowVolumeDynamic":b instanceof THREE.MeshNormalMaterial?i="normal":b instanceof THREE.MeshBasicMaterial?i="basic":b instanceof THREE.MeshLambertMaterial?i="lambert":b instanceof THREE.MeshPhongMaterial?i="phong":b instanceof THREE.LineBasicMaterial?i="basic":b instanceof THREE.ParticleBasicMaterial&&(i="particle_basic");
-if(i){var j=THREE.ShaderLib[i];b.uniforms=THREE.UniformsUtils.clone(j.uniforms);b.vertexShader=j.vertexShader;b.fragmentShader=j.fragmentShader}var k,o,r;k=r=j=0;for(o=d.length;k<o;k++)h=d[k],h instanceof THREE.DirectionalLight&&r++,h instanceof THREE.PointLight&&j++;j+r<=4?d=r:(d=Math.ceil(4*r/(j+r)),j=4-d);h={directional:d,point:j};r=50;if(f!==void 0&&f instanceof THREE.SkinnedMesh)r=f.bones.length;var n;a:{k=b.fragmentShader;o=b.vertexShader;var j=b.uniforms,d=b.attributes,e={map:!!b.map,envMap:!!b.envMap,
-lightMap:!!b.lightMap,vertexColors:b.vertexColors,fog:e,sizeAttenuation:b.sizeAttenuation,skinning:b.skinning,morphTargets:b.morphTargets,maxMorphTargets:this.maxMorphTargets,maxDirLights:h.directional,maxPointLights:h.point,maxBones:r},p;h=[];i?h.push(i):(h.push(k),h.push(o));for(p in e)h.push(p),h.push(e[p]);i=h.join();p=0;for(h=ha.length;p<h;p++)if(ha[p].code==i){n=ha[p].program;break a}p=c.createProgram();h=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+e.maxDirLights,
-"#define MAX_POINT_LIGHTS "+e.maxPointLights,e.fog?"#define USE_FOG":"",e.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.lightMap?"#define USE_LIGHTMAP":"",e.vertexColors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");r=[ma?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+e.maxDirLights,"#define MAX_POINT_LIGHTS "+e.maxPointLights,"#define MAX_BONES "+e.maxBones,e.map?"#define USE_MAP":
-"",e.envMap?"#define USE_ENVMAP":"",e.lightMap?"#define USE_LIGHTMAP":"",e.vertexColors?"#define USE_COLOR":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nuniform mat4 cameraInverseMatrix;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n");
-c.attachShader(p,K("fragment",h+k));c.attachShader(p,K("vertex",r+o));c.linkProgram(p);c.getProgramParameter(p,c.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+c.getProgramParameter(p,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");p.uniforms={};p.attributes={};var q;k=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices","morphTargetInfluences"];for(q in j)k.push(q);q=k;j=0;for(k=
-q.length;j<k;j++)o=q[j],p.uniforms[o]=c.getUniformLocation(p,o);k=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(q=0;q<e.maxMorphTargets;q++)k.push("morphTarget"+q);for(n in d)k.push(n);n=k;q=0;for(d=n.length;q<d;q++)e=n[q],p.attributes[e]=c.getAttribLocation(p,e);ha.push({program:p,code:i});n=p}b.program=n;n=b.program.attributes;n.position>=0&&c.enableVertexAttribArray(n.position);n.color>=0&&c.enableVertexAttribArray(n.color);n.normal>=
+var L=this,c,sa=[],la=null,ha=null,ma=!0,M=null,na=null,F=null,$=null,T=null,R=null,pa=null,G=0,xa=0,va=0,qa=0,ra=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],ia=new THREE.Matrix4,ta=new Float32Array(16),ya=new Float32Array(16),Da=new THREE.Vector4,Ga={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]}},b=b||{},wa=b.canvas!==void 0?b.canvas:document.createElement("canvas"),
+Fa=b.stencil!==void 0?b.stencil:!0,Ka=b.antialias!==void 0?b.antialias:!1,oa=b.clearColor!==void 0?new THREE.Color(b.clearColor):new THREE.Color(0),Ea=b.clearAlpha!==void 0?b.clearAlpha:0;this.data={vertices:0,faces:0,drawCalls:0};this.maxMorphTargets=8;this.domElement=wa;this.sortObjects=this.autoClear=!0;try{if(!(c=wa.getContext("experimental-webgl",{antialias:Ka,stencil:Fa})))throw"Error creating WebGL context.";}catch(La){console.error(La)}console.log(navigator.userAgent+" | "+c.getParameter(c.VERSION)+
+" | "+c.getParameter(c.VENDOR)+" | "+c.getParameter(c.RENDERER)+" | "+c.getParameter(c.SHADING_LANGUAGE_VERSION));c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendEquation(c.FUNC_ADD);c.blendFunc(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA);c.clearColor(oa.r,oa.g,oa.b,Ea);this.context=c;var Ja=c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;if(Fa){var x={};x.vertices=new Float32Array(12);
+x.faces=new Uint16Array(6);x.darkness=0.5;x.vertices[0]=-20;x.vertices[1]=-20;x.vertices[2]=-1;x.vertices[3]=20;x.vertices[4]=-20;x.vertices[5]=-1;x.vertices[6]=20;x.vertices[7]=20;x.vertices[8]=-1;x.vertices[9]=-20;x.vertices[10]=20;x.vertices[11]=-1;x.faces[0]=0;x.faces[1]=1;x.faces[2]=2;x.faces[3]=0;x.faces[4]=2;x.faces[5]=3;x.vertexBuffer=c.createBuffer();x.elementBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,x.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,x.vertices,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
+x.elementBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,x.faces,c.STATIC_DRAW);x.program=c.createProgram();c.attachShader(x.program,B("fragment",THREE.ShaderLib.shadowPost.fragmentShader));c.attachShader(x.program,B("vertex",THREE.ShaderLib.shadowPost.vertexShader));c.linkProgram(x.program);x.vertexLocation=c.getAttribLocation(x.program,"position");x.projectionLocation=c.getUniformLocation(x.program,"projectionMatrix");x.darknessLocation=c.getUniformLocation(x.program,"darkness")}var v={};v.vertices=
+new Float32Array(16);v.faces=new Uint16Array(6);b=0;v.vertices[b++]=-1;v.vertices[b++]=-1;v.vertices[b++]=0;v.vertices[b++]=0;v.vertices[b++]=1;v.vertices[b++]=-1;v.vertices[b++]=1;v.vertices[b++]=0;v.vertices[b++]=1;v.vertices[b++]=1;v.vertices[b++]=1;v.vertices[b++]=1;v.vertices[b++]=-1;v.vertices[b++]=1;v.vertices[b++]=0;v.vertices[b++]=1;b=0;v.faces[b++]=0;v.faces[b++]=1;v.faces[b++]=2;v.faces[b++]=0;v.faces[b++]=2;v.faces[b++]=3;v.vertexBuffer=c.createBuffer();v.elementBuffer=c.createBuffer();
+v.tempTexture=c.createTexture();v.occlusionTexture=c.createTexture();c.bindBuffer(c.ARRAY_BUFFER,v.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,v.vertices,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,v.elementBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,v.faces,c.STATIC_DRAW);c.bindTexture(c.TEXTURE_2D,v.tempTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGB,16,16,0,c.RGB,c.UNSIGNED_BYTE,null);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);
+c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST);c.bindTexture(c.TEXTURE_2D,v.occlusionTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,16,16,0,c.RGBA,c.UNSIGNED_BYTE,null);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST);c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=
+0?(v.hasVertexTexture=!1,v.program=c.createProgram(),c.attachShader(v.program,B("fragment",THREE.ShaderLib.lensFlare.fragmentShader)),c.attachShader(v.program,B("vertex",THREE.ShaderLib.lensFlare.vertexShader))):(v.hasVertexTexture=!0,v.program=c.createProgram(),c.attachShader(v.program,B("fragment",THREE.ShaderLib.lensFlareVertexTexture.fragmentShader)),c.attachShader(v.program,B("vertex",THREE.ShaderLib.lensFlareVertexTexture.vertexShader)));c.linkProgram(v.program);v.attributes={};v.uniforms={};
+v.attributes.vertex=c.getAttribLocation(v.program,"position");v.attributes.uv=c.getAttribLocation(v.program,"UV");v.uniforms.renderType=c.getUniformLocation(v.program,"renderType");v.uniforms.map=c.getUniformLocation(v.program,"map");v.uniforms.occlusionMap=c.getUniformLocation(v.program,"occlusionMap");v.uniforms.opacity=c.getUniformLocation(v.program,"opacity");v.uniforms.scale=c.getUniformLocation(v.program,"scale");v.uniforms.rotation=c.getUniformLocation(v.program,"rotation");v.uniforms.screenPosition=
+c.getUniformLocation(v.program,"screenPosition");var Ia=!1,r={};r.vertices=new Float32Array(16);r.faces=new Uint16Array(6);b=0;r.vertices[b++]=-1;r.vertices[b++]=-1;r.vertices[b++]=0;r.vertices[b++]=1;r.vertices[b++]=1;r.vertices[b++]=-1;r.vertices[b++]=1;r.vertices[b++]=1;r.vertices[b++]=1;r.vertices[b++]=1;r.vertices[b++]=1;r.vertices[b++]=0;r.vertices[b++]=-1;r.vertices[b++]=1;r.vertices[b++]=0;b=r.vertices[b++]=0;r.faces[b++]=0;r.faces[b++]=1;r.faces[b++]=2;r.faces[b++]=0;r.faces[b++]=2;r.faces[b++]=
+3;r.vertexBuffer=c.createBuffer();r.elementBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,r.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,r.vertices,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,r.elementBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,r.faces,c.STATIC_DRAW);r.program=c.createProgram();c.attachShader(r.program,B("fragment",THREE.ShaderLib.sprite.fragmentShader));c.attachShader(r.program,B("vertex",THREE.ShaderLib.sprite.vertexShader));c.linkProgram(r.program);r.attributes={};r.uniforms=
+{};r.attributes.position=c.getAttribLocation(r.program,"position");r.attributes.uv=c.getAttribLocation(r.program,"uv");r.uniforms.uvOffset=c.getUniformLocation(r.program,"uvOffset");r.uniforms.uvScale=c.getUniformLocation(r.program,"uvScale");r.uniforms.rotation=c.getUniformLocation(r.program,"rotation");r.uniforms.scale=c.getUniformLocation(r.program,"scale");r.uniforms.alignment=c.getUniformLocation(r.program,"alignment");r.uniforms.map=c.getUniformLocation(r.program,"map");r.uniforms.opacity=c.getUniformLocation(r.program,
+"opacity");r.uniforms.useScreenCoordinates=c.getUniformLocation(r.program,"useScreenCoordinates");r.uniforms.affectedByDistance=c.getUniformLocation(r.program,"affectedByDistance");r.uniforms.screenPosition=c.getUniformLocation(r.program,"screenPosition");r.uniforms.modelViewMatrix=c.getUniformLocation(r.program,"modelViewMatrix");r.uniforms.projectionMatrix=c.getUniformLocation(r.program,"projectionMatrix");var Ha=!1;this.setSize=function(b,c){wa.width=b;wa.height=c;this.setViewport(0,0,wa.width,
+wa.height)};this.setViewport=function(b,d,e,f){G=b;xa=d;va=e;qa=f;c.viewport(G,xa,va,qa)};this.setScissor=function(b,d,e,f){c.scissor(b,d,e,f)};this.enableScissorTest=function(b){b?c.enable(c.SCISSOR_TEST):c.disable(c.SCISSOR_TEST)};this.enableDepthBufferWrite=function(b){ma=b;c.depthMask(b)};this.setClearColorHex=function(b,d){oa.setHex(b);Ea=d;c.clearColor(oa.r,oa.g,oa.b,Ea)};this.setClearColor=function(b,d){oa.copy(b);Ea=d;c.clearColor(oa.r,oa.g,oa.b,Ea)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|
+c.DEPTH_BUFFER_BIT|c.STENCIL_BUFFER_BIT)};this.setStencilShadowDarkness=function(b){x.darkness=b};this.getContext=function(){return c};this.initMaterial=function(b,d,e,f){var g,h,i;b instanceof THREE.MeshDepthMaterial?i="depth":b instanceof THREE.ShadowVolumeDynamicMaterial?i="shadowVolumeDynamic":b instanceof THREE.MeshNormalMaterial?i="normal":b instanceof THREE.MeshBasicMaterial?i="basic":b instanceof THREE.MeshLambertMaterial?i="lambert":b instanceof THREE.MeshPhongMaterial?i="phong":b instanceof
+THREE.LineBasicMaterial?i="basic":b instanceof THREE.ParticleBasicMaterial&&(i="particle_basic");if(i){var j=THREE.ShaderLib[i];b.uniforms=THREE.UniformsUtils.clone(j.uniforms);b.vertexShader=j.vertexShader;b.fragmentShader=j.fragmentShader}var k,o,p;k=p=j=0;for(o=d.length;k<o;k++)h=d[k],h instanceof THREE.DirectionalLight&&p++,h instanceof THREE.PointLight&&j++;j+p<=4?d=p:(d=Math.ceil(4*p/(j+p)),j=4-d);h={directional:d,point:j};p=50;if(f!==void 0&&f instanceof THREE.SkinnedMesh)p=f.bones.length;
+var n;a:{k=b.fragmentShader;o=b.vertexShader;var j=b.uniforms,d=b.attributes,e={map:!!b.map,envMap:!!b.envMap,lightMap:!!b.lightMap,vertexColors:b.vertexColors,fog:e,sizeAttenuation:b.sizeAttenuation,skinning:b.skinning,morphTargets:b.morphTargets,maxMorphTargets:this.maxMorphTargets,maxDirLights:h.directional,maxPointLights:h.point,maxBones:p},q;h=[];i?h.push(i):(h.push(k),h.push(o));for(q in e)h.push(q),h.push(e[q]);i=h.join();q=0;for(h=sa.length;q<h;q++)if(sa[q].code==i){n=sa[q].program;break a}q=
+c.createProgram();h=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+e.maxDirLights,"#define MAX_POINT_LIGHTS "+e.maxPointLights,e.fog?"#define USE_FOG":"",e.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.lightMap?"#define USE_LIGHTMAP":"",e.vertexColors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");p=[Ja?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+
+e.maxDirLights,"#define MAX_POINT_LIGHTS "+e.maxPointLights,"#define MAX_BONES "+e.maxBones,e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.lightMap?"#define USE_LIGHTMAP":"",e.vertexColors?"#define USE_COLOR":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nuniform mat4 cameraInverseMatrix;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n");
+c.attachShader(q,B("fragment",h+k));c.attachShader(q,B("vertex",p+o));c.linkProgram(q);c.getProgramParameter(q,c.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+c.getProgramParameter(q,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");q.uniforms={};q.attributes={};var t;k=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices","morphTargetInfluences"];for(t in j)k.push(t);t=k;j=0;for(k=
+t.length;j<k;j++)o=t[j],q.uniforms[o]=c.getUniformLocation(q,o);k=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(t=0;t<e.maxMorphTargets;t++)k.push("morphTarget"+t);for(n in d)k.push(n);n=k;t=0;for(d=n.length;t<d;t++)e=n[t],q.attributes[e]=c.getAttribLocation(q,e);sa.push({program:q,code:i});n=q}b.program=n;n=b.program.attributes;n.position>=0&&c.enableVertexAttribArray(n.position);n.color>=0&&c.enableVertexAttribArray(n.color);n.normal>=
 0&&c.enableVertexAttribArray(n.normal);n.tangent>=0&&c.enableVertexAttribArray(n.tangent);b.skinning&&n.skinVertexA>=0&&n.skinVertexB>=0&&n.skinIndex>=0&&n.skinWeight>=0&&(c.enableVertexAttribArray(n.skinVertexA),c.enableVertexAttribArray(n.skinVertexB),c.enableVertexAttribArray(n.skinIndex),c.enableVertexAttribArray(n.skinWeight));if(b.attributes)for(g in b.attributes)n[g]!==void 0&&n[g]>=0&&c.enableVertexAttribArray(n[g]);if(b.morphTargets){b.numSupportedMorphTargets=0;n.morphTarget0>=0&&(c.enableVertexAttribArray(n.morphTarget0),
 b.numSupportedMorphTargets++);n.morphTarget1>=0&&(c.enableVertexAttribArray(n.morphTarget1),b.numSupportedMorphTargets++);n.morphTarget2>=0&&(c.enableVertexAttribArray(n.morphTarget2),b.numSupportedMorphTargets++);n.morphTarget3>=0&&(c.enableVertexAttribArray(n.morphTarget3),b.numSupportedMorphTargets++);n.morphTarget4>=0&&(c.enableVertexAttribArray(n.morphTarget4),b.numSupportedMorphTargets++);n.morphTarget5>=0&&(c.enableVertexAttribArray(n.morphTarget5),b.numSupportedMorphTargets++);n.morphTarget6>=
-0&&(c.enableVertexAttribArray(n.morphTarget6),b.numSupportedMorphTargets++);n.morphTarget7>=0&&(c.enableVertexAttribArray(n.morphTarget7),b.numSupportedMorphTargets++);f.__webglMorphTargetInfluences=new Float32Array(this.maxMorphTargets);b=0;for(g=this.maxMorphTargets;b<g;b++)f.__webglMorphTargetInfluences[b]=0}};this.render=function(b,e,p,t){var u,E,oa,B,F,G,r,P,J=b.lights,K=b.fog;R.data.vertices=0;R.data.faces=0;R.data.drawCalls=0;e.matrixAutoUpdate&&e.update(void 0,!0);b.update(void 0,!1,e);e.matrixWorldInverse.flattenToArray(_viewMatrixArray);
-e.projectionMatrix.flattenToArray(_projectionMatrixArray);_projScreenMatrix.multiply(e.projectionMatrix,e.matrixWorldInverse);k(_projScreenMatrix);this.initWebGLObjects(b);$(p);(this.autoClear||t)&&this.clear();F=b.__webglObjects.length;for(t=0;t<F;t++)if(u=b.__webglObjects[t],r=u.object,r.visible)if(!(r instanceof THREE.Mesh)||o(r)){if(r.matrixWorld.flattenToArray(r._objectMatrixArray),C(r,e),q(u),u.render=!0,this.sortObjects)u.object.renderDepth?u.z=u.object.renderDepth:(_vector3.copy(r.position),
-_projScreenMatrix.multiplyVector3(_vector3),u.z=_vector3.z)}else u.render=!1;else u.render=!1;this.sortObjects&&b.__webglObjects.sort(w);G=b.__webglObjectsImmediate.length;for(t=0;t<G;t++)u=b.__webglObjectsImmediate[t],r=u.object,r.visible&&(r.matrixAutoUpdate&&r.matrixWorld.flattenToArray(r._objectMatrixArray),C(r,e),n(u));v(THREE.NormalBlending);for(t=0;t<F;t++)if(u=b.__webglObjects[t],u.render){r=u.object;P=u.buffer;oa=u.opaque;i(r);for(u=0;u<oa.count;u++)B=oa.list[u],g(B.depthTest),j(B.polygonOffset,
-B.polygonOffsetFactor,B.polygonOffsetUnits),f(e,J,K,B,P,r)}for(t=0;t<G;t++)if(u=b.__webglObjectsImmediate[t],r=u.object,r.visible){oa=u.opaque;i(r);for(u=0;u<oa.count;u++)B=oa.list[u],g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,B.polygonOffsetUnits),E=d(e,J,K,B,r),r.render(function(b){h(b,E,B.shading)})}for(t=0;t<F;t++)if(u=b.__webglObjects[t],u.render){r=u.object;P=u.buffer;oa=u.transparent;i(r);for(u=0;u<oa.count;u++)B=oa.list[u],v(B.blending),g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,
-B.polygonOffsetUnits),f(e,J,K,B,P,r)}for(t=0;t<G;t++)if(u=b.__webglObjectsImmediate[t],r=u.object,r.visible){oa=u.transparent;i(r);for(u=0;u<oa.count;u++)B=oa.list[u],v(B.blending),g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,B.polygonOffsetUnits),E=d(e,J,K,B,r),r.render(function(b){h(b,E,B.shading)})}b.__webglSprites.length&&D(b,e);_stencil&&b.__webglShadowVolumes.length&&b.lights.length&&y(b);b.__webglLensFlares.length&&z(b,e);p&&p.minFilter!==THREE.NearestFilter&&p.minFilter!==THREE.LinearFilter&&
-(c.bindTexture(c.TEXTURE_2D,p.__webglTexture),c.generateMipmap(c.TEXTURE_2D),c.bindTexture(c.TEXTURE_2D,null))};this.initWebGLObjects=function(b){if(!b.__webglObjects)b.__webglObjects=[],b.__webglObjectsImmediate=[],b.__webglShadowVolumes=[],b.__webglLensFlares=[],b.__webglSprites=[];for(;b.__objectsAdded.length;){var d=b.__objectsAdded[0],e=b,f=void 0,g=void 0,h=void 0;if(d._modelViewMatrix==void 0)d._modelViewMatrix=new THREE.Matrix4,d._normalMatrixArray=new Float32Array(9),d._modelViewMatrixArray=
-new Float32Array(16),d._objectMatrixArray=new Float32Array(16),d.matrixWorld.flattenToArray(d._objectMatrixArray);if(d instanceof THREE.Mesh)for(f in g=d.geometry,g.geometryGroups==void 0&&O(g),g.geometryGroups){h=g.geometryGroups[f];if(!h.__webglVertexBuffer){var i=h;i.__webglVertexBuffer=c.createBuffer();i.__webglNormalBuffer=c.createBuffer();i.__webglTangentBuffer=c.createBuffer();i.__webglColorBuffer=c.createBuffer();i.__webglUVBuffer=c.createBuffer();i.__webglUV2Buffer=c.createBuffer();i.__webglSkinVertexABuffer=
-c.createBuffer();i.__webglSkinVertexBBuffer=c.createBuffer();i.__webglSkinIndicesBuffer=c.createBuffer();i.__webglSkinWeightsBuffer=c.createBuffer();i.__webglFaceBuffer=c.createBuffer();i.__webglLineBuffer=c.createBuffer();if(i.numMorphTargets){var j=void 0,k=void 0;i.__webglMorphTargetsBuffers=[];j=0;for(k=i.numMorphTargets;j<k;j++)i.__webglMorphTargetsBuffers.push(c.createBuffer())}for(var i=h,j=d,n=void 0,o=void 0,p=void 0,t=p=void 0,q=void 0,u=void 0,w=u=k=0,v=p=o=void 0,z=v=o=n=void 0,p=void 0,
-t=j.geometry,q=t.faces,v=i.faces,n=0,o=v.length;n<o;n++)p=v[n],p=q[p],p instanceof THREE.Face3?(k+=3,u+=1,w+=3):p instanceof THREE.Face4&&(k+=4,u+=2,w+=4);for(var n=i,o=j,y=v=q=void 0,B=void 0,y=void 0,p=[],q=0,v=o.materials.length;q<v;q++)if(y=o.materials[q],y instanceof THREE.MeshFaceMaterial){y=0;for(l=n.materials.length;y<l;y++)(B=n.materials[y])&&p.push(B)}else(B=y)&&p.push(B);n=p;i.__materials=n;a:{q=o=void 0;v=n.length;for(o=0;o<v;o++)if(q=n[o],q.map||q.lightMap||q instanceof THREE.MeshShaderMaterial){o=
-!0;break a}o=!1}a:{v=q=void 0;p=n.length;for(q=0;q<p;q++)if(v=n[q],!(v instanceof THREE.MeshBasicMaterial&&!v.envMap||v instanceof THREE.MeshDepthMaterial)){v=v&&v.shading!=void 0&&v.shading==THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading;break a}v=!1}a:{p=q=void 0;y=n.length;for(q=0;q<y;q++)if(p=n[q],p.vertexColors){p=p.vertexColors;break a}p=!1}i.__vertexArray=new Float32Array(k*3);if(v)i.__normalArray=new Float32Array(k*3);if(t.hasTangents)i.__tangentArray=new Float32Array(k*4);if(p)i.__colorArray=
-new Float32Array(k*3);if(o){if(t.faceUvs.length>0||t.faceVertexUvs.length>0)i.__uvArray=new Float32Array(k*2);if(t.faceUvs.length>1||t.faceVertexUvs.length>1)i.__uv2Array=new Float32Array(k*2)}if(j.geometry.skinWeights.length&&j.geometry.skinIndices.length)i.__skinVertexAArray=new Float32Array(k*4),i.__skinVertexBArray=new Float32Array(k*4),i.__skinIndexArray=new Float32Array(k*4),i.__skinWeightArray=new Float32Array(k*4);i.__faceArray=new Uint16Array(u*3+(j.geometry.edgeFaces?j.geometry.edgeFaces.length*
-6:0));i.__lineArray=new Uint16Array(w*2);if(i.numMorphTargets){i.__morphTargetsArrays=[];t=0;for(q=i.numMorphTargets;t<q;t++)i.__morphTargetsArrays.push(new Float32Array(k*3))}i.__needsSmoothNormals=v==THREE.SmoothShading;i.__uvType=o;i.__vertexColorType=p;i.__normalType=v;i.__webglFaceCount=u*3+(j.geometry.edgeFaces?j.geometry.edgeFaces.length*6:0);i.__webglLineCount=w*2;t=0;for(q=n.length;t<q;t++)if(o=n[t],o.attributes)for(a in i.__webglCustomAttributes={},o.attributes){p=o.attributes[a];v={};for(z in p)v[z]=
-p[z];if(!v.__webglInitialized||v.createUniqueBuffers)v.__webglInitialized=!0,u=1,v.type==="v2"?u=2:v.type==="v3"?u=3:v.type==="v4"?u=4:v.type==="c"&&(u=3),v.size=u,v.array=new Float32Array(k*u),v.buffer=c.createBuffer(),v.buffer.belongsToAttribute=a,p.needsUpdate=!0,v.__original=p;i.__webglCustomAttributes[a]=v}i.__inittedArrays=!0;g.__dirtyVertices=!0;g.__dirtyMorphTargets=!0;g.__dirtyElements=!0;g.__dirtyUvs=!0;g.__dirtyNormals=!0;g.__dirtyTangents=!0;g.__dirtyColors=!0}d instanceof THREE.ShadowVolume?
-F(e.__webglShadowVolumes,h,d):F(e.__webglObjects,h,d)}else if(d instanceof THREE.LensFlare)F(e.__webglLensFlares,void 0,d);else if(d instanceof THREE.Ribbon){g=d.geometry;if(!g.__webglVertexBuffer)f=g,f.__webglVertexBuffer=c.createBuffer(),f.__webglColorBuffer=c.createBuffer(),f=g,h=f.vertices.length,f.__vertexArray=new Float32Array(h*3),f.__colorArray=new Float32Array(h*3),f.__webglVertexCount=h,g.__dirtyVertices=!0,g.__dirtyColors=!0;F(e.__webglObjects,g,d)}else if(d instanceof THREE.Line){g=d.geometry;
-if(!g.__webglVertexBuffer)f=g,f.__webglVertexBuffer=c.createBuffer(),f.__webglColorBuffer=c.createBuffer(),f=g,h=f.vertices.length,f.__vertexArray=new Float32Array(h*3),f.__colorArray=new Float32Array(h*3),f.__webglLineCount=h,g.__dirtyVertices=!0,g.__dirtyColors=!0;F(e.__webglObjects,g,d)}else if(d instanceof THREE.ParticleSystem){g=d.geometry;if(!g.__webglVertexBuffer)f=g,f.__webglVertexBuffer=c.createBuffer(),f.__webglColorBuffer=c.createBuffer(),f=g,h=f.vertices.length,f.__vertexArray=new Float32Array(h*
-3),f.__colorArray=new Float32Array(h*3),f.__sortArray=[],f.__webglParticleCount=h,g.__dirtyVertices=!0,g.__dirtyColors=!0;F(e.__webglObjects,g,d)}else THREE.MarchingCubes!==void 0&&d instanceof THREE.MarchingCubes?e.__webglObjectsImmediate.push({object:d,opaque:{list:[],count:0},transparent:{list:[],count:0}}):d instanceof THREE.Sprite&&e.__webglSprites.push(d);b.__objectsAdded.splice(0,1)}for(;b.__objectsRemoved.length;){e=b.__objectsRemoved[0];d=b;if(e instanceof THREE.ShadowVolume)aa(d.__webglShadowVolumes,
-e);else if(e instanceof THREE.Mesh||e instanceof THREE.ParticleSystem||e instanceof THREE.Ribbon||e instanceof THREE.Line)aa(d.__webglObjects,e);else if(e instanceof THREE.Sprite){d=d.__webglSprites;g=void 0;for(g=d.length-1;g>=0;g--)d[g]==e&&d.splice(g,1)}else e instanceof THREE.LensFlare?aa(d.__webglLensFlares,e):e instanceof THREE.MarchingCubes&&aa(d.__webglObjectsImmediate,e);b.__objectsRemoved.splice(0,1)}d=0;for(e=b.__webglObjects.length;d<e;d++)ga(b.__webglObjects[d].object,b);d=0;for(e=b.__webglShadowVolumes.length;d<
-e;d++)ga(b.__webglShadowVolumes[d].object,b);d=0;for(e=b.__webglLensFlares.length;d<e;d++)ga(b.__webglLensFlares[d].object,b)};this.setFaceCulling=function(b,d){b?(!d||d=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW),b=="back"?c.cullFace(c.BACK):b=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK),c.enable(c.CULL_FACE)):c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return ma}};
+0&&(c.enableVertexAttribArray(n.morphTarget6),b.numSupportedMorphTargets++);n.morphTarget7>=0&&(c.enableVertexAttribArray(n.morphTarget7),b.numSupportedMorphTargets++);f.__webglMorphTargetInfluences=new Float32Array(this.maxMorphTargets);b=0;for(g=this.maxMorphTargets;b<g;b++)f.__webglMorphTargetInfluences[b]=0}};this.render=function(b,e,q,r){var v,x,za,B,F,G,p,O,H=b.lights,K=b.fog;L.data.vertices=0;L.data.faces=0;L.data.drawCalls=0;e.matrixAutoUpdate&&e.update(void 0,!0);b.update(void 0,!1,e);e.matrixWorldInverse.flattenToArray(ya);
+e.projectionMatrix.flattenToArray(ta);ia.multiply(e.projectionMatrix,e.matrixWorldInverse);k(ia);this.initWebGLObjects(b);Q(q);(this.autoClear||r)&&this.clear();F=b.__webglObjects.length;for(r=0;r<F;r++)if(v=b.__webglObjects[r],p=v.object,p.visible)if(!(p instanceof THREE.Mesh)||o(p)){if(p.matrixWorld.flattenToArray(p._objectMatrixArray),C(p,e),t(v),v.render=!0,this.sortObjects)v.object.renderDepth?v.z=v.object.renderDepth:(Da.copy(p.position),ia.multiplyVector3(Da),v.z=Da.z)}else v.render=!1;else v.render=
+!1;this.sortObjects&&b.__webglObjects.sort(u);G=b.__webglObjectsImmediate.length;for(r=0;r<G;r++)v=b.__webglObjectsImmediate[r],p=v.object,p.visible&&(p.matrixAutoUpdate&&p.matrixWorld.flattenToArray(p._objectMatrixArray),C(p,e),n(v));if(b.overrideMaterial){g(b.overrideMaterial.depthTest);y(b.overrideMaterial.blending);for(r=0;r<F;r++)if(v=b.__webglObjects[r],v.render)p=v.object,O=v.buffer,i(p),f(e,H,K,b.overrideMaterial,O,p);for(r=0;r<G;r++)v=b.__webglObjectsImmediate[r],p=v.object,p.visible&&(i(p),
+x=d(e,H,K,b.overrideMaterial,p),p.render(function(c){h(c,x,b.overrideMaterial.shading)}))}else{y(THREE.NormalBlending);for(r=0;r<F;r++)if(v=b.__webglObjects[r],v.render){p=v.object;O=v.buffer;za=v.opaque;i(p);for(v=0;v<za.count;v++)B=za.list[v],g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,B.polygonOffsetUnits),f(e,H,K,B,O,p)}for(r=0;r<G;r++)if(v=b.__webglObjectsImmediate[r],p=v.object,p.visible){za=v.opaque;i(p);for(v=0;v<za.count;v++)B=za.list[v],g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,
+B.polygonOffsetUnits),x=d(e,H,K,B,p),p.render(function(b){h(b,x,B.shading)})}for(r=0;r<F;r++)if(v=b.__webglObjects[r],v.render){p=v.object;O=v.buffer;za=v.transparent;i(p);for(v=0;v<za.count;v++)B=za.list[v],y(B.blending),g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,B.polygonOffsetUnits),f(e,H,K,B,O,p)}for(r=0;r<G;r++)if(v=b.__webglObjectsImmediate[r],p=v.object,p.visible){za=v.transparent;i(p);for(v=0;v<za.count;v++)B=za.list[v],y(B.blending),g(B.depthTest),j(B.polygonOffset,B.polygonOffsetFactor,
+B.polygonOffsetUnits),x=d(e,H,K,B,p),p.render(function(b){h(b,x,B.shading)})}}b.__webglSprites.length&&D(b,e);Fa&&b.__webglShadowVolumes.length&&b.lights.length&&z(b);b.__webglLensFlares.length&&E(b,e);q&&q.minFilter!==THREE.NearestFilter&&q.minFilter!==THREE.LinearFilter&&(c.bindTexture(c.TEXTURE_2D,q.__webglTexture),c.generateMipmap(c.TEXTURE_2D),c.bindTexture(c.TEXTURE_2D,null))};this.initWebGLObjects=function(b){if(!b.__webglObjects)b.__webglObjects=[],b.__webglObjectsImmediate=[],b.__webglShadowVolumes=
+[],b.__webglLensFlares=[],b.__webglSprites=[];for(;b.__objectsAdded.length;){var d=b.__objectsAdded[0],e=b,f=void 0,g=void 0,h=void 0;if(d._modelViewMatrix==void 0)d._modelViewMatrix=new THREE.Matrix4,d._normalMatrixArray=new Float32Array(9),d._modelViewMatrixArray=new Float32Array(16),d._objectMatrixArray=new Float32Array(16),d.matrixWorld.flattenToArray(d._objectMatrixArray);if(d instanceof THREE.Mesh)for(f in g=d.geometry,g.geometryGroups==void 0&&S(g),g.geometryGroups){h=g.geometryGroups[f];if(!h.__webglVertexBuffer){var i=
+h;i.__webglVertexBuffer=c.createBuffer();i.__webglNormalBuffer=c.createBuffer();i.__webglTangentBuffer=c.createBuffer();i.__webglColorBuffer=c.createBuffer();i.__webglUVBuffer=c.createBuffer();i.__webglUV2Buffer=c.createBuffer();i.__webglSkinVertexABuffer=c.createBuffer();i.__webglSkinVertexBBuffer=c.createBuffer();i.__webglSkinIndicesBuffer=c.createBuffer();i.__webglSkinWeightsBuffer=c.createBuffer();i.__webglFaceBuffer=c.createBuffer();i.__webglLineBuffer=c.createBuffer();if(i.numMorphTargets){var j=
+void 0,k=void 0;i.__webglMorphTargetsBuffers=[];j=0;for(k=i.numMorphTargets;j<k;j++)i.__webglMorphTargetsBuffers.push(c.createBuffer())}for(var i=h,j=d,n=void 0,p=void 0,o=void 0,q=o=void 0,r=void 0,t=void 0,v=t=k=0,u=o=p=void 0,x=u=p=n=void 0,o=void 0,q=j.geometry,r=q.faces,u=i.faces,n=0,p=u.length;n<p;n++)o=u[n],o=r[o],o instanceof THREE.Face3?(k+=3,t+=1,v+=3):o instanceof THREE.Face4&&(k+=4,t+=2,v+=4);for(var n=i,p=j,y=u=r=void 0,z=void 0,y=void 0,o=[],r=0,u=p.materials.length;r<u;r++)if(y=p.materials[r],
+y instanceof THREE.MeshFaceMaterial){y=0;for(l=n.materials.length;y<l;y++)(z=n.materials[y])&&o.push(z)}else(z=y)&&o.push(z);n=o;i.__materials=n;a:{r=p=void 0;u=n.length;for(p=0;p<u;p++)if(r=n[p],r.map||r.lightMap||r instanceof THREE.MeshShaderMaterial){p=!0;break a}p=!1}a:{u=r=void 0;o=n.length;for(r=0;r<o;r++)if(u=n[r],!(u instanceof THREE.MeshBasicMaterial&&!u.envMap||u instanceof THREE.MeshDepthMaterial)){u=u&&u.shading!=void 0&&u.shading==THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading;
+break a}u=!1}a:{o=r=void 0;y=n.length;for(r=0;r<y;r++)if(o=n[r],o.vertexColors){o=o.vertexColors;break a}o=!1}i.__vertexArray=new Float32Array(k*3);if(u)i.__normalArray=new Float32Array(k*3);if(q.hasTangents)i.__tangentArray=new Float32Array(k*4);if(o)i.__colorArray=new Float32Array(k*3);if(p){if(q.faceUvs.length>0||q.faceVertexUvs.length>0)i.__uvArray=new Float32Array(k*2);if(q.faceUvs.length>1||q.faceVertexUvs.length>1)i.__uv2Array=new Float32Array(k*2)}if(j.geometry.skinWeights.length&&j.geometry.skinIndices.length)i.__skinVertexAArray=
+new Float32Array(k*4),i.__skinVertexBArray=new Float32Array(k*4),i.__skinIndexArray=new Float32Array(k*4),i.__skinWeightArray=new Float32Array(k*4);i.__faceArray=new Uint16Array(t*3+(j.geometry.edgeFaces?j.geometry.edgeFaces.length*6:0));i.__lineArray=new Uint16Array(v*2);if(i.numMorphTargets){i.__morphTargetsArrays=[];q=0;for(r=i.numMorphTargets;q<r;q++)i.__morphTargetsArrays.push(new Float32Array(k*3))}i.__needsSmoothNormals=u==THREE.SmoothShading;i.__uvType=p;i.__vertexColorType=o;i.__normalType=
+u;i.__webglFaceCount=t*3+(j.geometry.edgeFaces?j.geometry.edgeFaces.length*6:0);i.__webglLineCount=v*2;q=0;for(r=n.length;q<r;q++)if(p=n[q],p.attributes)for(a in i.__webglCustomAttributes={},p.attributes){o=p.attributes[a];u={};for(x in o)u[x]=o[x];if(!u.__webglInitialized||u.createUniqueBuffers)u.__webglInitialized=!0,t=1,u.type==="v2"?t=2:u.type==="v3"?t=3:u.type==="v4"?t=4:u.type==="c"&&(t=3),u.size=t,u.array=new Float32Array(k*t),u.buffer=c.createBuffer(),u.buffer.belongsToAttribute=a,o.needsUpdate=
+!0,u.__original=o;i.__webglCustomAttributes[a]=u}i.__inittedArrays=!0;g.__dirtyVertices=!0;g.__dirtyMorphTargets=!0;g.__dirtyElements=!0;g.__dirtyUvs=!0;g.__dirtyNormals=!0;g.__dirtyTangents=!0;g.__dirtyColors=!0}d instanceof THREE.ShadowVolume?H(e.__webglShadowVolumes,h,d):H(e.__webglObjects,h,d)}else if(d instanceof THREE.LensFlare)H(e.__webglLensFlares,void 0,d);else if(d instanceof THREE.Ribbon){g=d.geometry;if(!g.__webglVertexBuffer)f=g,f.__webglVertexBuffer=c.createBuffer(),f.__webglColorBuffer=
+c.createBuffer(),f=g,h=f.vertices.length,f.__vertexArray=new Float32Array(h*3),f.__colorArray=new Float32Array(h*3),f.__webglVertexCount=h,g.__dirtyVertices=!0,g.__dirtyColors=!0;H(e.__webglObjects,g,d)}else if(d instanceof THREE.Line){g=d.geometry;if(!g.__webglVertexBuffer)f=g,f.__webglVertexBuffer=c.createBuffer(),f.__webglColorBuffer=c.createBuffer(),f=g,h=f.vertices.length,f.__vertexArray=new Float32Array(h*3),f.__colorArray=new Float32Array(h*3),f.__webglLineCount=h,g.__dirtyVertices=!0,g.__dirtyColors=
+!0;H(e.__webglObjects,g,d)}else if(d instanceof THREE.ParticleSystem){g=d.geometry;if(!g.__webglVertexBuffer)f=g,f.__webglVertexBuffer=c.createBuffer(),f.__webglColorBuffer=c.createBuffer(),f=g,h=f.vertices.length,f.__vertexArray=new Float32Array(h*3),f.__colorArray=new Float32Array(h*3),f.__sortArray=[],f.__webglParticleCount=h,g.__dirtyVertices=!0,g.__dirtyColors=!0;H(e.__webglObjects,g,d)}else THREE.MarchingCubes!==void 0&&d instanceof THREE.MarchingCubes?e.__webglObjectsImmediate.push({object:d,
+opaque:{list:[],count:0},transparent:{list:[],count:0}}):d instanceof THREE.Sprite&&e.__webglSprites.push(d);b.__objectsAdded.splice(0,1)}for(;b.__objectsRemoved.length;){e=b.__objectsRemoved[0];d=b;if(e instanceof THREE.ShadowVolume)ea(d.__webglShadowVolumes,e);else if(e instanceof THREE.Mesh||e instanceof THREE.ParticleSystem||e instanceof THREE.Ribbon||e instanceof THREE.Line)ea(d.__webglObjects,e);else if(e instanceof THREE.Sprite){d=d.__webglSprites;g=void 0;for(g=d.length-1;g>=0;g--)d[g]==e&&
+d.splice(g,1)}else e instanceof THREE.LensFlare?ea(d.__webglLensFlares,e):e instanceof THREE.MarchingCubes&&ea(d.__webglObjectsImmediate,e);b.__objectsRemoved.splice(0,1)}d=0;for(e=b.__webglObjects.length;d<e;d++)N(b.__webglObjects[d].object,b);d=0;for(e=b.__webglShadowVolumes.length;d<e;d++)N(b.__webglShadowVolumes[d].object,b);d=0;for(e=b.__webglLensFlares.length;d<e;d++)N(b.__webglLensFlares[d].object,b)};this.setFaceCulling=function(b,d){b?(!d||d=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW),b==
+"back"?c.cullFace(c.BACK):b=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK),c.enable(c.CULL_FACE)):c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return Ja}};
 THREE.WebGLRenderTarget=function(b,e,d){this.width=b;this.height=e;d=d||{};this.wrapS=d.wrapS!==void 0?d.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=d.wrapT!==void 0?d.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=d.magFilter!==void 0?d.magFilter:THREE.LinearFilter;this.minFilter=d.minFilter!==void 0?d.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=d.format!==void 0?d.format:THREE.RGBAFormat;this.type=d.type!==void 0?d.type:
 THREE.UnsignedByteType;this.depthBuffer=d.depthBuffer!==void 0?d.depthBuffer:!0;this.stencilBuffer=d.stencilBuffer!==void 0?d.stencilBuffer:!0};

+ 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/FPCamera.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.FPCamera( {
+				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/FPCamera.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>

+ 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.FPCamera( {
+				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.FPCamera( {
+				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.FPCamera( {
+				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.FPCamera( {
+				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.FPCamera( {
+				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 );

+ 4 - 4
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 -150px 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>
@@ -109,7 +109,9 @@
 				geometry = new THREE.PlaneGeometry( 100, 100, 15, 10 );
 	
 				mesh = new THREE.Mesh( geometry, xm );
+				mesh.position.x = 0;
 				mesh.position.y = FLOOR;
+				mesh.position.z = 0;
 				mesh.rotation.x = 1.57;
 				mesh.scale.x = mesh.scale.y = mesh.scale.z = 10;
 				mesh.doubleSided = true;
@@ -121,8 +123,7 @@
 				var material_spheres = new THREE.MeshLambertMaterial( { color: 0xdddddd } ),
 					sphere = new THREE.SphereGeometry( 100, 16, 8 );
 
-				for ( var i = 0; i < 10; i ++ ) {
-
+				for ( var i=0; i<10; i++ ) {
 					mesh = new THREE.Mesh( sphere, material_spheres );
 					mesh.position.x = 500 * (Math.random() - 0.5);
 					mesh.position.y = 300 * (Math.random() - 0) + FLOOR;
@@ -131,7 +132,6 @@
 					mesh.overdraw = true;
 					mesh.updateMatrix();
 					scene.addObject(mesh);
-
 				}
 
 

+ 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/FPCamera.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>

+ 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;

+ 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 = {
 	}
 
 };
+
+};

+ 5 - 5
src/extras/cameras/FPCamera.js → src/extras/cameras/FirstPersonCamera.js

@@ -30,7 +30,7 @@
  * }
  */
 
-THREE.FPCamera = function ( parameters ) {
+THREE.FirstPersonCamera = function ( parameters ) {
 
 	THREE.Camera.call( this, parameters.fov, parameters.aspect, parameters.near, parameters.far, parameters.target );
 
@@ -307,12 +307,12 @@ THREE.FPCamera = function ( parameters ) {
 };
 
 
-THREE.FPCamera.prototype = new THREE.Camera();
-THREE.FPCamera.prototype.constructor = THREE.FPCamera;
-THREE.FPCamera.prototype.supr = THREE.Camera.prototype;
+THREE.FirstPersonCamera.prototype = new THREE.Camera();
+THREE.FirstPersonCamera.prototype.constructor = THREE.FirstPersonCamera;
+THREE.FirstPersonCamera.prototype.supr = THREE.Camera.prototype;
 
 
-THREE.FPCamera.prototype.translate = function ( distance, axis ) {
+THREE.FirstPersonCamera.prototype.translate = function ( distance, axis ) {
 
 	this.matrix.rotateAxis( axis );
 

+ 2 - 2
src/extras/cameras/QuakeCamera.js

@@ -1,7 +1,7 @@
 /**
  * @author chriskillpack / http://chriskillpack.com/
  *
- * QuakeCamera has been renamed FPCamera. This property exists for backwards
+ * QuakeCamera has been renamed FirstPersonCamera. This property exists for backwards
  * compatibility only.
  */
-THREE.QuakeCamera = THREE.FPCamera;
+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
 
 				}
 
-			} 
+			}
 
 		}
 

+ 153 - 39
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,65 +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 );
 
-			if( m.mapDiffuseRepeat ) {
+		} else if ( m.DbgColor ) {
 
-				mpars.map.repeat.set( m.mapDiffuseRepeat[ 0 ], m.mapDiffuseRepeat[ 1 ] );
-				mpars.map.wrapS = mpars.map.wrapT = THREE.RepeatWrapping;
+			mpars.color = m.DbgColor;
 
-			}
+		}
 
-			if( m.mapDiffuseOffset ) {
+		if ( m.colorSpecular ) {
 
-				mpars.map.offset.set( m.mapDiffuseOffset[ 0 ], m.mapDiffuseOffset[ 1 ] );
+			mpars.specular = rgb2hex( m.colorSpecular );
 
-			}
+		}
 
-			load_image( mpars.map, texture_path + "/" + m.mapDiffuse );
+		if ( m.colorAmbient ) {
 
-		} else if ( m.colorDiffuse ) {
+			mpars.ambient = rgb2hex( m.colorAmbient );
 
-			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 ) {
+		// modifiers
 
-			mpars.color = m.DbgColor;
+		if ( m.transparency ) {
+
+			mpars.opacity = m.transparency;
+
+		}
+
+		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 ) {
 
-			texture = document.createElement( 'canvas' );
+			create_texture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
+
+		}
 
-			mpars.lightMap = new THREE.Texture( texture );
-			mpars.lightMap.sourceFile = m.mapLight;
+		if ( m.mapNormal && texture_path ) {
 
-			if( m.mapLightmapRepeat ) {
+			create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
+
+		}
 
-				mpars.lightMap.repeat.set( m.mapLightRepeat[ 0 ], m.mapLightRepeat[ 1 ] );
-				mpars.lightMap.wrapS = mpars.lightMap.wrapT = THREE.RepeatWrapping;
+		// 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( m.mapLightmapOffset ) {
+			if ( mpars.map ) {
 
-				mpars.lightMap.offset.set( m.mapLightmapOffset[ 0 ], m.mapLightmapOffset[ 1 ] );
+				uniforms[ "tDiffuse" ].texture = mpars.map;
+				uniforms[ "enableDiffuse" ].value = true;
 
 			}
 
-			load_image( mpars.lightMap, texture_path + "/" + m.mapLightmap );
+			// 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 ) {
 
-		material = new THREE[ mtype ]( mpars );
+				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;
 

+ 106 - 20
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();
 
 					}
@@ -589,11 +603,34 @@ 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 ] );
-						texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
+
+						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 ] ];
 
 					}
 
@@ -646,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;
 
 			}

+ 4 - 4
src/materials/Material.js

@@ -13,10 +13,10 @@ 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;
+
+	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 - 1
src/objects/Sprite.js

@@ -24,7 +24,7 @@ THREE.Sprite = function( parameters ) {
 	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.alignment = parameters.alignment instanceof THREE.Vector2 ? parameters.alignment : THREE.SpriteAlignment.center;
 
 	this.rotation3d = this.rotation;
 	this.rotation = 0;

+ 191 - 141
src/renderers/WebGLRenderer.js

@@ -179,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"         );
+
 	}
 
 
@@ -193,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;
 
@@ -268,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;
@@ -529,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++ ) {
 
@@ -614,7 +622,7 @@ 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
@@ -679,7 +687,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		if ( geometryGroup.numMorphTargets ) {
 
-			geometryGroup.__morphTargetsArrays = []; 
+			geometryGroup.__morphTargetsArrays = [];
 
 			for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m++ ) {
 
@@ -739,7 +747,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 						attribute.array = new Float32Array( nvertices * size );
 						attribute.buffer = _gl.createBuffer();
 						attribute.buffer.belongsToAttribute = a;
-						
+
 						originalAttribute.needsUpdate = true;
 						attribute.__original = originalAttribute;
 
@@ -917,7 +925,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 					for ( a in customAttributes ) {
 
 						customAttribute = customAttributes[ a ];
-						
+
 						if ( customAttribute.__original.needsUpdate ) {
 
 							offset_custom = customAttribute.offset;
@@ -2181,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 );
 
 		}
@@ -2309,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,
@@ -2340,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 ] );
-	
+
 			}
-			
+
 		}
 
 
@@ -2515,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 );
-				
+
 			}
 
 		}
@@ -2527,9 +2535,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 			 material.skinning ) {
 
 			if ( p_uniforms.objectMatrix !== null ) {
-				
+
 				_gl.uniformMatrix4fv( p_uniforms.objectMatrix, false, object._objectMatrixArray );
-				
+
 			}
 
 		}
@@ -2540,10 +2548,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 			 material.skinning ) {
 
 			if( p_uniforms.viewMatrix !== null ) {
-				
+
 				_gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, _viewMatrixArray );
-				
-			} 
+
+			}
 
 		}
 
@@ -2626,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 );
 
@@ -2857,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 );
-			
+
 		}
 
 	}
@@ -2910,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;
 
@@ -2993,35 +3001,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 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 ) {
 
@@ -3182,16 +3190,16 @@ THREE.WebGLRenderer = function ( parameters ) {
 					if ( this.sortObjects ) {
 
 						if ( webglObject.object.renderDepth ) {
-							
+
 							webglObject.z = webglObject.object.renderDepth;
-						
+
 						} else {
-						
+
 							_vector3.copy( object.position );
 							_projScreenMatrix.multiplyVector3( _vector3 );
-	
+
 							webglObject.z = _vector3.z;
-							
+
 						}
 
 					}
@@ -3239,118 +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 ) {
 
-			if ( webglObject.render ) {
+					object = webglObject.object;
+					buffer = webglObject.buffer;
 
+					setObjectFaces( object );
+
+					renderBuffer( camera, lights, fog, scene.overrideMaterial, buffer, object );
+
+				}
+
+			}
+
+			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;
+
+					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 );
-					renderBuffer( camera, lights, fog, material, buffer, object );
+						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 );
-                    setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
+						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 );
-                    setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
+						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 );
-                    setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
+						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 ); } );
+					}
 
 				}
 
@@ -3401,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 ) {
@@ -3537,7 +3587,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	/*
 	 * Render sprites
-	 * 
+	 *
 	 */
 
 	function renderSprites( scene, camera ) {
@@ -3617,7 +3667,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 					if ( object.useScreenCoordinates ) {
 
 						_gl.uniform1i( uniforms.useScreenCoordinates, 1 );
-						_gl.uniform3f( uniforms.screenPosition, ( object.position.x - halfViewportWidth  ) / halfViewportWidth, 
+						_gl.uniform3f( uniforms.screenPosition, ( object.position.x - halfViewportWidth  ) / halfViewportWidth,
 																( halfViewportHeight - object.position.y ) / halfViewportHeight,
 																  Math.max( 0, Math.min( 1, object.position.z )));
 
@@ -3689,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 ) {
@@ -3725,10 +3775,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		if ( ! _lensFlareAttributesEnabled ) {
-		
+
 			_gl.enableVertexAttribArray( _lensFlare.attributes.vertex );
 			_gl.enableVertexAttribArray( _lensFlare.attributes.uv );
-			
+
 			_lensFlareAttributesEnabled = true;
 
 		}
@@ -3777,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 &&
@@ -4497,7 +4547,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		].join("\n");
 
 		var prefix_vertex = [
-			
+
 			_supportsVertexTextures ? "#define VERTEX_TEXTURES" : "",
 
 			"#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
@@ -4830,7 +4880,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 		*/
-		
+
 		_gl.activeTexture( _gl.TEXTURE0 + slot );
 		_gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
 
@@ -4917,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 );
@@ -5045,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.py

@@ -89,7 +89,7 @@ EXTRAS_FILES = [
 'extras/ShaderUtils.js',
 'extras/animation/AnimationHandler.js',
 'extras/animation/Animation.js',
-'extras/cameras/FPCamera.js',
+'extras/cameras/FirstPersonCamera.js',
 'extras/cameras/PathCamera.js',
 'extras/cameras/FlyCamera.js',
 'extras/cameras/RollCamera.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()
 
 

+ 219 - 70
utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -20,13 +20,13 @@
 Blender exporter for Three.js (ASCII JSON format).
 
 TODO
-    - copy used images to folder where exported file goes
     - binary format
 """
 
 import bpy
 import mathutils
 
+import shutil
 import os
 import os.path
 import math
@@ -91,7 +91,7 @@ TEMPLATE_SCENE_ASCII = """\
 var scene = {
 
 "type" : "scene",
-"urlBaseType" : "relativeToScene",
+"urlBaseType" : %(basetype)s,
 
 %(sections)s
 
@@ -693,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):
@@ -721,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 = {}
@@ -749,22 +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
 
-            texture = m.active_texture
+            textures = guess_material_textures(m)
 
-            if texture and texture.type == 'IMAGE' and texture.image:
-                fn = bpy.path.abspath(texture.image.filepath)
-                fn = os.path.normpath(fn)
-                fn_strip = os.path.basename(fn)
-
-                material['mapDiffuse'] = fn_strip
-                
-                if texture.repeat_x != 1 or texture.repeat_y != 1:
-                    material['mapDiffuseRepeat'] = [texture.repeat_x, texture.repeat_y]
+            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
 
@@ -779,7 +775,7 @@ def extract_materials(mesh, scene, option_colors):
 
     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
 
@@ -801,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
 # #####################################################
@@ -821,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[:]
 
@@ -843,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)
@@ -897,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
 
@@ -937,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,
@@ -949,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)
@@ -968,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"""
 
@@ -984,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)
 
@@ -1085,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,
@@ -1103,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
@@ -1195,10 +1239,25 @@ def generate_textures_scene(data):
 
             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)
+                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),
@@ -1215,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
 # #####################################################
@@ -1248,38 +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 t.use_normal_map:
-                    material['mapNormal'] = name
+                if texture.use_normal_map:
+                    textures['normal'] = { "texture": texture, "slot": slot }
 
                 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
 
-    material['shading'] = m.THREE_materialType
-
-    return material
+    return textures
 
 def generate_material_string(material):
     type_map = {
@@ -1302,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)
@@ -1309,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"'
@@ -1340,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":
 
@@ -1377,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 ""
@@ -1455,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],
@@ -1474,7 +1600,11 @@ def generate_ascii_scene(data):
 
     default_camera = ""
     if data["use_cameras"]:
-        default_camera = "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"],
@@ -1488,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"]),
@@ -1499,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)
 
@@ -1539,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')
 
@@ -1580,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,
@@ -1599,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:
 
@@ -1626,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'}

+ 23 - 7
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/__init__.py

@@ -20,13 +20,11 @@
 # Init
 # ################################################################
 
-# To support reload properly, try to access a package var,
-# if it's there, reload everything
 
 bl_info = {
     "name": "three.js format",
-    "author": "mrdoob, kikko, alteredq, remoe",
-    "version": (1, 0),
+    "author": "mrdoob, kikko, alteredq, remoe, pxf",
+    "version": (1, 0, 2),
     "blender": (2, 5, 7),
     "api": 35622,
     "location": "File > Import-Export",
@@ -36,6 +34,11 @@ bl_info = {
     "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():
@@ -43,7 +46,6 @@ if "bpy" in locals():
     if "import_threejs" in locals():
         imp.reload(import_threejs)
 
-import bpy
 from bpy.props import *
 from bpy_extras.io_utils import ExportHelper, ImportHelper
 
@@ -175,7 +177,9 @@ 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 +229,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 +269,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 +292,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 +350,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()
 
 

+ 235 - 86
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -20,13 +20,13 @@
 Blender exporter for Three.js (ASCII JSON format).
 
 TODO
-    - copy used images to folder where exported file goes
     - binary format
 """
 
 import bpy
 import mathutils
 
+import shutil
 import os
 import os.path
 import math
@@ -79,7 +79,7 @@ COLORS = [0xeeeeee, 0xee0000, 0x00ee00, 0x0000ee, 0xeeee00, 0x00eeee, 0xee00ee]
 TEMPLATE_SCENE_ASCII = """\
 /* Converted from: %(fname)s
  *
- * File generated with Blender 2.57 Exporter
+ * File generated with Blender 2.58 Exporter
  * https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender/
  *
  * objects:    %(nobjects)s
@@ -91,7 +91,7 @@ TEMPLATE_SCENE_ASCII = """\
 var scene = {
 
 "type" : "scene",
-"urlBaseType" : "relativeToScene",
+"urlBaseType" : %(basetype)s,
 
 %(sections)s
 
@@ -222,7 +222,7 @@ TEMPLATE_HEX = "0x%06x"
 
 TEMPLATE_FILE_ASCII = """\
 /*
- * File generated with Blender 2.57 Exporter
+ * File generated with Blender 2.58 Exporter
  * https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender/
  *
  * vertices: %(nvertex)d
@@ -693,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):
@@ -721,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 = {}
@@ -749,22 +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
 
-            texture = m.active_texture
+            textures = guess_material_textures(m)
 
-            if texture and texture.type == 'IMAGE' and texture.image:
-                fn = bpy.path.abspath(texture.image.filepath)
-                fn = os.path.normpath(fn)
-                fn_strip = os.path.basename(fn)
-
-                material['mapDiffuse'] = fn_strip
-                
-                if texture.repeat_x != 1 or texture.repeat_y != 1:
-                    material['mapDiffuseRepeat'] = [texture.repeat_x, texture.repeat_y]
+            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
 
@@ -779,7 +775,7 @@ def extract_materials(mesh, scene, option_colors):
 
     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
 
@@ -801,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
 # #####################################################
@@ -821,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[:]
 
@@ -843,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)
@@ -873,7 +906,7 @@ def generate_ascii_model(mesh, scene,
     "ncolor"    : ncolor,
     "nmaterial" : nmaterial,
     "nedges"    : nedges,
-    
+
     "model"     : model_string
     }
 
@@ -897,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
 
@@ -937,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,
@@ -949,11 +988,13 @@ 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)
-    
+
     return text, model_string
 
 def export_mesh(obj, scene, filepath,
@@ -968,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"""
 
@@ -984,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)
 
@@ -1085,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,
@@ -1103,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
@@ -1117,7 +1161,7 @@ def generate_objects(data):
                 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,
@@ -1153,7 +1197,7 @@ def generate_geometries(data):
             if name not in geo_set:
 
                 geometry_id = "geo_%s" % name
-                
+
                 if data["embed_meshes"]:
 
                     embed_id = "emb_%s" % name
@@ -1195,10 +1239,25 @@ def generate_textures_scene(data):
 
             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)
+                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),
@@ -1215,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
 # #####################################################
@@ -1248,38 +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 t.use_normal_map:
-                    material['mapNormal'] = name
+                if texture.use_normal_map:
+                    textures['normal'] = { "texture": texture, "slot": slot }
 
                 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
 
-    material['shading'] = m.THREE_materialType
-
-    return material
+    return textures
 
 def generate_material_string(material):
     type_map = {
@@ -1302,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)
@@ -1309,10 +1404,12 @@ 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"'
-        
+
     material_string = TEMPLATE_MATERIAL_SCENE % {
     "material_id" : generate_string(material_id),
     "type"        : generate_string(material_type),
@@ -1340,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":
 
@@ -1377,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 ""
@@ -1417,7 +1536,7 @@ def generate_lights(data):
             chunks.append(light_string)
 
         return ",\n\n".join(chunks)
-        
+
     return ""
 
 # #####################################################
@@ -1425,20 +1544,20 @@ def generate_lights(data):
 # #####################################################
 
 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
 # #####################################################
@@ -1455,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],
@@ -1474,7 +1600,11 @@ def generate_ascii_scene(data):
 
     default_camera = ""
     if data["use_cameras"]:
-        default_camera = "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"],
@@ -1488,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"]),
@@ -1499,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)
 
@@ -1539,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,9 +1705,9 @@ def save(operator, context, filepath = "",
                     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,
@@ -1580,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,
@@ -1599,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:
 
@@ -1626,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'}

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