Browse Source

Merge remote branch 'upstream/master'

timk 14 years ago
parent
commit
e06a811f5a
98 changed files with 8850 additions and 8424 deletions
  1. 25 5
      README.md
  2. 1 1
      REVISION
  3. 82 149
      build/Three.js
  4. 100 97
      build/custom/ThreeCanvas.js
  5. 43 42
      build/custom/ThreeDOM.js
  6. 13 7
      build/custom/ThreeExtras.js
  7. 90 90
      build/custom/ThreeSVG.js
  8. 118 131
      build/custom/ThreeWebGL.js
  9. 0 1
      examples/canvas_geometry_birds.html
  10. 1 0
      examples/canvas_geometry_earth.html
  11. 18 21
      examples/canvas_geometry_text.html
  12. 1 1
      examples/canvas_interactive_particles.html
  13. 4 1
      examples/canvas_materials_depth.html
  14. 1 0
      examples/canvas_particles_sprites.html
  15. 5 1
      examples/canvas_sandbox.html
  16. 8 5
      examples/misc_ubiquity_test.html
  17. 0 1
      examples/textures/metal.txt
  18. BIN
      examples/textures/sprites/disc.png
  19. BIN
      examples/textures/sprites/spark1.png
  20. BIN
      examples/utf8/ben.utf8
  21. BIN
      examples/utf8/hand.utf8
  22. 5 2
      examples/webgl_custom_attributes.html
  23. 224 0
      examples/webgl_custom_attributes_particles.html
  24. 223 0
      examples/webgl_custom_attributes_particles2.html
  25. 282 0
      examples/webgl_custom_attributes_particles3.html
  26. 1 1
      examples/webgl_flycamera_earth.html
  27. 1 1
      examples/webgl_geometry_dynamic.html
  28. 1 1
      examples/webgl_geometry_large_mesh.html
  29. 1 1
      examples/webgl_geometry_minecraft.html
  30. 3 3
      examples/webgl_geometry_minecraft_ao.html
  31. 477 0
      examples/webgl_geometry_shapes.html
  32. 111 133
      examples/webgl_geometry_text.html
  33. 1 1
      examples/webgl_interactive_cubes.html
  34. 1 1
      examples/webgl_materials_grass.html
  35. 3 3
      examples/webgl_objconvert_test.html
  36. 5 3
      examples/webgl_sandbox.html
  37. 411 0
      examples/webgl_shadowmap.html
  38. 0 178
      examples/webgl_stencil.html
  39. 0 190
      examples/webgl_stencilLensFlare.html
  40. 174 0
      examples/webgl_utf8loader.html
  41. 39 30
      src/core/Color.js
  42. 4 0
      src/core/Geometry.js
  43. 4 2
      src/core/Matrix3.js
  44. 35 25
      src/core/Matrix4.js
  45. 11 6
      src/core/Object3D.js
  46. 11 9
      src/core/Quaternion.js
  47. 2 0
      src/core/Ray.js
  48. 4 2
      src/core/UV.js
  49. 21 19
      src/core/Vector2.js
  50. 29 27
      src/core/Vector3.js
  51. 19 17
      src/core/Vector4.js
  52. 352 1
      src/extras/GeometryUtils.js
  53. 13 4
      src/extras/ShaderUtils.js
  54. 72 67
      src/extras/animation/AnimationHandler.js
  55. 21 2
      src/extras/cameras/FirstPersonCamera.js
  56. 662 0
      src/extras/geometries/Curve.js
  57. 298 0
      src/extras/geometries/CurvePath.js
  58. 704 0
      src/extras/geometries/ExtrudeGeometry.js
  59. 0 3
      src/extras/geometries/IcosahedronGeometry.js
  60. 641 0
      src/extras/geometries/Path.js
  61. 514 0
      src/extras/geometries/Shape.js
  62. 201 445
      src/extras/geometries/TextGeometry.js
  63. 68 0
      src/extras/geometries/TextPath.js
  64. 0 2
      src/extras/geometries/TorusGeometry.js
  65. 3 1
      src/extras/io/BinaryLoader.js
  66. 3 1
      src/extras/io/Loader.js
  67. 3 1
      src/extras/io/LoaderOld.js
  68. 3 1
      src/extras/io/SceneLoader.js
  69. 350 0
      src/extras/io/UTF8Loader.js
  70. 0 87
      src/lights/LensFlare.js
  71. 20 0
      src/lights/SpotLight.js
  72. 31 0
      src/materials/DataTexture.js
  73. 5 4
      src/materials/Material.js
  74. 0 63
      src/materials/ShadowVolumeDynamicMaterial.js
  75. 12 1
      src/materials/Texture.js
  76. 3 2
      src/objects/Mesh.js
  77. 0 345
      src/objects/ShadowVolume.js
  78. 93 75
      src/renderers/CanvasRenderer.js
  79. 9 13
      src/renderers/SVGRenderer.js
  80. 394 239
      src/renderers/WebGLRenderer.js
  81. 285 20
      src/renderers/WebGLShaders.js
  82. 10 6
      utils/build.py
  83. 0 359
      utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/__init__.py
  84. 0 1623
      utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/export_threejs.py
  85. 0 635
      utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/import_threejs.py
  86. 0 388
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/__init__.py
  87. 0 1781
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/export_threejs.py
  88. 0 631
      utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/import_threejs.py
  89. 35 4
      utils/exporters/blender/2.59/scripts/addons/io_mesh_threejs/__init__.py
  90. 249 122
      utils/exporters/blender/2.59/scripts/addons/io_mesh_threejs/export_threejs.py
  91. 0 0
      utils/exporters/blender/2.59/scripts/addons/io_mesh_threejs/import_threejs.py
  92. 179 172
      utils/exporters/convert_obj_three.py
  93. 118 118
      utils/exporters/max/ThreeJSExporter.ms
  94. 37 0
      utils/exporters/utf8/README
  95. 1 0
      utils/exporters/utf8/build.bat
  96. 787 0
      utils/exporters/utf8/mesh.h
  97. 61 0
      utils/exporters/utf8/objcompress.cc
  98. BIN
      utils/exporters/utf8/objcompress.exe

+ 25 - 5
README.md

@@ -5,7 +5,7 @@ three.js
 
 The aim of the project is to create a lightweight 3D engine with a very low level of complexity — in other words, for dummies. The engine can render using <canvas>, <svg> and WebGL.
 
-[Contributors](https://github.com/mrdoob/three.js/contributors) — [Getting Started](http://www.aerotwist.com/lab/getting-started-with-three-js/) — [API Reference](https://github.com/mrdoob/three.js/wiki/API-Reference)
+[Contributors](http://github.com/mrdoob/three.js/contributors) — [Getting Started](http://www.aerotwist.com/lab/getting-started-with-three-js/) — [API Reference](http://github.com/mrdoob/three.js/wiki/API-Reference)
 
 More? [#three.js on irc.freenode.net](http://webchat.freenode.net/?channels=three.js)
 
@@ -66,7 +66,7 @@ More? [#three.js on irc.freenode.net](http://webchat.freenode.net/?channels=thre
 [![Infinite beanstalk](http://mrdoob.github.com/three.js/assets/projects/19_beanstalk.png)](http://inear.se/beanstalk/)
 [![Mission Control](http://mrdoob.github.com/three.js/assets/projects/18_missioncontrol.png)](http://superfad.com/missioncontrol/)
 [![ROME](http://mrdoob.github.com/three.js/assets/projects/17_rome.png)](http://ro.me/)
-[![Globe](http://mrdoob.github.com/three.js/assets/projects/16_globe.png)](http://data-arts.appspot.com/globe/)
+[![Globe](http://mrdoob.github.com/three.js/assets/projects/16_globe.png)](http://data-arts.appspot.com/globe)
 [![Photoparticles](http://mrdoob.github.com/three.js/assets/projects/15_photoparticles.png)](http://lab.aerotwist.com/webgl/photoparticles/)
 [![Plumegraph](http://mrdoob.github.com/three.js/assets/projects/14_plumegraph.png)](http://plumegraph.org/)
 [![HelloRacer](http://mrdoob.github.com/three.js/assets/projects/13_helloracer.png)](http://helloracer.com/webgl/)
@@ -135,13 +135,33 @@ This code creates a camera, then creates a scene, adds a cube on it, creates a &
 
 ### Change Log ###
 
-2011 07 06 - **r42** (277.852 KB, gzip, gzip: 69.469 KB)
+
+2011 08 14 - **r43** (298.199 KB, gzip: 74.805 KB)
+
+* Improved Blender exporter - 2.58 (and 2.59) support, normals maps, specular, ao maps... ([alteredq](http://github.com/alteredq))
+* Added [CORS](http://www.w3.org/TR/cors/) to `ImageUtils`. ([mrdoob](http://github.com/mrdoob))
+* Refactored `TextGeometry` and added `Shape`, `Curve`, `Path`, `ExtrudeGeometry`, `TextPath`. ([zz85](http://github.com/zz85) and [alteredq](http://github.com/alteredq))
+* Added handling of custom attributes for `ParticleSystems`. ([alteredq](http://github.com/alteredq))
+* Fixed `CanvasRenderer.setClearColor`. ([mrdoob](http://github.com/mrdoob), [StephenHopkins](http://github.com/StephenHopkins) and [sebleedelisle](http://github.com/sebleedelisle))
+* Improved uniform handling in `WebGLRenderer`. ([alteredq](http://github.com/alteredq))
+* Implemented Shadow Mapping in `WebGLRenderer`. ([alteredq](http://github.com/alteredq))
+* Added `Spotlight` light type. ([alteredq](http://github.com/alteredq))
+* Fixed constructor-less prototypes. ([pushmatrix](http://github.com/pushmatrix))
+* Added `DataTexture`. ([alteredq](http://github.com/alteredq))
+* `WebGLRenderer` opaque pass now renders from front to back. ([alteredq](http://github.com/alteredq))
+* Simplified `Color`. ([mrdoob](http://github.com/mrdoob))
+* Added `preserveDrawingBuffer` option to `WebGLRenderer`. ([jeromeetienne](http://github.com/jeromeetienne))
+* Added `UTF8Loader` for loading the new, uber compressed, [UTF8 format](http://code.google.com/p/webgl-loader/). ([alteredq](http://github.com/alteredq))
+* `CanvasRenderer` now supports `RepeatWrapping`, `texture.offset` and `texture.repeat`. ([mrdoob](http://github.com/mrdoob))
+* Removed Stencil Shadows and Lensflare code. ([mrdoob](http://github.com/mrdoob))
+
+2011 07 06 - **r42** (277.852 KB, gzip: 69.469 KB)
 
 * Added `AnaglypWebGLRenderer` and `CrosseyedWebGLRenderer`. ([mrdoob](http://github.com/mrdoob), [alteredq](http://github.com/alteredq) and [marklundin](http://github.com/marklundin))
 * Added `TextGeometry`. ([zz85](http://github.com/zz85) and [alteredq](http://github.com/alteredq))
 * Added `setViewOffset` method to `Camera`. ([greggman](http://github.com/greggman))
 * Renamed geometries to `*Geometry`. ([mrdoob](http://github.com/mrdoob))
-* Improved Blender exporter. ([alteredq](http://github.com/alteredq), [sweetfish](http://github.com/sweetfish) and [Jhonnyg](https://github.com/Jhonnyg))
+* Improved Blender exporter. ([alteredq](http://github.com/alteredq), [sweetfish](http://github.com/sweetfish) and [Jhonnyg](http://github.com/Jhonnyg))
 * Added Blender 2.58 exporter. ([georgik](http://github.com/georgik))
 * Fixed `Matrix4.multiply()`. (thanks [lukem1](http://github.com/lukem1)) 
 * Added support for additional Euler rotation orders in `Matrix4`. ([rectalogic](http://github.com/rectalogic))
@@ -154,7 +174,7 @@ This code creates a camera, then creates a scene, adds a cube on it, creates a &
 
 2011 05 31 - **r41/ROME** (265.317 KB, gzip: 64.849 KB)
 
-(Up to this point, some [rome](http://ro.me) specific features managed to get in the lib. The aim is to clean this up in next revisions.)
+(Up to this point, some [RO.ME](http://ro.me) specific features managed to get in the lib. The aim is to clean this up in next revisions.)
 
 * Improved Blender Object and Scene exporters. ([alteredq](http://github.com/alteredq))
 * Fixes on WebGL attributes. ([alteredq](http://github.com/alteredq) and [empaempa](http://github.com/empaempa))

+ 1 - 1
REVISION

@@ -1 +1 @@
-42
+43

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


+ 100 - 97
build/custom/ThreeCanvas.js

@@ -1,69 +1,70 @@
-// ThreeCanvas.js r42 - http://github.com/mrdoob/three.js
-var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){this.setHex(a)};
-THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,f,g,e,h,i;if(c==0)d=f=g=0;else switch(e=Math.floor(a*6),h=a*6-e,a=c*(1-b),i=c*(1-b*h),b=c*(1-b*(1-h)),e){case 1:d=i;f=c;g=a;break;case 2:d=a;f=c;g=b;break;case 3:d=a;f=i;g=c;break;case 4:d=b;f=a;g=c;break;case 5:d=c;f=a;g=i;break;case 6:case 0:d=c,f=b,g=a}this.setRGB(d,
-f,g)},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGB:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},clone:function(){return new THREE.Color(this.hex)}};THREE.Vector2=function(a,b){this.set(a||0,b||0)};
-THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},divideScalar:function(a){a?
-(this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
+// ThreeCanvas.js r43 - http://github.com/mrdoob/three.js
+var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){a!==void 0&&this.setHex(a);return this};
+THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;return this},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSV:function(a,b,c){var d,f,g;if(c==0)this.r=this.g=this.b=0;else switch(d=Math.floor(a*6),f=a*6-d,a=c*(1-b),g=c*(1-b*f),b=c*(1-b*(1-f)),d){case 1:this.r=g;this.g=c;this.b=a;break;case 2:this.r=a;this.g=c;this.b=b;break;case 3:this.r=a;this.g=g;this.b=c;break;case 4:this.r=b;this.g=a;this.b=c;break;case 5:this.r=
+c;this.g=a;this.b=g;break;case 6:case 0:this.r=c,this.g=b,this.b=a}return this},setHex:function(a){a=Math.floor(a);this.r=(a>>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},getHex:function(){return~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},getContextStyle:function(){return"rgb("+Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}};
+THREE.Vector2=function(a,b){this.set(a||0,b||0)};
+THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},
+divideScalar:function(a){a?(this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
 unit:function(){return this.normalize()},equals:function(a){return a.x==this.x&&a.y==this.y}};THREE.Vector3=function(a,b,c){this.set(a||0,b||0,c||0)};
-THREE.Vector3.prototype={set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=
-a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){return this.divide(this,a)},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.set(0,0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*
-a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){return this.set(this.y*a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*
-a.y-this.y*a.x)},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,a).lengthSq()},setPositionFromMatrix:function(a){this.x=a.n14;this.y=a.n24;this.z=a.n34},setRotationFromMatrix:function(a){var b=Math.cos(this.y);this.y=Math.asin(a.n13);Math.abs(b)>1.0E-5?(this.x=Math.atan2(-a.n23/b,a.n33/b),this.z=Math.atan2(-a.n12/b,a.n11/b)):(this.x=0,this.z=Math.atan2(a.n21,a.n22))},isZero:function(){return this.lengthSq()<1.0E-4}};
-THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
-THREE.Vector4.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=
-a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
+THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=
+a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){return this.divide(this,a)},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.set(0,0,0);return this},negate:function(){return this.multiplyScalar(-1)},
+dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){return this.set(this.y*
+a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*a.y-this.y*a.x)},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,a).lengthSq()},setPositionFromMatrix:function(a){this.x=a.n14;this.y=a.n24;this.z=a.n34},setRotationFromMatrix:function(a){var b=Math.cos(this.y);this.y=Math.asin(a.n13);Math.abs(b)>1.0E-5?(this.x=Math.atan2(-a.n23/b,a.n33/b),this.z=Math.atan2(-a.n12/b,a.n11/b)):(this.x=0,this.z=Math.atan2(a.n21,a.n22))},isZero:function(){return this.lengthSq()<
+1.0E-4}};THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
+THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},
+subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
 setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}};THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
-f=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(f),e=c.dot(c),c=c.dot(f),f=1/(a*e-b*b),e=(e*d-b*c)*f,a=(a*c-b*d)*f;return e>0&&a>0&&e+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var f,g,e,h,i,l,m,n,j,o,k=a.geometry,
-q=k.vertices,w=[],d=0;for(f=k.faces.length;d<f;d++)if(g=k.faces[d],j=this.origin.clone(),o=this.direction.clone(),l=a.matrixWorld,e=l.multiplyVector3(q[g.a].position.clone()),h=l.multiplyVector3(q[g.b].position.clone()),i=l.multiplyVector3(q[g.c].position.clone()),l=g instanceof THREE.Face4?l.multiplyVector3(q[g.d].position.clone()):null,m=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),n=o.dot(m),a.doubleSided||(a.flipSided?n>0:n<0))if(m=m.dot((new THREE.Vector3).sub(e,j))/n,j=j.addSelf(o.multiplyScalar(m)),
-g instanceof THREE.Face3)c(j,e,h,i)&&(g={distance:this.origin.distanceTo(j),point:j,face:g,object:a},w.push(g));else if(g instanceof THREE.Face4&&(c(j,e,h,l)||c(j,h,i,l)))g={distance:this.origin.distanceTo(j),point:j,face:g,object:a},w.push(g);return w}else return[]}};
-THREE.Rectangle=function(){function a(){g=d-b;e=f-c}var b,c,d,f,g,e,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return e};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return f};this.set=function(e,g,m,n){h=!1;b=e;c=g;d=m;f=n;a()};this.addPoint=function(e,g){h?(h=!1,b=e,c=g,d=e,f=g):(b=b<e?b:e,c=c<g?c:g,d=d>e?d:e,f=f>g?f:g);a()};this.add3Points=
-function(e,g,m,n,j,o){h?(h=!1,b=e<m?e<j?e:j:m<j?m:j,c=g<n?g<o?g:o:n<o?n:o,d=e>m?e>j?e:j:m>j?m:j,f=g>n?g>o?g:o:n>o?n:o):(b=e<m?e<j?e<b?e:b:j<b?j:b:m<j?m<b?m:b:j<b?j:b,c=g<n?g<o?g<c?g:c:o<c?o:c:n<o?n<c?n:c:o<c?o:c,d=e>m?e>j?e>d?e:d:j>d?j:d:m>j?m>d?m:d:j>d?j:d,f=g>n?g>o?g>f?g:f:o>f?o:f:n>o?n>f?n:f:o>f?o:f);a()};this.addRectangle=function(e){h?(h=!1,b=e.getLeft(),c=e.getTop(),d=e.getRight(),f=e.getBottom()):(b=b<e.getLeft()?b:e.getLeft(),c=c<e.getTop()?c:e.getTop(),d=d>e.getRight()?d:e.getRight(),f=f>
+THREE.Ray.prototype={constructor:THREE.Ray,intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),
+c=c.clone().subSelf(b),f=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(f),e=c.dot(c),c=c.dot(f),f=1/(a*e-b*b),e=(e*d-b*c)*f,a=(a*c-b*d)*f;return e>0&&a>0&&e+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var f,g,e,h,
+j,l,m,i,n,k,p=a.geometry,q=p.vertices,v=[],d=0;for(f=p.faces.length;d<f;d++)if(g=p.faces[d],n=this.origin.clone(),k=this.direction.clone(),l=a.matrixWorld,e=l.multiplyVector3(q[g.a].position.clone()),h=l.multiplyVector3(q[g.b].position.clone()),j=l.multiplyVector3(q[g.c].position.clone()),l=g instanceof THREE.Face4?l.multiplyVector3(q[g.d].position.clone()):null,m=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),i=k.dot(m),a.doubleSided||(a.flipSided?i>0:i<0))if(m=m.dot((new THREE.Vector3).sub(e,
+n))/i,n=n.addSelf(k.multiplyScalar(m)),g instanceof THREE.Face3)c(n,e,h,j)&&(g={distance:this.origin.distanceTo(n),point:n,face:g,object:a},v.push(g));else if(g instanceof THREE.Face4&&(c(n,e,h,l)||c(n,h,j,l)))g={distance:this.origin.distanceTo(n),point:n,face:g,object:a},v.push(g);return v}else return[]}};
+THREE.Rectangle=function(){function a(){g=d-b;e=f-c}var b,c,d,f,g,e,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return e};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return f};this.set=function(e,g,m,i){h=!1;b=e;c=g;d=m;f=i;a()};this.addPoint=function(e,g){h?(h=!1,b=e,c=g,d=e,f=g):(b=b<e?b:e,c=c<g?c:g,d=d>e?d:e,f=f>g?f:g);a()};this.add3Points=
+function(e,g,m,i,n,k){h?(h=!1,b=e<m?e<n?e:n:m<n?m:n,c=g<i?g<k?g:k:i<k?i:k,d=e>m?e>n?e:n:m>n?m:n,f=g>i?g>k?g:k:i>k?i:k):(b=e<m?e<n?e<b?e:b:n<b?n:b:m<n?m<b?m:b:n<b?n:b,c=g<i?g<k?g<c?g:c:k<c?k:c:i<k?i<c?i:c:k<c?k:c,d=e>m?e>n?e>d?e:d:n>d?n:d:m>n?m>d?m:d:n>d?n:d,f=g>i?g>k?g>f?g:f:k>f?k:f:i>k?i>f?i:f:k>f?k:f);a()};this.addRectangle=function(e){h?(h=!1,b=e.getLeft(),c=e.getTop(),d=e.getRight(),f=e.getBottom()):(b=b<e.getLeft()?b:e.getLeft(),c=c<e.getTop()?c:e.getTop(),d=d>e.getRight()?d:e.getRight(),f=f>
 e.getBottom()?f:e.getBottom());a()};this.inflate=function(e){b-=e;c-=e;d+=e;f+=e;a()};this.minSelf=function(e){b=b>e.getLeft()?b:e.getLeft();c=c>e.getTop()?c:e.getTop();d=d<e.getRight()?d:e.getRight();f=f<e.getBottom()?f:e.getBottom();a()};this.instersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(f,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;f=d=c=b=0;a()};this.isEmpty=function(){return h}};THREE.Matrix3=function(){this.m=[]};
-THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,f,g,e,h,i,l,m,n,j,o,k,q){this.set(a||1,b||0,c||0,d||0,f||0,g||1,e||0,h||0,i||0,l||0,m||1,n||0,j||0,o||0,k||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
-THREE.Matrix4.prototype={set:function(a,b,c,d,f,g,e,h,i,l,m,n,j,o,k,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=f;this.n22=g;this.n23=e;this.n24=h;this.n31=i;this.n32=l;this.n33=m;this.n34=n;this.n41=j;this.n42=o;this.n43=k;this.n44=q;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
-f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());f.cross(g,d).normalize();this.n11=d.x;this.n12=f.x;this.n13=g.x;this.n21=d.y;this.n22=f.y;this.n23=g.y;this.n31=d.z;this.n32=f.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,f=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*f;a.y=(this.n21*b+this.n22*c+this.n23*
-d+this.n24)*f;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,f=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*f;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*f;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*f;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*f;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+c*this.n32+d*this.n33;a.normalize();
-return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,f=a.n13,g=a.n14,e=a.n21,h=a.n22,i=a.n23,l=a.n24,m=a.n31,n=a.n32,j=a.n33,o=a.n34,k=a.n41,q=a.n42,w=a.n43,s=a.n44,J=b.n11,N=b.n12,v=b.n13,B=b.n14,p=b.n21,O=b.n22,
-r=b.n23,u=b.n24,y=b.n31,R=b.n32,aa=b.n33,$=b.n34,C=b.n41,F=b.n42,L=b.n43,D=b.n44;this.n11=c*J+d*p+f*y+g*C;this.n12=c*N+d*O+f*R+g*F;this.n13=c*v+d*r+f*aa+g*L;this.n14=c*B+d*u+f*$+g*D;this.n21=e*J+h*p+i*y+l*C;this.n22=e*N+h*O+i*R+l*F;this.n23=e*v+h*r+i*aa+l*L;this.n24=e*B+h*u+i*$+l*D;this.n31=m*J+n*p+j*y+o*C;this.n32=m*N+n*O+j*R+o*F;this.n33=m*v+n*r+j*aa+o*L;this.n34=m*B+n*u+j*$+o*D;this.n41=k*J+q*p+w*y+s*C;this.n42=k*N+q*O+w*R+s*F;this.n43=k*v+q*r+w*aa+s*L;this.n44=k*B+q*u+w*$+s*D;return this},multiplyToArray:function(a,
-b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
-a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,f=this.n21,g=this.n22,e=this.n23,h=this.n24,i=this.n31,l=this.n32,m=this.n33,n=this.n34,j=this.n41,o=this.n42,k=this.n43,q=this.n44;return d*e*l*j-c*h*l*j-d*g*m*j+b*h*m*j+c*g*n*j-b*e*n*j-d*e*i*o+c*h*i*o+d*f*m*o-a*h*m*o-c*f*n*o+a*e*n*o+d*g*i*k-b*h*i*k-d*f*l*k+a*h*l*k+b*f*n*k-a*g*n*k-c*g*i*q+b*e*i*q+c*f*l*q-a*e*l*q-b*f*m*q+a*g*m*q},transpose:function(){var a;a=this.n21;this.n21=
-this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=
-this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=
-this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,
-b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},setRotationAxis:function(a,
-b){var c=Math.cos(b),d=Math.sin(b),f=1-c,g=a.x,e=a.y,h=a.z,i=f*g,l=f*e;this.set(i*g+c,i*e-d*h,i*h+d*e,0,i*e+d*h,l*e+c,l*h-d*g,0,i*h-d*e,l*h+d*g,f*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);
-return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,f=a.z,g=Math.cos(c),c=Math.sin(c),e=Math.cos(d),d=Math.sin(d),h=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var i=e*h,l=e*f,m=d*h,n=d*f;this.n11=i+n*c;this.n12=
-m*c-l;this.n13=g*d;this.n21=g*f;this.n22=g*h;this.n23=-c;this.n31=l*c-m;this.n32=n+i*c;this.n33=g*e;break;case "ZXY":i=e*h;l=e*f;m=d*h;n=d*f;this.n11=i-n*c;this.n12=-g*f;this.n13=m+l*c;this.n21=l+m*c;this.n22=g*h;this.n23=n-i*c;this.n31=-g*d;this.n32=c;this.n33=g*e;break;case "ZYX":i=g*h;l=g*f;m=c*h;n=c*f;this.n11=e*h;this.n12=m*d-l;this.n13=i*d+n;this.n21=e*f;this.n22=n*d+i;this.n23=l*d-m;this.n31=-d;this.n32=c*e;this.n33=g*e;break;case "YZX":i=g*e;l=g*d;m=c*e;n=c*d;this.n11=e*h;this.n12=n-i*f;this.n13=
-m*f+l;this.n21=f;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=l*f+m;this.n33=i-n*f;break;case "XZY":i=g*e;l=g*d;m=c*e;n=c*d;this.n11=e*h;this.n12=-f;this.n13=d*h;this.n21=i*f+n;this.n22=g*h;this.n23=l*f-m;this.n31=m*f-l;this.n32=c*h;this.n33=n*f+i;break;default:i=g*h,l=g*f,m=c*h,n=c*f,this.n11=e*h,this.n12=-e*f,this.n13=d,this.n21=l+m*d,this.n22=i-n*d,this.n23=-c*e,this.n31=n-i*d,this.n32=m+l*d,this.n33=g*e}return this},setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,f=a.w,g=b+b,
-e=c+c,h=d+d,a=b*g,i=b*e;b*=h;var l=c*e;c*=h;d*=h;g*=f;e*=f;f*=h;this.n11=1-(l+d);this.n12=i-f;this.n13=b+e;this.n21=i+f;this.n22=1-(a+d);this.n23=c-g;this.n31=b-e;this.n32=c+g;this.n33=1-(a+l);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,
-b){var c=1/b.x,d=1/b.y,f=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*f;this.n23=a.n23*f;this.n33=a.n33*f}};
-THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,f=a.n13,g=a.n14,e=a.n21,h=a.n22,i=a.n23,l=a.n24,m=a.n31,n=a.n32,j=a.n33,o=a.n34,k=a.n41,q=a.n42,w=a.n43,s=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=i*o*q-l*j*q+l*n*w-h*o*w-i*n*s+h*j*s;b.n12=g*j*q-f*o*q-g*n*w+d*o*w+f*n*s-d*j*s;b.n13=f*l*q-g*i*q+g*h*w-d*l*w-f*h*s+d*i*s;b.n14=g*i*n-f*l*n-g*h*j+d*l*j+f*h*o-d*i*o;b.n21=l*j*k-i*o*k-l*m*w+e*o*w+i*m*s-e*j*s;b.n22=f*o*k-g*j*k+g*m*w-c*o*w-f*m*s+c*j*s;b.n23=g*i*k-f*l*k-g*e*w+c*l*w+f*e*s-c*i*s;b.n24=
-f*l*m-g*i*m+g*e*j-c*l*j-f*e*o+c*i*o;b.n31=h*o*k-l*n*k+l*m*q-e*o*q-h*m*s+e*n*s;b.n32=g*n*k-d*o*k-g*m*q+c*o*q+d*m*s-c*n*s;b.n33=f*l*k-g*h*k+g*e*q-c*l*q-d*e*s+c*h*s;b.n34=g*h*m-d*l*m-g*e*n+c*l*n+d*e*o-c*h*o;b.n41=i*n*k-h*j*k-i*m*q+e*j*q+h*m*w-e*n*w;b.n42=d*j*k-f*n*k+f*m*q-c*j*q-d*m*w+c*n*w;b.n43=f*h*k-d*i*k-f*e*q+c*i*q+d*e*w-c*h*w;b.n44=d*i*m-f*h*m+f*e*n-c*i*n-d*e*j+c*h*j;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,f=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,e=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,i=-a.n32*a.n11+a.n31*a.n12,l=a.n23*a.n12-a.n22*a.n13,m=-a.n23*a.n11+a.n21*a.n13,n=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*e+a.n31*l;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*f;c[2]=a*g;c[3]=a*e;c[4]=a*h;c[5]=a*i;c[6]=a*l;c[7]=a*m;c[8]=a*n;return b};
+THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,f,g,e,h,j,l,m,i,n,k,p,q){this.set(a||1,b||0,c||0,d||0,f||0,g||1,e||0,h||0,j||0,l||0,m||1,i||0,n||0,k||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
+THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,f,g,e,h,j,l,m,i,n,k,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=f;this.n22=g;this.n23=e;this.n24=h;this.n31=j;this.n32=l;this.n33=m;this.n34=i;this.n41=n;this.n42=k;this.n43=p;this.n44=q;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,
+b,c){var d=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());f.cross(g,d).normalize();this.n11=d.x;this.n12=f.x;this.n13=g.x;this.n21=d.y;this.n22=f.y;this.n23=g.y;this.n31=d.z;this.n32=f.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,f=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*f;
+a.y=(this.n21*b+this.n22*c+this.n23*d+this.n24)*f;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,f=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*f;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*f;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*f;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*f;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+
+c*this.n32+d*this.n33;a.normalize();return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,f=a.n13,g=a.n14,e=a.n21,h=a.n22,j=a.n23,l=a.n24,m=a.n31,i=a.n32,n=a.n33,k=a.n34,p=a.n41,q=a.n42,v=a.n43,s=a.n44,O=b.n11,P=b.n12,
+y=b.n13,B=b.n14,o=b.n21,t=b.n22,r=b.n23,x=b.n24,E=b.n31,Z=b.n32,$=b.n33,I=b.n34,D=b.n41,J=b.n42,M=b.n43,F=b.n44;this.n11=c*O+d*o+f*E+g*D;this.n12=c*P+d*t+f*Z+g*J;this.n13=c*y+d*r+f*$+g*M;this.n14=c*B+d*x+f*I+g*F;this.n21=e*O+h*o+j*E+l*D;this.n22=e*P+h*t+j*Z+l*J;this.n23=e*y+h*r+j*$+l*M;this.n24=e*B+h*x+j*I+l*F;this.n31=m*O+i*o+n*E+k*D;this.n32=m*P+i*t+n*Z+k*J;this.n33=m*y+i*r+n*$+k*M;this.n34=m*B+i*x+n*I+k*F;this.n41=p*O+q*o+v*E+s*D;this.n42=p*P+q*t+v*Z+s*J;this.n43=p*y+q*r+v*$+s*M;this.n44=p*B+q*
+x+v*I+s*F;return this},multiplyToArray:function(a,b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=
+a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,f=this.n21,g=this.n22,e=this.n23,h=this.n24,j=this.n31,l=this.n32,m=this.n33,i=this.n34,n=this.n41,k=this.n42,p=this.n43,q=this.n44;return d*e*l*n-c*h*l*n-d*g*m*n+b*h*m*n+c*g*i*n-b*e*i*n-d*e*j*k+c*h*j*k+d*f*m*k-a*h*m*k-c*f*i*k+a*e*i*k+d*g*j*p-b*h*j*p-d*f*l*p+a*h*l*p+b*f*i*p-a*g*i*p-c*g*j*q+b*e*j*q+c*f*l*q-a*e*l*q-b*f*m*q+a*g*m*q},
+transpose:function(){var a;a=this.n21;this.n21=this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;
+a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;
+a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;
+a[b+15]=this.n44;return a},setTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,
+0,0,1,0,0,0,0,1);return this},setRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),f=1-c,g=a.x,e=a.y,h=a.z,j=f*g,l=f*e;this.set(j*g+c,j*e-d*h,j*h+d*e,0,j*e+d*h,l*e+c,l*h-d*g,0,j*h-d*e,l*h+d*g,f*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=
+new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,f=a.z,g=Math.cos(c),c=Math.sin(c),e=Math.cos(d),d=Math.sin(d),h=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var j=
+e*h,l=e*f,m=d*h,i=d*f;this.n11=j+i*c;this.n12=m*c-l;this.n13=g*d;this.n21=g*f;this.n22=g*h;this.n23=-c;this.n31=l*c-m;this.n32=i+j*c;this.n33=g*e;break;case "ZXY":j=e*h;l=e*f;m=d*h;i=d*f;this.n11=j-i*c;this.n12=-g*f;this.n13=m+l*c;this.n21=l+m*c;this.n22=g*h;this.n23=i-j*c;this.n31=-g*d;this.n32=c;this.n33=g*e;break;case "ZYX":j=g*h;l=g*f;m=c*h;i=c*f;this.n11=e*h;this.n12=m*d-l;this.n13=j*d+i;this.n21=e*f;this.n22=i*d+j;this.n23=l*d-m;this.n31=-d;this.n32=c*e;this.n33=g*e;break;case "YZX":j=g*e;l=
+g*d;m=c*e;i=c*d;this.n11=e*h;this.n12=i-j*f;this.n13=m*f+l;this.n21=f;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=l*f+m;this.n33=j-i*f;break;case "XZY":j=g*e;l=g*d;m=c*e;i=c*d;this.n11=e*h;this.n12=-f;this.n13=d*h;this.n21=j*f+i;this.n22=g*h;this.n23=l*f-m;this.n31=m*f-l;this.n32=c*h;this.n33=i*f+j;break;default:j=g*h,l=g*f,m=c*h,i=c*f,this.n11=e*h,this.n12=-e*f,this.n13=d,this.n21=l+m*d,this.n22=j-i*d,this.n23=-c*e,this.n31=i-j*d,this.n32=m+l*d,this.n33=g*e}return this},setRotationFromQuaternion:function(a){var b=
+a.x,c=a.y,d=a.z,f=a.w,g=b+b,e=c+c,h=d+d,a=b*g,j=b*e;b*=h;var l=c*e;c*=h;d*=h;g*=f;e*=f;f*=h;this.n11=1-(l+d);this.n12=j-f;this.n13=b+e;this.n21=j+f;this.n22=1-(a+d);this.n23=c-g;this.n31=b-e;this.n32=c+g;this.n33=1-(a+l);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},
+extractRotation:function(a,b){var c=1/b.x,d=1/b.y,f=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*f;this.n23=a.n23*f;this.n33=a.n33*f}};
+THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,f=a.n13,g=a.n14,e=a.n21,h=a.n22,j=a.n23,l=a.n24,m=a.n31,i=a.n32,n=a.n33,k=a.n34,p=a.n41,q=a.n42,v=a.n43,s=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=j*k*q-l*n*q+l*i*v-h*k*v-j*i*s+h*n*s;b.n12=g*n*q-f*k*q-g*i*v+d*k*v+f*i*s-d*n*s;b.n13=f*l*q-g*j*q+g*h*v-d*l*v-f*h*s+d*j*s;b.n14=g*j*i-f*l*i-g*h*n+d*l*n+f*h*k-d*j*k;b.n21=l*n*p-j*k*p-l*m*v+e*k*v+j*m*s-e*n*s;b.n22=f*k*p-g*n*p+g*m*v-c*k*v-f*m*s+c*n*s;b.n23=g*j*p-f*l*p-g*e*v+c*l*v+f*e*s-c*j*s;b.n24=
+f*l*m-g*j*m+g*e*n-c*l*n-f*e*k+c*j*k;b.n31=h*k*p-l*i*p+l*m*q-e*k*q-h*m*s+e*i*s;b.n32=g*i*p-d*k*p-g*m*q+c*k*q+d*m*s-c*i*s;b.n33=f*l*p-g*h*p+g*e*q-c*l*q-d*e*s+c*h*s;b.n34=g*h*m-d*l*m-g*e*i+c*l*i+d*e*k-c*h*k;b.n41=j*i*p-h*n*p-j*m*q+e*n*q+h*m*v-e*i*v;b.n42=d*n*p-f*i*p+f*m*q-c*n*q-d*m*v+c*i*v;b.n43=f*h*p-d*j*p-f*e*q+c*j*q+d*e*v-c*h*v;b.n44=d*j*m-f*h*m+f*e*i-c*j*i-d*e*n+c*h*n;b.multiplyScalar(1/a.determinant());return b};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,f=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,e=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,j=-a.n32*a.n11+a.n31*a.n12,l=a.n23*a.n12-a.n22*a.n13,m=-a.n23*a.n11+a.n21*a.n13,i=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*e+a.n31*l;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*f;c[2]=a*g;c[3]=a*e;c[4]=a*h;c[5]=a*j;c[6]=a*l;c[7]=a*m;c[8]=a*i;return b};
 THREE.Matrix4.makeFrustum=function(a,b,c,d,f,g){var e;e=new THREE.Matrix4;e.n11=2*f/(b-a);e.n12=0;e.n13=(b+a)/(b-a);e.n14=0;e.n21=0;e.n22=2*f/(d-c);e.n23=(d+c)/(d-c);e.n24=0;e.n31=0;e.n32=0;e.n33=-(g+f)/(g-f);e.n34=-2*g*f/(g-f);e.n41=0;e.n42=0;e.n43=-1;e.n44=0;return e};THREE.Matrix4.makePerspective=function(a,b,c,d){var f,a=c*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,c,d)};
-THREE.Matrix4.makeOrtho=function(a,b,c,d,f,g){var e,h,i,l;e=new THREE.Matrix4;h=b-a;i=c-d;l=g-f;e.n11=2/h;e.n12=0;e.n13=0;e.n14=-((b+a)/h);e.n21=0;e.n22=2/i;e.n23=0;e.n24=-((c+d)/i);e.n31=0;e.n32=0;e.n33=-2/l;e.n34=-((g+f)/l);e.n41=0;e.n42=0;e.n43=0;e.n44=1;return e};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
+THREE.Matrix4.makeOrtho=function(a,b,c,d,f,g){var e,h,j,l;e=new THREE.Matrix4;h=b-a;j=c-d;l=g-f;e.n11=2/h;e.n12=0;e.n13=0;e.n14=-((b+a)/h);e.n21=0;e.n22=2/j;e.n23=0;e.n24=-((c+d)/j);e.n31=0;e.n32=0;e.n33=-2/l;e.n34=-((g+f)/l);e.n41=0;e.n42=0;e.n43=0;e.n44=1;return e};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
 THREE.Object3D=function(){this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;
-this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
-THREE.Object3D.prototype={translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
+this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this.receiveShadow=this.castShadow=!1;this._vector=new THREE.Vector3;this.name=""};
+THREE.Object3D.prototype={constructor:THREE.Object3D,translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
 -1){a.parent!==void 0&&a.parent.removeChild(a);a.parent=this;this.children.push(a);for(var b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.addChildRecurse(a)}},removeChild:function(a){var b=this.children.indexOf(a);if(b!==-1)a.parent=void 0,this.children.splice(b,1)},getChildByName:function(a,b){var c,d,f;c=0;for(d=this.children.length;c<d;c++){f=this.children[c];if(f.name===a)return f;if(b&&(f=f.getChildByName(a,b),f!==void 0))return f}},updateMatrix:function(){this.matrix.setPosition(this.position);
 this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,this.eulerOrder);if(this.scale.x!==1||this.scale.y!==1||this.scale.z!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,Math.max(this.scale.y,this.scale.z));this.matrixWorldNeedsUpdate=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),
 this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
-THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),g=Math.cos(c),c=Math.sin(c),e=a*b,h=d*f;this.w=e*g-h*c;this.x=e*c+h*g;this.y=d*b*g+a*f*c;this.z=a*f*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);this.x=a.x*d;this.y=a.y*
-d;this.z=a.z*d;this.w=Math.cos(c);return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},
-multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,f=this.w,g=a.x,e=a.y,h=a.z,a=a.w;this.x=b*a+f*g+c*h-d*e;this.y=c*a+f*e+d*g-b*h;this.z=d*a+f*h+b*e-c*g;this.w=f*a-b*g-c*e-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,f=a.z,g=this.x,e=this.y,h=this.z,i=this.w,l=i*c+e*f-h*d,m=
-i*d+h*c-g*f,n=i*f+g*d-e*c,c=-g*c-e*d-h*f;b.x=l*i+c*-g+m*-h-n*-e;b.y=m*i+c*-e+n*-g-l*-h;b.z=n*i+c*-h+l*-e-m*-g;return b}};
+THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),g=Math.cos(c),c=Math.sin(c),e=a*b,h=d*f;this.w=e*g-h*c;this.x=e*c+h*g;this.y=d*b*g+a*f*c;this.z=a*f*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
+this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=
+a,this.w*=a);return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,f=this.w,g=a.x,e=a.y,h=a.z,a=a.w;this.x=b*a+f*g+c*h-d*e;this.y=c*a+f*e+d*g-b*h;this.z=d*a+f*h+b*e-c*g;this.w=f*a-b*g-c*e-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,f=a.z,g=this.x,e=this.y,h=this.z,
+j=this.w,l=j*c+e*f-h*d,m=j*d+h*c-g*f,i=j*f+g*d-e*c,c=-g*c-e*d-h*f;b.x=l*j+c*-g+m*-h-i*-e;b.y=m*j+c*-e+i*-g-l*-h;b.z=i*j+c*-h+l*-e-m*-g;return b}};
 THREE.Quaternion.slerp=function(a,b,c,d){var f=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(f)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(f),e=Math.sqrt(1-f*f);if(Math.abs(e)<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;f=Math.sin((1-d)*g)/e;d=Math.sin(d*g)/e;c.w=a.w*f+b.w*d;c.x=a.x*f+b.x*d;c.y=a.y*f+b.y*d;c.z=a.z*f+b.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
 THREE.Face3=function(a,b,c,d,f,g){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
 THREE.Face4=function(a,b,c,d,f,g,e){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=e instanceof Array?e:[e];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.set(a||0,b||0)};
-THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.colors=[];this.faces=[];this.edges=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
-THREE.Geometry.prototype={computeCentroids:function(){var a,b,c;a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c.centroid.set(0,0,0),c instanceof THREE.Face3?(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),c.centroid.divideScalar(3)):c instanceof THREE.Face4&&(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),
-c.centroid.addSelf(this.vertices[c.d].position),c.centroid.divideScalar(4))},computeFaceNormals:function(a){var b,c,d,f,g,e,h=new THREE.Vector3,i=new THREE.Vector3;d=0;for(f=this.faces.length;d<f;d++){g=this.faces[d];if(a&&g.vertexNormals.length){h.set(0,0,0);b=0;for(c=g.vertexNormals.length;b<c;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else b=this.vertices[g.a],c=this.vertices[g.b],e=this.vertices[g.c],h.sub(e.position,c.position),i.sub(b.position,c.position),h.crossSelf(i);h.isZero()||
+THREE.UV.prototype={constructor:THREE.UV,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.dynamic=this.hasTangents=!1};
+THREE.Geometry.prototype={constructor:THREE.Geometry,computeCentroids:function(){var a,b,c;a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c.centroid.set(0,0,0),c instanceof THREE.Face3?(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),c.centroid.divideScalar(3)):c instanceof THREE.Face4&&(c.centroid.addSelf(this.vertices[c.a].position),c.centroid.addSelf(this.vertices[c.b].position),c.centroid.addSelf(this.vertices[c.c].position),
+c.centroid.addSelf(this.vertices[c.d].position),c.centroid.divideScalar(4))},computeFaceNormals:function(a){var b,c,d,f,g,e,h=new THREE.Vector3,j=new THREE.Vector3;d=0;for(f=this.faces.length;d<f;d++){g=this.faces[d];if(a&&g.vertexNormals.length){h.set(0,0,0);b=0;for(c=g.vertexNormals.length;b<c;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else b=this.vertices[g.a],c=this.vertices[g.b],e=this.vertices[g.c],h.sub(e.position,c.position),j.sub(b.position,c.position),h.crossSelf(j);h.isZero()||
 h.normalize();g.normal.copy(h)}},computeVertexNormals:function(){var a,b,c,d;if(this.__tmpVertices==void 0){d=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)d[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++)if(c=this.faces[a],c instanceof THREE.Face3)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(c instanceof THREE.Face4)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}else{d=
 this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)d[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c instanceof THREE.Face3?(d[c.a].addSelf(c.normal),d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal)):c instanceof THREE.Face4&&(d[c.a].addSelf(c.normal),d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal),d[c.d].addSelf(c.normal));a=0;for(b=this.vertices.length;a<b;a++)d[a].normalize();a=0;for(b=this.faces.length;a<b;a++)c=this.faces[a],c instanceof THREE.Face3?(c.vertexNormals[0].copy(d[c.a]),
-c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c])):c instanceof THREE.Face4&&(c.vertexNormals[0].copy(d[c.a]),c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c]),c.vertexNormals[3].copy(d[c.d]))},computeTangents:function(){function a(a,b,c,d,f,g,r){h=a.vertices[b].position;i=a.vertices[c].position;l=a.vertices[d].position;m=e[f];n=e[g];j=e[r];o=i.x-h.x;k=l.x-h.x;q=i.y-h.y;w=l.y-h.y;s=i.z-h.z;J=l.z-h.z;N=n.u-m.u;v=j.u-m.u;B=n.v-m.v;p=j.v-m.v;O=1/(N*p-v*B);R.set((p*o-B*k)*
-O,(p*q-B*w)*O,(p*s-B*J)*O);aa.set((N*k-v*o)*O,(N*w-v*q)*O,(N*J-v*s)*O);u[b].addSelf(R);u[c].addSelf(R);u[d].addSelf(R);y[b].addSelf(aa);y[c].addSelf(aa);y[d].addSelf(aa)}var b,c,d,f,g,e,h,i,l,m,n,j,o,k,q,w,s,J,N,v,B,p,O,r,u=[],y=[],R=new THREE.Vector3,aa=new THREE.Vector3,$=new THREE.Vector3,C=new THREE.Vector3,F=new THREE.Vector3;b=0;for(c=this.vertices.length;b<c;b++)u[b]=new THREE.Vector3,y[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)g=this.faces[b],e=this.faceVertexUvs[0][b],g instanceof
-THREE.Face3?a(this,g.a,g.b,g.c,0,1,2):g instanceof THREE.Face4&&(a(this,g.a,g.b,g.c,0,1,2),a(this,g.a,g.b,g.d,0,1,3));var L=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++)F.copy(g.vertexNormals[d]),f=g[L[d]],r=u[f],$.copy(r),$.subSelf(F.multiplyScalar(F.dot(r))).normalize(),C.cross(g.vertexNormals[d],r),f=C.dot(y[f]),f=f<0?-1:1,g.vertexTangents[d]=new THREE.Vector4($.x,$.y,$.z,f)}this.hasTangents=!0},computeBoundingBox:function(){var a;
+c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c])):c instanceof THREE.Face4&&(c.vertexNormals[0].copy(d[c.a]),c.vertexNormals[1].copy(d[c.b]),c.vertexNormals[2].copy(d[c.c]),c.vertexNormals[3].copy(d[c.d]))},computeTangents:function(){function a(a,b,c,d,f,g,r){h=a.vertices[b].position;j=a.vertices[c].position;l=a.vertices[d].position;m=e[f];i=e[g];n=e[r];k=j.x-h.x;p=l.x-h.x;q=j.y-h.y;v=l.y-h.y;s=j.z-h.z;O=l.z-h.z;P=i.u-m.u;y=n.u-m.u;B=i.v-m.v;o=n.v-m.v;t=1/(P*o-y*B);Z.set((o*k-B*p)*
+t,(o*q-B*v)*t,(o*s-B*O)*t);$.set((P*p-y*k)*t,(P*v-y*q)*t,(P*O-y*s)*t);x[b].addSelf(Z);x[c].addSelf(Z);x[d].addSelf(Z);E[b].addSelf($);E[c].addSelf($);E[d].addSelf($)}var b,c,d,f,g,e,h,j,l,m,i,n,k,p,q,v,s,O,P,y,B,o,t,r,x=[],E=[],Z=new THREE.Vector3,$=new THREE.Vector3,I=new THREE.Vector3,D=new THREE.Vector3,J=new THREE.Vector3;b=0;for(c=this.vertices.length;b<c;b++)x[b]=new THREE.Vector3,E[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)g=this.faces[b],e=this.faceVertexUvs[0][b],g instanceof
+THREE.Face3?a(this,g.a,g.b,g.c,0,1,2):g instanceof THREE.Face4&&(a(this,g.a,g.b,g.c,0,1,2),a(this,g.a,g.b,g.d,0,1,3));var M=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){g=this.faces[b];for(d=0;d<g.vertexNormals.length;d++)J.copy(g.vertexNormals[d]),f=g[M[d]],r=x[f],I.copy(r),I.subSelf(J.multiplyScalar(J.dot(r))).normalize(),D.cross(g.vertexNormals[d],r),f=D.dot(E[f]),f=f<0?-1:1,g.vertexTangents[d]=new THREE.Vector4(I.x,I.y,I.z,f)}this.hasTangents=!0},computeBoundingBox:function(){var a;
 if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,c=this.vertices.length;b<c;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;
 else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;b<c;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},computeEdgeFaces:function(){function a(a,b){return Math.min(a,b)+"_"+Math.max(a,b)}function b(a,b,c){a[b]===
 void 0?(a[b]={set:{},array:[]},a[b].set[c]=1,a[b].array.push(c)):a[b].set[c]===void 0&&(a[b].set[c]=1,a[b].array.push(c))}var c,d,f,g,e,h={};c=0;for(d=this.faces.length;c<d;c++)e=this.faces[c],e instanceof THREE.Face3?(f=a(e.a,e.b),b(h,f,c),f=a(e.b,e.c),b(h,f,c),f=a(e.a,e.c),b(h,f,c)):e instanceof THREE.Face4&&(f=a(e.b,e.d),b(h,f,c),f=a(e.a,e.b),b(h,f,c),f=a(e.a,e.d),b(h,f,c),f=a(e.b,e.c),b(h,f,c),f=a(e.c,e.d),b(h,f,c));c=0;for(d=this.edges.length;c<d;c++){e=this.edges[c];f=e.vertexIndices[0];g=e.vertexIndices[1];
@@ -75,10 +76,10 @@ THREE.Camera.prototype.update=function(a,b,c){if(this.useTarget)this.matrix.look
 !1,b=!0,THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse);for(a=0;a<this.children.length;a++)this.children[a].update(this.matrixWorld,b,c)};THREE.Light=function(a){THREE.Object3D.call(this);this.color=new THREE.Color(a)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;
 THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b,c,d){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1;this.distance=c||0;this.castShadow=d!==void 0?d:!1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1;this.distance=c||0};
 THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;
-THREE.Material=function(a){this.id=THREE.MaterialCounter.value++;a=a||{};this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:!1;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.depthTest=a.depthTest!==void 0?a.depthTest:!0;this.polygonOffset=a.polygonOffset!==void 0?a.polygonOffset:!1;this.polygonOffsetFactor=a.polygonOffsetFactor!==void 0?a.polygonOffsetFactor:0;this.polygonOffsetUnits=a.polygonOffsetUnits!==void 0?a.polygonOffsetUnits:
-0};THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;THREE.MaterialCounter={value:0};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};
-THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:!1};THREE.LineBasicMaterial.prototype=new THREE.Material;
-THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
+THREE.Material=function(a){this.id=THREE.MaterialCount++;a=a||{};this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:!1;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.depthTest=a.depthTest!==void 0?a.depthTest:!0;this.polygonOffset=a.polygonOffset!==void 0?a.polygonOffset:!1;this.polygonOffsetFactor=a.polygonOffsetFactor!==void 0?a.polygonOffsetFactor:0;this.polygonOffsetUnits=a.polygonOffsetUnits!==void 0?a.polygonOffsetUnits:
+0;this.alphaTest=a.alphaTest!==void 0?a.alphaTest:0};THREE.MaterialCount=0;THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
+THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:!1};
+THREE.LineBasicMaterial.prototype=new THREE.Material;THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
 THREE.MeshBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.shading=a.shading!==
 void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:!1;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:!1;this.skinning=a.skinning!==void 0?a.skinning:!1;this.morphTargets=a.morphTargets!==void 0?a.morphTargets:!1};
 THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
@@ -92,10 +93,10 @@ THREE.MeshDepthMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.sha
 THREE.MeshNormalMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.shading=a.shading?a.shading:THREE.FlatShading;this.wireframe=a.wireframe?a.wireframe:!1;this.wireframeLinewidth=a.wireframeLinewidth?a.wireframeLinewidth:1};THREE.MeshNormalMaterial.prototype=new THREE.Material;THREE.MeshNormalMaterial.prototype.constructor=THREE.MeshNormalMaterial;THREE.MeshFaceMaterial=function(){};
 THREE.ParticleBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.size=a.size!==void 0?a.size:1;this.sizeAttenuation=a.sizeAttenuation!==void 0?a.sizeAttenuation:!0;this.vertexColors=a.vertexColors!==void 0?a.vertexColors:!1};THREE.ParticleBasicMaterial.prototype=new THREE.Material;THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;
 THREE.ParticleCanvasMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.program=a.program!==void 0?a.program:function(){}};THREE.ParticleCanvasMaterial.prototype=new THREE.Material;THREE.ParticleCanvasMaterial.prototype.constructor=THREE.ParticleCanvasMaterial;
-THREE.Texture=function(a,b,c,d,f,g){this.image=a;this.mapping=b!==void 0?b:new THREE.UVMapping;this.wrapS=c!==void 0?c:THREE.ClampToEdgeWrapping;this.wrapT=d!==void 0?d:THREE.ClampToEdgeWrapping;this.magFilter=f!==void 0?f:THREE.LinearFilter;this.minFilter=g!==void 0?g:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.needsUpdate=!1};
-THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter)}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;
-THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;THREE.Particle=function(a){THREE.Object3D.call(this);this.materials=a instanceof Array?a:[a]};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;
-THREE.Line=function(a,b,c){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.type=c!=void 0?c:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
+THREE.Texture=function(a,b,c,d,f,g){this.id=THREE.TextureCount++;this.image=a;this.mapping=b!==void 0?b:new THREE.UVMapping;this.wrapS=c!==void 0?c:THREE.ClampToEdgeWrapping;this.wrapT=d!==void 0?d:THREE.ClampToEdgeWrapping;this.magFilter=f!==void 0?f:THREE.LinearFilter;this.minFilter=g!==void 0?g:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.needsUpdate=!1};
+THREE.Texture.prototype={constructor:THREE.Texture,clone:function(){var a=new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter);a.offset.copy(this.offset);a.repeat.copy(this.repeat);return a}};THREE.TextureCount=0;THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;
+THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;THREE.Particle=function(a){THREE.Object3D.call(this);this.materials=a instanceof Array?a:[a]};THREE.Particle.prototype=new THREE.Object3D;
+THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b,c){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.type=c!=void 0?c:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
 THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b&&b.length?b:[b];this.overdraw=!1;if(this.geometry&&(this.geometry.boundingSphere||this.geometry.computeBoundingSphere(),this.boundRadius=a.boundingSphere.radius,this.geometry.morphTargets.length)){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var c=0;c<this.geometry.morphTargets.length;c++)this.morphTargetInfluences.push(0),this.morphTargetDictionary[this.geometry.morphTargets[c].name]=
 c}};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.Mesh.prototype.supr=THREE.Object3D.prototype;THREE.Mesh.prototype.getMorphTargetIndexByName=function(a){if(this.morphTargetDictionary[a]!==void 0)return this.morphTargetDictionary[a];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+a+" does not exist. Returning 0.");return 0};
 THREE.Bone=function(a){THREE.Object3D.call(this);this.skin=a;this.skinMatrix=new THREE.Matrix4;this.hasNoneBoneChildren=!1};THREE.Bone.prototype=new THREE.Object3D;THREE.Bone.prototype.constructor=THREE.Bone;THREE.Bone.prototype.supr=THREE.Object3D.prototype;
@@ -104,42 +105,44 @@ b,c)};THREE.Bone.prototype.addChild=function(a){if(this.children.indexOf(a)===-1
 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.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.Camera||(b=this.objects.indexOf(a),b!==-1&&(this.objects.splice(b,1),this.__objectsRemoved.push(a)));for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;
 THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
-THREE.Projector=function(){function a(){var a=i[h]=i[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f))),g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,f,g=[],e,h,i=[],l,m,n=[],j,o=[],k,q,w=[],s,J,N=[],v=new THREE.Vector4,B=new THREE.Vector4,
-p=new THREE.Matrix4,O=new THREE.Matrix4,r=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],u=new THREE.Vector4,y=new THREE.Vector4;this.projectVector=function(a,b){p.multiply(b.projectionMatrix,b.matrixWorldInverse);p.multiplyVector3(a);return a};this.unprojectVector=function(a,b){p.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));p.multiplyVector3(a);return a};this.projectObjects=function(a,c,e){var c=[],h,l,k;f=0;l=
-a.objects;a=0;for(h=l.length;a<h;a++){k=l[a];var i;if(!(i=!k.visible))if(i=k instanceof THREE.Mesh){a:{i=void 0;for(var j=k.matrixWorld,m=-k.geometry.boundingSphere.radius*Math.max(k.scale.x,Math.max(k.scale.y,k.scale.z)),n=0;n<6;n++)if(i=r[n].x*j.n14+r[n].y*j.n24+r[n].z*j.n34+r[n].w,i<=m){i=!1;break a}i=!0}i=!i}if(!i)i=g[f]=g[f]||new THREE.RenderableObject,f++,d=i,v.copy(k.position),p.multiplyVector3(v),d.object=k,d.z=v.z,c.push(d)}e&&c.sort(b);return c};this.projectScene=function(d,f,g){var C=[],
-F=f.near,L=f.far,D,G,z,P,x,M,K,v,V,t,H,E,I,S,W,da,X;J=q=j=m=0;f.matrixAutoUpdate&&f.update(void 0,!0);d.update(void 0,!1,f);p.multiply(f.projectionMatrix,f.matrixWorldInverse);r[0].set(p.n41-p.n11,p.n42-p.n12,p.n43-p.n13,p.n44-p.n14);r[1].set(p.n41+p.n11,p.n42+p.n12,p.n43+p.n13,p.n44+p.n14);r[2].set(p.n41+p.n21,p.n42+p.n22,p.n43+p.n23,p.n44+p.n24);r[3].set(p.n41-p.n21,p.n42-p.n22,p.n43-p.n23,p.n44-p.n24);r[4].set(p.n41-p.n31,p.n42-p.n32,p.n43-p.n33,p.n44-p.n34);r[5].set(p.n41+p.n31,p.n42+p.n32,p.n43+
-p.n33,p.n44+p.n34);for(D=0;D<6;D++)V=r[D],V.divideScalar(Math.sqrt(V.x*V.x+V.y*V.y+V.z*V.z));V=this.projectObjects(d,f,!0);d=0;for(D=V.length;d<D;d++)if(t=V[d].object,t.visible)if(H=t.matrixWorld,E=t.matrixRotationWorld,I=t.materials,S=t.overdraw,h=0,t instanceof THREE.Mesh){W=t.geometry;P=W.vertices;da=W.faces;W=W.faceVertexUvs;G=0;for(z=P.length;G<z;G++)e=a(),e.positionWorld.copy(P[G].position),H.multiplyVector3(e.positionWorld),e.positionScreen.copy(e.positionWorld),p.multiplyVector4(e.positionScreen),
-e.positionScreen.x/=e.positionScreen.w,e.positionScreen.y/=e.positionScreen.w,e.visible=e.positionScreen.z>F&&e.positionScreen.z<L;P=0;for(G=da.length;P<G;P++){z=da[P];if(z instanceof THREE.Face3)if(x=i[z.a],M=i[z.b],K=i[z.c],x.visible&&M.visible&&K.visible&&(t.doubleSided||t.flipSided!=(K.positionScreen.x-x.positionScreen.x)*(M.positionScreen.y-x.positionScreen.y)-(K.positionScreen.y-x.positionScreen.y)*(M.positionScreen.x-x.positionScreen.x)<0))v=n[m]=n[m]||new THREE.RenderableFace3,m++,l=v,l.v1.copy(x),
-l.v2.copy(M),l.v3.copy(K);else continue;else if(z instanceof THREE.Face4)if(x=i[z.a],M=i[z.b],K=i[z.c],v=i[z.d],x.visible&&M.visible&&K.visible&&v.visible&&(t.doubleSided||t.flipSided!=((v.positionScreen.x-x.positionScreen.x)*(M.positionScreen.y-x.positionScreen.y)-(v.positionScreen.y-x.positionScreen.y)*(M.positionScreen.x-x.positionScreen.x)<0||(M.positionScreen.x-K.positionScreen.x)*(v.positionScreen.y-K.positionScreen.y)-(M.positionScreen.y-K.positionScreen.y)*(v.positionScreen.x-K.positionScreen.x)<
-0)))X=o[j]=o[j]||new THREE.RenderableFace4,j++,l=X,l.v1.copy(x),l.v2.copy(M),l.v3.copy(K),l.v4.copy(v);else continue;l.normalWorld.copy(z.normal);E.multiplyVector3(l.normalWorld);l.centroidWorld.copy(z.centroid);H.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);p.multiplyVector3(l.centroidScreen);K=z.vertexNormals;x=0;for(M=K.length;x<M;x++)v=l.vertexNormalsWorld[x],v.copy(K[x]),E.multiplyVector3(v);x=0;for(M=W.length;x<M;x++)if(X=W[x][P]){K=0;for(v=X.length;K<v;K++)l.uvs[x][K]=
-X[K]}l.meshMaterials=I;l.faceMaterials=z.materials;l.overdraw=S;l.z=l.centroidScreen.z;C.push(l)}}else if(t instanceof THREE.Line){O.multiply(p,H);P=t.geometry.vertices;x=a();x.positionScreen.copy(P[0].position);O.multiplyVector4(x.positionScreen);G=1;for(z=P.length;G<z;G++)if(x=a(),x.positionScreen.copy(P[G].position),O.multiplyVector4(x.positionScreen),M=i[h-2],u.copy(x.positionScreen),y.copy(M.positionScreen),c(u,y))u.multiplyScalar(1/u.w),y.multiplyScalar(1/y.w),H=w[q]=w[q]||new THREE.RenderableLine,
-q++,k=H,k.v1.positionScreen.copy(u),k.v2.positionScreen.copy(y),k.z=Math.max(u.z,y.z),k.materials=t.materials,C.push(k)}else if(t instanceof THREE.Particle&&(B.set(t.matrixWorld.n14,t.matrixWorld.n24,t.matrixWorld.n34,1),p.multiplyVector4(B),B.z/=B.w,B.z>0&&B.z<1))H=N[J]=N[J]||new THREE.RenderableParticle,J++,s=H,s.x=B.x/B.w,s.y=B.y/B.w,s.z=B.z,s.rotation=t.rotation.z,s.scale.x=t.scale.x*Math.abs(s.x-(B.x+f.projectionMatrix.n11)/(B.w+f.projectionMatrix.n14)),s.scale.y=t.scale.y*Math.abs(s.y-(B.y+
-f.projectionMatrix.n22)/(B.w+f.projectionMatrix.n24)),s.materials=t.materials,C.push(s);g&&C.sort(b);return C}};
-THREE.CanvasRenderer=function(a){function b(a){if(s!=a)k.globalAlpha=s=a}function c(a){if(J!=a){switch(a){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}J=a}}function d(a){if(N!=a.hex)N=a.hex,k.strokeStyle="#"+g(N.toString(16))}function f(a){if(v!=a.hex)v=a.hex,k.fillStyle="#"+g(v.toString(16))}function g(a){for(;a.length<6;)a="0"+a;return a}
-var e=this,h=null,i=new THREE.Projector,a=a||{},l=a.canvas!==void 0?a.canvas:document.createElement("canvas"),m,n,j,o,k=l.getContext("2d"),q=new THREE.Color(0),w=0,s=1,J=0,N=null,v=null,B=null,p=null,O=null,r,u,y,R,aa=new THREE.RenderableVertex,$=new THREE.RenderableVertex,C,F,L,D,G,z,P,x,M,K,oa,V,t=new THREE.Color(0),H=new THREE.Color(0),E=new THREE.Color(0),I=new THREE.Color(0),S=new THREE.Color(0),W,da,X,ba,Ba,Ca,Da,Ea,Fa,Ga,ka=new THREE.Rectangle,Y=new THREE.Rectangle,U=new THREE.Rectangle,ya=
-!1,ca=new THREE.Color,Z=new THREE.Color,sa=new THREE.Color,ta=new THREE.Color,Q=new THREE.Vector3,pa,qa,za,ea,ra,ua,a=16;pa=document.createElement("canvas");pa.width=pa.height=2;qa=pa.getContext("2d");qa.fillStyle="rgba(0,0,0,1)";qa.fillRect(0,0,2,2);za=qa.getImageData(0,0,2,2);ea=za.data;ra=document.createElement("canvas");ra.width=ra.height=a;ua=ra.getContext("2d");ua.translate(-a/2,-a/2);ua.scale(a,a);a--;this.domElement=l;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,
-faces:0};this.setSize=function(a,b){m=a;n=b;j=m/2;o=n/2;l.width=m;l.height=n;ka.set(-j,-o,j,o);Y.set(-j,-o,j,o);s=1;J=0;O=p=B=v=N=null};this.setClearColor=function(a,b){q=a;w=b;Y.set(-j,-o,j,o)};this.setClearColorHex=function(a,b){q.setHex(a);w=b;Y.set(-j,-o,j,o)};this.clear=function(){k.setTransform(1,0,0,-1,j,o);if(!Y.isEmpty())Y.inflate(1),Y.minSelf(ka),w==0?k.clearRect(Y.getX(),Y.getY(),Y.getWidth(),Y.getHeight()):(c(THREE.NormalBlending),b(1),v="rgba("+Math.floor(q.r*255)+","+Math.floor(q.g*
-255)+","+Math.floor(q.b*255)+","+w+")",k.fillStyle=v,k.fillRect(Y.getX(),Y.getY(),Y.getWidth(),Y.getHeight())),Y.empty()};this.render=function(a,g){function l(a){var b,c,d,f=a.lights;Z.setRGB(0,0,0);sa.setRGB(0,0,0);ta.setRGB(0,0,0);a=0;for(b=f.length;a<b;a++)c=f[a],d=c.color,c instanceof THREE.AmbientLight?(Z.r+=d.r,Z.g+=d.g,Z.b+=d.b):c instanceof THREE.DirectionalLight?(sa.r+=d.r,sa.g+=d.g,sa.b+=d.b):c instanceof THREE.PointLight&&(ta.r+=d.r,ta.g+=d.g,ta.b+=d.b)}function m(a,b,c,d){var f,e,g,h,
-l=a.lights,a=0;for(f=l.length;a<f;a++)e=l[a],g=e.color,e instanceof THREE.DirectionalLight?(h=c.dot(e.position),h<=0||(h*=e.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)):e instanceof THREE.PointLight&&(h=c.dot(Q.sub(e.position,b).normalize()),h<=0||(h*=e.distance==0?1:1-Math.min(b.distanceTo(e.position)/e.distance,1),h!=0&&(h*=e.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)))}function n(a,e,g){b(g.opacity);c(g.blending);var h,l,i,m,Aa,p;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)m=g.map.image,
-Aa=m.width>>1,p=m.height>>1,g=e.scale.x*j,i=e.scale.y*o,h=g*Aa,l=i*p,U.set(a.x-h,a.y-l,a.x+h,a.y+l),ka.instersects(U)&&(k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(g,-i),k.translate(-Aa,-p),k.drawImage(m,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=e.scale.x*j,l=e.scale.y*o,U.set(a.x-h,a.y-l,a.x+h,a.y+l),ka.instersects(U)&&(d(g.color),f(g.color),k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(h,l),g.program(k),k.restore()))}function q(a,e,f,g){b(g.opacity);
-c(g.blending);k.beginPath();k.moveTo(a.positionScreen.x,a.positionScreen.y);k.lineTo(e.positionScreen.x,e.positionScreen.y);k.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(B!=a)k.lineWidth=B=a;a=g.linecap;if(p!=a)k.lineCap=p=a;a=g.linejoin;if(O!=a)k.lineJoin=O=a;d(g.color);k.stroke();U.inflate(g.linewidth*2)}}function s(a,d,f,h,l,i,k,j,n){e.data.vertices+=3;e.data.faces++;b(j.opacity);c(j.blending);C=a.positionScreen.x;F=a.positionScreen.y;L=d.positionScreen.x;D=d.positionScreen.y;
-G=f.positionScreen.x;z=f.positionScreen.y;v(C,F,L,D,G,z);if(j instanceof THREE.MeshBasicMaterial)if(j.map)j.map.mapping instanceof THREE.UVMapping&&(ba=k.uvs[0],ga(C,F,L,D,G,z,j.map.image,ba[h].u,ba[h].v,ba[l].u,ba[l].v,ba[i].u,ba[i].v));else if(j.envMap){if(j.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=g.matrixWorldInverse,Q.copy(k.vertexNormalsWorld[0]),Ba=(Q.x*a.n11+Q.y*a.n12+Q.z*a.n13)*0.5+0.5,Ca=-(Q.x*a.n21+Q.y*a.n22+Q.z*a.n23)*0.5+0.5,Q.copy(k.vertexNormalsWorld[1]),Da=(Q.x*
-a.n11+Q.y*a.n12+Q.z*a.n13)*0.5+0.5,Ea=-(Q.x*a.n21+Q.y*a.n22+Q.z*a.n23)*0.5+0.5,Q.copy(k.vertexNormalsWorld[2]),Fa=(Q.x*a.n11+Q.y*a.n12+Q.z*a.n13)*0.5+0.5,Ga=-(Q.x*a.n21+Q.y*a.n22+Q.z*a.n23)*0.5+0.5,ga(C,F,L,D,G,z,j.envMap.image,Ba,Ca,Da,Ea,Fa,Ga)}else j.wireframe?J(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshLambertMaterial)j.map&&!j.wireframe&&(j.map.mapping instanceof THREE.UVMapping&&(ba=k.uvs[0],ga(C,F,L,D,G,z,j.map.image,ba[h].u,
-ba[h].v,ba[l].u,ba[l].v,ba[i].u,ba[i].v)),c(THREE.SubtractiveBlending)),ya?!j.wireframe&&j.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==3?(H.r=E.r=I.r=Z.r,H.g=E.g=I.g=Z.g,H.b=E.b=I.b=Z.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],H),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],E),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],I),S.r=(E.r+I.r)*0.5,S.g=(E.g+I.g)*0.5,S.b=(E.b+I.b)*0.5,X=va(H,E,I,S),ga(C,F,L,D,G,z,X,0,0,1,0,0,1)):(ca.r=Z.r,ca.g=Z.g,ca.b=Z.b,m(n,k.centroidWorld,k.normalWorld,
-ca),t.r=Math.max(0,Math.min(j.color.r*ca.r,1)),t.g=Math.max(0,Math.min(j.color.g*ca.g,1)),t.b=Math.max(0,Math.min(j.color.b*ca.b,1)),t.updateHex(),j.wireframe?J(t,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(t)):j.wireframe?J(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshDepthMaterial)W=g.near,da=g.far,H.r=H.g=H.b=1-la(a.positionScreen.z,W,da),E.r=E.g=E.b=1-la(d.positionScreen.z,W,da),I.r=I.g=I.b=1-la(f.positionScreen.z,
-W,da),S.r=(E.r+I.r)*0.5,S.g=(E.g+I.g)*0.5,S.b=(E.b+I.b)*0.5,X=va(H,E,I,S),ga(C,F,L,D,G,z,X,0,0,1,0,0,1);else if(j instanceof THREE.MeshNormalMaterial)t.r=ma(k.normalWorld.x),t.g=ma(k.normalWorld.y),t.b=ma(k.normalWorld.z),t.updateHex(),j.wireframe?J(t,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(t)}function w(a,d,f,h,j,l,k,i,n){e.data.vertices+=4;e.data.faces++;b(i.opacity);c(i.blending);if(i.map||i.envMap)s(a,d,h,0,1,3,k,i,n),s(j,f,l,1,2,3,k,i,n);else if(C=a.positionScreen.x,F=
-a.positionScreen.y,L=d.positionScreen.x,D=d.positionScreen.y,G=f.positionScreen.x,z=f.positionScreen.y,P=h.positionScreen.x,x=h.positionScreen.y,M=j.positionScreen.x,K=j.positionScreen.y,oa=l.positionScreen.x,V=l.positionScreen.y,i instanceof THREE.MeshBasicMaterial)N(C,F,L,D,G,z,P,x),i.wireframe?J(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color);else if(i instanceof THREE.MeshLambertMaterial)ya?!i.wireframe&&i.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==
-4?(H.r=E.r=I.r=S.r=Z.r,H.g=E.g=I.g=S.g=Z.g,H.b=E.b=I.b=S.b=Z.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],H),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],E),m(n,k.v4.positionWorld,k.vertexNormalsWorld[3],I),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],S),X=va(H,E,I,S),v(C,F,L,D,P,x),ga(C,F,L,D,P,x,X,0,0,1,0,0,1),v(M,K,G,z,oa,V),ga(M,K,G,z,oa,V,X,1,0,1,1,0,1)):(ca.r=Z.r,ca.g=Z.g,ca.b=Z.b,m(n,k.centroidWorld,k.normalWorld,ca),t.r=Math.max(0,Math.min(i.color.r*ca.r,1)),t.g=Math.max(0,Math.min(i.color.g*
-ca.g,1)),t.b=Math.max(0,Math.min(i.color.b*ca.b,1)),t.updateHex(),N(C,F,L,D,G,z,P,x),i.wireframe?J(t,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(t)):(N(C,F,L,D,G,z,P,x),i.wireframe?J(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color));else if(i instanceof THREE.MeshNormalMaterial)t.r=ma(k.normalWorld.x),t.g=ma(k.normalWorld.y),t.b=ma(k.normalWorld.z),t.updateHex(),N(C,F,L,D,G,z,P,x),i.wireframe?J(t,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):
-ha(t);else if(i instanceof THREE.MeshDepthMaterial)W=g.near,da=g.far,H.r=H.g=H.b=1-la(a.positionScreen.z,W,da),E.r=E.g=E.b=1-la(d.positionScreen.z,W,da),I.r=I.g=I.b=1-la(h.positionScreen.z,W,da),S.r=S.g=S.b=1-la(f.positionScreen.z,W,da),X=va(H,E,I,S),v(C,F,L,D,P,x),ga(C,F,L,D,P,x,X,0,0,1,0,0,1),v(M,K,G,z,oa,V),ga(M,K,G,z,oa,V,X,1,0,1,1,0,1)}function v(a,b,c,d,e,f){k.beginPath();k.moveTo(a,b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(a,b);k.closePath()}function N(a,b,c,d,e,f,g,h){k.beginPath();k.moveTo(a,
-b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(g,h);k.lineTo(a,b);k.closePath()}function J(a,b,c,e){if(B!=b)k.lineWidth=B=b;if(p!=c)k.lineCap=p=c;if(O!=e)k.lineJoin=O=e;d(a);k.stroke();U.inflate(b*2)}function ha(a){f(a);k.fill()}function ga(a,b,c,d,e,f,g,h,i,j,l,m,n){var o,p;o=g.width-1;p=g.height-1;h*=o;i*=p;j*=o;l*=p;m*=o;n*=p;c-=a;d-=b;e-=a;f-=b;j-=h;l-=i;m-=h;n-=i;o=j*n-m*l;if(!((o<0?-o:o)<1))p=1/o,o=(n*c-l*e)*p,l=(n*d-l*f)*p,c=(j*e-m*c)*p,d=(j*f-m*d)*p,a=a-o*h-c*i,b=b-l*h-d*i,k.save(),k.transform(o,
-l,c,d,a,b),k.clip(),k.drawImage(g,0,0),k.restore()}function va(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),h=~~(b.g*255),b=~~(b.b*255),i=~~(c.r*255),j=~~(c.g*255),c=~~(c.b*255),k=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);ea[0]=e<0?0:e>255?255:e;ea[1]=f<0?0:f>255?255:f;ea[2]=a<0?0:a>255?255:a;ea[4]=g<0?0:g>255?255:g;ea[5]=h<0?0:h>255?255:h;ea[6]=b<0?0:b>255?255:b;ea[8]=i<0?0:i>255?255:i;ea[9]=j<0?0:j>255?255:j;ea[10]=c<0?0:c>255?255:c;ea[12]=k<0?0:k>255?255:k;ea[13]=l<0?0:l>
-255?255:l;ea[14]=d<0?0:d>255?255:d;qa.putImageData(za,0,0);ua.drawImage(pa,0,0);return ra}function la(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function ma(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function ia(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;e!=0&&(e=1/Math.sqrt(e),c*=e,d*=e,b.x+=c,b.y+=d,a.x-=c,a.y-=d)}var wa,Ha,A,fa,ja,na,xa,T;this.autoClear?this.clear():k.setTransform(1,0,0,-1,j,o);e.data.vertices=0;e.data.faces=0;h=i.projectScene(a,g,this.sortElements);(ya=a.lights.length>0)&&l(a);wa=0;for(Ha=
-h.length;wa<Ha;wa++){A=h[wa];U.empty();if(A instanceof THREE.RenderableParticle){r=A;r.x*=j;r.y*=o;fa=0;for(ja=A.materials.length;fa<ja;)T=A.materials[fa++],T.opacity!=0&&n(r,A,T,a)}else if(A instanceof THREE.RenderableLine){if(r=A.v1,u=A.v2,r.positionScreen.x*=j,r.positionScreen.y*=o,u.positionScreen.x*=j,u.positionScreen.y*=o,U.addPoint(r.positionScreen.x,r.positionScreen.y),U.addPoint(u.positionScreen.x,u.positionScreen.y),ka.instersects(U)){fa=0;for(ja=A.materials.length;fa<ja;)T=A.materials[fa++],
-T.opacity!=0&&q(r,u,A,T,a)}}else if(A instanceof THREE.RenderableFace3){if(r=A.v1,u=A.v2,y=A.v3,r.positionScreen.x*=j,r.positionScreen.y*=o,u.positionScreen.x*=j,u.positionScreen.y*=o,y.positionScreen.x*=j,y.positionScreen.y*=o,A.overdraw&&(ia(r.positionScreen,u.positionScreen),ia(u.positionScreen,y.positionScreen),ia(y.positionScreen,r.positionScreen)),U.add3Points(r.positionScreen.x,r.positionScreen.y,u.positionScreen.x,u.positionScreen.y,y.positionScreen.x,y.positionScreen.y),ka.instersects(U)){fa=
-0;for(ja=A.meshMaterials.length;fa<ja;)if(T=A.meshMaterials[fa++],T instanceof THREE.MeshFaceMaterial){na=0;for(xa=A.faceMaterials.length;na<xa;)(T=A.faceMaterials[na++])&&T.opacity!=0&&s(r,u,y,0,1,2,A,T,a)}else T.opacity!=0&&s(r,u,y,0,1,2,A,T,a)}}else if(A instanceof THREE.RenderableFace4&&(r=A.v1,u=A.v2,y=A.v3,R=A.v4,r.positionScreen.x*=j,r.positionScreen.y*=o,u.positionScreen.x*=j,u.positionScreen.y*=o,y.positionScreen.x*=j,y.positionScreen.y*=o,R.positionScreen.x*=j,R.positionScreen.y*=o,aa.positionScreen.copy(u.positionScreen),
-$.positionScreen.copy(R.positionScreen),A.overdraw&&(ia(r.positionScreen,u.positionScreen),ia(u.positionScreen,R.positionScreen),ia(R.positionScreen,r.positionScreen),ia(y.positionScreen,aa.positionScreen),ia(y.positionScreen,$.positionScreen)),U.addPoint(r.positionScreen.x,r.positionScreen.y),U.addPoint(u.positionScreen.x,u.positionScreen.y),U.addPoint(y.positionScreen.x,y.positionScreen.y),U.addPoint(R.positionScreen.x,R.positionScreen.y),ka.instersects(U))){fa=0;for(ja=A.meshMaterials.length;fa<
-ja;)if(T=A.meshMaterials[fa++],T instanceof THREE.MeshFaceMaterial){na=0;for(xa=A.faceMaterials.length;na<xa;)(T=A.faceMaterials[na++])&&T.opacity!=0&&w(r,u,y,R,aa,$,A,T,a)}else T.opacity!=0&&w(r,u,y,R,aa,$,A,T,a)}Y.addRectangle(U)}k.setTransform(1,0,0,1,0,0)}};THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};
+THREE.Projector=function(){function a(){var a=j[h]=j[h]||new THREE.RenderableVertex;h++;return a}function b(a,b){return b.z-a.z}function c(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f))),g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h))),d<c?!1:(a.lerpSelf(b,c),b.lerpSelf(a,1-d),!0))}var d,f,g=[],e,h,j=[],l,m,i=[],n,k=[],p,q,v=[],s,O,P=[],y=new THREE.Vector4,B=new THREE.Vector4,
+o=new THREE.Matrix4,t=new THREE.Matrix4,r=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],x=new THREE.Vector4,E=new THREE.Vector4;this.projectVector=function(a,b){o.multiply(b.projectionMatrix,b.matrixWorldInverse);o.multiplyVector3(a);return a};this.unprojectVector=function(a,b){o.multiply(b.matrixWorld,THREE.Matrix4.makeInvert(b.projectionMatrix));o.multiplyVector3(a);return a};this.projectObjects=function(a,c,e){var c=[],h,k,l;f=0;k=
+a.objects;a=0;for(h=k.length;a<h;a++){l=k[a];var i;if(!(i=!l.visible))if(i=l instanceof THREE.Mesh){a:{i=void 0;for(var j=l.matrixWorld,n=-l.geometry.boundingSphere.radius*Math.max(l.scale.x,Math.max(l.scale.y,l.scale.z)),m=0;m<6;m++)if(i=r[m].x*j.n14+r[m].y*j.n24+r[m].z*j.n34+r[m].w,i<=n){i=!1;break a}i=!0}i=!i}if(!i)i=g[f]=g[f]||new THREE.RenderableObject,f++,d=i,y.copy(l.position),o.multiplyVector3(y),d.object=l,d.z=y.z,c.push(d)}e&&c.sort(b);return c};this.projectScene=function(d,f,g){var D=[],
+J=f.near,M=f.far,F,K,G,Q,w,N,L,y,C,u,A,H,S,la,V,ca,W;O=q=n=m=0;f.matrixAutoUpdate&&f.update(void 0,!0);d.update(void 0,!1,f);o.multiply(f.projectionMatrix,f.matrixWorldInverse);r[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);r[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);r[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);r[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);r[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);r[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+
+o.n33,o.n44+o.n34);for(F=0;F<6;F++)C=r[F],C.divideScalar(Math.sqrt(C.x*C.x+C.y*C.y+C.z*C.z));C=this.projectObjects(d,f,!0);d=0;for(F=C.length;d<F;d++)if(u=C[d].object,u.visible)if(A=u.matrixWorld,H=u.matrixRotationWorld,S=u.materials,la=u.overdraw,h=0,u instanceof THREE.Mesh){V=u.geometry;Q=V.vertices;ca=V.faces;V=V.faceVertexUvs;K=0;for(G=Q.length;K<G;K++)e=a(),e.positionWorld.copy(Q[K].position),A.multiplyVector3(e.positionWorld),e.positionScreen.copy(e.positionWorld),o.multiplyVector4(e.positionScreen),
+e.positionScreen.x/=e.positionScreen.w,e.positionScreen.y/=e.positionScreen.w,e.visible=e.positionScreen.z>J&&e.positionScreen.z<M;Q=0;for(K=ca.length;Q<K;Q++){G=ca[Q];if(G instanceof THREE.Face3)if(w=j[G.a],N=j[G.b],L=j[G.c],w.visible&&N.visible&&L.visible&&(u.doubleSided||u.flipSided!=(L.positionScreen.x-w.positionScreen.x)*(N.positionScreen.y-w.positionScreen.y)-(L.positionScreen.y-w.positionScreen.y)*(N.positionScreen.x-w.positionScreen.x)<0))y=i[m]=i[m]||new THREE.RenderableFace3,m++,l=y,l.v1.copy(w),
+l.v2.copy(N),l.v3.copy(L);else continue;else if(G instanceof THREE.Face4)if(w=j[G.a],N=j[G.b],L=j[G.c],y=j[G.d],w.visible&&N.visible&&L.visible&&y.visible&&(u.doubleSided||u.flipSided!=((y.positionScreen.x-w.positionScreen.x)*(N.positionScreen.y-w.positionScreen.y)-(y.positionScreen.y-w.positionScreen.y)*(N.positionScreen.x-w.positionScreen.x)<0||(N.positionScreen.x-L.positionScreen.x)*(y.positionScreen.y-L.positionScreen.y)-(N.positionScreen.y-L.positionScreen.y)*(y.positionScreen.x-L.positionScreen.x)<
+0)))W=k[n]=k[n]||new THREE.RenderableFace4,n++,l=W,l.v1.copy(w),l.v2.copy(N),l.v3.copy(L),l.v4.copy(y);else continue;l.normalWorld.copy(G.normal);H.multiplyVector3(l.normalWorld);l.centroidWorld.copy(G.centroid);A.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);o.multiplyVector3(l.centroidScreen);L=G.vertexNormals;w=0;for(N=L.length;w<N;w++)y=l.vertexNormalsWorld[w],y.copy(L[w]),H.multiplyVector3(y);w=0;for(N=V.length;w<N;w++)if(W=V[w][Q]){L=0;for(y=W.length;L<y;L++)l.uvs[w][L]=
+W[L]}l.meshMaterials=S;l.faceMaterials=G.materials;l.overdraw=la;l.z=l.centroidScreen.z;D.push(l)}}else if(u instanceof THREE.Line){t.multiply(o,A);Q=u.geometry.vertices;w=a();w.positionScreen.copy(Q[0].position);t.multiplyVector4(w.positionScreen);K=1;for(G=Q.length;K<G;K++)if(w=a(),w.positionScreen.copy(Q[K].position),t.multiplyVector4(w.positionScreen),N=j[h-2],x.copy(w.positionScreen),E.copy(N.positionScreen),c(x,E))x.multiplyScalar(1/x.w),E.multiplyScalar(1/E.w),A=v[q]=v[q]||new THREE.RenderableLine,
+q++,p=A,p.v1.positionScreen.copy(x),p.v2.positionScreen.copy(E),p.z=Math.max(x.z,E.z),p.materials=u.materials,D.push(p)}else if(u instanceof THREE.Particle&&(B.set(u.matrixWorld.n14,u.matrixWorld.n24,u.matrixWorld.n34,1),o.multiplyVector4(B),B.z/=B.w,B.z>0&&B.z<1))A=P[O]=P[O]||new THREE.RenderableParticle,O++,s=A,s.x=B.x/B.w,s.y=B.y/B.w,s.z=B.z,s.rotation=u.rotation.z,s.scale.x=u.scale.x*Math.abs(s.x-(B.x+f.projectionMatrix.n11)/(B.w+f.projectionMatrix.n14)),s.scale.y=u.scale.y*Math.abs(s.y-(B.y+
+f.projectionMatrix.n22)/(B.w+f.projectionMatrix.n24)),s.materials=u.materials,D.push(s);g&&D.sort(b);return D}};
+THREE.CanvasRenderer=function(a){function b(a){if(v!=a)k.globalAlpha=v=a}function c(a){if(s!=a){switch(a){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}s=a}}function d(a){if(O!=a)k.strokeStyle=O=a}function f(a){if(P!=a)k.fillStyle=P=a}var g=this,e=null,h=new THREE.Projector,a=a||{},j=a.canvas!==void 0?a.canvas:document.createElement("canvas"),
+l,m,i,n,k=j.getContext("2d"),p=new THREE.Color(0),q=0,v=1,s=0,O=null,P=null,y=null,B=null,o=null,t,r,x,E,Z=new THREE.RenderableVertex,$=new THREE.RenderableVertex,I,D,J,M,F,K,G,Q,w,N,L,pa,C=new THREE.Color(0),u=new THREE.Color(0),A=new THREE.Color(0),H=new THREE.Color(0),S=new THREE.Color(0),la=[],V,ca,W,aa,Da,Ea,Fa,Ga,Ha,Ia,ja=new THREE.Rectangle,X=new THREE.Rectangle,U=new THREE.Rectangle,za=!1,ba=new THREE.Color,Y=new THREE.Color,ta=new THREE.Color,ua=new THREE.Color,R=new THREE.Vector3,qa,ra,
+Aa,da,sa,va,a=16;qa=document.createElement("canvas");qa.width=qa.height=2;ra=qa.getContext("2d");ra.fillStyle="rgba(0,0,0,1)";ra.fillRect(0,0,2,2);Aa=ra.getImageData(0,0,2,2);da=Aa.data;sa=document.createElement("canvas");sa.width=sa.height=a;va=sa.getContext("2d");va.translate(-a/2,-a/2);va.scale(a,a);a--;this.domElement=j;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};this.setSize=function(a,b){l=a;m=b;i=Math.floor(l/2);n=Math.floor(m/2);j.width=l;j.height=m;
+ja.set(-i,-n,i,n);X.set(-i,-n,i,n);v=1;s=0;o=B=y=P=O=null};this.setClearColor=function(a,b){p.copy(a);q=b;X.set(-i,-n,i,n)};this.setClearColorHex=function(a,b){p.setHex(a);q=b;X.set(-i,-n,i,n)};this.clear=function(){k.setTransform(1,0,0,-1,i,n);X.isEmpty()||(X.minSelf(ja),X.inflate(2),q<1&&k.clearRect(Math.floor(X.getX()),Math.floor(X.getY()),Math.floor(X.getWidth()),Math.floor(X.getHeight())),q>0&&(c(THREE.NormalBlending),b(1),f("rgba("+Math.floor(p.r*255)+","+Math.floor(p.g*255)+","+Math.floor(p.b*
+255)+","+q+")"),k.fillRect(Math.floor(X.getX()),Math.floor(X.getY()),Math.floor(X.getWidth()),Math.floor(X.getHeight()))),X.empty())};this.render=function(a,l){function j(a){var b,c,d,f=a.lights;Y.setRGB(0,0,0);ta.setRGB(0,0,0);ua.setRGB(0,0,0);a=0;for(b=f.length;a<b;a++)c=f[a],d=c.color,c instanceof THREE.AmbientLight?(Y.r+=d.r,Y.g+=d.g,Y.b+=d.b):c instanceof THREE.DirectionalLight?(ta.r+=d.r,ta.g+=d.g,ta.b+=d.b):c instanceof THREE.PointLight&&(ua.r+=d.r,ua.g+=d.g,ua.b+=d.b)}function m(a,b,c,d){var f,
+e,g,h,l=a.lights,a=0;for(f=l.length;a<f;a++)e=l[a],g=e.color,e instanceof THREE.DirectionalLight?(h=c.dot(e.position),h<=0||(h*=e.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)):e instanceof THREE.PointLight&&(h=c.dot(R.sub(e.position,b).normalize()),h<=0||(h*=e.distance==0?1:1-Math.min(b.distanceTo(e.position)/e.distance,1),h!=0&&(h*=e.intensity,d.r+=g.r*h,d.g+=g.g*h,d.b+=g.b*h)))}function p(a,e,g){b(g.opacity);c(g.blending);var h,l,m,j,Ba,o;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)j=g.map.image,
+Ba=j.width>>1,o=j.height>>1,g=e.scale.x*i,m=e.scale.y*n,h=g*Ba,l=m*o,U.set(a.x-h,a.y-l,a.x+h,a.y+l),ja.instersects(U)&&(k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(g,-m),k.translate(-Ba,-o),k.drawImage(j,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=e.scale.x*i,l=e.scale.y*n,U.set(a.x-h,a.y-l,a.x+h,a.y+l),ja.instersects(U)&&(d(g.color.getContextStyle()),f(g.color.getContextStyle()),k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(h,l),g.program(k),
+k.restore()))}function q(a,e,f,g){b(g.opacity);c(g.blending);k.beginPath();k.moveTo(a.positionScreen.x,a.positionScreen.y);k.lineTo(e.positionScreen.x,e.positionScreen.y);k.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(y!=a)k.lineWidth=y=a;a=g.linecap;if(B!=a)k.lineCap=B=a;a=g.linejoin;if(o!=a)k.lineJoin=o=a;d(g.color.getContextStyle());k.stroke();U.inflate(g.linewidth*2)}}function s(a,d,e,f,h,k,i,j,n){g.data.vertices+=3;g.data.faces++;b(j.opacity);c(j.blending);I=a.positionScreen.x;
+D=a.positionScreen.y;J=d.positionScreen.x;M=d.positionScreen.y;F=e.positionScreen.x;K=e.positionScreen.y;O(I,D,J,M,F,K);if(j instanceof THREE.MeshBasicMaterial)if(j.map)j.map.mapping instanceof THREE.UVMapping&&(aa=i.uvs[0],Ca(I,D,J,M,F,K,aa[f].u,aa[f].v,aa[h].u,aa[h].v,aa[k].u,aa[k].v,j.map));else if(j.envMap){if(j.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=l.matrixWorldInverse,R.copy(i.vertexNormalsWorld[0]),Da=(R.x*a.n11+R.y*a.n12+R.z*a.n13)*0.5+0.5,Ea=-(R.x*a.n21+R.y*a.n22+R.z*
+a.n23)*0.5+0.5,R.copy(i.vertexNormalsWorld[1]),Fa=(R.x*a.n11+R.y*a.n12+R.z*a.n13)*0.5+0.5,Ga=-(R.x*a.n21+R.y*a.n22+R.z*a.n23)*0.5+0.5,R.copy(i.vertexNormalsWorld[2]),Ha=(R.x*a.n11+R.y*a.n12+R.z*a.n13)*0.5+0.5,Ia=-(R.x*a.n21+R.y*a.n22+R.z*a.n23)*0.5+0.5,Ca(I,D,J,M,F,K,Da,Ea,Fa,Ga,Ha,Ia,j.envMap)}else j.wireframe?fa(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ga(j.color);else if(j instanceof THREE.MeshLambertMaterial)j.map&&!j.wireframe&&(j.map.mapping instanceof THREE.UVMapping&&
+(aa=i.uvs[0],Ca(I,D,J,M,F,K,aa[f].u,aa[f].v,aa[h].u,aa[h].v,aa[k].u,aa[k].v,j.map)),c(THREE.SubtractiveBlending)),za?!j.wireframe&&j.shading==THREE.SmoothShading&&i.vertexNormalsWorld.length==3?(u.r=A.r=H.r=Y.r,u.g=A.g=H.g=Y.g,u.b=A.b=H.b=Y.b,m(n,i.v1.positionWorld,i.vertexNormalsWorld[0],u),m(n,i.v2.positionWorld,i.vertexNormalsWorld[1],A),m(n,i.v3.positionWorld,i.vertexNormalsWorld[2],H),S.r=(A.r+H.r)*0.5,S.g=(A.g+H.g)*0.5,S.b=(A.b+H.b)*0.5,W=wa(u,A,H,S),ma(I,D,J,M,F,K,0,0,1,0,0,1,W)):(ba.r=Y.r,
+ba.g=Y.g,ba.b=Y.b,m(n,i.centroidWorld,i.normalWorld,ba),C.r=Math.max(0,Math.min(j.color.r*ba.r,1)),C.g=Math.max(0,Math.min(j.color.g*ba.g,1)),C.b=Math.max(0,Math.min(j.color.b*ba.b,1)),j.wireframe?fa(C,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ga(C)):j.wireframe?fa(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ga(j.color);else if(j instanceof THREE.MeshDepthMaterial)V=l.near,ca=l.far,u.r=u.g=u.b=1-ka(a.positionScreen.z,V,ca),A.r=A.g=A.b=1-ka(d.positionScreen.z,
+V,ca),H.r=H.g=H.b=1-ka(e.positionScreen.z,V,ca),S.r=(A.r+H.r)*0.5,S.g=(A.g+H.g)*0.5,S.b=(A.b+H.b)*0.5,W=wa(u,A,H,S),ma(I,D,J,M,F,K,0,0,1,0,0,1,W);else if(j instanceof THREE.MeshNormalMaterial)C.r=na(i.normalWorld.x),C.g=na(i.normalWorld.y),C.b=na(i.normalWorld.z),j.wireframe?fa(C,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ga(C)}function v(a,d,e,f,h,j,i,k,n){g.data.vertices+=4;g.data.faces++;b(k.opacity);c(k.blending);if(k.map||k.envMap)s(a,d,f,0,1,3,i,k,n),s(h,e,j,1,2,3,i,k,n);else if(I=
+a.positionScreen.x,D=a.positionScreen.y,J=d.positionScreen.x,M=d.positionScreen.y,F=e.positionScreen.x,K=e.positionScreen.y,G=f.positionScreen.x,Q=f.positionScreen.y,w=h.positionScreen.x,N=h.positionScreen.y,L=j.positionScreen.x,pa=j.positionScreen.y,k instanceof THREE.MeshBasicMaterial)P(I,D,J,M,F,K,G,Q),k.wireframe?fa(k.color,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ga(k.color);else if(k instanceof THREE.MeshLambertMaterial)za?!k.wireframe&&k.shading==THREE.SmoothShading&&i.vertexNormalsWorld.length==
+4?(u.r=A.r=H.r=S.r=Y.r,u.g=A.g=H.g=S.g=Y.g,u.b=A.b=H.b=S.b=Y.b,m(n,i.v1.positionWorld,i.vertexNormalsWorld[0],u),m(n,i.v2.positionWorld,i.vertexNormalsWorld[1],A),m(n,i.v4.positionWorld,i.vertexNormalsWorld[3],H),m(n,i.v3.positionWorld,i.vertexNormalsWorld[2],S),W=wa(u,A,H,S),O(I,D,J,M,G,Q),ma(I,D,J,M,G,Q,0,0,1,0,0,1,W),O(w,N,F,K,L,pa),ma(w,N,F,K,L,pa,1,0,1,1,0,1,W)):(ba.r=Y.r,ba.g=Y.g,ba.b=Y.b,m(n,i.centroidWorld,i.normalWorld,ba),C.r=Math.max(0,Math.min(k.color.r*ba.r,1)),C.g=Math.max(0,Math.min(k.color.g*
+ba.g,1)),C.b=Math.max(0,Math.min(k.color.b*ba.b,1)),P(I,D,J,M,F,K,G,Q),k.wireframe?fa(C,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ga(C)):(P(I,D,J,M,F,K,G,Q),k.wireframe?fa(k.color,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ga(k.color));else if(k instanceof THREE.MeshNormalMaterial)C.r=na(i.normalWorld.x),C.g=na(i.normalWorld.y),C.b=na(i.normalWorld.z),P(I,D,J,M,F,K,G,Q),k.wireframe?fa(C,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ga(C);else if(k instanceof
+THREE.MeshDepthMaterial)V=l.near,ca=l.far,u.r=u.g=u.b=1-ka(a.positionScreen.z,V,ca),A.r=A.g=A.b=1-ka(d.positionScreen.z,V,ca),H.r=H.g=H.b=1-ka(f.positionScreen.z,V,ca),S.r=S.g=S.b=1-ka(e.positionScreen.z,V,ca),W=wa(u,A,H,S),O(I,D,J,M,G,Q),ma(I,D,J,M,G,Q,0,0,1,0,0,1,W),O(w,N,F,K,L,pa),ma(w,N,F,K,L,pa,1,0,1,1,0,1,W)}function O(a,b,c,d,e,f){k.beginPath();k.moveTo(a,b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(a,b);k.closePath()}function P(a,b,c,d,e,f,g,h){k.beginPath();k.moveTo(a,b);k.lineTo(c,d);k.lineTo(e,
+f);k.lineTo(g,h);k.lineTo(a,b);k.closePath()}function fa(a,b,c,e){if(y!=b)k.lineWidth=y=b;if(B!=c)k.lineCap=B=c;if(o!=e)k.lineJoin=o=e;d(a.getContextStyle());k.stroke();U.inflate(b*2)}function ga(a){f(a.getContextStyle());k.fill()}function Ca(a,b,c,d,e,g,h,j,i,l,m,n,o){if(o.image.width!=0){if(o.needsUpdate==!0||la[o.id]==void 0){var p=o.wrapS==THREE.RepeatWrapping,q=o.wrapT==THREE.RepeatWrapping;la[o.id]=k.createPattern(o.image,p&&q?"repeat":p&&!q?"repeat-x":!p&&q?"repeat-y":"no-repeat");o.needsUpdate=
+!1}f(la[o.id]);var p=o.offset.x/o.repeat.x,q=o.offset.y/o.repeat.y,r=(o.image.width-1)*o.repeat.x,o=(o.image.height-1)*o.repeat.y,h=(h+p)*r,j=(j+q)*o,i=(i+p)*r,l=(l+q)*o,m=(m+p)*r,n=(n+q)*o;c-=a;d-=b;e-=a;g-=b;i-=h;l-=j;m-=h;n-=j;p=1/(i*n-m*l);o=(n*c-l*e)*p;l=(n*d-l*g)*p;c=(i*e-m*c)*p;d=(i*g-m*d)*p;a=a-o*h-c*j;b=b-l*h-d*j;k.save();k.transform(o,l,c,d,a,b);k.fill();k.restore()}}function ma(a,b,c,d,e,f,g,h,j,i,l,m,n){var o,p;o=n.width-1;p=n.height-1;g*=o;h*=p;j*=o;i*=p;l*=o;m*=p;c-=a;d-=b;e-=a;f-=b;
+j-=g;i-=h;l-=g;m-=h;p=1/(j*m-l*i);o=(m*c-i*e)*p;i=(m*d-i*f)*p;c=(j*e-l*c)*p;d=(j*f-l*d)*p;a=a-o*g-c*h;b=b-i*g-d*h;k.save();k.transform(o,i,c,d,a,b);k.clip();k.drawImage(n,0,0);k.restore()}function wa(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),h=~~(b.g*255),b=~~(b.b*255),i=~~(c.r*255),j=~~(c.g*255),c=~~(c.b*255),k=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);da[0]=e<0?0:e>255?255:e;da[1]=f<0?0:f>255?255:f;da[2]=a<0?0:a>255?255:a;da[4]=g<0?0:g>255?255:g;da[5]=h<0?0:h>255?255:h;
+da[6]=b<0?0:b>255?255:b;da[8]=i<0?0:i>255?255:i;da[9]=j<0?0:j>255?255:j;da[10]=c<0?0:c>255?255:c;da[12]=k<0?0:k>255?255:k;da[13]=l<0?0:l>255?255:l;da[14]=d<0?0:d>255?255:d;ra.putImageData(Aa,0,0);va.drawImage(qa,0,0);return sa}function ka(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function na(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function ha(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;e!=0&&(e=1/Math.sqrt(e),c*=e,d*=e,b.x+=c,b.y+=d,a.x-=c,a.y-=d)}var xa,Ja,z,ea,ia,oa,ya,T;this.autoClear?this.clear():k.setTransform(1,
+0,0,-1,i,n);g.data.vertices=0;g.data.faces=0;e=h.projectScene(a,l,this.sortElements);(za=a.lights.length>0)&&j(a);xa=0;for(Ja=e.length;xa<Ja;xa++){z=e[xa];U.empty();if(z instanceof THREE.RenderableParticle){t=z;t.x*=i;t.y*=n;ea=0;for(ia=z.materials.length;ea<ia;)T=z.materials[ea++],T.opacity!=0&&p(t,z,T,a)}else if(z instanceof THREE.RenderableLine){if(t=z.v1,r=z.v2,t.positionScreen.x*=i,t.positionScreen.y*=n,r.positionScreen.x*=i,r.positionScreen.y*=n,U.addPoint(t.positionScreen.x,t.positionScreen.y),
+U.addPoint(r.positionScreen.x,r.positionScreen.y),ja.instersects(U)){ea=0;for(ia=z.materials.length;ea<ia;)T=z.materials[ea++],T.opacity!=0&&q(t,r,z,T,a)}}else if(z instanceof THREE.RenderableFace3){if(t=z.v1,r=z.v2,x=z.v3,t.positionScreen.x*=i,t.positionScreen.y*=n,r.positionScreen.x*=i,r.positionScreen.y*=n,x.positionScreen.x*=i,x.positionScreen.y*=n,z.overdraw&&(ha(t.positionScreen,r.positionScreen),ha(r.positionScreen,x.positionScreen),ha(x.positionScreen,t.positionScreen)),U.add3Points(t.positionScreen.x,
+t.positionScreen.y,r.positionScreen.x,r.positionScreen.y,x.positionScreen.x,x.positionScreen.y),ja.instersects(U)){ea=0;for(ia=z.meshMaterials.length;ea<ia;)if(T=z.meshMaterials[ea++],T instanceof THREE.MeshFaceMaterial){oa=0;for(ya=z.faceMaterials.length;oa<ya;)(T=z.faceMaterials[oa++])&&T.opacity!=0&&s(t,r,x,0,1,2,z,T,a)}else T.opacity!=0&&s(t,r,x,0,1,2,z,T,a)}}else if(z instanceof THREE.RenderableFace4&&(t=z.v1,r=z.v2,x=z.v3,E=z.v4,t.positionScreen.x*=i,t.positionScreen.y*=n,r.positionScreen.x*=
+i,r.positionScreen.y*=n,x.positionScreen.x*=i,x.positionScreen.y*=n,E.positionScreen.x*=i,E.positionScreen.y*=n,Z.positionScreen.copy(r.positionScreen),$.positionScreen.copy(E.positionScreen),z.overdraw&&(ha(t.positionScreen,r.positionScreen),ha(r.positionScreen,E.positionScreen),ha(E.positionScreen,t.positionScreen),ha(x.positionScreen,Z.positionScreen),ha(x.positionScreen,$.positionScreen)),U.addPoint(t.positionScreen.x,t.positionScreen.y),U.addPoint(r.positionScreen.x,r.positionScreen.y),U.addPoint(x.positionScreen.x,
+x.positionScreen.y),U.addPoint(E.positionScreen.x,E.positionScreen.y),ja.instersects(U))){ea=0;for(ia=z.meshMaterials.length;ea<ia;)if(T=z.meshMaterials[ea++],T instanceof THREE.MeshFaceMaterial){oa=0;for(ya=z.faceMaterials.length;oa<ya;)(T=z.faceMaterials[oa++])&&T.opacity!=0&&v(t,r,x,E,Z,$,z,T,a)}else T.opacity!=0&&v(t,r,x,E,Z,$,z,T,a)}X.addRectangle(U)}k.setTransform(1,0,0,1,0,0)}};
+THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};
 THREE.RenderableFace3=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};
 THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.v4=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};
 THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.materials=null};

+ 43 - 42
build/custom/ThreeDOM.js

@@ -1,62 +1,63 @@
-// ThreeDOM.js r42 - http://github.com/mrdoob/three.js
-var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){this.setHex(a)};
-THREE.Color.prototype={copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;this.hex=a.hex},setHex:function(a){this.hex=~~a&16777215;this.updateRGB()},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;this.updateHex()},setHSV:function(a,b,c){var d,e,g,f,h,j;if(c==0)d=e=g=0;else switch(f=Math.floor(a*6),h=a*6-f,a=c*(1-b),j=c*(1-b*h),b=c*(1-b*(1-h)),f){case 1:d=j;e=c;g=a;break;case 2:d=a;e=c;g=b;break;case 3:d=a;e=j;g=c;break;case 4:d=b;e=a;g=c;break;case 5:d=c;e=a;g=j;break;case 6:case 0:d=c,e=b,g=a}this.setRGB(d,
-e,g)},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGB:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},clone:function(){return new THREE.Color(this.hex)}};THREE.Vector2=function(a,b){this.set(a||0,b||0)};
-THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},divideScalar:function(a){a?
-(this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
+// ThreeDOM.js r43 - http://github.com/mrdoob/three.js
+var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(a){a!==void 0&&this.setHex(a);return this};
+THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;return this},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSV:function(a,b,c){var d,e,g;if(c==0)this.r=this.g=this.b=0;else switch(d=Math.floor(a*6),e=a*6-d,a=c*(1-b),g=c*(1-b*e),b=c*(1-b*(1-e)),d){case 1:this.r=g;this.g=c;this.b=a;break;case 2:this.r=a;this.g=c;this.b=b;break;case 3:this.r=a;this.g=g;this.b=c;break;case 4:this.r=b;this.g=a;this.b=c;break;case 5:this.r=
+c;this.g=a;this.b=g;break;case 6:case 0:this.r=c,this.g=b,this.b=a}return this},setHex:function(a){a=Math.floor(a);this.r=(a>>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},getHex:function(){return~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},getContextStyle:function(){return"rgb("+Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}};
+THREE.Vector2=function(a,b){this.set(a||0,b||0)};
+THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},
+divideScalar:function(a){a?(this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
 unit:function(){return this.normalize()},equals:function(a){return a.x==this.x&&a.y==this.y}};THREE.Vector3=function(a,b,c){this.set(a||0,b||0,c||0)};
-THREE.Vector3.prototype={set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=
-a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){return this.divide(this,a)},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.set(0,0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*
-a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){return this.set(this.y*a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*
-a.y-this.y*a.x)},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,a).lengthSq()},setPositionFromMatrix:function(a){this.x=a.n14;this.y=a.n24;this.z=a.n34},setRotationFromMatrix:function(a){var b=Math.cos(this.y);this.y=Math.asin(a.n13);Math.abs(b)>1.0E-5?(this.x=Math.atan2(-a.n23/b,a.n33/b),this.z=Math.atan2(-a.n12/b,a.n11/b)):(this.x=0,this.z=Math.atan2(a.n21,a.n22))},isZero:function(){return this.lengthSq()<1.0E-4}};
-THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
-THREE.Vector4.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=
-a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
+THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=
+a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){return this.divide(this,a)},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.set(0,0,0);return this},negate:function(){return this.multiplyScalar(-1)},
+dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){return this.set(this.y*
+a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*a.y-this.y*a.x)},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,a).lengthSq()},setPositionFromMatrix:function(a){this.x=a.n14;this.y=a.n24;this.z=a.n34},setRotationFromMatrix:function(a){var b=Math.cos(this.y);this.y=Math.asin(a.n13);Math.abs(b)>1.0E-5?(this.x=Math.atan2(-a.n23/b,a.n33/b),this.z=Math.atan2(-a.n12/b,a.n11/b)):(this.x=0,this.z=Math.atan2(a.n21,a.n22))},isZero:function(){return this.lengthSq()<
+1.0E-4}};THREE.Vector4=function(a,b,c,d){this.set(a||0,b||0,c||0,d||1)};
+THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){return this.set(a.x,a.y,a.z,a.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},
+subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
 setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}};THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),c=c.clone().subSelf(b),
-e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,j,i,k,l,m,n,p=a.geometry,
-q=p.vertices,t=[],d=0;for(e=p.faces.length;d<e;d++)if(g=p.faces[d],m=this.origin.clone(),n=this.direction.clone(),i=a.matrixWorld,f=i.multiplyVector3(q[g.a].position.clone()),h=i.multiplyVector3(q[g.b].position.clone()),j=i.multiplyVector3(q[g.c].position.clone()),i=g instanceof THREE.Face4?i.multiplyVector3(q[g.d].position.clone()):null,k=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),l=n.dot(k),a.doubleSided||(a.flipSided?l>0:l<0))if(k=k.dot((new THREE.Vector3).sub(f,m))/l,m=m.addSelf(n.multiplyScalar(k)),
-g instanceof THREE.Face3)c(m,f,h,j)&&(g={distance:this.origin.distanceTo(m),point:m,face:g,object:a},t.push(g));else if(g instanceof THREE.Face4&&(c(m,f,h,i)||c(m,h,j,i)))g={distance:this.origin.distanceTo(m),point:m,face:g,object:a},t.push(g);return t}else return[]}};
+THREE.Ray.prototype={constructor:THREE.Ray,intersectScene:function(a){return this.intersectObjects(a.objects)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b<c;b++)d=d.concat(this.intersectObject(a[b]));d.sort(function(a,b){return a.distance-b.distance});return d},intersectObject:function(a){function b(a,b,c){var d,c=c.matrixWorld.getPosition();d=c.clone().subSelf(a).dot(b);a=a.clone().addSelf(b.clone().multiplyScalar(d));return c.distanceTo(a)}function c(a,b,c,d){var d=d.clone().subSelf(b),
+c=c.clone().subSelf(b),e=a.clone().subSelf(b),a=d.dot(d),b=d.dot(c),d=d.dot(e),f=c.dot(c),c=c.dot(e),e=1/(a*f-b*b),f=(f*d-b*c)*e,a=(a*c-b*d)*e;return f>0&&a>0&&f+a<1}if(a instanceof THREE.Particle){var d=b(this.origin,this.direction,a);if(!d||d>a.scale.x)return[];return[{distance:d,point:a.position,face:null,object:a}]}else if(a instanceof THREE.Mesh){d=b(this.origin,this.direction,a);if(!d||d>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return[];var e,g,f,h,
+j,i,k,l,m,n,p=a.geometry,q=p.vertices,t=[],d=0;for(e=p.faces.length;d<e;d++)if(g=p.faces[d],m=this.origin.clone(),n=this.direction.clone(),i=a.matrixWorld,f=i.multiplyVector3(q[g.a].position.clone()),h=i.multiplyVector3(q[g.b].position.clone()),j=i.multiplyVector3(q[g.c].position.clone()),i=g instanceof THREE.Face4?i.multiplyVector3(q[g.d].position.clone()):null,k=a.matrixRotationWorld.multiplyVector3(g.normal.clone()),l=n.dot(k),a.doubleSided||(a.flipSided?l>0:l<0))if(k=k.dot((new THREE.Vector3).sub(f,
+m))/l,m=m.addSelf(n.multiplyScalar(k)),g instanceof THREE.Face3)c(m,f,h,j)&&(g={distance:this.origin.distanceTo(m),point:m,face:g,object:a},t.push(g));else if(g instanceof THREE.Face4&&(c(m,f,h,i)||c(m,h,j,i)))g={distance:this.origin.distanceTo(m),point:m,face:g,object:a},t.push(g);return t}else return[]}};
 THREE.Rectangle=function(){function a(){g=d-b;f=e-c}var b,c,d,e,g,f,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return g};this.getHeight=function(){return f};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,k,l){h=!1;b=f;c=g;d=k;e=l;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
 function(f,g,k,l,m,n){h?(h=!1,b=f<k?f<m?f:m:k<m?k:m,c=g<l?g<n?g:n:l<n?l:n,d=f>k?f>m?f:m:k>m?k:m,e=g>l?g>n?g:n:l>n?l:n):(b=f<k?f<m?f<b?f:b:m<b?m:b:k<m?k<b?k:b:m<b?m:b,c=g<l?g<n?g<c?g:c:n<c?n:c:l<n?l<c?l:c:n<c?n:c,d=f>k?f>m?f>d?f:d:m>d?m:d:k>m?k>d?k:d:m>d?m:d,e=g>l?g>n?g>e?g:e:n>e?n:e:l>n?l>e?l:e:n>e?n:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
 f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.instersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};THREE.Matrix3=function(){this.m=[]};
-THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,g,f,h,j,i,k,l,m,n,p,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,j||0,i||0,k||1,l||0,m||0,n||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
-THREE.Matrix4.prototype={set:function(a,b,c,d,e,g,f,h,j,i,k,l,m,n,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=j;this.n32=i;this.n33=k;this.n34=l;this.n41=m;this.n42=n;this.n43=p;this.n44=q;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,c){var d=THREE.Matrix4.__v1,
-e=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());e.cross(g,d).normalize();this.n11=d.x;this.n12=e.x;this.n13=g.x;this.n21=d.y;this.n22=e.y;this.n23=g.y;this.n31=d.z;this.n32=e.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,e=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*e;a.y=(this.n21*b+this.n22*c+this.n23*
-d+this.n24)*e;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*e;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,e=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*e;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*e;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*e;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*e;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+c*this.n32+d*this.n33;a.normalize();
-return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,i=a.n24,k=a.n31,l=a.n32,m=a.n33,n=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44,J=b.n11,M=b.n12,G=b.n13,v=b.n14,o=b.n21,K=b.n22,
-z=b.n23,C=b.n24,D=b.n31,Q=b.n32,R=b.n33,S=b.n34,H=b.n41,T=b.n42,O=b.n43,E=b.n44;this.n11=c*J+d*o+e*D+g*H;this.n12=c*M+d*K+e*Q+g*T;this.n13=c*G+d*z+e*R+g*O;this.n14=c*v+d*C+e*S+g*E;this.n21=f*J+h*o+j*D+i*H;this.n22=f*M+h*K+j*Q+i*T;this.n23=f*G+h*z+j*R+i*O;this.n24=f*v+h*C+j*S+i*E;this.n31=k*J+l*o+m*D+n*H;this.n32=k*M+l*K+m*Q+n*T;this.n33=k*G+l*z+m*R+n*O;this.n34=k*v+l*C+m*S+n*E;this.n41=p*J+q*o+t*D+r*H;this.n42=p*M+q*K+t*Q+r*T;this.n43=p*G+q*z+t*R+r*O;this.n44=p*v+q*C+t*S+r*E;return this},multiplyToArray:function(a,
-b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
-a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,j=this.n31,i=this.n32,k=this.n33,l=this.n34,m=this.n41,n=this.n42,p=this.n43,q=this.n44;return d*f*i*m-c*h*i*m-d*g*k*m+b*h*k*m+c*g*l*m-b*f*l*m-d*f*j*n+c*h*j*n+d*e*k*n-a*h*k*n-c*e*l*n+a*f*l*n+d*g*j*p-b*h*j*p-d*e*i*p+a*h*i*p+b*e*l*p-a*g*l*p-c*g*j*q+b*f*j*q+c*e*i*q-a*f*i*q-b*e*k*q+a*g*k*q},transpose:function(){var a;a=this.n21;this.n21=
-this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=
-this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=
-this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,
-b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},setRotationAxis:function(a,
-b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,j=e*g,i=e*f;this.set(j*g+c,j*f-d*h,j*h+d*f,0,j*f+d*h,i*f+c,i*h-d*g,0,j*h-d*f,i*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);
-return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,e=a.z,g=Math.cos(c),c=Math.sin(c),f=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e);switch(b){case "YXZ":var j=f*h,i=f*e,k=d*h,l=d*e;this.n11=j+l*c;this.n12=
-k*c-i;this.n13=g*d;this.n21=g*e;this.n22=g*h;this.n23=-c;this.n31=i*c-k;this.n32=l+j*c;this.n33=g*f;break;case "ZXY":j=f*h;i=f*e;k=d*h;l=d*e;this.n11=j-l*c;this.n12=-g*e;this.n13=k+i*c;this.n21=i+k*c;this.n22=g*h;this.n23=l-j*c;this.n31=-g*d;this.n32=c;this.n33=g*f;break;case "ZYX":j=g*h;i=g*e;k=c*h;l=c*e;this.n11=f*h;this.n12=k*d-i;this.n13=j*d+l;this.n21=f*e;this.n22=l*d+j;this.n23=i*d-k;this.n31=-d;this.n32=c*f;this.n33=g*f;break;case "YZX":j=g*f;i=g*d;k=c*f;l=c*d;this.n11=f*h;this.n12=l-j*e;this.n13=
-k*e+i;this.n21=e;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=i*e+k;this.n33=j-l*e;break;case "XZY":j=g*f;i=g*d;k=c*f;l=c*d;this.n11=f*h;this.n12=-e;this.n13=d*h;this.n21=j*e+l;this.n22=g*h;this.n23=i*e-k;this.n31=k*e-i;this.n32=c*h;this.n33=l*e+j;break;default:j=g*h,i=g*e,k=c*h,l=c*e,this.n11=f*h,this.n12=-f*e,this.n13=d,this.n21=i+k*d,this.n22=j-l*d,this.n23=-c*f,this.n31=l-j*d,this.n32=k+i*d,this.n33=g*f}return this},setRotationFromQuaternion:function(a){var b=a.x,c=a.y,d=a.z,e=a.w,g=b+b,
-f=c+c,h=d+d,a=b*g,j=b*f;b*=h;var i=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(i+d);this.n12=j-e;this.n13=b+f;this.n21=j+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+i);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},extractRotation:function(a,
-b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
+THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,g,f,h,j,i,k,l,m,n,p,q){this.set(a||1,b||0,c||0,d||0,e||0,g||1,f||0,h||0,j||0,i||0,k||1,l||0,m||0,n||0,p||0,q||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
+THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,g,f,h,j,i,k,l,m,n,p,q){this.n11=a;this.n12=b;this.n13=c;this.n14=d;this.n21=e;this.n22=g;this.n23=f;this.n24=h;this.n31=j;this.n32=i;this.n33=k;this.n34=l;this.n41=m;this.n42=n;this.n43=p;this.n44=q;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,
+b,c){var d=THREE.Matrix4.__v1,e=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;d.cross(c,g).normalize();d.length()===0&&(g.x+=1.0E-4,d.cross(c,g).normalize());e.cross(g,d).normalize();this.n11=d.x;this.n12=e.x;this.n13=g.x;this.n21=d.y;this.n22=e.y;this.n23=g.y;this.n31=d.z;this.n32=e.z;this.n33=g.z;return this},multiplyVector3:function(a){var b=a.x,c=a.y,d=a.z,e=1/(this.n41*b+this.n42*c+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*c+this.n13*d+this.n14)*e;
+a.y=(this.n21*b+this.n22*c+this.n23*d+this.n24)*e;a.z=(this.n31*b+this.n32*c+this.n33*d+this.n34)*e;return a},multiplyVector4:function(a){var b=a.x,c=a.y,d=a.z,e=a.w;a.x=this.n11*b+this.n12*c+this.n13*d+this.n14*e;a.y=this.n21*b+this.n22*c+this.n23*d+this.n24*e;a.z=this.n31*b+this.n32*c+this.n33*d+this.n34*e;a.w=this.n41*b+this.n42*c+this.n43*d+this.n44*e;return a},rotateAxis:function(a){var b=a.x,c=a.y,d=a.z;a.x=b*this.n11+c*this.n12+d*this.n13;a.y=b*this.n21+c*this.n22+d*this.n23;a.z=b*this.n31+
+c*this.n32+d*this.n33;a.normalize();return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,i=a.n24,k=a.n31,l=a.n32,m=a.n33,n=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44,J=b.n11,M=b.n12,
+G=b.n13,v=b.n14,o=b.n21,K=b.n22,z=b.n23,C=b.n24,D=b.n31,Q=b.n32,R=b.n33,S=b.n34,H=b.n41,T=b.n42,O=b.n43,E=b.n44;this.n11=c*J+d*o+e*D+g*H;this.n12=c*M+d*K+e*Q+g*T;this.n13=c*G+d*z+e*R+g*O;this.n14=c*v+d*C+e*S+g*E;this.n21=f*J+h*o+j*D+i*H;this.n22=f*M+h*K+j*Q+i*T;this.n23=f*G+h*z+j*R+i*O;this.n24=f*v+h*C+j*S+i*E;this.n31=k*J+l*o+m*D+n*H;this.n32=k*M+l*K+m*Q+n*T;this.n33=k*G+l*z+m*R+n*O;this.n34=k*v+l*C+m*S+n*E;this.n41=p*J+q*o+t*D+r*H;this.n42=p*M+q*K+t*Q+r*T;this.n43=p*G+q*z+t*R+r*O;this.n44=p*v+q*
+C+t*S+r*E;return this},multiplyToArray:function(a,b,c){this.multiply(a,b);c[0]=this.n11;c[1]=this.n21;c[2]=this.n31;c[3]=this.n41;c[4]=this.n12;c[5]=this.n22;c[6]=this.n32;c[7]=this.n42;c[8]=this.n13;c[9]=this.n23;c[10]=this.n33;c[11]=this.n43;c[12]=this.n14;c[13]=this.n24;c[14]=this.n34;c[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=
+a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,c=this.n13,d=this.n14,e=this.n21,g=this.n22,f=this.n23,h=this.n24,j=this.n31,i=this.n32,k=this.n33,l=this.n34,m=this.n41,n=this.n42,p=this.n43,q=this.n44;return d*f*i*m-c*h*i*m-d*g*k*m+b*h*k*m+c*g*l*m-b*f*l*m-d*f*j*n+c*h*j*n+d*e*k*n-a*h*k*n-c*e*l*n+a*f*l*n+d*g*j*p-b*h*j*p-d*e*i*p+a*h*i*p+b*e*l*p-a*g*l*p-c*g*j*q+b*f*j*q+c*e*i*q-a*f*i*q-b*e*k*q+a*g*k*q},
+transpose:function(){var a;a=this.n21;this.n21=this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;
+a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(a){a[0]=this.n11;
+a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;
+a[b+15]=this.n44;return a},setTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},setScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},setRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,
+0,0,1,0,0,0,0,1);return this},setRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,g=a.x,f=a.y,h=a.z,j=e*g,i=e*f;this.set(j*g+c,j*f-d*h,j*h+d*f,0,j*f+d*h,i*f+c,i*h-d*g,0,j*h-d*f,i*h+d*g,e*h*h+c,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=
+new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(a,b){var c=a.x,d=a.y,e=a.z,g=Math.cos(c),c=Math.sin(c),f=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e);switch(b){case "YXZ":var j=
+f*h,i=f*e,k=d*h,l=d*e;this.n11=j+l*c;this.n12=k*c-i;this.n13=g*d;this.n21=g*e;this.n22=g*h;this.n23=-c;this.n31=i*c-k;this.n32=l+j*c;this.n33=g*f;break;case "ZXY":j=f*h;i=f*e;k=d*h;l=d*e;this.n11=j-l*c;this.n12=-g*e;this.n13=k+i*c;this.n21=i+k*c;this.n22=g*h;this.n23=l-j*c;this.n31=-g*d;this.n32=c;this.n33=g*f;break;case "ZYX":j=g*h;i=g*e;k=c*h;l=c*e;this.n11=f*h;this.n12=k*d-i;this.n13=j*d+l;this.n21=f*e;this.n22=l*d+j;this.n23=i*d-k;this.n31=-d;this.n32=c*f;this.n33=g*f;break;case "YZX":j=g*f;i=
+g*d;k=c*f;l=c*d;this.n11=f*h;this.n12=l-j*e;this.n13=k*e+i;this.n21=e;this.n22=g*h;this.n23=-c*h;this.n31=-d*h;this.n32=i*e+k;this.n33=j-l*e;break;case "XZY":j=g*f;i=g*d;k=c*f;l=c*d;this.n11=f*h;this.n12=-e;this.n13=d*h;this.n21=j*e+l;this.n22=g*h;this.n23=i*e-k;this.n31=k*e-i;this.n32=c*h;this.n33=l*e+j;break;default:j=g*h,i=g*e,k=c*h,l=c*e,this.n11=f*h,this.n12=-f*e,this.n13=d,this.n21=i+k*d,this.n22=j-l*d,this.n23=-c*f,this.n31=l-j*d,this.n32=k+i*d,this.n33=g*f}return this},setRotationFromQuaternion:function(a){var b=
+a.x,c=a.y,d=a.z,e=a.w,g=b+b,f=c+c,h=d+d,a=b*g,j=b*f;b*=h;var i=c*f;c*=h;d*=h;g*=e;f*=e;e*=h;this.n11=1-(i+d);this.n12=j-e;this.n13=b+f;this.n21=j+e;this.n22=1-(a+d);this.n23=c-g;this.n31=b-f;this.n32=c+g;this.n33=1-(a+i);return this},scale:function(a){var b=a.x,c=a.y,a=a.z;this.n11*=b;this.n12*=c;this.n13*=a;this.n21*=b;this.n22*=c;this.n23*=a;this.n31*=b;this.n32*=c;this.n33*=a;this.n41*=b;this.n42*=c;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=a.n34},
+extractRotation:function(a,b){var c=1/b.x,d=1/b.y,e=1/b.z;this.n11=a.n11*c;this.n21=a.n21*c;this.n31=a.n31*c;this.n12=a.n12*d;this.n22=a.n22*d;this.n32=a.n32*d;this.n13=a.n13*e;this.n23=a.n23*e;this.n33=a.n33*e}};
 THREE.Matrix4.makeInvert=function(a,b){var c=a.n11,d=a.n12,e=a.n13,g=a.n14,f=a.n21,h=a.n22,j=a.n23,i=a.n24,k=a.n31,l=a.n32,m=a.n33,n=a.n34,p=a.n41,q=a.n42,t=a.n43,r=a.n44;b===void 0&&(b=new THREE.Matrix4);b.n11=j*n*q-i*m*q+i*l*t-h*n*t-j*l*r+h*m*r;b.n12=g*m*q-e*n*q-g*l*t+d*n*t+e*l*r-d*m*r;b.n13=e*i*q-g*j*q+g*h*t-d*i*t-e*h*r+d*j*r;b.n14=g*j*l-e*i*l-g*h*m+d*i*m+e*h*n-d*j*n;b.n21=i*m*p-j*n*p-i*k*t+f*n*t+j*k*r-f*m*r;b.n22=e*n*p-g*m*p+g*k*t-c*n*t-e*k*r+c*m*r;b.n23=g*j*p-e*i*p-g*f*t+c*i*t+e*f*r-c*j*r;b.n24=
 e*i*k-g*j*k+g*f*m-c*i*m-e*f*n+c*j*n;b.n31=h*n*p-i*l*p+i*k*q-f*n*q-h*k*r+f*l*r;b.n32=g*l*p-d*n*p-g*k*q+c*n*q+d*k*r-c*l*r;b.n33=e*i*p-g*h*p+g*f*q-c*i*q-d*f*r+c*h*r;b.n34=g*h*k-d*i*k-g*f*l+c*i*l+d*f*n-c*h*n;b.n41=j*l*p-h*m*p-j*k*q+f*m*q+h*k*t-f*l*t;b.n42=d*m*p-e*l*p+e*k*q-c*m*q-d*k*t+c*l*t;b.n43=e*h*p-d*j*p-e*f*q+c*j*q+d*f*t-c*h*t;b.n44=d*j*k-e*h*k+e*f*l-c*j*l-d*f*m+c*h*m;b.multiplyScalar(1/a.determinant());return b};
 THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,c=b.m,d=a.n33*a.n22-a.n32*a.n23,e=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,f=-a.n33*a.n12+a.n32*a.n13,h=a.n33*a.n11-a.n31*a.n13,j=-a.n32*a.n11+a.n31*a.n12,i=a.n23*a.n12-a.n22*a.n13,k=-a.n23*a.n11+a.n21*a.n13,l=a.n22*a.n11-a.n21*a.n12,a=a.n11*d+a.n21*f+a.n31*i;a==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");a=1/a;c[0]=a*d;c[1]=a*e;c[2]=a*g;c[3]=a*f;c[4]=a*h;c[5]=a*j;c[6]=a*i;c[7]=a*k;c[8]=a*l;return b};
 THREE.Matrix4.makeFrustum=function(a,b,c,d,e,g){var f;f=new THREE.Matrix4;f.n11=2*e/(b-a);f.n12=0;f.n13=(b+a)/(b-a);f.n14=0;f.n21=0;f.n22=2*e/(d-c);f.n23=(d+c)/(d-c);f.n24=0;f.n31=0;f.n32=0;f.n33=-(g+e)/(g-e);f.n34=-2*g*e/(g-e);f.n41=0;f.n42=0;f.n43=-1;f.n44=0;return f};THREE.Matrix4.makePerspective=function(a,b,c,d){var e,a=c*Math.tan(a*Math.PI/360);e=-a;return THREE.Matrix4.makeFrustum(e*b,a*b,e,a,c,d)};
 THREE.Matrix4.makeOrtho=function(a,b,c,d,e,g){var f,h,j,i;f=new THREE.Matrix4;h=b-a;j=c-d;i=g-e;f.n11=2/h;f.n12=0;f.n13=0;f.n14=-((b+a)/h);f.n21=0;f.n22=2/j;f.n23=0;f.n24=-((c+d)/j);f.n31=0;f.n32=0;f.n33=-2/i;f.n34=-((g+e)/i);f.n41=0;f.n42=0;f.n43=0;f.n44=1;return f};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
 THREE.Object3D=function(){this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;
-this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
-THREE.Object3D.prototype={translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
+this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this.receiveShadow=this.castShadow=!1;this._vector=new THREE.Vector3;this.name=""};
+THREE.Object3D.prototype={constructor:THREE.Object3D,translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===
 -1){a.parent!==void 0&&a.parent.removeChild(a);a.parent=this;this.children.push(a);for(var b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.addChildRecurse(a)}},removeChild:function(a){var b=this.children.indexOf(a);if(b!==-1)a.parent=void 0,this.children.splice(b,1)},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c<d;c++){e=this.children[c];if(e.name===a)return e;if(b&&(e=e.getChildByName(a,b),e!==void 0))return e}},updateMatrix:function(){this.matrix.setPosition(this.position);
 this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,this.eulerOrder);if(this.scale.x!==1||this.scale.y!==1||this.scale.z!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,Math.max(this.scale.y,this.scale.z));this.matrixWorldNeedsUpdate=!0},update:function(a,b,c){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b)a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix),
 this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,b=!0;for(var a=0,d=this.children.length;a<d;a++)this.children[a].update(this.matrixWorld,b,c)}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
-THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),g=Math.cos(c),c=Math.sin(c),f=a*b,h=d*e;this.w=f*g-h*c;this.x=f*c+h*g;this.y=d*b*g+a*e*c;this.z=a*e*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);this.x=a.x*d;this.y=a.y*
-d;this.z=a.z*d;this.w=Math.cos(c);return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},
-multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,j=this.w,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.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),g=Math.cos(c),c=Math.sin(c),f=a*b,h=d*e;this.w=f*g-h*c;this.x=f*c+h*g;this.y=d*b*g+a*e*c;this.z=a*e*g-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
+this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a==0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=
+a,this.w*=a);return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,
+j=this.w,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.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;
+THREE.UV.prototype={constructor:THREE.UV,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;
 THREE.Camera.prototype.supr=THREE.Object3D.prototype;THREE.Camera.prototype.translate=function(a,b){this.matrix.rotateAxis(b);b.multiplyScalar(a);this.position.addSelf(b);this.target.position.addSelf(b)};
 THREE.Camera.prototype.updateProjectionMatrix=function(){if(this.fullWidth){var a=this.fullWidth/this.fullHeight,b=Math.tan(this.fov*Math.PI/360)*this.near,c=-b,d=a*c,a=Math.abs(a*b-d),c=Math.abs(b-c);this.projectionMatrix=THREE.Matrix4.makeFrustum(d+this.x*a/this.fullWidth,d+(this.x+this.width)*a/this.fullWidth,b-(this.y+this.height)*c/this.fullHeight,b-this.y*c/this.fullHeight,this.near,this.far)}else this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};
 THREE.Camera.prototype.setViewOffset=function(a,b,c,d,e,g){this.fullWidth=a;this.fullHeight=b;this.x=c;this.y=d;this.width=e;this.height=g;this.updateProjectionMatrix()};

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


+ 90 - 90
build/custom/ThreeSVG.js

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

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


+ 0 - 1
examples/canvas_geometry_birds.html

@@ -420,7 +420,6 @@
 
 					color = bird.materials[ 0 ].color;
 					color.r = color.g = color.b = ( 500 - bird.position.z ) / 1000;
-					color.updateHex();
 
 					bird.rotation.y = Math.atan2( - boid.velocity.z, boid.velocity.x );
 					bird.rotation.z = Math.asin( boid.velocity.y / boid.velocity.length() );

+ 1 - 0
examples/canvas_geometry_earth.html

@@ -64,6 +64,7 @@
 				scene = new THREE.Scene();
 
 				mesh = new THREE.Mesh( new THREE.PlaneGeometry( 300, 300, 3, 3 ), new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'textures/shadow.png' ) } ) );
+				mesh.overdraw = true;
 				mesh.position.y = - 250;
 				mesh.rotation.x = - 90 * Math.PI / 180;
 				scene.addObject(mesh);

+ 18 - 21
examples/canvas_geometry_text.html

@@ -20,11 +20,11 @@
 
 		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
 		<script type="text/javascript" src="js/Stats.js"></script>
-		      
+
 		<!-- load the font file from canvas-text -->
 
 		<script type="text/javascript" src="fonts/helvetiker_regular.typeface.js"></script>
-        
+
 
 		<script type="text/javascript">
 
@@ -69,47 +69,44 @@
 				// Get text from hash
 
 				var theText = "Hello three.js! :)";
-				
+
 				var hash = document.location.hash.substr( 1 );
-				
+
 				if ( hash.length !== 0 ) {
-                   
+
 					theText = hash;
 
 				}
-                
-		var text3d = new THREE.TextGeometry( theText, {
 
-					size: 80, 
+				var text3d = new THREE.TextGeometry( theText, {
+
+					size: 80,
 					height: 20,
 					curveSegments: 2,
 					font: "helvetiker"
 
 				});
 
-                var textMaterial = new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe:false } );
+				text3d.computeBoundingBox();
+				var centerOffset = -0.5 * ( text3d.boundingBox.x[ 1 ] - text3d.boundingBox.x[ 0 ] );
+
+                var textMaterial = new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: false } );
                 text = new THREE.Mesh( text3d, textMaterial );
 
                 text.doubleSided = false;
 
-                text.position.y = 0;
+                text.position.x = centerOffset;
                 text.position.y = 100;
                 text.position.z = 0;
 
                 text.rotation.x = 0;
-                text.rotation.y = Math.PI*2;
+                text.rotation.y = Math.PI * 2;
 				text.overdraw = true;
 
-                scene.addObject( text );
-
-				// Plane
-
-				plane = new THREE.Mesh( new THREE.PlaneGeometry( 800, 800 ), new THREE.MeshBasicMaterial( { color: 0xe0e0e0, wireframe:true }) );
-				plane.rotation.x = - 90 * ( Math.PI / 180 );
-                plane.position.x = 0;
-				plane.overdraw = true;
+				parent = new THREE.Object3D();
+                parent.addChild( text );
 
-				//scene.addObject( plane );
+				scene.addObject( parent );
 
 				renderer = new THREE.CanvasRenderer();
                 renderer.setSize( window.innerWidth, window.innerHeight );
@@ -205,7 +202,7 @@
 
 			function render() {
 
-				plane.rotation.z = text.rotation.y += ( targetRotation - text.rotation.y ) * 0.05;
+				parent.rotation.y += ( targetRotation - parent.rotation.y ) * 0.05;
 				renderer.render( scene, camera );
 
 			}

+ 1 - 1
examples/canvas_interactive_particles.html

@@ -71,7 +71,7 @@
 
 				for ( var i = 0; i < 100; i ++ ) {
 
-					var particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808008 + 0x808080, program: programStroke } ) );
+					var particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808080 + 0x808080, program: programStroke } ) );
 					particle.position.x = Math.random() * 800 - 400;
 					particle.position.y = Math.random() * 800 - 400;
 					particle.position.z = Math.random() * 800 - 400;

+ 4 - 1
examples/canvas_materials_depth.html

@@ -73,9 +73,12 @@
 				var material = new THREE.MeshDepthMaterial();
 
 				plane = new THREE.Mesh( new THREE.PlaneGeometry( 1000, 1000, 10, 10 ), material );
+				plane.overdraw = true;
+				plane.doubleSided = true;
+				
 				plane.rotation.x = - 90 * ( Math.PI / 180 );
 				plane.position.y = - 100;
-				plane.doubleSided = true;
+
 				scene.addObject( plane );
 
 				// Spheres

+ 1 - 0
examples/canvas_particles_sprites.html

@@ -60,6 +60,7 @@
 				renderer = new THREE.CanvasRenderer();
 				renderer.setSize( window.innerWidth, window.innerHeight );
 				renderer.sortElements = false;
+				renderer.setClearColorHex( 0x0000ff, 0.25 );
 				container.appendChild( renderer.domElement );
 
 				stats = new Stats();

+ 5 - 1
examples/canvas_sandbox.html

@@ -93,8 +93,12 @@
 		<script type="text/javascript" src="../src/extras/cameras/FlyCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/RollCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/TrackballCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/cameras/QuakeCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/Path.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/Shape.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/CubeGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/CylinderGeometry.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/ExtrudeGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/IcosahedronGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/LatheGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/PlaneGeometry.js"></script>
@@ -190,7 +194,7 @@
 				for ( var i = 0; i < 10; i ++ ) {
 
 					sphere = new THREE.Mesh( geometry, material );
-					// sphere.overdraw = true;
+					sphere.overdraw = true;
 
 					sphere.position.x = Math.random() * 1000 - 500;
 					sphere.position.y = Math.random() * 1000 - 500;

+ 8 - 5
examples/misc_ubiquity_test.html

@@ -13,7 +13,7 @@
 	</head>
 	<body>
 
-		<!-- 
+		<!--
 		<script type="text/javascript" src="../build/Three.js"></script>
 		-->
 
@@ -40,6 +40,7 @@
 		<script type="text/javascript" src="../src/lights/AmbientLight.js"></script>
 		<script type="text/javascript" src="../src/lights/DirectionalLight.js"></script>
 		<script type="text/javascript" src="../src/lights/PointLight.js"></script>
+		<script type="text/javascript" src="../src/lights/SpotLight.js"></script>
 		<script type="text/javascript" src="../src/lights/LensFlare.js"></script>
 		<script type="text/javascript" src="../src/materials/Material.js"></script>
 		<script type="text/javascript" src="../src/materials/Mappings.js"></script>
@@ -63,7 +64,6 @@
 		<script type="text/javascript" src="../src/objects/Bone.js"></script>
 		<script type="text/javascript" src="../src/objects/SkinnedMesh.js"></script>
 		<script type="text/javascript" src="../src/objects/Ribbon.js"></script>
-		<script type="text/javascript" src="../src/objects/Sound.js"></script>
 		<script type="text/javascript" src="../src/objects/LOD.js"></script>
 		<script type="text/javascript" src="../src/objects/ShadowVolume.js"></script>
 		<script type="text/javascript" src="../src/objects/Sprite.js"></script>
@@ -77,7 +77,6 @@
 		<script type="text/javascript" src="../src/renderers/WebGLShaders.js"></script>
 		<script type="text/javascript" src="../src/renderers/WebGLRenderer.js"></script>
 		<script type="text/javascript" src="../src/renderers/WebGLRenderTarget.js"></script>
-		<script type="text/javascript" src="../src/renderers/SoundRenderer.js"></script>
 		<script type="text/javascript" src="../src/renderers/renderables/RenderableVertex.js"></script>
 		<script type="text/javascript" src="../src/renderers/renderables/RenderableFace3.js"></script>
 		<script type="text/javascript" src="../src/renderers/renderables/RenderableFace4.js"></script>
@@ -96,8 +95,12 @@
 		<script type="text/javascript" src="../src/extras/cameras/FlyCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/RollCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/TrackballCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/cameras/QuakeCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/Path.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/Shape.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/CubeGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/CylinderGeometry.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/ExtrudeGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/IcosahedronGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/LatheGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/PlaneGeometry.js"></script>
@@ -115,7 +118,7 @@
 		<script type="text/javascript" src="../src/extras/physics/CollisionUtils.js"></script>
 		<script type="text/javascript" src="../src/extras/renderers/AnaglyphWebGLRenderer.js"></script>
 		<script type="text/javascript" src="../src/extras/renderers/CrosseyedWebGLRenderer.js"></script>
-		
+
 		<script type="text/javascript" src="obj/Qrcode.js"></script>
 
 		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
@@ -218,7 +221,7 @@
 				geometry.computeFaceNormals();
 				geometry.computeCentroids();
 
-				mesh = new THREE.Mesh( geometry, [ new THREE.MeshFaceMaterial(), new THREE.MeshBasicMaterial( { color: 0xff0000, opacity: 0.5, wireframe: true, wireframeLinewidth: 10 } ) ] );
+				mesh = new THREE.Mesh( geometry, [ new THREE.MeshFaceMaterial(), new THREE.MeshBasicMaterial( { color: 0xff0000, opacity: 0.5, transparent: true, wireframe: true, wireframeLinewidth: 10 } ) ] );
 				mesh.doubleSided = true;
 				mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
 				scene.addObject( mesh );

+ 0 - 1
examples/textures/metal.txt

@@ -1 +0,0 @@
-http://www.scene.org/file.php?file=/parties/2003/stream03/demo/kwl_itch.zip

BIN
examples/textures/sprites/disc.png


BIN
examples/textures/sprites/spark1.png


BIN
examples/utf8/ben.utf8


BIN
examples/utf8/hand.utf8


+ 5 - 2
examples/webgl_custom_attributes.html

@@ -31,6 +31,7 @@
 		<div id="container"></div>
 
 		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
+		<script type="text/javascript" src="js/Detector.js"></script>
 		<script type="text/javascript" src="js/Stats.js"></script>
 
 		<script src="../build/Three.js"></script>
@@ -84,6 +85,8 @@
 
 		<script type="text/javascript">
 
+		if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
 		var renderer, scene, camera, stats;
 
 		var sphere, uniforms, attributes;
@@ -131,9 +134,9 @@
 
 			var radius = 50, segments = 128, rings = 64;
 			var geometry = new THREE.SphereGeometry( radius, segments, rings );
+			geometry.dynamic = true;
 
 			sphere = new THREE.Mesh( geometry, shaderMaterial );
-			sphere.dynamic = true;
 
 			var vertices = sphere.geometry.vertices;
 			var values = attributes.displacement.value;
@@ -207,4 +210,4 @@
 
 </body>
 
-</html>
+</html>

+ 224 - 0
examples/webgl_custom_attributes_particles.html

@@ -0,0 +1,224 @@
+<!doctype html>
+<html>
+	<head>
+		<meta charset="utf-8" />
+		<title>three.js webgl - custom attributes [particles]</title>
+		<style>
+			body {
+				color: #ffffff;
+				font-family:Monospace;
+				font-size:13px;
+				text-align:center;
+				font-weight: bold;
+
+				background-color: #000000;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				color: #fff;
+				background-color: rgba( 0, 0, 0, 0.75 );
+				position: relative;
+				top: 0px; width: 100%;
+				padding: 5px;
+				z-index:100;
+				width:33em;
+				margin:0 auto -2em;
+			}
+			a { color: #ff0000 }
+		</style>
+	</head>
+
+	<body>
+		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - custom attributes example - particles</div>
+		<div id="container"></div>
+
+		<script src="../build/Three.js"></script>
+
+		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
+		<script type="text/javascript" src="js/Detector.js"></script>
+		<script type="text/javascript" src="js/Stats.js"></script>
+
+		<script type="x-shader/x-vertex" id="vertexshader">
+
+			uniform float amplitude;
+			attribute float size;
+			attribute vec3 customColor;
+
+			varying vec3 vColor;
+
+			void main() {
+
+				vColor = customColor;
+
+				vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
+
+				//gl_PointSize = size;
+				gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
+
+				gl_Position = projectionMatrix * mvPosition;
+
+			}
+
+		</script>
+
+		<script type="x-shader/x-fragment" id="fragmentshader">
+
+			uniform vec3 color;
+			uniform sampler2D texture;
+
+			varying vec3 vColor;
+
+			void main() {
+
+				gl_FragColor = vec4( color * vColor, 1.0 );
+				gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
+
+			}
+
+		</script>
+
+
+		<script type="text/javascript">
+
+		if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
+		var renderer, scene, camera, stats;
+
+		var sphere, uniforms, attributes;
+
+		var noise = [];
+
+		var WIDTH = window.innerWidth,
+			HEIGHT = window.innerHeight;
+
+		init();
+		animate();
+
+		function init() {
+
+			camera = new THREE.Camera( 40, WIDTH / HEIGHT, 1, 10000 );
+			camera.position.z = 300;
+
+			scene = new THREE.Scene();
+
+			attributes = {
+
+				size: {	type: 'f', value: [] },
+				customColor: { type: 'c', value: [] }
+
+			};
+
+			uniforms = {
+
+				amplitude: { type: "f", value: 1.0 },
+				color:     { type: "c", value: new THREE.Color( 0xffffff ) },
+				texture:   { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "textures/sprites/spark1.png" ) },
+
+			};
+
+			var shaderMaterial = new THREE.MeshShaderMaterial( {
+
+				uniforms: 		uniforms,
+				attributes:     attributes,
+				vertexShader:   document.getElementById( 'vertexshader' ).textContent,
+				fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
+
+				blending: 		THREE.AdditiveBlending,
+				depthTest: 		false,
+				transparent:	true
+
+			});
+
+
+			var radius = 200;
+			var geometry = new THREE.Geometry();
+
+			for ( var i = 0; i < 100000; i++ ) {
+
+				vector = new THREE.Vector3( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
+				vector.multiplyScalar( radius );
+
+				geometry.vertices.push( new THREE.Vertex( vector ) );
+
+			}
+
+			sphere = new THREE.ParticleSystem( geometry, shaderMaterial );
+
+			sphere.dynamic = true;
+			//sphere.sortParticles = true;
+
+			var vertices = sphere.geometry.vertices;
+			var values_size = attributes.size.value;
+			var values_color = attributes.customColor.value;
+
+
+			for( var v = 0; v < vertices.length; v++ ) {
+
+				values_size[ v ] = 10;
+				values_color[ v ] = new THREE.Color( 0xffaa00 );
+
+				if ( vertices[ v ].position.x < 0 )
+					values_color[ v ].setHSV( 0.5 + 0.1 * ( v / vertices.length ), 0.7, 0.9 );
+				else
+					values_color[ v ].setHSV( 0.0 + 0.1 * ( v / vertices.length ), 0.9, 0.9 );
+
+			}
+
+			scene.addChild( sphere );
+
+			renderer = new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1 } );
+			renderer.setSize( WIDTH, HEIGHT );
+
+			var container = document.getElementById( 'container' );
+			container.appendChild( renderer.domElement );
+
+			stats = new Stats();
+			stats.domElement.style.position = 'absolute';
+			stats.domElement.style.top = '0px';
+			container.appendChild( stats.domElement );
+
+		}
+
+		function cap( x, a, b ) {
+
+			return ( x < a ) ? a : ( ( x > b ) ? b : x );
+
+		}
+
+		var i, value;
+
+		function animate() {
+
+			requestAnimationFrame( animate );
+
+			render();
+			stats.update();
+
+		}
+
+		function render() {
+
+			var time = new Date().getTime() * 0.005;
+
+			sphere.rotation.z = 0.01 * time;
+
+			for( i = 0; i < attributes.size.value.length; i++ ) {
+
+				attributes.size.value[ i ] = 14 + 13 * Math.sin( 0.1 * i + time );
+
+
+			}
+
+			attributes.size.needsUpdate = true;
+
+			renderer.render( scene, camera );
+
+		}
+
+
+	</script>
+
+</body>
+
+</html>

+ 223 - 0
examples/webgl_custom_attributes_particles2.html

@@ -0,0 +1,223 @@
+<!doctype html>
+<html>
+	<head>
+		<meta charset="utf-8" />
+		<title>three.js webgl - custom attributes [particles][billboards]</title>
+		<style>
+			body {
+				color: #ffffff;
+				font-family:Monospace;
+				font-size:13px;
+				text-align:center;
+				font-weight: bold;
+
+				background-color: #000000;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				color: #fff;
+				position: absolute;
+				top: 0px; width: 100%;
+				padding: 5px;
+				z-index:100;
+			}
+
+		</style>
+	</head>
+
+	<body>
+		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - custom attributes example - particles - billboards</div>
+		<div id="container"></div>
+
+		<script src="../build/Three.js"></script>
+
+		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
+		<script type="text/javascript" src="js/Detector.js"></script>
+		<script type="text/javascript" src="js/Stats.js"></script>
+
+		<script type="x-shader/x-vertex" id="vertexshader">
+
+			attribute float size;
+			attribute vec3 ca;
+
+			varying vec3 vColor;
+
+			void main() {
+
+				vColor = ca;
+
+				vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
+
+				//gl_PointSize = size;
+				gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) );
+
+				gl_Position = projectionMatrix * mvPosition;
+
+			}
+
+		</script>
+
+		<script type="x-shader/x-fragment" id="fragmentshader">
+
+			uniform vec3 color;
+			uniform sampler2D texture;
+
+			varying vec3 vColor;
+
+			void main() {
+
+				gl_FragColor = vec4( color * vColor, 1.0 );
+				gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
+
+			}
+
+		</script>
+
+
+		<script type="text/javascript">
+
+		if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
+		var renderer, scene, camera, stats;
+
+		var sphere, uniforms, attributes;
+
+		var vc1;
+
+		var WIDTH = window.innerWidth,
+			HEIGHT = window.innerHeight;
+
+		init();
+		animate();
+
+		function init() {
+
+			camera = new THREE.Camera( 45, WIDTH / HEIGHT, 1, 10000 );
+			camera.position.z = 300;
+
+			scene = new THREE.Scene();
+
+			attributes = {
+
+				size: {	type: 'f', value: [] },
+				ca:   {	type: 'c', value: [] }
+
+			};
+
+			uniforms = {
+
+				amplitude: { type: "f", value: 1.0 },
+				color:     { type: "c", value: new THREE.Color( 0xffffff ) },
+				texture:   { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "textures/sprites/disc.png" ) },
+
+			};
+
+			uniforms.texture.texture.wrapS = uniforms.texture.texture.wrapT = THREE.RepeatWrapping;
+
+			var shaderMaterial = new THREE.MeshShaderMaterial( {
+
+				uniforms: 		uniforms,
+				attributes:     attributes,
+				vertexShader:   document.getElementById( 'vertexshader' ).textContent,
+				fragmentShader: document.getElementById( 'fragmentshader' ).textContent
+
+			});
+
+
+			var radius = 100, segments = 68, rings = 38;
+			var geometry = new THREE.SphereGeometry( radius, segments, rings );
+
+			vc1 = geometry.vertices.length;
+
+			var geometry2 = new THREE.CubeGeometry( 0.8 * radius, 0.8 * radius, 0.8 * radius, 10, 10, 10 );
+
+			THREE.GeometryUtils.merge( geometry, geometry2 );
+
+			sphere = new THREE.ParticleSystem( geometry, shaderMaterial );
+
+			sphere.dynamic = true;
+			sphere.sortParticles = true;
+
+			var vertices = sphere.geometry.vertices;
+			var values_size = attributes.size.value;
+			var values_color = attributes.ca.value;
+
+
+			for( var v = 0; v < vertices.length; v++ ) {
+
+				values_size[ v ] = 10;
+				values_color[ v ] = new THREE.Color( 0xffffff );
+
+				if ( v < vc1 ) {
+
+					values_color[ v ].setHSV( 0.01 + 0.1 * ( v / vc1 ), 0.99, ( vertices[ v ].position.y + radius ) / ( 2 *radius ) );
+
+				} else {
+
+					values_size[ v ] = 40;
+					values_color[ v ].setHSV( 0.6, 0.75, 0.5 + vertices[ v ].position.y / ( 0.8 * radius ) );
+
+				}
+
+			}
+
+			scene.addChild( sphere );
+
+			renderer = new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1 } );
+			renderer.setSize( WIDTH, HEIGHT );
+
+			var container = document.getElementById( 'container' );
+			container.appendChild( renderer.domElement );
+
+			stats = new Stats();
+			stats.domElement.style.position = 'absolute';
+			stats.domElement.style.top = '0px';
+			container.appendChild( stats.domElement );
+
+		}
+
+		function cap( x, a, b ) {
+
+			return ( x < a ) ? a : ( ( x > b ) ? b : x );
+
+		}
+
+		var i, value;
+
+		function animate() {
+
+			requestAnimationFrame( animate );
+
+			render();
+			stats.update();
+
+		}
+
+		function render() {
+
+			var time = new Date().getTime() * 0.005;
+
+			sphere.rotation.y = 0.02 * time;
+			sphere.rotation.z = 0.02 * time;
+
+			for( i = 0; i < attributes.size.value.length; i++ ) {
+
+				if ( i < vc1 )
+					attributes.size.value[ i ] = 16 + 12 * Math.sin( 0.1 * i + time );
+
+
+			}
+
+			attributes.size.needsUpdate = true;
+
+			renderer.render( scene, camera );
+
+		}
+
+
+	</script>
+
+</body>
+
+</html>

+ 282 - 0
examples/webgl_custom_attributes_particles3.html

@@ -0,0 +1,282 @@
+<!doctype html>
+<html>
+	<head>
+		<meta charset="utf-8" />
+		<title>three.js webgl - custom attributes [particles][billboards][alphatest]</title>
+		<style>
+			body {
+				color: #ffffff;
+				font-family:Monospace;
+				font-size:13px;
+				text-align:center;
+				font-weight: bold;
+
+				background-color: #000000;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				color: #fff;
+				position: absolute;
+				top: 0px; width: 100%;
+				padding: 5px;
+				z-index:100;
+			}
+
+		</style>
+	</head>
+
+	<body>
+		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - custom attributes example - particles - billboards - alphatest</div>
+		<div id="container"></div>
+
+		<script src="../build/Three.js"></script>
+
+		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
+		<script type="text/javascript" src="js/Detector.js"></script>
+		<script type="text/javascript" src="js/Stats.js"></script>
+
+		<script type="x-shader/x-vertex" id="vertexshader">
+
+			attribute float size;
+			attribute vec4 ca;
+
+			varying vec4 vColor;
+
+			void main() {
+
+				vColor = ca;
+
+				vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
+
+				gl_PointSize = size * ( 150.0 / length( mvPosition.xyz ) );
+
+				gl_Position = projectionMatrix * mvPosition;
+
+			}
+
+		</script>
+
+		<script type="x-shader/x-fragment" id="fragmentshader">
+
+			uniform vec3 color;
+			uniform sampler2D texture;
+
+			varying vec4 vColor;
+
+			void main() {
+
+				vec4 outColor = texture2D( texture, gl_PointCoord );
+
+				if ( outColor.a < 0.5 ) discard;
+
+				gl_FragColor = outColor * vec4( color * vColor.xyz, 1.0 );
+
+				float depth = gl_FragCoord.z / gl_FragCoord.w;
+				const vec3 fogColor = vec3( 0.0 );
+
+				float fogFactor = smoothstep( 200.0, 600.0, depth );
+				gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );
+
+			}
+
+		</script>
+
+
+		<script type="text/javascript">
+
+		if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
+		var renderer, scene, camera, stats;
+
+		var object, uniforms, attributes;
+
+		var vc1;
+
+		var WIDTH = window.innerWidth,
+			HEIGHT = window.innerHeight;
+
+		init();
+		animate();
+
+		function init() {
+
+			camera = new THREE.Camera( 40, WIDTH / HEIGHT, 1, 1000 );
+			camera.position.z = 500;
+
+			scene = new THREE.Scene();
+
+			attributes = {
+
+				size: {	type: 'f', value: [] },
+				ca:   {	type: 'c', value: [] }
+
+			};
+
+			uniforms = {
+
+				amplitude: { type: "f", value: 1.0 },
+				color:     { type: "c", value: new THREE.Color( 0xffffff ) },
+				texture:   { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "textures/sprites/ball.png" ) },
+
+			};
+
+			uniforms.texture.texture.wrapS = uniforms.texture.texture.wrapT = THREE.RepeatWrapping;
+
+			var shaderMaterial = new THREE.MeshShaderMaterial( {
+
+				uniforms: 		uniforms,
+				attributes:     attributes,
+				vertexShader:   document.getElementById( 'vertexshader' ).textContent,
+				fragmentShader: document.getElementById( 'fragmentshader' ).textContent
+
+			});
+
+
+			var radius = 100, inner = 0.6 * radius;
+			var geometry = new THREE.Geometry();
+
+			for ( var i = 0; i < 100000; i++ ) {
+
+				vector = new THREE.Vector3( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
+
+				vector.multiplyScalar( radius );
+
+				if ( ( vector.x > inner || vector.x < -inner ) ||
+				     ( vector.y > inner || vector.y < -inner ) ||
+				     ( vector.z > inner || vector.z < -inner )  )
+
+				geometry.vertices.push( new THREE.Vertex( vector ) );
+
+			}
+
+			vc1 = geometry.vertices.length;
+
+			var m, dummyMaterial = new THREE.MeshFaceMaterial();
+
+			radius = 200;
+			var geometry2 = new THREE.CubeGeometry( radius, 0.1 * radius, 0.1 * radius, 50, 5, 5 );
+
+			function addGeo( geo, x, y, z, ry ) {
+
+				m = new THREE.Mesh( geo, dummyMaterial );
+				m.rotation.y = ry;
+				m.position.set( x, y, z );
+				THREE.GeometryUtils.merge( geometry, m );
+
+			}
+
+			// side 1
+
+			addGeo( geometry2, 0,  110,  110, 0 );
+			addGeo( geometry2, 0,  110, -110, 0 );
+			addGeo( geometry2, 0, -110,  110, 0 );
+			addGeo( geometry2, 0, -110, -110, 0 );
+
+			// side 2
+
+			addGeo( geometry2,  110,  110, 0, 1.57 );
+			addGeo( geometry2,  110, -110, 0, 1.57 );
+			addGeo( geometry2, -110,  110, 0, 1.57 );
+			addGeo( geometry2, -110, -110, 0, 1.57 );
+
+			// corner edges
+
+			var geometry3 = new THREE.CubeGeometry( 0.1 * radius, radius * 1.2, 0.1 * radius, 5, 60, 5 );
+
+			addGeo( geometry3,  110, 0,  110, 0 );
+			addGeo( geometry3,  110, 0, -110, 0 );
+			addGeo( geometry3, -110, 0,  110, 0 );
+			addGeo( geometry3, -110, 0, -110, 0 );
+
+			// particle system
+
+			object = new THREE.ParticleSystem( geometry, shaderMaterial );
+			object.dynamic = true;
+
+			// custom attributes
+
+			var vertices = object.geometry.vertices;
+
+			var values_size = attributes.size.value;
+			var values_color = attributes.ca.value;
+
+			for( var v = 0; v < vertices.length; v++ ) {
+
+				values_size[ v ] = 10;
+				values_color[ v ] = new THREE.Color( 0xffffff );
+
+				if ( v < vc1 ) {
+
+					values_color[ v ].setHSV( 0.5 + 0.2 * ( v / vc1 ), 0.99, 1.0 );
+
+				} else {
+
+					values_size[ v ] = 55;
+					values_color[ v ].setHSV( 0.1, 0.99, 1.0 );
+
+				}
+
+			}
+
+			console.log( vertices.length );
+
+			scene.addObject( object );
+
+			renderer = new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1 } );
+			renderer.setSize( WIDTH, HEIGHT );
+
+			var container = document.getElementById( 'container' );
+			container.appendChild( renderer.domElement );
+
+			stats = new Stats();
+			stats.domElement.style.position = 'absolute';
+			stats.domElement.style.top = '0px';
+			container.appendChild( stats.domElement );
+
+		}
+
+		function cap( x, a, b ) {
+
+			return ( x < a ) ? a : ( ( x > b ) ? b : x );
+
+		}
+
+		var i, value;
+
+		function animate() {
+
+			requestAnimationFrame( animate );
+
+			render();
+			stats.update();
+
+		}
+
+		function render() {
+
+			var time = new Date().getTime() * 0.01;
+
+			object.rotation.y = 0.02 * time;
+			object.rotation.z = 0.02 * time;
+
+			for( i = 0; i < attributes.size.value.length; i++ ) {
+
+				if ( i < vc1 )
+					attributes.size.value[ i ] = 26 + 32 * Math.sin( 0.1 * i + 0.6 * time );
+
+
+			}
+
+			attributes.size.needsUpdate = true;
+
+			renderer.render( scene, camera );
+
+		}
+
+
+	</script>
+
+</body>
+
+</html>

+ 1 - 1
examples/webgl_flycamera_earth.html

@@ -138,7 +138,7 @@
 
 		uniforms[ "uShininess" ].value = 30;
 
-		var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
+		var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
 		var materialNormalMap = new THREE.MeshShaderMaterial( parameters );
 
 		// planet

+ 1 - 1
examples/webgl_geometry_dynamic.html

@@ -90,6 +90,7 @@
 				camera.target.position.y = camera.position.y;
 
 				geometry = new THREE.PlaneGeometry( 20000, 20000, worldWidth - 1, worldDepth - 1 );
+				geometry.dynamic = true;
 
 				var i, j, il, jl;
 
@@ -111,7 +112,6 @@
 				material = new THREE.MeshBasicMaterial( { color:0x0044ff, opacity:1, map: texture } );
 
 				mesh = new THREE.Mesh( geometry, material );
-				mesh.dynamic = true;
 				mesh.rotation.x = - 90 * Math.PI / 180;
 				scene.addObject( mesh );
 

+ 1 - 1
examples/webgl_geometry_large_mesh.html

@@ -142,7 +142,7 @@
 
 				if ( render_gl ) {
 					try {
-						webglRenderer = new THREE.WebGLRenderer();
+						webglRenderer = new THREE.WebGLRenderer( { antialias: true } );
 						webglRenderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
 						webglRenderer.domElement.style.position = "relative";
 						container.appendChild( webglRenderer.domElement );

+ 1 - 1
examples/webgl_geometry_minecraft.html

@@ -144,7 +144,7 @@
 						mesh.position.y = h * 100;
 						mesh.position.z = z * 100 - worldHalfDepth * 100;
 
-						GeometryUtils.merge( geometry, mesh );
+						THREE.GeometryUtils.merge( geometry, mesh );
 
 					}
 

+ 3 - 3
examples/webgl_geometry_minecraft_ao.html

@@ -431,7 +431,7 @@
 						mesh.position.y = h * 100;
 						mesh.position.z = z * 100 - worldHalfDepth * 100;
 
-						GeometryUtils.merge( geometry, mesh );
+						THREE.GeometryUtils.merge( geometry, mesh );
 
 					}
 
@@ -521,7 +521,7 @@
 				canvas.width = canvas.height = size;
 
 				var texture = new THREE.Texture( canvas, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
-				
+
 				function generateTexture() {
 
 					if( count == 3 ) {
@@ -578,7 +578,7 @@
 
 				var texture = new THREE.Texture( canvas, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
 				texture.needsUpdate = true;
-				
+
 				return new THREE.MeshLambertMaterial( { map: texture } );
 
 			}

+ 477 - 0
examples/webgl_geometry_shapes.html

@@ -0,0 +1,477 @@
+<!DOCTYPE HTML>
+<html lang="en">
+	<head>
+		<title>three.js canvas - geometry - shapes</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
+		<style type="text/css">
+			body {
+				font-family: Monospace;
+				background-color: #f0f0f0;
+				margin: 0px;
+				overflow: hidden;
+			}
+		</style>
+	</head>
+	<body>
+		<canvas id="debug" style="position:absolute; left:100px"></canvas>
+
+		<script type="text/javascript" src="../build/Three.js"></script>
+
+		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
+		<script type="text/javascript" src="js/Stats.js"></script>
+
+
+		<script type="text/javascript">
+
+			var container, stats;
+
+			var camera, scene, renderer;
+
+			var text, plane;
+
+			var targetRotation = 0;
+			var targetRotationOnMouseDown = 0;
+
+			var mouseX = 0;
+			var mouseXOnMouseDown = 0;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+			init();
+			animate();
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				var info = document.createElement( 'div' );
+				info.style.position = 'absolute';
+				info.style.top = '10px';
+				info.style.width = '100%';
+				info.style.textAlign = 'center';
+				info.innerHTML = 'Simple procedurally generated 3D shapes example by <a href="http://www.lab4games.net/zz85/blog">zz85</a><br/>Drag to spin';
+				container.appendChild( info );
+
+				camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
+				camera.position.y = 150;
+				camera.position.z = 500;
+				camera.target.position.y = 150;
+
+				scene = new THREE.Scene();
+
+				var light = new THREE.DirectionalLight( 0xffffff );
+				light.position.set( 0, 0, 1 );
+				light.position.normalize();
+				scene.addLight( light );
+
+				parent = new THREE.Object3D();
+				parent.position.y = 50;
+				scene.addChild( parent );
+
+				function addGeometry( geometry, points, spacedPoints, color, x, y, z, rx, ry, rz, s ) {
+
+					// 3d shape
+
+					var mesh = new THREE.Mesh( geometry, [ new THREE.MeshLambertMaterial( { color: color } ), new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } ) ] );
+					mesh.position.set( x, y, z - 75 );
+					mesh.rotation.set( rx, ry, rz );
+					mesh.scale.set( s, s, s );
+					parent.addChild( mesh );
+
+					// solid line
+
+					var line = new THREE.Line( points, new THREE.LineBasicMaterial( { color: color, linewidth: 2 } ) );
+					line.position.set( x, y, z + 25 );
+					line.rotation.set( rx, ry, rz );
+					line.scale.set( s, s, s );
+					parent.addChild( line );
+
+					// transparent line from real points
+
+					var line = new THREE.Line( points, new THREE.LineBasicMaterial( { color: color, opacity: 0.5 } ) );
+					line.position.set( x, y, z + 75 );
+					line.rotation.set( rx, ry, rz );
+					line.scale.set( s, s, s );
+					parent.addChild( line );
+
+					// vertices from real points
+
+					var pgeo = THREE.GeometryUtils.clone( points );
+					var particles = new THREE.ParticleSystem( pgeo, new THREE.ParticleBasicMaterial( { color: color, size: 2, opacity: 0.75 } ) );
+					particles.position.set( x, y, z + 75 );
+					particles.rotation.set( rx, ry, rz );
+					particles.scale.set( s, s, s );
+					parent.addChild( particles );
+
+					// transparent line from equidistance sampled points
+
+					var line = new THREE.Line( spacedPoints, new THREE.LineBasicMaterial( { color: color, opacity: 0.2 } ) );
+					line.position.set( x, y, z + 100 );
+					line.rotation.set( rx, ry, rz );
+					line.scale.set( s, s, s );
+					parent.addChild( line );
+
+					// equidistance sampled points
+
+					var pgeo = THREE.GeometryUtils.clone( spacedPoints );
+					var particles2 = new THREE.ParticleSystem( pgeo, new THREE.ParticleBasicMaterial( { color: color, size: 2, opacity: 0.5 } ) );
+					particles2.position.set( x, y, z + 100 );
+					particles2.rotation.set( rx, ry, rz );
+					particles2.scale.set( s, s, s );
+					parent.addChild( particles2 );
+
+				}
+
+				var extrudeSettings = {	amount: 20,  bevelEnabled: true, bevelSegments: 2, steps: 2 }; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5,
+
+				// California
+
+				var californiaPts = [];
+
+				californiaPts.push( new THREE.Vector2 ( 610, 320 ) );
+				californiaPts.push( new THREE.Vector2 ( 450, 300 ) );
+				californiaPts.push( new THREE.Vector2 ( 392, 392 ) );
+				californiaPts.push( new THREE.Vector2 ( 266, 438 ) );
+				californiaPts.push( new THREE.Vector2 ( 190, 570 ) );
+				californiaPts.push( new THREE.Vector2 ( 190, 600 ) );
+				californiaPts.push( new THREE.Vector2 ( 160, 620 ) );
+				californiaPts.push( new THREE.Vector2 ( 160, 650 ) );
+				californiaPts.push( new THREE.Vector2 ( 180, 640 ) );
+				californiaPts.push( new THREE.Vector2 ( 165, 680 ) );
+				californiaPts.push( new THREE.Vector2 ( 150, 670 ) );
+				californiaPts.push( new THREE.Vector2 (  90, 737 ) );
+				californiaPts.push( new THREE.Vector2 (  80, 795 ) );
+				californiaPts.push( new THREE.Vector2 (  50, 835 ) );
+				californiaPts.push( new THREE.Vector2 (  64, 870 ) );
+				californiaPts.push( new THREE.Vector2 (  60, 945 ) );
+				californiaPts.push( new THREE.Vector2 ( 300, 945 ) );
+				californiaPts.push( new THREE.Vector2 ( 300, 743 ) );
+				californiaPts.push( new THREE.Vector2 ( 600, 473 ) );
+				californiaPts.push( new THREE.Vector2 ( 626, 425 ) );
+				californiaPts.push( new THREE.Vector2 ( 600, 370 ) );
+				californiaPts.push( new THREE.Vector2 ( 610, 320 ) );
+
+				var californiaShape = new THREE.Shape( californiaPts );
+
+				var california3d = new THREE.ExtrudeGeometry( californiaShape, { amount: 20	} );
+				var californiaPoints = californiaShape.createPointsGeometry();
+				var californiaSpacedPoints = californiaShape.createSpacedPointsGeometry( 100 );
+
+				// Triangle
+
+				var triangleShape = new THREE.Shape();
+				triangleShape.moveTo(  80, 20 );
+				triangleShape.lineTo(  40, 80 );
+				triangleShape.lineTo( 120, 80 );
+				triangleShape.lineTo(  80, 20 ); // close path
+
+				var triangle3d = triangleShape.extrude( extrudeSettings );
+				var trianglePoints = triangleShape.createPointsGeometry();
+				var triangleSpacedPoints = triangleShape.createSpacedPointsGeometry();
+
+
+				// Heart
+
+				var x = 0, y = 0;
+
+				var heartShape = new THREE.Shape(); // From http://blog.burlock.org/html5/130-paths
+
+				heartShape.moveTo( x + 25, y + 25 );
+				heartShape.bezierCurveTo( x + 25, y + 25, x + 20, y, x, y );
+				heartShape.bezierCurveTo( x - 30, y, x - 30, y + 35,x - 30,y + 35 );
+				heartShape.bezierCurveTo( x - 30, y + 55, x - 10, y + 77, x + 25, y + 95 );
+				heartShape.bezierCurveTo( x + 60, y + 77, x + 80, y + 55, x + 80, y + 35 );
+				heartShape.bezierCurveTo( x + 80, y + 35, x + 80, y, x + 50, y );
+				heartShape.bezierCurveTo( x + 35, y, x + 25, y + 25, x + 25, y + 25 );
+
+				var heart3d = heartShape.extrude( extrudeSettings );
+				var heartPoints = heartShape.createPointsGeometry();
+				var heartSpacedPoints = heartShape.createSpacedPointsGeometry();
+
+				//heartShape.debug( document.getElementById("debug") );
+
+				// Square
+
+				var sqLength = 80;
+
+				var squareShape = new THREE.Shape();
+				squareShape.moveTo( 0,0 );
+				squareShape.lineTo( 0, sqLength );
+				squareShape.lineTo( sqLength, sqLength );
+				squareShape.lineTo( sqLength, 0 );
+				squareShape.lineTo( 0, 0 );
+
+				var square3d = squareShape.extrude( extrudeSettings );
+				var squarePoints = squareShape.createPointsGeometry();
+				var squareSpacedPoints = squareShape.createSpacedPointsGeometry();
+
+				// Rectangle
+
+				var rectLength = 120, rectWidth = 40;
+
+				var rectShape = new THREE.Shape();
+				rectShape.moveTo( 0,0 );
+				rectShape.lineTo( 0, rectWidth );
+				rectShape.lineTo( rectLength, rectWidth );
+				rectShape.lineTo( rectLength, 0 );
+				rectShape.lineTo( 0, 0 );
+
+				var rect3d = rectShape.extrude( extrudeSettings );
+				var rectPoints = rectShape.createPointsGeometry();
+				var rectSpacedPoints = rectShape.createSpacedPointsGeometry();
+
+				// Rounded rectangle
+
+				var roundedRectShape = new THREE.Shape();
+				roundedRect( roundedRectShape, 0, 0, 50, 50, 20 );
+
+				var roundedRect3d = roundedRectShape.extrude( extrudeSettings );
+				var roundedRectPoints = roundedRectShape.createPointsGeometry();
+				var roundedRectSpacedPoints = roundedRectShape.createSpacedPointsGeometry();
+
+				function roundedRect( ctx, x, y, width, height, radius ){
+
+					ctx.moveTo( x, y + radius );
+					ctx.lineTo( x, y + height - radius );
+					ctx.quadraticCurveTo( x, y + height, x + radius, y + height );
+					ctx.lineTo( x + width - radius, y + height) ;
+					ctx.quadraticCurveTo( x + width, y + height, x + width, y + height - radius );
+					ctx.lineTo( x + width, y + radius );
+					ctx.quadraticCurveTo( x + width, y, x + width - radius, y );
+					ctx.lineTo( x + radius, y );
+					ctx.quadraticCurveTo( x, y, x, y + radius );
+
+				}
+
+				// Circle
+
+				var circleRadius = 40;
+				var circleShape = new THREE.Shape();
+				circleShape.moveTo( 0, circleRadius );
+				circleShape.quadraticCurveTo( circleRadius, circleRadius, circleRadius, 0 );
+				circleShape.quadraticCurveTo( circleRadius, -circleRadius, 0, -circleRadius );
+				circleShape.quadraticCurveTo( -circleRadius, -circleRadius, -circleRadius, 0 );
+				circleShape.quadraticCurveTo( -circleRadius, circleRadius, 0, circleRadius );
+
+				var circle3d = circleShape.extrude( extrudeSettings );
+				var circlePoints = circleShape.createPointsGeometry();
+				var circleSpacedPoints = circleShape.createSpacedPointsGeometry();
+
+				// Fish
+
+				x = y = 0;
+
+				var fishShape = new THREE.Shape();
+
+				fishShape.moveTo(x,y);
+				fishShape.quadraticCurveTo(x + 50, y - 80, x + 90, y - 10);
+				fishShape.quadraticCurveTo(x + 100, y - 10, x + 115, y - 40);
+				fishShape.quadraticCurveTo(x + 115, y, x + 115, y + 40);
+				fishShape.quadraticCurveTo(x + 100, y + 10, x + 90, y + 10);
+				fishShape.quadraticCurveTo(x + 50, y + 80, x, y);
+
+				var fish3d = fishShape.extrude( extrudeSettings );
+				var fishPoints = fishShape.createPointsGeometry();
+				var fishSpacedPoints = fishShape.createSpacedPointsGeometry();
+
+				// Arc circle
+
+				var arcShape = new THREE.Shape();
+				arcShape.moveTo( 0, 0 );
+				arcShape.arc( 10, 10, 40, 0, Math.PI*2, false );
+
+				var holePath = new THREE.Path();
+				holePath.moveTo( 0, 0 );
+				holePath.arc( 10, 10, 10, 0, Math.PI*2, true );
+				arcShape.holes.push( holePath );
+
+				var arc3d = arcShape.extrude( extrudeSettings );
+				var arcPoints = arcShape.createPointsGeometry();
+				var arcSpacedPoints = arcShape.createSpacedPointsGeometry();
+
+
+				// Smiley
+
+				var smileyShape = new THREE.Shape();
+				smileyShape.moveTo( 0, 0 );
+				smileyShape.arc( 40, 40, 40, 0, Math.PI*2, false );
+
+				var smileyEye1Path = new THREE.Path();
+				smileyEye1Path.moveTo( 0, 0 );
+				smileyEye1Path.arc( 25, 20, 10, 0, Math.PI*2, true );
+				smileyShape.holes.push( smileyEye1Path );
+
+				var smileyEye2Path = new THREE.Path();
+				smileyEye2Path.moveTo( 0, 0 );
+				smileyEye2Path.arc( 55, 20, 10, 0, Math.PI*2, true );
+				smileyShape.holes.push( smileyEye2Path );
+
+				var smileyMouthPath = new THREE.Path();
+				// ugly box mouth
+				// smileyMouthPath.moveTo( 20, 40 );
+				// smileyMouthPath.lineTo( 60, 40 );
+				// smileyMouthPath.lineTo( 60, 60 );
+				// smileyMouthPath.lineTo( 20, 60 );
+				// smileyMouthPath.lineTo( 20, 40 );
+
+				smileyMouthPath.moveTo( 20, 40 );
+				smileyMouthPath.quadraticCurveTo( 40, 60, 60, 40 );
+				smileyMouthPath.bezierCurveTo( 70, 45, 70, 50, 60, 60 );
+				smileyMouthPath.quadraticCurveTo( 40, 80, 20, 60 );
+				smileyMouthPath.quadraticCurveTo( 5, 50, 20, 40 );
+
+				smileyShape.holes.push( smileyMouthPath );
+
+
+				var smiley3d = smileyShape.extrude( extrudeSettings );
+				var smileyPoints = smileyShape.createPointsGeometry();
+				var smileySpacedPoints = smileyShape.createSpacedPointsGeometry();
+
+				// Spline shape + path extrusion
+
+				var splinepts = [];
+				splinepts.push( new THREE.Vector2 ( 350, 100 ) );
+				splinepts.push( new THREE.Vector2 ( 400, 450 ) );
+				splinepts.push( new THREE.Vector2 ( -140, 350 ) );
+				splinepts.push( new THREE.Vector2 ( 0, 0 ) );
+
+				var splineShape = new THREE.Shape(  );
+				splineShape.moveTo( 0, 0 );
+				splineShape.splineThru( splinepts );
+
+				//splineShape.debug( document.getElementById("debug") );
+
+				var extrudePath = new THREE.Path();
+
+				extrudePath.moveTo( 0, 0 );
+				extrudePath.lineTo( 10, 10 );
+				extrudePath.quadraticCurveTo( 80, 60, 160, 10 );
+				extrudePath.quadraticCurveTo( 240, -40, 320, 10 );
+
+				extrudeSettings.extrudePath = extrudePath;
+				extrudeSettings.bevelEnabled = false;
+
+				var splineShape3d = splineShape.extrude( extrudeSettings );
+				var splinePoints = splineShape.createPointsGeometry( );
+				var splineSpacedPoints = splineShape.createSpacedPointsGeometry( );
+
+				addGeometry( california3d, californiaPoints, californiaSpacedPoints,	0xffaa00, -300, -100, 0,     0, 0, 0, 0.25 );
+				addGeometry( triangle3d, trianglePoints, triangleSpacedPoints, 			0xffee00, -180,    0, 0,     0, 0, 0, 1 );
+				addGeometry( roundedRect3d, roundedRectPoints, roundedRectSpacedPoints,	0x005500, -150,  150, 0,     0, 0, 0, 1 );
+				addGeometry( square3d, squarePoints, squareSpacedPoints,				0x0055ff,  150,  100, 0,     0, 0, 0, 1 );
+				addGeometry( heart3d, heartPoints, heartSpacedPoints,					0xff1100,    0,  100, 0,   3.14, 0, 0, 1 );
+				addGeometry( circle3d, circlePoints, circleSpacedPoints,				0x00ff11,  120,  250, 0,     0, 0, 0, 1 );
+				addGeometry( fish3d, fishPoints, fishSpacedPoints,						0x222222,  -60,  200, 0,     0, 0, 0, 1 );
+				addGeometry( splineShape3d, splinePoints, splineSpacedPoints,			0x888888,  -50,  -100, -50,  0, 0, 0, 0.2 );
+				addGeometry( arc3d, arcPoints, arcSpacedPoints,							0xbb4422,  150,    0, 0,     0, 0, 0, 1 );
+				addGeometry( smiley3d, smileyPoints, smileySpacedPoints,				0xee00ff,  -270,    250, 0,     Math.PI, 0, 0, 1 );
+
+
+				//
+
+				renderer = new THREE.WebGLRenderer( { antialias: true } );
+                renderer.setSize( window.innerWidth, window.innerHeight );
+
+				container.appendChild( renderer.domElement );
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				container.appendChild( stats.domElement );
+
+				document.addEventListener( 'mousedown', onDocumentMouseDown, false );
+				document.addEventListener( 'touchstart', onDocumentTouchStart, false );
+				document.addEventListener( 'touchmove', onDocumentTouchMove, false );
+
+			}
+
+			//
+
+			function onDocumentMouseDown( event ) {
+
+				event.preventDefault();
+
+				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.addEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.addEventListener( 'mouseout', onDocumentMouseOut, false );
+
+				mouseXOnMouseDown = event.clientX - windowHalfX;
+				targetRotationOnMouseDown = targetRotation;
+
+			}
+
+			function onDocumentMouseMove( event ) {
+
+				mouseX = event.clientX - windowHalfX;
+
+				targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;
+
+			}
+
+			function onDocumentMouseUp( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
+
+			}
+
+			function onDocumentMouseOut( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
+
+			}
+
+			function onDocumentTouchStart( event ) {
+
+				if ( event.touches.length == 1 ) {
+
+					event.preventDefault();
+
+					mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
+					targetRotationOnMouseDown = targetRotation;
+
+				}
+
+			}
+
+			function onDocumentTouchMove( event ) {
+
+				if ( event.touches.length == 1 ) {
+
+					event.preventDefault();
+
+					mouseX = event.touches[ 0 ].pageX - windowHalfX;
+					targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
+
+				}
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			function render() {
+
+				parent.rotation.y += ( targetRotation - parent.rotation.y ) * 0.05;
+				renderer.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 111 - 133
examples/webgl_geometry_text.html

@@ -26,14 +26,15 @@
 	<body>
 
 		<div id="info">
-		<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - procedural 3D text by <a href="http://www.lab4games.net/zz85/blog" target="_blank">zz85</a> &amp; alteredq 
+		<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - procedural 3D text by <a href="http://www.lab4games.net/zz85/blog" target="_blank">zz85</a> &amp; alteredq
 		(fonts from <a href="http://typeface.neocracy.org/">typeface.js</a> and <a href="http://en.wikipedia.org/wiki/Droid_%28font%29">Droid</a>)
 		<br/>type to enter new text, drag to spin the text
-		<br/><span class="button" id="color">change color</span>, 
-			<span class="button" id="font">change font</span>, 
+		<br/><span class="button" id="color">change color</span>,
+			<span class="button" id="font">change font</span>,
 			<span class="button" id="weight">change weight</span>,
-			<span class="button" id="bezel">change bezel</span>,
-			<span class="button" id="postprocessing">change postprocessing</span>, 
+			<span class="button" id="bevel">change bevel</span>,
+			<span class="button" id="bend">bend</span>,
+			<span class="button" id="postprocessing">change postprocessing</span>,
 			<a id="permalink" href="#">permalink</a>
 		</div>
 
@@ -43,13 +44,9 @@
 		<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>
-			  
-		<!-- load the font file from canvas-text -->
 
-		<!--
-		
-		
-		-->
+		<!-- load the font files -->
+
 		<script type="text/javascript" src="fonts/gentilis_bold.typeface.js"></script>
 		<script type="text/javascript" src="fonts/gentilis_regular.typeface.js"></script>
 		<script type="text/javascript" src="fonts/optimer_bold.typeface.js"></script>
@@ -60,7 +57,8 @@
 		<script type="text/javascript" src="fonts/droid/droid_sans_bold.typeface.js"></script>
 		<script type="text/javascript" src="fonts/droid/droid_serif_regular.typeface.js"></script>
 		<script type="text/javascript" src="fonts/droid/droid_serif_bold.typeface.js"></script>
-		
+
+		<!-- todo async loader for fonts -->
 
 		<script type="text/javascript">
 
@@ -82,9 +80,11 @@
 
 				curveSegments = 6,
 
-				bezelThickness = 2,
-				bezelSize = 1.5,
-				bezelEnabled = true,
+				bevelThickness = 2,
+				bevelSize = 1.5,
+				bevelSegments = 3,
+				bevelEnabled = true,
+				bend = true,
 
 				font = "optimer", 		// helvetiker, optimer, gentilis, droid sans, droid serif
 				weight = "bold",		// normal bold
@@ -134,9 +134,9 @@
 			}
 
 			function decimalToHex( d ) {
-  
+
 				var hex = Number( d ).toString( 16 );
-				hex = "000000".substr( 0, 6 - hex.length ) + hex; 
+				hex = "000000".substr( 0, 6 - hex.length ) + hex;
 				return hex.toUpperCase();
 
 			}
@@ -163,7 +163,7 @@
 				scene.addLight( dirLight );
 
 				var pointLight = new THREE.PointLight( 0xffffff, 1.5 );
-				pointLight.position.set( 0, 100, 50 );
+				pointLight.position.set( 0, 100, 90 );
 				scene.addLight( pointLight );
 
 				//text = capitalize( font ) + " " + capitalize( weight );
@@ -180,8 +180,9 @@
 					var fonthash   = hash.substring( 6, 7 );
 					var weighthash = hash.substring( 7, 8 );
 					var pphash 	   = hash.substring( 8, 9 );
-					var bezelhash  = hash.substring( 9, 10 );
-					var texthash   = hash.substring( 11 );
+					var bevelhash  = hash.substring( 9, 10 );
+					var bendhash   = hash.substring( 10, 11 );
+					var texthash   = hash.substring( 12 );
 
 					hex = colorhash;
 					pointLight.color.setHex( parseInt( colorhash, 16 ) );
@@ -190,7 +191,8 @@
 					weight = reverseWeightMap[ parseInt( weighthash ) ];
 
 					postprocessing.enabled = parseInt( pphash );
-					bezelEnabled = parseInt( bezelhash );
+					bevelEnabled = parseInt( bevelhash );
+					bend = parseInt( bendhash );
 
 					text = decodeURI( texthash );
 
@@ -199,60 +201,19 @@
 				} else {
 
 					pointLight.color.setHSV( Math.random(), 0.95, 0.85 );
-					pointLight.color.updateHex();
-					hex = decimalToHex( pointLight.color.hex );
+					hex = decimalToHex( pointLight.color.getHex() );
 
 				}
 
-				textGeo = new THREE.TextGeometry( text, {
-
-					size: size, 
-					height: height,
-					curveSegments: curveSegments,
-
-					font: font,
-					weight: weight,
-					style: style,
-
-					bezelThickness: bezelThickness,
-					bezelSize: bezelSize,
-					bezelEnabled: bezelEnabled
-
-				});
-				
 				textMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, wireframe: false } );
 
 				parent = new THREE.Object3D();
-				
-				textMesh1 = new THREE.Mesh( textGeo, textMaterial );
-
-				textMesh1.position.x = 0;
-				textMesh1.position.y = hover;
-				textMesh1.position.z = 0;
-
-				textMesh1.rotation.x = 0;
-				textMesh1.rotation.y = Math.PI * 2;
-
-				parent.addChild( textMesh1 );
-
-				if ( mirror ) {
-
-					textMesh2 = new THREE.Mesh( textGeo, textMaterial );
-
-					textMesh2.position.x = 0;
-					textMesh2.position.y = -hover;
-					textMesh2.position.z = height;
-
-					textMesh2.rotation.x = Math.PI;
-					textMesh2.rotation.y = Math.PI * 2;
-
-					parent.addChild( textMesh2 );
-					
-				}
-
 				parent.position.y = 100;
+
 				scene.addChild( parent );
 
+				createText();
+
 				var plane = new THREE.Mesh( new THREE.PlaneGeometry( 10000, 10000 ), new THREE.MeshBasicMaterial( { color: 0xffffff, opacity: 0.5, transparent: true } ) );
 				plane.rotation.x = -1.57;
 				plane.position.y = 100;
@@ -260,7 +221,7 @@
 
 				renderer = new THREE.WebGLRenderer( { antialias: false } );
 				renderer.setSize( window.innerWidth, window.innerHeight );
-				
+
 				renderer.setClearColor( scene.fog.color, 1 );
 
 				container.appendChild( renderer.domElement );
@@ -277,91 +238,98 @@
 				document.addEventListener( 'keydown', onDocumentKeyDown, false );
 
 				document.getElementById( "color" ).addEventListener( 'click', function() {
-				
+
 					pointLight.color.setHSV( Math.random(), 0.95, 0.85 );
-					pointLight.color.updateHex();
-					hex = decimalToHex( pointLight.color.hex );
-					
+					hex = decimalToHex( pointLight.color.getHex() );
+
 					updatePermalink();
-					
+
 				}, false );
 
 				document.getElementById( "font" ).addEventListener( 'click', function() {
-				
+
 					if ( font == "helvetiker" ) {
 
 						font = "optimer";
 
 					} else if ( font == "optimer" ) {
-						
+
 						font = "gentilis";
-						
+
 					} else if ( font == "gentilis" ) {
-						
+
 						font = "droid sans";
-						
+
 					} else if ( font == "droid sans" ) {
-						
+
 						font = "droid serif";
 
 					} else {
-					
+
 						font = "helvetiker";
-						
+
 					}
-					
+
 					refreshText();
-					
+
 				}, false );
 
 				document.getElementById( "weight" ).addEventListener( 'click', function() {
-				
+
 					if ( weight == "bold" ) {
 
 						weight = "normal";
 
 					} else {
-					
+
 						weight = "bold";
-						
+
 					}
-					
+
+					refreshText();
+
+				}, false );
+
+				document.getElementById( "bevel" ).addEventListener( 'click', function() {
+
+					bevelEnabled = !bevelEnabled;
+
 					refreshText();
-					
+
 				}, false );
 
-				document.getElementById( "bezel" ).addEventListener( 'click', function() {
-				
-					bezelEnabled = !bezelEnabled;
-					
+				document.getElementById( "bend" ).addEventListener( 'click', function() {
+
+					bend = !bend;
 					refreshText();
-					
+
 				}, false );
 
 				document.getElementById( "postprocessing" ).addEventListener( 'click', function() {
-				
+
 					postprocessing.enabled = !postprocessing.enabled;
 					updatePermalink();
-					
+
 				}, false );
 
 				initPostprocessing();
 				renderer.autoClear = false;
 
 			}
-			
+
 			//
-			
+
 			function boolToNum( b ) {
-				
+
 				return b ? 1 : 0;
 
 			}
-			
+
 			function updatePermalink() {
-			
-				var link = hex + fontMap[ font ] + weightMap[ weight ] + boolToNum( postprocessing.enabled ) + boolToNum( bezelEnabled ) + "#" + encodeURI( text );
-				
+
+				var link = hex + fontMap[ font ] + weightMap[ weight ] + boolToNum( postprocessing.enabled ) + boolToNum( bevelEnabled )
+				+ boolToNum( bend ) + "#" + encodeURI( text );
+
 				permalink.href = "#" + link;
 				window.location.hash = link;
 
@@ -370,14 +338,14 @@
 			function onDocumentKeyDown( event ) {
 
 				if ( firstLetter ) {
-				
+
 					firstLetter = false;
 					text = "";
 
 				}
-				
+
 				var keyCode = event.keyCode;
-				
+
 				// backspace
 
 				if ( keyCode == 8 ) {
@@ -388,23 +356,23 @@
 					refreshText();
 
 					return false;
-					
+
 				}
 
 			}
-			
+
 			function onDocumentKeyPress( event ) {
-				
+
 				var keyCode = event.which;
-				
+
 				// backspace
 
 				if ( keyCode == 8 ) {
-					
+
 					event.preventDefault();
-					
+
 				} else {
-				
+
 					var ch = String.fromCharCode( keyCode );
 					text += ch;
 
@@ -413,16 +381,11 @@
 				}
 
 			}
-			
-			function refreshText() {
-
-				updatePermalink();
-				
-				scene.removeChild( textMesh1 );
 
+			function createText() {
 				textGeo = new THREE.TextGeometry( text, {
 
-					size: size, 
+					size: size,
 					height: height,
 					curveSegments: curveSegments,
 
@@ -430,15 +393,20 @@
 					weight: weight,
 					style: style,
 
-					bezelThickness: bezelThickness,
-					bezelSize: bezelSize,
-					bezelEnabled: bezelEnabled
+					bevelThickness: bevelThickness,
+					bevelSize: bevelSize,
+					bevelEnabled: bevelEnabled,
+
+					bend: bend
 
 				});
 
+				textGeo.computeBoundingBox();
+				var centerOffset = -0.5 * ( textGeo.boundingBox.x[ 1 ] - textGeo.boundingBox.x[ 0 ] );
+
 				textMesh1 = new THREE.Mesh( textGeo, textMaterial );
 
-				textMesh1.position.x = 0;
+				textMesh1.position.x = centerOffset;
 				textMesh1.position.y = hover;
 				textMesh1.position.z = 0;
 
@@ -449,24 +417,34 @@
 
 				if ( mirror ) {
 
-					scene.removeChild( textMesh2 );
-
 					textMesh2 = new THREE.Mesh( textGeo, textMaterial );
 
-					textMesh2.position.x = 0;
+					textMesh2.position.x = centerOffset;
 					textMesh2.position.y = -hover;
 					textMesh2.position.z = height;
 
 					textMesh2.rotation.x = Math.PI;
 					textMesh2.rotation.y = Math.PI * 2;
-					
-					
+
 					parent.addChild( textMesh2 );
-					
+
 				}
 
 			}
-			
+
+			function refreshText() {
+
+				updatePermalink();
+
+				scene.removeChild( textMesh1 );
+				if ( mirror ) scene.removeChild( textMesh2 );
+
+				if ( !text ) return;
+
+				createText();
+
+			}
+
 			function onDocumentMouseDown( event ) {
 
 				event.preventDefault();
@@ -531,7 +509,7 @@
 			}
 
 			//
-			
+
 			function initPostprocessing() {
 
 				postprocessing.scene = new THREE.Scene();
@@ -621,9 +599,9 @@
 				time = new Date().getTime();
 				delta = 0.1 * ( time - oldTime );
 				oldTime = time;
-				
+
 				parent.rotation.y += ( targetRotation - parent.rotation.y ) * 0.05;
-				
+
 				if ( postprocessing.enabled ) {
 
 					renderer.clear();
@@ -669,7 +647,7 @@
 					renderer.clear();
 					renderer.render( scene, camera );
 
-				}				
+				}
 
 			}
 

+ 1 - 1
examples/webgl_interactive_cubes.html

@@ -145,7 +145,7 @@
 						if ( INTERSECTED ) INTERSECTED.materials[ 0 ].color.setHex( INTERSECTED.currentHex );
 
 						INTERSECTED = intersects[ 0 ].object;
-						INTERSECTED.currentHex = INTERSECTED.materials[ 0 ].color.hex;
+						INTERSECTED.currentHex = INTERSECTED.materials[ 0 ].color.getHex();
 						INTERSECTED.materials[ 0 ].color.setHex( 0xff0000 );
 
 					}

+ 1 - 1
examples/webgl_materials_grass.html

@@ -46,7 +46,7 @@
 
 				for ( var i = 0; i < 15; i ++ ) {
 
-					mesh = levels[ i ] = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map: new THREE.Texture( generateTextureLevel( bitmap ) ), depthTest: false } ) );
+					mesh = levels[ i ] = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map: new THREE.Texture( generateTextureLevel( bitmap ) ), transparent: true, depthTest: false } ) );
 					mesh.materials[0].map.needsUpdate = true;
 					mesh.rotation.x = - 90 * ( Math.PI / 180 );
 					mesh.position.y = i * 0.25;

+ 3 - 3
examples/webgl_objconvert_test.html

@@ -102,12 +102,12 @@
 				xc.fillStyle = "#555";
 				xc.fillRect(96, 96, 32, 32);
 
-				var xm = new THREE.MeshBasicMaterial( { map: new THREE.Texture( x, THREE.UVMapping, THREE.RepeatWrapping, THREE.RepeatWrapping ) } );
+				var xm = new THREE.MeshBasicMaterial( { map: new THREE.Texture( x, new THREE.UVMapping(), THREE.RepeatWrapping, THREE.RepeatWrapping ) } );
 				xm.map.needsUpdate = true;
 				xm.map.repeat.set( 10, 10 );
 
 				geometry = new THREE.PlaneGeometry( 100, 100, 15, 10 );
-	
+
 				mesh = new THREE.Mesh( geometry, xm );
 				mesh.position.x = 0;
 				mesh.position.y = FLOOR;
@@ -229,7 +229,7 @@
 					xc.font = "50pt arial bold";
 					xc.fillText(i, 10, 64);
 
-					var xm = new THREE.MeshBasicMaterial( { map: new THREE.Texture( x ) } );
+					var xm = new THREE.MeshBasicMaterial( { map: new THREE.Texture( x ), transparent: true } );
 					xm.map.needsUpdate = true;
 
 					mesh = new THREE.Mesh( new THREE.PlaneGeometry( size, size ), xm );

+ 5 - 3
examples/webgl_sandbox.html

@@ -20,7 +20,7 @@
 				font-family:Monospace;
 				font-size:13px;
 				text-align:center;
-				z-index:1000; 
+				z-index:1000;
 			}
 
 			a {
@@ -81,7 +81,6 @@
 		<script type="text/javascript" src="../src/objects/Bone.js"></script>
 		<script type="text/javascript" src="../src/objects/SkinnedMesh.js"></script>
 		<script type="text/javascript" src="../src/objects/Ribbon.js"></script>
-		<script type="text/javascript" src="../src/objects/Sound.js"></script>
 		<script type="text/javascript" src="../src/objects/LOD.js"></script>
 		<script type="text/javascript" src="../src/objects/ShadowVolume.js"></script>
 		<script type="text/javascript" src="../src/objects/Sprite.js"></script>
@@ -95,7 +94,6 @@
 		<script type="text/javascript" src="../src/renderers/WebGLShaders.js"></script>
 		<script type="text/javascript" src="../src/renderers/WebGLRenderer.js"></script>
 		<script type="text/javascript" src="../src/renderers/WebGLRenderTarget.js"></script>
-		<script type="text/javascript" src="../src/renderers/SoundRenderer.js"></script>
 		<script type="text/javascript" src="../src/renderers/renderables/RenderableVertex.js"></script>
 		<script type="text/javascript" src="../src/renderers/renderables/RenderableFace3.js"></script>
 		<script type="text/javascript" src="../src/renderers/renderables/RenderableFace4.js"></script>
@@ -114,8 +112,12 @@
 		<script type="text/javascript" src="../src/extras/cameras/FlyCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/RollCamera.js"></script>
 		<script type="text/javascript" src="../src/extras/cameras/TrackballCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/cameras/QuakeCamera.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/Path.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/Shape.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/CubeGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/CylinderGeometry.js"></script>
+		<script type="text/javascript" src="../src/extras/geometries/ExtrudeGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/IcosahedronGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/LatheGeometry.js"></script>
 		<script type="text/javascript" src="../src/extras/geometries/PlaneGeometry.js"></script>

+ 411 - 0
examples/webgl_shadowmap.html

@@ -0,0 +1,411 @@
+<!DOCTYPE HTML>
+<html lang="en">
+	<head>
+		<title>three.js webgl - shadow map</title>
+		<meta charset="utf-8">
+		<style type="text/css">
+			body {
+				font-family: Monospace;
+				background-color: #000;
+				color: #fff;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				position: absolute;
+				top: 10px;
+				width: 100%;
+				text-align: center;
+				z-index: 100;
+				display:block;
+			}
+			#info a { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
+		</style>
+	</head>
+
+	<body>
+
+		<div id="info">
+		<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - shadowmap - models by <a href="http://mirada.com/">mirada</a> from <a href="http://ro.me">rome</a></br>
+		move camera with WASD / RF + mouse
+		</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>
+
+		<script type="text/javascript" src="fonts/helvetiker_bold.typeface.js"></script>
+
+		<script type="text/javascript">
+
+			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
+			var SHADOW_MAP_WIDTH = 1024, SHADOW_MAP_HEIGHT = 1024;
+
+			var MARGIN = 100;
+
+			var SCREEN_WIDTH = window.innerWidth;
+			var SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
+			var FLOOR = -250;
+
+			var camera, scene, renderer;
+			var container, stats;
+
+			var NEAR = 5, FAR = 3000;
+
+			var sceneHUD, cameraOrtho, hudMaterial;
+
+			var morphs = [];
+
+			var light;
+
+			init();
+			animate();
+
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				// SCENE CAMERA
+
+				camera = new THREE.FirstPersonCamera( { fov: 23, aspect: SCREEN_WIDTH / SCREEN_HEIGHT, near: NEAR, far: FAR,
+														lookSpeed: 0.0125, movementSpeed: 500, noFly: false, lookVertical: true,
+														constrainVertical: true, verticalMin: 1.5, verticalMax: 2.0
+														} );
+
+				camera.position.set( 700, 50, 1900 );
+				camera.lon = -110;
+
+				// SCENE
+
+				scene = new THREE.Scene();
+				scene.fog = new THREE.Fog( 0xffaa55, 1000, FAR );
+				THREE.ColorUtils.adjustHSV( scene.fog.color, 0.02, -0.15, -0.65 );
+
+				// LIGHTS
+
+				var ambient = new THREE.AmbientLight( 0x444444 );
+				scene.addLight( ambient );
+
+				light = new THREE.SpotLight( 0xffffff );
+				light.position.set( 0, 1500, 1000 );
+				light.target.position.set( 0, 0, 0 );
+				light.castShadow = true;
+				scene.addLight( light );
+
+				createHUD();
+				createScene();
+
+				// RENDERER
+
+				renderer = new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1, antialias: false } );
+				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
+				renderer.domElement.style.position = "relative";
+				renderer.domElement.style.top = MARGIN + 'px';
+				container.appendChild( renderer.domElement );
+
+				renderer.setClearColor( scene.fog.color, 1 );
+				renderer.autoClear = false;
+
+				renderer.shadowCameraNear = 3;
+				renderer.shadowCameraFar = camera.far;
+				renderer.shadowCameraFov = 50;
+
+				renderer.shadowMapBias = 0.0039;
+				renderer.shadowMapDarkness = 0.5;
+				renderer.shadowMapWidth = SHADOW_MAP_WIDTH;
+				renderer.shadowMapHeight = SHADOW_MAP_HEIGHT;
+
+				renderer.shadowMapEnabled = true;
+				renderer.shadowMapSoft = true;
+
+				// STATS
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				stats.domElement.style.zIndex = 100;
+				//container.appendChild( stats.domElement );
+
+			}
+
+			function createHUD() {
+
+				cameraOrtho = new THREE.Camera( 45, SHADOW_MAP_WIDTH / SHADOW_MAP_HEIGHT, NEAR, FAR );
+				cameraOrtho.projectionMatrix = THREE.Matrix4.makeOrtho( SCREEN_WIDTH / - 2, SCREEN_WIDTH / 2,  SCREEN_HEIGHT / 2, SCREEN_HEIGHT / - 2, -10, 1000 );
+				cameraOrtho.position.z = 10;
+
+				var shader = THREE.ShaderUtils.lib[ "screen" ];
+				var uniforms = new THREE.UniformsUtils.clone( shader.uniforms );
+
+				hudMaterial = new THREE.MeshShaderMaterial( { vertexShader: shader.vertexShader, fragmentShader: shader.fragmentShader, uniforms: uniforms } );
+
+				var hudGeo = new THREE.PlaneGeometry( SHADOW_MAP_WIDTH / 2, SHADOW_MAP_HEIGHT / 2 );
+				var hudMesh = new THREE.Mesh( hudGeo, hudMaterial );
+				hudMesh.position.x = ( SCREEN_WIDTH - SHADOW_MAP_WIDTH / 2 ) * -0.5;
+				hudMesh.position.y = ( SCREEN_HEIGHT - SHADOW_MAP_HEIGHT / 2 ) * -0.5;
+
+				sceneHUD = new THREE.Scene();
+				sceneHUD.addObject( hudMesh );
+
+			}
+
+			function createScene( ) {
+
+				// GROUND
+
+				var geometry = new THREE.PlaneGeometry( 100, 100 );
+				var planeMaterial = new THREE.MeshLambertMaterial( { color: 0xffdd99 } );
+				THREE.ColorUtils.adjustHSV( planeMaterial.color, 0, 0, 0.9 );
+
+				var ground = new THREE.Mesh( geometry, planeMaterial );
+
+				ground.position.set( 0, FLOOR, 0 );
+				ground.rotation.x = -1.57;
+				ground.scale.set( 100, 100, 100 );
+
+				ground.castShadow = false;
+				ground.receiveShadow = true;
+
+				scene.addObject( ground );
+
+				// TEXT
+
+				var textGeo = new THREE.TextGeometry( "THREE.JS", {
+
+					size: 200,
+					height: 50,
+					curveSegments: 12,
+
+					font: "helvetiker",
+					weight: "bold",
+					style: "normal",
+
+					bevelThickness: 2,
+					bevelSize: 5,
+					bevelEnabled: true
+
+				});
+
+				textGeo.computeBoundingBox();
+				var centerOffset = -0.5 * ( textGeo.boundingBox.x[ 1 ] - textGeo.boundingBox.x[ 0 ] );
+
+				var textMaterial = new THREE.MeshPhongMaterial( { color: 0xff0000, specular: 0xffffff, ambient: 0xaa0000 } );
+
+				var mesh = new THREE.Mesh( textGeo, textMaterial );
+				mesh.position.x = centerOffset;
+				mesh.position.y = FLOOR + 67;
+
+				mesh.castShadow = true;
+				mesh.receiveShadow = true;
+
+				scene.addObject( mesh );
+
+				// CUBES
+
+				var mesh = new THREE.Mesh( new THREE.CubeGeometry( 1500, 220, 150 ), planeMaterial );
+
+				mesh.position.y = FLOOR - 50;
+				mesh.position.z = 20;
+
+				mesh.castShadow = true;
+				mesh.receiveShadow = true;
+
+				scene.addObject( mesh );
+
+				var mesh = new THREE.Mesh( new THREE.CubeGeometry( 1600, 170, 250 ), planeMaterial );
+
+				mesh.position.y = FLOOR - 50;
+				mesh.position.z = 20;
+
+				mesh.castShadow = true;
+				mesh.receiveShadow = true;
+
+				scene.addObject( mesh );
+
+				// MORPHS
+
+				function addMorph( geometry, speed, duration, x, y, z, fudgeColor ) {
+
+					var material = new THREE.MeshLambertMaterial( { color: 0xffaa55, morphTargets: true, vertexColors: THREE.FaceColors } );
+
+					if ( fudgeColor ) THREE.ColorUtils.adjustHSV( material.color, 0, 0.5 - Math.random(), 0.5 - Math.random() );
+
+					var meshAnim = new THREE.Mesh( geometry, material );
+
+					meshAnim.position.set( x, y, z );
+					meshAnim.rotation.y = 1.57;
+
+					meshAnim.castShadow = true;
+					meshAnim.receiveShadow = false;
+
+					scene.addObject( meshAnim );
+
+					morphs.push( { mesh: meshAnim, lastKeyframe: 0, currentKeyframe: 0,
+								   offset: Math.random() * 6, speed: speed, duration: duration,
+								   oldTime: new Date().getTime() } );
+
+				}
+
+				function morphColorsToFaceColors( geometry ) {
+
+					if ( geometry.morphColors && geometry.morphColors.length ) {
+
+						var colorMap = geometry.morphColors[ 0 ];
+
+						for ( var i = 0; i < colorMap.colors.length; i ++ ) {
+
+							geometry.faces[ i ].color = colorMap.colors[ i ];
+
+						}
+
+					}
+
+				}
+
+				var loader = new THREE.JSONLoader();
+
+				loader.load( { model: "models/animated/horse.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+
+					addMorph( geometry, 0.55, 1000, 100 - Math.random() * 1000, FLOOR, 300, true );
+					addMorph( geometry, 0.55, 1000, 100 - Math.random() * 1000, FLOOR, 450, true );
+					addMorph( geometry, 0.55, 1000, 100 - Math.random() * 1000, FLOOR, 600, true );
+
+					addMorph( geometry, 0.55, 1000, 100 - Math.random() * 1000, FLOOR, -300, true );
+					addMorph( geometry, 0.55, 1000, 100 - Math.random() * 1000, FLOOR, -450, true );
+					addMorph( geometry, 0.55, 1000, 100 - Math.random() * 1000, FLOOR, -600, true );
+
+				} } );
+
+				/*
+				loader.load( { model: "obj/morphs/fox.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.2, 1000, 100 - Math.random() * 500, FLOOR - 5, 600 );
+
+				} } );
+
+				loader.load( { model: "obj/morphs/shdw3walk.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.04, 2000, -500, FLOOR + 60, 245 );
+
+				} } );
+
+				loader.load( { model: "obj/morphs/flamingo.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.5, 1000, 500 - Math.random() * 500, FLOOR + 350, 40 );
+
+				} } );
+
+				loader.load( { model: "obj/morphs/stork.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.35, 1000, 500 - Math.random() * 500, FLOOR + 350, 340 );
+
+				} } );
+
+				loader.load( { model: "obj/morphs/mountainlion.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.4, 1000, 500 - Math.random() * 500, FLOOR - 5, 700 );
+
+				} } );
+
+				loader.load( { model: "obj/morphs/bearBrown.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.3, 2500, -500, FLOOR - 5, -750 );
+
+				} } );
+
+				loader.load( { model: "obj/morphs/parrot.js", callback: function( geometry ) {
+
+					morphColorsToFaceColors( geometry );
+					addMorph( geometry, 0.45, 500, 500 - Math.random() * 500, FLOOR + 300, 700 );
+
+				} } );
+
+				*/
+
+			}
+
+
+			var t = 0, newTime, delta;
+
+
+			function updateMorph( morph ) {
+
+				// Alternate morph targets
+
+				var interpolation = morph.duration / ( morph.mesh.geometry.morphTargets.length - 1 );
+
+				var time = ( new Date().getTime()  + morph.offset * 100 ) % morph.duration;
+				var keyframe = Math.floor( time / interpolation ) + 1;
+
+				var mesh = morph.mesh;
+
+				if ( keyframe != morph.currentKeyframe ) {
+
+					mesh.morphTargetInfluences[ morph.lastKeyframe ] = 0;
+					mesh.morphTargetInfluences[ morph.currentKeyframe ] = 1;
+					mesh.morphTargetInfluences[ keyframe ] = 0;
+
+					morph.lastKeyframe = morph.currentKeyframe;
+					morph.currentKeyframe = keyframe;
+
+				}
+
+				mesh.morphTargetInfluences[ keyframe ] = ( time % interpolation ) / interpolation;
+				mesh.morphTargetInfluences[ morph.lastKeyframe ] = 1 - mesh.morphTargetInfluences[ keyframe ];
+
+				var newTime = new Date().getTime();
+				delta = newTime - morph.oldTime;
+				morph.oldTime = newTime;
+
+				mesh.position.x += morph.speed * delta;
+
+				if ( mesh.position.x  > 2000 )  {
+
+					mesh.position.x = -1000 - Math.random() * 500;
+
+				}
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			function render() {
+
+				for ( var i = 0; i < morphs.length; i++ ) updateMorph( morphs[ i ] );
+
+				renderer.clear();
+				renderer.render( scene, camera );
+
+				// Render debug HUD with shadow map
+
+				//hudMaterial.uniforms.tDiffuse.texture = renderer.shadowMap[ 0 ];
+				//renderer.render( sceneHUD, cameraOrtho );
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 0 - 178
examples/webgl_stencil.html

@@ -1,178 +0,0 @@
-<!DOCTYPE HTML>
-<html lang="en">
-	<head>
-		<title>three.js webgl - stencil shadow</title>
-		<meta charset="utf-8">
-		<style type="text/css">
-			body {
-				background:#fff;
-				padding:0;
-				margin:0;
-				font-weight: bold;
-				overflow:hidden;
-			}
-		</style>
-	</head>
-
-	<body>
-		<script type="text/javascript" src="../build/Three.js"></script>
-		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
-		<script type="text/javascript" src="js/Stats.js"></script>
-
-
-		<script type="text/javascript">
-
-			var container, stats;
-
-			var camera, scene, renderer;
-
-			var mesh, boxMesh, light, lightCube, light2, lightCube2, zmesh, lightMesh, geometry;
-
-			var mouseX = 0, mouseY = 0;
-
-			var windowHalfX = window.innerWidth / 2;
-			var windowHalfY = window.innerHeight / 2;
-
-			document.addEventListener( 'mousemove', onDocumentMouseMove, false );
-
-			init();
-			animate();
-
-			function init() {
-
-				container = document.createElement( 'div' );
-				document.body.appendChild( container );
-
-				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
-				camera.position.z = 250;
-
-				scene = new THREE.Scene();
-
-
-				// world
-
-				var cube = new THREE.CubeGeometry( 300, 300, 10 );
-				var material0 = new THREE.MeshPhongMaterial( { color:0xff00ff } );
-				var material1 = new THREE.MeshLambertMaterial( { color:0x00ff00 } );
-				var material2 = new THREE.MeshLambertMaterial( { color:0x0000ff } );
-
-				var mesh1 = new THREE.Mesh( cube, material0 );
-				mesh1.position.z = - 150;
-				scene.addChild( mesh1 );
-
-				var mesh2 = new THREE.Mesh( cube, material1 );
-				mesh2.position.x = - 150;
-				mesh2.rotation.y = 90 * Math.PI / 180;
-				scene.addChild( mesh2 );
-
-				var mesh3 = new THREE.Mesh( cube, material2 );
-				mesh3.position.y = - 150;
-				mesh3.rotation.x = 90 * Math.PI / 180;
-				scene.addChild( mesh3 );
-
-				new THREE.ShadowVolume( mesh1 )
-				new THREE.ShadowVolume( mesh2 )
-				new THREE.ShadowVolume( mesh3 )
-
-
-				// moving objects
-
-				var cube = new THREE.CubeGeometry( 40, 40, 40 );
-				var torus = new THREE.TorusGeometry( 40, 10 );
-				var sphere = new THREE.SphereGeometry( 40 );
-				var cylinder = new THREE.CylinderGeometry( 10, 10, 20, 40, 0, 0 );
-				mesh = new THREE.Mesh( torus, material1 );
-				scene.addChild( mesh );
-
-				boxMesh = new THREE.Mesh( cube, material2 );
-				scene.addChild( boxMesh );
-
-				new THREE.ShadowVolume( mesh );
-				new THREE.ShadowVolume( boxMesh );
-
-
-				// lights
-
-				light = new THREE.DirectionalLight( 0xffffff );
-				light.castShadow = true;
-				light.position.set( 0, 1, 0 );
-				scene.addChild( light );
-
-				var cube = new THREE.SphereGeometry( 5 );
-				lightCube = new THREE.Mesh( cube, material2 );
-				scene.addChild( lightCube );
-
-
-				// renderer
-
-				renderer = new THREE.WebGLRenderer();
-				renderer.setClearColorHex( 0xaaaaaa, 1 );
-				renderer.setSize( window.innerWidth, window.innerHeight );
-				container.appendChild( renderer.domElement );
-
-				stats = new Stats();
-				stats.domElement.style.position = 'absolute';
-				stats.domElement.style.top = '0px';
-				stats.domElement.style.zIndex = 100;
-				container.appendChild( stats.domElement );
-
-			}
-
-
-			function onDocumentMouseMove(event) {
-
-				mouseX = ( event.clientX - windowHalfX );
-				mouseY = ( event.clientY - windowHalfY );
-
-			}
-
-			function animate() {
-
-				requestAnimationFrame( animate );
-
-				render();
-				stats.update();
-
-			}
-
-			var t = 0;
-
-			function render() {
-
-				mesh.position.x = Math.sin( t ) * 100;
-				mesh.position.y = Math.cos( t ) * 100;
-
-				mesh.rotation.x += 0.5 * Math.PI / 180;
-				mesh.rotation.y += 1.0 * Math.PI / 180;
-				mesh.rotation.z += 1.5 * Math.PI / 180;
-
-				boxMesh.position.z = Math.sin( t ) * 100;
-				boxMesh.rotation.x = Math.sin( t ) * 180 * Math.PI / 180;
-
-				light.position.x = Math.sin( t );
-				light.position.y = 1.5;
-				light.position.z = Math.cos( t );
-
-				lightCube.position.copy( light.position );
-				lightCube.position.multiplyScalar( 200 );
-
-
-				t += 0.02;
-
-				camera.position.x += ( mouseX - camera.position.x ) * .05;
-				camera.position.y += ( - mouseY - camera.position.y ) * .05;
-
-				renderer.render( scene, camera );
-
-			}
-
-			function log( text ) {
-
-				var e = document.getElementById("log");
-				e.innerHTML = text + "<br/>" + e.innerHTML;
-
-			}
-		</script>
-
-	</body>
-</html>

+ 0 - 190
examples/webgl_stencilLensFlare.html

@@ -1,190 +0,0 @@
-<!DOCTYPE HTML>
-<html lang="en">
-	<head>
-		<title>three.js - webgl</title>
-		<meta charset="utf-8">
-		<style type="text/css">
-			body {
-				background:#fff;
-				padding:0;
-				margin:0;
-				font-weight: bold;
-				overflow:hidden;
-			}
-		</style>
-	</head>
-
-	<body>
-		<script type="text/javascript" src="../build/Three.js"></script>
-		<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
-		<script type="text/javascript" src="js/Stats.js"></script>
-
-		<script type="text/javascript">
-
-			var container, stats;
-
-			var camera, scene, renderer;
-
-			var mesh, boxMesh, light, lightCube, light2, lightCube2, zmesh, lightMesh, geometry;
-
-			var mouseX = 0, mouseY = 0;
-
-			var windowHalfX = window.innerWidth / 2;
-			var windowHalfY = window.innerHeight / 2;
-
-			document.addEventListener( 'mousemove', onDocumentMouseMove, false );
-
-			init();
-			animate();
-
-			function init() {
-
-				container = document.createElement( 'div' );
-				document.body.appendChild( container );
-
-				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
-				camera.position.z = 250;
-
-				scene = new THREE.Scene();
-
-
-				// world
-
-				var cube = new THREE.CubeGeometry( 300, 300, 10 );
-				var material0 = new THREE.MeshPhongMaterial( { color:0xff00ff } );
-				var material1 = new THREE.MeshLambertMaterial( { color:0x00ff00 } );
-				var material2 = new THREE.MeshLambertMaterial( { color:0x0000ff } );
-
-				var mesh1 = new THREE.Mesh( cube, material0 );
-				mesh1.position.z = -150;
-				scene.addChild( mesh1 );
-
-				var mesh2 = new THREE.Mesh( cube, material1 );
-				mesh2.position.x = -150;
-				mesh2.rotation.y = 90 * Math.PI / 180;
-				scene.addChild( mesh2 );
-
-				var mesh3 = new THREE.Mesh( cube, material2 );
-				mesh3.position.y = -150;
-				mesh3.rotation.x = 90 * Math.PI / 180;
-				scene.addChild( mesh3 );
-
-				new THREE.ShadowVolume( mesh1 )
-				new THREE.ShadowVolume( mesh2 )
-				new THREE.ShadowVolume( mesh3 )
-
-
-				// moving objects
-
-				var cube = new THREE.CubeGeometry( 40, 40, 40 );
-				var torus = new THREE.TorusGeometry( 40, 10 );
-				var sphere = new THREE.SphereGeometry( 40 );
-				var cylinder = new THREE.CylinderGeometry( 10, 10, 20, 40, 0, 0 );
-				mesh = new THREE.Mesh( torus, material1 );
-				scene.addChild( mesh );
-
-				boxMesh = new THREE.Mesh( cube, material2 );
-				scene.addChild( boxMesh );
-
-				new THREE.ShadowVolume( mesh );
-				new THREE.ShadowVolume( boxMesh );
-
-
-				// lights
-
-				light = new THREE.PointLight( 0xffffff );
-				scene.addChild( light );
-
-
-				light = new THREE.DirectionalLight( 0xffffff );
-				light.castShadow = true;
-				light.position.set( 0, 1, 0 );
-				scene.addChild( light );
-
-
-				var cube = new THREE.SphereGeometry( 2 );
-				lightCube = new THREE.Mesh( cube, material2 );
-				lightCube.visible = false;
-				scene.addChild( lightCube );
-
-				var lensFlare = new THREE.LensFlare( THREE.ImageUtils.loadTexture( "textures/lensflare0.png" ), 128, 0.0, THREE.AdditiveBlending );
-				lensFlare.add( THREE.ImageUtils.loadTexture( "textures/lensflare1.png" ), 256, 0.33, THREE.AdditiveBlending );
-				lensFlare.add( lensFlare.lensFlares[ 1 ].texture, 300, 0.66, THREE.AdditiveBlending );
-				lensFlare.add( lensFlare.lensFlares[ 1 ].texture, 400, 1.0, THREE.AdditiveBlending );
-
-				lightCube.addChild( lensFlare );
-
-
-				// renderer
-
-				renderer = new THREE.WebGLRenderer( { antialias: false } );
-				renderer.setClearColorHex( 0x222222, 1 );
-				renderer.setSize( window.innerWidth, window.innerHeight );
-				container.appendChild( renderer.domElement );
-
-				stats = new Stats();
-				stats.domElement.style.position = 'absolute';
-				stats.domElement.style.top = '0px';
-				stats.domElement.style.zIndex = 100;
-				container.appendChild( stats.domElement );
-
-			}
-
-
-			function onDocumentMouseMove(event) {
-
-				mouseX = ( event.clientX - windowHalfX );
-				mouseY = ( event.clientY - windowHalfY );
-
-			}
-
-			function animate() {
-
-				requestAnimationFrame( animate );
-
-				render();
-				stats.update();
-
-			}
-
-			var t = 0;
-
-			function render() {
-
-				mesh.position.x = Math.sin( t ) * 100;
-				mesh.position.y = Math.cos( t ) * 100;
-
-				mesh.rotation.x += 0.5 * Math.PI / 180;
-				mesh.rotation.y += 1.0 * Math.PI / 180;
-				mesh.rotation.z += 1.5 * Math.PI / 180;
-
-				boxMesh.position.z = Math.sin( t ) * 100;
-				boxMesh.rotation.x = Math.sin( t ) * 180 * Math.PI / 180;
-
-				light.position.x = Math.sin( t );
-				light.position.y = 0.5;
-				light.position.normalize();
-
-				lightCube.position.copy( light.position );
-				lightCube.position.multiplyScalar( 200 );
-
-
-				t += 0.015;
-
-				camera.position.x += ( mouseX - camera.position.x ) * .05;
-				camera.position.y += ( - mouseY - camera.position.y ) * .05;
-
-				renderer.render( scene, camera );
-
-			}
-
-			function log( text ) {
-
-				var e = document.getElementById("log");
-				e.innerHTML = text + "<br/>" + e.innerHTML;
-
-			}
-		</script>
-
-	</body>
-</html>

+ 174 - 0
examples/webgl_utf8loader.html

@@ -0,0 +1,174 @@
+<!DOCTYPE HTML>
+<html lang="en">
+	<head>
+		<title>three.js webgl - io - UTF8 loader</title>
+		<meta charset="utf-8">
+		<style type="text/css">
+			body {
+				font-family: Monospace;
+				background-color: #000;
+				color: #fff;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				color: #fff;
+				position: absolute;
+				top: 10px;
+				width: 100%;
+				text-align: center;
+				z-index: 100;
+				display:block;
+			}
+			#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
+		</style>
+	</head>
+
+	<body>
+		<div id="info">
+		<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> -
+		<a href="http://code.google.com/p/webgl-loader/" target="_blank">UTF8 format</a> loader test -
+		models from <a href="http://www.sci.utah.edu/~wald/animrep/" target="_blank">The Utah 3D Animation Repository</a>
+		</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>
+
+		<script type="text/javascript">
+
+			var SCREEN_WIDTH = window.innerWidth;
+			var SCREEN_HEIGHT = window.innerHeight;
+
+			var NEAR = 1;
+			var FAR = 2000;
+
+			var FLOOR = -150;
+
+			var container, stats;
+
+			var camera, scene, renderer;
+
+			var mesh, zmesh, geometry;
+
+			var mouseX = 0, mouseY = 0;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+			document.addEventListener('mousemove', onDocumentMouseMove, false);
+
+			init();
+			animate();
+
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				camera = new THREE.Camera( 20, SCREEN_WIDTH / SCREEN_HEIGHT, NEAR, FAR );
+				camera.position.z = 800;
+				camera.updateMatrix();
+
+				scene = new THREE.Scene();
+				scene.fog = new THREE.Fog( 0x000000, 800, FAR );
+
+
+				var path = "textures/cube/SwedishRoyalCastle/";
+				var format = '.jpg';
+				var urls = [
+						path + 'px' + format, path + 'nx' + format,
+						path + 'py' + format, path + 'ny' + format,
+						path + 'pz' + format, path + 'nz' + format
+					];
+
+				reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
+
+				// LIGHTS
+
+				var ambient = new THREE.AmbientLight( 0x221100 );
+				scene.addLight( ambient );
+
+				var directionalLight = new THREE.DirectionalLight( 0xffeedd );
+				directionalLight.position.set( 0, 0, 1 );
+				directionalLight.position.normalize();
+				scene.addLight( directionalLight );
+
+				// RENDERER
+
+				renderer = new THREE.WebGLRenderer();
+				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
+
+				renderer.setClearColor( scene.fog.color, 1 );
+
+				renderer.domElement.style.position = "relative";
+				container.appendChild( renderer.domElement );
+
+				// STATS
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				stats.domElement.style.zIndex = 100;
+				container.appendChild( stats.domElement );
+
+				var loader = new THREE.UTF8Loader();
+
+				loader.load( { model: "utf8/hand.utf8",
+								scale: 0.815141, offsetX: -0.371823, offsetY: -0.011920, offsetZ: -0.416061,
+								callback: function( geometry ) { callbackModel( geometry, 400, 0xffffff, 125, FLOOR, 0 ); } } );
+
+				loader.load( { model: "utf8/ben.utf8",
+								scale: 0.707192, offsetX: -0.109362, offsetY: -0.006435, offsetZ: -0.268751,
+								callback: function( geometry ) { callbackModel( geometry, 400, 0xffaa00, -125, FLOOR, 0 ); } } );
+
+			}
+
+			function callbackModel( geometry, s, color, x, y, z ) {
+
+				var material = new THREE.MeshLambertMaterial( { color: color, map: THREE.ImageUtils.loadTexture( "textures/UV.jpg" ), envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.3 } );
+				//material.shading =  THREE.FlatShading;
+
+				var mesh = new THREE.Mesh( geometry, material );
+
+				mesh.position.set( x, y, z );
+				mesh.scale.set( s, s, s );
+
+				scene.addObject( mesh );
+
+			}
+
+			function onDocumentMouseMove( event ) {
+
+				mouseX = ( event.clientX - windowHalfX );
+				mouseY = ( event.clientY - windowHalfY );
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			function render() {
+
+				camera.position.x += ( mouseX - camera.position.x ) * .05;
+				camera.position.y += ( - mouseY - camera.position.y ) * .05;
+
+				renderer.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 39 - 30
src/core/Color.js

@@ -4,48 +4,47 @@
 
 THREE.Color = function ( hex ) {
 
-	this.setHex( hex );
+	if ( hex !== undefined ) this.setHex( hex );
+	return this;
 
 };
 
 THREE.Color.prototype = {
 
-	copy : function ( color ) {
+	constructor: THREE.Color,
+	
+	r: 1, g: 1, b: 1,
+
+	copy: function ( color ) {
 
 		this.r = color.r;
 		this.g = color.g;
 		this.b = color.b;
-		this.hex = color.hex;
-
-	},
 
-	setHex : function ( hex ) {
-
-		this.hex = ( ~~ hex ) & 0xffffff;
-		this.updateRGB();
+		return this;
 
 	},
 
-	setRGB : function ( r, g, b ) {
+	setRGB: function ( r, g, b ) {
 
 		this.r = r;
 		this.g = g;
 		this.b = b;
 
-		this.updateHex();
+		return this;
 
 	},
 
-	setHSV : function ( h, s, v ) {
+	setHSV: function ( h, s, v ) {
 
 		// based on MochiKit implementation by Bob Ippolito
 		// h,s,v ranges are < 0.0 - 1.0 >
 
-		var r, g, b, i, f, p, q, t;
+		var i, f, p, q, t;
 
-		if ( v == 0.0 ) {
+		if ( v == 0 ) {
 
-			r = g = b = 0;
+			this.r = this.g = this.b = 0;
 
 		} else {
 
@@ -57,39 +56,49 @@ THREE.Color.prototype = {
 
 			switch ( i ) {
 
-				case 1: r = q; g = v; b = p; break;
-				case 2: r = p; g = v; b = t; break;
-				case 3: r = p; g = q; b = v; break;
-				case 4: r = t; g = p; b = v; break;
-				case 5: r = v; g = p; b = q; break;
+				case 1: this.r = q; this.g = v; this.b = p; break;
+				case 2: this.r = p; this.g = v; this.b = t; break;
+				case 3: this.r = p; this.g = q; this.b = v; break;
+				case 4: this.r = t; this.g = p; this.b = v; break;
+				case 5: this.r = v; this.g = p; this.b = q; break;
 				case 6: // fall through
-				case 0: r = v; g = t; b = p; break;
+				case 0: this.r = v; this.g = t; this.b = p; break;
 
 			}
 
 		}
 
-		this.setRGB( r, g, b );
+		return this;
+
+	},
+
+	setHex: function ( hex ) {
+
+		hex = Math.floor( hex );
+
+		this.r = ( hex >> 16 & 255 ) / 255;
+		this.g = ( hex >> 8 & 255 ) / 255;
+		this.b = ( hex & 255 ) / 255;
+
+		return this;
 
 	},
 
-	updateHex : function () {
+	getHex: function () {
 
-		this.hex = ~~ ( this.r * 255 ) << 16 ^ ~~ ( this.g * 255 ) << 8 ^ ~~ ( this.b * 255 );
+		return ~~ ( this.r * 255 ) << 16 ^ ~~ ( this.g * 255 ) << 8 ^ ~~ ( this.b * 255 );
 
 	},
 
-	updateRGB : function () {
+	getContextStyle: function () {
 
-		this.r = ( this.hex >> 16 & 255 ) / 255;
-		this.g = ( this.hex >> 8 & 255 ) / 255;
-		this.b = ( this.hex & 255 ) / 255;
+		return 'rgb(' + Math.floor( this.r * 255 ) + ',' + Math.floor( this.g * 255 ) + ',' + Math.floor( this.b * 255 ) + ')';
 
 	},
 
-	clone : function () {
+	clone: function () {
 
-		return new THREE.Color( this.hex );
+		return new THREE.Color().setRGB( this.r, this.g, this.b );
 
 	}
 

+ 4 - 0
src/core/Geometry.js

@@ -30,10 +30,14 @@ THREE.Geometry = function () {
 
 	this.hasTangents = false;
 
+	this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer.
+
 };
 
 THREE.Geometry.prototype = {
 
+	constructor : THREE.Geometry,
+
 	computeCentroids: function () {
 
 		var f, fl, face;

+ 4 - 2
src/core/Matrix3.js

@@ -6,7 +6,9 @@ THREE.Matrix3 = function () {
 
 THREE.Matrix3.prototype = {
 
-	transpose : function () {
+	constructor: THREE.Matrix3,
+
+	transpose: function () {
 
 		var tmp, m = this.m;
 
@@ -18,7 +20,7 @@ THREE.Matrix3.prototype = {
 
 	},
 
-	transposeIntoArray : function ( r ) {
+	transposeIntoArray: function ( r ) {
 
 		var m = this.m;
 

+ 35 - 25
src/core/Matrix4.js

@@ -26,7 +26,9 @@ THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33
 
 THREE.Matrix4.prototype = {
 
-	set : function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
+	constructor: THREE.Matrix4,
+
+	set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
 
 		this.n11 = n11; this.n12 = n12; this.n13 = n13; this.n14 = n14;
 		this.n21 = n21; this.n22 = n22; this.n23 = n23; this.n24 = n24;
@@ -37,7 +39,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	identity : function () {
+	identity: function () {
 
 		this.set(
 
@@ -52,7 +54,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	copy : function ( m ) {
+	copy: function ( m ) {
 
 		this.set(
 
@@ -67,7 +69,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	lookAt : function ( eye, center, up ) {
+	lookAt: function ( eye, center, up ) {
 
 		var x = THREE.Matrix4.__v1, y = THREE.Matrix4.__v2, z = THREE.Matrix4.__v3;
 
@@ -99,7 +101,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplyVector3 : function ( v ) {
+	multiplyVector3: function ( v ) {
 
 		var vx = v.x, vy = v.y, vz = v.z,
 		d = 1 / ( this.n41 * vx + this.n42 * vy + this.n43 * vz + this.n44 );
@@ -112,7 +114,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplyVector4 : function ( v ) {
+	multiplyVector4: function ( v ) {
 
 		var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
 
@@ -125,7 +127,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	rotateAxis : function ( v ) {
+	rotateAxis: function ( v ) {
 
 		var vx = v.x, vy = v.y, vz = v.z;
 
@@ -139,7 +141,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	crossVector : function ( a ) {
+	crossVector: function ( a ) {
 
 		var v = new THREE.Vector4();
 
@@ -153,7 +155,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiply : function ( a, b ) {
+	multiply: function ( a, b ) {
 
 		var a11 = a.n11, a12 = a.n12, a13 = a.n13, a14 = a.n14,
 		a21 = a.n21, a22 = a.n22, a23 = a.n23, a24 = a.n24,
@@ -189,7 +191,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplyToArray : function ( a, b, r ) {
+	multiplyToArray: function ( a, b, r ) {
 
 		this.multiply( a, b );
 
@@ -202,7 +204,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplySelf : function ( m ) {
+	multiplySelf: function ( m ) {
 
 		this.multiply( this, m );
 
@@ -210,7 +212,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	multiplyScalar : function ( s ) {
+	multiplyScalar: function ( s ) {
 
 		this.n11 *= s; this.n12 *= s; this.n13 *= s; this.n14 *= s;
 		this.n21 *= s; this.n22 *= s; this.n23 *= s; this.n24 *= s;
@@ -221,7 +223,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	determinant : function () {
+	determinant: function () {
 
 		var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14,
 		n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24,
@@ -264,7 +266,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	transpose : function () {
+	transpose: function () {
 
 		var tmp;
 
@@ -280,7 +282,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	clone : function () {
+	clone: function () {
 
 		var m = new THREE.Matrix4();
 
@@ -293,7 +295,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	flatten : function () {
+	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;
@@ -304,7 +306,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	flattenToArray : function ( flat ) {
+	flattenToArray: function ( flat ) {
 
 		flat[ 0 ] = this.n11; flat[ 1 ] = this.n21; flat[ 2 ] = this.n31; flat[ 3 ] = this.n41;
 		flat[ 4 ] = this.n12; flat[ 5 ] = this.n22; flat[ 6 ] = this.n32; flat[ 7 ] = this.n42;
@@ -315,7 +317,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	flattenToArrayOffset : function( flat, offset ) {
+	flattenToArrayOffset: function( flat, offset ) {
 
 		flat[ offset ] = this.n11;
 		flat[ offset + 1 ] = this.n21;
@@ -341,7 +343,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setTranslation : function( x, y, z ) {
+	setTranslation: function( x, y, z ) {
 
 		this.set(
 
@@ -356,7 +358,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setScale : function ( x, y, z ) {
+	setScale: function ( x, y, z ) {
 
 		this.set(
 
@@ -371,7 +373,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setRotationX : function ( theta ) {
+	setRotationX: function ( theta ) {
 
 		var c = Math.cos( theta ), s = Math.sin( theta );
 
@@ -388,7 +390,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setRotationY : function( theta ) {
+	setRotationY: function( theta ) {
 
 		var c = Math.cos( theta ), s = Math.sin( theta );
 
@@ -405,7 +407,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setRotationZ : function( theta ) {
+	setRotationZ: function( theta ) {
 
 		var c = Math.cos( theta ), s = Math.sin( theta );
 
@@ -422,7 +424,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setRotationAxis : function( axis, angle ) {
+	setRotationAxis: function( axis, angle ) {
 
 		// Based on http://www.gamedev.net/reference/articles/article1199.asp
 
@@ -445,7 +447,7 @@ THREE.Matrix4.prototype = {
 
 	},
 
-	setPosition : function( v ) {
+	setPosition: function( v ) {
 
 		this.n14 = v.x;
 		this.n24 = v.y;
@@ -518,7 +520,9 @@ THREE.Matrix4.prototype = {
 		e = Math.cos( z ), f = Math.sin( z );
 
 		switch ( order ) {
+
 			case 'YXZ':
+
 				var ce = c * e, cf = c * f, de = d * e, df = d * f;
 
 				this.n11 = ce + df * b;
@@ -535,6 +539,7 @@ THREE.Matrix4.prototype = {
 				break;
 
 			case 'ZXY':
+
 				var ce = c * e, cf = c * f, de = d * e, df = d * f;
 
 				this.n11 = ce - df * b;
@@ -551,6 +556,7 @@ THREE.Matrix4.prototype = {
 				break;
 
 			case 'ZYX':
+
 				var ae = a * e, af = a * f, be = b * e, bf = b * f;
 
 				this.n11 = c * e;
@@ -567,6 +573,7 @@ THREE.Matrix4.prototype = {
 				break;
 
 			case 'YZX':
+
 				var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
 
 				this.n11 = c * e;
@@ -583,6 +590,7 @@ THREE.Matrix4.prototype = {
 				break;
 
 			case 'XZY':
+
 				var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
 
 				this.n11 = c * e;
@@ -599,6 +607,7 @@ THREE.Matrix4.prototype = {
 				break;
 
 			default: // 'XYZ'
+
 				var ae = a * e, af = a * f, be = b * e, bf = b * f;
 
 				this.n11 = c * e;
@@ -613,6 +622,7 @@ THREE.Matrix4.prototype = {
 				this.n32 = be + af * d;
 				this.n33 = a * c;
 				break;
+
 		}
 
 		return this;

+ 11 - 6
src/core/Object3D.js

@@ -17,7 +17,7 @@ THREE.Object3D = function() {
 	this.scale = new THREE.Vector3( 1, 1, 1 );
 
 	this.dynamic = false; // when true it retains arrays so they can be updated with __dirty*
-	
+
 	this.doubleSided = false;
 	this.flipSided = false;
 
@@ -40,6 +40,9 @@ THREE.Object3D = function() {
 
 	this.visible = true;
 
+	this.castShadow = false;
+	this.receiveShadow = false;
+
 	this._vector = new THREE.Vector3();
 
 	this.name = "";
@@ -49,32 +52,34 @@ THREE.Object3D = function() {
 
 THREE.Object3D.prototype = {
 
-	translate : function ( distance, axis ) {
+	constructor: THREE.Object3D,
+
+	translate: function ( distance, axis ) {
 
 		this.matrix.rotateAxis( axis );
 		this.position.addSelf( axis.multiplyScalar( distance ) );
 
 	},
 
-	translateX : function ( distance ) {
+	translateX: function ( distance ) {
 
 		this.translate( distance, this._vector.set( 1, 0, 0 ) );
 
 	},
 
-	translateY : function ( distance ) {
+	translateY: function ( distance ) {
 
 		this.translate( distance, this._vector.set( 0, 1, 0 ) );
 
 	},
 
-	translateZ : function ( distance ) {
+	translateZ: function ( distance ) {
 
 		this.translate( distance, this._vector.set( 0, 0, 1 ) );
 
 	},
 
-	lookAt : function ( vector ) {
+	lookAt: function ( vector ) {
 
 		// TODO: Add hierarchy support.
 

+ 11 - 9
src/core/Quaternion.js

@@ -18,7 +18,9 @@ THREE.Quaternion = function( x, y, z, w ) {
 
 THREE.Quaternion.prototype = {
 
-	set : function ( x, y, z, w ) {
+	constructor: THREE.Quaternion,
+
+	set: function ( x, y, z, w ) {
 
 		this.x = x;
 		this.y = y;
@@ -29,7 +31,7 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	copy : function ( q ) {
+	copy: function ( q ) {
 
 		this.x = q.x;
 		this.y = q.y;
@@ -40,7 +42,7 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	setFromEuler : function ( vec3 ) {
+	setFromEuler: function ( vec3 ) {
 
 		var c = 0.5 * Math.PI / 360, // 0.5 is an optimization
 		x = vec3.x * c,
@@ -83,7 +85,7 @@ THREE.Quaternion.prototype = {
 
 	},
 	
-	calculateW  : function () {
+	calculateW : function () {
 
 		this.w = - Math.sqrt( Math.abs( 1.0 - this.x * this.x - this.y * this.y - this.z * this.z ) );
 
@@ -91,7 +93,7 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	inverse : function () {
+	inverse: function () {
 
 		this.x *= -1;
 		this.y *= -1;
@@ -101,13 +103,13 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	length : function () {
+	length: function () {
 
 		return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
 
 	},
 
-	normalize : function () {
+	normalize: function () {
 
 		var l = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
 
@@ -133,7 +135,7 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	multiplySelf : function ( quat2 ) {
+	multiplySelf: function ( quat2 ) {
 
 		var qax = this.x,  qay = this.y,  qaz = this.z,  qaw = this.w,
 		qbx = quat2.x, qby = quat2.y, qbz = quat2.z, qbw = quat2.w;
@@ -160,7 +162,7 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	multiplyVector3 : function ( vec, dest ) {
+	multiplyVector3: function ( vec, dest ) {
 
 		if( !dest ) { dest = vec; }
 

+ 2 - 0
src/core/Ray.js

@@ -11,6 +11,8 @@ THREE.Ray = function ( origin, direction ) {
 
 THREE.Ray.prototype = {
 
+	constructor: THREE.Ray,
+
 	intersectScene: function ( scene ) {
 
 		return this.intersectObjects( scene.objects );

+ 4 - 2
src/core/UV.js

@@ -15,7 +15,9 @@ THREE.UV = function ( u, v ) {
 
 THREE.UV.prototype = {
 
-	set : function ( u, v ) {
+	constructor: THREE.UV,
+
+	set: function ( u, v ) {
 
 		this.u = u;
 		this.v = v;
@@ -24,7 +26,7 @@ THREE.UV.prototype = {
 
 	},
 
-	copy : function ( uv ) {
+	copy: function ( uv ) {
 
 		this.set(
 

+ 21 - 19
src/core/Vector2.js

@@ -18,7 +18,9 @@ THREE.Vector2 = function ( x, y ) {
 
 THREE.Vector2.prototype = {
 
-	set : function ( x, y ) {
+	constructor: THREE.Vector2,
+
+	set: function ( x, y ) {
 
 		this.x = x;
 		this.y = y;
@@ -27,7 +29,7 @@ THREE.Vector2.prototype = {
 
 	},
 
-	copy : function ( v ) {
+	copy: function ( v ) {
 
 		this.x = v.x;
 		this.y = v.y;
@@ -36,14 +38,14 @@ THREE.Vector2.prototype = {
 
 	},
 
-	clone : function () {
+	clone: function () {
 
 		return new THREE.Vector2( this.x, this.y );
 
 	},
 
 
-	add : function ( v1, v2 ) {
+	add: function ( v1, v2 ) {
 
 		this.x = v1.x + v2.x;
 		this.y = v1.y + v2.y;
@@ -52,7 +54,7 @@ THREE.Vector2.prototype = {
 
 	},
 
-	addSelf : function ( v ) {
+	addSelf: function ( v ) {
 
 		this.x += v.x;
 		this.y += v.y;
@@ -61,7 +63,7 @@ THREE.Vector2.prototype = {
 
 	},
 
-	sub : function ( v1, v2 ) {
+	sub: function ( v1, v2 ) {
 
 		this.x = v1.x - v2.x;
 		this.y = v1.y - v2.y;
@@ -70,7 +72,7 @@ THREE.Vector2.prototype = {
 
 	},
 
-	subSelf : function ( v ) {
+	subSelf: function ( v ) {
 
 		this.x -= v.x;
 		this.y -= v.y;
@@ -79,7 +81,7 @@ THREE.Vector2.prototype = {
 
 	},
 
-	multiplyScalar : function ( s ) {
+	multiplyScalar: function ( s ) {
 
 		this.x *= s;
 		this.y *= s;
@@ -88,7 +90,7 @@ THREE.Vector2.prototype = {
 
 	},
 
-	divideScalar : function ( s ) {
+	divideScalar: function ( s ) {
 
 		if ( s ) {
 
@@ -106,43 +108,43 @@ THREE.Vector2.prototype = {
 	},
 
 
-	negate : function() {
+	negate: function() {
 
 		return this.multiplyScalar( -1 );
 
 	},
 
-	dot : function ( v ) {
+	dot: function ( v ) {
 
 		return this.x * v.x + this.y * v.y;
 
 	},
 
-	lengthSq : function () {
+	lengthSq: function () {
 
 		return this.x * this.x + this.y * this.y;
 
 	},
 
-	length : function () {
+	length: function () {
 
 		return Math.sqrt( this.lengthSq() );
 
 	},
 
-	normalize : function () {
+	normalize: function () {
 
 		return this.divideScalar( this.length() );
 
 	},
 	
-	distanceTo : function ( v ) {
+	distanceTo: function ( v ) {
 
 		return Math.sqrt( this.distanceToSquared( v ) );
 
 	},
 
-	distanceToSquared : function ( v ) {
+	distanceToSquared: function ( v ) {
 
 		var dx = this.x - v.x, dy = this.y - v.y;
 		return dx * dx + dy * dy;
@@ -150,7 +152,7 @@ THREE.Vector2.prototype = {
 	},
 
 
-	setLength : function ( l ) {
+	setLength: function ( l ) {
 
 		return this.normalize().multiplyScalar( l );
 
@@ -158,7 +160,7 @@ THREE.Vector2.prototype = {
 
 	// deprecated: same as normalize
 
-	unit : function () {
+	unit: function () {
 
 		return this.normalize();
 
@@ -168,7 +170,7 @@ THREE.Vector2.prototype = {
 	// (which may be not what is expected thanks to floating point precision)
 	// (should be probably using some tiny epsilon instead of equality)
 	
-	equals : function( v ) {
+	equals: function( v ) {
 
 		return ( ( v.x == this.x ) && ( v.y == this.y ) );
 

+ 29 - 27
src/core/Vector3.js

@@ -21,7 +21,9 @@ THREE.Vector3 = function ( x, y, z ) {
 
 THREE.Vector3.prototype = {
 
-	set : function ( x, y, z ) {
+	constructor: THREE.Vector3,
+
+	set: function ( x, y, z ) {
 
 		this.x = x;
 		this.y = y;
@@ -31,7 +33,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	copy : function ( v ) {
+	copy: function ( v ) {
 
 		this.x = v.x;
 		this.y = v.y;
@@ -41,14 +43,14 @@ THREE.Vector3.prototype = {
 
 	},
 
-	clone : function () {
+	clone: function () {
 
 		return new THREE.Vector3( this.x, this.y, this.z );
 
 	},
 
 
-	add : function ( v1, v2 ) {
+	add: function ( v1, v2 ) {
 
 		this.x = v1.x + v2.x;
 		this.y = v1.y + v2.y;
@@ -58,7 +60,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	addSelf : function ( v ) {
+	addSelf: function ( v ) {
 
 		this.x += v.x;
 		this.y += v.y;
@@ -68,7 +70,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	addScalar : function ( s ) {
+	addScalar: function ( s ) {
 
 		this.x += s;
 		this.y += s;
@@ -78,7 +80,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	sub : function ( v1, v2 ) {
+	sub: function ( v1, v2 ) {
 
 		this.x = v1.x - v2.x;
 		this.y = v1.y - v2.y;
@@ -88,7 +90,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	subSelf : function ( v ) {
+	subSelf: function ( v ) {
 
 		this.x -= v.x;
 		this.y -= v.y;
@@ -98,7 +100,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	multiply : function ( a, b ) {
+	multiply: function ( a, b ) {
 
 		this.x = a.x * b.x;
 		this.y = a.y * b.y;
@@ -108,7 +110,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	multiplySelf : function ( v ) {
+	multiplySelf: function ( v ) {
 
 		this.x *= v.x;
 		this.y *= v.y;
@@ -118,7 +120,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	multiplyScalar : function ( s ) {
+	multiplyScalar: function ( s ) {
 
 		this.x *= s;
 		this.y *= s;
@@ -128,13 +130,13 @@ THREE.Vector3.prototype = {
 
 	},
 
-	divideSelf : function ( v ) {
+	divideSelf: function ( v ) {
 
 		return this.divide( this, v );
 
 	},
 
-	divideScalar : function ( s ) {
+	divideScalar: function ( s ) {
 
 		if ( s ) {
 
@@ -153,31 +155,31 @@ THREE.Vector3.prototype = {
 	},
 
 
-	negate : function() {
+	negate: function() {
 
 		return this.multiplyScalar( -1 );
 
 	},
 
-	dot : function ( v ) {
+	dot: function ( v ) {
 
 		return this.x * v.x + this.y * v.y + this.z * v.z;
 
 	},
 
-	lengthSq : function () {
+	lengthSq: function () {
 
 		return this.x * this.x + this.y * this.y + this.z * this.z;
 
 	},
 
-	length : function () {
+	length: function () {
 
 		return Math.sqrt( this.lengthSq() );
 
 	},
 
-	lengthManhattan : function () {
+	lengthManhattan: function () {
 
 		// correct version
 		// return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
@@ -186,20 +188,20 @@ THREE.Vector3.prototype = {
 
 	},
 
-	normalize : function () {
+	normalize: function () {
 
 		return this.divideScalar( this.length() );
 
 	},
 
-	setLength : function ( l ) {
+	setLength: function ( l ) {
 
 		return this.normalize().multiplyScalar( l );
 
 	},
 
 
-	cross : function ( a, b ) {
+	cross: function ( a, b ) {
 
 		this.x = a.y * b.z - a.z * b.y;
 		this.y = a.z * b.x - a.x * b.z;
@@ -209,7 +211,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	crossSelf : function ( v ) {
+	crossSelf: function ( v ) {
 
 		return this.set(
 
@@ -222,20 +224,20 @@ THREE.Vector3.prototype = {
 	},
 
 
-	distanceTo : function ( v ) {
+	distanceTo: function ( v ) {
 
 		return Math.sqrt( this.distanceToSquared( v ) );
 
 	},
 
-	distanceToSquared : function ( v ) {
+	distanceToSquared: function ( v ) {
 
 		return new THREE.Vector3().sub( this, v ).lengthSq();
 
 	},
 
 
-	setPositionFromMatrix : function ( m ) {
+	setPositionFromMatrix: function ( m ) {
 
 		this.x = m.n14;
 		this.y = m.n24;
@@ -243,7 +245,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	setRotationFromMatrix : function ( m ) {
+	setRotationFromMatrix: function ( m ) {
 
 		var cosY = Math.cos( this.y );
 
@@ -263,7 +265,7 @@ THREE.Vector3.prototype = {
 
 	},
 
-	isZero : function () {
+	isZero: function () {
 
 		return ( this.lengthSq() < 0.0001 /* almostZero */ );
 

+ 19 - 17
src/core/Vector4.js

@@ -20,7 +20,9 @@ THREE.Vector4 = function ( x, y, z, w ) {
 
 THREE.Vector4.prototype = {
 
-	set : function ( x, y, z, w ) {
+	constructor: THREE.Vector4,
+
+	set: function ( x, y, z, w ) {
 
 		this.x = x;
 		this.y = y;
@@ -31,7 +33,7 @@ THREE.Vector4.prototype = {
 
 	},
 
-	copy : function ( v ) {
+	copy: function ( v ) {
 
 		return this.set(
 
@@ -44,14 +46,14 @@ THREE.Vector4.prototype = {
 
 	},
 
-	clone : function () {
+	clone: function () {
 
 		return new THREE.Vector4( this.x, this.y, this.z, this.w );
 
 	},
 
 
-	add : function ( v1, v2 ) {
+	add: function ( v1, v2 ) {
 
 		this.x = v1.x + v2.x;
 		this.y = v1.y + v2.y;
@@ -62,7 +64,7 @@ THREE.Vector4.prototype = {
 
 	},
 
-	addSelf : function ( v ) {
+	addSelf: function ( v ) {
 
 		this.x += v.x;
 		this.y += v.y;
@@ -73,7 +75,7 @@ THREE.Vector4.prototype = {
 
 	},
 
-	sub : function ( v1, v2 ) {
+	sub: function ( v1, v2 ) {
 
 		this.x = v1.x - v2.x;
 		this.y = v1.y - v2.y;
@@ -84,7 +86,7 @@ THREE.Vector4.prototype = {
 
 	},
 
-	subSelf : function ( v ) {
+	subSelf: function ( v ) {
 
 		this.x -= v.x;
 		this.y -= v.y;
@@ -95,7 +97,7 @@ THREE.Vector4.prototype = {
 
 	},
 
-	multiplyScalar : function ( s ) {
+	multiplyScalar: function ( s ) {
 
 		this.x *= s;
 		this.y *= s;
@@ -106,7 +108,7 @@ THREE.Vector4.prototype = {
 
 	},
 
-	divideScalar : function ( s ) {
+	divideScalar: function ( s ) {
 
 		if ( s ) {
 
@@ -126,44 +128,44 @@ THREE.Vector4.prototype = {
 	},
 
 
-	negate : function() {
+	negate: function() {
 
 		return this.multiplyScalar( -1 );
 
 	},
 
-	dot : function ( v ) {
+	dot: function ( v ) {
 
 		return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
 
 	},
 
-	lengthSq : function () {
+	lengthSq: function () {
 
 		return this.dot( this );
 
 	},
 
-	length : function () {
+	length: function () {
 
 		return Math.sqrt( this.lengthSq() );
 
 	},
 
-	normalize : function () {
+	normalize: function () {
 
 		return this.divideScalar( this.length() );
 
 	},
 
-	setLength : function ( l ) {
+	setLength: function ( l ) {
 
 		return this.normalize().multiplyScalar( l );
 
 	},
 
 
-	lerpSelf : function ( v, alpha ) {
+	lerpSelf: function ( v, alpha ) {
 
 		this.x += (v.x - this.x) * alpha;
 		this.y += (v.y - this.y) * alpha;
@@ -172,6 +174,6 @@ THREE.Vector4.prototype = {
 
 		return this;
 
-	},
+	}
 
 };

+ 352 - 1
src/extras/GeometryUtils.js

@@ -1,4 +1,9 @@
-var GeometryUtils = {
+/**
+ * @author mrdoob / http://mrdoob.com/
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.GeometryUtils = {
 
 	merge: function ( geometry1, object2 /* mesh | geometry */ ) {
 
@@ -15,6 +20,8 @@ var GeometryUtils = {
 
 		isMesh && object2.matrixAutoUpdate && object2.updateMatrix();
 
+		// vertices
+
 		for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
 
 			var vertex = vertices2[ i ];
@@ -27,6 +34,8 @@ var GeometryUtils = {
 
 		}
 
+		// faces
+
 		for ( i = 0, il = faces2.length; i < il; i ++ ) {
 
 			var face = faces2[ i ], faceCopy, normal, color,
@@ -69,6 +78,8 @@ var GeometryUtils = {
 
 		}
 
+		// uvs
+
 		for ( i = 0, il = uvs2.length; i < il; i ++ ) {
 
 			var uv = uvs2[ i ], uvCopy = [];
@@ -83,6 +94,346 @@ var GeometryUtils = {
 
 		}
 
+	},
+
+	clone: function ( geometry ) {
+
+		var cloneGeo = new THREE.Geometry();
+
+		var i, il;
+
+		var vertices = geometry.vertices,
+			faces = geometry.faces,
+			uvs = geometry.faceVertexUvs[ 0 ];
+
+		// vertices
+
+		for ( i = 0, il = vertices.length; i < il; i ++ ) {
+
+			var vertex = vertices[ i ];
+			var vertexCopy = new THREE.Vertex( vertex.position.clone() );
+
+			cloneGeo.vertices.push( vertexCopy );
+
+		}
+
+		// faces
+
+		for ( i = 0, il = faces.length; i < il; i ++ ) {
+
+			var face = faces[ i ], faceCopy, normal, color,
+			faceVertexNormals = face.vertexNormals,
+			faceVertexColors = face.vertexColors;
+
+			if ( face instanceof THREE.Face3 ) {
+
+				faceCopy = new THREE.Face3( face.a, face.b, face.c );
+
+			} else if ( face instanceof THREE.Face4 ) {
+
+				faceCopy = new THREE.Face4( face.a, face.b, face.c, face.d );
+
+			}
+
+			faceCopy.normal.copy( face.normal );
+
+			for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
+
+				normal = faceVertexNormals[ j ];
+				faceCopy.vertexNormals.push( normal.clone() );
+
+			}
+
+			faceCopy.color.copy( face.color );
+
+			for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
+
+				color = faceVertexColors[ j ];
+				faceCopy.vertexColors.push( color.clone() );
+
+			}
+
+			faceCopy.materials = face.materials.slice();
+
+			faceCopy.centroid.copy( face.centroid );
+
+			cloneGeo.faces.push( faceCopy );
+
+		}
+
+		// uvs
+
+		for ( i = 0, il = uvs.length; i < il; i ++ ) {
+
+			var uv = uvs[ i ], uvCopy = [];
+
+			for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
+
+				uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
+
+			}
+
+			cloneGeo.faceVertexUvs[ 0 ].push( uvCopy );
+
+		}
+
+		return cloneGeo;
+
+	},
+
+	// Get random point in triangle (via barycentric coordinates)
+	// 	(uniform distribution)
+	// 	http://www.cgafaq.info/wiki/Random_Point_In_Triangle
+
+	randomPointInTriangle: function( vectorA, vectorB, vectorC ) {
+
+		var a, b, c,
+			point = new THREE.Vector3(),
+			tmp = THREE.GeometryUtils.__v1;
+
+		a = THREE.GeometryUtils.random();
+		b = THREE.GeometryUtils.random();
+
+		if ( ( a + b ) > 1 ) {
+
+			a = 1 - a;
+			b = 1 - b;
+
+		}
+
+		c = 1 - a - b;
+
+		point.copy( vectorA );
+		point.multiplyScalar( a );
+
+		tmp.copy( vectorB );
+		tmp.multiplyScalar( b );
+
+		point.addSelf( tmp );
+
+		tmp.copy( vectorC );
+		tmp.multiplyScalar( c );
+
+		point.addSelf( tmp );
+
+		return point;
+
+	},
+
+	// Get random point in face (triangle / quad)
+	// (uniform distribution)
+
+	randomPointInFace: function( face, geometry, useCachedAreas ) {
+
+		var vA, vB, vC, vD;
+
+		if ( face instanceof THREE.Face3 ) {
+
+			vA = geometry.vertices[ face.a ].position;
+			vB = geometry.vertices[ face.b ].position;
+			vC = geometry.vertices[ face.c ].position;
+
+			return THREE.GeometryUtils.randomPointInTriangle( vA, vB, vC );
+
+		} else if ( face instanceof THREE.Face4 ) {
+
+			vA = geometry.vertices[ face.a ].position;
+			vB = geometry.vertices[ face.b ].position;
+			vC = geometry.vertices[ face.c ].position;
+			vD = geometry.vertices[ face.d ].position;
+
+			var area1, area2;
+
+			if ( useCachedAreas ) {
+
+				if ( face._area1 && face._area2 ) {
+
+					area1 = face._area1;
+					area2 = face._area2;
+
+				} else {
+
+					area1 = THREE.GeometryUtils.triangleArea( vA, vB, vD );
+					area2 = THREE.GeometryUtils.triangleArea( vB, vC, vD );
+
+					face._area1 = area1;
+					face._area2 = area2;
+
+				}
+
+			} else {
+
+				area1 = THREE.GeometryUtils.triangleArea( vA, vB, vD ),
+				area2 = THREE.GeometryUtils.triangleArea( vB, vC, vD );
+
+			}
+
+			var r = THREE.GeometryUtils.random() * ( area1 + area2 );
+
+			if ( r < area1 ) {
+
+				return THREE.GeometryUtils.randomPointInTriangle( vA, vB, vD );
+
+			} else {
+
+				return THREE.GeometryUtils.randomPointInTriangle( vB, vC, vD );
+
+			}
+
+		}
+
+	},
+
+	// Get uniformly distributed random points in mesh
+	// 	- create array with cumulative sums of face areas
+	//  - pick random number from 0 to total area
+	//  - find corresponding place in area array by binary search
+	//	- get random point in face
+
+	randomPointsInGeometry: function( geometry, n ) {
+
+		var face, i,
+			faces = geometry.faces,
+			vertices = geometry.vertices,
+			il = faces.length,
+			totalArea = 0,
+			cumulativeAreas = [],
+			vA, vB, vC, vD;
+
+		// precompute face areas
+
+		for ( i = 0; i < il; i ++ ) {
+
+			face = faces[ i ];
+
+			if ( face instanceof THREE.Face3 ) {
+
+				vA = vertices[ face.a ].position;
+				vB = vertices[ face.b ].position;
+				vC = vertices[ face.c ].position;
+
+				face._area = THREE.GeometryUtils.triangleArea( vA, vB, vC );
+
+			} else if ( face instanceof THREE.Face4 ) {
+
+				vA = vertices[ face.a ].position;
+				vB = vertices[ face.b ].position;
+				vC = vertices[ face.c ].position;
+				vD = vertices[ face.d ].position;
+
+				face._area1 = THREE.GeometryUtils.triangleArea( vA, vB, vD );
+				face._area2 = THREE.GeometryUtils.triangleArea( vB, vC, vD );
+
+				face._area = face._area1 + face._area2;
+
+			}
+
+			totalArea += face._area;
+
+			cumulativeAreas[ i ] = totalArea;
+
+		}
+
+		// binary search cumulative areas array
+
+		function binarySearchIndices( value ) {
+
+			function binarySearch( start, end ) {
+
+				// return closest larger index
+				// if exact number is not found
+
+				if ( end < start )
+					return start;
+
+				var mid = start + Math.floor( ( end - start ) / 2 );
+
+				if ( cumulativeAreas[ mid ] > value ) {
+
+					return binarySearch( start, mid - 1 );
+
+				} else if ( cumulativeAreas[ mid ] < value ) {
+
+					return binarySearch( mid + 1, end );
+
+				} else {
+
+					return mid;
+
+				}
+
+			}
+
+			var result = binarySearch( 0, cumulativeAreas.length - 1 )
+			return result;
+
+		}
+
+		// pick random face weighted by face area
+
+		var r, index,
+			result = [];
+
+		var stats = {};
+
+		for ( i = 0; i < n; i ++ ) {
+
+			r = THREE.GeometryUtils.random() * totalArea;
+
+			index = binarySearchIndices( r );
+
+			result[ i ] = THREE.GeometryUtils.randomPointInFace( faces[ index ], geometry, true );
+
+			if ( ! stats[ index ] ) {
+
+				stats[ index ] = 1;
+
+			} else {
+
+				stats[ index ] += 1;
+
+			}
+
+		}
+
+		return result;
+
+	},
+
+	// Get triangle area (by Heron's formula)
+	// 	http://en.wikipedia.org/wiki/Heron%27s_formula
+
+	triangleArea: function( vectorA, vectorB, vectorC ) {
+
+		var s, a, b, c,
+			tmp = THREE.GeometryUtils.__v1;
+
+		tmp.sub( vectorA, vectorB );
+		a = tmp.length();
+
+		tmp.sub( vectorA, vectorC );
+		b = tmp.length();
+
+		tmp.sub( vectorB, vectorC );
+		c = tmp.length();
+
+		s = 0.5 * ( a + b + c );
+
+		return Math.sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) );
+
+	},
+
+	// Get 16 bits of randomness
+	// (standard Math.random() creates repetitive patterns when applied over larger space)
+
+	random16: function() {
+
+		return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
+
 	}
 
 };
+
+THREE.GeometryUtils.random = THREE.GeometryUtils.random16;
+
+THREE.GeometryUtils.__v1 = new THREE.Vector3();

+ 13 - 4
src/extras/ShaderUtils.js

@@ -1,6 +1,15 @@
 /**
  * @author alteredq / http://alteredqualia.com/
  * @author mr.doob / http://mrdoob.com/
+ *
+ * ShaderUtils currently contains
+ *	fresnel
+ *	normal
+ * 	cube
+ * 	convolution
+ * 	film
+ * 	screen
+ *	basic
  */
 
 if ( THREE.WebGLRenderer ) {
@@ -197,12 +206,12 @@ THREE.ShaderUtils = {
 
 					"#if MAX_POINT_LIGHTS > 0",
 
-						"vec4 pointTotal  = vec4( 0.0 );",
+						"vec4 pointTotal = vec4( vec3( 0.0 ), 1.0 );",
 
 						"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 							"vec3 pointVector = normalize( vPointLight[ i ].xyz );",
-							"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + vViewPosition );",
+							"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );",
 							"float pointDistance = vPointLight[ i ].w;",
 
 							"float pointDotNormalHalf = dot( normal, pointHalfVector );",
@@ -222,14 +231,14 @@ THREE.ShaderUtils = {
 
 					"#if MAX_DIR_LIGHTS > 0",
 
-						"vec4 dirTotal  = vec4( 0.0 );",
+						"vec4 dirTotal = vec4( vec3( 0.0 ), 1.0 );",
 
 						"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
 
 							"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
 
 							"vec3 dirVector = normalize( lDirection.xyz );",
-							"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
+							"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
 
 							"float dirDotNormalHalf = dot( normal, dirHalfVector );",
 							"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",

+ 72 - 67
src/extras/animation/AnimationHandler.js

@@ -42,7 +42,7 @@ THREE.AnimationHandler = (function() {
 
 
 	//--- add ---
-	
+
 	that.add = function( data ) {
 
 		if( library[ data.name ] !== undefined )
@@ -55,61 +55,61 @@ THREE.AnimationHandler = (function() {
 
 
 	//--- get ---
-	
+
 	that.get = function( name ) {
-		
+
 		if( typeof name === "string" ) {
-			
+
 			if( library[ name ] ) {
-				
+
 				return library[ name ];
-			
+
 			} else {
-				
+
 				console.log( "THREE.AnimationHandler.get: Couldn't find animation " + name );
 				return null;
 
 			}
 
 		} else {
-			
+
 			// todo: add simple tween library
 
 		}
-		
+
 	};
 
 	//--- parse ---
-	
+
 	that.parse = function( root ) {
-		
+
 		// setup hierarchy
 
 		var hierarchy = [];
-	
+
 		if ( root instanceof THREE.SkinnedMesh ) {
-	
+
 			for( var b = 0; b < root.bones.length; b++ ) {
-	
+
 				hierarchy.push( root.bones[ b ] );
-	
+
 			}
-	
+
 		} else {
-	
+
 			parseRecurseHierarchy( root, hierarchy );
-	
+
 		}
-		
+
 		return hierarchy;
 
 	};
 
 	var parseRecurseHierarchy = function( root, hierarchy ) {
-		
+
 		hierarchy.push( root );
-		
-		for( var c = 0; c < root.children.length; c++ ) 
+
+		for( var c = 0; c < root.children.length; c++ )
 			parseRecurseHierarchy( root.children[ c ], hierarchy );
 
 	}
@@ -118,16 +118,16 @@ THREE.AnimationHandler = (function() {
 	//--- init data ---
 
 	var initData = function( data ) {
- 
+
 		if( data.initialized === true )
 			return;
-		
+
 
 		// loop through all keys
 
-		for( var h = 0; h < data.hierarchy.length; h++ ) {
+		for( var h = 0; h < data.hierarchy.length; h ++ ) {
 
-			for( var k = 0; k < data.hierarchy[ h ].keys.length; k++ ) {
+			for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
 
 				// remove minus times
 
@@ -148,77 +148,81 @@ THREE.AnimationHandler = (function() {
 
 
 			// prepare morph target keys
-			
+
 			if( data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
 
 				// get all used
 
 				var usedMorphTargets = {};
-				
-				for( var k = 0; k < data.hierarchy[ h ].keys.length; k++ ) {
-	
-					for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m++ ) {
-						
+
+				for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
+
+					for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
+
 						var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
 						usedMorphTargets[ morphTargetName ] = -1;
-					}					
-				
+
+					}
+
 				}
-				
+
 				data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
-				
-				
+
+
 				// set all used on all frames
-				
-				for( var k = 0; k < data.hierarchy[ h ].keys.length; k++ ) {
-	
+
+				for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
+
 					var influences = {};
-	
+
 					for( var morphTargetName in usedMorphTargets ) {
-			
-						for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m++ ) {
-	
+
+						for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
+
 							if( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
-								
+
 								influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
-								break;	
+								break;
+
 							}
-					
+
 						}
-						
+
 						if( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
-							
+
 							influences[ morphTargetName ] = 0;
+
 						}
-	
+
 					}
-				
+
 					data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
+
 				}
-			
+
 			}
-			
-			
+
+
 			// remove all keys that are on the same time
-			
-			for( var k = 1; k < data.hierarchy[ h ].keys.length; k++ ) {
-				
+
+			for( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
+
 				if( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
-					
+
 					data.hierarchy[ h ].keys.splice( k, 1 );
-					k--;
-				
+					k --;
+
 				}
-				
+
 			}
 
 
 			// set index
-			
-			for( var k = 1; k < data.hierarchy[ h ].keys.length; k++ ) {
-				
+
+			for( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
+
 				data.hierarchy[ h ].keys[ k ].index = k;
-				
+
 			}
 
 		}
@@ -231,8 +235,8 @@ THREE.AnimationHandler = (function() {
 		data.JIT = {};
 		data.JIT.hierarchy = [];
 
-		for( var h = 0; h < data.hierarchy.length; h++ )
-			data.JIT.hierarchy.push( new Array( lengthInFrames ));
+		for( var h = 0; h < data.hierarchy.length; h ++ )
+			data.JIT.hierarchy.push( new Array( lengthInFrames ) );
 
 
 		// done
@@ -249,4 +253,5 @@ THREE.AnimationHandler = (function() {
 	that.CATMULLROM_FORWARD = 2;
 
 	return that;
+
 }());

+ 21 - 2
src/extras/cameras/FirstPersonCamera.js

@@ -164,6 +164,9 @@ THREE.FirstPersonCamera = function ( parameters ) {
 			case 39: /*right*/
 			case 68: /*D*/ this.moveRight = true; break;
 
+			case 82: /*R*/ this.moveUp = true; break;
+			case 70: /*F*/ this.moveDown = true; break;
+
 			case 81: this.freeze = !this.freeze; break;
 
 		}
@@ -186,6 +189,9 @@ THREE.FirstPersonCamera = function ( parameters ) {
 			case 39: /*right*/
 			case 68: /*D*/ this.moveRight = false; break;
 
+			case 82: /*R*/ this.moveUp = false; break;
+			case 70: /*F*/ this.moveDown = false; break;
+
 		}
 
 	};
@@ -195,7 +201,7 @@ THREE.FirstPersonCamera = function ( parameters ) {
 		var now = new Date().getTime();
 		this.tdiff = ( now - this.lastUpdate ) / 1000;
 		this.lastUpdate = now;
-		
+
 		if ( !this.freeze ) {
 
 
@@ -216,9 +222,13 @@ THREE.FirstPersonCamera = function ( parameters ) {
 
 			if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
 			if ( this.moveBackward ) this.translateZ( actualMoveSpeed );
+
 			if ( this.moveLeft ) this.translateX( - actualMoveSpeed );
 			if ( this.moveRight ) this.translateX( actualMoveSpeed );
 
+			if ( this.moveUp ) this.translateY( actualMoveSpeed );
+			if ( this.moveDown ) this.translateY( - actualMoveSpeed );
+
 			var actualLookSpeed = this.tdiff * this.lookSpeed;
 
 			if ( !this.activeLook ) {
@@ -243,11 +253,20 @@ THREE.FirstPersonCamera = function ( parameters ) {
 
 		}
 
+		var verticalLookRatio = 1;
+
+		if ( this.constrainVertical ) {
+
+			verticalLookRatio = 3.14 / ( this.verticalMax - this.verticalMin );
+
+		}
+
 		this.lon += this.mouseX * actualLookSpeed;
-		if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
+		if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
 
 		this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
 		this.phi = ( 90 - this.lat ) * Math.PI / 180;
+
 		this.theta = this.lon * Math.PI / 180;
 
 		if ( this.constrainVertical ) {

+ 662 - 0
src/extras/geometries/Curve.js

@@ -0,0 +1,662 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ * Extensible curve object
+ *
+ * This file contains following classes:
+ *
+ * THREE.Curve
+ * THREE.LineCurve
+ * THREE.QuadraticBezierCurve
+ * THREE.CubicBezierCurve
+ * THREE.SplineCurve
+ * THREE.ArcCurve
+ *
+ **/
+
+/**************************************************************
+ *	Abstract Curve base class
+ **************************************************************/
+
+THREE.Curve = function () {
+
+};
+
+// Virtual base class method to overwrite and implement in subclasses
+//	- t [0 .. 1]
+
+THREE.Curve.prototype.getPoint = function ( t ) {
+
+	console.log( "Warning, getPoint() not implemented!" );
+	return null;
+
+};
+
+// Get point at relative position in curve according to arc length
+// - u [0 .. 1]
+
+THREE.Curve.prototype.getPointAt = function ( u ) {
+
+	var t = this.getUtoTmapping( u );
+	return this.getPoint( t );
+
+};
+
+// Get sequence of points using getPoint( t )
+
+THREE.Curve.prototype.getPoints = function ( divisions ) {
+
+	if ( !divisions ) divisions = 5;
+
+	var d, pts = [];
+
+	for ( d = 0; d <= divisions; d ++ ) {
+
+		pts.push( this.getPoint( d / divisions ) );
+
+	};
+
+	return pts;
+
+};
+
+// Get sequence of points using getPointAt( u )
+
+THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
+
+	if ( !divisions ) divisions = 5;
+
+	var d, pts = [];
+
+	for ( d = 0; d <= divisions; d ++ ) {
+
+		pts.push( this.getPointAt( d / divisions ) );
+
+	};
+
+	return pts;
+
+};
+
+// Get total curve length
+
+THREE.Curve.prototype.getLength = function () {
+
+	var lengths = this.getLengths();
+	return lengths[ lengths.length - 1 ];
+
+};
+
+// Get list of cumulative segment lengths
+
+THREE.Curve.prototype.getLengths = function ( divisions ) {
+
+	if ( !divisions ) divisions = 200;
+
+	if ( this.cacheArcLengths && ( this.cacheArcLengths.length == divisions + 1 ) ) {
+
+		//console.log( "cached", this.cacheArcLengths );
+		return this.cacheArcLengths;
+
+	}
+
+	var cache = [];
+	var current, last = this.getPoint( 0 );
+	var p, sum = 0;
+
+	cache.push( 0 );
+
+	for ( p = 1; p <= divisions; p ++ ) {
+
+		current = this.getPoint ( p / divisions );
+		sum += current.distanceTo( last );
+		cache.push( sum );
+		last = current;
+
+	}
+
+	this.cacheArcLengths = cache;
+
+	return cache; // { sums: cache, sum:sum }; Sum is in the last element.
+
+};
+
+// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance
+
+THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
+
+	var arcLengths = this.getLengths();
+
+	var i = 0, il = arcLengths.length;
+
+	var targetArcLength; // The targeted u distance value to get
+
+	if ( distance ) {
+
+		targetArcLength = distance;
+
+	} else {
+
+		targetArcLength = u * arcLengths[ il - 1 ];
+
+	}
+
+	// // TODO Should do binary search + sub division + interpolation when needed
+	// time = Date.now();
+	// while ( i < il ) {
+	//
+	// 	i++;
+	//
+	// 	if ( targetArcLength < arcLengths[ i ] ) break;
+	//
+	// }
+	//
+	// i--;
+	// console.log('o' , i, Date.now()- time);
+
+	time = Date.now();
+
+	// binary search for the index with largest value smaller than target u distance
+
+	var low = 0, high = il - 1, comparison;
+
+	while ( low <= high ) {
+
+		i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
+
+	  	comparison = arcLengths[ i ] - targetArcLength;
+
+	  	if ( comparison < 0 ) {
+
+			low = i + 1;
+			continue;
+
+		} else if ( comparison > 0 ) {
+
+			high = i - 1;
+			continue;
+
+		} else {
+
+			high = i;
+			break;
+
+			// DONE
+
+		}
+
+	}
+
+	i = high;
+
+	//console.log('b' , i, low, high, Date.now()- time);
+
+	if ( arcLengths[ i ] == targetArcLength ) {
+
+		var t = i / ( il - 1 );
+		return t;
+
+	}
+
+	// we could get finer grain at lengths, or use simple interpolatation between two points
+
+	var lengthBefore = arcLengths[ i ];
+    var lengthAfter = arcLengths[ i + 1 ];
+
+    var segmentLength = lengthAfter - lengthBefore;
+
+    // determine where we are between the 'before' and 'after' points
+
+    var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
+
+    // add that fractional amount to t
+
+    t = ( i + segmentFraction ) / ( il -1 );
+
+	return t;
+
+};
+
+// In case any sub curve does not implement its tangent / normal finding,
+// we get 2 points with a small delta and find a gradient of the 2 points
+// which seems to make a reasonable approximation
+
+THREE.Curve.prototype.getNormalVector = function( t ) {
+
+	var vec = this.getTangent( t );
+
+	return new THREE.Vector2( -vec.y , vec.x );
+
+};
+
+// Returns a unit vector tangent at t
+
+THREE.Curve.prototype.getTangent = function( t ) {
+
+	var delta = 0.0001;
+	var t1 = t - delta;
+	var t2 = t + delta;
+
+	// Capping in case of danger
+
+	if ( t1 < 0 ) t1 = 0;
+	if ( t2 > 1 ) t2 = 1;
+
+	var pt1 = this.getPoint( t1 );
+	var pt2 = this.getPoint( t2 );
+
+	var vec = new THREE.Vector2();
+	vec.sub( pt2, pt1 );
+	return vec.unit();
+
+};
+
+
+/**************************************************************
+ *	Line
+ **************************************************************/
+
+THREE.LineCurve = function ( v1, v2 ) {
+
+	if ( ! ( v1 instanceof THREE.Vector2 ) ) {
+
+		// Fall back for old constuctor signature - should be removed over time
+
+		THREE.LineCurve.oldConstructor.apply( this, arguments );
+		return;
+
+	}
+
+	this.v1 = v1;
+	this.v2 = v2;
+
+};
+
+THREE.LineCurve.oldConstructor = function ( x1, y1, x2, y2 ) {
+
+	this.constructor( new THREE.Vector2( x1, y1 ), new THREE.Vector2( x2, y2 ) );
+
+};
+
+THREE.LineCurve.prototype = new THREE.Curve();
+THREE.LineCurve.prototype.constructor = THREE.LineCurve;
+
+THREE.LineCurve.prototype.getPoint = function ( t ) {
+
+	var point = new THREE.Vector2();
+
+	point.sub( this.v2, this.v1 );
+	point.multiplyScalar( t ).addSelf( this.v1 );
+
+	return point;
+
+	// 	var dx = this.x2 - this.x1;
+	// 	var dy = this.y2 - this.y1;
+	//
+	// 	var tx = this.x1 + dx * t;
+	// 	var ty = this.y1 + dy * t;
+	//
+	// 	return new THREE.Vector2( tx, ty );
+
+};
+
+// Line curve is linear, so we can overwrite default getPointAt
+
+THREE.LineCurve.prototype.getPointAt = function ( u ) {
+
+	return this.getPoint( u );
+
+};
+
+THREE.LineCurve.prototype.getTangent = function( t ) {
+
+	var tangent = new THREE.Vector2();
+
+	tangent.sub( this.v2, this.v1 );
+	tangent.normalize();
+
+	return tangent;
+
+};
+
+/**************************************************************
+ *	Quadratic Bezier curve
+ **************************************************************/
+
+
+THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
+
+	if ( !( v1 instanceof THREE.Vector2 ) ) {
+
+		var args = Array.prototype.slice.call( arguments );
+
+		v0 = new THREE.Vector2( args[ 0 ], args[ 1 ] );
+		v1 = new THREE.Vector2( args[ 2 ], args[ 3 ] );
+		v2 = new THREE.Vector2( args[ 4 ], args[ 5 ] );
+
+	}
+
+	this.v0 = v0;
+	this.v1 = v1;
+	this.v2 = v2;
+
+};
+
+THREE.QuadraticBezierCurve.prototype = new THREE.Curve();
+THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
+
+
+THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
+
+	var tx, ty;
+
+	tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
+	ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
+
+	return new THREE.Vector2( tx, ty );
+
+};
+
+
+THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
+
+	// iterate sub segments
+	// 	get lengths for sub segments
+	// 	if segment is bezier
+	//		perform subdivisions
+
+	// var x0, y0, x1, y1, x2, y2;
+
+	// x0 = this.actions[ 0 ].args[ 0 ];
+	// y0 = this.actions[ 0 ].args[ 1 ];
+	//
+	// x1 = this.actions[ 1 ].args[ 0 ];
+	// y1 = this.actions[ 1 ].args[ 1 ];
+	//
+	// x2 = this.actions[ 1 ].args[ 2 ];
+	// y2 = this.actions[ 1 ].args[ 3 ];
+
+	var tx, ty;
+
+	tx = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
+	ty = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
+
+	// returns unit vector
+
+	var tangent = new THREE.Vector2( tx, ty );
+	tangent.normalize();
+
+	return tangent;
+
+};
+
+
+/**************************************************************
+ *	Cubic Bezier curve
+ **************************************************************/
+
+THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
+
+	if ( ! ( v1 instanceof THREE.Vector2 ) ) {
+
+		var args = Array.prototype.slice.call( arguments );
+
+		v0 = new THREE.Vector2( args[ 0 ], args[ 1 ] );
+		v1 = new THREE.Vector2( args[ 2 ], args[ 3 ] );
+		v2 = new THREE.Vector2( args[ 4 ], args[ 5 ] );
+		v3 = new THREE.Vector2( args[ 6 ], args[ 7 ] );
+
+	}
+
+	this.v0 = v0;
+	this.v1 = v1;
+	this.v2 = v2;
+	this.v3 = v3;
+
+};
+
+THREE.CubicBezierCurve.prototype = new THREE.Curve();
+THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
+
+THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
+
+	var tx, ty;
+
+	tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
+	ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
+
+	return new THREE.Vector2( tx, ty );
+
+};
+
+THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
+
+	var tx, ty;
+
+	tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
+	ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
+
+	// return normal unit vector
+
+	var tangent = new THREE.Vector2( tx, ty );
+	tangent.normalize();
+
+	return tangent;
+
+};
+
+
+/**************************************************************
+ *	Spline curve
+ **************************************************************/
+
+THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
+
+	this.points = points;
+
+};
+
+THREE.SplineCurve.prototype = new THREE.Curve();
+THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
+
+THREE.SplineCurve.prototype.getPoint = function ( t ) {
+
+	var v = new THREE.Vector2();
+	var c = [];
+	var points = this.points, point, intPoint, weight;
+	point = ( points.length - 1 ) * t;
+
+	intPoint = Math.floor( point );
+	weight = point - intPoint;
+
+	c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
+	c[ 1 ] = intPoint;
+	c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
+	c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
+
+	v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
+	v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
+
+	return v;
+
+};
+
+/**************************************************************
+ *	Arc curve
+ **************************************************************/
+
+THREE.ArcCurve = function ( aX, aY, aRadius,
+							aStartAngle, aEndAngle,
+							aClockwise ) {
+
+	this.aX = aX;
+	this.aY = aY;
+
+	this.aRadius = aRadius;
+
+	this.aStartAngle = aStartAngle;
+	this.aEndAngle = aEndAngle;
+
+	this.aClockwise = aClockwise;
+
+};
+
+THREE.ArcCurve.prototype = new THREE.Curve();
+THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
+
+THREE.ArcCurve.prototype.getPoint = function ( t ) {
+
+	var deltaAngle = this.aEndAngle - this.aStartAngle;
+
+	if ( !this.aClockwise ) {
+
+		t = 1 - t;
+
+	}
+
+	var angle = this.aStartAngle + t * deltaAngle;
+
+	var tx = this.aX + this.aRadius * Math.cos( angle );
+	var ty = this.aY + this.aRadius * Math.sin( angle );
+
+	return new THREE.Vector2( tx, ty );
+
+};
+
+/**************************************************************
+ *	Utils
+ **************************************************************/
+
+THREE.Curve.Utils = {
+
+	tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
+
+		return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
+
+	},
+
+	// Puay Bing, thanks for helping with this derivative!
+
+	tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
+
+		return -3 * p0 * (1 - t) * (1 - t)  +
+			3 * p1 * (1 - t) * (1-t) - 6 *t *p1 * (1-t) +
+			6 * t *  p2 * (1-t) - 3 * t * t * p2 +
+			3 * t * t * p3;
+	},
+
+
+	tangentSpline: function ( t, p0, p1, p2, p3 ) {
+
+		// To check if my formulas are correct
+
+		var h00 = 6 * t * t - 6 * t; 	// derived from 2t^3 − 3t^2 + 1
+		var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
+		var h01 = -6 * t * t + 6 * t; 	// − 2t3 + 3t2
+		var h11 = 3 * t * t - 2 * t;	// t3 − t2
+
+		return h00 + h10 + h01 + h11;
+
+	},
+
+	// Catmull-Rom
+
+	interpolate: function( p0, p1, p2, p3, t ) {
+
+		var v0 = ( p2 - p0 ) * 0.5;
+		var v1 = ( p3 - p1 ) * 0.5;
+		var t2 = t * t;
+		var t3 = t * t2;
+		return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
+
+	}
+
+};
+
+
+/*
+getPoint DONE
+getLength DONE
+getLengths DONE
+
+curve.getPoints(); DONE
+curve.getPointAtArcLength(t); DONE
+curve.transform(params);
+curve.getTangentAt(t); DONE
+*/
+
+/**************************************************************
+ *	3D Curves
+ **************************************************************/
+
+// A Factory method for creating new curve subclasses
+
+THREE.Curve.create = function( constructor, getPointFunc ) {
+
+    var subClass = constructor;
+
+	subClass.prototype = new THREE.Curve();
+
+	subClass.prototype.constructor = constructor;
+    subClass.prototype.getPoint = getPointFunc;
+
+	return subClass;
+
+};
+
+
+/**************************************************************
+ *	Line3D
+ **************************************************************/
+
+THREE.LineCurve3 = THREE.Curve.create(
+
+	function ( v1, v2 ) {
+
+		this.v1 = v1;
+		this.v2 = v2;
+
+	},
+
+	function ( t ) {
+
+		var r = new THREE.Vector3();
+
+
+		r.sub( v2, v1 ); // diff
+		r.multiplyScalar( t );
+		r.addSelf( this.v1 );
+
+		return r;
+
+	}
+
+);
+
+
+/**************************************************************
+ *	Quadratic Bezier 3D curve
+ **************************************************************/
+
+THREE.QuadraticBezierCurve3 = THREE.Curve.create(
+
+	function ( v0, v1, v2 ) {
+
+		this.v0 = v0;
+		this.v1 = v1;
+		this.v2 = v2;
+
+	},
+
+	function ( t ) {
+
+		var tx, ty, tz;
+
+		tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
+		ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
+		tz = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
+
+		return new THREE.Vector3( tx, ty, tz );
+
+	}
+
+);

+ 298 - 0
src/extras/geometries/CurvePath.js

@@ -0,0 +1,298 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ *
+ **/
+
+/**************************************************************
+ *	Curved Path - a curve path is simply a array of connected
+ *  curves, but retains the api of a curve
+ **************************************************************/
+
+THREE.CurvePath = function () {
+
+	this.curves = [];
+	this.bends = [];
+
+};
+
+THREE.CurvePath.prototype = new THREE.Curve();
+THREE.CurvePath.prototype.constructor = THREE.CurvePath;
+
+THREE.CurvePath.prototype.add = function ( curve ) {
+
+	this.curves.push( curve );
+
+};
+
+THREE.CurvePath.prototype.checkConnection = function() {
+
+};
+
+// Add a line curve  if start and end of lines are not connected
+
+THREE.CurvePath.prototype.closePath = function() {
+
+};
+
+// To get accurate point with reference to
+// entire path distance at time t,
+// following has to be done:
+
+// 1. Length of each sub path have to be known
+// 2. Locate and identify type of curve
+// 3. Get t for the curve
+// 4. Return curve.getPointAt(t')
+
+THREE.CurvePath.prototype.getPoint = function( t ) {
+
+	var d = t * this.getLength();
+	var curveLengths = this.getCurveLengths();
+	var i = 0, diff, curve;
+
+	// To think about boundaries points.
+
+	while ( i < curveLengths.length ) {
+
+		if ( curveLengths[ i ] >= d ) {
+
+			diff = curveLengths[ i ] - d;
+			curve = this.curves[ i ];
+
+			var u = 1 - diff / curve.getLength();
+
+			return curve.getPointAt( u );
+
+			break;
+		}
+
+		i ++;
+
+	}
+
+	return null;
+
+	// loop where sum != 0, sum > d , sum+1 <d
+
+};
+
+/*
+THREE.CurvePath.prototype.getTangent = function( t ) {
+};*/
+
+
+// We cannot use the default THREE.Curve getPoint() with getLength() because in
+// THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
+// getPoint() depends on getLength
+
+THREE.CurvePath.prototype.getLength = function() {
+
+	var lens = this.getCurveLengths();
+	return lens[ lens.length - 1 ];
+
+};
+
+// Compute lengths and cache them
+// We cannot overwrite getLengths() because UtoT mapping uses it.
+
+THREE.CurvePath.prototype.getCurveLengths = function() {
+
+	// We use cache values if curves and cache array are same length
+
+	if ( this.cacheLengths && this.cacheLengths.length == this.curves.length ) {
+
+		return this.cacheLengths;
+
+	};
+
+	// Get length of subsurve
+	// Push sums into cached array
+
+	var lengths = [], sums = 0;
+	var i, il = this.curves.length;
+
+	for ( i = 0; i < il; i ++ ) {
+
+		sums += this.curves[ i ].getLength();
+		lengths.push( sums );
+
+	}
+
+	this.cacheLengths = lengths;
+
+	return lengths;
+
+};
+
+
+
+// Returns min and max coordinates, as well as centroid
+
+THREE.CurvePath.prototype.getBoundingBox = function () {
+
+	var points = this.getPoints();
+
+	var maxX, maxY;
+	var minX, minY;
+
+	maxX = maxY = Number.NEGATIVE_INFINITY;
+	minX = minY = Number.POSITIVE_INFINITY;
+
+	var p, i, il, sum;
+
+	sum = new THREE.Vector2();
+
+	for ( i = 0, il = points.length; i < il; i ++ ) {
+
+		p = points[ i ];
+
+		if ( p.x > maxX ) maxX = p.x;
+		else if ( p.x < minX ) minX = p.x;
+
+		if ( p.y > maxY ) maxY = p.y;
+		else if ( p.y < maxY ) minY = p.y;
+
+		sum.addSelf( p.x, p.y );
+
+	}
+
+	return {
+
+		minX: minX,
+		minY: minY,
+		maxX: maxX,
+		maxY: maxY,
+		centroid: sum.divideScalar( il )
+
+	};
+
+};
+
+/**************************************************************
+ *	Create Geometries Helpers
+ **************************************************************/
+
+/// Generate geometry from path points (for Line or ParticleSystem objects)
+
+THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
+
+    var pts = this.getPoints( divisions, true );
+	return this.createGeometry( pts );
+
+};
+
+// Generate geometry from equidistance sampling along the path
+
+THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
+
+    var pts = this.getSpacedPoints( divisions, true );
+	return this.createGeometry( pts );
+
+};
+
+THREE.CurvePath.prototype.createGeometry = function( points ) {
+
+	var geometry = new THREE.Geometry();
+
+    for( var i = 0; i < points.length; i ++ ) {
+
+        geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( points[ i ].x, points[ i ].y, 0 ) ) );
+
+    }
+
+    return geometry;
+
+};
+
+
+/**************************************************************
+ *	Bend / Wrap Helper Methods
+ **************************************************************/
+
+// Wrap path / Bend modifiers?
+
+THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
+
+	this.bends.push( bendpath );
+
+};
+
+THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
+
+	var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
+	var i, il;
+
+	if ( !bends ) {
+
+		bends = this.bends;
+
+	}
+
+	for ( i = 0, il = bends.length; i < il; i ++ ) {
+
+		oldPts = this.getWrapPoints( oldPts, bends[ i ] );
+
+	}
+
+	return oldPts;
+
+};
+
+THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
+
+	var oldPts = this.getSpacedPoints( segments );
+
+	var i, il;
+
+	if ( !bends ) {
+
+		bends = this.bends;
+
+	}
+
+	for ( i = 0, il = bends.length; i < il; i ++ ) {
+
+		oldPts = this.getWrapPoints( oldPts, bends[ i ] );
+
+	}
+
+	return oldPts;
+
+};
+
+// This returns getPoints() bend/wrapped around the contour of a path.
+// Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
+
+THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
+
+	var bounds = this.getBoundingBox();
+
+	var i, il, p, oldX, oldY, xNorm;
+
+	for ( i = 0, il = oldPts.length; i < il; i ++ ) {
+
+		p = oldPts[ i ];
+
+		oldX = p.x;
+		oldY = p.y;
+
+		var xNorm = oldX/ bounds.maxX;
+
+		// If using actual distance, for length > path, requires line extrusions
+		//xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
+
+		xNorm = path.getUtoTmapping( xNorm, oldX );
+
+		// check for out of bounds?
+
+		var pathPt = path.getPoint( xNorm );
+		var normal = path.getNormalVector( xNorm ).multiplyScalar( oldY );
+
+		p.x = pathPt.x + normal.x;
+		p.y = pathPt.y + normal.y;
+
+	}
+
+	return oldPts;
+
+};
+

+ 704 - 0
src/extras/geometries/ExtrudeGeometry.js

@@ -0,0 +1,704 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ *
+ * Creates extruded geometry from a path shape.
+ *
+ * parameters = {
+ *  size: 			<float>, 	// size of the text
+ *  height: 		<float>, 	// thickness to extrude text
+ *  curveSegments: 	<int>,		// number of points on the curves
+ *
+ *  font: 			<string>,		// font name
+ *  weight: 		<string>,		// font weight (normal, bold)
+ *  style: 			<string>,		// font style  (normal, italics)
+ *
+ *  bevelEnabled:	<bool>,			// turn on bevel
+ *  bevelThickness: <float>, 		// how deep into text bevel goes
+ *  bevelSize:		<float>, 		// how far from text outline is bevel
+ *  bevelSegments:	<int>, 			// number of bevel layers
+ *
+ *  extrudePath:	<THREE.CurvePath>	// path to extrude shape along
+ *  bendPath:		<THREE.CurvePath> 	// path to bend the geometry around
+ *  }
+  **/
+
+THREE.ExtrudeGeometry = function( shapes, options ) {
+
+	if( typeof( shapes ) == "undefined" ) {
+
+		shapes = [];
+		return;
+
+	}
+
+	THREE.Geometry.call( this );
+
+	shapes = shapes instanceof Array ? shapes : [ shapes ];
+
+	var s, sl = shapes.length, shape;
+
+	for ( s = 0; s < sl; s ++ ) {
+
+		shape = shapes[ s ];
+
+		this.addShape( shape, options );
+
+	}
+
+};
+
+THREE.ExtrudeGeometry.prototype = new THREE.Geometry();
+THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
+
+
+THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
+
+	//var startTime = Date.now();
+
+	var amount = options.amount !== undefined ? options.amount : 100;
+
+	var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
+	var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
+	var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
+
+	var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
+
+	var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
+
+	var steps = options.steps !== undefined ? options.steps : 1;
+
+	var bendPath = options.bendPath;
+
+	var extrudePath = options.extrudePath;
+	var extrudePts, extrudeByPath = false;
+
+	var useSpacedPoints = options.useSpacedPoints !== undefined ? options.useSpacedPoints : false;
+
+	if ( extrudePath ) {
+
+		extrudePts = extrudePath.getPoints( curveSegments );
+		steps = extrudePts.length;
+		extrudeByPath = true;
+		bevelEnabled = false; // bevels not supported for path extrusion
+
+	}
+
+	// Safeguards if bevels are not enabled
+
+	if ( !bevelEnabled ) {
+
+		bevelSegments = 0;
+		bevelThickness = 0;
+		bevelSize = 0;
+
+	}
+
+
+	// TODO, extrude by path's tangents? also via 3d path?
+
+	// Variables initalization
+
+	var ahole, h, hl; // looping of holes
+	var scope = this;
+	var bevelPoints = [];
+
+	var shapesOffset = this.vertices.length;
+
+
+	if ( bendPath ) {
+
+		shape.addWrapPath( bendPath );
+
+		//shapePoints = shape.extractAllPointsWithBend( curveSegments, bendPath );
+
+	}
+
+	var shapePoints;
+
+	if ( !useSpacedPoints ) {
+
+	  	shapePoints = shape.extractAllPoints( curveSegments ); //
+
+	} else {
+
+		// QN - Would it be better to pass useSpacePoints parameter to shape, just like bendpath ?
+
+		shapePoints = shape.extractAllSpacedPoints( curveSegments ) // for points with equal divisions
+
+	}
+
+    var vertices = shapePoints.shape;
+	var holes = shapePoints.holes;
+
+	var reverse = !THREE.Shape.Utils.isClockWise( vertices ) ;
+
+	if ( reverse ) {
+
+		vertices = vertices.reverse();
+
+		// Maybe we should also check if holes are in the opposite direction, just to be safe ...
+
+		for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+
+			ahole = holes[ h ];
+
+			if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
+
+				holes[ h ] = ahole.reverse();
+
+			}
+
+		}
+
+		reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
+
+	}
+
+
+	var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
+	//var faces = THREE.Shape.Utils.triangulate2( vertices, holes );
+
+	// Would it be better to move points after triangulation?
+	// shapePoints = shape.extractAllPointsWithBend( curveSegments, bendPath );
+	// 	vertices = shapePoints.shape;
+	// 	holes = shapePoints.holes;
+
+	//console.log(faces);
+
+	////
+	///   Handle Vertices
+	////
+
+	var contour = vertices; // vertices has all points but contour has only points of circumference
+
+	for ( h = 0, hl = holes.length;  h < hl; h ++ ) {
+
+		ahole = holes[ h ];
+
+		vertices = vertices.concat( ahole );
+
+	}
+
+
+	var i, il;
+
+	// We no longer need centroids
+
+	// Find all centroids of shapes and holes
+
+	//var sum = new THREE.Vector2();
+
+	// for ( i = 0, il = contour.length; i < il; i ++ ) {
+	//
+	// 	sum.addSelf( contour[ i ] );
+	//
+	// }
+	//
+	// var contourCentroid = sum.divideScalar( contour.length );
+	//
+	// var holesCentroids = [];
+	//
+	// for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+	//
+	// 	sum = new THREE.Vector2();
+	// 	ahole = holes[ h ];
+	//
+	// 	for ( i=0, il = ahole.length; i < il; i ++ ) {
+	//
+	// 		sum.addSelf( ahole[ i ] );
+	//
+	// 	}
+	//
+	// 	holesCentroids[ h ] = sum.divideScalar( ahole.length );
+	//
+	// }
+	//
+	// function scalePt ( pt, centroid, size, expandOutwards /* Boolean */ ) {
+	//
+	// 	var vectorFromCentroid = pt.clone().subSelf( centroid );
+	// 	var adj = size / vectorFromCentroid.length();
+	//
+	// 	if ( expandOutwards ) {
+	//
+	// 		adj = 1 + adj;
+	//
+	// 	}  else {
+	//
+	// 		adj = 1 - adj;
+	//
+	// 	}
+	//
+	// 	return vectorFromCentroid.multiplyScalar( adj ).addSelf( centroid );
+	//
+	// }
+
+
+	function scalePt2 ( pt, vec, size ) {
+
+		if ( !vec ) console.log( "die" );
+
+		return vec.clone().multiplyScalar( size ).addSelf( pt );
+
+	}
+
+	var b, bs, t, z,
+		vert, vlen = vertices.length,
+		face, flen = faces.length,
+		cont, clen = contour.length;
+
+
+	//------
+	// Find directions for point movement
+	//
+
+	var RAD_TO_DEGREES = 180 / Math.PI;
+
+
+	function getBevelVec( pt_i, pt_j, pt_k ) {
+
+		// Algorithm 2
+
+		return getBevelVec2( pt_i, pt_j, pt_k );
+
+	}
+
+	function getBevelVec1( pt_i, pt_j, pt_k ) {
+
+		var anglea = Math.atan2( pt_j.y - pt_i.y, pt_j.x - pt_i.x );
+		var angleb = Math.atan2( pt_k.y - pt_i.y, pt_k.x - pt_i.x );
+
+		if ( anglea > angleb ) {
+
+			angleb += Math.PI * 2;
+
+		}
+
+		anglec = ( anglea + angleb ) / 2;
+
+
+		//console.log('angle1', anglea * RAD_TO_DEGREES,'angle2', angleb * RAD_TO_DEGREES, 'anglec', anglec *RAD_TO_DEGREES);
+
+		var x = - Math.cos( anglec );
+		var y = - Math.sin( anglec );
+
+		var vec = new THREE.Vector2( x, y ); //.normalize();
+
+		return vec;
+
+	}
+
+	function getBevelVec2( pt_i, pt_j, pt_k ) {
+
+		var a = THREE.ExtrudeGeometry.__v1,
+			b = THREE.ExtrudeGeometry.__v2,
+			v_hat = THREE.ExtrudeGeometry.__v3,
+			w_hat = THREE.ExtrudeGeometry.__v4,
+			p = THREE.ExtrudeGeometry.__v5,
+			q = THREE.ExtrudeGeometry.__v6,
+			v, w,
+			v_dot_w_hat, q_sub_p_dot_w_hat,
+			s, intersection;
+
+		// good reading for line-line intersection
+		// http://sputsoft.com/blog/2010/03/line-line-intersection.html
+
+		// define a as vector j->i
+		// define b as vectot k->i
+
+		a.set( pt_i.x - pt_j.x, pt_i.y - pt_j.y );
+		b.set( pt_i.x - pt_k.x, pt_i.y - pt_k.y );
+
+		// get unit vectors
+
+		v = a.normalize();
+		w = b.normalize();
+
+		// normals from pt i
+
+		v_hat.set( -v.y, v.x );
+		w_hat.set( w.y, -w.x );
+
+		// pts from i
+
+		p.copy( pt_i ).addSelf( v_hat );
+		q.copy( pt_i ).addSelf( w_hat );
+
+		if ( p.equals( q ) ) {
+
+			//console.log("Warning: lines are straight");
+			return w_hat.clone();
+
+		}
+
+		// Points from j, k. helps prevents points cross overover most of the time
+
+		p.copy( pt_j ).addSelf( v_hat );
+		q.copy( pt_k ).addSelf( w_hat );
+
+		v_dot_w_hat = v.dot( w_hat );
+		q_sub_p_dot_w_hat = q.subSelf( p ).dot( w_hat );
+
+		// We should not reach these conditions
+
+		if ( v_dot_w_hat == 0 ) {
+
+			console.log( "Either infinite or no solutions!" );
+
+			if ( q_sub_p_dot_w_hat == 0 ) {
+
+				console.log( "Its finite solutions." );
+
+			} else {
+
+				console.log( "Too bad, no solutions." );
+
+			}
+
+		}
+
+		s = q_sub_p_dot_w_hat / v_dot_w_hat;
+
+		if ( s < 0 ) {
+
+			// in case of emergecy, revert to algorithm 1.
+			// console.log("opps");
+
+			return getBevelVec1( pt_i, pt_j, pt_k );
+
+		}
+
+		intersection = v.multiplyScalar( s ).addSelf( p );
+
+		return intersection.subSelf( pt_i ).clone(); // Don't normalize!, otherwise sharp corners become ugly
+
+	}
+
+	var contourMovements = [];
+
+	for ( i = 0, il = contour.length, j = il-1, k = i + 1; i < il; i++, j++, k++ ) {
+
+		if ( j == il ) j = 0;
+		if ( k == il ) k = 0;
+
+		//  (j)---(i)---(k)
+		// console.log('i,j,k', i, j , k)
+
+		var pt_i = contour[ i ];
+		var pt_j = contour[ j ];
+		var pt_k = contour[ k ];
+
+		contourMovements[ i ]= getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
+
+	}
+
+	var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
+
+	for ( h = 0, hl = holes.length; h < hl; h++ ) {
+
+		ahole = holes[ h ];
+
+		oneHoleMovements = [];
+
+		for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i++, j++, k++ ) {
+
+			if ( j == il ) j = 0;
+			if ( k == il ) k = 0;
+
+			//  (j)---(i)---(k)
+			oneHoleMovements[ i ]= getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
+
+		}
+
+		holesMovements.push( oneHoleMovements );
+		verticesMovements = verticesMovements.concat( oneHoleMovements );
+
+	}
+
+
+	// Loop bevelSegments, 1 for the front, 1 for the back
+
+	for ( b = 0; b < bevelSegments; b ++ ) {
+	//for ( b = bevelSegments; b > 0; b -- ) {
+
+		t = b / bevelSegments;
+		z = bevelThickness * ( 1 - t );
+
+		//z = bevelThickness * t;
+		bs = bevelSize * ( Math.sin ( t * Math.PI/2 ) ) ; // curved
+		//bs = bevelSize * t ; // linear
+
+		// contract shape
+
+		for ( i = 0, il = contour.length; i < il; i ++ ) {
+
+			vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
+			//vert = scalePt( contour[ i ], contourCentroid, bs, false );
+			v( vert.x, vert.y,  - z );
+
+		}
+
+		// expand holes
+
+		for ( h = 0, hl = holes.length; h < hl; h++ ) {
+
+			ahole = holes[ h ];
+			oneHoleMovements = holesMovements[ h ];
+
+			for ( i = 0, il = ahole.length; i < il; i++ ) {
+
+				vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
+				//vert = scalePt( ahole[ i ], holesCentroids[ h ], bs, true );
+
+				v( vert.x, vert.y,  -z );
+
+			}
+
+		}
+
+	}
+
+	bs = bevelSize;
+
+	// Back facing vertices
+
+	for ( i = 0; i < vlen; i ++ ) {
+
+		vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
+
+		if ( !extrudeByPath ) {
+
+			v( vert.x, vert.y, 0 );
+
+		} else {
+
+			v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
+
+		}
+
+	}
+
+	// Add stepped vertices...
+	// Including front facing vertices
+
+	var s;
+
+	for ( s = 1; s <= steps; s ++ ) {
+
+		for ( i = 0; i < vlen; i ++ ) {
+
+			vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
+
+			if ( !extrudeByPath ) {
+
+				v( vert.x, vert.y, amount / steps * s );
+
+			} else {
+
+				v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
+
+			}
+
+		}
+
+	}
+
+
+	// Add bevel segments planes
+
+	//for ( b = 1; b <= bevelSegments; b ++ ) {
+	for ( b = bevelSegments - 1; b >= 0; b -- ) {
+
+		t = b / bevelSegments;
+		z = bevelThickness * ( 1 - t );
+		//bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
+		bs = bevelSize * Math.sin ( t * Math.PI/2 ) ;
+
+		// contract shape
+
+		for ( i = 0, il = contour.length; i < il; i ++ ) {
+
+			vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
+			//vert = scalePt( contour[ i ], contourCentroid, bs, false );
+			v( vert.x, vert.y,  amount + z );
+
+		}
+
+		// expand holes
+
+		for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+
+			ahole = holes[ h ];
+			oneHoleMovements = holesMovements[ h ];
+
+			for ( i = 0, il = ahole.length; i < il; i++ ) {
+
+				//vert = scalePt( ahole[ i ], holesCentroids[h], bs, true );
+				vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
+
+				if ( !extrudeByPath ) {
+
+					v( vert.x, vert.y,  amount + z );
+
+				} else {
+
+					v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
+
+				}
+
+			}
+
+		}
+
+	}
+
+
+	////
+	///   Handle Faces
+	////
+
+	// not used anywhere
+	// var layers = ( steps + bevelSegments * 2 ) * vlen;
+
+	// Bottom faces
+
+	if ( bevelEnabled ) {
+
+		var layer = 0 ; // steps + 1
+		var offset = vlen * layer;
+
+		for ( i = 0; i < flen; i ++ ) {
+
+			face = faces[ i ];
+			f3( face[ 2 ]+ offset, face[ 1 ]+ offset, face[ 0 ] + offset );
+
+		}
+
+		layer = steps + bevelSegments * 2;
+		offset = vlen * layer;
+
+		// Top faces
+
+		for ( i = 0; i < flen; i ++ ) {
+
+			face = faces[ i ];
+			f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
+
+		}
+
+	} else {
+
+		for ( i = 0; i < flen; i++ ) {
+
+			face = faces[ i ];
+			f3( face[ 2 ], face[ 1 ], face[ 0 ] );
+
+		}
+
+		// Top faces
+
+		for ( i = 0; i < flen; i ++ ) {
+
+			face = faces[ i ];
+			f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
+
+		}
+
+	}
+
+	var tmpPt;
+	var j, k, l, m;
+
+	var layeroffset = 0;
+
+	// Sides faces
+
+	sidewalls( contour );
+	layeroffset += contour.length;
+
+	for ( h = 0, hl = holes.length;  h < hl; h ++ ) {
+
+		ahole = holes[ h ];
+		sidewalls( ahole );
+
+		//, true
+		layeroffset += ahole.length;
+
+	}
+
+	// Create faces for the z-sides of the shape
+
+	function sidewalls( contour ) {
+
+		i = contour.length;
+
+		while ( --i >= 0 ) {
+
+			tmpPt = contour[ i ];
+
+			j = i;
+			k = i - 1;
+
+			if ( k < 0 ) k = contour.length - 1;
+
+			//console.log('b', i,j, i-1, k,vertices.length);
+
+			var s = 0;
+
+			for ( s = 0; s < ( steps  + bevelSegments * 2 ); s ++ ) {
+
+				var slen1 = vlen * s;
+				var slen2 = vlen * ( s + 1 );
+
+				f4( layeroffset + j + slen1, layeroffset + k + slen1, layeroffset + k + slen2, layeroffset + j + slen2 );
+
+			}
+
+		}
+
+	}
+
+	// UVs to be added
+	// How can we create UVs on this?
+
+	this.computeCentroids();
+	this.computeFaceNormals();
+	//this.computeVertexNormals();
+
+	//console.log( "took", ( Date.now() - startTime ) );
+
+	function v( x, y, z ) {
+
+		scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
+
+	}
+
+	function f3( a, b, c ) {
+
+		a += shapesOffset;
+		b += shapesOffset;
+		c += shapesOffset;
+
+		scope.faces.push( new THREE.Face3( a, b, c ) );
+
+	}
+
+	function f4( a, b, c, d ) {
+
+		a += shapesOffset;
+		b += shapesOffset;
+		c += shapesOffset;
+		d += shapesOffset;
+
+ 		scope.faces.push( new THREE.Face4( a, b, c, d ) );
+
+	}
+
+};
+
+
+THREE.ExtrudeGeometry.__v1 = new THREE.Vector2();
+THREE.ExtrudeGeometry.__v2 = new THREE.Vector2();
+THREE.ExtrudeGeometry.__v3 = new THREE.Vector2();
+THREE.ExtrudeGeometry.__v4 = new THREE.Vector2();
+THREE.ExtrudeGeometry.__v5 = new THREE.Vector2();
+THREE.ExtrudeGeometry.__v6 = new THREE.Vector2();

+ 0 - 3
src/extras/geometries/IcosahedronGeometry.js

@@ -84,9 +84,6 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
 	scope.faces = tempScope.faces;
 	//scope.uvs = tempScope.uvs;
 
-	delete tempScope;
-	delete tempFaces;
-
 	this.computeCentroids();
 	this.computeFaceNormals();
 	this.computeVertexNormals();

+ 641 - 0
src/extras/geometries/Path.js

@@ -0,0 +1,641 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ * Creates free form 2d path using series of points, lines or curves.
+ *
+ **/
+
+THREE.Path = function ( points ) {
+
+	THREE.CurvePath.call(this);
+
+	this.actions = [];
+
+	if ( points ) {
+
+		this.fromPoints( points );
+
+	}
+
+};
+
+THREE.Path.prototype = new THREE.CurvePath();
+THREE.Path.prototype.constructor = THREE.Path;
+
+
+THREE.PathActions = {
+
+	MOVE_TO: 'moveTo',
+	LINE_TO: 'lineTo',
+	QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
+	BEZIER_CURVE_TO: 'bezierCurveTo', 		// Bezier cubic curve
+	CSPLINE_THRU: 'splineThru',				// Catmull-rom spline
+	ARC: 'arc'								// Circle
+
+};
+
+// TODO Clean up PATH API
+
+// Create path using straight lines to connect all points
+// - vectors: array of Vector2
+
+THREE.Path.prototype.fromPoints = function ( vectors ) {
+
+	this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
+
+	var v, vlen = vectors.length;
+
+	for ( v = 1; v < vlen; v++ ) {
+
+		this.lineTo( vectors[ v ].x, vectors[ v ].y );
+
+	};
+
+};
+
+// startPath() endPath()?
+
+THREE.Path.prototype.moveTo = function ( x, y ) {
+
+	var args = Array.prototype.slice.call( arguments );
+	this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
+
+};
+
+THREE.Path.prototype.lineTo = function ( x, y ) {
+
+	var args = Array.prototype.slice.call( arguments );
+
+	var lastargs = this.actions[ this.actions.length - 1 ].args;
+
+	var x0 = lastargs[ lastargs.length - 2 ];
+	var y0 = lastargs[ lastargs.length - 1 ];
+
+	var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
+	this.curves.push( curve );
+
+	this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
+
+};
+
+THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
+
+	var args = Array.prototype.slice.call( arguments );
+
+	var lastargs = this.actions[ this.actions.length - 1 ].args;
+
+	var x0 = lastargs[ lastargs.length - 2 ];
+	var y0 = lastargs[ lastargs.length - 1 ];
+
+	var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
+												new THREE.Vector2( aCPx, aCPy ),
+												new THREE.Vector2( aX, aY ) );
+	this.curves.push( curve );
+
+	this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
+
+};
+
+THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
+                                               aCP2x, aCP2y,
+                                               aX, aY ) {
+
+	var args = Array.prototype.slice.call( arguments );
+
+	var lastargs = this.actions[ this.actions.length - 1 ].args;
+
+	var x0 = lastargs[ lastargs.length - 2 ];
+	var y0 = lastargs[ lastargs.length - 1 ];
+
+	var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
+											new THREE.Vector2( aCP1x, aCP1y ),
+											new THREE.Vector2( aCP2x, aCP2y ),
+											new THREE.Vector2( aX, aY ) );
+	this.curves.push( curve );
+
+	this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
+
+};
+
+THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
+
+	var args = Array.prototype.slice.call( arguments );
+	var lastargs = this.actions[ this.actions.length - 1 ].args;
+
+	var x0 = lastargs[ lastargs.length - 2 ];
+	var y0 = lastargs[ lastargs.length - 1 ];
+
+	var npts = [ new THREE.Vector2( x0, y0 ) ];
+	npts =  npts.concat( pts );
+
+	var curve = new THREE.SplineCurve( npts );
+	this.curves.push( curve );
+
+	this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
+
+};
+
+// FUTURE: Change the API or follow canvas API?
+// TODO ARC ( x, y, x - radius, y - radius, startAngle, endAngle )
+
+THREE.Path.prototype.arc = function ( aX, aY, aRadius,
+									  aStartAngle, aEndAngle, aClockwise ) {
+
+	var args = Array.prototype.slice.call( arguments );
+
+	var curve = new THREE.ArcCurve( aX, aY, aRadius,
+									aStartAngle, aEndAngle, aClockwise );
+	this.curves.push( curve );
+
+	// console.log( 'arc', args );
+
+	this.actions.push( { action: THREE.PathActions.ARC, args: args } );
+
+ };
+
+
+THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
+
+	if ( !divisions ) divisions = 40;
+
+	var points = [];
+
+	for ( var i = 0; i < divisions; i ++ ) {
+
+		points.push( this.getPoint( i / divisions ) );
+
+		//if( !this.getPoint( i / divisions ) ) throw "DIE";
+
+	}
+
+	// if ( closedPath ) {
+	//
+	// 	points.push( points[ 0 ] );
+	//
+	// }
+
+	return points;
+
+};
+
+/* Return an array of vectors based on contour of the path */
+
+THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
+
+	divisions = divisions || 12;
+
+	var points = [];
+
+	var i, il, item, action, args;
+	var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
+		laste, j,
+		t, tx, ty;
+
+	for ( i = 0, il = this.actions.length; i < il; i ++ ) {
+
+		item = this.actions[ i ];
+
+		action = item.action;
+		args = item.args;
+
+		switch( action ) {
+
+		case THREE.PathActions.MOVE_TO:
+
+			// points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
+
+			break;
+
+		case THREE.PathActions.LINE_TO:
+
+			points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
+
+			break;
+
+		case THREE.PathActions.QUADRATIC_CURVE_TO:
+
+			cpx  = args[ 2 ];
+			cpy  = args[ 3 ];
+
+			cpx1 = args[ 0 ];
+			cpy1 = args[ 1 ];
+
+			if ( points.length > 0 ) {
+
+				laste = points[ points.length - 1 ];
+
+				cpx0 = laste.x;
+				cpy0 = laste.y;
+
+			} else {
+
+				laste = this.actions[ i - 1 ].args;
+
+				cpx0 = laste[ laste.length - 2 ];
+				cpy0 = laste[ laste.length - 1 ];
+
+			}
+
+			for ( j = 1; j <= divisions; j ++ ) {
+
+				t = j / divisions;
+
+				tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
+				ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
+
+				points.push( new THREE.Vector2( tx, ty ) );
+
+		  	}
+
+			break;
+
+		case THREE.PathActions.BEZIER_CURVE_TO:
+
+			cpx  = args[ 4 ];
+			cpy  = args[ 5 ];
+
+			cpx1 = args[ 0 ];
+			cpy1 = args[ 1 ];
+
+			cpx2 = args[ 2 ];
+			cpy2 = args[ 3 ];
+
+			if ( points.length > 0 ) {
+
+				laste = points[ points.length - 1 ];
+
+				cpx0 = laste.x;
+				cpy0 = laste.y;
+
+			} else {
+
+				laste = this.actions[ i - 1 ].args;
+
+				cpx0 = laste[ laste.length - 2 ];
+				cpy0 = laste[ laste.length - 1 ];
+
+			}
+
+
+			for ( j = 1; j <= divisions; j ++ ) {
+
+				t = j / divisions;
+
+				tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
+				ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
+
+				points.push( new THREE.Vector2( tx, ty ) );
+
+			}
+
+			break;
+
+		case THREE.PathActions.CSPLINE_THRU:
+
+			laste = this.actions[ i - 1 ].args;
+
+			var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
+			var spts = [ last ];
+
+			var n = divisions * args[ 0 ].length;
+
+			spts = spts.concat( args[ 0 ] );
+
+			var spline = new THREE.SplineCurve( spts );
+
+			for ( j = 1; j <= n; j ++ ) {
+
+				points.push( spline.getPointAt( j / n ) ) ;
+
+			}
+
+			break;
+
+		case THREE.PathActions.ARC:
+
+			laste = this.actions[ i - 1 ].args;
+
+			var aX = args[ 0 ], aY = args[ 1 ],
+				aRadius = args[ 2 ],
+				aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
+				aClockwise = !!args[ 5 ];
+
+			var lastx = laste[ laste.length - 2 ],
+				lasty = laste[ laste.length - 1 ];
+
+			if ( laste.length == 0 ) {
+
+				lastx = lasty = 0;
+
+			}
+
+
+			var deltaAngle = aEndAngle - aStartAngle;
+			var angle;
+			var tdivisions = divisions * 2;
+			var t;
+
+			for ( j = 1; j <= tdivisions; j ++ ) {
+
+				t = j / tdivisions;
+
+				if ( !aClockwise ) {
+
+					t = 1 - t;
+
+				}
+
+				angle = aStartAngle + t * deltaAngle;
+
+				tx = lastx + aX + aRadius * Math.cos( angle );
+				ty = lasty + aY + aRadius * Math.sin( angle );
+
+				//console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
+
+				points.push( new THREE.Vector2( tx, ty ) );
+
+			}
+
+			//console.log(points);
+
+		  break;
+
+		} // end switch
+
+	}
+
+	if ( closedPath ) {
+
+		points.push( points[ 0 ] );
+
+	}
+
+	return points;
+
+};
+
+
+
+// This was used for testing purposes. Should be removed soon.
+
+THREE.Path.prototype.transform = function( path, segments ) {
+
+	var bounds = this.getBoundingBox();
+	var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
+
+	//console.log( path.cacheArcLengths() );
+	//path.getLengths(400);
+	//segments = 40;
+
+	return this.getWrapPoints( oldPts, path );
+
+};
+
+// Read http://www.tinaja.com/glib/nonlingr.pdf
+// nonlinear transforms
+
+THREE.Path.prototype.nltransform = function( a, b, c, d, e, f ) {
+
+	// a - horizontal size
+	// b - lean
+	// c - x offset
+	// d - vertical size
+	// e - climb
+	// f - y offset
+
+	var oldPts = this.getPoints();
+
+	var i, il, p, oldX, oldY;
+
+	for ( i = 0, il = oldPts.length; i < il; i ++ ) {
+
+		p = oldPts[i];
+
+		oldX = p.x;
+		oldY = p.y;
+
+		p.x = a * oldX + b * oldY + c;
+		p.y = d * oldY + e * oldX + f;
+
+	}
+
+	return oldPts;
+
+};
+
+
+// FUTURE Export JSON Format
+
+/* Draws this path onto a 2d canvas easily */
+
+THREE.Path.prototype.debug = function( canvas ) {
+
+	var bounds = this.getBoundingBox();
+
+	if ( !canvas ) {
+
+		canvas = document.createElement( "canvas" );
+
+		canvas.setAttribute( 'width',  bounds.maxX + 100 );
+		canvas.setAttribute( 'height', bounds.maxY + 100 );
+
+		document.body.appendChild( canvas );
+
+	}
+
+	var ctx = canvas.getContext( "2d" );
+	ctx.fillStyle = "white";
+	ctx.fillRect( 0, 0, canvas.width, canvas.height );
+
+	ctx.strokeStyle = "black";
+	ctx.beginPath();
+
+	var i, il, item, action, args;
+
+	// Debug Path
+
+	for ( i = 0, il = this.actions.length; i < il; i ++ ) {
+
+		item = this.actions[ i ];
+
+		args = item.args;
+		action = item.action;
+
+		// Short hand for now
+
+		if ( action != THREE.PathActions.CSPLINE_THRU ) {
+
+			ctx[ action ].apply( ctx, args );
+
+		}
+
+		/*
+		switch ( action ) {
+
+			case THREE.PathActions.MOVE_TO:
+
+				ctx[ action ]( args[ 0 ], args[ 1 ] );
+				break;
+
+			case THREE.PathActions.LINE_TO:
+
+				ctx[ action ]( args[ 0 ], args[ 1 ] );
+				break;
+
+			case THREE.PathActions.QUADRATIC_CURVE_TO:
+
+				ctx[ action ]( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ] );
+				break;
+
+			case THREE.PathActions.CUBIC_CURVE_TO:
+
+				ctx[ action ]( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ] );
+				break;
+
+		}
+		*/
+
+	}
+
+	ctx.stroke();
+	ctx.closePath();
+
+	// Debug Points
+
+	ctx.strokeStyle = "red";
+
+	/* TO CLEAN UP */
+
+	var p, points = this.getPoints();
+
+	//var theta = -90 /180 * Math.PI;
+	//var p, points = this.transform( 0.866, - 0.866,0, 0.500 , 0.50,-50 );
+
+	//0.866, - 0.866,0, 0.500 , 0.50,-50
+
+	// Math.cos(theta),Math.sin(theta),100,
+	// Math.cos(theta),-Math.sin(theta),-50
+
+	// translate, scale, rotation
+
+
+	for ( i = 0, il = points.length; i < il; i ++ ) {
+
+		p = points[ i ];
+
+		ctx.beginPath();
+		ctx.arc( p.x, p.y, 1.5, 0, Math.PI * 2, false );
+		ctx.stroke();
+		ctx.closePath();
+
+	}
+
+};
+
+// Breaks path into shapes
+
+THREE.Path.prototype.toShapes = function() {
+
+	var i, il, item, action, args;
+
+	var subPaths = [], lastPath = new THREE.Path();
+
+	for ( i = 0, il = this.actions.length; i < il; i ++ ) {
+
+		item = this.actions[ i ];
+
+		args = item.args;
+		action = item.action;
+
+		if ( action == THREE.PathActions.MOVE_TO ) {
+
+			if ( lastPath.actions.length != 0 ) {
+
+				subPaths.push( lastPath );
+				lastPath = new THREE.Path();
+
+			}
+
+		}
+
+		lastPath[ action ].apply( lastPath, args );
+
+	}
+
+	if ( lastPath.actions.length != 0 ) {
+
+		subPaths.push( lastPath );
+
+	}
+
+	//console.log(subPaths);
+
+	if ( subPaths.length == 0 ) return [];
+
+	var holesFirst = !THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
+
+	var tmpPath, tmpShape, shapes = [];
+
+	//console.log("Holes first", holesFirst);
+
+	if ( holesFirst ) {
+
+		tmpShape = new THREE.Shape();
+
+		for ( i = 0, il = subPaths.length; i < il; i ++ ) {
+
+			tmpPath = subPaths[ i ];
+
+			if ( THREE.Shape.Utils.isClockWise( tmpPath.getPoints() ) ) {
+
+				tmpShape.actions = tmpPath.actions;
+				tmpShape.curves = tmpPath.curves;
+
+				shapes.push( tmpShape );
+				tmpShape = new THREE.Shape();
+
+				//console.log('cw', i);
+
+			} else {
+
+				tmpShape.holes.push( tmpPath );
+
+				//console.log('ccw', i);
+
+			}
+
+		}
+
+	} else {
+
+		// Shapes first
+
+		for ( i = 0, il = subPaths.length; i < il; i ++ ) {
+
+			tmpPath = subPaths[ i ];
+
+			if ( THREE.Shape.Utils.isClockWise( tmpPath.getPoints() ) ) {
+
+
+				if ( tmpShape ) shapes.push( tmpShape );
+
+				tmpShape = new THREE.Shape();
+				tmpShape.actions = tmpPath.actions;
+				tmpShape.curves = tmpPath.curves;
+
+			} else {
+
+				tmpShape.holes.push( tmpPath );
+
+			}
+
+		}
+
+		shapes.push( tmpShape );
+
+	}
+
+	//console.log("shape", shapes);
+
+	return shapes;
+
+};

+ 514 - 0
src/extras/geometries/Shape.js

@@ -0,0 +1,514 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ * Defines a 2d shape plane using paths.
+ **/
+
+// STEP 1 Create a path.
+// STEP 2 Turn path into shape.
+// STEP 3 ExtrudeGeometry takes in Shape/Shapes
+// STEP 3a - Extract points from each shape, turn to vertices
+// STEP 3b - Triangulate each shape, add faces.
+
+THREE.Shape = function ( ) {
+
+	THREE.Path.apply( this, arguments );
+	this.holes = [];
+
+};
+
+THREE.Shape.prototype = new THREE.Path();
+THREE.Shape.prototype.constructor = THREE.Path;
+
+// Convenience method to return ExtrudeGeometry
+
+THREE.Shape.prototype.extrude = function ( options ) {
+
+	var extruded = new THREE.ExtrudeGeometry( this, options );
+	return extruded;
+
+};
+
+// Get points of holes
+
+THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
+
+	var i, il = this.holes.length, holesPts = [];
+
+	for ( i = 0; i < il; i ++ ) {
+
+		holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
+
+	}
+
+	return holesPts;
+
+};
+
+// Get points of holes (spaced by regular distance)
+
+THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
+
+	var i, il = this.holes.length, holesPts = [];
+
+	for ( i = 0; i < il; i ++ ) {
+
+		holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
+
+	}
+
+	return holesPts;
+
+};
+
+
+// Get points of shape and holes (keypoints based on segments parameter)
+
+THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
+
+	return {
+
+		shape: this.getTransformedPoints( divisions ),
+		holes: this.getPointsHoles( divisions )
+
+	};
+
+};
+
+//
+// THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
+//
+// 	return {
+//
+// 		shape: this.transform( bend, divisions ),
+// 		holes: this.getPointsHoles( divisions, bend )
+//
+// 	};
+//
+// };
+
+// Get points of shape and holes (spaced by regular distance)
+
+THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
+
+	return {
+
+		shape: this.getTransformedSpacedPoints( divisions ),
+		holes: this.getSpacedPointsHoles( divisions )
+
+	};
+
+};
+
+/**************************************************************
+ *	Utils
+ **************************************************************/
+
+THREE.Shape.Utils = {
+
+	/*
+		contour - array of vector2 for contour
+		holes   - array of array of vector2
+	*/
+
+	removeHoles: function ( contour, holes ) {
+
+		var shape = contour.concat(); // work on this shape
+		var allpoints = shape.concat();
+
+		/* For each isolated shape, find the closest points and break to the hole to allow triangulation */
+
+
+		var prevShapeVert, nextShapeVert,
+			prevHoleVert, nextHoleVert,
+			holeIndex, shapeIndex,
+			shapeId, shapeGroup,
+			h, h2,
+			hole, shortest, d,
+			p, pts1, pts2,
+			tmpShape1, tmpShape2,
+			tmpHole1, tmpHole2,
+			verts = [];
+
+		for ( h = 0; h < holes.length; h ++ ) {
+
+			hole = holes[ h ];
+
+			/*
+			shapeholes[ h ].concat(); // preserves original
+			holes.push( hole );
+			*/
+
+			allpoints = allpoints.concat( hole );
+
+			shortest = Number.POSITIVE_INFINITY;
+
+
+			// Find the shortest pair of pts between shape and hole
+
+			// Note: Actually, I'm not sure now if we could optimize this to be faster than O(m*n)
+			// Using distanceToSquared() intead of distanceTo() should speed a little
+			// since running square roots operations are reduced.
+
+			for ( h2 = 0; h2 < hole.length; h2 ++ ) {
+
+				pts1 = hole[ h2 ];
+				var dist = [];
+
+				for ( p = 0; p < shape.length; p++ ) {
+
+					pts2 = shape[ p ];
+					d = pts1.distanceToSquared( pts2 );
+					dist.push( d );
+
+					if ( d < shortest ) {
+
+						shortest = d;
+						holeIndex = h2;
+						shapeIndex = p;
+
+					}
+
+				}
+
+			}
+
+			//console.log("shortest", shortest, dist);
+
+			prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
+			prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
+
+			var areaapts = [
+
+				hole[ holeIndex ],
+				shape[ shapeIndex ],
+				shape[ prevShapeVert ]
+
+			];
+
+			var areaa = THREE.FontUtils.Triangulate.area( areaapts );
+
+			var areabpts = [
+
+				hole[ holeIndex ],
+				hole[ prevHoleVert ],
+				shape[ shapeIndex ]
+
+			];
+
+			var areab = THREE.FontUtils.Triangulate.area( areabpts );
+
+			var shapeOffset = 1;
+			var holeOffset = -1;
+
+			var oldShapeIndex = shapeIndex, oldHoleIndex = holeIndex;
+			shapeIndex += shapeOffset;
+			holeIndex += holeOffset;
+
+			if ( shapeIndex < 0 ) { shapeIndex += shape.length;  }
+			shapeIndex %= shape.length;
+
+			if ( holeIndex < 0 ) { holeIndex += hole.length;  }
+			holeIndex %= hole.length;
+
+			prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
+			prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
+
+			areaapts = [
+
+				hole[ holeIndex ],
+				shape[ shapeIndex ],
+				shape[ prevShapeVert ]
+
+			];
+
+			var areaa2 = THREE.FontUtils.Triangulate.area( areaapts );
+
+			areabpts = [
+
+				hole[ holeIndex ],
+				hole[ prevHoleVert ],
+				shape[ shapeIndex ]
+
+			];
+
+			var areab2 = THREE.FontUtils.Triangulate.area( areabpts );
+			//console.log(areaa,areab ,areaa2,areab2, ( areaa + areab ),  ( areaa2 + areab2 ));
+
+			if ( ( areaa + areab ) > ( areaa2 + areab2 ) ) {
+
+				// In case areas are not correct.
+				//console.log("USE THIS");
+
+				shapeIndex = oldShapeIndex;
+				holeIndex = oldHoleIndex ;
+
+				if ( shapeIndex < 0 ) { shapeIndex += shape.length;  }
+				shapeIndex %= shape.length;
+
+				if ( holeIndex < 0 ) { holeIndex += hole.length;  }
+				holeIndex %= hole.length;
+
+				prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
+				prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
+
+			} else {
+
+				//console.log("USE THAT ")
+
+			}
+
+			tmpShape1 = shape.slice( 0, shapeIndex );
+			tmpShape2 = shape.slice( shapeIndex );
+			tmpHole1 = hole.slice( holeIndex );
+			tmpHole2 = hole.slice( 0, holeIndex );
+
+			// Should check orders here again?
+
+			var trianglea = [
+
+				hole[ holeIndex ],
+				shape[ shapeIndex ],
+				shape[ prevShapeVert ]
+
+			];
+
+			var triangleb = [
+
+				hole[ holeIndex ] ,
+				hole[ prevHoleVert ],
+				shape[ shapeIndex ]
+
+			];
+
+			verts.push( trianglea );
+			verts.push( triangleb );
+
+			shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
+
+		}
+
+		return {
+
+			shape:shape, 		/* shape with no holes */
+			isolatedPts: verts, /* isolated faces */
+			allpoints: allpoints
+
+		}
+
+
+	},
+
+	triangulateShape: function ( contour, holes ) {
+
+		var shapeWithoutHoles = THREE.Shape.Utils.removeHoles( contour, holes );
+
+		var shape = shapeWithoutHoles.shape,
+			allpoints = shapeWithoutHoles.allpoints,
+			isolatedPts = shapeWithoutHoles.isolatedPts;
+
+		var triangles = THREE.FontUtils.Triangulate( shape, false ); // True returns indices for points of spooled shape
+
+		// To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
+
+		//console.log( "triangles",triangles, triangles.length );
+		//console.log( "allpoints",allpoints, allpoints.length );
+
+		var i, il, f, face,
+			key, index,
+			allPointsMap = {},
+			isolatedPointsMap = {};
+
+		// prepare all points map
+
+		for ( i = 0, il = allpoints.length; i < il; i ++ ) {
+
+			key = allpoints[ i ].x + ":" + allpoints[ i ].y;
+
+			if ( allPointsMap[ key ] !== undefined ) {
+
+				console.log( "Duplicate point", key );
+
+			}
+
+			allPointsMap[ key ] = i;
+
+		}
+
+		// check all face vertices against all points map
+
+		for ( i = 0, il = triangles.length; i < il; i ++ ) {
+
+			face = triangles[ i ];
+
+			for ( f = 0; f < 3; f ++ ) {
+
+				key = face[ f ].x + ":" + face[ f ].y;
+
+				index = allPointsMap[ key ];
+
+				if ( index !== undefined ) {
+
+					face[ f ] = index;
+
+				}
+
+			}
+
+		}
+
+		// check isolated points vertices against all points map
+
+		for ( i = 0, il = isolatedPts.length; i < il; i ++ ) {
+
+			face = isolatedPts[ i ];
+
+			for ( f = 0; f < 3; f ++ ) {
+
+				key = face[ f ].x + ":" + face[ f ].y;
+
+				index = allPointsMap[ key ];
+
+				if ( index !== undefined ) {
+
+					face[ f ] = index;
+
+				}
+
+			}
+
+		}
+
+		return triangles.concat( isolatedPts );
+
+	}, // end triangulate shapes
+
+	/*
+	triangulate2 : function( pts, holes ) {
+
+		// For use with Poly2Tri.js
+
+		var allpts = pts.concat();
+		var shape = [];
+		for (var p in pts) {
+			shape.push(new js.poly2tri.Point(pts[p].x, pts[p].y));
+		}
+
+		var swctx = new js.poly2tri.SweepContext(shape);
+
+		for (var h in holes) {
+			var aHole = holes[h];
+			var newHole = []
+			for (i in aHole) {
+				newHole.push(new js.poly2tri.Point(aHole[i].x, aHole[i].y));
+				allpts.push(aHole[i]);
+			}
+			swctx.AddHole(newHole);
+		}
+
+		var find;
+		var findIndexForPt = function (pt) {
+			find = new THREE.Vector2(pt.x, pt.y);
+			var p;
+			for (p=0, pl = allpts.length; p<pl; p++) {
+				if (allpts[p].equals(find)) return p;
+			}
+			return -1;
+		};
+
+		// triangulate
+		js.poly2tri.sweep.Triangulate(swctx);
+
+		var triangles =  swctx.GetTriangles();
+		var tr ;
+		var facesPts = [];
+		for (var t in triangles) {
+			tr =  triangles[t];
+			facesPts.push([
+				findIndexForPt(tr.GetPoint(0)),
+				findIndexForPt(tr.GetPoint(1)),
+				findIndexForPt(tr.GetPoint(2))
+					]);
+		}
+
+
+	//	console.log(facesPts);
+	//	console.log("triangles", triangles.length, triangles);
+
+		// Returns array of faces with 3 element each
+	return facesPts;
+	},
+*/
+
+	isClockWise: function ( pts ) {
+
+		return THREE.FontUtils.Triangulate.area( pts ) < 0;
+
+	},
+
+	// Bezier Curves formulas obtained from
+	// http://en.wikipedia.org/wiki/B%C3%A9zier_curve
+
+	// Quad Bezier Functions
+
+	b2p0: function ( t, p ) {
+
+		var k = 1 - t;
+		return k * k * p;
+
+	},
+
+	b2p1: function ( t, p ) {
+
+		return 2 * ( 1 - t ) * t * p;
+
+	},
+
+	b2p2: function ( t, p ) {
+
+		return t * t * p;
+
+	},
+
+	b2: function ( t, p0, p1, p2 ) {
+
+		return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
+
+	},
+
+	// Cubic Bezier Functions
+
+	b3p0: function ( t, p ) {
+
+		var k = 1 - t;
+		return k * k * k * p;
+
+	},
+
+	b3p1: function ( t, p ) {
+
+		var k = 1 - t;
+		return 3 * k * k * t * p;
+
+	},
+
+	b3p2: function ( t, p ) {
+
+		var k = 1 - t;
+		return 3 * k * t * t * p;
+
+	},
+
+	b3p3: function ( t, p ) {
+
+		return t * t * t * p;
+
+	},
+
+	b3: function ( t, p0, p1, p2, p3 ) {
+
+		return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) +  this.b3p3( t, p3 );
+
+	}
+
+};
+

+ 201 - 445
src/extras/geometries/TextGeometry.js

@@ -15,250 +15,124 @@
  *  weight: 		<string>,		// font weight (normal, bold)
  *  style: 			<string>,		// font style  (normal, italics)
  *
- *  bezelEnabled:	<bool>,			// turn on bezel
- *  bezelThickness: <float>, 		// how deep into text bezel goes
- *  bezelSize:		<float>, 		// how far from text outline is bezel
+ *  bevelEnabled:	<bool>,			// turn on bevel
+ *  bevelThickness: <float>, 		// how deep into text bevel goes
+ *  bevelSize:		<float>, 		// how far from text outline is bevel
+ *
+ *  bend:			<bool>			// bend according to hardcoded curve (for the moment)
  *  }
- *  
- * It uses techniques used in
- * 
+ *
+ * It uses techniques used in:
+ *
  * 	typeface.js and canvastext
- * 		For converting fonts and rendering with javascript 
+ * 		For converting fonts and rendering with javascript
  *		http://typeface.neocracy.org
- * 
+ *
  *	Triangulation ported from AS3
  *		Simple Polygon Triangulation
  *		http://actionsnippet.com/?p=1462
  *
- * 	A Method to triangulate shapes with holes 
+ * 	A Method to triangulate shapes with holes
  *		http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  *
  */
- 
-THREE.TextGeometry = function ( text, parameters ) {
-
-	THREE.Geometry.call( this );
-
-	this.parameters = parameters || {};
-	this.set( text );
-
-};
-
-THREE.TextGeometry.prototype = new THREE.Geometry();
-THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
-
-THREE.TextGeometry.prototype.set = function ( text, parameters ) {
-
-	this.text = text;
-	var parameters = parameters || this.parameters;
-
-	var size = parameters.size !== undefined ? parameters.size : 100;
-	var height = parameters.height !== undefined ? parameters.height : 50;
-	var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments: 4;
-
-	var font = parameters.font !== undefined ? parameters.font : "helvetiker";
-	var weight = parameters.weight !== undefined ? parameters.weight : "normal";
-	var style = parameters.style !== undefined ? parameters.style : "normal";
-
-	var bezelThickness = parameters.bezelThickness !== undefined ? parameters.bezelThickness : 10;
-	var bezelSize = parameters.bezelSize !== undefined ? parameters.bezelSize : 8;
-	var bezelEnabled = parameters.bezelEnabled !== undefined ? parameters.bezelEnabled : false;
-
-	THREE.FontUtils.size = size;
-	THREE.FontUtils.divisions = curveSegments;
-
-	THREE.FontUtils.face = font;
-	THREE.FontUtils.weight = weight;
-	THREE.FontUtils.style = style;
-
-	THREE.FontUtils.bezelSize = bezelSize;
-
-	// Get a Font data json object
-
-	var data = THREE.FontUtils.drawText( text );
-
-	var vertices = data.points;
-	var faces = data.faces;
-	var contour = data.contour;
-	var bezelPoints = data.bezel;
-
-	var scope = this;
-
-	scope.vertices = [];
-	scope.faces = [];
-
-	var i, 
-		vert, vlen = vertices.length, 
-		face, flen = faces.length,
-		bezelPt, blen = bezelPoints.length;
-
-	// Back facing vertices
-
-	for ( i = 0; i < vlen; i++ ) {
-
-		vert = vertices[ i ];
-		v( vert.x, vert.y, 0 );
-
-	}
-
-	// Front facing vertices
-
-	for ( i = 0; i < vlen; i++ ) {
-	
-		vert = vertices[ i ];
-		v( vert.x, vert.y, height );
-
-	}
-
-	if ( bezelEnabled ) {
-
-		for ( i = 0; i < blen; i++ ) {
-
-			bezelPt = bezelPoints[ i ];
-			v( bezelPt.x, bezelPt.y, bezelThickness );
-
-		}
-
-		for ( i = 0; i < blen; i++ ) {
-
-			bezelPt = bezelPoints[ i ];
-			v( bezelPt.x, bezelPt.y, height - bezelThickness );
-
-		}
-
-	}
-
-	// Bottom faces
-
-	for ( i = 0; i < flen; i++ ) {
-
-		face = faces[ i ];
-		f3( face[ 2 ], face[ 1 ], face[ 0 ] );
-
-	}
-
-	// Top faces
-
-	for ( i = 0; i < flen; i++ ) {
-
-		face = faces[ i ];
-		f3( face[ 0 ] + vlen, face[ 1 ] + vlen, face[ 2 ] + vlen );
-
-	}
-
-	var lastV;
-	var j, k, l, m;
-
-	if ( bezelEnabled ) {
-
-		i = bezelPoints.length;
-
-		while ( --i > 0 ) {
-
-			if ( !lastV ) {
-
-				lastV = contour[ i ];
-
-			} else if ( lastV.equals( contour[ i ] ) ) {
 
-				// We reached the last point of a closed loop
-
-				lastV = null;
-				continue;
-
-			}
-
-			l = vlen * 2 + i;
-			m = l - 1;
-
-			// Create faces for the z-sides of the text
-
-			f4( l, m, m + blen, l + blen );
-
-			for ( j = 0; j < vlen; j++ ) {
-
-				if ( vertices[ j ].equals( contour[ i ] ) ) break;
-
-			}
-
-			for ( k = 0; k < vlen; k++ ) {
-
-				if ( vertices[ k ].equals( contour[ i - 1 ] ) ) break;
-
-			}
-
-			// Create faces for the z-sides of the text
-
-			f4( j, k, m, l );
-			f4( l + blen, m + blen, k + vlen, j + vlen );
-
-		}
-
-	} else {
-
-		i = contour.length;
-
-		while ( --i > 0 ) {
-
-			if ( !lastV ) {
-
-				lastV = contour[ i ];
-
-			} else if ( lastV.equals( contour[ i ] ) ) {
-
-				// We reached the last point of a closed loop
-
-				lastV = null;
-				continue;
-
-			}
+THREE.TextGeometry = function ( text, parameters ) {
 
-			for ( j = 0; j < vlen; j++ ) {
+	var textPath = new THREE.TextPath( text, parameters );
+	var textShapes = textPath.toShapes();
 
-				if ( vertices[ j ].equals( contour[ i ] ) ) break;
+	// translate parameters to ExtrudeGeometry API
 
-			}
+	parameters.amount = parameters.height !== undefined ? parameters.height : 50;
 
-			for ( k = 0; k < vlen; k++ ) {
+	// defaults
 
-				if ( vertices[ k ].equals( contour[ i - 1 ] ) ) break;
+	if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
+	if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
+	if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
 
-			}
+	if ( parameters.bend ) {
 
-			// Create faces for the z-sides of the text
+		var b = textShapes[ textShapes.length - 1 ].getBoundingBox();
+		var max = b.maxX;
 
-			f4( j, k, k + vlen, j + vlen );
+		parameters.bendPath = new THREE.QuadraticBezierCurve( new THREE.Vector2( 0, 0 ),
+															  new THREE.Vector2( max / 2, 120 ),
+															  new THREE.Vector2( max, 0 ) );
 
-		}
 	}
 
+	// // Bend Testings.
+	//
+	// var path = new THREE.CurvePath();
+	//
+	// path.add(new THREE.CubicBezierCurve(
+	// 		new THREE.Vector2(0, 0),
+	//   		new THREE.Vector2(10, 100),
+	// 		new THREE.Vector2(200, -10),
+	// 		new THREE.Vector2(300, 0)
+	// 	));
+	//
+	// path.add(new THREE.QuadraticBezierCurve(
+	// 	new THREE.Vector2(300, 0),
+	//   		new THREE.Vector2(450, -10),
+	// 	new THREE.Vector2(500, 100)
+	// ));
+	//
+	// parameters.bendPath = path;
+
+	// var path = new THREE.CurvePath();
+	// 	path.add(new THREE.LineCurve( 0, 0,  250, 0));
+	// 	path.add(new THREE.LineCurve( 250, 0,  300, 200));
+	//
+	// 	parameters.bendPath = path;
+
+	// var path = new THREE.SplineCurve([
+	// 		new THREE.Vector2(0, 0),
+	// 		new THREE.Vector2(100, 40),
+	// 		new THREE.Vector2(200, 0),
+	// 		new THREE.Vector2(400, 20)
+	// 	]);
+	//
+	// console.log(path);
+	//
+	// path = new THREE.LineCurve( new THREE.Vector2(0, 0),  new THREE.Vector2(400, 100));
+
+	// var bend = new THREE.Path();
+	// 	bend.moveTo(0,0);
+	// 	bend.quadraticCurveTo( 500, 100, 1000, 0 );
+	//
+	// 	parameters.bendPath = bend;
+
+
+
+	THREE.ExtrudeGeometry.call( this, textShapes, parameters );
 
-	// UVs to be added
-
-	this.computeCentroids();
-	this.computeFaceNormals();
-	//this.computeVertexNormals();
-
-	function v( x, y, z ) {
+};
 
-		scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
+THREE.TextGeometry.prototype = new THREE.ExtrudeGeometry();
+THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
 
-	}
 
-	function f3( a, b, c ) {
+/*
+	// TextGeometry wrapper
 
-		scope.faces.push( new THREE.Face3( a, b, c) );
+	var text3d = new TextGeometry( text, options );
 
-	}
+	// Complete manner
 
-	function f4( a, b, c, d ) {
+	var textPath = new TextPath( text, options );
+	var textShapes = textPath.toShapes();
+	var text3d = new ExtrudeGeometry( textShapes, options );
 
-		scope.faces.push( new THREE.Face4( a, b, c, d) );
+	// Factory Method
 
-	}
+	var textShapes = FontUtils.getTextShapes( text, options );
+	text3d = new ExtrudeGeometry( textShapes, options );
 
+*/
 
-};
 
 THREE.FontUtils = {
 
@@ -278,6 +152,14 @@ THREE.FontUtils = {
 
 	},
 
+	getTextShapes: function( text, options ) {
+
+		var textPath = new TextPath( text, options );
+		var textShapes = textPath.toShapes();
+		return textShapes;
+
+	},
+
 	loadFace : function( data ) {
 
 		var family = data.familyName.toLowerCase();
@@ -285,7 +167,7 @@ THREE.FontUtils = {
 		var ThreeFont = this;
 
 		ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
-	
+
 		ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
 		ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
 
@@ -295,6 +177,7 @@ THREE.FontUtils = {
 
 	},
 
+/* LEGACY CODE
 
 	extractPoints : function( allPoints, charactersPoints ) {
 
@@ -358,7 +241,7 @@ THREE.FontUtils = {
 				firstPt = all[ firstIndex ];
 				endPt = all.slice( firstIndex + 1 ).indexOf( firstPt ) + firstIndex;
 
-				if ( endPt <= firstIndex ) break; 
+				if ( endPt <= firstIndex ) break;
 
 				var contours = singleCharPoints.slice( firstIndex, endPt + 1 );
 
@@ -414,7 +297,7 @@ THREE.FontUtils = {
 
 		//console.log("isolatedShapes", isolatedShapes);
 
-		/* For each isolated shape, find the closest points and break to the hole to allow triangulation*/
+		// For each isolated shape, find the closest points and break to the hole to allow triangulation
 
 		// Find closest points between holes
 
@@ -472,7 +355,7 @@ THREE.FontUtils = {
 				prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
 				nextShapeVert = ( shapeIndex + 1 ) < shape.length ? shapeIndex + 1 : 0;
 
-				prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1; 
+				prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
 				nextHoleVert = ( holeIndex + 1 ) < hole.length ? holeIndex + 1 : 0 ;
 
 				var areaapts = [];
@@ -495,7 +378,7 @@ THREE.FontUtils = {
 				var oldShapeIndex = shapeIndex, oldHoleIndex = holeIndex;
 				shapeIndex += shapeOffset;
 				holeIndex += holeOffset;
-				
+
 				if ( shapeIndex < 0 ) { shapeIndex += shape.length;  }
 				shapeIndex %= shape.length;
 
@@ -505,7 +388,7 @@ THREE.FontUtils = {
 				prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
 				nextShapeVert = ( shapeIndex + 1 ) < shape.length ? shapeIndex + 1 : 0;
 
-				prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1; 
+				prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
 				nextHoleVert = ( holeIndex + 1 ) < hole.length ? holeIndex + 1 : 0 ;
 
 
@@ -538,7 +421,7 @@ THREE.FontUtils = {
 					prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
 					nextShapeVert = ( shapeIndex + 1 ) < shape.length ? shapeIndex + 1 : 0;
 
-					prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1; 
+					prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
 					nextHoleVert = ( holeIndex + 1 ) < hole.length ? holeIndex + 1 : 0 ;
 
 				}
@@ -563,7 +446,7 @@ THREE.FontUtils = {
 			shapeGroup.shape = shape;
 
 		}
-	
+
 		var triangulatedPoints = [];
 		var triangulatedFaces = [];
 		var lastTriangles = 0;
@@ -593,7 +476,7 @@ THREE.FontUtils = {
 			lastTriangles += shape.length;
 
 		}
-  
+
 
 		// Now we push the "cut" vertices back to the triangulated indices.
 
@@ -649,7 +532,7 @@ THREE.FontUtils = {
 
 		};
 
-	},
+	},*/
 
 	drawText : function( text ) {
 
@@ -660,193 +543,48 @@ THREE.FontUtils = {
 		var i, p,
 			face = this.getFace(),
 			scale = this.size / face.resolution,
-			offset = 0, 
-			chars = String( text ).split( '' ), 
+			offset = 0,
+			chars = String( text ).split( '' ),
 			length = chars.length;
 
-		for ( i = 0; i < length; i++ ) {
-
-			var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset );
-			offset += ret.offset;
-			characterPts.push( ret.points );
-			allPts = allPts.concat( ret.points );
-
-		}
-
-		// get the width 
-
-		var width = offset / 2;
-
-		for ( p = 0; p < allPts.length; p++ ) {
-
-			allPts[ p ].x -= width;
-
-		}
-
-		var extract = this.extractPoints( allPts, characterPts );
-		extract.contour = allPts;
-
-		var bezelPoints = [];
+		var fontPaths = [];
 
-		var centroids = [], forCentroids = [], expandOutwards = [], sum = new THREE.Vector2(), lastV;
+		for ( i = 0; i < length; i ++ ) {
 
-		i = allPts.length;
+			var path = new THREE.Path();
 
-		while ( --i >= 0 ) {
-
-			if ( !lastV ) {
-
-				lastV = allPts[ i ];
-
-			} else if ( lastV.equals( allPts[ i ] ) ) {
-
-				// We reached the last point of a closed loop
-
-				lastV = null;
-
-				var bool = this.Triangulate.area( forCentroids ) > 0;
-				expandOutwards.push( bool );
-				centroids.push( sum.divideScalar( forCentroids.length ) );
-				forCentroids = [];
-
-				sum = new THREE.Vector2();
-				continue;
-
-			}
-
-			sum.addSelf( allPts[ i ] );
-			forCentroids.push( allPts[ i ] );
-
-		}
-
-
-		i = allPts.length;
-		p = 0;
-		var pt, centroid ;
-		var dirV, adj;
-
-		while ( --i >= 0 ) {
-
-			pt = allPts[ i ];
-			centroid = centroids[ p ];
-
-			dirV = pt.clone().subSelf( centroid );
-			adj = this.bezelSize / dirV.length();
-
-			if ( expandOutwards[ p ] ) {
-
-				adj += 1;
-
-			}  else {
-
-				adj = 1 - adj;
-
-			}
-
-			adj = dirV.multiplyScalar( adj ).addSelf( centroid );
-			bezelPoints.unshift( adj );
-
-
-			if ( !lastV ) {
-
-				lastV = allPts[ i ];
-
-			} else if ( lastV.equals( allPts[ i ] ) ) {
-
-				// We reached the last point of a closed loop
-
-				lastV = null;
-				p++;
-				continue;
-
-			}
-
-		}
-
-
-		/*
-		for ( p = 0; p < allPts.length; p++ ) {
-
-			pt = allPts[ p ];
-			bezelPoints.push( new THREE.Vector2( pt.x + this.bezelSize, pt.y + this.bezelSize ) );
+			var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
+			offset += ret.offset;
+			//characterPts.push( ret.points );
+			//allPts = allPts.concat( ret.points );
+			fontPaths.push( ret.path );
 
 		}
-		*/
-
-		extract.bezel = bezelPoints;
-
-		return extract;
-
-	},
-
-
-	// Bezier Curves formulas obtained from
-	// http://en.wikipedia.org/wiki/B%C3%A9zier_curve
-
-	// Quad Bezier Functions
-
-	b2p0: function ( t, p ) {
-
-		var k = 1 - t;
-		return k * k * p;
-
-	},
-
-	b2p1: function ( t, p ) {
-
-		return 2 * ( 1 - t ) * t * p;
-
-	},
-
-	b2p2: function ( t, p ) {
-
-		return t * t * p;
-
-	},
-
-	b2: function ( t, p0, p1, p2 ) {
-
-		return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
-
-	},
-
-	// Cubic Bezier Functions
 
-	b3p0: function ( t, p ) {
+		// get the width
 
-		var k = 1 - t;
-		return k * k * k * p;
-
-	},
-
-	b3p1: function ( t, p ) {
-
-		var k = 1 - t;
-		return 3 * k * k * t * p;
-
-	},
-
-	b3p2: function ( t, p ) {
-
-		var k = 1 - t;
-		return 3 * k * t * t * p;
+		var width = offset / 2;
+		//
+		// for ( p = 0; p < allPts.length; p++ ) {
+		//
+		// 	allPts[ p ].x -= width;
+		//
+		// }
 
-	},
+		//var extract = this.extractPoints( allPts, characterPts );
+		//extract.contour = allPts;
 
-	b3p3: function ( t, p ) {
+		//extract.paths = fontPaths;
+		//extract.offset = width;
 
-		return t * t * t * p;
+		return { paths : fontPaths, offset : width };
 
 	},
 
-	b3: function ( t, p0, p1, p2, p3 ) {
 
-		return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) +  this.b3p3( t, p3 );
-
-	},
 
 
-	extractGlyphPoints : function( c, face, scale, offset ) {
+	extractGlyphPoints : function( c, face, scale, offset, path ) {
 
 		var pts = [];
 
@@ -856,21 +594,23 @@ THREE.FontUtils = {
 			x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
 			laste,
 			glyph = face.glyphs[ c ] || face.glyphs[ ctxt.options.fallbackCharacter ];
-	
+
 		if ( !glyph ) return;
-  
+
 		if ( glyph.o ) {
-	  
+
 			outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
 			length = outline.length;
-		
+
 			scaleX = scale;
 			scaleY = scale;
-		 
+
 			for ( i = 0; i < length; ) {
 
-				action = outline[ i++ ];
-  
+				action = outline[ i ++ ];
+
+				//console.log( action );
+
 				switch( action ) {
 
 				case 'm':
@@ -879,7 +619,10 @@ THREE.FontUtils = {
 
 					x = outline[ i++ ] * scaleX + offset;
 					y = outline[ i++ ] * scaleY;
+
 					pts.push( new THREE.Vector2( x, y ) );
+
+					path.moveTo( x, y );
 					break;
 
 				case 'l':
@@ -889,60 +632,65 @@ THREE.FontUtils = {
 					x = outline[ i++ ] * scaleX + offset;
 					y = outline[ i++ ] * scaleY;
 					pts.push( new THREE.Vector2( x, y ) );
+					path.lineTo(x,y);
 					break;
-					
+
 				case 'q':
 
 					// QuadraticCurveTo
-				  
+
 					cpx  = outline[ i++ ] * scaleX + offset;
 					cpy  = outline[ i++ ] * scaleY;
 					cpx1 = outline[ i++ ] * scaleX + offset;
 					cpy1 = outline[ i++ ] * scaleY;
-			  
+
+					path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
+
 					laste = pts[ pts.length - 1 ];
-			  
+
 					if ( laste ) {
 
 						cpx0 = laste.x;
 						cpy0 = laste.y;
-				
+
 						for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2++ ) {
 
 							var t = i2 / divisions;
-							var tx = THREE.FontUtils.b2( t, cpx0, cpx1, cpx );
-							var ty = THREE.FontUtils.b2( t, cpy0, cpy1, cpy );
+							var tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
+							var ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
 							pts.push( new THREE.Vector2( tx, ty ) );
 
 					  }
 
-				  }              
-			  
+				  }
+
 				  break;
 
 				case 'b':
 
 					// Cubic Bezier Curve
-				  
+
 					cpx  = outline[ i++ ] *  scaleX + offset;
 					cpy  = outline[ i++ ] *  scaleY;
 					cpx1 = outline[ i++ ] *  scaleX + offset;
 					cpy1 = outline[ i++ ] * -scaleY;
 					cpx2 = outline[ i++ ] *  scaleX + offset;
 					cpy2 = outline[ i++ ] * -scaleY;
-			  
+
+					path.bezierCurveTo( cpx, cpy, cpx1, cpy1, cpx2, cpy2 );
+
 					laste = pts[ pts.length - 1 ];
-			  
+
 					if ( laste ) {
 
 						cpx0 = laste.x;
 						cpy0 = laste.y;
-				
+
 						for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2++ ) {
 
 							var t = i2 / divisions;
-							var tx = THREE.FontUtils.b3( t, cpx0, cpx1, cpx2, cpx );
-							var ty = THREE.FontUtils.b3( t, cpy0, cpy1, cpy2, cpy );
+							var tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
+							var ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
 							pts.push( new THREE.Vector2( tx, ty ) );
 
 						}
@@ -956,7 +704,9 @@ THREE.FontUtils = {
 			}
 		}
 
-		return { offset: glyph.ha*scale, points:pts };
+
+
+		return { offset: glyph.ha*scale, points:pts, path:path};
 	}
 
 };
@@ -964,17 +714,17 @@ THREE.FontUtils = {
 
 
 /**
- * This code is a quick port of code written in C++ which was submitted to 
- * flipcode.com by John W. Ratcliff  // July 22, 2000 
+ * This code is a quick port of code written in C++ which was submitted to
+ * flipcode.com by John W. Ratcliff  // July 22, 2000
  * See original code and more information here:
  * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
- * 
+ *
  * ported to actionscript by Zevan Rosser
  * www.actionsnippet.com
- * 
+ *
  * ported to javascript by Joshua Koo
  * http://www.lab4games.net/zz85/blog
- * 
+ *
  */
 
 
@@ -982,7 +732,7 @@ THREE.FontUtils = {
 
 	var EPSILON = 0.0000000001;
 
-	// takes in an contour array and returns 
+	// takes in an contour array and returns
 
 	var process = function( contour, indices ) {
 
@@ -991,7 +741,7 @@ THREE.FontUtils = {
 		if ( n < 3 ) return null;
 
 		var result = [],
-			verts = [], 
+			verts = [],
 			vertIndices = [];
 
 		/* we want a counter-clockwise polygon in verts */
@@ -1024,7 +774,7 @@ THREE.FontUtils = {
 
 				//throw ( "Warning, unable to triangulate polygon!" );
 				//return null;
-
+				// Sometimes warning is fine, especially polygons are triangulated in reverse.
 				console.log( "Warning, unable to triangulate polygon!" );
 
 				if ( indices ) return vertIndices;
@@ -1033,39 +783,45 @@ THREE.FontUtils = {
 			}
 
 			/* three consecutive vertices in current polygon, <u,v,w> */
-			
+
 			u = v; 	 	if ( nv <= u ) u = 0;     /* previous */
 			v = u + 1;  if ( nv <= v ) v = 0;     /* new v    */
 			w = v + 1;  if ( nv <= w ) w = 0;     /* next     */
-			
+
 			if ( snip( contour, u, v, w, nv, verts ) ) {
 
 				var a, b, c, s, t;
-			
+
 				/* true names of the vertices */
 
-				a = verts[ u ]; 
-				b = verts[ v ]; 
+				a = verts[ u ];
+				b = verts[ v ];
 				c = verts[ w ];
 
 				/* output Triangle */
 
+				/*
 				result.push( contour[ a ] );
 				result.push( contour[ b ] );
 				result.push( contour[ c ] );
+				*/
+				result.push( [ contour[ a ],
+					contour[ b ],
+					contour[ c ] ] );
+
 
 				vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
-			
+
 				/* remove v from the remaining polygon */
 
 				for( s = v, t = v + 1; t < nv; s++, t++ ) {
-					
-					verts[ s ] = verts[ t ]; 
+
+					verts[ s ] = verts[ t ];
 
 				}
 
 				nv--;
-			
+
 				/* reset error detection counter */
 
 				count = 2 * nv;
@@ -1073,19 +829,19 @@ THREE.FontUtils = {
 			}
 
 		}
-		
+
 		if ( indices ) return vertIndices;
 		return result;
 
 	};
-	
+
 	// calculate area of the contour polygon
 
 	var area = function ( contour ) {
 
 		var n = contour.length;
 		var a = 0.0;
-		
+
 		for( var p = n - 1, q = 0; q < n; p = q++ ) {
 
 			a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
@@ -1095,7 +851,7 @@ THREE.FontUtils = {
 		return a * 0.5;
 
 	};
-	
+
 	// see if p is inside triangle abc
 
 	var insideTriangle = function( ax, ay,
@@ -1107,23 +863,23 @@ THREE.FontUtils = {
 		  var cX, cY, apx, apy;
 		  var bpx, bpy, cpx, cpy;
 		  var cCROSSap, bCROSScp, aCROSSbp;
-		
+
 		  aX = cx - bx;  aY = cy - by;
 		  bX = ax - cx;  bY = ay - cy;
 		  cX = bx - ax;  cY = by - ay;
 		  apx= px  -ax;  apy= py - ay;
 		  bpx= px - bx;  bpy= py - by;
 		  cpx= px - cx;  cpy= py - cy;
-		
+
 		  aCROSSbp = aX*bpy - aY*bpx;
 		  cCROSSap = cX*apy - cY*apx;
 		  bCROSScp = bX*cpy - bY*cpx;
-		
+
 		  return ( (aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0) );
 
 	};
-	
-	
+
+
 	var snip = function ( contour, u, v, w, n, verts ) {
 
 		var p;
@@ -1138,13 +894,13 @@ THREE.FontUtils = {
 
 		cx = contour[ verts[ w ] ].x;
 		cy = contour[ verts[ w ] ].y;
-		
+
 		if ( EPSILON > (((bx-ax)*(cy-ay)) - ((by-ay)*(cx-ax))) ) return false;
-		
+
 			for ( p = 0; p < n; p++ ) {
 
 				if( (p == u) || (p == v) || (p == w) ) continue;
-			
+
 				px = contour[ verts[ p ] ].x
 				py = contour[ verts[ p ] ].y
 
@@ -1155,11 +911,11 @@ THREE.FontUtils = {
 		  return true;
 
 	};
-	
-	
+
+
 	namespace.Triangulate = process;
 	namespace.Triangulate.area = area;
-	
+
 	return namespace;
 
 })(THREE.FontUtils);

+ 68 - 0
src/extras/geometries/TextPath.js

@@ -0,0 +1,68 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ *
+ * TextPath
+ *
+ **/
+
+THREE.TextPath = function ( text, parameters ) {
+
+	THREE.Path.call( this );
+
+	this.parameters = parameters || {};
+
+	this.set( text );
+
+};
+
+THREE.TextPath.prototype.set = function ( text, parameters ) {
+
+	this.text = text;
+
+	var parameters = parameters || this.parameters;
+
+	var size = parameters.size !== undefined ? parameters.size : 100;
+	var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments: 4;
+
+	var font = parameters.font !== undefined ? parameters.font : "helvetiker";
+	var weight = parameters.weight !== undefined ? parameters.weight : "normal";
+	var style = parameters.style !== undefined ? parameters.style : "normal";
+
+	THREE.FontUtils.size = size;
+	THREE.FontUtils.divisions = curveSegments;
+
+	THREE.FontUtils.face = font;
+	THREE.FontUtils.weight = weight;
+	THREE.FontUtils.style = style;
+
+};
+
+
+
+THREE.TextPath.prototype.toShapes = function () {
+
+	// Get a Font data json object
+
+	var data = THREE.FontUtils.drawText( this.text );
+
+	var paths = data.paths;
+	var shapes = [];
+
+	for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
+
+		shapes = shapes.concat( paths[ p ].toShapes() );
+
+	}
+
+	return shapes;
+
+	//console.log(path);
+	//console.log(fontShapes);
+
+	// Either find actions or curves.
+
+	//var text3d = new THREE.ExtrudeGeometry( shapes , { amount: 20, bevelEnabled:true, bevelThickness:3	} );
+
+	//return text3d;
+
+};

+ 0 - 2
src/extras/geometries/TorusGeometry.js

@@ -54,8 +54,6 @@ THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT ) {
 
 	}
 
-	delete temp_uv;
-
 	this.computeCentroids();
 	this.computeFaceNormals();
 	this.computeVertexNormals();

+ 3 - 1
src/extras/io/BinaryLoader.js

@@ -767,6 +767,8 @@ THREE.BinaryLoader.prototype = {
 		uv.push( new THREE.UV( u4, v4 ) );
 		where.push( uv );
 
-	}
+	},
+	
+	constructor : THREE.BinaryLoader
 
 };

+ 3 - 1
src/extras/io/Loader.js

@@ -366,6 +366,8 @@ THREE.Loader.prototype = {
 
 		return material;
 
-	}
+	},
+	
+	constructor : THREE.Loader
 
 };

+ 3 - 1
src/extras/io/LoaderOld.js

@@ -1318,6 +1318,8 @@ THREE.LoaderOld.prototype = {
 		chunks.pop();
 		return chunks.join( "/" );
 		
-	}
+	},
+	
+	constructor : THREE.LoaderOld
 
 };

+ 3 - 1
src/extras/io/SceneLoader.js

@@ -763,6 +763,8 @@ THREE.SceneLoader.prototype = {
 
 		};
 
-	}
+	},
+	
+	constructor : THREE.SceneLoader
 
 };

+ 350 - 0
src/extras/io/UTF8Loader.js

@@ -0,0 +1,350 @@
+/**
+ * Loader for UTF8 encoded models generated by:
+ *	http://code.google.com/p/webgl-loader/
+ *
+ * Limitations:
+ *  - number of vertices < 65536 (this is after optimizations in compressor, input OBJ may have even less)
+ *	- models must have normals and texture coordinates
+ *  - texture coordinates must be only from <0,1>
+ *  - no materials support yet
+ *  - models are scaled and offset (copy numbers from compressor and use them as parameters in UTF8Loader.load() )
+ *
+ * @author alteredq / http://alteredqualia.com/
+ * @author won3d / http://twitter.com/won3d
+ */
+
+THREE.UTF8Loader = function ( ) {
+
+};
+
+THREE.UTF8Loader.prototype = new THREE.UTF8Loader();
+THREE.UTF8Loader.prototype.constructor = THREE.UTF8Loader;
+
+
+THREE.UTF8Loader.prototype = {
+
+	// Load UTF8 compressed models generated by objcompress
+	//  - parameters
+	//		- model (required)
+	//		- callback (required)
+
+	load: function( parameters ) {
+
+		var xhr = new XMLHttpRequest(),
+			url = parameters.model,
+
+			callback = parameters.callback,
+			callback_progress = null,
+
+			scale = parameters.scale !== undefined ? parameters.scale : 1,
+			offsetX = parameters.offsetX !== undefined ? parameters.offsetX : 0,
+			offsetY = parameters.offsetY !== undefined ? parameters.offsetY : 0,
+			offsetZ = parameters.offsetZ !== undefined ? parameters.offsetZ : 0;
+
+		var length = 0;
+
+		xhr.onreadystatechange = function() {
+
+			if ( xhr.readyState == 4 ) {
+
+				if ( xhr.status == 200 || xhr.status == 0 ) {
+
+					THREE.UTF8Loader.prototype.createModel( xhr.responseText, callback, scale, offsetX, offsetY, offsetZ );
+
+				} else {
+
+					alert( "Couldn't load [" + url + "] [" + xhr.status + "]" );
+
+				}
+
+			} else if ( xhr.readyState == 3 ) {
+
+				if ( callback_progress ) {
+
+					if ( length == 0 ) {
+
+						length = xhr.getResponseHeader( "Content-Length" );
+
+					}
+
+					callback_progress( { total: length, loaded: xhr.responseText.length } );
+
+				}
+
+			} else if ( xhr.readyState == 2 ) {
+
+				length = xhr.getResponseHeader( "Content-Length" );
+
+			}
+
+		}
+
+		xhr.open( "GET", url, true );
+		xhr.send( null );
+
+	},
+
+	// UTF-8 decoder from webgl-loader
+	// http://code.google.com/p/webgl-loader/
+
+	// Copyright 2011 Google Inc. All Rights Reserved.
+	//
+	// Licensed under the Apache License, Version 2.0 (the "License"); you
+	// may not use this file except in compliance with the License. You
+	// may obtain a copy of the License at
+	//
+	// http://www.apache.org/licenses/LICENSE-2.0
+	//
+	// Unless required by applicable law or agreed to in writing, software
+	// distributed under the License is distributed on an "AS IS" BASIS,
+	// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+	// implied. See the License for the specific language governing
+	// permissions and limitations under the License.
+
+	decompressMesh: function ( str ) {
+
+		var num_verts = str.charCodeAt( 0 );
+
+		if ( num_verts >= 0xE000 ) {
+
+			num_verts -= 0x0800;
+
+		}
+
+		num_verts ++;
+
+		var attribs_out = new Float32Array( 8 * num_verts );
+
+		var offset = 1;
+
+		for ( var i = 0; i < 8; i ++ ) {
+
+			var prev_attrib = 0;
+
+			for ( var j = 0; j < num_verts; ++ j ) {
+
+				var code = str.charCodeAt( j + offset );
+
+				prev_attrib += ( code >> 1 ) ^ ( - ( code & 1 ) );
+
+				attribs_out[ 8 * j + i ] = prev_attrib;
+
+			}
+
+			offset += num_verts;
+
+		}
+
+		var num_indices = str.length - offset;
+
+		var indices_out = new Uint16Array( num_indices );
+
+		var index_high_water_mark = 0;
+
+		for ( var i = 0; i < num_indices; i ++ ) {
+
+			var code = str.charCodeAt( i + offset );
+
+			indices_out[ i ] = index_high_water_mark - code;
+
+			if ( code == 0 ) {
+
+				index_high_water_mark ++;
+
+			}
+
+		}
+
+		return [ attribs_out, indices_out ];
+
+	},
+
+	createModel: function ( data, callback, scale, offsetX, offsetY, offsetZ ) {
+
+		var Model = function ( texture_path ) {
+
+			//var s = (new Date).getTime();
+
+			var scope = this;
+
+			scope.materials = [];
+
+			THREE.Geometry.call( this );
+
+			var buffers = THREE.UTF8Loader.prototype.decompressMesh( data );
+
+			var normals = [],
+				uvs = [];
+
+			init_vertices( buffers[ 0 ], 8, 0 );
+			init_uvs( buffers[ 0 ], 8, 3 );
+			init_normals( buffers[ 0 ], 8, 5 );
+
+			init_faces( buffers[ 1 ] );
+
+			this.computeCentroids();
+			this.computeFaceNormals();
+			//this.computeTangents();
+
+			//var e = (new Date).getTime();
+
+			//console.log( "utf8 data parse time: " + (e-s) + " ms" );
+
+			function init_vertices( data, stride, offset ) {
+
+				var i, x, y, z,
+					end = data.length;
+
+				for( i = offset; i < end; i += stride ) {
+
+					x = data[ i ];
+					y = data[ i + 1 ];
+					z = data[ i + 2 ];
+
+					// fix scale and offsets
+
+					x = ( x / 16383 ) * scale;
+					y = ( y / 16383 ) * scale;
+					z = ( z / 16383 ) * scale;
+
+					x += offsetX;
+					y += offsetY;
+					z += offsetZ;
+
+					THREE.UTF8Loader.prototype.v( scope, x, y, z );
+
+				}
+
+			}
+
+			function init_normals( data, stride, offset ) {
+
+				var i, x, y, z,
+					end = data.length;
+
+				for( i = offset; i < end; i += stride ) {
+
+					x = data[ i ];
+					y = data[ i + 1 ];
+					z = data[ i + 2 ];
+
+					// normalize to <-1,1>
+
+					x = ( x - 512 ) / 511;
+					y = ( y - 512 ) / 511;
+					z = ( z - 512 ) / 511;
+
+					normals.push( x, y, z );
+
+				}
+
+			}
+
+			function init_uvs( data, stride, offset ) {
+
+				var i, u, v,
+					end = data.length;
+
+				for( i = offset; i < end; i += stride ) {
+
+					u = data[ i ];
+					v = data[ i + 1 ];
+
+					// normalize to <0,1>
+
+					u /= 1023;
+					v /= 1023;
+
+					uvs.push( u, v );
+
+				}
+
+			}
+
+			function init_faces( indices ) {
+
+				var i,
+					a, b, c,
+					u1, v1, u2, v2, u3, v3,
+					m,
+					end = indices.length;
+
+				m = 0; // all faces defaulting to material 0
+
+				for( i = 0; i < end; i += 3 ) {
+
+					a = indices[ i ];
+					b = indices[ i + 1 ];
+					c = indices[ i + 2 ];
+
+					THREE.UTF8Loader.prototype.f3n( scope, normals, a, b, c, m, a, b, c );
+
+					u1 = uvs[ a * 2 ];
+					v1 = uvs[ a * 2 + 1 ];
+
+					u2 = uvs[ b * 2 ];
+					v2 = uvs[ b * 2 + 1 ];
+
+					u3 = uvs[ c * 2 ];
+					v3 = uvs[ c * 2 + 1 ];
+
+					THREE.UTF8Loader.prototype.uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 );
+
+				}
+
+
+			}
+
+		}
+
+		Model.prototype = new THREE.Geometry();
+		Model.prototype.constructor = Model;
+
+		callback( new Model() );
+
+	},
+
+
+	v: function( scope, x, y, z ) {
+
+		scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
+
+	},
+
+	f3n: function( scope, normals, a, b, c, mi, na, nb, nc ) {
+
+		var material = scope.materials[ mi ],
+
+			nax = normals[ na * 3     ],
+			nay = normals[ na * 3 + 1 ],
+			naz = normals[ na * 3 + 2 ],
+
+			nbx = normals[ nb * 3     ],
+			nby = normals[ nb * 3 + 1 ],
+			nbz = normals[ nb * 3 + 2 ],
+
+			ncx = normals[ nc * 3     ],
+			ncy = normals[ nc * 3 + 1 ],
+			ncz = normals[ nc * 3 + 2 ];
+
+		var na = new THREE.Vector3( nax, nay, naz ),
+			nb = new THREE.Vector3( nbx, nby, nbz ),
+			nc = new THREE.Vector3( ncx, ncy, ncz );
+
+		scope.faces.push( new THREE.Face3( a, b, c, [ na, nb, nc ], null, material ) );
+
+	},
+
+	uv3: function( where, u1, v1, u2, v2, u3, v3 ) {
+
+		var uv = [];
+		uv.push( new THREE.UV( u1, v1 ) );
+		uv.push( new THREE.UV( u2, v2 ) );
+		uv.push( new THREE.UV( u3, v3 ) );
+		where.push( uv );
+
+	},
+
+	constructor : THREE.UTF8Loader
+
+};

+ 0 - 87
src/lights/LensFlare.js

@@ -1,87 +0,0 @@
-/**
- * @author Mikael Emtinger
- */
- 
-THREE.LensFlare = function ( texture, size, distance, blending ) {
-
-	THREE.Object3D.call( this );
-
-	this.positionScreen = new THREE.Vector3();
-	this.lensFlares = [];
-	this.customUpdateCallback = undefined;
-
-	if( texture !== undefined ) {
-		
-		this.add( texture, size, distance, blending );
-		
-	}
-
-};
-
-THREE.LensFlare.prototype = new THREE.Object3D();
-THREE.LensFlare.prototype.constructor = THREE.LensFlare;
-THREE.LensFlare.prototype.supr = THREE.Object3D.prototype;
-
-
-/*
- * Add: adds another flare 
- */
-
-THREE.LensFlare.prototype.add = function( texture, size, distance, blending ) {
-	
-	if( size === undefined ) size = -1;
-	if( distance === undefined ) distance = 0;
-	if( blending === undefined ) blending = THREE.BillboardBlending;
-	
-	distance = Math.min( distance, Math.max( 0, distance ));
-
-	this.lensFlares.push( { texture: texture, 			// THREE.Texture
-		                    size: size, 				// size in pixels (-1 = use texture.width)
-		                    distance: distance, 		// distance (0-1) from light source (0=at light source)
-		                    x: 0, y: 0, z: 0,			// screen position (-1 => 1) z = 0 is ontop z = 1 is back 
-		                    scale: 1, 					// scale
-		                    rotation: 1, 				// rotation
-		                    opacity: 1,					// opacity
-		                    blending: blending } );		// blending
-
-};
-
-
-/*
- * Update lens flares update positions on all flares based on the screen position
- * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
- */
-
-THREE.LensFlare.prototype.updateLensFlares = function() {
-	
-	var f, fl = this.lensFlares.length;
-	var flare;
-	var vecX = -this.positionScreen.x * 2;
-	var vecY = -this.positionScreen.y * 2; 
-	
-	
-	for( f = 0; f < fl; f++ ) {
-		
-		flare = this.lensFlares[ f ];
-		
-		flare.x = this.positionScreen.x + vecX * flare.distance;
-		flare.y = this.positionScreen.y + vecY * flare.distance;
-
-		flare.wantedRotation = flare.x * Math.PI * 0.25;
-		flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
-
-	}
-
-};
-
-
-
-
-
-
-
-
-
-
-
-

+ 20 - 0
src/lights/SpotLight.js

@@ -0,0 +1,20 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.SpotLight = function ( hex, intensity, distance, castShadow ) {
+
+	THREE.Light.call( this, hex );
+
+	this.position = new THREE.Vector3( 0, 1, 0 );
+	this.target = new THREE.Object3D();
+
+	this.intensity = intensity || 1;
+	this.distance = distance || 0;
+
+	this.castShadow = castShadow !== undefined ? castShadow : false;
+
+};
+
+THREE.SpotLight.prototype = new THREE.Light();
+THREE.SpotLight.prototype.constructor = THREE.SpotLight;

+ 31 - 0
src/materials/DataTexture.js

@@ -0,0 +1,31 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ */
+
+THREE.DataTexture = function ( data, width, height, format, mapping, wrapS, wrapT, magFilter, minFilter ) {
+
+	THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter );
+
+	this.image = { data: data, width: width, height: height };
+
+	this.format = format !== undefined ? format : THREE.RGBAFormat;
+
+};
+
+THREE.DataTexture.prototype = new THREE.Texture();
+THREE.DataTexture.prototype.constructor = THREE.DataTexture;
+
+THREE.DataTexture.prototype = {
+
+	clone: function () {
+
+		var clonedTexture = new THREE.DataTexture( this.data.slice( 0 ), this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
+
+		clonedTexture.offset.copy( this.offset );
+		clonedTexture.repeat.copy( this.repeat );
+
+		return clonedTexture;
+
+	}
+
+};

+ 5 - 4
src/materials/Material.js

@@ -4,7 +4,7 @@
 
 THREE.Material = function ( parameters ) {
 
-	this.id = THREE.MaterialCounter.value ++;
+	this.id = THREE.MaterialCount ++;
 
 	parameters = parameters || {};
 
@@ -18,8 +18,12 @@ THREE.Material = function ( parameters ) {
 	this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0;
 	this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0;
 
+	this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0;
+
 }
 
+THREE.MaterialCount = 0;
+
 THREE.NoShading = 0;
 THREE.FlatShading = 1;
 THREE.SmoothShading = 2;
@@ -33,6 +37,3 @@ THREE.AdditiveBlending = 1;
 THREE.SubtractiveBlending = 2;
 THREE.MultiplyBlending = 3;
 THREE.AdditiveAlphaBlending = 4;
-
-
-THREE.MaterialCounter = { value: 0 };

+ 0 - 63
src/materials/ShadowVolumeDynamicMaterial.js

@@ -1,63 +0,0 @@
-/**
- * @author mr.doob / http://mrdoob.com/
- * @author alteredq / http://alteredqualia.com/
- *
- * parameters = {
- *  color: <hex>,
- *  opacity: <float>,
- *  map: new THREE.Texture( <Image> ),
- 
- *  lightMap: new THREE.Texture( <Image> ),
- 
- *  envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
- *  combine: THREE.Multiply,
- *  reflectivity: <float>,
- *  refractionRatio: <float>,
- 
- *  shading: THREE.SmoothShading,
- *  blending: THREE.NormalBlending,
- *  depthTest: <bool>,
- 
- *  wireframe: <boolean>,
- *  wireframeLinewidth: <float>,
- 
- *  vertexColors: <bool>,
- *  skinning: <bool>
- * }
- */
-
-THREE.ShadowVolumeDynamicMaterial = function ( parameters ) {
-
-	THREE.Material.call( this, parameters );
-
-	parameters = parameters || {};
-
-	this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
-
-	this.map = parameters.map !== undefined ? parameters.map : null;
-
-	this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
-
-	this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
-	this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
-	this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
-	this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
-
-	// this.enableFog = parameters.enableFog ? parameters.enableFog : true;
-
-	this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
-
-	this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
-	this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
-	this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
-	this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
-
-	this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false;
-
-	this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
-	this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
-
-};
-
-THREE.ShadowVolumeDynamicMaterial.prototype = new THREE.Material();
-THREE.ShadowVolumeDynamicMaterial.prototype.constructor = THREE.ShadowVolumeDynamicMaterial;

+ 12 - 1
src/materials/Texture.js

@@ -6,6 +6,8 @@
 
 THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter ) {
 
+	this.id = THREE.TextureCount ++;
+
 	this.image = image;
 
 	this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
@@ -25,14 +27,23 @@ THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter )
 
 THREE.Texture.prototype = {
 
+	constructor: THREE.Texture,
+
 	clone: function () {
 
-		return new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
+		var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
+
+		clonedTexture.offset.copy( this.offset );
+		clonedTexture.repeat.copy( this.repeat );
+
+		return clonedTexture;
 
 	}
 
 };
 
+THREE.TextureCount = 0;
+
 THREE.MultiplyOperation = 0;
 THREE.MixOperation = 1;
 

+ 3 - 2
src/objects/Mesh.js

@@ -36,7 +36,7 @@ THREE.Mesh = function ( geometry, materials ) {
 			this.morphTargetInfluences = [];
 			this.morphTargetDictionary = {};
 
-			for( var m = 0; m < this.geometry.morphTargets.length; m++ ) {
+			for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) {
 
 				this.morphTargetInfluences.push( 0 );
 				this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
@@ -65,6 +65,7 @@ THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
 		return this.morphTargetDictionary[ name ];
 	}
 
-	console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );	
+	console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
 	return 0;
+
 }

+ 0 - 345
src/objects/ShadowVolume.js

@@ -1,345 +0,0 @@
-/**
- * @author mikael emtinger / http://gomo.se/
- */
-
-THREE.ShadowVolume = function( meshOrGeometry, isStatic ) {
-
-	if( meshOrGeometry instanceof THREE.Mesh ) {
-
-		THREE.Mesh.call( this, meshOrGeometry.geometry, isStatic ? [ new THREE.ShadowVolumeDynamicMaterial() ] : [ new THREE.ShadowVolumeDynamicMaterial() ] );
-		meshOrGeometry.addChild( this );
-
-	} else {
-
-		THREE.Mesh.call( this, meshOrGeometry, isStatic ? [ 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;
-
-
-/*
- * Calculate Shadow Faces
- */
-
-THREE.ShadowVolume.prototype.calculateShadowVolumeGeometry = function() {
-
-	if ( this.geometry.edges && this.geometry.edges.length ) {
-
-		var f, fl, face, faceA, faceB, faceAIndex, faceBIndex, vertexA, vertexB;
-		var faceACombination, faceBCombination;
-		var faceAvertexAIndex, faceAvertexBIndex, faceBvertexAIndex, faceBvertexBIndex;
-		var e, el, edge, temp;
-
-		var newGeometry = new THREE.Geometry();
-		var vertices = newGeometry.vertices = this.geometry.vertices;
-		var faces = newGeometry.faces = this.geometry.faces;
-		var edges = newGeometry.egdes = this.geometry.edges;
-		var edgeFaces = newGeometry.edgeFaces = [];
-
-		var vertexOffset = 0;
-		var vertexOffsetPerFace = [];
-
-		for( f = 0, fl = faces.length; f < fl; f++ ) {
-
-			face = faces[ f ];
-
-			// calculate faces vertex offset
-
-			vertexOffsetPerFace.push( vertexOffset );
-			vertexOffset += face instanceof THREE.Face3 ? 3 : 4;
-
-			// set vertex normals to face normal
-
-			face.vertexNormals[ 0 ] = face.normal;
-			face.vertexNormals[ 1 ] = face.normal;
-			face.vertexNormals[ 2 ] = face.normal;
-
-			if( face instanceof THREE.Face4 ) face.vertexNormals[ 3 ] = face.normal;
-
-		}
-
-
-		// setup edge faces
-
-		for( e = 0, el = edges.length; e < el; e++ ) {
-
-			edge = edges[ e ];
-
-			faceA = edge.faces[ 0 ];
-			faceB = edge.faces[ 1 ];
-
-			faceAIndex = edge.faceIndices[ 0 ];
-			faceBIndex = edge.faceIndices[ 1 ];
-
-			vertexA = edge.vertexIndices[ 0 ];
-			vertexB = edge.vertexIndices[ 1 ];
-
-			// find combination and processed vertex index (vertices are split up by renderer)
-
-			     if( faceA.a === vertexA ) { faceACombination = "a"; faceAvertexAIndex = vertexOffsetPerFace[ faceAIndex ] + 0; }
-			else if( faceA.b === vertexA ) { faceACombination = "b"; faceAvertexAIndex = vertexOffsetPerFace[ faceAIndex ] + 1; }
-			else if( faceA.c === vertexA ) { faceACombination = "c"; faceAvertexAIndex = vertexOffsetPerFace[ faceAIndex ] + 2; }
-			else if( faceA.d === vertexA ) { faceACombination = "d"; faceAvertexAIndex = vertexOffsetPerFace[ faceAIndex ] + 3; }
-
-			     if( faceA.a === vertexB ) { faceACombination += "a"; faceAvertexBIndex = vertexOffsetPerFace[ faceAIndex ] + 0; }
-			else if( faceA.b === vertexB ) { faceACombination += "b"; faceAvertexBIndex = vertexOffsetPerFace[ faceAIndex ] + 1; }
-			else if( faceA.c === vertexB ) { faceACombination += "c"; faceAvertexBIndex = vertexOffsetPerFace[ faceAIndex ] + 2; }
-			else if( faceA.d === vertexB ) { faceACombination += "d"; faceAvertexBIndex = vertexOffsetPerFace[ faceAIndex ] + 3; }
-
-			     if( faceB.a === vertexA ) { faceBCombination = "a"; faceBvertexAIndex = vertexOffsetPerFace[ faceBIndex ] + 0; }
-			else if( faceB.b === vertexA ) { faceBCombination = "b"; faceBvertexAIndex = vertexOffsetPerFace[ faceBIndex ] + 1; }
-			else if( faceB.c === vertexA ) { faceBCombination = "c"; faceBvertexAIndex = vertexOffsetPerFace[ faceBIndex ] + 2; }
- 			else if( faceB.d === vertexA ) { faceBCombination = "d"; faceBvertexAIndex = vertexOffsetPerFace[ faceBIndex ] + 3; }
-
-			     if( faceB.a === vertexB ) { faceBCombination += "a"; faceBvertexBIndex = vertexOffsetPerFace[ faceBIndex ] + 0; }
-			else if( faceB.b === vertexB ) { faceBCombination += "b"; faceBvertexBIndex = vertexOffsetPerFace[ faceBIndex ] + 1; }
-			else if( faceB.c === vertexB ) { faceBCombination += "c"; faceBvertexBIndex = vertexOffsetPerFace[ faceBIndex ] + 2; }
-			else if( faceB.d === vertexB ) { faceBCombination += "d"; faceBvertexBIndex = vertexOffsetPerFace[ faceBIndex ] + 3; }
-
-			if( faceACombination === "ac" ||
-				faceACombination === "ad" ||
-				faceACombination === "ca" ||
-				faceACombination === "da" ) {
-
-				if( faceAvertexAIndex > faceAvertexBIndex ) {
-
-					temp = faceAvertexAIndex;
-					faceAvertexAIndex = faceAvertexBIndex;
-					faceAvertexBIndex = temp;
-
-				}
-
-			} else {
-
-				if( faceAvertexAIndex < faceAvertexBIndex ) {
-
-					temp = faceAvertexAIndex;
-					faceAvertexAIndex = faceAvertexBIndex;
-					faceAvertexBIndex = temp;
-
-				}
-
-			}
-
-			if( faceBCombination === "ac" ||
-				faceBCombination === "ad" ||
-				faceBCombination === "ca" ||
-				faceBCombination === "da" ) {
-
-				if( faceBvertexAIndex > faceBvertexBIndex ) {
-
-					temp = faceBvertexAIndex;
-					faceBvertexAIndex = faceBvertexBIndex;
-					faceBvertexBIndex = temp;
-
-				}
-
-			} else {
-
-				if( faceBvertexAIndex < faceBvertexBIndex ) {
-
-					temp = faceBvertexAIndex;
-					faceBvertexAIndex = faceBvertexBIndex;
-					faceBvertexBIndex = temp;
-
-				}
-
-			}
-
-			face = new THREE.Face4( faceAvertexAIndex, faceAvertexBIndex, faceBvertexAIndex, faceBvertexBIndex );
-			face.normal.set( 1, 0, 0 );
-			edgeFaces.push( face );
-
-		}
-
-		this.geometry = newGeometry;
-
-	} else {
-
-		this.calculateShadowVolumeGeometryWithoutEdgeInfo( this.geometry );
-
-	}
-}
-
-
-THREE.ShadowVolume.prototype.calculateShadowVolumeGeometryWithoutEdgeInfo = function( originalGeometry ) {
-
-	// create geometry
-
-	this.geometry = new THREE.Geometry();
-	this.geometry.boundingSphere = originalGeometry.boundingSphere;
-	this.geometry.edgeFaces = [];
-
-	// copy vertices / faces from original mesh
-
-	var vertexTypes = this.geometry.vertexTypes;
-	var vertices    = this.geometry.vertices;
-	var	faces       = this.geometry.faces;
-	var edgeFaces   = this.geometry.edgeFaces;
-
-	var originalFaces    = originalGeometry.faces;
-	var originalVertices = originalGeometry.vertices;
-	var	fl               = originalFaces.length;
-
-	var	originalFace, face, i, f, n, vertex, numVertices;
-	var indices = [ "a", "b", "c", "d" ];
-
-
-	for( f = 0; f < fl; f++ ) {
-
-		numVertices = vertices.length;
-		originalFace = originalFaces[ f ];
-
-		if ( originalFace instanceof THREE.Face4 ) {
-
-			n = 4;
-			face = new THREE.Face4( numVertices, numVertices + 1, numVertices + 2, numVertices + 3 );
-
-		} else {
-
-          	n = 3;
-			face = new THREE.Face3( numVertices, numVertices + 1, numVertices + 2 );
-
-		}
-
-		face.normal.copy( originalFace.normal );
-		faces.push( face );
-
-
-		for( i = 0; i < n; i++ ) {
-
-			vertex = originalVertices[ originalFace[ indices[ i ]]];
-			vertices.push( new THREE.Vertex( vertex.position.clone()));
-
-		}
-
-	}
-
-
-	// calculate edge faces
-
-	var result, faceA, faceB, v, vl;
-
-	for( var fa = 0; fa < originalFaces.length - 1; fa++ ) {
-
-		faceA = faces[ fa ];
-
-		for( var fb = fa + 1; fb < originalFaces.length; fb++ ) {
-
-			faceB = faces[ fb ];
-			result = this.facesShareEdge( vertices, faceA, faceB );
-
-			if( result !== undefined ) {
-
-				numVertices = vertices.length;
-				face = new THREE.Face4( result.indices[ 0 ], result.indices[ 3 ], result.indices[ 2 ], result.indices[ 1 ] );
-				face.normal.set( 1, 0, 0 );
-				edgeFaces.push( face );
-
-			}
-
-		}
-
-	}
-
-};
-
-
-THREE.ShadowVolume.prototype.facesShareEdge = function( vertices, faceA, faceB ) {
-
-	var indicesA,
-		indicesB,
-		indexA,
-		indexB,
-		vertexA,
-		vertexB,
-		savedVertexA,
-		savedVertexB,
-		savedIndexA,
-		savedIndexB,
-		indexLetters,
-		a, b,
-		numMatches = 0,
-		indices = [ "a", "b", "c", "d" ];
-
-	if( faceA instanceof THREE.Face4 ) indicesA = 4;
-	else                               indicesA = 3;
-
-	if( faceB instanceof THREE.Face4 ) indicesB = 4;
-	else                               indicesB = 3;
-
-
-	for( a = 0; a < indicesA; a++ ) {
-
-		indexA  = faceA[ indices[ a ] ];
-		vertexA = vertices[ indexA ];
-
-		for( b = 0; b < indicesB; b++ ) {
-
-			indexB  = faceB[ indices[ b ] ];
-			vertexB = vertices[ indexB ];
-
-			if( Math.abs( vertexA.position.x - vertexB.position.x ) < 0.0001 &&
-				Math.abs( vertexA.position.y - vertexB.position.y ) < 0.0001 &&
-				Math.abs( vertexA.position.z - vertexB.position.z ) < 0.0001 ) {
-
-				numMatches++;
-
-				if( numMatches === 1 ) {
-
- 					savedVertexA = vertexA;
- 					savedVertexB = vertexB;
-					savedIndexA  = indexA;
-					savedIndexB  = indexB;
-					indexLetters = indices[ a ];
-
-				}
-
-				if( numMatches === 2 ) {
-
-					indexLetters += indices[ a ];
-
-					if( indexLetters === "ad" || indexLetters === "ac" ) {
-
-						return {
-
-							faces   	: [ faceA, faceB ],
-							vertices	: [ savedVertexA, savedVertexB, vertexB, vertexA  ],
-							indices		: [ savedIndexA,  savedIndexB,  indexB,  indexA   ],
-							vertexTypes	: [ 1, 2, 2, 1 ],
-							extrudable	: true
-
-						};
-
-					} else {
-
-						return {
-
-							faces   	: [ faceA, faceB ],
-							vertices	: [ savedVertexA, vertexA, vertexB, savedVertexB ],
-							indices		: [ savedIndexA,  indexA,  indexB,  savedIndexB  ],
-							vertexTypes	: [ 1, 1, 2, 2 ],
-							extrudable	: true
-
-						};
-
-					}
-
-				}
-
-			}
-
-		}
-
-	}
-
-	return undefined;
-
-};

+ 93 - 75
src/renderers/CanvasRenderer.js

@@ -39,9 +39,11 @@ THREE.CanvasRenderer = function ( parameters ) {
 	_color3 = new THREE.Color( 0x000000 ),
 	_color4 = new THREE.Color( 0x000000 ),
 
+	_patterns = [],
+
 	_near, _far,
 
-	_bitmap, _uvs,
+	_image, _uvs,
 	_uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y,
 
 	_clipRect = new THREE.Rectangle(),
@@ -96,8 +98,8 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		_canvasWidth = width;
 		_canvasHeight = height;
-		_canvasWidthHalf = _canvasWidth / 2;
-		_canvasHeightHalf = _canvasHeight / 2;
+		_canvasWidthHalf = Math.floor( _canvasWidth / 2 );
+		_canvasHeightHalf = Math.floor( _canvasHeight / 2 );
 
 		_canvas.width = _canvasWidth;
 		_canvas.height = _canvasHeight;
@@ -117,7 +119,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	this.setClearColor = function( color, opacity ) {
 
-		_clearColor = color;
+		_clearColor.copy( color );
 		_clearOpacity = opacity;
 
 		_clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
@@ -139,21 +141,23 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		if ( !_clearRect.isEmpty() ) {
 
-			_clearRect.inflate( 1 );
 			_clearRect.minSelf( _clipRect );
+			_clearRect.inflate( 2 );
+
+			if ( _clearOpacity < 1 ) {
 
-			if ( _clearOpacity == 0 ) {
+				_context.clearRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) );
 
-				_context.clearRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
+			}
 
-			} else {
+			if ( _clearOpacity > 0 ) {
 
 				setBlending( THREE.NormalBlending );
 				setOpacity( 1 );
 
-				_contextFillStyle = 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')'
-				_context.fillStyle = _contextFillStyle;
-				_context.fillRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
+				setFillStyle( 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')' );
+
+				_context.fillRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) );
 
 			}
 
@@ -161,6 +165,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		}
 
+
 	};
 
 	this.render = function ( scene, camera ) {
@@ -514,8 +519,8 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				}
 
-				setStrokeStyle( material.color );
-				setFillStyle( material.color );
+				setStrokeStyle( material.color.getContextStyle() );
+				setFillStyle( material.color.getContextStyle() );
 
 				_context.save();
 				_context.translate( v1.x, v1.y );
@@ -545,7 +550,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 				setLineWidth( material.linewidth );
 				setLineCap( material.linecap );
 				setLineJoin( material.linejoin );
-				setStrokeStyle( material.color );
+				setStrokeStyle( material.color.getContextStyle() );
 
 				_context.stroke();
 				_bboxRect.inflate( material.linewidth * 2 );
@@ -575,7 +580,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 					if ( material.map.mapping instanceof THREE.UVMapping ) {
 
 						_uvs = element.uvs[ 0 ];
-						texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, material.map.image, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v );
+						patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
 
 					}
 
@@ -598,7 +603,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 						_uv3x = ( _vector3.x * cameraMatrix.n11 + _vector3.y * cameraMatrix.n12 + _vector3.z * cameraMatrix.n13 ) * 0.5 + 0.5;
 						_uv3y = - ( _vector3.x * cameraMatrix.n21 + _vector3.y * cameraMatrix.n22 + _vector3.z * cameraMatrix.n23 ) * 0.5 + 0.5;
 
-						texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, material.envMap.image, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y );
+						patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap );
 
 					}/* else if ( material.envMap.mapping == THREE.SphericalRefractionMapping ) {
 
@@ -620,7 +625,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 					if ( material.map.mapping instanceof THREE.UVMapping ) {
 
 						_uvs = element.uvs[ 0 ];
-						texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, material.map.image, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v );
+						patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
 
 					}
 
@@ -644,9 +649,9 @@ THREE.CanvasRenderer = function ( parameters ) {
 						_color4.g = ( _color2.g + _color3.g ) * 0.5;
 						_color4.b = ( _color2.b + _color3.b ) * 0.5;
 
-						_bitmap = getGradientTexture( _color1, _color2, _color3, _color4 );
+						_image = getGradientTexture( _color1, _color2, _color3, _color4 );
 
-						texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _bitmap, 0, 0, 1, 0, 0, 1 );
+						clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image );
 
 					} else {
 
@@ -659,7 +664,6 @@ THREE.CanvasRenderer = function ( parameters ) {
 						_color.r = Math.max( 0, Math.min( material.color.r * _light.r, 1 ) );
 						_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
 						_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
-						_color.updateHex();
 
 						material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
 
@@ -684,16 +688,15 @@ THREE.CanvasRenderer = function ( parameters ) {
 				_color4.g = ( _color2.g + _color3.g ) * 0.5;
 				_color4.b = ( _color2.b + _color3.b ) * 0.5;
 
-				_bitmap = getGradientTexture( _color1, _color2, _color3, _color4 );
+				_image = getGradientTexture( _color1, _color2, _color3, _color4 );
 
-				texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _bitmap, 0, 0, 1, 0, 0, 1 );
+				clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image );
 
 			} else if ( material instanceof THREE.MeshNormalMaterial ) {
 
 				_color.r = normalToComponent( element.normalWorld.x );
 				_color.g = normalToComponent( element.normalWorld.y );
 				_color.b = normalToComponent( element.normalWorld.z );
-				_color.updateHex();
 
 				material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
 
@@ -748,15 +751,15 @@ THREE.CanvasRenderer = function ( parameters ) {
 						calculateLight( scene, element.v4.positionWorld, element.vertexNormalsWorld[ 3 ], _color3 );
 						calculateLight( scene, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color4 );
 
-						_bitmap = getGradientTexture( _color1, _color2, _color3, _color4 );
+						_image = getGradientTexture( _color1, _color2, _color3, _color4 );
 
 						// TODO: UVs are incorrect, v4->v3?
 
 						drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y );
-						texturePath( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, _bitmap, 0, 0, 1, 0, 0, 1 );
+						clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image );
 
 						drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y );
-						texturePath( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, _bitmap, 1, 0, 1, 1, 0, 1 );
+						clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image );
 
 					} else {
 
@@ -769,7 +772,6 @@ THREE.CanvasRenderer = function ( parameters ) {
 						_color.r = Math.max( 0, Math.min( material.color.r * _light.r, 1 ) );
 						_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
 						_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
-						_color.updateHex();
 
 						drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
 
@@ -790,7 +792,6 @@ THREE.CanvasRenderer = function ( parameters ) {
 				_color.r = normalToComponent( element.normalWorld.x );
 				_color.g = normalToComponent( element.normalWorld.y );
 				_color.b = normalToComponent( element.normalWorld.z );
-				_color.updateHex();
 
 				drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
 
@@ -806,15 +807,15 @@ THREE.CanvasRenderer = function ( parameters ) {
 				_color3.r = _color3.g = _color3.b = 1 - smoothstep( v4.positionScreen.z, _near, _far );
 				_color4.r = _color4.g = _color4.b = 1 - smoothstep( v3.positionScreen.z, _near, _far );
 
-				_bitmap = getGradientTexture( _color1, _color2, _color3, _color4 );
+				_image = getGradientTexture( _color1, _color2, _color3, _color4 );
 
 				// TODO: UVs are incorrect, v4->v3?
 
 				drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y );
-				texturePath( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, _bitmap, 0, 0, 1, 0, 0, 1 );
+				clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image );
 
 				drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y );
-				texturePath( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, _bitmap, 1, 0, 1, 1, 0, 1 );
+				clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image );
 
 			}
 
@@ -850,7 +851,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 			setLineWidth( linewidth );
 			setLineCap( linecap );
 			setLineJoin( linejoin );
-			setStrokeStyle( color );
+			setStrokeStyle( color.getContextStyle() );
 
 			_context.stroke();
 
@@ -860,49 +861,77 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		function fillPath( color ) {
 
-			setFillStyle( color );
+			setFillStyle( color.getContextStyle() );
 			_context.fill();
 
 		}
 
-		function texturePath( x0, y0, x1, y1, x2, y2, bitmap, u0, v0, u1, v1, u2, v2 ) {
+		function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) {
 
-			/*
-			// http://tulrich.com/geekstuff/canvas/jsgl.js
+			if ( texture.image.width == 0 ) return;
 
-			var m11, m12, m21, m22, dx, dy, denom,
-			width = bitmap.width - 1,
-			height = bitmap.height - 1;
+			if ( texture.needsUpdate == true || _patterns[ texture.id ] == undefined ) {
 
-			u0 *= width; v0 *= height;
-			u1 *= width; v1 *= height;
-			u2 *= width; v2 *= height;
+				var repeatX = texture.wrapS == THREE.RepeatWrapping;
+				var repeatY = texture.wrapT == THREE.RepeatWrapping;
 
-			_context.save();
+				_patterns[ texture.id ] = _context.createPattern( texture.image, repeatX && repeatY ? 'repeat' : repeatX && !repeatY ? 'repeat-x' : !repeatX && repeatY ? 'repeat-y' : 'no-repeat' );
+
+				texture.needsUpdate = false;
+
+			}
+
+			setFillStyle( _patterns[ texture.id ] );
+
+			// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
 
-			denom = u0 * (v2 - v1) - u1 * v2 + u2 * v1 + (u1 - u2) * v0;
+			var a, b, c, d, e, f, det, idet,
+			offsetX = texture.offset.x / texture.repeat.x,
+			offsetY = texture.offset.y / texture.repeat.y,
+			width = ( texture.image.width - 1 ) * texture.repeat.x,
+			height = ( texture.image.height - 1 ) * texture.repeat.y;
 
-			if ( denom == 0 ) return;
+			u0 = ( u0 + offsetX ) * width;
+			v0 = ( v0 + offsetY ) * height;
 
-			m11 = - (v0 * (x2 - x1) - v1 * x2 + v2 * x1 + (v1 - v2) * x0) / denom;
-			m12 = (v1 * y2 + v0 * (y1 - y2) - v2 * y1 + (v2 - v1) * y0) / denom;
-			m21 = (u0 * (x2 - x1) - u1 * x2 + u2 * x1 + (u1 - u2) * x0) / denom;
-			m22 = - (u1 * y2 + u0 * (y1 - y2) - u2 * y1 + (u2 - u1) * y0) / denom;
-			dx = (u0 * (v2 * x1 - v1 * x2) + v0 * (u1 * x2 - u2 * x1) + (u2 * v1 - u1 * v2) * x0) / denom;
-			dy = (u0 * (v2 * y1 - v1 * y2) + v0 * (u1 * y2 - u2 * y1) + (u2 * v1 - u1 * v2) * y0) / denom;
+			u1 = ( u1 + offsetX ) * width;
+			v1 = ( v1 + offsetY ) * height;
 
-			_context.transform( m11, m12, m21, m22, dx, dy );
+			u2 = ( u2 + offsetX ) * width;
+			v2 = ( v2 + offsetY ) * height;
 
-			_context.clip();
-			_context.drawImage( bitmap, 0, 0 );
+			x1 -= x0; y1 -= y0;
+			x2 -= x0; y2 -= y0;
+
+			u1 -= u0; v1 -= v0;
+			u2 -= u0; v2 -= v0;
+
+			det = u1 * v2 - u2 * v1;
+
+			idet = 1 / det;
+
+			a = ( v2 * x1 - v1 * x2 ) * idet;
+			b = ( v2 * y1 - v1 * y2 ) * idet;
+			c = ( u1 * x2 - u2 * x1 ) * idet;
+			d = ( u1 * y2 - u2 * y1 ) * idet;
+
+			e = x0 - a * u0 - c * v0;
+			f = y0 - b * u0 - d * v0;
+
+			_context.save();
+			_context.transform( a, b, c, d, e, f );
+			_context.fill();
 			_context.restore();
-			*/
+
+		}
+
+		function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) {
 
 			// http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
 
 			var a, b, c, d, e, f, det, idet,
-			width = bitmap.width - 1,
-			height = bitmap.height - 1;
+			width = image.width - 1,
+			height = image.height - 1;
 
 			u0 *= width; v0 *= height;
 			u1 *= width; v1 *= height;
@@ -916,8 +945,6 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 			det = u1 * v2 - u2 * v1;
 
-			if ( /*Math.abs*/ ( det < 0 ? - det : det ) < 1 ) return;
-
 			idet = 1 / det;
 
 			a = ( v2 * x1 - v1 * x2 ) * idet;
@@ -931,7 +958,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 			_context.save();
 			_context.transform( a, b, c, d, e, f );
 			_context.clip();
-			_context.drawImage( bitmap, 0, 0 );
+			_context.drawImage( image, 0, 0 );
 			_context.restore();
 
 		}
@@ -1084,33 +1111,24 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	}
 
-	function setStrokeStyle( color ) {
+	function setStrokeStyle( style ) {
 
-		if ( _contextStrokeStyle != color.hex ) {
+		if ( _contextStrokeStyle != style ) {
 
-			_contextStrokeStyle = color.hex;
-			_context.strokeStyle = '#' + pad( _contextStrokeStyle.toString( 16 ) );
+			_context.strokeStyle = _contextStrokeStyle = style;
 
 		}
 
 	}
 
-	function setFillStyle( color ) {
+	function setFillStyle( style ) {
 
-		if ( _contextFillStyle != color.hex ) {
+		if ( _contextFillStyle != style ) {
 
-			_contextFillStyle = color.hex;
-			_context.fillStyle = '#' + pad( _contextFillStyle.toString( 16 ) );
+			_context.fillStyle = _contextFillStyle = style;
 
 		}
 
 	}
 
-	function pad( str ) {
-
-		while ( str.length < 6 ) str = '0' + str;
-		return str;
-
-	}
-
 };

+ 9 - 13
src/renderers/SVGRenderer.js

@@ -363,7 +363,7 @@ THREE.SVGRenderer = function () {
 
 		if ( material instanceof THREE.LineBasicMaterial ) {
 
-			_svgNode.setAttribute( 'style', 'fill: none; stroke: #' + '#' + pad( material.color.hex.toString( 16 ) ) + '; stroke-width: ' + material.linewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.linecap + '; stroke-linejoin: ' + material.linejoin );
+			_svgNode.setAttribute( 'style', 'fill: none; stroke: ' + material.color.getContextStyle() + '; stroke-width: ' + material.linewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.linecap + '; stroke-linejoin: ' + material.linejoin );
 
 			_svg.appendChild( _svgNode );
 
@@ -381,7 +381,7 @@ THREE.SVGRenderer = function () {
 
 		if ( material instanceof THREE.MeshBasicMaterial ) {
 
-			_color.hex = material.color.hex;
+			_color.copy( material.color );
 
 		} else if ( material instanceof THREE.MeshLambertMaterial ) {
 
@@ -397,11 +397,9 @@ THREE.SVGRenderer = function () {
 				_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
 				_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
 
-				_color.updateHex();
-
 			} else {
 
-				_color.hex = material.color.hex;
+				_color.copy( material.color );
 
 			}
 
@@ -418,11 +416,11 @@ THREE.SVGRenderer = function () {
 
 		if ( material.wireframe ) {
 
-			_svgNode.setAttribute( 'style', 'fill: none; stroke: #' + pad( _color.hex.toString( 16 ) ) + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
+			_svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.getContextStyle() + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
 
 		} else {
 
-			_svgNode.setAttribute( 'style', 'fill: #' + pad( _color.hex.toString( 16 ) ) + '; fill-opacity: ' + material.opacity );
+			_svgNode.setAttribute( 'style', 'fill: ' + _color.getContextStyle() + '; fill-opacity: ' + material.opacity );
 
 		}
 
@@ -440,7 +438,7 @@ THREE.SVGRenderer = function () {
 
 		if ( material instanceof THREE.MeshBasicMaterial ) {
 
-			_color.hex = material.color.hex;
+			_color.copy( material.color );
 
 		} else if ( material instanceof THREE.MeshLambertMaterial ) {
 
@@ -456,11 +454,9 @@ THREE.SVGRenderer = function () {
 				_color.g = Math.max( 0, Math.min( material.color.g * _light.g, 1 ) );
 				_color.b = Math.max( 0, Math.min( material.color.b * _light.b, 1 ) );
 
-				_color.updateHex();
-
 			} else {
 
-				_color.hex = material.color.hex;
+				_color.copy( material.color );
 
 			}
 
@@ -477,11 +473,11 @@ THREE.SVGRenderer = function () {
 
 		if ( material.wireframe ) {
 
-			_svgNode.setAttribute( 'style', 'fill: none; stroke: #' + pad( _color.hex.toString( 16 ) ) + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
+			_svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.getContextStyle() + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
 
 		} else {
 
-			_svgNode.setAttribute( 'style', 'fill: #' + pad( _color.hex.toString( 16 ) ) + '; fill-opacity: ' + material.opacity );
+			_svgNode.setAttribute( 'style', 'fill: ' + _color.getContextStyle() + '; fill-opacity: ' + material.opacity );
 
 		}
 

File diff suppressed because it is too large
+ 394 - 239
src/renderers/WebGLRenderer.js


+ 285 - 20
src/renderers/WebGLShaders.js

@@ -6,7 +6,6 @@
 
 THREE.ShaderChunk = {
 
-
 	// FOG
 
 	fog_pars_fragment: [
@@ -16,10 +15,14 @@ THREE.ShaderChunk = {
 		"uniform vec3 fogColor;",
 
 		"#ifdef FOG_EXP2",
+
 			"uniform float fogDensity;",
+
 		"#else",
+
 			"uniform float fogNear;",
 			"uniform float fogFar;",
+
 		"#endif",
 
 	"#endif"
@@ -33,11 +36,15 @@ THREE.ShaderChunk = {
 		"float depth = gl_FragCoord.z / gl_FragCoord.w;",
 
 		"#ifdef FOG_EXP2",
+
 			"const float LOG2 = 1.442695;",
 			"float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );",
 			"fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );",
+
 		"#else",
+
 			"float fogFactor = smoothstep( fogNear, fogFar, depth );",
+
 		"#endif",
 
 		"gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );",
@@ -53,6 +60,7 @@ THREE.ShaderChunk = {
 	"#ifdef USE_ENVMAP",
 
 		"varying vec3 vReflect;",
+
 		"uniform float reflectivity;",
 		"uniform samplerCube envMap;",
 		"uniform int combine;",
@@ -69,7 +77,6 @@ THREE.ShaderChunk = {
 
 		"if ( combine == 1 ) {",
 
-			//"gl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );",
 			"gl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );",
 
 		"} else {",
@@ -87,6 +94,7 @@ THREE.ShaderChunk = {
 	"#ifdef USE_ENVMAP",
 
 		"varying vec3 vReflect;",
+
 		"uniform float refractionRatio;",
 		"uniform bool useRefract;",
 
@@ -99,7 +107,7 @@ THREE.ShaderChunk = {
 	"#ifdef USE_ENVMAP",
 
 		"vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
-		"vec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;",
+		"vec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;",
 
 		"if ( useRefract ) {",
 
@@ -244,7 +252,9 @@ THREE.ShaderChunk = {
 		"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
 
 		"#ifdef PHONG",
+
 			"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
+
 		"#endif",
 
 	"#endif"
@@ -265,7 +275,7 @@ THREE.ShaderChunk = {
 
 		"#if MAX_DIR_LIGHTS > 0",
 
-		"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
+		"for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
 
 			"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
 			"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );",
@@ -277,7 +287,7 @@ THREE.ShaderChunk = {
 
 		"#if MAX_POINT_LIGHTS > 0",
 
-			"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {",
+			"for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 				"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
 
@@ -330,13 +340,13 @@ THREE.ShaderChunk = {
 
 	"#if MAX_POINT_LIGHTS > 0",
 
-		"vec4 pointDiffuse  = vec4( 0.0 );",
-		"vec4 pointSpecular = vec4( 0.0 );",
+		"vec4 pointDiffuse  = vec4( vec3( 0.0 ), 1.0 );",
+		"vec4 pointSpecular = vec4( vec3( 0.0 ), 1.0 );",
 
 		"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 			"vec3 pointVector = normalize( vPointLight[ i ].xyz );",
-			"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + vViewPosition );",
+			"vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );",
 			"float pointDistance = vPointLight[ i ].w;",
 
 			"float pointDotNormalHalf = dot( normal, pointHalfVector );",
@@ -356,15 +366,15 @@ THREE.ShaderChunk = {
 
 	"#if MAX_DIR_LIGHTS > 0",
 
-		"vec4 dirDiffuse  = vec4( 0.0 );",
-		"vec4 dirSpecular = vec4( 0.0 );" ,
+		"vec4 dirDiffuse  = vec4( vec3( 0.0 ), 1.0 );",
+		"vec4 dirSpecular = vec4( vec3( 0.0 ), 1.0 );" ,
 
-		"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
+		"for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
 
 			"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
 
 			"vec3 dirVector = normalize( lDirection.xyz );",
-			"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
+			"vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );",
 
 			"float dirDotNormalHalf = dot( normal, dirHalfVector );",
 
@@ -384,11 +394,15 @@ THREE.ShaderChunk = {
 	"vec4 totalLight = vec4( ambient, opacity );",
 
 	"#if MAX_DIR_LIGHTS > 0",
+
 		"totalLight += dirDiffuse + dirSpecular;",
+
 	"#endif",
 
 	"#if MAX_POINT_LIGHTS > 0",
+
 		"totalLight += pointDiffuse + pointSpecular;",
+
 	"#endif",
 
 	"gl_FragColor = gl_FragColor * totalLight;"
@@ -439,7 +453,7 @@ THREE.ShaderChunk = {
 
 	].join("\n"),
 
-	// skinning
+	// SKINNING
 
 	skinning_pars_vertex: [
 
@@ -467,7 +481,7 @@ THREE.ShaderChunk = {
 
 	].join("\n"),
 
-	// morphing
+	// MORPHING
 
 	morphtarget_pars_vertex: [
 
@@ -510,6 +524,150 @@ THREE.ShaderChunk = {
 	"#endif",
 	"#endif"
 
+	].join("\n"),
+
+	// SHADOW MAP
+
+	// based on SpiderGL shadow map and Fabien Sanglard's GLSL shadow mapping examples
+	//  http://spidergl.org/example.php?id=6
+	// 	http://fabiensanglard.net/shadowmapping
+
+	shadowmap_pars_fragment: [
+
+	"#ifdef USE_SHADOWMAP",
+
+		"uniform sampler2D shadowMap[ MAX_SHADOWS ];",
+
+		"uniform float shadowDarkness;",
+		"uniform float shadowBias;",
+
+		"varying vec4 vShadowCoord[ MAX_SHADOWS ];",
+
+		"float unpackDepth( const in vec4 rgba_depth ) {",
+
+			"const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
+			"float depth = dot( rgba_depth, bit_shift );",
+			"return depth;",
+
+		"}",
+
+	"#endif"
+
+	].join("\n"),
+
+	shadowmap_fragment: [
+
+	"#ifdef USE_SHADOWMAP",
+
+		"#ifdef SHADOWMAP_SOFT",
+
+			"const float xPixelOffset = 1.0 / SHADOWMAP_WIDTH;",
+			"const float yPixelOffset = 1.0 / SHADOWMAP_HEIGHT;",
+
+		"#endif",
+
+		"vec4 shadowColor = vec4( 1.0 );",
+
+		"for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
+
+			"vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;",
+
+			"if ( shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 ) {",
+
+				"#ifdef SHADOWMAP_SOFT",
+
+					// Percentage-close filtering
+					// (9 pixel kernel)
+					// http://fabiensanglard.net/shadowmappingPCF/
+
+					"float shadow = 0.0;",
+
+					"for ( float y = -1.25; y <= 1.25; y += 1.25 )",
+						"for ( float x = -1.25; x <= 1.25; x += 1.25 ) {",
+
+							"vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );",
+
+							// doesn't seem to produce any noticeable visual difference compared to simple "texture2D" lookup
+							//"vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );",
+
+							"float fDepth = unpackDepth( rgbaDepth );",
+
+							"if ( fDepth < ( shadowCoord.z + shadowBias ) )",
+								"shadow += 1.0;",
+
+					"}",
+
+					"shadow /= 9.0;",
+
+					"shadowColor = shadowColor * vec4( vec3( ( 1.0 - shadowDarkness * shadow ) ), 1.0 );",
+
+				"#else",
+
+					"vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );",
+					"float fDepth = unpackDepth( rgbaDepth );",
+
+					"if ( fDepth < ( shadowCoord.z + shadowBias ) )",
+
+						// spot with multiple shadows is darker
+
+						"shadowColor = shadowColor * vec4( vec3( shadowDarkness ), 1.0 );",
+
+						// spot with multiple shadows has the same color as single shadow spot
+
+						//"shadowColor = min( shadowColor, vec4( vec3( shadowDarkness ), 1.0 ) );",
+
+				"#endif",
+
+			"}",
+
+
+			// uncomment to see light frustum boundaries
+			//"if ( !( shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 ) )",
+			//	"gl_FragColor =  gl_FragColor * vec4( 1.0, 0.0, 0.0, 1.0 );",
+
+		"}",
+
+		"gl_FragColor = gl_FragColor * shadowColor;",
+
+	"#endif"
+
+	].join("\n"),
+
+	shadowmap_pars_vertex: [
+
+	"#ifdef USE_SHADOWMAP",
+
+		"varying vec4 vShadowCoord[ MAX_SHADOWS ];",
+		"uniform mat4 shadowMatrix[ MAX_SHADOWS ];",
+
+	"#endif"
+
+	].join("\n"),
+
+	shadowmap_vertex: [
+
+	"#ifdef USE_SHADOWMAP",
+
+		"for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
+
+			"vShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );",
+
+		"}",
+
+	"#endif"
+
+	].join("\n"),
+
+	// ALPHATEST
+
+	alphatest_fragment: [
+
+	"#ifdef ALPHATEST",
+
+		"if ( gl_FragColor.a < ALPHATEST ) discard;",
+
+	"#endif"
+
 	].join("\n")
 
 };
@@ -549,11 +707,18 @@ THREE.UniformsUtils = {
 				parameter_src = uniforms_src[ u ][ p ];
 
 				if ( parameter_src instanceof THREE.Color ||
+					 parameter_src instanceof THREE.Vector2 ||
 					 parameter_src instanceof THREE.Vector3 ||
+					 parameter_src instanceof THREE.Vector4 ||
+					 parameter_src instanceof THREE.Matrix4 ||
 					 parameter_src instanceof THREE.Texture ) {
 
 					uniforms_dst[ u ][ p ] = parameter_src.clone();
 
+				} else if ( parameter_src instanceof Array ) {
+
+					uniforms_dst[ u ][ p ] = parameter_src.slice();
+
 				} else {
 
 					uniforms_dst[ u ][ p ] = parameter_src;
@@ -626,6 +791,16 @@ THREE.UniformsLib = {
 		"fogFar" : { type: "f", value: 2000 },
 		"fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
 
+	},
+
+	shadowmap: {
+
+		"shadowMap": { type: "tv", value: 3, texture: [] },
+		"shadowMatrix" : { type: "m4v", value: [] },
+
+		"shadowBias" : { type: "f", value: 0.0039 },
+		"shadowDarkness": { type: "f", value: 0.2 }
+
 	}
 
 };
@@ -927,7 +1102,7 @@ THREE.ShaderLib = {
 			"void main() {",
 
 				"vec4 pos      = objectMatrix * vec4( position, 1.0 );",
-				"vec3 norm     = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;",
+				"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 );",
 
 				"gl_Position   = projectionMatrix * viewMatrix * ( pos + extruded );",
@@ -1023,7 +1198,8 @@ THREE.ShaderLib = {
 		uniforms: THREE.UniformsUtils.merge( [
 
 			THREE.UniformsLib[ "common" ],
-			THREE.UniformsLib[ "fog" ]
+			THREE.UniformsLib[ "fog" ],
+			THREE.UniformsLib[ "shadowmap" ]
 
 		] ),
 
@@ -1037,15 +1213,18 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
+			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 
 			"void main() {",
 
 				"gl_FragColor = vec4( diffuse, opacity );",
 
 				THREE.ShaderChunk[ "map_fragment" ],
+				THREE.ShaderChunk[ "alphatest_fragment" ],
 				THREE.ShaderChunk[ "lightmap_fragment" ],
 				THREE.ShaderChunk[ "color_fragment" ],
 				THREE.ShaderChunk[ "envmap_fragment" ],
+				THREE.ShaderChunk[ "shadowmap_fragment" ],
 				THREE.ShaderChunk[ "fog_fragment" ],
 
 			"}"
@@ -1060,6 +1239,7 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "color_pars_vertex" ],
 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
 
 			"void main() {",
 
@@ -1072,6 +1252,7 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "skinning_vertex" ],
 				THREE.ShaderChunk[ "morphtarget_vertex" ],
 				THREE.ShaderChunk[ "default_vertex" ],
+				THREE.ShaderChunk[ "shadowmap_vertex" ],
 
 			"}"
 
@@ -1085,7 +1266,8 @@ THREE.ShaderLib = {
 
 			THREE.UniformsLib[ "common" ],
 			THREE.UniformsLib[ "fog" ],
-			THREE.UniformsLib[ "lights" ]
+			THREE.UniformsLib[ "lights" ],
+			THREE.UniformsLib[ "shadowmap" ]
 
 		] ),
 
@@ -1101,16 +1283,21 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
+			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 
 			"void main() {",
 
 				"gl_FragColor = vec4( diffuse, opacity );",
-				"gl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",
 
 				THREE.ShaderChunk[ "map_fragment" ],
+				THREE.ShaderChunk[ "alphatest_fragment" ],
+
+				"gl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",
+
 				THREE.ShaderChunk[ "lightmap_fragment" ],
 				THREE.ShaderChunk[ "color_fragment" ],
 				THREE.ShaderChunk[ "envmap_fragment" ],
+				THREE.ShaderChunk[ "shadowmap_fragment" ],
 				THREE.ShaderChunk[ "fog_fragment" ],
 
 			"}"
@@ -1128,6 +1315,7 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "color_pars_vertex" ],
 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
 
 			"void main() {",
 
@@ -1144,6 +1332,8 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "skinning_vertex" ],
 				THREE.ShaderChunk[ "morphtarget_vertex" ],
 				THREE.ShaderChunk[ "default_vertex" ],
+				THREE.ShaderChunk[ "shadowmap_vertex" ],
+
 
 			"}"
 
@@ -1158,6 +1348,7 @@ THREE.ShaderLib = {
 			THREE.UniformsLib[ "common" ],
 			THREE.UniformsLib[ "fog" ],
 			THREE.UniformsLib[ "lights" ],
+			THREE.UniformsLib[ "shadowmap" ],
 
 			{
 				"ambient"  : { type: "c", value: new THREE.Color( 0x050505 ) },
@@ -1184,16 +1375,21 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
 			THREE.ShaderChunk[ "lights_pars_fragment" ],
+			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 
 			"void main() {",
 
 				"gl_FragColor = vec4( vLightWeighting, 1.0 );",
-				THREE.ShaderChunk[ "lights_fragment" ],
 
 				THREE.ShaderChunk[ "map_fragment" ],
+				THREE.ShaderChunk[ "alphatest_fragment" ],
+
+				THREE.ShaderChunk[ "lights_fragment" ],
+
 				THREE.ShaderChunk[ "lightmap_fragment" ],
 				THREE.ShaderChunk[ "color_fragment" ],
 				THREE.ShaderChunk[ "envmap_fragment" ],
+				THREE.ShaderChunk[ "shadowmap_fragment" ],
 				THREE.ShaderChunk[ "fog_fragment" ],
 
 			"}"
@@ -1215,6 +1411,7 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "color_pars_vertex" ],
 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
 
 			"void main() {",
 
@@ -1226,7 +1423,9 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "color_vertex" ],
 
 				"#ifndef USE_ENVMAP",
+
 					"vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
+
 				"#endif",
 
 				"vViewPosition = cameraPosition - mPosition.xyz;",
@@ -1238,6 +1437,7 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "skinning_vertex" ],
 				THREE.ShaderChunk[ "morphtarget_vertex" ],
 				THREE.ShaderChunk[ "default_vertex" ],
+				THREE.ShaderChunk[ "shadowmap_vertex" ],
 
 			"}"
 
@@ -1247,7 +1447,12 @@ THREE.ShaderLib = {
 
 	'particle_basic': {
 
-		uniforms: THREE.UniformsLib[ "particle" ],
+		uniforms:  THREE.UniformsUtils.merge( [
+
+			THREE.UniformsLib[ "particle" ],
+			THREE.UniformsLib[ "shadowmap" ]
+
+		] ),
 
 		fragmentShader: [
 
@@ -1257,13 +1462,16 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "color_pars_fragment" ],
 			THREE.ShaderChunk[ "map_particle_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
+			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
 
 			"void main() {",
 
 				"gl_FragColor = vec4( psColor, opacity );",
 
 				THREE.ShaderChunk[ "map_particle_fragment" ],
+				THREE.ShaderChunk[ "alphatest_fragment" ],
 				THREE.ShaderChunk[ "color_fragment" ],
+				THREE.ShaderChunk[ "shadowmap_fragment" ],
 				THREE.ShaderChunk[ "fog_fragment" ],
 
 			"}"
@@ -1276,6 +1484,7 @@ THREE.ShaderLib = {
 			"uniform float scale;",
 
 			THREE.ShaderChunk[ "color_pars_vertex" ],
+			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
 
 			"void main() {",
 
@@ -1291,6 +1500,62 @@ THREE.ShaderLib = {
 
 				"gl_Position = projectionMatrix * mvPosition;",
 
+				THREE.ShaderChunk[ "shadowmap_vertex" ],
+
+			"}"
+
+		].join("\n")
+
+	},
+
+	// Depth encoding into RGBA texture
+	// 	based on SpiderGL shadow map example
+	// 		http://spidergl.org/example.php?id=6
+	// 	originally from
+	//		http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
+	// 	see also here:
+	//		http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
+
+	'depthRGBA': {
+
+		uniforms: {},
+
+		fragmentShader: [
+
+			"vec4 pack_depth( const in float depth ) {",
+
+				"const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
+				"const vec4 bit_mask  = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
+				"vec4 res = fract( depth * bit_shift );",
+				"res -= res.xxyz * bit_mask;",
+				"return res;",
+
+			"}",
+
+			"void main() {",
+
+				"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
+
+				//"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
+				//"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
+				//"gl_FragData[ 0 ] = pack_depth( z );",
+				//"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
+
+			"}"
+
+		].join("\n"),
+
+		vertexShader: [
+
+			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+
+			"void main() {",
+
+				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+
+				THREE.ShaderChunk[ "morphtarget_vertex" ],
+				THREE.ShaderChunk[ "default_vertex" ],
+
 			"}"
 
 		].join("\n")

+ 10 - 6
utils/build.py

@@ -35,7 +35,7 @@ COMMON_FILES = [
 'lights/AmbientLight.js',
 'lights/DirectionalLight.js',
 'lights/PointLight.js',
-'lights/LensFlare.js',
+'lights/SpotLight.js',
 'materials/Material.js',
 'materials/Mappings.js',
 'materials/LineBasicMaterial.js',
@@ -46,11 +46,11 @@ COMMON_FILES = [
 'materials/MeshNormalMaterial.js',
 'materials/MeshFaceMaterial.js',
 'materials/MeshShaderMaterial.js',
-'materials/ShadowVolumeDynamicMaterial.js',
 'materials/ParticleBasicMaterial.js',
 'materials/ParticleCanvasMaterial.js',
 'materials/ParticleDOMMaterial.js',
 'materials/Texture.js',
+'materials/DataTexture.js',
 'objects/Particle.js',
 'objects/ParticleSystem.js',
 'objects/Line.js',
@@ -59,7 +59,6 @@ COMMON_FILES = [
 'objects/SkinnedMesh.js',
 'objects/Ribbon.js',
 'objects/LOD.js',
-'objects/ShadowVolume.js',
 'objects/Sprite.js',
 'scenes/Scene.js',
 'scenes/Fog.js',
@@ -93,8 +92,14 @@ EXTRAS_FILES = [
 'extras/cameras/RollCamera.js',
 'extras/cameras/TrackballCamera.js',
 'extras/cameras/QuakeCamera.js',
+'extras/geometries/Curve.js',
+'extras/geometries/CurvePath.js',
+'extras/geometries/Path.js',
+'extras/geometries/Shape.js',
+'extras/geometries/TextPath.js',
 'extras/geometries/CubeGeometry.js',
 'extras/geometries/CylinderGeometry.js',
+'extras/geometries/ExtrudeGeometry.js',
 'extras/geometries/IcosahedronGeometry.js',
 'extras/geometries/LatheGeometry.js',
 'extras/geometries/PlaneGeometry.js',
@@ -106,6 +111,7 @@ EXTRAS_FILES = [
 'extras/io/JSONLoader.js',
 'extras/io/BinaryLoader.js',
 'extras/io/SceneLoader.js',
+'extras/io/UTF8Loader.js',
 'extras/objects/MarchingCubes.js',
 'extras/objects/Trident.js',
 'extras/physics/Collisions.js',
@@ -259,7 +265,7 @@ WEBGL_FILES = [
 'lights/AmbientLight.js',
 'lights/DirectionalLight.js',
 'lights/PointLight.js',
-'lights/LensFlare.js',
+'lights/SpotLight.js',
 'materials/Material.js',
 'materials/Mappings.js',
 'materials/LineBasicMaterial.js',
@@ -271,7 +277,6 @@ WEBGL_FILES = [
 'materials/MeshFaceMaterial.js',
 'materials/MeshShaderMaterial.js',
 'materials/ParticleBasicMaterial.js',
-'materials/ShadowVolumeDynamicMaterial.js',
 'materials/Texture.js',
 'objects/Particle.js',
 'objects/ParticleSystem.js',
@@ -281,7 +286,6 @@ WEBGL_FILES = [
 'objects/SkinnedMesh.js',
 'objects/Ribbon.js',
 'objects/LOD.js',
-'objects/ShadowVolume.js',
 'objects/Sprite.js',
 'scenes/Scene.js',
 'scenes/Fog.js',

+ 0 - 359
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/__init__.py

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

+ 0 - 1623
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/export_threejs.py

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

+ 0 - 635
utils/exporters/blender/2.56/scripts/op/io_mesh_threejs/import_threejs.py

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

+ 0 - 388
utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs/__init__.py

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

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

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

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

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

+ 35 - 4
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/__init__.py → utils/exporters/blender/2.59/scripts/addons/io_mesh_threejs/__init__.py

@@ -24,7 +24,7 @@
 bl_info = {
     "name": "three.js format",
     "author": "mrdoob, kikko, alteredq, remoe, pxf",
-    "version": (1, 0, 2),
+    "version": (1, 1, 0),
     "blender": (2, 5, 7),
     "api": 35622,
     "location": "File > Import-Export",
@@ -183,6 +183,10 @@ def save_settings_export(properties):
     "option_lights" : properties.option_lights,
     "option_cameras" : properties.option_cameras,
 
+    "option_animation" : properties.option_animation,
+    "option_frame_step" : properties.option_frame_step,
+    "option_all_meshes" : properties.option_all_meshes,
+
     "option_flip_yz"      : properties.option_flip_yz,
 
     "option_materials"       : properties.option_materials,
@@ -235,6 +239,10 @@ def restore_settings_export(properties):
     properties.option_lights = settings.get("option_lights", False)
     properties.option_cameras = settings.get("option_cameras", False)
 
+    properties.option_animation = settings.get("option_animation", False)
+    properties.option_frame_step = settings.get("option_frame_step", 1)
+    properties.option_all_meshes = settings.get("option_all_meshes", True)
+
 # ################################################################
 # Exporter
 # ################################################################
@@ -268,13 +276,17 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
     option_flip_yz = BoolProperty(name = "Flip YZ", description = "Flip YZ", default = True)
 
     option_export_scene = BoolProperty(name = "Scene", description = "Export scene", default = False)
-    option_embed_meshes = BoolProperty(name = "Embed", description = "Embed meshes", default = True)
+    option_embed_meshes = BoolProperty(name = "Embed meshes", 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)
 
+    option_animation = BoolProperty(name = "Animation", description = "Export animation (morphs)", default = False)
+    option_frame_step = IntProperty(name = "Frame step", description = "Animation frame step", min = 1, max = 1000, soft_min = 1, soft_max = 1000, default = 1)
+    option_all_meshes = BoolProperty(name = "All meshes", description = "All meshes (merged)", default = True)
+
     def invoke(self, context, event):
         restore_settings_export(self.properties)
         return ExportHelper.invoke(self, context, event)
@@ -346,17 +358,36 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
         layout.separator()
 
         row = layout.row()
-        row.label(text="Beta:")
+        row.label(text="--------- Experimental ---------")
+        layout.separator()
+
+        row = layout.row()
+        row.label(text="Scene:")
 
         row = layout.row()
         row.prop(self.properties, "option_export_scene")
+        row.prop(self.properties, "option_embed_meshes")
 
         row = layout.row()
         row.prop(self.properties, "option_lights")
         row.prop(self.properties, "option_cameras")
+        layout.separator()
+
+        row = layout.row()
+        row.label(text="Animation:")
+
+        row = layout.row()
+        row.prop(self.properties, "option_animation")
+        row.prop(self.properties, "option_frame_step")
+        layout.separator()
+
+        row = layout.row()
+        row.label(text="Settings:")
+
+        row = layout.row()
+        row.prop(self.properties, "option_all_meshes")
 
         row = layout.row()
-        row.prop(self.properties, "option_embed_meshes")
         row.prop(self.properties, "option_copy_textures")
 
         row = layout.row()

+ 249 - 122
utils/exporters/blender/2.58/scripts/addons/io_mesh_threejs/export_threejs.py → utils/exporters/blender/2.59/scripts/addons/io_mesh_threejs/export_threejs.py

@@ -232,6 +232,7 @@ TEMPLATE_FILE_ASCII = """\
  * colors: %(ncolor)d
  * materials: %(nmaterial)d
  * edges: %(nedges)d
+ * morphTargets: %(nmorphTarget)d
  *
  */
 
@@ -254,7 +255,7 @@ TEMPLATE_MODEL_ASCII = """\
 
     "vertices": [%(vertices)s],
 
-    "morphTargets": [],
+    "morphTargets": [%(morphTargets)s],
 
     "normals": [%(normals)s],
 
@@ -272,7 +273,6 @@ TEMPLATE_VERTEX_TRUNCATE = "%d,%d,%d"
 
 TEMPLATE_N = "%f,%f,%f"
 TEMPLATE_UV = "%f,%f"
-#TEMPLATE_C = "0x%06x"
 TEMPLATE_C = "%d"
 TEMPLATE_EDGE = "%d,%d"
 
@@ -454,8 +454,8 @@ def generate_vertex_color(c):
 def generate_uv(uv):
     return TEMPLATE_UV % (uv[0], 1.0 - uv[1])
 
-def generate_edge(e):
-    return TEMPLATE_EDGE % (e.vertices[0], e.vertices[1])
+def generate_edge(e, offset):
+    return TEMPLATE_EDGE % (e.vertices[0] + offset, e.vertices[1] + offset)
 
 # #####################################################
 # Model exporter - faces
@@ -469,13 +469,49 @@ def setBit(value, position, on):
         mask = ~(1 << position)
         return (value & mask)
 
-def generate_faces(normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz, option_faces):
+def generate_faces(normals, uvs, colors, meshes, option_normals, option_colors, option_uv_coords, option_materials, flipyz, option_faces):
+
     if not option_faces:
-        return ""
+        return "", 0
+
+    vertex_offset = 0
+    material_offset = 0
+
+    chunks = []
+    for mesh, object in meshes:
+
+        faceUV = (len(mesh.uv_textures) > 0)
+        vertexUV = (len(mesh.sticky) > 0)
+        vertexColors = len(mesh.vertex_colors) > 0
+
+        mesh_colors = option_colors and vertexColors
+        mesh_uvs = option_uv_coords and (faceUV or vertexUV)
+
+        if faceUV or vertexUV:
+            active_uv_layer = mesh.uv_textures.active
+            if not active_uv_layer:
+                mesh_extract_uvs = False
+
+        if vertexColors:
+            active_col_layer = mesh.vertex_colors.active
+            if not active_col_layer:
+                mesh_extract_colors = False
+
+        for i, f in enumerate(mesh.faces):
+            face = generate_face(f, i, normals, uvs, colors, mesh, option_normals, mesh_colors, mesh_uvs, option_materials, flipyz, vertex_offset, material_offset)
+            chunks.append(face)
+
+        vertex_offset += len(mesh.vertices)
 
-    return ",".join(generate_face(f, i, normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz) for i, f in enumerate(mesh.faces))
+        material_count = len(mesh.materials)
+        if material_count == 0:
+            material_count = 1
 
-def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz):
+        material_offset += material_count
+
+    return ",".join(chunks), len(chunks)
+
+def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz, vertex_offset, material_offset):
     isTriangle = ( len(f.vertices) == 3 )
 
     if isTriangle:
@@ -521,11 +557,12 @@ def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, opti
     # must clamp in case on polygons bigger than quads
 
     for i in range(nVertices):
-        index = f.vertices[i]
+        index = f.vertices[i] + vertex_offset
         faceData.append(index)
 
     if hasMaterial:
-        faceData.append( f.material_index )
+        index = f.material_index + material_offset
+        faceData.append( index )
 
     if hasFaceVertexUvs:
         uv = get_uv_indices(faceIndex, uvs, mesh)
@@ -552,13 +589,7 @@ def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, opti
 # Model exporter - normals
 # #####################################################
 
-def extract_vertex_normals(mesh, option_normals):
-    if not option_normals:
-        return {}, 0
-
-    count = 0
-    normals = {}
-
+def extract_vertex_normals(mesh, normals, count):
     for f in mesh.faces:
         for v in f.vertices:
 
@@ -569,7 +600,7 @@ def extract_vertex_normals(mesh, option_normals):
                 normals[key] = count
                 count += 1
 
-    return normals, count
+    return count
 
 def generate_normals(normals, option_normals):
     if not option_normals:
@@ -585,14 +616,7 @@ def generate_normals(normals, option_normals):
 # Model exporter - vertex colors
 # #####################################################
 
-def extract_vertex_colors(mesh, option_colors):
-
-    if not option_colors:
-        return {}, 0
-
-    count = 0
-    colors = {}
-
+def extract_vertex_colors(mesh, colors, count):
     color_layer = mesh.vertex_colors.active.data
 
     for face_index, face in enumerate(mesh.faces):
@@ -606,7 +630,7 @@ def extract_vertex_colors(mesh, option_colors):
                 colors[key] = count
                 count += 1
 
-    return colors, count
+    return count
 
 def generate_vertex_colors(colors, option_colors):
     if not option_colors:
@@ -622,14 +646,7 @@ def generate_vertex_colors(colors, option_colors):
 # Model exporter - UVs
 # #####################################################
 
-def extract_uvs(mesh, option_uv_coords):
-
-    if not option_uv_coords:
-        return {}, 0
-
-    count = 0
-    uvs = {}
-
+def extract_uvs(mesh, uvs, count):
     uv_layer = mesh.uv_textures.active.data
 
     for face_index, face in enumerate(mesh.faces):
@@ -641,7 +658,7 @@ def extract_uvs(mesh, option_uv_coords):
                 uvs[key] = count
                 count += 1
 
-    return uvs, count
+    return count
 
 def generate_uvs(uvs, option_uv_coords):
     if not option_uv_coords:
@@ -779,21 +796,22 @@ def extract_materials(mesh, scene, option_colors, option_copy_textures, filepath
 
     return materials
 
-def generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath):
+def generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath, offset):
 
     random.seed(42) # to get well defined color order for debug materials
 
     materials = {}
     if mesh.materials:
         for i, m in enumerate(mesh.materials):
+            mat_id = i + offset
             if m:
-                materials[m.name] = i
+                materials[m.name] = mat_id
             else:
-                materials["undefined_dummy_%0d" % i] = i
+                materials["undefined_dummy_%0d" % mat_id] = mat_id
 
 
     if not materials:
-        materials = { 'default':0 }
+        materials = { 'default': 0 }
 
     # default dummy materials
 
@@ -844,7 +862,8 @@ def handle_texture(id, textures, material, filepath, option_copy_textures):
 # ASCII model generator
 # #####################################################
 
-def generate_ascii_model(mesh, scene,
+def generate_ascii_model(meshes, morphs,
+                         scene,
                          option_vertices,
                          option_vertices_truncate,
                          option_faces,
@@ -856,35 +875,103 @@ def generate_ascii_model(mesh, scene,
                          align_model,
                          flipyz,
                          option_scale,
-                         draw_type,
                          option_copy_textures,
-                         filepath):
+                         filepath,
+                         option_animation,
+                         option_frame_step):
 
-    vertices = mesh.vertices[:]
+    vertices = []
 
-    if align_model == 1:
-        center(vertices)
-    elif align_model == 2:
-        bottom(vertices)
-    elif align_model == 3:
-        top(vertices)
+    vertex_offset = 0
+    vertex_offsets = []
 
-    normals, nnormal = extract_vertex_normals(mesh, option_normals)
-    colors, ncolor = extract_vertex_colors(mesh, option_colors)
-    uvs, nuv = extract_uvs(mesh, option_uv_coords)
+    edges = []
+
+    nnormal = 0
+    normals = {}
+
+    ncolor = 0
+    colors = {}
+
+    nuv = 0
+    uvs = {}
 
-    materials_string = ""
     nmaterial = 0
+    materials = []
+
+    for mesh, object in meshes:
+
+        faceUV = (len(mesh.uv_textures) > 0)
+        vertexUV = (len(mesh.sticky) > 0)
+        vertexColors = len(mesh.vertex_colors) > 0
+
+        mesh_extract_colors = option_colors and vertexColors
+        mesh_extract_uvs = option_uv_coords and (faceUV or vertexUV)
+
+        if faceUV or vertexUV:
+            active_uv_layer = mesh.uv_textures.active
+            if not active_uv_layer:
+                mesh_extract_uvs = False
+
+        if vertexColors:
+            active_col_layer = mesh.vertex_colors.active
+            if not active_col_layer:
+                mesh_extract_colors = False
+
+        vertex_offsets.append(vertex_offset)
+        vertex_offset += len(vertices)
+
+        vertices.extend(mesh.vertices[:])
+
+        edges.append(mesh.edges[:])
+
+        if option_normals:
+            nnormal = extract_vertex_normals(mesh, normals, nnormal)
+
+        if mesh_extract_colors:
+            ncolor = extract_vertex_colors(mesh, colors, ncolor)
+
+        if mesh_extract_uvs:
+            nuv = extract_uvs(mesh, uvs, nuv)
+
+        if option_materials:
+            mesh_materials, nmaterial = generate_materials_string(mesh, scene, mesh_extract_colors, object.draw_type, option_copy_textures, filepath, nmaterial)
+            materials.append(mesh_materials)
+
+
+    morphTargets_string = ""
+    nmorphTarget = 0
+
+    if option_animation:
+        chunks = []
+        for i, morphVertices in enumerate(morphs):
+            morphTarget = '{ "name": "%s_%06d", "vertices": [%s] }' % ("animation", i, morphVertices)
+            chunks.append(morphTarget)
+
+        morphTargets_string = ",\n\t".join(chunks)
+        nmorphTarget = len(morphs)
 
     edges_string = ""
     nedges = 0
 
-    if option_materials:
-        materials_string, nmaterial = generate_materials_string(mesh, scene, option_colors, draw_type, option_copy_textures, filepath)
-
     if option_edges:
-        nedges = len(mesh.edges)
-        edges_string  = ",".join(generate_edge(e) for e in mesh.edges)
+        chunks = []
+        for edges_mesh, offset in zip(edges, vertex_offsets):
+            for edge in edges_mesh:
+                chunks.append(generate_edge(edge, offset))
+        nedges = len(chunks)
+        edges_string  = ",".join(chunks)
+
+    if align_model == 1:
+        center(vertices)
+    elif align_model == 2:
+        bottom(vertices)
+    elif align_model == 3:
+        top(vertices)
+
+    faces_string, nfaces = generate_faces(normals, uvs, colors, meshes, option_normals, option_colors, option_uv_coords, option_materials, flipyz, option_faces)
+
+    materials_string = ",\n\n".join(materials)
 
     model_string = TEMPLATE_MODEL_ASCII % {
     "scale" : option_scale,
@@ -897,19 +984,22 @@ def generate_ascii_model(mesh, scene,
 
     "vertices" : generate_vertices(vertices, option_vertices_truncate, option_vertices),
 
-    "faces"    : generate_faces(normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, flipyz, option_faces),
+    "faces"    : faces_string,
 
-    "edges"    : edges_string
+    "edges"    : edges_string,
+
+    "morphTargets" : morphTargets_string
     }
 
     text = TEMPLATE_FILE_ASCII % {
-    "nvertex"   : len(mesh.vertices),
-    "nface"     : len(mesh.faces),
+    "nvertex"   : len(vertices),
+    "nface"     : nfaces,
     "nuv"       : nuv,
     "nnormal"   : nnormal,
     "ncolor"    : ncolor,
     "nmaterial" : nmaterial,
     "nedges"    : nedges,
+    "nmorphTarget": nmorphTarget,
 
     "model"     : model_string
     }
@@ -922,7 +1012,35 @@ def generate_ascii_model(mesh, scene,
 # Model exporter - export single mesh
 # #####################################################
 
-def generate_mesh_string(obj, scene,
+def extract_meshes(objects, scene, export_single_model, option_scale):
+
+    meshes = []
+
+    for object in objects:
+
+        if object.type == "MESH" and object.THREE_exportGeometry:
+
+            # collapse modifiers into mesh
+
+            mesh = object.to_mesh(scene, True, 'RENDER')
+
+            if not mesh:
+                raise Exception("Error, could not get mesh data from object [%s]" % object.name)
+
+            # that's what Blender's native export_obj.py does
+            # to flip YZ
+
+            if export_single_model:
+                X_ROT = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')
+                mesh.transform(X_ROT * object.matrix_world)
+
+            mesh.calc_normals()
+            mesh.transform(mathutils.Matrix.Scale(option_scale, 4))
+            meshes.append([mesh, object])
+
+    return meshes
+
+def generate_mesh_string(objects, scene,
                 option_vertices,
                 option_vertices_truncate,
                 option_faces,
@@ -936,51 +1054,43 @@ def generate_mesh_string(obj, scene,
                 option_scale,
                 export_single_model,
                 option_copy_textures,
-                filepath):
+                filepath,
+                option_animation,
+                option_frame_step):
+
+    meshes = extract_meshes(objects, scene, export_single_model, option_scale)
 
-    # collapse modifiers into mesh
+    morphs = []
 
-    mesh = obj.to_mesh(scene, True, 'RENDER')
+    if option_animation:
 
-    if not mesh:
-        raise Exception("Error, could not get mesh data from object [%s]" % obj.name)
+        original_frame = scene.frame_current # save animation state
 
-    # that's what Blender's native export_obj.py does
-    # to flip YZ
+        scene_frames = range(scene.frame_start, scene.frame_end + 1, option_frame_step)
 
-    if export_single_model:
-        X_ROT = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')
-        mesh.transform(X_ROT * obj.matrix_world)
+        for frame in scene_frames:
+            scene.frame_set(frame, 0.0)
 
-    mesh.calc_normals()
+            anim_meshes = extract_meshes(objects, scene, export_single_model, option_scale)
 
-    mesh.transform(mathutils.Matrix.Scale(option_scale, 4))
+            frame_vertices = []
 
-    faceUV = (len(mesh.uv_textures) > 0)
-    vertexUV = (len(mesh.sticky) > 0)
-    vertexColors = len(mesh.vertex_colors) > 0
+            for mesh, object in anim_meshes:
+                frame_vertices.extend(mesh.vertices[:])
 
-    if not vertexColors:
-        option_colors = False
+            morphVertices = generate_vertices(frame_vertices, option_vertices_truncate, option_vertices)
+            morphs.append(morphVertices)
 
-    if (not faceUV) and (not vertexUV):
-        option_uv_coords = False
+            # remove temp meshes
 
-    if faceUV:
-        active_uv_layer = mesh.uv_textures.active
-        if not active_uv_layer:
-            option_uv_coords = False
+            for mesh, object in anim_meshes:
+                bpy.data.meshes.remove(mesh)
 
-    if vertexColors:
-        active_col_layer = mesh.vertex_colors.active
-        if not active_col_layer:
-            option_colors = False
+        scene.frame_set(original_frame, 0.0) # restore animation state
 
-    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,
+    text, model_string = generate_ascii_model(meshes, morphs,
+                                scene,
                                 option_vertices,
                                 option_vertices_truncate,
                                 option_faces,
@@ -992,16 +1102,20 @@ def generate_mesh_string(obj, scene,
                                 align_model,
                                 flipyz,
                                 option_scale,
-                                obj.draw_type,
-                                option_copy_textures_model,
-                                filepath)
-    # remove temp mesh
+                                option_copy_textures,
+                                filepath,
+                                option_animation,
+                                option_frame_step)
 
-    bpy.data.meshes.remove(mesh)
+    # remove temp meshes
+
+    for mesh, object in meshes:
+        bpy.data.meshes.remove(mesh)
 
     return text, model_string
 
-def export_mesh(obj, scene, filepath,
+def export_mesh(objects,
+                scene, filepath,
                 option_vertices,
                 option_vertices_truncate,
                 option_faces,
@@ -1014,11 +1128,14 @@ def export_mesh(obj, scene, filepath,
                 flipyz,
                 option_scale,
                 export_single_model,
-                option_copy_textures):
+                option_copy_textures,
+                option_animation,
+                option_frame_step):
 
     """Export single mesh"""
 
-    text, model_string = generate_mesh_string(obj, scene,
+    text, model_string = generate_mesh_string(objects,
+                scene,
                 option_vertices,
                 option_vertices_truncate,
                 option_faces,
@@ -1032,7 +1149,9 @@ def export_mesh(obj, scene, filepath,
                 option_scale,
                 export_single_model,
                 option_copy_textures,
-                filepath)
+                filepath,
+                option_animation,
+                option_frame_step)
 
     write_file(filepath, text)
 
@@ -1546,7 +1665,6 @@ def generate_lights(data):
                 light_string = TEMPLATE_LIGHT_DIRECTIONAL % {
                 "light_id"      : generate_string(light["name"]),
                 "direction"     : generate_vec3(light["direction"]),
-                #"color"         : generate_hex(rgb2int(light["color"])),
                 "color"         : rgb2int(light["color"]),
                 "intensity"     : light["intensity"]
                 }
@@ -1555,7 +1673,6 @@ def generate_lights(data):
                 light_string = TEMPLATE_LIGHT_POINT % {
                 "light_id"      : generate_string(light["name"]),
                 "position"      : generate_vec3(light["position"]),
-                #"color"         : generate_hex(rgb2int(light["color"])),
                 "color"         : rgb2int(light["color"]),
                 "intensity"     : light["intensity"]
                 }
@@ -1701,7 +1818,10 @@ def save(operator, context, filepath = "",
          option_scale = 1.0,
          option_embed_meshes = True,
          option_url_base_html = False,
-         option_copy_textures = False):
+         option_copy_textures = False,
+         option_animation = False,
+         option_frame_step = 1,
+         option_all_meshes = True):
 
     #print("URL TYPE", option_url_base_html)
 
@@ -1712,30 +1832,35 @@ def save(operator, context, filepath = "",
     if scene.objects.active:
         bpy.ops.object.mode_set(mode='OBJECT')
 
+    if option_all_meshes:
+        objects = scene.objects
+    else:
+        objects = context.selected_objects
+
     if option_export_scene:
 
         geo_set = set()
         embeds = {}
 
-        for obj in scene.objects:
-            if obj.type == "MESH" and obj.THREE_exportGeometry:
+        for object in objects:
+            if object.type == "MESH" and object.THREE_exportGeometry:
 
                 # create extra copy of geometry with applied modifiers
                 # (if they exist)
 
-                if len(obj.modifiers) > 0:
-                    name = obj.name
+                if len(object.modifiers) > 0:
+                    name = object.name
 
                 # otherwise can share geometry
 
                 else:
-                    name = obj.data.name
+                    name = object.data.name
 
                 if name not in geo_set:
 
                     if option_embed_meshes:
 
-                        text, model_string = generate_mesh_string(obj, scene,
+                        text, model_string = generate_mesh_string([object], scene,
                                                         option_vertices,
                                                         option_vertices_truncate,
                                                         option_faces,
@@ -1749,14 +1874,16 @@ def save(operator, context, filepath = "",
                                                         option_scale,
                                                         False,          # export_single_model
                                                         False,          # option_copy_textures
-                                                        filepath)
+                                                        filepath,
+                                                        option_animation,
+                                                        option_frame_step)
 
                         embeds[name] = model_string
 
                     else:
 
                         fname = generate_mesh_filename(name, filepath)
-                        export_mesh(obj, scene,
+                        export_mesh([object], scene,
                                     fname,
                                     option_vertices,
                                     option_vertices_truncate,
@@ -1770,7 +1897,9 @@ def save(operator, context, filepath = "",
                                     option_flip_yz,
                                     option_scale,
                                     False,          # export_single_model
-                                    option_copy_textures)
+                                    option_copy_textures,
+                                    option_animation,
+                                    option_frame_step)
 
                     geo_set.add(name)
 
@@ -1786,11 +1915,7 @@ def save(operator, context, filepath = "",
 
     else:
 
-        obj = context.object
-        if not obj:
-            raise Exception("Error, Select 1 active object or select 'export scene'")
-
-        export_mesh(obj, scene, filepath,
+        export_mesh(objects, scene, filepath,
                     option_vertices,
                     option_vertices_truncate,
                     option_faces,
@@ -1803,6 +1928,8 @@ def save(operator, context, filepath = "",
                     option_flip_yz,
                     option_scale,
                     True,            # export_single_model
-                    option_copy_textures)
+                    option_copy_textures,
+                    option_animation,
+                    option_frame_step)
 
     return {'FINISHED'}

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


File diff suppressed because it is too large
+ 179 - 172
utils/exporters/convert_obj_three.py


+ 118 - 118
utils/exporters/max/ThreeJSExporter.ms

@@ -34,34 +34,34 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	triNFormat = "%,%,%,%,%,%,%",
 	triUVNFormat = "%,%,%,%,%,%,%,%,%,%",
 
-	footerFormat = "}\n\npostMessage( model );"
+	footerFormat = "}\n\npostMessage( model );\nclose();"
 
 	-------------------------------------------------------------------------------------
 	-- User interface
 
 
-	group "ThreeJSExporter  v0.6"
+	group "ThreeJSExporter  v0.7"
 	(
 
 		label msg "Exports selected meshes in Three.js ascii JSON format" align:#left
 		hyperLink lab1 "Original source at GitHub" address:"https://github.com/alteredq/three.js/blob/master/utils/exporters/max/ThreeJSExporter.ms" color:(color 255 120 0) align:#left
 
 		label dummy1 "--------------------------------------------------------" align:#left
-		
+
 		checkbox exportColor "Export vertex colors" checked:false enabled:true
 		checkbox exportUv "Export uvs" checked:true enabled:true
 		checkbox exportNormal "Export normals" checked:true enabled:true
 		checkbox smoothNormal "Use vertex normals" checked:false enabled:true
-		
+
 		label dummy2 "--------------------------------------------------------" align:#left
-		
+
 		checkbox flipYZ "Flip YZ" checked:true enabled:true
 		checkbox flipUV "Flip UV" checked:true enabled:true
 		checkbox flipFace "Flip all faces" checked:false enabled:true
 		checkbox autoflipFace "Try fixing flipped faces" checked:false enabled:true
 
 		label dummy3 "--------------------------------------------------------" align:#left
-		
+
 		button btn_export "Export selected objects"
 
 	)
@@ -70,7 +70,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	-------------------------------------------------------------------------------------
 	-- Dump vertices
 
-	function DumpVertices src = 
+	function DumpVertices src =
 	(
 
 		Format "\"vertices\": [" to:ostream
@@ -102,9 +102,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
 					z = vert.z
 
 				)
-				
+
 				Format vertexFormat x y z to:ostream
-				
+
 				if i < num then Format "," to:ostream
 
 			)
@@ -114,11 +114,11 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		Format "],\n\n" to:ostream
 
 	)
-	
+
 	-------------------------------------------------------------------------------------
 	-- Dump colors
 
-	function DumpColors src useColors = 
+	function DumpColors src useColors =
 	(
 
 		Format "\"colors\": [" to:ostream
@@ -132,19 +132,19 @@ rollout ThreeJSExporter "ThreeJSExporter"
 			(
 
 				col = src[i]
-				
+
 				r = col.r as Integer
 				g = col.g as Integer
 				b = col.b as Integer
-				
+
 				hexNum = ( bit.shift r 16 ) + ( bit.shift g 8 ) + b
-				
+
 				-- hexColor = formattedPrint hexNum format:"#x"
 				-- Format "%" hexColor to:ostream
 
 				decColor = formattedPrint hexNum format:"#d"
 				Format "%" decColor to:ostream
-				
+
 				if i < num then Format "," to:ostream
 
 			)
@@ -153,12 +153,12 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 		Format "],\n\n" to:ostream
 
-	)	
+	)
 
 	-------------------------------------------------------------------------------------
 	-- Dump normals
 
-	function DumpNormals src = 
+	function DumpNormals src =
 	(
 
 		Format "\"normals\": [" to:ostream
@@ -180,9 +180,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
 					x = normal.x
 					y = normal.z
 					z = normal.y
-					
+
 					z *= -1
-					
+
 				)
 				else
 				(
@@ -208,7 +208,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	-------------------------------------------------------------------------------------
 	-- Dump uvs
 
-	function DumpUvs src = 
+	function DumpUvs src =
 	(
 
 		Format "\"uvs\": [[" to:ostream
@@ -225,7 +225,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 				u = uvw.x
 
-				if flipUV.checked then 
+				if flipUV.checked then
 				(
 					v = 1 - uvw.y
 				)
@@ -249,11 +249,11 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	-------------------------------------------------------------------------------------
 	-- Dump faces
 
-	function DumpFaces src useColors = 
+	function DumpFaces src useColors =
 	(
 
 		Format "\"faces\": [" to:ostream
-		
+
 		num = src.count
 
 		if num > 0 then
@@ -268,9 +268,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
 				fuv = zface[2]
 				m   = zface[3] - 1
 				fc  = zface[4]
-				
+
 				needsFlip = zface[5]
-				
+
 				isTriangle = true
 				hasMaterial = true
 				hasFaceUvs = false
@@ -289,12 +289,12 @@ rollout ThreeJSExporter "ThreeJSExporter"
 				faceType = bit.set faceType 6 hasFaceVertexNormals
 				faceType = bit.set faceType 7 hasFaceColors
 				faceType = bit.set faceType 8 hasFaceVertexColors
-				
+
 				if i > 1 then
 				(
 					Format "," faceType to:ostream
 				)
-				
+
 				Format "%" faceType to:ostream
 
 				if isTriangle then
@@ -303,8 +303,8 @@ rollout ThreeJSExporter "ThreeJSExporter"
 					va = (fv.x - 1) as Integer
 					vb = (fv.y - 1) as Integer
 					vc = (fv.z - 1) as Integer
-					
-					if flipFace.checked or needsFlip then 
+
+					if flipFace.checked or needsFlip then
 					(
 
 						tmp = vb
@@ -312,26 +312,26 @@ rollout ThreeJSExporter "ThreeJSExporter"
 						vc = tmp
 
 					)
-					
-					
+
+
 					Format ",%,%,%" va vb vc to:ostream
 
-				
-					if hasMaterial then 
+
+					if hasMaterial then
 					(
 
 						Format ",%" m to:ostream
 
 					)
-					
+
 					if hasFaceVertexUvs then
 					(
 
 						ua = (fuv.x - 1) as Integer
 						ub = (fuv.y - 1) as Integer
 						uc = (fuv.z - 1) as Integer
-						
-						if flipFace.checked or needsFlip then 
+
+						if flipFace.checked or needsFlip then
 						(
 
 							tmp = ub
@@ -339,15 +339,15 @@ rollout ThreeJSExporter "ThreeJSExporter"
 							uc = tmp
 
 						)
-						
+
 						Format ",%,%,%" ua ub uc to:ostream
 
 					)
-				
+
 					if hasFaceVertexNormals then
 					(
 
-						if smoothNormal.checked then 
+						if smoothNormal.checked then
 						(
 
 							-- normals have the same indices as vertices
@@ -357,7 +357,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 							nc = vc
 
 						)
-						else 
+						else
 						(
 							-- normals have the same indices as face
 
@@ -366,8 +366,8 @@ rollout ThreeJSExporter "ThreeJSExporter"
 							nc = na
 
 						)
-						
-						if flipFace.checked or needsFlip then 
+
+						if flipFace.checked or needsFlip then
 						(
 
 							tmp = nb
@@ -375,20 +375,20 @@ rollout ThreeJSExporter "ThreeJSExporter"
 							nc = tmp
 
 						)
-						
+
 						Format ",%,%,%" na nb nc to:ostream
 
 					)
 
-				
+
 					if hasFaceVertexColors then
 					(
 
 						ca = (fc.x - 1) as Integer
 						cb = (fc.y - 1) as Integer
 						cc = (fc.z - 1) as Integer
-						
-						if flipFace.checked or needsFlip then 
+
+						if flipFace.checked or needsFlip then
 						(
 
 							tmp = cb
@@ -396,13 +396,13 @@ rollout ThreeJSExporter "ThreeJSExporter"
 							cc = tmp
 
 						)
-						
+
 						Format ",%,%,%" ca cb cc to:ostream
 
 					)
 
 				)
-				
+
 			)
 
 		)
@@ -414,7 +414,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	-------------------------------------------------------------------------------------
 	-- Dump color
 
-	function DumpColor pcolor label = 
+	function DumpColor pcolor label =
 	(
 		r = pcolor.r / 255
 		g = pcolor.g / 255
@@ -426,19 +426,19 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 		Format "\"%\"  : [%, %, %],\n" label fr fg fb to:ostream
 
-	)	
+	)
 
 	-------------------------------------------------------------------------------------
 	-- Dump map
 
-	function DumpMap pmap label = 
+	function DumpMap pmap label =
 	(
 
 		if classof pmap == BitmapTexture then
 		(
 			bm = pmap.bitmap
 
-			if bm != undefined then 
+			if bm != undefined then
 			(
 
 				fname = filenameFromPath bm.filename
@@ -453,7 +453,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	-------------------------------------------------------------------------------------
 	-- Export materials
 
-	function ExportMaterials zmaterials zcolors = 
+	function ExportMaterials zmaterials zcolors =
 	(
 
 		Format "\"materials\": [\n" to:ostream
@@ -474,9 +474,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
 			(
 
 				useVertexColors = zcolors[i]
-				
+
 				Format "\"DbgName\"  : \"%\",\n" mat.name to:ostream
-				
+
 				-- colors
 
 				DumpColor mat.diffuse  "colorDiffuse"
@@ -485,7 +485,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 				t = mat.opacity / 100
 				s = mat.glossiness
-				
+
 				Format "\"transparency\"  : %,\n" t to:ostream
 				Format "\"specularCoef\"  : %,\n" s to:ostream
 
@@ -498,24 +498,24 @@ rollout ThreeJSExporter "ThreeJSExporter"
 				DumpMap mat.opacityMap 	"mapAlpha"
 
 			)
-			else 
+			else
 			(
-				
+
 				useVertexColors = false
-				
+
 				Format "\"DbgName\"  : \"%\",\n" "dummy" to:ostream
-				
+
 				DumpColor red "colorDiffuse"
-				
+
 			)
-				
+
 			Format "\"vertexColors\" : %\n" useVertexColors to:ostream
 			Format "}" to:ostream
 
 			if ( i < totalMaterials ) then Format "," to:ostream
 			Format "\n\n" to:ostream
 
-		)		
+		)
 
 		Format "],\n\n" to:ostream
 
@@ -546,7 +546,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	(
 
 		nColors = GetNumCPVVerts obj
-		
+
 		if nColors > 0 then
 		(
 
@@ -573,8 +573,8 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		(
 
 			num = obj.numVerts
-			
-			for i = 1 to num do 
+
+			for i = 1 to num do
 			(
 
 				n = GetNormal obj i
@@ -596,7 +596,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 			num = obj.numFaces
 
-			for i = 1 to num do 
+			for i = 1 to num do
 			(
 
 				n = GetFaceNormal obj i
@@ -622,8 +622,8 @@ rollout ThreeJSExporter "ThreeJSExporter"
 	function ExtractUvs obj whereto =
 	(
 		n = obj.numTVerts
-		
-		for i = 1 to n do 
+
+		for i = 1 to n do
 		(
 
 			v = GetTVert obj i
@@ -643,10 +643,10 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 		useMultiMaterial = false
 		materialIDList = #()
-		
+
 		materialClass = classof objMaterial
-		
-		if materialClass == StandardMaterial then 
+
+		if materialClass == StandardMaterial then
 		(
 
 			fm = findItem allMaterials objMaterial
@@ -657,12 +657,12 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 			useMultiMaterial = true
 
-			for i = 1 to n do 
+			for i = 1 to n do
 			(
 
 				mID = GetFaceMatID objMesh i
 				materialIndex = findItem objMaterial.materialIDList mID
-				
+
 				if materialIndex > 0 then
 				(
 
@@ -670,7 +670,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 					mMergedIndex = findItem allMaterials subMaterial
 
-					if mMergedIndex > 0 then 
+					if mMergedIndex > 0 then
 					(
 
 						materialIDList[mID] = mMergedIndex
@@ -696,29 +696,29 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		)
 		else
 		(
-			
+
 			-- undefined material
-			
+
 			fm = findItem allMaterials false
-			
+
 		)
-		
-		for i = 1 to n do 
+
+		for i = 1 to n do
 		(
 
 			zface = #()
-			
+
 			fv = GetFace objMesh i
 
 			fv.x += offsetVert
 			fv.y += offsetVert
 			fv.z += offsetVert
 
-			if useMultiMaterial then 
+			if useMultiMaterial then
 			(
 
 				mID = GetFaceMatID objMesh i
-				fm = materialIDList[mID]				
+				fm = materialIDList[mID]
 
 			)
 
@@ -726,7 +726,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 			(
 
 				fuv = GetTVFace objMesh i
-				
+
 				fuv.x += offsetUv
 				fuv.y += offsetUv
 				fuv.z += offsetUv
@@ -738,12 +738,12 @@ rollout ThreeJSExporter "ThreeJSExporter"
 				fuv = false
 
 			)
-			
+
 			if hasVColors then
 			(
 
 				fc = GetVCFace objMesh i
-				
+
 				fc.x += offsetColor
 				fc.y += offsetColor
 				fc.z += offsetColor
@@ -756,7 +756,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 			)
 
-			append zface fv 
+			append zface fv
 			append zface fuv
 			append zface fm
 			append zface fc
@@ -770,10 +770,10 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 	-------------------------------------------------------------------------------------
 	-- Extract materials from eventual multi-material
-	
+
 	function ExtractMaterials objMesh objMaterial whereto wheretoColors zname hasVColors =
 	(
-		
+
 		materialClass = classof objMaterial
 
 		if materialClass == StandardMaterial then
@@ -792,13 +792,13 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		(
 
 			n = objMesh.numFaces
-			
-			for i = 1 to n do 
+
+			for i = 1 to n do
 			(
-			
+
 				mID = getFaceMatId objMesh i
 				materialIndex = findItem objMaterial.materialIDList mID
-				
+
 				if materialIndex > 0 then
 				(
 
@@ -812,16 +812,16 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 					)
 
-				)				
+				)
 
 			)
 
 		)
 		else
 		(
-			
+
 			-- unknown or undefined material
-			
+
 			append whereto false
 			append wheretoColors false
 
@@ -831,8 +831,8 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 	-------------------------------------------------------------------------------------
 	-- Hack to figure out if normals are messed up
-	
-	function NeedsFaceFlip node = 
+
+	function NeedsFaceFlip node =
 	(
 		needsFlip = false
 
@@ -865,29 +865,29 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		(
 			needsFlip = false
 			hasVColors = false
-			
+
 			zmesh = SnapshotAsMesh node
-			
+
 			if autoflipFace.checked then
 			(
 
 				needsFlip = NeedsFaceFlip node
 
 			)
-			
+
 			if exportColor.checked and ( getNumCPVVerts zmesh ) > 0 then
 			(
 
 				hasVColors = true
 
 			)
-			
+
 			return #( zmesh, node.name, node.material, needsFlip, hasVColors )
 
 		)
 
 		-- Not geometry ... could be a camera, light, etc.
-		
+
 		return #( false, node.name, 0, false, false )
 
 	)
@@ -905,31 +905,31 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		mergedVertices = #()
 		mergedNormals = #()
 		mergedColors = #()
-		
+
 		mergedUvs = #()
 		mergedFaces = #()
-		
+
 		mergedMaterials = #()
 		mergedMaterialsColors = #()
-		
+
 		sceneHasVColors = false
-		
-		for obj in selection do 
+
+		for obj in selection do
 		(
 
 			result = ExtractMesh obj
 			meshObj = result[1]
 
-			if ClassOf meshObj == TriMesh then 
+			if ClassOf meshObj == TriMesh then
 			(
 
 				meshName     = result[2]
 				meshMaterial = result[3]
 				needsFlip    = result[4]
 				hasVColors   = result[5]
-				
+
 				sceneHasVColors = sceneHasVColors or hasVColors
-				
+
 				append meshObjects result
 
 				vertexOffset = mergedVertices.count
@@ -941,7 +941,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 				ExtractVertices meshObj mergedVertices
 				ExtractNormals meshObj mergedNormals needsFlip
 				ExtractColors meshObj mergedColors
-				
+
 				ExtractUvs meshObj mergedUvs
 
 				ExtractFaces meshObj meshMaterial mergedFaces mergedMaterials needsFlip hasVColors vertexOffset uvOffset colorOffset
@@ -953,13 +953,13 @@ rollout ThreeJSExporter "ThreeJSExporter"
 		totalVertices = mergedVertices.count
 		totalFaces = mergedFaces.count
 		totalMaterials = mergedMaterials.count
-		
+
 		totalColors = 0
 		totalNormals = 0
 		totalUvs = 0
-		
+
 		useColors = false
-		
+
 		if sceneHasVColors and exportColor.checked then
 		(
 
@@ -968,7 +968,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 		)
 
-		if exportNormal.checked then 
+		if exportNormal.checked then
 		(
 
 			totalNormals = mergedNormals.count
@@ -993,7 +993,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 		i = 0
 
-		for obj in meshObjects do 
+		for obj in meshObjects do
 		(
 
 			meshName = obj[2]
@@ -1070,5 +1070,5 @@ rollout ThreeJSExporter "ThreeJSExporter"
 
 	)
 
-) 
+)
 createDialog ThreeJSExporter width:300

+ 37 - 0
utils/exporters/utf8/README

@@ -0,0 +1,37 @@
+-------------------------
+---- three.js README ----
+-------------------------
+
+Slightly modified "mesh.h" so that compressor:
+
+- compiles with latest MinGW on Windows 64-bit
+  (had to replace %z size_t formatting option)
+
+- dumps to stderr scaling and offset parameters
+
+
+Also for convenience added pre-build executable for Windows.
+
+Latest version of compressor can be downloaded at webgl-loader repository:
+
+http://code.google.com/p/webgl-loader/
+
+--------------------------------------------
+---- Original README from webgl-loader -----
+--------------------------------------------
+
+Usage: ./objcompress in.obj [out.utf8]
+
+        If 'out' is specified, then attempt to write out a compressed,
+        UTF-8 version to 'out.'
+
+        If not, write a JSON version to STDOUT.
+
+
+Building:
+
+Since there are no external dependences outside of the C/C++ standard
+libraries, you can pretty much build this however you please. I've
+included a cheeky way to do this on POSIX-like systems by including a
+build shell script at the top of the file itself. You can build by
+making the .cc file executable, and running it on the command line.

+ 1 - 0
utils/exporters/utf8/build.bat

@@ -0,0 +1 @@
+g++ objcompress.cc -O2 -Wall -o objcompress

+ 787 - 0
utils/exporters/utf8/mesh.h

@@ -0,0 +1,787 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you
+// may not use this file except in compliance with the License. You
+// may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied. See the License for the specific language governing
+// permissions and limitations under the License.
+
+#ifndef WEBGL_LOADER_MESH_H_
+#define WEBGL_LOADER_MESH_H_
+
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
+
+typedef unsigned short uint16;
+typedef short int16;
+
+typedef std::vector<float> AttribList;
+typedef std::vector<int> IndexList;
+typedef std::vector<uint16> QuantizedAttribList;
+
+struct DrawMesh {
+  // Interleaved vertex format:
+  //  3-D Position
+  //  3-D Normal
+  //  2-D TexCoord
+  // Note that these
+  AttribList interleaved_attribs;
+  // Indices are 0-indexed.
+  IndexList triangle_indices;
+};
+
+void DumpJsonFromQuantizedAttribs(const QuantizedAttribList& attribs) {
+  puts("var attribs = new Uint16Array([");
+  for (size_t i = 0; i < attribs.size(); i += 8) {
+    printf("%u,%hu,%hu,%hu,%hu,%hu,%hu,%hu,\n",
+           attribs[i + 0], attribs[i + 1], attribs[i + 2], attribs[i + 3],
+           attribs[i + 4], attribs[i + 5], attribs[i + 6], attribs[i + 7]);
+  }
+  puts("]);");
+}
+
+void DumpJsonFromInterleavedAttribs(const AttribList& attribs) {
+  puts("var attribs = new Float32Array([");
+  for (size_t i = 0; i < attribs.size(); i += 8) {
+    printf("%f,%f,%f,%f,%f,%f,%f,%f,\n",
+           attribs[i + 0], attribs[i + 1], attribs[i + 2], attribs[i + 3],
+           attribs[i + 4], attribs[i + 5], attribs[i + 6], attribs[i + 7]);
+  }
+  puts("]);");
+}
+
+void DumpJsonFromIndices(const IndexList& indices) {
+  puts("var indices = new Uint16Array([");
+  for (size_t i = 0; i < indices.size(); i += 3) {
+    printf("%d,%d,%d,\n", indices[i + 0], indices[i + 1], indices[i + 2]);
+  }
+  puts("]);");
+}
+
+// A short list of floats, useful for parsing a single vector
+// attribute.
+class ShortFloatList {
+ public:
+  static const size_t kMaxNumFloats = 4;
+  ShortFloatList()
+      : size_(0) { }
+
+  // Parse up to kMaxNumFloats from C string.
+  size_t ParseLine(const char* line) {
+    for (size_ = 0; size_ != kMaxNumFloats; ++size_) {
+      char* endptr = NULL;
+      a_[size_] = strtof(line, &endptr);
+      if (endptr == NULL || line == endptr) break;
+      line = endptr;
+    }
+    return size_;
+  }
+
+  void AppendTo(AttribList* attribs) const {
+    attribs->insert(attribs->end(), a_, a_ + size_);
+  }
+
+  bool empty() const { return size_ == 0; }
+
+  size_t size() const { return size_; }
+ private:
+  float a_[kMaxNumFloats];
+  size_t size_;
+};
+
+class IndexFlattener {
+ public:
+  explicit IndexFlattener(size_t num_positions)
+      : count_(0),
+        table_(num_positions) {
+  }
+
+  int count() const { return count_; }
+
+  // Returns a pair of: < flattened index, newly inserted >.
+  std::pair<int, bool> GetFlattenedIndex(int position_index,
+                                         int texcoord_index,
+                                         int normal_index) {
+    // First, optimistically look up position_index in the table.
+    IndexType& index = table_[position_index];
+    if (index.position_or_flat == kIndexUnknown) {
+      // This is the first time we've seen this position in the table,
+      // so fill it. Since the table is indexed by position, we can
+      // use the position_or_flat_index field to store the flat index.
+      const int flat_index = count_++;
+      index.position_or_flat = flat_index;
+      index.texcoord = texcoord_index;
+      index.normal = normal_index;
+      return std::make_pair(flat_index, true);
+    } else if (index.position_or_flat == kIndexNotInTable) {
+      // There are multiple flattened indices at this position index,
+      // so resort to the map.
+      return GetFlattenedIndexFromMap(position_index,
+                                      texcoord_index,
+                                      normal_index);
+    } else if (index.texcoord == texcoord_index &&
+               index.normal == normal_index) {
+      // The other indices match, so we can use the value cached in
+      // the table.
+      return std::make_pair(index.position_or_flat, false);
+    }
+    // The other indices don't match, so we mark this table entry,
+    // and insert both the old and new indices into the map.
+    const IndexType old_index(position_index, index.texcoord, index.normal);
+    map_.insert(std::make_pair(old_index, index.position_or_flat));
+    index.position_or_flat = kIndexNotInTable;
+    const IndexType new_index(position_index, texcoord_index, normal_index);
+    const int flat_index = count_++;
+    map_.insert(std::make_pair(new_index, flat_index));
+    return std::make_pair(flat_index, true);
+  }
+ private:
+  std::pair<int, bool> GetFlattenedIndexFromMap(int position_index,
+                                                int texcoord_index,
+                                                int normal_index) {
+    IndexType index(position_index, texcoord_index, normal_index);
+    MapType::iterator iter = map_.lower_bound(index);
+    if (iter == map_.end() || iter->first != index) {
+      const int flat_index = count_++;
+      map_.insert(iter, std::make_pair(index, flat_index));
+      return std::make_pair(flat_index, true);
+    } else {
+      return std::make_pair(iter->second, false);
+    }
+  }
+
+  static const int kIndexUnknown = -1;
+  static const int kIndexNotInTable = -2;
+
+  struct IndexType {
+    IndexType()
+        : position_or_flat(kIndexUnknown),
+          texcoord(kIndexUnknown),
+          normal(kIndexUnknown)
+    { }
+
+    IndexType(int position_index, int texcoord_index, int normal_index)
+        : position_or_flat(position_index),
+          texcoord(texcoord_index),
+          normal(normal_index)
+    { }
+
+    // I'm being tricky/lazy here. The table_ stores the flattened
+    // index in the first field, since it is indexed by position. The
+    // map_ stores position and uses this struct as a key to lookup the
+    // flattened index.
+    int position_or_flat;
+    int texcoord;
+    int normal;
+
+    // An ordering for std::map.
+    bool operator<(const IndexType& that) const {
+      if (position_or_flat == that.position_or_flat) {
+        if (texcoord == that.texcoord) {
+          return normal < that.normal;
+        } else {
+          return texcoord < that.texcoord;
+        }
+      } else {
+        return position_or_flat < that.position_or_flat;
+      }
+    }
+
+    bool operator==(const IndexType& that) const {
+      return position_or_flat == that.position_or_flat &&
+          texcoord == that.texcoord && normal == that.normal;
+    }
+
+    bool operator!=(const IndexType& that) const {
+      return !operator==(that);
+    }
+  };
+  typedef std::map<IndexType, int> MapType;
+
+  int count_;
+  std::vector<IndexType> table_;
+  MapType map_;
+};
+
+// TODO: consider splitting this into a low-level parser and a high-level
+// object.
+class WavefrontObjFile {
+ public:
+  struct Group {
+    std::string name;
+    size_t start, end;
+  };
+
+  typedef std::vector<Group> GroupList;
+
+  explicit WavefrontObjFile(FILE* fp) {
+    ParseFile(fp);
+  };
+
+  const GroupList& groups() const { return groups_; }
+
+  // Populate draw_meshes.
+  void CreateDrawMeshes(std::vector<DrawMesh>* draw_meshes) {
+    draw_meshes->push_back(DrawMesh());
+    DrawMesh& draw_mesh = draw_meshes->back();
+    IndexFlattener flattener(positions_.size() / positionDim());
+    for (size_t i = 0; i < faces_.size(); i += 3) {
+      // .OBJ files use 1-based indexing.
+      const int position_index = faces_[i + 0] - 1;
+      const int texcoord_index = faces_[i + 1] - 1;
+      const int normal_index = faces_[i + 2] - 1;
+      const std::pair<int, bool> flattened = flattener.GetFlattenedIndex(
+          position_index, texcoord_index, normal_index);
+      draw_mesh.triangle_indices.push_back(flattened.first);
+      if (flattened.second) {
+        for (size_t i = 0; i < positionDim(); ++i) {
+          draw_mesh.interleaved_attribs.push_back(
+              positions_[positionDim() * position_index + i]);
+        }
+        for (size_t i = 0; i < texcoordDim(); ++i) {
+          draw_mesh.interleaved_attribs.push_back(
+              texcoords_[texcoordDim() * texcoord_index + i]);
+        }
+        for (size_t i = 0; i < normalDim(); ++i) {
+          draw_mesh.interleaved_attribs.push_back(
+              normals_[normalDim() * normal_index + i]);
+        }
+      }
+    }
+  }
+
+  /*
+  // %z formatting chokes MinGW compiler on Windows :/
+  // using instead unsigned long
+
+  void DumpDebug() const {
+    printf("positions size: %zu\ntexcoords size: %zu\nnormals size: %zu"
+           "\nfaces size: %zu\n", positions_.size(), texcoords_.size(),
+           normals_.size(), faces_.size());
+  }
+  */
+
+  void DumpDebug() const {
+    printf("positions size: %lu\ntexcoords size: %lu\nnormals size: %lu"
+           "\nfaces size: %lu\n", (unsigned long)positions_.size(), (unsigned long)texcoords_.size(),
+           (unsigned long)normals_.size(), (unsigned long)faces_.size());
+  }
+
+ private:
+  void ParseFile(FILE* fp) {
+    // TODO: don't use a fixed-size buffer.
+    const size_t kLineBufferSize = 256;
+    char buffer[kLineBufferSize];
+    unsigned int line_num = 1;
+    while (fgets(buffer, kLineBufferSize, fp) != NULL) {
+      const char* stripped = buffer;
+      while (isspace(*stripped)) {
+        ++stripped;
+      }
+      ParseLine(stripped, line_num++);
+    }
+  }
+
+  void ParseLine(const char* line, unsigned int line_num) {
+    switch (*line) {
+      case 'v':
+        ParseAttrib(line + 1, line_num);
+        break;
+      case 'f':
+        ParseFace(line + 1, line_num);
+        break;
+      case 'g':
+        ParseGroup(line + 1, line_num);
+        break;
+      case '\0':
+      case '#':
+        break;  // Do nothing for comments or blank lines.
+      case 'p':
+        WarnLine("point unsupported", line_num);
+        break;
+      case 'l':
+        WarnLine("line unsupported", line_num);
+        break;
+      case 'u':
+        WarnLine("usemtl (?) unsupported", line_num);
+        break;
+      case 'm':
+        WarnLine("mtllib (?) unsupported", line_num);
+        break;
+      case 's':
+        WarnLine("s unsupported", line_num);
+        break;
+      default:
+        WarnLine("unknown keyword", line_num);
+        break;
+    }
+  }
+
+  void ParseAttrib(const char* line, unsigned int line_num) {
+    ShortFloatList floats;
+    floats.ParseLine(line + 1);
+    if (isspace(*line)) {
+      ParsePosition(floats, line_num);
+    } else if (*line == 't') {
+      ParseTexCoord(floats, line_num);
+    } else if (*line == 'n') {
+      ParseNormal(floats, line_num);
+    } else {
+      WarnLine("unknown attribute format", line_num);
+    }
+  }
+
+  void ParsePosition(const ShortFloatList& floats, unsigned int line_num) {
+    if (floats.size() != positionDim()) {
+      ErrorLine("bad position", line_num);
+    }
+    floats.AppendTo(&positions_);
+  }
+
+  void ParseTexCoord(const ShortFloatList& floats, unsigned int line_num) {
+    if (floats.size() != texcoordDim()) {
+      ErrorLine("bad texcoord", line_num);
+    }
+    floats.AppendTo(&texcoords_);
+  }
+
+  void ParseNormal(const ShortFloatList& floats, unsigned int line_num) {
+    if (floats.size() != normalDim()) {
+      ErrorLine("bad normal", line_num);
+    }
+    floats.AppendTo(&normals_);
+  }
+
+  // Parses faces and converts to triangle fans. This is not a
+  // particularly good tesselation in general case, but it is really
+  // simple, and is perfectly fine for triangles and quads.
+  void ParseFace(const char* line, unsigned int line_num) {
+    // Also handle face outlines as faces.
+    if (*line == 'o') ++line;
+
+    // TODO: instead of storing these indices as-is, it might make
+    // sense to flatten them right away. This can reduce memory
+    // consumption and improve access locality, especially since .OBJ
+    // face indices are so needlessly large.
+    int indices[9] = { 0 };
+    // The first index acts as the pivot for the triangle fan.
+    line = ParseIndices(line, line_num, indices + 0, indices + 1, indices + 2);
+    if (line == NULL) {
+      ErrorLine("bad first index", line_num);
+    }
+    line = ParseIndices(line, line_num, indices + 3, indices + 4, indices + 5);
+    if (line == NULL) {
+      ErrorLine("bad second index", line_num);
+    }
+    // After the first two indices, each index introduces a new
+    // triangle to the fan.
+    while ((line = ParseIndices(line, line_num,
+                                indices + 6, indices + 7, indices + 8))) {
+      faces_.insert(faces_.end(), indices, indices + 9);
+      // The most recent vertex is reused for the next triangle.
+      indices[3] = indices[6];
+      indices[4] = indices[7];
+      indices[5] = indices[8];
+      indices[6] = indices[7] = indices[8] = 0;
+    }
+  }
+
+  // Parse a single group of indices, separated by slashes ('/').
+  // TODO: convert negative indices (that is, relative to the end of
+  // the current vertex positions) to more conventional positive
+  // indices.
+  const char* ParseIndices(const char* line, unsigned int line_num,
+                           int* position_index, int* texcoord_index,
+                           int* normal_index) {
+    int bytes_consumed = 0;
+    int indices_parsed = sscanf(line, "%d/%d/%d%n",
+                                position_index, texcoord_index, normal_index,
+                                &bytes_consumed);
+    if (indices_parsed != 3) {
+      return NULL;
+    }
+
+    if (*position_index <= 0 || *texcoord_index <= 0 || *normal_index <= 0 ) {
+      ErrorLine("bad index format", line_num);
+    }
+
+    return line + bytes_consumed;
+  }
+
+  void ParseGroup(const char* line, unsigned int line_num) {
+    WarnLine("group unsupported", line_num);
+  }
+
+  void WarnLine(const char* why, unsigned int line_num) {
+    fprintf(stderr, "WARNING: %s at line %u\n", why, line_num);
+  }
+
+  void ErrorLine(const char* why, unsigned int line_num) {
+    fprintf(stderr, "ERROR: %s at line %u\n", why, line_num);
+    exit(-1);
+  }
+
+  static size_t positionDim() { return 3; }
+  static size_t texcoordDim() { return 2; }
+  static size_t normalDim() { return 3; }
+
+  AttribList positions_;
+  AttribList texcoords_;
+  AttribList normals_;
+  // Indices are 1-indexed, and per-attrib.
+  IndexList faces_;
+  GroupList groups_;
+};
+
+// Axis-aligned bounding box
+struct AABB {
+  float mins[3];
+  float maxes[3];
+};
+
+void DumpJsonFromAABB(const AABB& aabb) {
+  printf("var aabb = { mins: [%f, %f, %f], maxes: [%f, %f, %f] };\n",
+         aabb.mins[0], aabb.mins[1], aabb.mins[2],
+         aabb.maxes[0], aabb.maxes[1], aabb.maxes[2]);
+}
+
+float UniformScaleFromAABB(const AABB& aabb) {
+  const float x = aabb.maxes[0] - aabb.mins[0];
+  const float y = aabb.maxes[1] - aabb.mins[1];
+  const float z = aabb.maxes[2] - aabb.mins[2];
+  return (x > y)
+      ? ((x > z) ? x : z)
+      : ((y > z) ? y : z);
+}
+
+void AABBToCenter(const AABB& aabb, float center[3]) {
+  for (size_t i = 0; i < 3; ++i) {
+    center[i] = 0.5*(aabb.mins[i] + aabb.maxes[i]);
+  }
+}
+
+AABB AABBFromAttribs(const AttribList& interleaved_attribs) {
+  AABB aabb;
+  for (size_t i = 0; i < 3; ++i) {
+    aabb.mins[i] = FLT_MAX;
+    aabb.maxes[i] = -FLT_MAX;
+  }
+  for (size_t i = 0; i < interleaved_attribs.size(); i += 8) {
+    for (size_t j = 0; j < 3; ++j) {
+      const float attrib = interleaved_attribs[i + j];
+      if (aabb.mins[j] > attrib) {
+        aabb.mins[j] = attrib;
+      }
+      if (aabb.maxes[j] < attrib) {
+        aabb.maxes[j] = attrib;
+      }
+    }
+  }
+  return aabb;
+}
+
+uint16 Quantize(float f, float offset, float range, int bits) {
+  const float f_offset = f + offset;
+  // Losslessly multiply a float by 1 << bits;
+  const float f_scaled = ldexpf(f_offset, bits);
+  // static_cast rounds towards zero (i.e. truncates).
+  return static_cast<uint16>(f_scaled / range - 0.5f);
+}
+
+void AttribsToQuantizedAttribs(const AttribList& interleaved_attribs,
+                               QuantizedAttribList* quantized_attribs) {
+  const AABB aabb = AABBFromAttribs(interleaved_attribs);
+  const float scale = UniformScaleFromAABB(aabb);
+  quantized_attribs->resize(interleaved_attribs.size());
+  const float offsets[8] = { -aabb.mins[0], -aabb.mins[1], -aabb.mins[2],
+                             0.0f, 0.0f, 1.f, 1.f, 1.f };
+  const float scales[8] = { scale, scale, scale, 1.f, 1.f, 2.f, 2.f, 2.f };
+  const int bits[8] = { 14, 14, 14, 10, 10, 10, 10, 10 };
+  for (size_t i = 0; i < interleaved_attribs.size(); i += 8) {
+    for (size_t j = 0; j < 8; ++j) {
+      quantized_attribs->at(i + j) = Quantize(interleaved_attribs[i + j],
+                                              offsets[j], scales[j], bits[j]);
+    }
+  }
+
+  // dump for reconstruction of real dimensions in JavaScript
+  // (probably should be embedded as a part of the UTF8 file)
+  fprintf(stderr, "scale: %f, offsetX: %f, offsetY: %f, offsetZ: %f\n", scale, aabb.mins[0], aabb.mins[1], aabb.mins[2] );
+}
+
+// Based on:
+// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
+class VertexOptimizer {
+ public:
+  // TODO: this could easily work with non-quantized attribute lists.
+  VertexOptimizer(const QuantizedAttribList& attribs, const IndexList& indices)
+      : attribs_(attribs),
+        indices_(indices),
+        per_vertex_data_(attribs_.size() / 8) {
+    // The cache has an extra slot allocated to simplify the logic in
+    // InsertIndexToCache.
+    for (unsigned int i = 0; i <= kCacheSize; ++i) {
+      cache_[i] = kUnknownIndex;
+    }
+
+    // Loop through the indices, incrementing active triangle counts.
+    for (size_t i = 0; i < indices_.size(); ++i) {
+      per_vertex_data_[indices_[i]].active_tris++;
+    }
+
+    // Compute initial vertex scores.
+    for (size_t i = 0; i < per_vertex_data_.size(); ++i) {
+      per_vertex_data_[i].UpdateScore();
+    }
+  }
+
+  void GetOptimizedMesh(QuantizedAttribList* attribs, IndexList* indices) {
+    attribs->resize(attribs_.size());
+    indices->resize(indices_.size());
+
+    uint16* attribs_out = &attribs->at(0);
+    int* indices_out = &indices->at(0);
+    int next_unused_index = 0;
+    // Consume indices_, one triangle at a time. When a triangle is consumed from
+    // the middle of indices_, the last one is copied in to replace it so that we
+    // can shrink indices_ from the end.
+    while (!indices_.empty()) {
+      const size_t best_triangle = FindBestTriangle();
+      const size_t last_triangle = indices_.size() - 3;
+      // Go through the indices of the best triangle.
+      for (size_t i = 0; i < 3; ++i) {
+        const int index = indices_[best_triangle + i];
+        // After consuming this vertex, copy the corresponding index
+        // from the last triangle into this slot.
+        indices_[best_triangle + i] = indices_[last_triangle + i];
+        per_vertex_data_[index].active_tris--;
+        InsertIndexToCache(index);
+        const int cached_output_index = per_vertex_data_[index].output_index;
+        // Have we seen this index before?
+        if (cached_output_index != kUnknownIndex) {
+          *indices_out++ = cached_output_index;
+          continue;
+        }
+        // The first time we see an index, not only do we increment
+        // next_index counter, but we must also copy the corresponding
+        // attributes.
+        per_vertex_data_[index].output_index = next_unused_index;
+        for (size_t j = 0; j < 8; ++j) {
+          *attribs_out++ = attribs_[8*index + j];
+        }
+        *indices_out++ = next_unused_index++;
+      }
+      // Remove the last triangle.
+      indices_.resize(last_triangle);
+    }
+  }
+ private:
+  static const int kUnknownIndex = -1;
+  static const uint16 kCacheSize = 32;
+
+  struct VertexData {
+    VertexData()
+        : active_tris(0),
+          cache_tag(kCacheSize),
+          output_index(kUnknownIndex),
+          score(-1.f)
+    { }
+
+    void UpdateScore() {
+      if (active_tris <= 0) {
+        score = -1.f;
+        return;
+      }
+      // TODO: build initial score table.
+      if (cache_tag < 3) {
+        // The most recent triangle should has a fixed score to
+        // discourage generating nothing but really long strips. If we
+        // want strips, we should use a different optimizer.
+        const float kLastTriScore = 0.75f;
+        score = kLastTriScore;
+      } else if (cache_tag < kCacheSize) {
+        // Points for being recently used.
+        const float kScale = 1.f / (kCacheSize - 3);
+        const float kCacheDecayPower = 1.5f;
+        score = powf(1.f - kScale * (cache_tag - 3), kCacheDecayPower);
+      } else {
+        // Not in cache.
+        score = 0.f;
+      }
+
+      // Bonus points for having a low number of tris still to use the
+      // vert, so we get rid of lone verts quickly.
+      const float kValenceBoostScale = 2.0f;
+      const float kValenceBoostPower = 0.5f;
+      const float valence_boost = powf(active_tris, -kValenceBoostPower);  // rsqrt?
+      score += valence_boost * kValenceBoostScale;
+    };
+
+    int active_tris;
+    unsigned int cache_tag;  // == kCacheSize means not in cache.
+    int output_index;  // For output remapping.
+    float score;
+  };
+
+  // This also updates the vertex scores!
+  void InsertIndexToCache(int index) {
+    // Find how recently the vertex was used.
+    const unsigned int cache_tag = per_vertex_data_[index].cache_tag;
+
+    // Don't do anything if the vertex is already at the head of the
+    // LRU list.
+    if (cache_tag == 0) return;
+
+    // Loop through the cache, inserting the index at the front, and
+    // bubbling down to where the index was originally found. If the
+    // index was not originally in the cache, then it claims to be at
+    // the (kCacheSize + 1)th entry, and we use an extra slot to make
+    // that case simpler.
+    int to_insert = index;
+    for (unsigned int i = 0; i <= cache_tag; ++i) {
+      const int current_index = cache_[i];
+
+      // Update cross references between the entry of the cache and
+      // the per-vertex data.
+      cache_[i] = to_insert;
+      per_vertex_data_[to_insert].cache_tag = i;
+      per_vertex_data_[to_insert].UpdateScore();
+
+      // No need to continue if we find an empty entry.
+      if (current_index == kUnknownIndex) {
+        break;
+      }
+
+      to_insert = current_index;
+    }
+  }
+
+  size_t FindBestTriangle() {
+    float best_score = -FLT_MAX;
+    size_t best_triangle = 0;
+    // TODO: without a boundary structure, this performs a linear
+    // scan, which makes Tom Forsyth's linear algorithm run in
+    // quadratic time!
+    for (size_t i = 0; i < indices_.size(); i += 3) {
+      const float score =
+          per_vertex_data_[indices_[i + 0]].score +
+          per_vertex_data_[indices_[i + 1]].score +
+          per_vertex_data_[indices_[i + 2]].score;
+      if (score > best_score) {
+        best_score = score;
+        best_triangle = i;
+      }
+    }
+    return best_triangle;
+  }
+
+  const QuantizedAttribList& attribs_;
+  IndexList indices_;
+  std::vector<VertexData> per_vertex_data_;
+  int cache_[kCacheSize + 1];
+};
+
+uint16 ZigZag(int16 word) {
+  return (word >> 15) ^ (word << 1);
+}
+
+#define CHECK(PRED) if (!(PRED)) {                              \
+    fprintf(stderr, "%d: CHECK failed: " #PRED "\n", __LINE__); \
+    exit(-1); } else
+
+bool Uint16ToUtf8(uint16 word, std::vector<char>* utf8) {
+  const char kMoreBytesPrefix = static_cast<char>(0x80);
+  const uint16 kMoreBytesMask = 0x3F;
+  if (word < 0x80) {
+    utf8->push_back(static_cast<char>(word));
+  } else if (word < 0x800) {
+    const char kTwoBytePrefix = static_cast<char>(0xC0);
+    utf8->push_back(kTwoBytePrefix + static_cast<char>(word >> 6));
+    utf8->push_back(kMoreBytesPrefix +
+                    static_cast<char>(word & kMoreBytesMask));
+  } else if (word < 0xF800) {
+    const char kThreeBytePrefix = static_cast<char>(0xE0);
+    // We can only encode 65535 - 2048 values because of illegal UTF-8
+    // characters, such as surrogate pairs in [0xD800, 0xDFFF].
+    //TODO: what about other characters, like reversed-BOM 0xFFFE?
+    if (word >= 0xD800) {
+      // Shift the result to avoid the surrogate pair range.
+      word += 0x0800;
+    }
+    utf8->push_back(kThreeBytePrefix + static_cast<char>(word >> 12));
+    utf8->push_back(kMoreBytesPrefix +
+                    static_cast<char>((word >> 6) & kMoreBytesMask));
+    utf8->push_back(kMoreBytesPrefix +
+                    static_cast<char>(word & kMoreBytesMask));
+  } else {
+    return false;
+  }
+  return true;
+}
+
+void CompressIndicesToUtf8(const IndexList& list, std::vector<char>* utf8) {
+  // For indices, we don't do delta from the most recent index, but
+  // from the high water mark. The assumption is that the high water
+  // mark only ever moves by one at a time. Foruntately, the vertex
+  // optimizer does that for us, to optimize for per-transform vertex
+  // fetch order.
+  uint16 index_high_water_mark = 0;
+  for (size_t i = 0; i < list.size(); ++i) {
+    const int index = list[i];
+    CHECK(index >= 0);
+    CHECK(index <= index_high_water_mark);
+    CHECK(Uint16ToUtf8(index_high_water_mark - index, utf8));
+    if (index == index_high_water_mark) {
+      ++index_high_water_mark;
+    }
+  }
+}
+
+void CompressQuantizedAttribsToUtf8(const QuantizedAttribList& attribs,
+                                    std::vector<char>* utf8) {
+  for (size_t i = 0; i < 8; ++i) {
+    // Use a transposed representation, and delta compression.
+    uint16 prev = 0;
+    for (size_t j = i; j < attribs.size(); j += 8) {
+      const uint16 word = attribs[j];
+      const uint16 za = ZigZag(static_cast<int16>(word - prev));
+      prev = word;
+      CHECK(Uint16ToUtf8(za, utf8));
+    }
+  }
+}
+
+void CompressMeshToFile(const QuantizedAttribList& attribs,
+                        const IndexList& indices,
+                        const char* fn) {
+  CHECK((attribs.size() & 7) == 0);
+  const size_t num_verts = attribs.size() / 8;
+
+  fprintf(stderr, "num_verts: %lu", (unsigned long)num_verts);
+
+  CHECK(num_verts > 0);
+  CHECK(num_verts < 65536);
+  std::vector<char> utf8;
+  CHECK(Uint16ToUtf8(static_cast<uint16>(num_verts - 1), &utf8));
+  CompressQuantizedAttribsToUtf8(attribs, &utf8);
+  CompressIndicesToUtf8(indices, &utf8);
+
+  FILE* fp = fopen(fn, "wb");
+  fwrite(&utf8[0], 1, utf8.size(), fp);
+  fclose(fp);
+}
+
+#endif  // WEBGL_LOADER_MESH_H_

+ 61 - 0
utils/exporters/utf8/objcompress.cc

@@ -0,0 +1,61 @@
+#if 0  // A cute trick to making this .cc self-building from shell.
+g++ $0 -O2 -Wall -Werror -o `basename $0 .cc`;
+exit;
+#endif
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you
+// may not use this file except in compliance with the License. You
+// may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied. See the License for the specific language governing
+// permissions and limitations under the License.
+
+#include "mesh.h"
+
+const bool kQuantize = true;
+const bool kOptimize = true;
+
+int main(int argc, char* argv[]) {
+  if (argc < 2 || argc > 3) {
+    fprintf(stderr, "Usage: %s in.obj [out.utf8]\n\n"
+            "\tIf 'out' is specified, then attempt to write out a compressed,\n"
+            "\tUTF-8 version to 'out.'\n\n"
+            "\tIf not, write a JSON version to STDOUT.\n\n",
+            argv[0]);
+    return -1;
+  }
+  FILE* fp = fopen(argv[1], "r");
+  WavefrontObjFile obj(fp);
+  fclose(fp);
+  std::vector<DrawMesh> meshes;
+  obj.CreateDrawMeshes(&meshes);
+  if (kQuantize) {
+    QuantizedAttribList attribs;
+    AttribsToQuantizedAttribs(meshes[0].interleaved_attribs, &attribs);
+    if (kOptimize) {
+      QuantizedAttribList optimized_attribs;
+      IndexList optimized_indices;
+      VertexOptimizer vertex_optimizer(attribs, meshes[0].triangle_indices);
+      vertex_optimizer.GetOptimizedMesh(&optimized_attribs, &optimized_indices);
+      if (argc == 3) {
+        CompressMeshToFile(optimized_attribs, optimized_indices, argv[2]);
+      } else {
+        DumpJsonFromQuantizedAttribs(optimized_attribs);
+        DumpJsonFromIndices(optimized_indices);
+      }
+      return 0;
+    } else {
+      DumpJsonFromQuantizedAttribs(attribs);
+    }
+  } else {
+    DumpJsonFromInterleavedAttribs(meshes[0].interleaved_attribs);
+  }
+  DumpJsonFromIndices(meshes[0].triangle_indices);
+  return 0;
+}

BIN
utils/exporters/utf8/objcompress.exe


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