فهرست منبع

Merge pull request #3 from mrdoob/dev

Sync
Ben Adams 10 سال پیش
والد
کامیت
5e6fd61e1b
100فایلهای تغییر یافته به همراه2915 افزوده شده و 2490 حذف شده
  1. 221 149
      build/three.js
  2. 227 221
      build/three.min.js
  3. 1 1
      docs/api/cameras/CubeCamera.html
  4. 3 1
      docs/api/constants/CustomBlendingEquations.html
  5. 1 1
      docs/api/constants/GLState.html
  6. 14 3
      docs/api/constants/Textures.html
  7. 4 4
      docs/api/core/Raycaster.html
  8. 6 4
      docs/api/extras/geometries/CylinderGeometry.html
  9. 1 1
      docs/api/extras/helpers/CameraHelper.html
  10. 5 5
      docs/api/extras/helpers/DirectionalLightHelper.html
  11. 4 2
      docs/api/extras/helpers/EdgesHelper.html
  12. 9 11
      docs/api/extras/helpers/HemisphereLightHelper.html
  13. 1 1
      docs/api/loaders/OBJMTLLoader.html
  14. 0 114
      docs/api/loaders/SceneLoader.html
  15. 1 6
      docs/api/materials/MeshLambertMaterial.html
  16. 6 13
      docs/api/materials/MeshNormalMaterial.html
  17. 2 7
      docs/api/materials/MeshPhongMaterial.html
  18. 1 1
      docs/api/materials/SpriteMaterial.html
  19. 8 0
      docs/api/math/Color.html
  20. 141 138
      docs/api/math/Euler.html
  21. 1 2
      docs/api/math/Matrix4.html
  22. 8 5
      docs/api/math/Quaternion.html
  23. 4 1
      docs/api/math/Vector2.html
  24. 4 1
      docs/api/math/Vector3.html
  25. 9 6
      docs/api/math/Vector4.html
  26. 1 1
      docs/api/renderers/WebGLRenderTarget.html
  27. 16 4
      docs/index.html
  28. 0 1
      docs/list.js
  29. 1 5
      docs/scenes/js/material.js
  30. 7 10
      editor/css/dark.css
  31. 7 10
      editor/css/light.css
  32. 16 0
      editor/css/main.css
  33. 5 4
      editor/examples/arkanoid.app.json
  34. 63 49
      editor/examples/camera.app.json
  35. 4 4
      editor/examples/pong.app.json
  36. 13 2
      editor/index.html
  37. 28 17
      editor/js/Editor.js
  38. 0 32
      editor/js/Menubar.Edit.js
  39. 15 8
      editor/js/Menubar.File.js
  40. 2 2
      editor/js/Player.js
  41. 87 4
      editor/js/Script.js
  42. 60 0
      editor/js/Sidebar.Geometry.js
  43. 20 8
      editor/js/Sidebar.Material.js
  44. 34 6
      editor/js/Sidebar.Object3D.js
  45. 2 2
      editor/js/Sidebar.Scene.js
  46. 1 1
      editor/js/Sidebar.Script.js
  47. 1 1
      editor/js/Storage.js
  48. 0 2
      editor/js/Toolbar.js
  49. 0 6
      editor/js/Viewport.js
  50. 62 7
      editor/js/libs/app.js
  51. 197 0
      editor/js/libs/esprima.js
  52. 1 0
      editor/js/libs/sortable.min.js
  53. 15 168
      editor/js/libs/ui.js
  54. 176 0
      editor/js/libs/ui.three.js
  55. 2 1
      examples/index.html
  56. 1 1
      examples/js/AudioObject.js
  57. 9 9
      examples/js/BlendCharacter.js
  58. 3 3
      examples/js/Car.js
  59. 26 26
      examples/js/Cloth.js
  60. 9 9
      examples/js/CurveExtras.js
  61. 1 1
      examples/js/Detector.js
  62. 10 10
      examples/js/ImprovedNoise.js
  63. 1 1
      examples/js/MD2Character.js
  64. 3 3
      examples/js/MD2CharacterComplex.js
  65. 23 23
      examples/js/MarchingCubes.js
  66. 10 9
      examples/js/Ocean.js
  67. 43 43
      examples/js/Octree.js
  68. 6 6
      examples/js/ParametricGeometries.js
  69. 11 10
      examples/js/ShaderDeferred.js
  70. 49 80
      examples/js/ShaderSkin.js
  71. 22 52
      examples/js/ShaderTerrain.js
  72. 233 233
      examples/js/SimplexNoise.js
  73. 2 2
      examples/js/SimulationRenderer.js
  74. 16 23
      examples/js/SkyShader.js
  75. 154 154
      examples/js/Sparks.js
  76. 5 5
      examples/js/TypedArrayUtils.js
  77. 1 1
      examples/js/cameras/CombinedCamera.js
  78. 3 3
      examples/js/controls/EditorControls.js
  79. 2 2
      examples/js/controls/FirstPersonControls.js
  80. 1 1
      examples/js/controls/FlyControls.js
  81. 25 25
      examples/js/controls/MouseControls.js
  82. 47 16
      examples/js/controls/OrbitControls.js
  83. 5 5
      examples/js/controls/OrthographicTrackballControls.js
  84. 66 73
      examples/js/controls/TrackballControls.js
  85. 38 38
      examples/js/controls/TransformControls.js
  86. 6 6
      examples/js/crossfade/scenes.js
  87. 12 12
      examples/js/crossfade/transition.js
  88. 1 1
      examples/js/curves/NURBSCurve.js
  89. 2 2
      examples/js/curves/NURBSSurface.js
  90. 29 29
      examples/js/curves/NURBSUtils.js
  91. 13 13
      examples/js/effects/AsciiEffect.js
  92. 23 23
      examples/js/effects/VREffect.js
  93. 16 14
      examples/js/exporters/SceneExporter.js
  94. 14 14
      examples/js/geometries/ConvexGeometry.js
  95. 23 23
      examples/js/geometries/DecalGeometry.js
  96. 1 1
      examples/js/geometries/hilbert2D.js
  97. 1 1
      examples/js/geometries/hilbert3D.js
  98. 348 348
      examples/js/loaders/AWDLoader.js
  99. 27 27
      examples/js/loaders/AssimpJSONLoader.js
  100. 56 56
      examples/js/loaders/BinaryLoader.js

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 221 - 149
build/three.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 227 - 221
build/three.min.js


+ 1 - 1
docs/api/cameras/CubeCamera.html

@@ -24,7 +24,7 @@
 		scene.add( cubeCamera );
 		
 		//Create car
-		var chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, ambient: 0xffffff, envMap: cubeCamera.renderTarget } );
+		var chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: cubeCamera.renderTarget } );
 		var car = new Mesh( carGeometry, chromeMaterial );
 		scene.add( car );
 		

+ 3 - 1
docs/api/constants/CustomBlendingEquations.html

@@ -13,7 +13,9 @@
 		<div>
 		THREE.AddEquation<br />
 		THREE.SubtractEquation<br />
-		THREE.ReverseSubtractEquation
+		THREE.ReverseSubtractEquation<br />
+		THREE.MinEquation<br />
+		THREE.MaxEquation
 		</div>
 
 		<h2>Destination Factors</h2>

+ 1 - 1
docs/api/constants/GLState.html

@@ -7,7 +7,7 @@
 		<link type="text/css" rel="stylesheet" href="../../page.css" />
 	</head>
 	<body>
-		<h1>GL State Conflicts</h1>
+		<h1>GL State Constants</h1>
 
 		<h2>Cull Face</h2>
 		<div>

+ 14 - 3
docs/api/constants/Textures.html

@@ -21,6 +21,8 @@
 		THREE.UVMapping<br />
 		THREE.CubeReflectionMapping<br />
 		THREE.CubeRefractionMapping<br />
+		THREE.EquirectangularReflectionMapping<br />
+		THREE.EquirectangularRefractionMapping<br />
 		THREE.SphericalReflectionMapping
 		</div>
 
@@ -49,7 +51,8 @@
 		THREE.UnsignedShortType<br />
 		THREE.IntType<br />
 		THREE.UnsignedIntType<br />
-		THREE.FloatType
+		THREE.FloatType<br />
+		THREE.HalfFloatType
 		</div>
 
 		<h2>Pixel Types</h2>
@@ -65,10 +68,11 @@
 		THREE.RGBFormat<br />
 		THREE.RGBAFormat<br />
 		THREE.LuminanceFormat<br />
-		THREE.LuminanceAlphaFormat
+		THREE.LuminanceAlphaFormat<br />
+		THREE.RGBEFormat
 		</div>
 
-		<h2>Compressed Texture Formats</h2>
+		<h2>DDS / ST3C Compressed Texture Formats</h2>
 		<div>
 		THREE.RGB_S3TC_DXT1_Format<br />
 		THREE.RGBA_S3TC_DXT1_Format<br />
@@ -76,6 +80,13 @@
 		THREE.RGBA_S3TC_DXT5_Format
 		</div>
 
+		<h2>PVRTC Compressed Texture Formats</h2>
+		<div>
+		THREE.RGB_PVRTC_4BPPV1_Format<br />
+		THREE.RGB_PVRTC_2BPPV1_Format<br />
+		THREE.RGBA_PVRTC_4BPPV1_Format<br />
+		THREE.RGBA_PVRTC_2BPPV1_Format
+		</div>
 
 		<h2>Source</h2>
 

+ 4 - 4
docs/api/core/Raycaster.html

@@ -23,8 +23,8 @@
 			// calculate mouse position in normalized device coordinates
 			// (-1 to +1) for both components
 
-			mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1
-			mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1		
+			mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
+			mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;		
 		
 		}
 
@@ -36,9 +36,9 @@
 			// calculate objects intersecting the picking ray
 			var intersects = raycaster.intersectObjects( scene.children );
 
-			for ( var intersect in intersects ) {
+			for ( var i = 0; i < intersects.length; i++ ) {
 
-				intersect.object.material.color = new THREE.Color( 0xff0000 );
+				intersects[ i ].object.material.color.set( 0xff0000 );
 			
 			}
 			

+ 6 - 4
docs/api/extras/geometries/CylinderGeometry.html

@@ -8,7 +8,7 @@
 	</head>
 	<body>
 		[page:Geometry] &rarr;
-		
+
 		<h1>[name]</h1>
 
 		<div class="desc">A class for generating cylinder geometries</div>
@@ -26,21 +26,23 @@
 		<h2>Constructor</h2>
 
 
-		<h3>[name]([page:Float radiusTop], [page:Float radiusBottom], [page:Float height], [page:Integer radiusSegments], [page:Integer heightSegments], [page:Boolean openEnded])</h3>
+		<h3>[name]([page:Float radiusTop], [page:Float radiusBottom], [page:Float height], [page:Integer radiusSegments], [page:Integer heightSegments], [page:Boolean openEnded], [page:Float thetaStart], [page:Float thetaLength])</h3>
 		<div>
 		radiusTop — Radius of the cylinder at the top. Default is 20.<br />
 		radiusBottom — Radius of the cylinder at the bottom. Default is 20.<br />
 		height — Height of the cylinder. Default is 100.<br />
 		radiusSegments — Number of segmented faces around the circumference of the cylinder. Default is 8<br />
 		heightSegments — Number of rows of faces along the height of the cylinder. Default is 1.<br />
-		openEnded — A Boolean indicating whether the ends of the cylinder are open or capped. Default is false, meaning capped.
+		openEnded — A Boolean indicating whether the ends of the cylinder are open or capped. Default is false, meaning capped.<br />
+		thetaStart — Start angle for first segment, default = 0 (three o'clock position).<br />
+		thetaLength — The central angle, often called theta, of the circular sector. The default is 2*Pi, which makes for a complete cylinder.
 		</div>
 
 
 		<h2>Properties</h2>
 
 		<div>
-		Each of the contructor parameters is accessible as a property of the same name. Any modification of these properties after instantiation does not change the geometry.
+		Each of the constructor parameters is accessible as a property of the same name. Any modification of these properties after instantiation does not change the geometry.
 		</div>
 
 

+ 1 - 1
docs/api/extras/helpers/CameraHelper.html

@@ -45,7 +45,7 @@
 		<h2>Methods</h2>
 
 
-		<h3>[method:todo update]()</h3>
+		<h3>[method:null update]()</h3>
 		<div>
 		Updates the helper based on the projectionMatrix of the camera.
 		</div>

+ 5 - 5
docs/api/extras/helpers/DirectionalLightHelper.html

@@ -17,7 +17,7 @@
 		<h2>Constructor</h2>
 
 
-		<h3>[name]([DirectionalLight:todo light], [page:Number size])</h3>
+		<h3>[name]([page:DirectionalLight light], [page:Number size])</h3>
 		<div>
 		light -- [page:DirectionalLight] -- Light to visualize <br />
 		size -- dimensions of the plane
@@ -32,18 +32,18 @@
 
 		<h3>[property:Line lightPlane]</h3>
 		<div>
-		todo
+		Contains the line mesh showing the location of the directional light.
 		</div> 
 
 		<h3>[property:DirectionalLight light]</h3>
 		<div>
-		todo
+		Contains the directionalLight.
 		</div> 
 
 		<h3>[property:Line targetLine]</h3>
 		<div>
-		todo
-		</div> 
+		Contains the line mesh that shows the direction of the light. 
+		</div>
 
 		<h2>Methods</h2>
 

+ 4 - 2
docs/api/extras/helpers/EdgesHelper.html

@@ -27,10 +27,12 @@
 		</code>
 
 		<h2>Constructor</h2>
-		<h3>[name]( [page:Object3D object], [page:Color color] )</h3>
+		<h3>[name]( [page:Object3D object], [page:Color color], [page:Float thresholdAngle] )</h3>
 		<div>
 		object -- Object of which to draw edges <br />
-		color -- Color of the edges.
+		color -- Color of the edges.<br />
+		thresholdAngle -- the minimim angle (in degrees), between the face normals of adjacent faces, that is required to render an edge. Default is 0.1.
+
 		</div>
 		<div>
 		Creates a [page:Line], showing only the "hard" edges of the passed object; specifically, no edge will be drawn between faces which are adjacent and coplanar (or nearly coplanar).

+ 9 - 11
docs/api/extras/helpers/HemisphereLightHelper.html

@@ -11,20 +11,18 @@
 		
 		<h1>[name]</h1>
 
-		<div class="desc">todo</div>
+		<div class="desc">Creates a visual aid for a [page:HemisphereLight HemisphereLight].</div>
 
 
 		<h2>Constructor</h2>
 
-		<h3>[name]([page:todo light], [page:todo sphereSize], [page:todo arrowLength], [page:todo domeSize])</h3>
+		<h3>[name]([page:HemisphereLight light], [page:Number sphereSize])</h3>
 		<div>
-		light -- todo <br />
-		sphereSize -- todo <br />
-		arrowLength -- todo <br />
-		domeSize -- todo
+		light -- The HemisphereLight. <br />
+		sphereSize -- The size of the sphere that shows the location.
 		</div>
 		<div>
-		todo
+		Creates an helper for the hemispherelight.
 		</div>
 
 
@@ -32,20 +30,20 @@
 
 		<h3>[property:Mesh lightSphere]</h3>
 		<div>
-		todo
+		The sphere mesh that shows the location of the hemispherelight. 
 		</div> 
 
 		<h3>[property:HemisphereLight light]</h3>
 		<div>
-		todo
+		Contains the HemisphereLight.
 		</div> 
 
 
 		<h2>Methods</h2>
 
-		<h3>[method:todo update]()</h3>
+		<h3>[method:null update]()</h3>
 		<div>
-		todo
+		Updates the helper to match the position and direction of the [page:.light].
 		</div>
 
 

+ 1 - 1
docs/api/loaders/OBJMTLLoader.html

@@ -47,7 +47,7 @@
 		</div>
 		<div>
 		Parse an <em>obj</em> text structure and return an [page:Object3D].<br />
-		Found objects are converted to [page:Mesh] with a [page:BufferGeometry] and materials are converted to [page:MeshLambertMaterial].
+		Found objects are converted to a [page:Mesh] and materials are converted to [page:MeshLambertMaterial].
 		</div>
 
 		<h2>Example</h2>

+ 0 - 114
docs/api/loaders/SceneLoader.html

@@ -1,114 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-	<head>
-		<meta charset="utf-8" />
-		<script src="../../list.js"></script>
-		<script src="../../page.js"></script>
-		<link type="text/css" rel="stylesheet" href="../../page.css" />
-	</head>
-	<body>
-
-		<h1>[name]</h1>
-
-		<div class="desc">A loader for loading a [page:Scene] from a <em>JSON</em> resource.</div>
-
-
-		<h2>Constructor</h2>
-
-		<h3>[name]( [page:LoadingManager manager] )</h3>
-		<div>
-		[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
-		</div>
-		<div>
-		Creates a new [name].
-		</div>
-
-		<h2>Properties</h2>
-
-
-		<h2>Methods</h2>
-
-		<h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
-		<div>
-		[page:String url] — required<br />
-		[page:Function onLoad] — Will be called when load completes. The argument will be an [page:Object] containing the loaded components.<br />
-		[page:Function onProgress] — Will be called while load progresses. The argument will be the XmlHttpRequest instance, that contain .[page:Integer total] and .[page:Integer loaded] bytes.<br />
-		[page:Function onError] — Will be called when load errors.<br />
-		</div>
-		<div>
-		Begin loading from url and call onLoad with the parsed scene.
-		</div>
-
-		<h3>[method:Object parse]( [page:Object json], [page:Function callbackFinished], [page:String url] )</h3>
-		<div>
-		[page:Object json] — The <em>JSON</em> structure to parse.<br />
-		[page:Function callbackFinished] — Will be called when parse completes.<br />
-		[page:String url] — Will be used as base for assets' relative URLs.<br />
-		</div>
-		<div>
-		Parse a <em>JSON</em> scene description and return a new [page:Object] with fully instantiated Three.js objects.
-		</div>
-
-		<h3>[method:null setCrossOrigin]( [page:String value] )</h3>
-		<div>
-		[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
-		</div>
-
-		<h3>[method:null addGeometryHandler]( [page:String typeID], [page:Function loaderClass] )</h3>
-		<div>
-		[page:String typeID] — The type to handle.<br />
-		[page:Function loaderClass] — The handler class.<br />
-		</div>
-		<div>
-		Add an handler for a specific geometry type.
-		</div>
-
-		<h3>[method:null addHierarchyHandler]( [page:String typeID], [page:Function loaderClass] )</h3>
-		<div>
-		[page:String typeID] — The type to handle.<br />
-		[page:Function loaderClass] — The handler class.<br />
-		</div>
-		<div>
-		Add an handler for a specific object type.
-		</div>
-
-
-		<h2>Example</h2>
-
-		<code>
-		// instantiate a loader
-		var loader = new THREE.SceneLoader();
-
-		// Handle STL geometries
-		loader.addGeometryHandler( "stl", THREE.STLLoader );
-
-		// Handle OBJ objects
-		loader.addHierarchyHandler( "obj", THREE.OBJLoader );
-
-		// load a JSON resource
-		loader.load(
-			// resource URL
-			'scenes/test_scene.js',
-			// Function when resource is loaded
-			function ( result ) {
-				scene.add( result.scene );
-			},
-			// Function called when download progresses
-			function ( xhr ) {
-				console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
-			},
-			// Function called when download errors
-			function ( xhr ) {
-				console.log( 'An error happened' );
-			}
-		);
-		</code>
-
-		[example:webgl_loader_scene]
-
-
-		<h2>Source</h2>
-
-		[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/SceneLoader.js examples/js/loaders/SceneLoader.js]
-	</body>
-</html>

+ 1 - 6
docs/api/materials/MeshLambertMaterial.html

@@ -29,7 +29,7 @@
 		specularMap — Set specular map. Default is null.<br />
 		alphaMap — Set alpha map. Default is null.<br />
 		envMap — Set env map. Default is null.<br />
-		fog — Define whether the material color is affected by global fog settings. Default is false.
+		fog — Define whether the material color is affected by global fog settings. Default is false.<br />
 		shading — How the triangles of a curved surface are rendered. Default is [page:Materials THREE.SmoothShading].<br/>
 		wireframe — Render geometry as wireframe. Default is false (i.e. render as smooth shaded).<br/>
 		wireframeLinewidth — Controls wireframe thickness. Default is 1.<br/>
@@ -49,11 +49,6 @@
 		Diffuse color of the material. Default is white.<br />
 		</div>
 
-		<h3>[property:Color ambient]</h3>
-		<div>
-		Ambient color of the material, multiplied by the color of the [page:AmbientLight]. Default is white.<br />
-		</div>
-
 		<h3>[property:Color emissive]</h3>
 		<div>
 		Emissive (light) color of the material, essentially a solid color unaffected by other lighting. Default is black.<br />

+ 6 - 13
docs/api/materials/MeshNormalMaterial.html

@@ -12,7 +12,7 @@
 		<h1>[name]</h1>
 
 		<div class="desc">A material that maps the normal vectors to RGB colors.</div>
-		
+
 		<iframe src='../../scenes/material-browser.html#MeshNormalMaterial'></iframe>
 
 
@@ -21,10 +21,9 @@
 
 		<h3>[name]([page:Object parameters])</h3>
 		<div>
-		parameters is an object with one or more properties defining the material's appearance. 
+		parameters is an object with one or more properties defining the material's appearance.
 		</div>
 		<div>
-		shading --  How the triangles of a curved surface are rendered. Default is [page:Materials THREE.FlatShading].<br/>
 		wireframe -- Render geometry as wireframe. Default is false (i.e. render as smooth shaded).<br/>
 		wireframeLinewidth -- Controls wireframe thickness. Default is 1.<br/>
 		morphTargets -- Define whether the material uses morphTargets. Default is false.<br/>
@@ -34,25 +33,19 @@
 		<h2>Properties</h2>
 
 
-		<h3>[property:number shading]</h3>
+		<h3>[property:boolean wireframe]</h3>
 		<div>
-			How the triangles of a curved surface are rendered: as a smooth surface, as flat separate facets, or no shading at all.<br/><br/>
-			Options are [page:Materials THREE.SmoothShading], [page:Materials THREE.FlatShading](default)
+			Render geometry as wireframe. Default is false (i.e. render as smooth shaded).
 		</div>
 
-		<h3>[property:boolean wireframe]</h3>
-		<div>
-			Render geometry as wireframe. Default is false (i.e. render as smooth shaded). 
-		</div> 
-		
 		<h3>[property:number wireframeLinewidth]</h3>
 		<div>
 			Controls wireframe thickness. Default is 1.<br/><br/>
 			Due to limitations in the ANGLE layer, on Windows platforms linewidth will always be 1 regardless of the set value.
-		</div> 
+		</div>
 
 		<h3>[property:boolean morphTargets]</h3>
-		<div>Define whether the material uses morphTargets. Default is false.</div> 
+		<div>Define whether the material uses morphTargets. Default is false.</div>
 
 		<h2>Methods</h2>
 

+ 2 - 7
docs/api/materials/MeshPhongMaterial.html

@@ -41,7 +41,7 @@
 		</div>
 		<div>
 		Example:<br>
-		materials.push( new THREE.MeshPhongMaterial( { ambient: 0x030303, color: 0xdddddd, specular: 0x009900, shininess: 30, shading: THREE.FlatShading } ) );
+		materials.push( new THREE.MeshPhongMaterial( { color: 0xdddddd, specular: 0x009900, shininess: 30, shading: THREE.FlatShading } ) );
 	
 		</div>
 
@@ -54,11 +54,6 @@
 		Diffuse color of the material. Default is white.<br />
 		</div>
 
-		<h3>[property:Color ambient]</h3>
-		<div>
-		Ambient color of the material, multiplied by the color of the [page:AmbientLight]. Default is white.<br />
-		</div>
-
 		<h3>[property:Color emissive]</h3>
 		<div>
 		Emissive (light) color of the material, essentially a solid color unaffected by other lighting. Default is black.<br />
@@ -70,7 +65,7 @@
 		</div>
 
 		<h3>[property:Float shininess]</h3>
-		<div>How shiny the specular highlight is; a higher value gives a sharper highlight. Default is *30*.</div>
+		<div>How shiny the specular highlight is; a higher value gives a sharper highlight. Default is *30*. It should not be set to 0.</div>
 
 		<h3>[property:boolean metal]</h3>
 		<div>

+ 1 - 1
docs/api/materials/SpriteMaterial.html

@@ -24,7 +24,7 @@
 		<div>
 		color - color of the sprite<br/>
 		map - the texture map<br/>
-		rotation - the rotation of the sprite
+		rotation - the rotation of the sprite<br/>
 		fog - whether or not to use the scene fog<br/>
 		</div>
 

+ 8 - 0
docs/api/math/Color.html

@@ -176,6 +176,14 @@
 		Linear interpolation of this colors rgb values and the rgb values of the first argument. The alpha argument can be thought of as the percent between the two colors, where 0 is this color and 1 is the first argument.
 		</div>
 
+		<h3>[method:Array toArray]( [page:Array array] )</h3>
+		<div>
+		array -- Optional array to store the color.
+		</div>
+		<div>
+		Returns an array [r,g,b]
+		</div>
+
 		<h3>[method:Color equals]( [page:Color c] ) [page:Color this]</h3>
 		<div>
 		Compares this color and c and returns true if they are the same, false otherwise.

+ 141 - 138
docs/api/math/Euler.html

@@ -1,141 +1,144 @@
 <!DOCTYPE html>
 <html lang="en">
-  <head>
-    <meta charset="utf-8" />
-    <script src="../../list.js"></script>
-    <script src="../../page.js"></script>
-    <link type="text/css" rel="stylesheet" href="../../page.css" />
-  </head>
-  <body>
-    <h1>[name]</h1>
-
-    <div class="desc">Euler Angles. <br/><br/>
-    
-    Euler angles describe a rotation transformation by rotating an object on its various axes in specified amounts per axis, and a specified axis order.
-    (More information on <a href='http://en.wikipedia.org/wiki/Euler_angles' target='blank'>Wikipedia</a>)</div>
-
-    <h2>Example</h2>
-
-    <code>var a = new THREE.Euler( 0, 1, 1.57, 'XYZ' );
-    var b = new THREE.Vector3( 1, 0, 1 );
-    b.applyEuler(a);
-    </code>
-
-
-    <h2>Constructor</h2>
-
-
-    <h3>[name]( [page:Float x], [page:Float y], [page:Float z], [page:String order] )</h3>
-    <div>
-    x -- [page:Float] the angle of the x axis in radians<br />
-    y -- [page:Float] the angle of the y axis in radians<br />
-    z -- [page:Float] the angle of the z axis in radians<br />
-    order -- [page:String] A string representing the order that the rotations are applied, defaults to 'XYZ' (must be upper case).
-    </div>
-    <div>
-    A euler angle for transforming
-    </div>
-
-
-    <h2>Properties</h2>
-
-    <h3>[property:Float x]</h3>
-
-    <h3>[property:Float y]</h3>
-
-    <h3>[property:Float z]</h3>
-
-    <h3>[property:String order]</h3>
-
-
-
-    <h2>Methods</h2>
-
-    <h3>[method:Euler set]( [page:Float x], [page:Float y], [page:Float z], [page:String order] ) [page:Euler this]</h3>
-    <div>
-    x -- [page:Float] Angle in x axis in radians<br />
-    y -- [page:Float] Angle in y axis in radians<br />
-    z -- [page:Float] Angle in z axis in radians<br />
-    order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
-    </div>
-    <div>
-    Sets the angles of this euler transform.
-    </div>
-
-    <h3>[method:Euler copy]( [page:Euler euler] ) [page:Euler this]</h3>
-    <div>
-    Copies value of *euler* to this euler.
-    </div>
-
-    <h3>[method:Euler setFromRotationMatrix]( [page:Matrix4 m], [page:String order] ) [page:Euler this]</h3>
-    <div>
-    m -- [page:Matrix4] assumes upper 3x3 of matrix is a pure rotation matrix (i.e. unscaled)<br />
-    order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
-    </div>
-    <div>
-    Sets the angles of this euler transform from a pure rotation matrix based on the orientation specified by order.
-    </div>
-
-    <h3>[method:Euler setFromQuaternion]( [page:Quaternion q], [page:String order] ) [page:Euler this]</h3>
-    <div>
-    q -- [page:Quaternion] quaternion must be normalized<br />
-    order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
-    </div>
-    <div>
-    Sets the angles of this euler transform from a normalized quaternion based on the orientation specified by order.
-    </div>
-
-    <h3>[method:Euler reorder]( [page:String newOrder] ) [page:Euler this]</h3>
-    <div>
-    Resets the euler angle with a new order by creating a quaternion from this euler angle and then setting this euler angle with the quaternion and the new order. <br />
-    WARNING: this discards revolution information.
-    </div>
-
-    <h3>[method:Euler setFromVector3]([page:Vector3 vector], [page:String order]) [page:Euler this]</h3>
-    <div>
-    vector -- [page:Vector3].
-    order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
-    </div>
-    <div>
-    Optionally Vector3 to the XYZ parameters of Euler, and order to the Euler's order property.
-    </div>
-
-    <h3>[method:Vector3 toVector3]()</h3>
-    <div>
-    Returns the Euler's XYZ properties as a Vector3.
-    </div>
-
-    <h3>[method:Euler fromArray]([page:Array array]) [page:Euler this]</h3>
-    <div>
-    array -- [page:Array] of length 3 or 4. array[3] is an optional order argument.
-    </div>
-    <div>
-    Assigns this euler's x angle to array[0]. <br />
-    Assigns this euler's y angle to array[1]. <br />
-    Assigns this euler's z angle to array[2]. <br />
-    Optionally assigns this euler's order to array[3].
-    </div>
-
-    <h3>[method:Array toArray]()</h3>
-    <div>
-    Returns an array [x, y, z, order].
-    </div>
-
-    <h3>[method:Boolean equals]( [page:Euler euler] )</h3>
-    <div>
-    Checks for strict equality of this euler and *euler*.
-    </div>
-
-    <h3>[method:Euler clone]()</h3>
-    <div>
-    Returns a new euler created from this euler.
-    </div>
-
-
-
-
-    <h2>Source</h2>
-
-    [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
-  </body>
+	<head>
+		<meta charset="utf-8" />
+		<script src="../../list.js"></script>
+		<script src="../../page.js"></script>
+		<link type="text/css" rel="stylesheet" href="../../page.css" />
+	</head>
+	<body>
+		<h1>[name]</h1>
+
+		<div class="desc">Euler Angles. <br/><br/>
+
+		Euler angles describe a rotation transformation by rotating an object on its various axes in specified amounts per axis, and a specified axis order.
+		(More information on <a href='http://en.wikipedia.org/wiki/Euler_angles' target='blank'>Wikipedia</a>)</div>
+
+		<h2>Example</h2>
+
+		<code>var a = new THREE.Euler( 0, 1, 1.57, 'XYZ' );
+		var b = new THREE.Vector3( 1, 0, 1 );
+		b.applyEuler(a);
+		</code>
+
+
+		<h2>Constructor</h2>
+
+
+		<h3>[name]( [page:Float x], [page:Float y], [page:Float z], [page:String order] )</h3>
+		<div>
+		x -- [page:Float] the angle of the x axis in radians<br />
+		y -- [page:Float] the angle of the y axis in radians<br />
+		z -- [page:Float] the angle of the z axis in radians<br />
+		order -- [page:String] A string representing the order that the rotations are applied, defaults to 'XYZ' (must be upper case).
+		</div>
+		<div>
+		A euler angle for transforming
+		</div>
+
+
+		<h2>Properties</h2>
+
+		<h3>[property:Float x]</h3>
+
+		<h3>[property:Float y]</h3>
+
+		<h3>[property:Float z]</h3>
+
+		<h3>[property:String order]</h3>
+
+
+
+		<h2>Methods</h2>
+
+		<h3>[method:Euler set]( [page:Float x], [page:Float y], [page:Float z], [page:String order] ) [page:Euler this]</h3>
+		<div>
+		x -- [page:Float] Angle in x axis in radians<br />
+		y -- [page:Float] Angle in y axis in radians<br />
+		z -- [page:Float] Angle in z axis in radians<br />
+		order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
+		</div>
+		<div>
+		Sets the angles of this euler transform.
+		</div>
+
+		<h3>[method:Euler copy]( [page:Euler euler] ) [page:Euler this]</h3>
+		<div>
+		Copies value of *euler* to this euler.
+		</div>
+
+		<h3>[method:Euler setFromRotationMatrix]( [page:Matrix4 m], [page:String order] ) [page:Euler this]</h3>
+		<div>
+		m -- [page:Matrix4] assumes upper 3x3 of matrix is a pure rotation matrix (i.e. unscaled)<br />
+		order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
+		</div>
+		<div>
+		Sets the angles of this euler transform from a pure rotation matrix based on the orientation specified by order.
+		</div>
+
+		<h3>[method:Euler setFromQuaternion]( [page:Quaternion q], [page:String order] ) [page:Euler this]</h3>
+		<div>
+		q -- [page:Quaternion] quaternion must be normalized<br />
+		order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
+		</div>
+		<div>
+		Sets the angles of this euler transform from a normalized quaternion based on the orientation specified by order.
+		</div>
+
+		<h3>[method:Euler reorder]( [page:String newOrder] ) [page:Euler this]</h3>
+		<div>
+		Resets the euler angle with a new order by creating a quaternion from this euler angle and then setting this euler angle with the quaternion and the new order. <br />
+		WARNING: this discards revolution information.
+		</div>
+
+		<h3>[method:Euler setFromVector3]([page:Vector3 vector], [page:String order]) [page:Euler this]</h3>
+		<div>
+		vector -- [page:Vector3].
+		order -- [page:string] Order of axes, defaults to 'XYZ' (must be upper case)
+		</div>
+		<div>
+		Optionally Vector3 to the XYZ parameters of Euler, and order to the Euler's order property.
+		</div>
+
+		<h3>[method:Vector3 toVector3]()</h3>
+		<div>
+		Returns the Euler's XYZ properties as a Vector3.
+		</div>
+
+		<h3>[method:Euler fromArray]([page:Array array]) [page:Euler this]</h3>
+		<div>
+		array -- [page:Array] of length 3 or 4. array[3] is an optional order argument.
+		</div>
+		<div>
+		Assigns this euler's x angle to array[0]. <br />
+		Assigns this euler's y angle to array[1]. <br />
+		Assigns this euler's z angle to array[2]. <br />
+		Optionally assigns this euler's order to array[3].
+		</div>
+
+		<h3>[method:Array toArray]( [page:Array array] )</h3>
+		<div>
+		array -- Optional array to store the euler.
+		</div>
+		<div>
+		Returns an array [x, y, z, order]
+		</div>
+
+		<h3>[method:Boolean equals]( [page:Euler euler] )</h3>
+		<div>
+		Checks for strict equality of this euler and *euler*.
+		</div>
+
+		<h3>[method:Euler clone]()</h3>
+		<div>
+		Returns a new euler created from this euler.
+		</div>
+
+
+
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
 </html>

+ 1 - 2
docs/api/math/Matrix4.html

@@ -165,8 +165,7 @@
 
 		<h3>[method:Array decompose]( [page:Vector3 translation], [page:Quaternion quaternion], [page:Vector3 scale] )</h3>
 		<div>
-		Decomposes this matrix into the *translation*, *quaternion* and *scale* components.<br />
-		If parameters are not passed, new instances will be created.
+		Decomposes this matrix into the *translation*, *quaternion* and *scale* components.
 		</div>
 
 		<h3>[method:Matrix4 makeTranslation]( [page:Float x], [page:Float y], [page:Float z] ) [page:Matrix4 this]</h3>

+ 8 - 5
docs/api/math/Quaternion.html

@@ -131,15 +131,18 @@
 		<h3>[method:Quaternion slerp]([page:Quaternion qb], [page:float t])</h3>
 		<div>
 		qb -- Target quaternion rotation.<br />
-		t -- Normalized [0..1] interpolation factor. 
+		t -- Normalized [0..1] interpolation factor.
 		</div>
 		<div>
 		Handles the spherical linear interpolation between this quaternion's configuration
-		and that of *qb*. *t* represents how close to the current (0) or target (1) rotation the 
-		result should be. 
+		and that of *qb*. *t* represents how close to the current (0) or target (1) rotation the
+		result should be.
 		</div>
 
-		<h3>.toArray() [page: Array]</h3>
+		<h3>[method:Array toArray]( [page:Array array] )</h3>
+		<div>
+		array -- Array to store the quaternion.
+		</div>
 		<div>
 		Returns the numerical elements of this quaternion in an array of format (x, y, z, w).
 		</div>
@@ -155,7 +158,7 @@
 
 		<h3>[method:Float lengthSq]()</h3>
 		<div>
-		Calculates the squared length of the quaternion. 
+		Calculates the squared length of the quaternion.
 		</div>
 
 		<h3>[method:Quaternion fromArray]([page:Array array])</h3>

+ 4 - 1
docs/api/math/Vector2.html

@@ -226,7 +226,10 @@
 		Sets this vector's x value to be array[0] and y value to be array[1].
 		</div>
 
-		<h3>[method:Array toArray]()</h3>
+		<h3>[method:Array toArray]( [page:Array array] )</h3>
+		<div>
+		array -- Optional array to store the vector.
+		</div>
 		<div>
 		Returns an array [x, y].
 		</div>

+ 4 - 1
docs/api/math/Vector3.html

@@ -401,7 +401,10 @@
 		Multiplies this vector and m, and divides by perspective.
 		</div>
 
-		<h3>[method:Array toArray]()</h3>
+		<h3>[method:Array toArray]( [page:Array array] )</h3>
+		<div>
+		array -- Optional array to store the vector.
+		</div>
 		<div>
 		Assigns this vector's x value to array[0]. <br />
 		Assigns this vector's y value to array[1]. <br />

+ 9 - 6
docs/api/math/Vector4.html

@@ -186,7 +186,7 @@
 		v -- [page:Vector4]
 		</div>
 		<div>
-		If this vector's x, y, z, or w value is greater than vector v's x, y, z, or w value, that value is replaced by the corresponding vector v value. 
+		If this vector's x, y, z, or w value is greater than vector v's x, y, z, or w value, that value is replaced by the corresponding vector v value.
 		</div>
 
 		<h3>[method:Vector4 addScalar]([page:Float s]) [page:Vector4 this]</h3>
@@ -204,7 +204,7 @@
 		<div>
 		Checks to see if this vector matches vector v.
 		</div>
-		
+
 		<h3>[method:Vector4 setAxisAngleFromRotationMatrix]([page:Matrix4 m]) [page:Vector4 this]</h3>
 		<div>
 		m -- [page:Matrix4]
@@ -236,7 +236,7 @@
 		Index 1: y<br/>
 		Index 2: z<br/>
 		Index 3: w<br/>
- 
+
 		</div>
 
 		<h3>[method:null setComponent]([page:Integer index], [page:Float value])</h3>
@@ -246,13 +246,13 @@
 		</div>
 		<div>
 		Sets the value of the vector component	x, y, or z by an index.<br/><br/>
-		
+
 		Index 0: x<br/>
 		Index 1: y<br/>
 		Index 2: z<br/>
 		Index 3: w<br/>
 		</div>
-		
+
 		<h3>[method:Vector4 fromArray]([page:Array array]) [page:Vector4 this]</h3>
 		<div>
 		array -- [page:Array] An array formatted [x, y, z, w]
@@ -261,7 +261,10 @@
 		Sets the vector's components based on an array formatted like [x, y, z, w]
 		</div>
 
-		<h3>[method:Array toArray]()</h3>
+		<h3>[method:Array toArray]( [page:Array array] )</h3>
+		<div>
+		array -- Optional array to store the vector.
+		</div>
 		<div>
 		Returns an array in the format [x, y, z, w]
 		</div>

+ 1 - 1
docs/api/renderers/WebGLRenderTarget.html

@@ -69,7 +69,7 @@
 
 		<h3>[property:number type]</h3>
 		<div>
-		The default is THREE.UnsignedByteType. Other valid types (as WebGL allows) are THREE.ByteType, THREE.ShortType, THREE.UnsignedShortType, THREE.IntType, THREE.UnsignedIntType, THREE.FloatType, THREE.UnsignedShort4444Type, THREE.UnsignedShort5551Type, and THREE.UnsignedShort565Type.
+		The default is THREE.UnsignedByteType. Other valid types (as WebGL allows) are THREE.ByteType, THREE.ShortType, THREE.UnsignedShortType, THREE.IntType, THREE.UnsignedIntType, THREE.HalfFloatType, THREE.FloatType, THREE.UnsignedShort4444Type, THREE.UnsignedShort5551Type, and THREE.UnsignedShort565Type.
 		</div>
 		
 		<h3>[property:boolean depthBuffer]</h3>

+ 16 - 4
docs/index.html

@@ -269,11 +269,11 @@
 						var li = document.createElement( 'li' );
 						var a = document.createElement( 'a' );
 						a.setAttribute( 'href', '#' );
-						( function( s, c, p ) { 
+						( function( s, c, p ) {
 							a.addEventListener( 'click', function( e ) {
 								goTo( s, c, p );
 								e.preventDefault();
-							} ) 
+							} )
 						} )( section, category, page[ 0 ] )
 						a.textContent = page[ 0 ];
 						li.appendChild( a );
@@ -370,7 +370,7 @@
 					// Resolve links of the form 'Class.member'
 					if(section.indexOf(MEMBER_DELIMITER) !== -1) {
 						parts = section.split(MEMBER_DELIMITER)
-						section = parts[0]; 
+						section = parts[0];
 						member = parts[1];
 					}
 
@@ -379,7 +379,7 @@
 					section = location.section;
 					category = location.category;
 					name = location.name;
-				} 
+				}
 
 				var title = 'three.js - documentation - ' + section + ' - ' + name;
 				var url = encodeUrl(section) + DELIMITER + encodeUrl( category ) + DELIMITER + encodeUrl(name) + (!!member ? MEMBER_DELIMITER + encodeUrl(member) : '');
@@ -405,6 +405,18 @@
 
 			if ( window.location.hash.length > 0 ) goToHash();
 
+			console.log([
+				'   __     __',
+				' __/ __\\  / __\\__   ____   _____   _____',
+				'/ __/  /\\/ /  /___\\/ ____\\/ _____\\/ _____\\',
+				'\\/_   __/ /   _   / /  __/ / __  / / __  /_   __   _____',
+				'/ /  / / /  / /  / /  / / /  ___/ /  ___/\\ _\\/ __\\/ _____\\',
+				'\\/__/  \\/__/\\/__/\\/__/  \\/_____/\\/_____/\\/__/ /  / /  ___/',
+				'                                         / __/  /  \\__  \\',
+				'                                         \\/____/\\/_____/'
+			].join('\n'));
+
 		</script>
+		<script src="../build/three.min.js"></script>
 	</body>
 </html>

+ 0 - 1
docs/list.js

@@ -63,7 +63,6 @@ var list = {
 			[ "ObjectLoader", "api/loaders/ObjectLoader" ],
 			[ "PDBLoader", "api/loaders/PDBLoader" ],
 			[ "SVGLoader", "api/loaders/SVGLoader" ],
-			[ "SceneLoader", "api/loaders/SceneLoader" ],
 			[ "TextureLoader", "api/loaders/TextureLoader" ],
 			[ "TGALoader", "api/loaders/TGALoader" ],
 			[ "XHRLoader", "api/loaders/XHRLoader" ]

+ 1 - 5
docs/scenes/js/material.js

@@ -393,7 +393,6 @@ function guiMeshLambertMaterial ( gui, mesh, material, geometry ) {
 
 	var data = {
 		color : material.color.getHex(),
-		ambient : material.ambient.getHex(),
 		emissive : material.emissive.getHex(),
 		envMaps : envMapKeys,
 		map : textureMapKeys,
@@ -407,7 +406,6 @@ function guiMeshLambertMaterial ( gui, mesh, material, geometry ) {
 	var folder = gui.addFolder('THREE.MeshLambertMaterial');
 
 	folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
-	folder.addColor( data, 'ambient' ).onChange( handleColorChange( material.ambient ) );
 	folder.addColor( data, 'emissive' ).onChange( handleColorChange( material.emissive ) );
 
 	folder.add( material, 'shading', constants.shading ).onChange( needsUpdate( material, geometry ) );
@@ -433,7 +431,6 @@ function guiMeshPhongMaterial ( gui, mesh, material, geometry ) {
 
 	var data = {
 		color : material.color.getHex(),
-		ambient : material.ambient.getHex(),
 		emissive : material.emissive.getHex(),
 		specular : material.specular.getHex(),
 		envMaps : envMapKeys,
@@ -446,11 +443,10 @@ function guiMeshPhongMaterial ( gui, mesh, material, geometry ) {
 	var folder = gui.addFolder('THREE.MeshPhongMaterial');
 
 	folder.addColor( data, 'color' ).onChange( handleColorChange( material.color ) );
-	folder.addColor( data, 'ambient' ).onChange( handleColorChange( material.ambient ) );
 	folder.addColor( data, 'emissive' ).onChange( handleColorChange( material.emissive ) );
 	folder.addColor( data, 'specular' ).onChange( handleColorChange( material.specular ) );
 
-	folder.add( material, 'shininess', 0, 100);
+	folder.add( material, 'shininess', 1, 100);
 	folder.add( material, 'shading', constants.shading).onChange( needsUpdate( material, geometry ) );
 	folder.add( material, 'wireframe' );
 	folder.add( material, 'wireframeLinewidth', 0, 10 );

+ 7 - 10
editor/css/dark.css

@@ -1,17 +1,21 @@
-.FancySelect {
+.Outliner {
+	color: #868686;
 	background: #222;
 	padding: 0;
+	width: 100%;
+	height: 140px;
+	font-size: 12px;
 	cursor: default;
 	overflow: auto;
 	outline: none;
 }
 
-	.FancySelect .option {
+	.Outliner .option {
 		padding: 4px;
 		white-space: nowrap;
 	}
 
-	.FancySelect .option.active {
+	.Outliner .option.active {
 		background-color: #153C5E;
 	}
 
@@ -159,13 +163,6 @@ input.Number {
 		border-top: 1px solid #333;
 	}
 
-	#sidebar #outliner {
-		width: 100%;
-		height: 140px;
-		color: #868686;
-		font-size: 12px;
-	}
-
 	#sidebar .Panel.Material canvas {
 
 		border: solid 1px #5A5A5A;

+ 7 - 10
editor/css/light.css

@@ -1,18 +1,22 @@
-.FancySelect {
+.Outliner {
+	color: #444;
 	background: #fff;
 	padding: 0;
+	width: 100%;
+	height: 140px;
+	font-size: 12px;
 	cursor: default;
 	overflow: auto;
 	outline: none;
 }
 
-	.FancySelect .option {
+	.Outliner .option {
 		padding: 4px;
 		color: #666;
 		white-space: nowrap;
 	}
 
-	.FancySelect .option.active {
+	.Outliner .option.active {
 		background-color: #f8f8f8;
 	}
 
@@ -152,13 +156,6 @@ input.Number {
 		border-top: 1px solid #ccc;
 	}
 
-	#sidebar #outliner {
-		width: 100%;
-		height: 140px;
-		color: #444;
-		font-size: 12px;
-	}
-
 #toolbar {
 	position: absolute;
 	left: 0px;

+ 16 - 0
editor/css/main.css

@@ -67,6 +67,8 @@ textarea, input { outline: none; } /* osx */
 		display: none;
 	}
 
+/* CodeMirror */
+
 .CodeMirror {
 
 	position: absolute !important;
@@ -76,6 +78,20 @@ textarea, input { outline: none; } /* osx */
 
 }
 
+	.CodeMirror .errorLine {
+
+		background: rgba(255,0,0,0.25);
+
+	}
+
+	.CodeMirror .esprima-error {
+
+		color: #f00;
+		text-align: right;
+		padding: 0px 20px;
+
+	}
+
 /* scene types */
 
 .type {

+ 5 - 4
editor/examples/arkanoid.app.json

@@ -6,7 +6,7 @@
 			"generator": "ObjectExporter"
 		},
 		"object": {
-			"uuid": "A32F9E56-4DDC-442E-8A0D-F23B9E93EEA9",
+			"uuid": "8EFB9C06-6312-4975-B04A-C9E4549BE348",
 			"type": "PerspectiveCamera",
 			"name": "Camera",
 			"fov": 50,
@@ -107,7 +107,7 @@
 					"name": "Ground",
 					"geometry": "8F05A1F2-3877-478B-8DFC-F572AC61AB3A",
 					"material": "2F69AF3A-DDF5-4BBA-87B5-80159F90DDBF",
-					"matrix": [1,0,0,0,0,0.0007962886593304574,-0.9999997019767761,0,0,0.9999997019767761,0.0007962886593304574,0,0,0,0,1]
+					"matrix": [1,0,0,0,0,0.000796250649727881,-0.9999997019767761,0,0,0.9999997019767761,0.000796250649727881,0,0,0,0,1]
 				},
 				{
 					"uuid": "6EE2E764-43E0-48E0-85F2-E0C8823C20DC",
@@ -148,6 +148,7 @@
 					"color": 16777215,
 					"intensity": 1,
 					"distance": 0,
+					"decay": 1,
 					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,-116.54356384277344,69.48957061767578,-206.8248291015625,1]
 				}]
 		}
@@ -161,7 +162,7 @@
 		"31517222-A9A7-4EAF-B5F6-60751C0BABA3": [
 			{
 				"name": "Game Logic",
-				"source": "var ball = this.getObjectByName( 'Ball' );\n\nvar direction = new THREE.Vector3();\ndirection.x = Math.random() - 0.5;\ndirection.z = - 0.5;\ndirection.normalize();\n\nvar speed = new THREE.Vector3();\n\n//\n\nvar group = new THREE.Group();\nthis.add( group );\n\nvar paddle = this.getObjectByName( 'Paddle' );\ngroup.add( paddle );\n\nvar brick = this.getObjectByName( 'Brick' );\n\nfor ( var j = 0; j < 8; j ++ ) {\n\n\tvar material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );\n\n\tfor ( var i = 0; i < 12; i ++ ) {\n\t\t\n\t\tvar object = brick.clone();\n\t\tobject.material = material;\n\t\tobject.position.x = i * 22 - 120;\n\t\tobject.position.z = j * 14 - 120;\n\t\tgroup.add( object );\n\t\t\n\t}\n\t\n}\n\nbrick.visible = false;\n\n//\n\nvar raycaster = new THREE.Raycaster();\n\nfunction update( event ) {\n\t\n\tif ( ball.position.x < - 150 || ball.position.x > 150 ) direction.x = - direction.x;\n\tif ( ball.position.z < - 200 || ball.position.z > 200 ) direction.z = - direction.z;\n\n\tball.position.add( speed.copy( direction ).multiplyScalar( 4 ) );\n\t\n\traycaster.set( ball.position, direction );\n\t\n\tvar intersections = raycaster.intersectObjects( group.children );\n\t\n\tif ( intersections.length > 0 ) {\n\t\n\t\tvar intersection = intersections[ 0 ];\n\t\t\n\t\tif ( intersection.distance < 5 ) {\n\t\t\t\n\t\t\tif ( intersection.object !== paddle ) {\n\n\t\t\t\tgroup.remove( intersection.object );\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tdirection.reflect( intersection.face.normal );\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n}"
+				"source": "var ball = this.getObjectByName( 'Ball' );\n\nvar direction = new THREE.Vector3();\ndirection.x = Math.random() - 0.5;\ndirection.z = - 0.5;\ndirection.normalize();\n\nvar speed = new THREE.Vector3();\n\n//\n\nvar group = new THREE.Group();\nthis.add( group );\n\nvar paddle = this.getObjectByName( 'Paddle' );\ngroup.add( paddle );\n\nvar brick = this.getObjectByName( 'Brick' );\n\nfor ( var j = 0; j < 8; j ++ ) {\n\n\tvar material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );\n\n\tfor ( var i = 0; i < 12; i ++ ) {\n\t\t\n\t\tvar object = brick.clone();\n\t\tobject.material = material;\n\t\tobject.position.x = i * 22 - 120;\n\t\tobject.position.z = j * 14 - 120;\n\t\tgroup.add( object );\n\t\t\n\t}\n\t\n}\n\nbrick.visible = false;\n\n//\n\nvar raycaster = new THREE.Raycaster();\n\nfunction update( event ) {\n\t\n\tif ( ball.position.x < - 150 || ball.position.x > 150 ) direction.x = - direction.x;\n\tif ( ball.position.z < - 200 || ball.position.z > 200 ) direction.z = - direction.z;\n\n\tball.position.x = Math.max( - 150, Math.min( 150, ball.position.x ) );\n\tball.position.z = Math.max( - 200, Math.min( 200, ball.position.z ) );\n\t\n\tball.position.add( speed.copy( direction ).multiplyScalar( event.delta / 4 ) );\n\t\n\traycaster.set( ball.position, direction );\n\t\n\tvar intersections = raycaster.intersectObjects( group.children );\n\t\n\tif ( intersections.length > 0 ) {\n\t\n\t\tvar intersection = intersections[ 0 ];\n\t\t\n\t\tif ( intersection.distance < 5 ) {\n\t\t\t\n\t\t\tif ( intersection.object !== paddle ) {\n\n\t\t\t\tgroup.remove( intersection.object );\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tdirection.reflect( intersection.face.normal );\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n}"
 			}]
 	}
-}
+}

+ 63 - 49
editor/examples/camera.app.json

@@ -6,14 +6,14 @@
 			"generator": "ObjectExporter"
 		},
 		"object": {
-			"uuid": "F0D8434F-4603-415B-8024-792FE97B9600",
+			"uuid": "C7FB195B-270E-47B4-95C9-1754652A9D11",
 			"type": "PerspectiveCamera",
 			"name": "Camera",
 			"fov": 50,
 			"aspect": 1.2252042007001167,
 			"near": 0.1,
 			"far": 100000,
-			"matrix": [0.9700406789779663,-5.500052080442686e-10,-0.24294254183769226,0,-0.04822639003396034,0.9800989627838135,-0.19256223738193512,0,0.23810774087905884,0.19850945472717285,0.950735867023468,0,159.0158233642578,132.5708465576172,634.9312744140625,1]
+			"matrix": [0.9700406789779663,-2.851828329042405e-9,-0.24294254183769226,0,-0.04822639003396034,0.9800989627838135,-0.1925622522830963,0,0.23810774087905884,0.19850945472717285,0.950735867023468,0,154.7735595703125,129.03408813476562,617.992431640625,1]
 		}
 	},
 	"scene": {
@@ -23,6 +23,14 @@
 			"generator": "ObjectExporter"
 		},
 		"geometries": [
+			{
+				"uuid": "51BB3E54-D2DF-4576-9953-FB8E940588B5",
+				"type": "PlaneGeometry",
+				"width": 1000,
+				"height": 1000,
+				"widthSegments": 1,
+				"heightSegments": 1
+			},
 			{
 				"uuid": "D8E200D3-27BC-49F8-A5C5-7384206E70FE",
 				"type": "BoxGeometry",
@@ -43,14 +51,6 @@
 				"heightSegments": 1,
 				"openEnded": false
 			},
-			{
-				"uuid": "51BB3E54-D2DF-4576-9953-FB8E940588B5",
-				"type": "PlaneGeometry",
-				"width": 1000,
-				"height": 1000,
-				"widthSegments": 1,
-				"heightSegments": 1
-			},
 			{
 				"uuid": "4DECFAB5-6FD1-4D84-9A29-565807B074EA",
 				"type": "IcosahedronGeometry",
@@ -59,25 +59,25 @@
 			}],
 		"materials": [
 			{
-				"uuid": "B5943856-E404-45D9-A427-4774202C2CD0",
+				"uuid": "4AE8130E-B6A8-47BC-ACCF-060973C74044",
 				"type": "MeshPhongMaterial",
-				"color": 37119,
+				"color": 16777215,
 				"emissive": 0,
 				"specular": 1118481,
 				"shininess": 30
 			},
 			{
-				"uuid": "3F872310-2067-4BE4-9250-5B3F4E43797E",
+				"uuid": "B5943856-E404-45D9-A427-4774202C2CD0",
 				"type": "MeshPhongMaterial",
-				"color": 15859456,
+				"color": 37119,
 				"emissive": 0,
 				"specular": 1118481,
 				"shininess": 30
 			},
 			{
-				"uuid": "4AE8130E-B6A8-47BC-ACCF-060973C74044",
+				"uuid": "3F872310-2067-4BE4-9250-5B3F4E43797E",
 				"type": "MeshPhongMaterial",
-				"color": 16777215,
+				"color": 15859456,
 				"emissive": 0,
 				"specular": 1118481,
 				"shininess": 30
@@ -97,19 +97,34 @@
 			"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
 			"children": [
 				{
-					"uuid": "60B69C58-4201-43FD-815E-AD2EDFBBD0CE",
-					"type": "PerspectiveCamera",
-					"name": "PerspectiveCamera 1",
-					"fov": 50,
-					"aspect": 1,
-					"near": 100,
-					"far": 10000,
-					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,100,400,1]
+					"uuid": "B7CBBC6F-EC26-49B5-8D0D-67D9C535924B",
+					"type": "Group",
+					"name": "Dummy",
+					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,100,400,1],
+					"children": [
+						{
+							"uuid": "60B69C58-4201-43FD-815E-AD2EDFBBD0CE",
+							"type": "PerspectiveCamera",
+							"name": "PerspectiveCamera",
+							"fov": 50,
+							"aspect": 1,
+							"near": 100,
+							"far": 10000,
+							"matrix": [-1,0,-1.2246468525851679e-16,0,0,1,0,0,1.2246468525851679e-16,0,-1,0,0,0,0,1]
+						}]
+				},
+				{
+					"uuid": "A460C230-DC88-4A8F-A3FB-AA0FE735F3ED",
+					"type": "Mesh",
+					"name": "Plane",
+					"geometry": "51BB3E54-D2DF-4576-9953-FB8E940588B5",
+					"material": "4AE8130E-B6A8-47BC-ACCF-060973C74044",
+					"matrix": [1,0,0,0,0,0.040785226970911026,-0.9991679191589355,0,0,0.9991679191589355,0.040785226970911026,0,0,-50,0,1]
 				},
 				{
 					"uuid": "26DAAD69-725D-43B7-AF9D-990A99DEF8C5",
 					"type": "Mesh",
-					"name": "Box 1",
+					"name": "Box",
 					"geometry": "D8E200D3-27BC-49F8-A5C5-7384206E70FE",
 					"material": "B5943856-E404-45D9-A427-4774202C2CD0",
 					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
@@ -117,27 +132,18 @@
 				{
 					"uuid": "AAAFF2D6-4725-4AFC-A9FE-26419B11011F",
 					"type": "Mesh",
-					"name": "Cylinder 3",
+					"name": "Cylinder",
 					"geometry": "25BA32DB-8B02-4ABA-A77C-69868C464A1A",
 					"material": "3F872310-2067-4BE4-9250-5B3F4E43797E",
 					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,-130,-15,0,1]
 				},
 				{
-					"uuid": "A460C230-DC88-4A8F-A3FB-AA0FE735F3ED",
+					"uuid": "B855E267-A266-4098-ACD6-6A1FDE7B88BA",
 					"type": "Mesh",
-					"name": "Plane 4",
-					"geometry": "51BB3E54-D2DF-4576-9953-FB8E940588B5",
-					"material": "4AE8130E-B6A8-47BC-ACCF-060973C74044",
-					"matrix": [1,0,0,0,0,0.040785059332847595,-0.9991679191589355,0,0,0.9991679191589355,0.040785059332847595,0,0,-50,0,1]
-				},
-				{
-					"uuid": "3412781E-27CC-43C3-A5DB-54C0C8E42ED6",
-					"type": "PointLight",
-					"name": "PointLight 2",
-					"color": 12773063,
-					"intensity": 1,
-					"distance": 0,
-					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,88.12999725341797,8.3100004196167,125.44999694824219,1]
+					"name": "Icosahedron",
+					"geometry": "4DECFAB5-6FD1-4D84-9A29-565807B074EA",
+					"material": "E1826901-7922-4584-A25D-6D487E2C9BBD",
+					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,130,-10,0,1]
 				},
 				{
 					"uuid": "E2939A7B-5E40-438A-8C1B-32126FBC6892",
@@ -146,23 +152,31 @@
 					"color": 9474221,
 					"intensity": 0.75,
 					"distance": 0,
+					"decay": 1,
 					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,-93.86000061035156,127.12999725341797,-114.30000305175781,1]
 				},
 				{
-					"uuid": "B855E267-A266-4098-ACD6-6A1FDE7B88BA",
-					"type": "Mesh",
-					"name": "Icosahedron 1",
-					"geometry": "4DECFAB5-6FD1-4D84-9A29-565807B074EA",
-					"material": "E1826901-7922-4584-A25D-6D487E2C9BBD",
-					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,130,-10,0,1]
+					"uuid": "3412781E-27CC-43C3-A5DB-54C0C8E42ED6",
+					"type": "PointLight",
+					"name": "PointLight 2",
+					"color": 12773063,
+					"intensity": 1,
+					"distance": 0,
+					"decay": 1,
+					"matrix": [1,0,0,0,0,1,0,0,0,0,1,0,88.12999725341797,8.3100004196167,125.44999694824219,1]
 				}]
 		}
 	},
 	"scripts": {
 		"60B69C58-4201-43FD-815E-AD2EDFBBD0CE": [
 			{
-				"name": "Camera Orbit",
-				"source": "player.setCamera( this );\n\nfunction update( event ) {\n\n\tvar time = event.time * 0.001;\n\n\tthis.position.x = Math.sin( time ) * 400;\n\tthis.position.z = Math.cos( time ) * 400;\n\tthis.lookAt( scene.position );\n\n}"
+				"name": "Player Camera",
+				"source": "player.setCamera( this );"
+			}],
+		"B7CBBC6F-EC26-49B5-8D0D-67D9C535924B": [
+			{
+				"name": "Orbit",
+				"source": "function update( event ) {\n\n\tvar time = event.time * 0.001;\n\n\tthis.position.x = Math.sin( time ) * 400;\n\tthis.position.z = Math.cos( time ) * 400;\n\tthis.lookAt( scene.position );\n\n}"
 			}]
 	}
-}
+}

+ 4 - 4
editor/examples/pong.app.json

@@ -6,7 +6,7 @@
 			"generator": "ObjectExporter"
 		},
 		"object": {
-			"uuid": "E5C76691-3D55-4E26-862E-24BADC21F4D7",
+			"uuid": "8EFB9C06-6312-4975-B04A-C9E4549BE348",
 			"type": "PerspectiveCamera",
 			"name": "Camera",
 			"fov": 50,
@@ -88,7 +88,7 @@
 					"name": "Ground",
 					"geometry": "77B20ED1-2871-4B14-A652-8F823B2A817E",
 					"material": "7EDF7C08-6325-418A-BBAB-89341C694730",
-					"matrix": [1,0,0,0,0,0.0007961748051457107,-0.9999997019767761,0,0,0.9999997019767761,0.0007961748051457107,0,0,-10,0,1]
+					"matrix": [1,0,0,0,0,0.0007960614748299122,-0.9999997019767761,0,0,0.9999997019767761,0.0007960614748299122,0,0,-10,0,1]
 				},
 				{
 					"uuid": "CE13E58A-4E8B-4F72-9E2E-7DE57C58F989",
@@ -128,7 +128,7 @@
 		"31517222-A9A7-4EAF-B5F6-60751C0BABA3": [
 			{
 				"name": "Game logic",
-				"source": "var ball = this.getObjectByName( 'Ball' );\n\nvar position = ball.position;\n\nvar velocity = new THREE.Vector3();\n\nvar direction = new THREE.Vector3();\ndirection.x = Math.random() - 0.5;\ndirection.z = Math.random() - 0.5;\ndirection.normalize();\n\nvar pad1 = this.getObjectByName( 'Pad 1' );\nvar pad2 = this.getObjectByName( 'Pad 2' );\n\nvar raycaster = new THREE.Raycaster();\nvar objects = [ pad1, pad2 ];\n\n//\n\nfunction mousemove( event ) {\n\n\tpad1.position.z = ( event.clientX / player.width ) * 300 - 150;\n\tpad2.position.z = - pad1.position.z;\n\n}\n\nfunction update( event ) {\n\n\tif ( position.x < -300 || position.x > 300 ) {\n\t\t\n\t\tdirection.x = - direction.x;\n\t\t\n\t}\n\n\tif ( position.z < -200 || position.z > 200 ) {\n\t\t\n\t\tdirection.z = - direction.z;\n\t\t\n\t}\n\t\n\traycaster.set( position, direction );\n\t\n\tvar intersections = raycaster.intersectObjects( objects );\n\t\n\tif ( intersections.length > 0 ) {\n\n\t\tvar intersection = intersections[ 0 ];\n\t\t\n\t\tif ( intersection.distance < 10 ) {\n\t\t\t\n\t\t\tdirection.reflect( intersection.face.normal );\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n\tposition.add( velocity.copy( direction ).multiplyScalar( 8 ) );\n\n}"
+				"source": "var ball = this.getObjectByName( 'Ball' );\n\nvar position = ball.position;\n\nvar velocity = new THREE.Vector3();\n\nvar direction = new THREE.Vector3();\ndirection.x = Math.random() - 0.5;\ndirection.z = Math.random() - 0.5;\ndirection.normalize();\n\nvar pad1 = this.getObjectByName( 'Pad 1' );\nvar pad2 = this.getObjectByName( 'Pad 2' );\n\nvar raycaster = new THREE.Raycaster();\nvar objects = [ pad1, pad2 ];\n\n//\n\nfunction mousemove( event ) {\n\n\tpad1.position.z = ( event.clientX / player.width ) * 300 - 150;\n\tpad2.position.z = - pad1.position.z;\n\n}\n\nfunction update( event ) {\n\t\n\tif ( position.x < -300 || position.x > 300 ) direction.x = - direction.x;\n\tif ( position.z < -200 || position.z > 200 ) direction.z = - direction.z;\n\t\n\tposition.x = Math.max( - 300, Math.min( 300, position.x ) );\n\tposition.z = Math.max( - 200, Math.min( 200, position.z ) );\n\t\n\traycaster.set( position, direction );\n\t\n\tvar intersections = raycaster.intersectObjects( objects );\n\t\n\tif ( intersections.length > 0 ) {\n\n\t\tvar intersection = intersections[ 0 ];\n\t\t\n\t\tif ( intersection.distance < 10 ) {\n\t\t\t\n\t\t\tdirection.reflect( intersection.face.normal );\n\t\t\t\n\t\t}\n\t\t\n\t}\n\n\tposition.add( velocity.copy( direction ).multiplyScalar( event.delta / 2 ) );\n\n}"
 			}]
 	}
-}
+}

+ 13 - 2
editor/index.html

@@ -19,7 +19,6 @@
 		<script src="../examples/js/loaders/ColladaLoader.js"></script>
 		<script src="../examples/js/loaders/OBJLoader.js"></script>
 		<script src="../examples/js/loaders/PLYLoader.js"></script>
-		<script src="../examples/js/loaders/SceneLoader.js"></script>
 		<script src="../examples/js/loaders/STLLoader.js"></script>
 		<script src="../examples/js/loaders/UTF8Loader.js"></script>
 		<script src="../examples/js/loaders/VRMLLoader.js"></script>
@@ -30,6 +29,8 @@
 		<script src="../examples/js/exporters/OBJExporter.js"></script>
 		<script src="../examples/js/exporters/STLExporter.js"></script>
 
+		<script src="../examples/js/loaders/deprecated/SceneLoader.js"></script>
+
 		<script src="../examples/js/renderers/Projector.js"></script>
 		<script src="../examples/js/renderers/CanvasRenderer.js"></script>
 		<script src="../examples/js/renderers/RaytracingRenderer.js"></script>
@@ -40,8 +41,10 @@
 		<link rel="stylesheet" href="js/libs/codemirror/theme/monokai.css">
 		<script src="js/libs/codemirror/codemirror.js"></script>
 		<script src="js/libs/codemirror/mode/javascript.js"></script>
+		<script src="js/libs/esprima.js"></script>
 
 		<script src="js/libs/jszip.min.js"></script>
+		<script src="js/libs/sortable.min.js"></script>
 		<script src="js/libs/signals.min.js"></script>
 		<script src="js/libs/ui.js"></script>
 		<script src="js/libs/ui.three.js"></script>
@@ -50,6 +53,9 @@
 		<script src="js/Player.js"></script>
 		<script src="js/Script.js"></script>
 
+		<script src="../examples/js/effects/VREffect.js"></script>
+		<script src="../examples/js/controls/VRControls.js"></script>
+
 		<script src="js/Storage.js"></script>
 
 		<script src="js/Editor.js"></script>
@@ -213,7 +219,12 @@
 			document.addEventListener( 'drop', function ( event ) {
 
 				event.preventDefault();
-				editor.loader.loadFile( event.dataTransfer.files[ 0 ] );
+
+				if ( event.dataTransfer.files.length > 0 ) {
+
+					editor.loader.loadFile( event.dataTransfer.files[ 0 ] );
+
+				}
 
 			}, false );
 

+ 28 - 17
editor/js/Editor.js

@@ -155,7 +155,31 @@ Editor.prototype = {
 
 	},
 
-	setObjectName: function ( object, name ) {
+	moveObject: function ( object, parent, before ) {
+
+		if ( parent === undefined ) {
+
+			parent = this.scene;
+
+		}
+
+		parent.add( object );
+
+		// sort children array
+
+		if ( before !== undefined ) {
+
+			var index = parent.children.indexOf( before );
+			parent.children.splice( index, 0, object );
+			parent.children.pop();
+
+		}
+
+		this.signals.sceneGraphChanged.dispatch();
+
+	},
+
+	nameObject: function ( object, name ) {
 
 		object.name = name;
 		this.signals.sceneGraphChanged.dispatch();
@@ -319,22 +343,6 @@ Editor.prototype = {
 
 	//
 
-	parent: function ( object, parent ) {
-
-		if ( parent === undefined ) {
-
-			parent = this.scene;
-
-		}
-
-		parent.add( object );
-
-		this.signals.sceneGraphChanged.dispatch();
-
-	},
-
-	//
-
 	select: function ( object ) {
 
 		if ( this.selected === object ) return;
@@ -462,6 +470,9 @@ Editor.prototype = {
 
 		return {
 
+			project: {
+				vr: this.config.getKey( 'project/vr' )
+			},
 			camera: this.camera.toJSON(),
 			scene: this.scene.toJSON(),
 			scripts: this.scripts

+ 0 - 32
editor/js/Menubar.Edit.js

@@ -53,38 +53,6 @@ Menubar.Edit = function ( editor ) {
 	} );
 	options.add( option );
 
-	//
-
-	options.add( new UI.HorizontalRule() );
-
-	// Flatten
-
-	var option = new UI.Panel();
-	option.setClass( 'option' );
-	option.setTextContent( 'Flatten' );
-	option.onClick( function () {
-
-		var object = editor.selected;
-
-		if ( object.parent === undefined ) return; // avoid flattening the camera or scene
-
-		if ( confirm( 'Flatten ' + object.name + '?' ) === false ) return;
-
-		var geometry = object.geometry;
-
-		geometry.applyMatrix( object.matrix );
-		geometry.verticesNeedUpdate = true;
-		geometry.normalsNeedUpdate = true;
-
-		object.position.set( 0, 0, 0 );
-		object.rotation.set( 0, 0, 0 );
-		object.scale.set( 1, 1, 1 );
-
-		editor.signals.objectChanged.dispatch( object );
-
-	} );
-	options.add( option );
-
 	return container;
 
 };

+ 15 - 8
editor/js/Menubar.File.js

@@ -89,7 +89,7 @@ Menubar.File = function ( editor ) {
 		output = JSON.stringify( output, null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 
-		exportString( output );
+		exportString( output, 'geometry.json' );
 
 	} );
 	options.add( option );
@@ -114,7 +114,7 @@ Menubar.File = function ( editor ) {
 		output = JSON.stringify( output, null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 
-		exportString( output );
+		exportString( output, 'model.json' );
 
 	} );
 	options.add( option );
@@ -130,7 +130,7 @@ Menubar.File = function ( editor ) {
 		output = JSON.stringify( output, null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 
-		exportString( output );
+		exportString( output, 'scene.json' );
 
 	} );
 	options.add( option );
@@ -153,7 +153,7 @@ Menubar.File = function ( editor ) {
 
 		var exporter = new THREE.OBJExporter();
 
-		exportString( exporter.parse( object ) );
+		exportString( exporter.parse( object ), 'model.obj' );
 
 	} );
 	options.add( option );
@@ -167,7 +167,7 @@ Menubar.File = function ( editor ) {
 
 		var exporter = new THREE.STLExporter();
 
-		exportString( exporter.parse( editor.scene ) );
+		exportString( exporter.parse( editor.scene ), 'model.stl' );
 
 	} );
 	options.add( option );
@@ -217,6 +217,10 @@ Menubar.File = function ( editor ) {
 			'',
 			'				document.body.appendChild( player.dom );',
 			'',
+			'				window.addEventListener( \'resize\', function () {',
+			'					player.setSize( window.innerWidth, window.innerHeight );',
+			'				} );',
+			'',
 			'			} );',
 			'',
 			'		</script>',
@@ -274,13 +278,16 @@ Menubar.File = function ( editor ) {
 
 	//
 
-	var exportString = function ( output ) {
+	var exportString = function ( output, filename ) {
 
 		var blob = new Blob( [ output ], { type: 'text/plain' } );
 		var objectURL = URL.createObjectURL( blob );
 
-		window.open( objectURL, '_blank' );
-		window.focus();
+		var link = document.createElement( 'a' );
+		link.href = objectURL;
+		link.download = filename || 'data.json';
+		link.target = '_blank';
+		link.click();
 
 	};
 

+ 2 - 2
editor/js/Player.js

@@ -19,7 +19,7 @@ var Player = function ( editor ) {
 
 		if ( player.dom === undefined ) return;
 
-		player.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
+		player.setSize( container.dom.clientWidth, container.dom.clientHeight );
 
 	} );
 
@@ -28,7 +28,7 @@ var Player = function ( editor ) {
 		container.setDisplay( '' );
 
 		player.load( editor.toJSON() );
-		player.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
+		player.setSize( container.dom.clientWidth, container.dom.clientHeight );
 		player.play();
 
 		container.dom.appendChild( player.dom );

+ 87 - 4
editor/js/Script.js

@@ -15,7 +15,7 @@ var Script = function ( editor ) {
 	var header = new UI.Panel();
 	header.setPadding( '10px' );
 	container.add( header );
-	
+
 	var title = new UI.Text().setColor( '#fff' );
 	header.add( title );
 
@@ -59,16 +59,99 @@ var Script = function ( editor ) {
 		clearTimeout( delay );
 		delay = setTimeout( function () {
 
-			currentScript.source = codemirror.getValue();
+			var value = codemirror.getValue();
+
+			if ( validate( value ) ) {
+
+				currentScript.source = value;
+				signals.scriptChanged.dispatch( currentScript );
 
-			signals.scriptChanged.dispatch( currentScript );
+			}
 
 		}, 300 );
 
 	});
 
+	// validate
+
+	var errorLines = [];
+	var widgets = [];
+
+	var validate = function ( string ) {
+
+		var syntax, errors;
+
+		return codemirror.operation( function () {
+
+			while ( errorLines.length > 0 ) {
+
+				codemirror.removeLineClass( errorLines.shift(), 'background', 'errorLine' );
+
+			}
+
+			while ( widgets.length > 0 ) {
+
+				codemirror.removeLineWidget( widgets.shift() );
+
+			}
+
+			//
+
+			try {
+
+				syntax = esprima.parse( string, { tolerant: true } );
+				errors = syntax.errors;
+
+				for ( var i = 0; i < errors.length; i ++ ) {
+
+					var error = errors[ i ];
+
+					var message = document.createElement( 'div' );
+					message.className = 'esprima-error';
+					message.textContent = error.message.replace(/Line [0-9]+: /, '');
+
+					var lineNumber = error.lineNumber - 1;
+					errorLines.push( lineNumber );
+
+					codemirror.addLineClass( lineNumber, 'background', 'errorLine' );
+
+					var widget = codemirror.addLineWidget(
+						lineNumber,
+						message
+					);
+
+					widgets.push( widget );
+
+				}
+
+			} catch ( error ) {
+
+				var message = document.createElement( 'div' );
+				message.className = 'esprima-error';
+				message.textContent = error.message.replace(/Line [0-9]+: /, '');
+
+				var lineNumber = error.lineNumber - 1;
+				errorLines.push( lineNumber );
+
+				codemirror.addLineClass( lineNumber, 'background', 'errorLine' );
+
+				var widget = codemirror.addLineWidget(
+					lineNumber,
+					message
+				);
+
+				widgets.push( widget );
+
+			}
+
+			return errorLines.length === 0;
+
+		});
+
+	};
+
 	//
-	
+
 	signals.editorCleared.add( function () {
 
 		container.setDisplay( 'none' );

+ 60 - 0
editor/js/Sidebar.Geometry.js

@@ -17,6 +17,66 @@ Sidebar.Geometry = function ( editor ) {
 
 	var geometryType = new UI.Text().setTextTransform( 'uppercase' );
 	container.addStatic( geometryType );
+
+	// Actions
+
+	var objectActions = new UI.Select().setPosition('absolute').setRight( '8px' ).setFontSize( '11px' );
+	objectActions.setOptions( {
+
+		'Actions': 'Actions',
+		'Center': 'Center',
+		'Flatten': 'Flatten'
+
+	} );
+	objectActions.onClick( function ( event ) {
+
+		event.stopPropagation(); // Avoid panel collapsing
+
+	} );
+	objectActions.onChange( function ( event ) {
+
+		var action = this.getValue();
+
+		var object = editor.selected;
+		var geometry = object.geometry;
+
+		if ( confirm( action + ' ' + object.name + '?' ) === false ) return;
+
+		switch ( action ) {
+
+			case 'Center':
+
+				var offset = geometry.center();
+
+				object.position.sub( offset );
+
+				editor.signals.geometryChanged.dispatch( geometry );
+				editor.signals.objectChanged.dispatch( object );
+
+				break;
+
+			case 'Flatten':
+
+				geometry.applyMatrix( object.matrix );
+
+				object.position.set( 0, 0, 0 );
+				object.rotation.set( 0, 0, 0 );
+				object.scale.set( 1, 1, 1 );
+
+				editor.signals.geometryChanged.dispatch( geometry );
+				editor.signals.objectChanged.dispatch( object );
+
+				break;
+
+		}
+
+		this.setValue( 'Actions' );
+
+		signals.objectChanged.dispatch( object );
+
+	} );
+	container.addStatic( objectActions );
+
 	container.add( new UI.Break() );
 
 	// uuid

+ 20 - 8
editor/js/Sidebar.Material.js

@@ -369,7 +369,7 @@ Sidebar.Material = function ( editor ) {
 
 		var geometry = object.geometry;
 		var material = object.material;
-		
+
 		var textureWarning = false;
 		var objectHasUvs = false;
 
@@ -436,8 +436,20 @@ Sidebar.Material = function ( editor ) {
 
 			if ( material.vertexColors !== undefined ) {
 
-				material.vertexColors = parseInt( materialVertexColors.getValue() );
-				material.needsUpdate = true;
+				var vertexColors = parseInt( materialVertexColors.getValue() );
+
+				if ( material.vertexColors !== vertexColors ) {
+
+					if ( geometry instanceof THREE.Geometry ) {
+
+						geometry.groupsNeedUpdate = true;
+
+					}
+
+					material.vertexColors = vertexColors;
+					material.needsUpdate = true;
+
+				}
 
 			}
 
@@ -451,7 +463,7 @@ Sidebar.Material = function ( editor ) {
 
 				var mapEnabled = materialMapEnabled.getValue() === true;
 
-				if ( objectHasUvs )  {
+				if ( objectHasUvs ) {
 
 					material.map = mapEnabled ? materialMap.getValue() : null;
 					material.needsUpdate = true;
@@ -468,7 +480,7 @@ Sidebar.Material = function ( editor ) {
 
 				var mapEnabled = materialAlphaMapEnabled.getValue() === true;
 
-				if ( objectHasUvs )  {
+				if ( objectHasUvs ) {
 
 					material.alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
 					material.needsUpdate = true;
@@ -504,7 +516,7 @@ Sidebar.Material = function ( editor ) {
 
 				var bumpMapEnabled = materialBumpMapEnabled.getValue() === true;
 
-				if ( objectHasUvs )  {
+				if ( objectHasUvs ) {
 
 					material.bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
 					material.bumpScale = materialBumpScale.getValue();
@@ -522,7 +534,7 @@ Sidebar.Material = function ( editor ) {
 
 				var normalMapEnabled = materialNormalMapEnabled.getValue() === true;
 
-				if ( objectHasUvs )  {
+				if ( objectHasUvs ) {
 
 					material.normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
 					material.needsUpdate = true;
@@ -539,7 +551,7 @@ Sidebar.Material = function ( editor ) {
 
 				var specularMapEnabled = materialSpecularMapEnabled.getValue() === true;
 
-				if ( objectHasUvs )  {
+				if ( objectHasUvs ) {
 
 					material.specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
 					material.needsUpdate = true;

+ 34 - 6
editor/js/Sidebar.Object3D.js

@@ -18,6 +18,8 @@ Sidebar.Object3D = function ( editor ) {
 	var objectType = new UI.Text().setTextTransform( 'uppercase' );
 	container.addStatic( objectType );
 
+	// Actions
+
 	var objectActions = new UI.Select().setPosition('absolute').setRight( '8px' ).setFontSize( '11px' );
 	objectActions.setOptions( {
 
@@ -29,7 +31,10 @@ Sidebar.Object3D = function ( editor ) {
 	} );
 	objectActions.onClick( function ( event ) {
 
-		event.stopPropagation();
+		event.stopPropagation(); // Avoid panel collapsing
+
+	} );
+	objectActions.onChange( function ( event ) {
 
 		var object = editor.selected;
 
@@ -48,14 +53,14 @@ Sidebar.Object3D = function ( editor ) {
 				break;
 
 		}
-		
+
 		this.setValue( 'Actions' );
 
 		signals.objectChanged.dispatch( object );
 
 	} );
 	container.addStatic( objectActions );
-	
+
 	container.add( new UI.Break() );
 
 	// uuid
@@ -81,7 +86,7 @@ Sidebar.Object3D = function ( editor ) {
 	var objectNameRow = new UI.Panel();
 	var objectName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
 
-			editor.setObjectName( editor.selected, objectName.getValue() );
+		editor.nameObject( editor.selected, objectName.getValue() );
 
 	} );
 
@@ -228,6 +233,16 @@ Sidebar.Object3D = function ( editor ) {
 
 	container.add( objectExponentRow );
 
+	// decay
+
+	var objectDecayRow = new UI.Panel();
+	var objectDecay = new UI.Number().setRange( 0, Infinity ).onChange( update );
+
+	objectDecayRow.add( new UI.Text( 'Decay' ).setWidth( '90px' ) );
+	objectDecayRow.add( objectDecay );
+
+	container.add( objectDecayRow );
+
 	// visible
 
 	var objectVisibleRow = new UI.Panel();
@@ -333,7 +348,7 @@ Sidebar.Object3D = function ( editor ) {
 
 				if ( object.parent.id !== newParentId && object.id !== newParentId ) {
 
-					editor.parent( object, editor.scene.getObjectById( newParentId, true ) );
+					editor.moveObject( object, editor.scene.getObjectById( newParentId ) );
 
 				}
 
@@ -406,6 +421,12 @@ Sidebar.Object3D = function ( editor ) {
 
 			}
 
+			if ( object.decay !== undefined ) {
+
+				object.decay = objectDecay.getValue();
+
+			}
+
 			object.visible = objectVisible.getValue();
 
 			try {
@@ -436,7 +457,8 @@ Sidebar.Object3D = function ( editor ) {
 			'groundColor': objectGroundColorRow,
 			'distance' : objectDistanceRow,
 			'angle' : objectAngleRow,
-			'exponent' : objectExponentRow
+			'exponent' : objectExponentRow,
+			'decay' : objectDecayRow
 		};
 
 		for ( var property in properties ) {
@@ -585,6 +607,12 @@ Sidebar.Object3D = function ( editor ) {
 
 		}
 
+		if ( object.decay !== undefined ) {
+
+			objectDecay.setValue( object.decay );
+
+		}
+
 		objectVisible.setValue( object.visible );
 
 		try {

+ 2 - 2
editor/js/Sidebar.Scene.js

@@ -19,7 +19,7 @@ Sidebar.Scene = function ( editor ) {
 
 	var ignoreObjectSelectedSignal = false;
 
-	var outliner = new UI.FancySelect().setId( 'outliner' );
+	var outliner = new UI.Outliner( editor );
 	outliner.onChange( function () {
 
 		ignoreObjectSelectedSignal = true;
@@ -134,7 +134,7 @@ Sidebar.Scene = function ( editor ) {
 		var options = [];
 
 		// options.push( { value: camera.id, html: '<span class="type ' + camera.type + '"></span> ' + camera.name } );
-		options.push( { value: scene.id, html: '<span class="type ' + scene.type + '"></span> ' + scene.name } );
+		options.push( { static: true, value: scene.id, html: '<span class="type ' + scene.type + '"></span> ' + scene.name } );
 
 		( function addObjects( objects, pad ) {
 

+ 1 - 1
editor/js/Sidebar.Script.js

@@ -84,7 +84,7 @@ Sidebar.Script = function ( editor ) {
 
 					} );
 					scriptsContainer.add( remove );
-					
+
 					scriptsContainer.add( new UI.Break() );
 
 				} )( object, scripts[ i ] )

+ 1 - 1
editor/js/Storage.js

@@ -8,7 +8,7 @@ var Storage = function () {
 
 	if ( indexedDB === undefined  ) {
 		console.warn( 'Storage: IndexedDB not available.' );
-		return { init: function (){}, get: function (){}, set: function (){}, clear: function (){} };
+		return { init: function () {}, get: function () {}, set: function () {}, clear: function () {} };
 	}
 
 	var name = 'threejs-editor';

+ 0 - 2
editor/js/Toolbar.js

@@ -62,8 +62,6 @@ var Toolbar = function ( editor ) {
 
 	}
 
-	update();
-
 	return container;
 
 }

+ 0 - 6
editor/js/Viewport.js

@@ -370,12 +370,6 @@ var Viewport = function ( editor ) {
 
 		transformControls.update();
 
-		if ( object.geometry !== undefined ) {
-
-			selectionBox.update( object );
-
-		}
-
 		if ( object instanceof THREE.PerspectiveCamera ) {
 
 			object.updateProjectionMatrix();

+ 62 - 7
editor/js/libs/app.js

@@ -6,9 +6,13 @@ var APP = {
 
 	Player: function () {
 
+		var scope = this;
+
 		var loader = new THREE.ObjectLoader();
 		var camera, scene, renderer;
 
+		var vr, controls;
+
 		var events = {};
 
 		this.dom = undefined;
@@ -18,12 +22,15 @@ var APP = {
 
 		this.load = function ( json ) {
 
+			vr = json.project.vr;
+
 			renderer = new THREE.WebGLRenderer( { antialias: true } );
 			renderer.setClearColor( 0x000000 );
 			renderer.setPixelRatio( window.devicePixelRatio );
+			this.dom = renderer.domElement;
 
-			camera = loader.parse( json.camera );
-			scene = loader.parse( json.scene );
+			this.setScene( loader.parse( json.scene ) );
+			this.setCamera( loader.parse( json.camera ) );
 
 			events = {
 				keydown: [],
@@ -47,7 +54,7 @@ var APP = {
 
 					var script = scripts[ i ];
 
-					var functions = ( new Function( 'player', 'scene', 'keydown', 'keyup', 'mousedown', 'mouseup', 'mousemove', 'touchstart', 'touchend', 'touchmove', 'update', script.source + '\nreturn { keydown: keydown, keyup: keyup, mousedown: mousedown, mouseup: mouseup, mousemove: mousemove, touchstart: touchstart, touchend: touchend, touchmove: touchmove, update: update };' ).bind( object ) )( this, scene );
+					var functions = ( new Function( 'player, scene, keydown, keyup, mousedown, mouseup, mousemove, touchstart, touchend, touchmove, update', script.source + '\nreturn { keydown: keydown, keyup: keyup, mousedown: mousedown, mouseup: mouseup, mousemove: mousemove, touchstart: touchstart, touchend: touchend, touchmove: touchmove, update: update };' ).bind( object ) )( this, scene );
 
 					for ( var name in functions ) {
 
@@ -68,8 +75,6 @@ var APP = {
 
 			}
 
-			this.dom = renderer.domElement;
-
 		};
 
 		this.setCamera = function ( value ) {
@@ -78,10 +83,55 @@ var APP = {
 			camera.aspect = this.width / this.height;
 			camera.updateProjectionMatrix();
 
+
+			if ( vr === true ) {
+
+				if ( camera.parent === undefined ) {
+
+					// camera needs to be in the scene so camera2 matrix updates
+					
+					scene.add( camera );
+
+				}
+
+				var camera2 = camera.clone();
+				camera.add( camera2 );
+
+				camera = camera2;
+
+				controls = new THREE.VRControls( camera );
+				renderer = new THREE.VREffect( renderer );
+
+				document.addEventListener( 'keyup', function ( event ) {
+
+					switch ( event.keyCode ) {
+						case 90:
+							controls.zeroSensor();
+							break;
+					}
+
+				} );
+
+				this.dom.addEventListener( 'dblclick', function () {
+
+					renderer.setFullScreen( true );
+
+				} );
+
+			}
+
 		};
 
+		this.setScene = function ( value ) {
+
+			scene = value;
+
+		},
+
 		this.setSize = function ( width, height ) {
 
+			if ( renderer._fullScreen ) return;
+
 			this.width = width;
 			this.height = height;
 
@@ -102,16 +152,20 @@ var APP = {
 
 		};
 
-		var request;
+		var prevTime, request;
 
 		var animate = function ( time ) {
 
 			request = requestAnimationFrame( animate );
 
-			dispatch( events.update, { time: time } );
+			dispatch( events.update, { time: time, delta: time - prevTime } );
+
+			if ( vr ) controls.update();
 
 			renderer.render( scene, camera );
 
+			prevTime = time;
+
 		};
 
 		this.play = function () {
@@ -126,6 +180,7 @@ var APP = {
 			document.addEventListener( 'touchmove', onDocumentTouchMove );
 
 			request = requestAnimationFrame( animate );
+			prevTime = performance.now();
 
 		};
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 197 - 0
editor/js/libs/esprima.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 0
editor/js/libs/sortable.min.js


+ 15 - 168
editor/js/libs/ui.js

@@ -15,7 +15,7 @@ UI.Element.prototype = {
 	setId: function ( id ) {
 
 		this.dom.id = id;
-		
+
 		return this;
 
 	},
@@ -137,7 +137,7 @@ UI.Panel.prototype.add = function () {
 UI.Panel.prototype.remove = function () {
 
 	for ( var i = 0; i < arguments.length; i ++ ) {
-	
+
 		var argument = arguments[ i ];
 
 		if ( argument instanceof UI.Element ) {
@@ -503,159 +503,6 @@ UI.Select.prototype.setValue = function ( value ) {
 
 };
 
-// FancySelect
-
-UI.FancySelect = function () {
-
-	UI.Element.call( this );
-
-	var scope = this;
-
-	var dom = document.createElement( 'div' );
-	dom.className = 'FancySelect';
-	dom.tabIndex = 0;	// keyup event is ignored without setting tabIndex
-
-	// Broadcast for object selection after arrow navigation
-	var changeEvent = document.createEvent('HTMLEvents');
-	changeEvent.initEvent( 'change', true, true );
-
-	// Prevent native scroll behavior
-	dom.addEventListener( 'keydown', function (event) {
-
-		switch ( event.keyCode ) {
-			case 38: // up
-			case 40: // down
-				event.preventDefault();
-				event.stopPropagation();
-				break;
-		}
-
-	}, false);
-
-	// Keybindings to support arrow navigation
-	dom.addEventListener( 'keyup', function (event) {
-
-		switch ( event.keyCode ) {
-			case 38: // up
-			case 40: // down
-				scope.selectedIndex += ( event.keyCode == 38 ) ? -1 : 1;
-
-				if ( scope.selectedIndex >= 0 && scope.selectedIndex < scope.options.length ) {
-
-					// Highlight selected dom elem and scroll parent if needed
-					scope.setValue( scope.options[ scope.selectedIndex ].value );
-
-					scope.dom.dispatchEvent( changeEvent );
-
-				}
-
-				break;
-		}
-
-	}, false);
-
-	this.dom = dom;
-
-	this.options = [];
-	this.selectedIndex = -1;
-	this.selectedValue = null;
-
-	return this;
-
-};
-
-UI.FancySelect.prototype = Object.create( UI.Element.prototype );
-UI.FancySelect.prototype.constructor = UI.FancySelect;
-
-UI.FancySelect.prototype.setOptions = function ( options ) {
-
-	var scope = this;
-
-	var changeEvent = document.createEvent( 'HTMLEvents' );
-	changeEvent.initEvent( 'change', true, true );
-
-	while ( scope.dom.children.length > 0 ) {
-
-		scope.dom.removeChild( scope.dom.firstChild );
-
-	}
-
-	scope.options = [];
-
-	for ( var i = 0; i < options.length; i ++ ) {
-
-		var option = options[ i ];
-
-		var div = document.createElement( 'div' );
-		div.className = 'option';
-		div.innerHTML = option.html;
-		div.value = option.value;
-		scope.dom.appendChild( div );
-
-		scope.options.push( div );
-
-		div.addEventListener( 'click', function ( event ) {
-
-			scope.setValue( this.value );
-			scope.dom.dispatchEvent( changeEvent );
-
-		}, false );
-
-	}
-
-	return scope;
-
-};
-
-UI.FancySelect.prototype.getValue = function () {
-
-	return this.selectedValue;
-
-};
-
-UI.FancySelect.prototype.setValue = function ( value ) {
-
-	for ( var i = 0; i < this.options.length; i ++ ) {
-
-		var element = this.options[ i ];
-
-		if ( element.value === value ) {
-
-			element.classList.add( 'active' );
-
-			// scroll into view
-
-			var y = element.offsetTop - this.dom.offsetTop;
-			var bottomY = y + element.offsetHeight;
-			var minScroll = bottomY - this.dom.offsetHeight;
-
-			if ( this.dom.scrollTop > y ) {
-
-				this.dom.scrollTop = y
-
-			} else if ( this.dom.scrollTop < minScroll ) {
-
-				this.dom.scrollTop = minScroll;
-
-			}
-
-			this.selectedIndex = i;
-
-		} else {
-
-			element.classList.remove( 'active' );
-
-		}
-
-	}
-
-	this.selectedValue = value;
-
-	return this;
-
-};
-
-
 // Checkbox
 
 UI.Checkbox = function ( boolean ) {
@@ -793,8 +640,8 @@ UI.Number = function ( number ) {
 	var distance = 0;
 	var onMouseDownValue = 0;
 
-	var pointer = new THREE.Vector2();
-	var prevPointer = new THREE.Vector2();
+	var pointer = [ 0, 0 ];
+	var prevPointer = [ 0, 0 ];
 
 	var onMouseDown = function ( event ) {
 
@@ -804,7 +651,7 @@ UI.Number = function ( number ) {
 
 		onMouseDownValue = parseFloat( dom.value );
 
-		prevPointer.set( event.clientX, event.clientY );
+		prevPointer = [ event.clientX, event.clientY ];
 
 		document.addEventListener( 'mousemove', onMouseMove, false );
 		document.addEventListener( 'mouseup', onMouseUp, false );
@@ -815,9 +662,9 @@ UI.Number = function ( number ) {
 
 		var currentValue = dom.value;
 
-		pointer.set( event.clientX, event.clientY );
+		pointer = [ event.clientX, event.clientY ];
 
-		distance += ( pointer.x - prevPointer.x ) - ( pointer.y - prevPointer.y );
+		distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
 
 		var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
 
@@ -825,7 +672,7 @@ UI.Number = function ( number ) {
 
 		if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
 
-		prevPointer.set( event.clientX, event.clientY );
+		prevPointer = [ event.clientX, event.clientY ];
 
 	};
 
@@ -957,8 +804,8 @@ UI.Integer = function ( number ) {
 	var distance = 0;
 	var onMouseDownValue = 0;
 
-	var pointer = new THREE.Vector2();
-	var prevPointer = new THREE.Vector2();
+	var pointer = [ 0, 0 ];
+	var prevPointer = [ 0, 0 ];
 
 	var onMouseDown = function ( event ) {
 
@@ -968,7 +815,7 @@ UI.Integer = function ( number ) {
 
 		onMouseDownValue = parseFloat( dom.value );
 
-		prevPointer.set( event.clientX, event.clientY );
+		prevPointer = [ event.clientX, event.clientY ];
 
 		document.addEventListener( 'mousemove', onMouseMove, false );
 		document.addEventListener( 'mouseup', onMouseUp, false );
@@ -979,9 +826,9 @@ UI.Integer = function ( number ) {
 
 		var currentValue = dom.value;
 
-		pointer.set( event.clientX, event.clientY );
+		pointer = [ event.clientX, event.clientY ];
 
-		distance += ( pointer.x - prevPointer.x ) - ( pointer.y - prevPointer.y );
+		distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
 
 		var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
 
@@ -989,7 +836,7 @@ UI.Integer = function ( number ) {
 
 		if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
 
-		prevPointer.set( event.clientX, event.clientY );
+		prevPointer = [ event.clientX, event.clientY ];
 
 	};
 
@@ -1154,7 +1001,7 @@ UI.Button.prototype.setLabel = function ( value ) {
 UI.Dialog = function ( value ) {
 
 	var scope = this;
-	
+
 	var dom = document.createElement( 'dialog' );
 
 	if ( dom.showModal === undefined ) {

+ 176 - 0
editor/js/libs/ui.three.js

@@ -133,3 +133,179 @@ UI.Texture.prototype.onChange = function ( callback ) {
 	return this;
 
 };
+
+// Outliner
+
+UI.Outliner = function ( editor ) {
+
+	UI.Element.call( this );
+
+	var scope = this;
+
+	var dom = document.createElement( 'div' );
+	dom.className = 'Outliner';
+	dom.tabIndex = 0;	// keyup event is ignored without setting tabIndex
+
+	var scene = editor.scene;
+
+	var sortable = Sortable.create( dom, {
+		draggable: '.draggable',
+		onUpdate: function ( event ) {
+
+			var item = event.item;
+
+			var object = scene.getObjectById( item.value );
+
+			if ( item.nextSibling === null ) {
+
+				editor.moveObject( object, editor.scene );
+
+			} else {
+
+				var nextObject = scene.getObjectById( item.nextSibling.value );
+				editor.moveObject( object, nextObject.parent, nextObject );
+
+			}
+
+		}
+	} );
+
+	// Broadcast for object selection after arrow navigation
+	var changeEvent = document.createEvent('HTMLEvents');
+	changeEvent.initEvent( 'change', true, true );
+
+	// Prevent native scroll behavior
+	dom.addEventListener( 'keydown', function (event) {
+
+		switch ( event.keyCode ) {
+			case 38: // up
+			case 40: // down
+			event.preventDefault();
+			event.stopPropagation();
+			break;
+		}
+
+	}, false);
+
+	// Keybindings to support arrow navigation
+	dom.addEventListener( 'keyup', function (event) {
+
+		switch ( event.keyCode ) {
+			case 38: // up
+			case 40: // down
+			scope.selectedIndex += ( event.keyCode == 38 ) ? -1 : 1;
+
+			if ( scope.selectedIndex >= 0 && scope.selectedIndex < scope.options.length ) {
+
+				// Highlight selected dom elem and scroll parent if needed
+				scope.setValue( scope.options[ scope.selectedIndex ].value );
+
+				scope.dom.dispatchEvent( changeEvent );
+
+			}
+
+			break;
+		}
+
+	}, false);
+
+	this.dom = dom;
+
+	this.options = [];
+	this.selectedIndex = -1;
+	this.selectedValue = null;
+
+	return this;
+
+};
+
+UI.Outliner.prototype = Object.create( UI.Element.prototype );
+UI.Outliner.prototype.constructor = UI.Outliner;
+
+UI.Outliner.prototype.setOptions = function ( options ) {
+
+	var scope = this;
+
+	var changeEvent = document.createEvent( 'HTMLEvents' );
+	changeEvent.initEvent( 'change', true, true );
+
+	while ( scope.dom.children.length > 0 ) {
+
+		scope.dom.removeChild( scope.dom.firstChild );
+
+	}
+
+	scope.options = [];
+
+	for ( var i = 0; i < options.length; i ++ ) {
+
+		var option = options[ i ];
+
+		var div = document.createElement( 'div' );
+		div.className = 'option ' + ( option.static === true ? '': 'draggable' );
+		div.innerHTML = option.html;
+		div.value = option.value;
+		scope.dom.appendChild( div );
+
+		scope.options.push( div );
+
+		div.addEventListener( 'click', function ( event ) {
+
+			scope.setValue( this.value );
+			scope.dom.dispatchEvent( changeEvent );
+
+		}, false );
+
+	}
+
+	return scope;
+
+};
+
+UI.Outliner.prototype.getValue = function () {
+
+	return this.selectedValue;
+
+};
+
+UI.Outliner.prototype.setValue = function ( value ) {
+
+	for ( var i = 0; i < this.options.length; i ++ ) {
+
+		var element = this.options[ i ];
+
+		if ( element.value === value ) {
+
+			element.classList.add( 'active' );
+
+			// scroll into view
+
+			var y = element.offsetTop - this.dom.offsetTop;
+			var bottomY = y + element.offsetHeight;
+			var minScroll = bottomY - this.dom.offsetHeight;
+
+			if ( this.dom.scrollTop > y ) {
+
+				this.dom.scrollTop = y
+
+			} else if ( this.dom.scrollTop < minScroll ) {
+
+				this.dom.scrollTop = minScroll;
+
+			}
+
+			this.selectedIndex = i;
+
+		} else {
+
+			element.classList.remove( 'active' );
+
+		}
+
+	}
+
+	this.selectedValue = value;
+
+	return this;
+
+};

+ 2 - 1
examples/index.html

@@ -183,7 +183,7 @@
 			</a>
 			<div id="content"></div>
 		</div>
-		<iframe id="viewer" allowfullscreen></iframe>
+		<iframe id="viewer" allowfullscreen onmousewheel=""></iframe>
 
 		<script>
 
@@ -358,6 +358,7 @@
 				"webgl_shadowmap",
 				"webgl_shadowmap_performance",
 				"webgl_shadowmap_viewer",
+				"webgl_shadowmesh",
 				"webgl_sprites",
 				"webgl_terrain_dynamic",
 				"webgl_test_memory",

+ 1 - 1
examples/js/AudioObject.js

@@ -40,7 +40,7 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
 
 			THREE.AudioObject.prototype.context = new webkitAudioContext();
 
-		} catch( error ) {
+		} catch ( error ) {
 
 			console.warn( "THREE.AudioObject: webkitAudioContext not found" );
 			return this;

+ 9 - 9
examples/js/BlendCharacter.js

@@ -22,7 +22,7 @@ THREE.BlendCharacter = function () {
 
 			// Create the animations
 
-			for ( var i = 0; i < geometry.animations.length; ++i ) {
+			for ( var i = 0; i < geometry.animations.length; ++ i ) {
 
 				var animName = geometry.animations[ i ].name;
 				scope.animations[ animName ] = new THREE.Animation( scope, geometry.animations[ i ] );
@@ -46,7 +46,7 @@ THREE.BlendCharacter = function () {
 
 	this.update = function( dt ) {
 
-		for ( var i = this.weightSchedule.length - 1; i >= 0; --i ) {
+		for ( var i = this.weightSchedule.length - 1; i >= 0; -- i ) {
 
 			var data = this.weightSchedule[ i ];
 			data.timeElapsed += dt;
@@ -87,7 +87,7 @@ THREE.BlendCharacter = function () {
 		// lengths match. This is useful for smoothing out transitions that get out of
 		// phase such as between a walk and run cycle
 
-		for ( var i = this.warpSchedule.length - 1; i >= 0; --i ) {
+		for ( var i = this.warpSchedule.length - 1; i >= 0; -- i ) {
 
 			var data = this.warpSchedule[ i ];
 			data.timeElapsed += dt;
@@ -203,17 +203,17 @@ THREE.BlendCharacter = function () {
 
 	this.unPauseAll = function() {
 
-	for ( var a in this.animations ) {
+		for ( var a in this.animations ) {
 
-	  if ( this.animations[ a ].isPlaying && this.animations[ a ].isPaused ) {
+			if ( this.animations[ a ].isPlaying && this.animations[ a ].isPaused ) {
 
-		this.animations[ a ].pause();
+				this.animations[ a ].pause();
 
-	  }
+			}
 
-	}
+		}
 
-  };
+	};
 
 
 	this.stopAll = function() {

+ 3 - 3
examples/js/Car.js

@@ -195,7 +195,7 @@ THREE.Car = function () {
 
 		var forwardDelta = this.speed * delta;
 
-		this.carOrientation += ( forwardDelta * this.STEERING_RADIUS_RATIO )* this.wheelOrientation;
+		this.carOrientation += ( forwardDelta * this.STEERING_RADIUS_RATIO ) * this.wheelOrientation;
 
 		// displacement
 
@@ -363,8 +363,8 @@ THREE.Car = function () {
 	};
 
 	function quadraticEaseOut( k ) { return - k * ( k - 2 ); }
-	function cubicEaseOut( k ) { return --k * k * k + 1; }
-	function circularEaseOut( k ) { return Math.sqrt( 1 - --k * k ); }
+	function cubicEaseOut( k ) { return -- k * k * k + 1; }
+	function circularEaseOut( k ) { return Math.sqrt( 1 - -- k * k ); }
 	function sinusoidalEaseOut( k ) { return Math.sin( k * Math.PI / 2 ); }
 	function exponentialEaseOut( k ) { return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1; }
 

+ 26 - 26
examples/js/Cloth.js

@@ -48,8 +48,8 @@ var lastTime;
 function plane(width, height) {
 
 	return function(u, v) {
-		var x = (u-0.5) * width;
-		var y = (v+0.5) * height;
+		var x = (u - 0.5) * width;
+		var y = (v + 0.5) * height;
 		var z = 0;
 
 		return new THREE.Vector3(x, y, z);
@@ -94,8 +94,8 @@ var diff = new THREE.Vector3();
 function satisifyConstrains(p1, p2, distance) {
 	diff.subVectors(p2.position, p1.position);
 	var currentDist = diff.length();
-	if (currentDist==0) return; // prevents division by 0
-	var correction = diff.multiplyScalar(1 - distance/currentDist);
+	if (currentDist == 0) return; // prevents division by 0
+	var correction = diff.multiplyScalar(1 - distance / currentDist);
 	var correctionHalf = correction.multiplyScalar(0.5);
 	p1.position.add(correctionHalf);
 	p2.position.sub(correctionHalf);
@@ -114,47 +114,47 @@ function Cloth(w, h) {
 	var u, v;
 
 	// Create particles
-	for (v=0;v<=h;v++) {
-		for (u=0;u<=w;u++) {
+	for (v = 0; v <= h; v ++) {
+		for (u = 0; u <= w; u ++) {
 			particles.push(
-				new Particle(u/w, v/h, 0, MASS)
+				new Particle(u / w, v / h, 0, MASS)
 			);
 		}
 	}
 
 	// Structural
 
-	for (v=0;v<h;v++) {
-		for (u=0;u<w;u++) {
+	for (v = 0; v < h; v ++) {
+		for (u = 0; u < w; u ++) {
 
 			constrains.push([
 				particles[index(u, v)],
-				particles[index(u, v+1)],
+				particles[index(u, v + 1)],
 				restDistance
 			]);
 
 			constrains.push([
 				particles[index(u, v)],
-				particles[index(u+1, v)],
+				particles[index(u + 1, v)],
 				restDistance
 			]);
 
 		}
 	}
 
-	for (u=w, v=0;v<h;v++) {
+	for (u = w, v = 0; v < h; v ++) {
 		constrains.push([
 			particles[index(u, v)],
-			particles[index(u, v+1)],
+			particles[index(u, v + 1)],
 			restDistance
 
 		]);
 	}
 
-	for (v=h, u=0;u<w;u++) {
+	for (v = h, u = 0; u < w; u ++) {
 		constrains.push([
 			particles[index(u, v)],
-			particles[index(u+1, v)],
+			particles[index(u + 1, v)],
 			restDistance
 		]);
 	}
@@ -211,7 +211,7 @@ function simulate(time) {
 
 		particles = cloth.particles;
 
-		for (i=0,il=faces.length;i<il;i++) {
+		for (i = 0,il = faces.length; i < il; i ++) {
 			face = faces[i];
 			normal = face.normal;
 
@@ -222,8 +222,8 @@ function simulate(time) {
 		}
 	}
 	
-	for (particles = cloth.particles, i=0, il = particles.length
-			;i<il;i++) {
+	for (particles = cloth.particles, i = 0, il = particles.length
+			; i < il; i ++) {
 		particle = particles[i];
 		particle.addForce(gravity);
 
@@ -234,7 +234,7 @@ function simulate(time) {
 
 	constrains = cloth.constrains,
 	il = constrains.length;
-	for (i=0;i<il;i++) {
+	for (i = 0; i < il; i ++) {
 		constrain = constrains[i];
 		satisifyConstrains(constrain[0], constrain[1], constrain[2]);
 	}
@@ -242,12 +242,12 @@ function simulate(time) {
 	// Ball Constrains
 
 
-	ballPosition.z = -Math.sin(Date.now()/600) * 90 ; //+ 40;
-	ballPosition.x = Math.cos(Date.now()/400) * 70
+	ballPosition.z = -Math.sin(Date.now() / 600) * 90 ; //+ 40;
+	ballPosition.x = Math.cos(Date.now() / 400) * 70
 
 	if (sphere.visible)
-	for (particles = cloth.particles, i=0, il = particles.length
-			;i<il;i++) {
+	for (particles = cloth.particles, i = 0, il = particles.length
+			; i < il; i ++) {
 		particle = particles[i];
 		pos = particle.position;
 		diff.subVectors(pos, ballPosition);
@@ -259,8 +259,8 @@ function simulate(time) {
 	}
 
 	// Floor Constains
-	for (particles = cloth.particles, i=0, il = particles.length
-			;i<il;i++) {
+	for (particles = cloth.particles, i = 0, il = particles.length
+			; i < il; i ++) {
 		particle = particles[i];
 		pos = particle.position;
 		if (pos.y < -250) {
@@ -269,7 +269,7 @@ function simulate(time) {
 	}
 
 	// Pin Constrains
-	for (i=0, il=pins.length;i<il;i++) {
+	for (i = 0, il = pins.length; i < il; i ++) {
 		var xy = pins[i];
 		var p = particles[xy];
 		p.position.copy(p.original);

+ 9 - 9
examples/js/CurveExtras.js

@@ -15,15 +15,15 @@
 THREE.Curves = {};
 
 
- THREE.Curves.GrannyKnot = THREE.Curve.create( function(){},
+ THREE.Curves.GrannyKnot = THREE.Curve.create( function() {},
 
 	 function(t) {
-	    t = 2 * Math.PI * t;
+		t = 2 * Math.PI * t;
 
-	    var x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
-	    var y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
-	    var z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
-	    return new THREE.Vector3(x, y, z).multiplyScalar(20);
+		var x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
+		var y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
+		var z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
+		return new THREE.Vector3(x, y, z).multiplyScalar(20);
 	}
 );
 
@@ -214,10 +214,10 @@ THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
 // }
 var scaleTo = function(x, y, t) {
 
-		var r = y - x;
-		return t * r + x;
+	var r = y - x;
+	return t * r + x;
 
-	}
+}
 
 THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
 

+ 1 - 1
examples/js/Detector.js

@@ -6,7 +6,7 @@
 var Detector = {
 
 	canvas: !! window.CanvasRenderingContext2D,
-	webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) ); } catch( e ) { return false; } } )(),
+	webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) ); } catch ( e ) { return false; } } )(),
 	workers: !! window.Worker,
 	fileapi: window.File && window.FileReader && window.FileList && window.Blob,
 

+ 10 - 10
examples/js/ImprovedNoise.js

@@ -2,7 +2,7 @@
 
 var ImprovedNoise = function () {
 
-	var p = [151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,
+	var p = [ 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,
 		 23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,
 		 174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,
 		 133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,
@@ -11,11 +11,11 @@ var ImprovedNoise = function () {
 		 248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,
 		 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,
 		 14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,
-		 93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
+		 93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 ];
 
-	for (var i=0; i < 256 ; i++) {
+	for (var i = 0; i < 256 ; i ++) {
 
-		p[256+i] = p[i];
+		p[256 + i] = p[i];
 
 	}
 
@@ -51,20 +51,20 @@ var ImprovedNoise = function () {
 			y -= floorY;
 			z -= floorZ;
 
-			var xMinus1 = x -1, yMinus1 = y - 1, zMinus1 = z - 1;
+			var xMinus1 = x - 1, yMinus1 = y - 1, zMinus1 = z - 1;
 
 			var u = fade(x), v = fade(y), w = fade(z);
 
-			var A = p[X]+Y, AA = p[A]+Z, AB = p[A+1]+Z, B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z;
+			var A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z, B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z;
 
 			return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), 
 							grad(p[BA], xMinus1, y, z)),
 						lerp(u, grad(p[AB], x, yMinus1, z),
 							grad(p[BB], xMinus1, yMinus1, z))),
-					lerp(v, lerp(u, grad(p[AA+1], x, y, zMinus1),
-							grad(p[BA+1], xMinus1, y, z-1)),
-						lerp(u, grad(p[AB+1], x, yMinus1, zMinus1),
-							grad(p[BB+1], xMinus1, yMinus1, zMinus1))));
+					lerp(v, lerp(u, grad(p[AA + 1], x, y, zMinus1),
+							grad(p[BA + 1], xMinus1, y, z - 1)),
+						lerp(u, grad(p[AB + 1], x, yMinus1, zMinus1),
+							grad(p[BB + 1], xMinus1, yMinus1, zMinus1))));
 
 		}
 	}

+ 1 - 1
examples/js/MD2Character.js

@@ -210,7 +210,7 @@ THREE.MD2Character = function () {
 		//
 
 		var mesh = new THREE.MorphAnimMesh( geometry, materialTexture );
-		mesh.rotation.y = -Math.PI/2;
+		mesh.rotation.y = -Math.PI / 2;
 
 		mesh.castShadow = true;
 		mesh.receiveShadow = true;

+ 3 - 3
examples/js/MD2CharacterComplex.js

@@ -402,7 +402,7 @@ THREE.MD2CharacterComplex = function () {
 
 		if ( controls.moveForward ) {
 
-			if ( this.meshBody )   {
+			if ( this.meshBody ) {
 
 				this.meshBody.setAnimationDirectionForward( this.activeAnimation );
 				this.meshBody.setAnimationDirectionForward( this.oldAnimation );
@@ -445,7 +445,7 @@ THREE.MD2CharacterComplex = function () {
 		// speed based on controls
 
 		if ( controls.crouch ) 	this.maxSpeed = this.crouchSpeed;
-		else  					this.maxSpeed = this.walkSpeed;
+		else this.maxSpeed = this.walkSpeed;
 
 		this.maxReverseSpeed = -this.maxSpeed;
 
@@ -533,7 +533,7 @@ THREE.MD2CharacterComplex = function () {
 		//
 
 		var mesh = new THREE.MorphBlendMesh( geometry, materialTexture );
-		mesh.rotation.y = -Math.PI/2;
+		mesh.rotation.y = -Math.PI / 2;
 
 		//
 

+ 23 - 23
examples/js/MarchingCubes.js

@@ -224,7 +224,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
 
 		// bottom of the cube
 
-		if ( bits & 16 )  {
+		if ( bits & 16 ) {
 
 			this.compNorm( qz );
 			this.compNorm( q1z );
@@ -232,7 +232,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
 
 		};
 
-		if ( bits & 32 )  {
+		if ( bits & 32 ) {
 
 			this.compNorm( q1z );
 			this.compNorm( q1yz );
@@ -485,22 +485,22 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
 
 		var x, y, z, y_offset, z_offset, fx, fy, fz, fz2, fy2, val;
 
-		for ( z = min_z; z < max_z; z++ ) {
+		for ( z = min_z; z < max_z; z ++ ) {
 
 			z_offset = this.size2 * z,
 			fz = z / this.size - ballz,
 			fz2 = fz * fz;
 
-			for ( y = min_y; y < max_y; y++ ) {
+			for ( y = min_y; y < max_y; y ++ ) {
 
 				y_offset = z_offset + this.size * y;
 				fy = y / this.size - bally;
 				fy2 = fy * fy;
 
-				for ( x = min_x; x < max_x; x++ ) {
+				for ( x = min_x; x < max_x; x ++ ) {
 
 					fx = x / this.size - ballx;
-					val = strength / ( 0.000001 + fx*fx + fy2 + fz2 ) - subtract;
+					val = strength / ( 0.000001 + fx * fx + fy2 + fz2 ) - subtract;
 					if ( val > 0.0 ) this.field[ y_offset + x ] += val;
 
 				}
@@ -763,38 +763,38 @@ THREE.MarchingCubes.prototype.constructor = THREE.MarchingCubes;
 // who in turn got them from Cory Gene Bloyd.
 
 THREE.edgeTable = new Int32Array([
-0x0  , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
+0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
-0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
+0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
-0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c,
+0x230, 0x339, 0x33, 0x13a, 0x636, 0x73f, 0x435, 0x53c,
 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
-0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac,
+0x3a0, 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, 0x4ac,
 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
-0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c,
+0x460, 0x569, 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c,
 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
-0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc,
+0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff, 0x3f5, 0x2fc,
 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
-0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c,
+0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55, 0x15c,
 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
-0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc ,
+0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc,
 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
-0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
+0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
-0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
+0x15c, 0x55, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
-0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
+0x2fc, 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
-0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460,
+0x36c, 0x265, 0x16f, 0x66, 0x76a, 0x663, 0x569, 0x460,
 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
-0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0,
+0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa, 0x1a3, 0x2a9, 0x3a0,
 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
-0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230,
+0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33, 0x339, 0x230,
 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
-0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190,
+0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190,
 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
-0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0])
+0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 ])
 
 THREE.triTable = new Int32Array([
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -1052,4 +1052,4 @@ THREE.triTable = new Int32Array([
 1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]);
+-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ]);

+ 10 - 9
examples/js/Ocean.js

@@ -20,8 +20,8 @@
 		return value !== undefined ? value : defaultValue;
 	};
 	options = options || {};
-	this.clearColor = optionalParameter(options.CLEAR_COLOR, [1.0, 1.0, 1.0, 0.0]);
-	this.geometryOrigin = optionalParameter(options.GEOMETRY_ORIGIN, [-1000.0, -1000.0]);
+	this.clearColor = optionalParameter(options.CLEAR_COLOR, [ 1.0, 1.0, 1.0, 0.0 ]);
+	this.geometryOrigin = optionalParameter(options.GEOMETRY_ORIGIN, [ -1000.0, -1000.0 ]);
 	this.sunDirectionX = optionalParameter(options.SUN_DIRECTION[0], -1.0);
 	this.sunDirectionY = optionalParameter(options.SUN_DIRECTION[1], 1.0);
 	this.sunDirectionZ = optionalParameter(options.SUN_DIRECTION[2], 1.0);
@@ -41,6 +41,7 @@
 	this.matrixNeedsUpdate = false;
 	
 	// Setup framebuffer pipeline
+	var renderTargetType = optionalParameter(options.USE_HALF_FLOAT, false) ? THREE.HalfFloatType : THREE.FloatType;
 	var LinearClampParams = {
 		minFilter: THREE.LinearFilter,
 		magFilter: THREE.LinearFilter,
@@ -50,7 +51,7 @@
 		stencilBuffer: false,
 		depthBuffer: false,
 		premultiplyAlpha: false,
-		type: THREE.FloatType
+		type: renderTargetType
 	};
 	var NearestClampParams = {
 		minFilter: THREE.NearestFilter,
@@ -61,7 +62,7 @@
 		stencilBuffer: false,
 		depthBuffer: false,
 		premultiplyAlpha:false,
-		type: THREE.FloatType
+		type: renderTargetType
 	};
 	var NearestRepeatParams = {
 		minFilter: THREE.NearestFilter,
@@ -72,7 +73,7 @@
 		stencilBuffer: false,
 		depthBuffer: false,
 		premultiplyAlpha: false,
-		type: THREE.FloatType
+		type: renderTargetType
 	};
 	this.initialSpectrumFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestRepeatParams);
 	this.spectrumFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestClampParams);
@@ -227,8 +228,8 @@ THREE.Ocean.prototype.generateSeedPhaseTexture = function() {
 	// Setup the seed texture
 	this.pingPhase = true;
 	var phaseArray = new window.Float32Array(this.resolution * this.resolution * 4);
-	for (var i = 0; i < this.resolution; i++) {
-		for (var j = 0; j < this.resolution; j++) {
+	for (var i = 0; i < this.resolution; i ++) {
+		for (var j = 0; j < this.resolution; j ++) {
 			phaseArray[i * this.resolution * 4 + j * 4] =  Math.random() * 2.0 * Math.PI;
 			phaseArray[i * this.resolution * 4 + j * 4 + 1] = 0.0;
 			phaseArray[i * this.resolution * 4 + j * 4 + 2] = 0.0;
@@ -282,7 +283,7 @@ THREE.Ocean.prototype.renderSpectrumFFT = function() {
 	
 	this.scene.overrideMaterial = this.materialOceanHorizontal;
 
-	for (var i = 0; i < iterations; i++) {
+	for (var i = 0; i < iterations; i ++) {
 		if (i === 0) {
 			this.materialOceanHorizontal.uniforms.u_input.value = this.spectrumFramebuffer;
 			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
@@ -300,7 +301,7 @@ THREE.Ocean.prototype.renderSpectrumFFT = function() {
 		}
 	}
 	this.scene.overrideMaterial = this.materialOceanVertical;
-	for (var i = iterations; i < iterations*2; i++) {
+	for (var i = iterations; i < iterations * 2; i ++) {
 		if (i === iterations * 2 - 1) {
 			this.materialOceanVertical.uniforms.u_input.value = (iterations % 2 === 0) ? this.pingTransformFramebuffer : this.pongTransformFramebuffer;
 			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);

+ 43 - 43
examples/js/Octree.js

@@ -29,7 +29,7 @@
 	
 	function indexOfValue( array, value ) {
 		
-		for ( var i = 0, il = array.length; i < il; i++ ) {
+		for ( var i = 0, il = array.length; i < il; i ++ ) {
 			
 			if ( array[ i ] === value ) {
 				
@@ -45,7 +45,7 @@
 	
 	function indexOfPropertyWithValue( array, property, value ) {
 		
-		for ( var i = 0, il = array.length; i < il; i++ ) {
+		for ( var i = 0, il = array.length; i < il; i ++ ) {
 			
 			if ( array[ i ][ property ] === value ) {
 				
@@ -140,7 +140,7 @@
 			
 			if ( this.objectsDeferred.length > 0 ) {
 				
-				for ( var i = 0, il = this.objectsDeferred.length; i < il; i++ ) {
+				for ( var i = 0, il = this.objectsDeferred.length; i < il; i ++ ) {
 					
 					var deferred = this.objectsDeferred[ i ];
 					
@@ -221,7 +221,7 @@
 					geometry = object.geometry;
 					vertices = geometry.vertices;
 					
-					for ( i = 0, l = vertices.length; i < l; i++ ) {
+					for ( i = 0, l = vertices.length; i < l; i ++ ) {
 						
 						this.addObjectData( object, vertices[ i ] );
 						
@@ -232,7 +232,7 @@
 					geometry = object.geometry;
 					faces = geometry.faces;
 					
-					for ( i = 0, l = faces.length; i < l; i++ ) {
+					for ( i = 0, l = faces.length; i < l; i ++ ) {
 						
 						this.addObjectData( object, faces[ i ] );
 						
@@ -297,7 +297,7 @@
 					
 					// remove from objects data list
 					
-					for ( i = 0, l = objectsDataRemoved.length; i < l; i++ ) {
+					for ( i = 0, l = objectsDataRemoved.length; i < l; i ++ ) {
 						
 						objectData = objectsDataRemoved[ i ];
 						
@@ -341,7 +341,7 @@
 				
 				objectsData = octree.objectsData;
 				
-				for ( i = 0, l = objectsData.length; i < l; i++ ) {
+				for ( i = 0, l = objectsData.length; i < l; i ++ ) {
 					
 					objectData = objectsData[ i ];
 					
@@ -366,7 +366,7 @@
 			// check all object data for changes in position
 			// assumes all object matrices are up to date
 			
-			for ( i = 0, l = this.objectsData.length; i < l; i++ ) {
+			for ( i = 0, l = this.objectsData.length; i < l; i ++ ) {
 				
 				objectData = this.objectsData[ i ];
 				
@@ -402,7 +402,7 @@
 			
 			// update changed objects
 			
-			for ( i = 0, l = objectsUpdate.length; i < l; i++ ) {
+			for ( i = 0, l = objectsUpdate.length; i < l; i ++ ) {
 				
 				objectData = objectsUpdate[ i ];
 				
@@ -429,14 +429,14 @@
 			
 			parent = object.parent;
 			
-			while( parent ) {
+			while ( parent ) {
 				
 				parentCascade.push( parent );
 				parent = parent.parent;
 				
 			}
 			
-			for ( i = 0, l = parentCascade.length; i < l; i++ ) {
+			for ( i = 0, l = parentCascade.length; i < l; i ++ ) {
 				
 				parent = parentCascade[ i ];
 				
@@ -494,7 +494,7 @@
 			
 			// search each node of root
 			
-			for ( i = 0, l = this.root.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.root.nodesIndices.length; i < l; i ++ ) {
 				
 				node = this.root.nodesByIndex[ this.root.nodesIndices[ i ] ];
 				
@@ -511,7 +511,7 @@
 				
 				// for each object data found
 				
-				for ( i = 0, l = objects.length; i < l; i++ ) {
+				for ( i = 0, l = objects.length; i < l; i ++ ) {
 					
 					objectData = objects[ i ];
 					object = objectData.object;
@@ -739,7 +739,7 @@
 		
 		// basic properties
 		
-		this.id = this.tree.nodeCount++;
+		this.id = this.tree.nodeCount ++;
 		this.position = parameters.position instanceof THREE.Vector3 ? parameters.position : new THREE.Vector3();
 		this.radius = parameters.radius > 0 ? parameters.radius : 1;
 		this.indexOctant = parameters.indexOctant;
@@ -811,7 +811,7 @@
 			
 			// cascade
 			
-			for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 				
 				this.nodesByIndex[ this.nodesIndices[ i ] ].updateProperties();
 				
@@ -832,7 +832,7 @@
 			
 			// unset parent in nodes
 			
-			for ( i = 0, l = nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = nodesIndices.length; i < l; i ++ ) {
 				
 				node = nodesByIndex[ nodesIndices[ i ] ];
 				
@@ -949,7 +949,7 @@
 			var i, l,
 				object;
 
-			for ( i = 0, l = objects.length; i < l; i++ ) {
+			for ( i = 0, l = objects.length; i < l; i ++ ) {
 				
 				object = objects[ i ];
 				
@@ -977,7 +977,7 @@
 			
 			if ( nodesRemovedFrom.length > 0 ) {
 				
-				for ( i = 0, l = nodesRemovedFrom.length; i < l; i++ ) {
+				for ( i = 0, l = nodesRemovedFrom.length; i < l; i ++ ) {
 					
 					nodesRemovedFrom[ i ].shrink();
 					
@@ -1021,7 +1021,7 @@
 			
 				// search each object data for object and remove (slow)
 				
-				for ( i = this.objects.length - 1; i >= 0; i-- ) {
+				for ( i = this.objects.length - 1; i >= 0; i -- ) {
 					
 					objectData = this.objects[ i ];
 					
@@ -1059,7 +1059,7 @@
 			
 			if ( removeData.searchComplete !== true ) {
 				
-				for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+				for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 					
 					node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 					
@@ -1106,7 +1106,7 @@
 			
 			// for each object
 			
-			for ( i = 0, l = this.objects.length; i < l; i++ ) {
+			for ( i = 0, l = this.objects.length; i < l; i ++ ) {
 				
 				object = this.objects[ i ];
 				
@@ -1183,7 +1183,7 @@
 				
 				// for each object
 				
-				for ( i = 0, l = objects.length; i < l; i++ ) {
+				for ( i = 0, l = objects.length; i < l; i ++ ) {
 					
 					object = objects[ i ];
 					
@@ -1314,7 +1314,7 @@
 				
 				// reset counts
 				
-				for ( i = 0, l = iom.length; i < l; i++ ) {
+				for ( i = 0, l = iom.length; i < l; i ++ ) {
 					
 					iom[ i ].count = 0;
 					
@@ -1322,7 +1322,7 @@
 				
 				// for all outside objects, find outside octants containing most objects
 				
-				for ( i = 0, l = objects.length; i < l; i++ ) {
+				for ( i = 0, l = objects.length; i < l; i ++ ) {
 					
 					object = objects[ i ];
 					
@@ -1344,11 +1344,11 @@
 						
 						if ( flagsOutside & this.tree.FLAG_POS_X ) {
 							
-							iom[ this.tree.INDEX_OUTSIDE_POS_X ].count++;
+							iom[ this.tree.INDEX_OUTSIDE_POS_X ].count ++;
 							
 						} else if ( flagsOutside & this.tree.FLAG_NEG_X ) {
 							
-							iom[ this.tree.INDEX_OUTSIDE_NEG_X ].count++;
+							iom[ this.tree.INDEX_OUTSIDE_NEG_X ].count ++;
 							
 						}
 						
@@ -1356,11 +1356,11 @@
 						
 						if ( flagsOutside & this.tree.FLAG_POS_Y ) {
 							
-							iom[ this.tree.INDEX_OUTSIDE_POS_Y ].count++;
+							iom[ this.tree.INDEX_OUTSIDE_POS_Y ].count ++;
 							
 						} else if ( flagsOutside & this.tree.FLAG_NEG_Y ) {
 							
-							iom[ this.tree.INDEX_OUTSIDE_NEG_Y ].count++;
+							iom[ this.tree.INDEX_OUTSIDE_NEG_Y ].count ++;
 							
 						}
 						
@@ -1368,11 +1368,11 @@
 						
 						if ( flagsOutside & this.tree.FLAG_POS_Z ) {
 							
-							iom[ this.tree.INDEX_OUTSIDE_POS_Z ].count++;
+							iom[ this.tree.INDEX_OUTSIDE_POS_Z ].count ++;
 							
 						} else if ( flagsOutside & this.tree.FLAG_NEG_Z ) {
 							
-							iom[ this.tree.INDEX_OUTSIDE_NEG_Z ].count++;
+							iom[ this.tree.INDEX_OUTSIDE_NEG_Z ].count ++;
 							
 						}
 						
@@ -1474,7 +1474,7 @@
 					
 					// add all expand objects to parent
 					
-					for ( i = 0, l = objectsExpand.length; i < l; i++ ) {
+					for ( i = 0, l = objectsExpand.length; i < l; i ++ ) {
 						
 						this.tree.root.addObject( objectsExpand[ i ] );
 						
@@ -1546,7 +1546,7 @@
 			
 			nodes = toArray( nodes );
 			
-			for ( i = 0, l = nodes.length; i < l; i++ ) {
+			for ( i = 0, l = nodes.length; i < l; i ++ ) {
 				
 				node = nodes[ i ];
 				
@@ -1586,7 +1586,7 @@
 				nodeHeaviestObjectsCount = 0;
 				outsideHeaviestObjectsCount = this.objects.length;
 				
-				for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+				for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 					
 					node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 					
@@ -1625,7 +1625,7 @@
 			
 			// handle all nodes
 			
-			for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 				
 				node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 				
@@ -1848,7 +1848,7 @@
 				
 				// search subtree
 				
-				for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+				for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 					
 					node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 					
@@ -1917,7 +1917,7 @@
 			tmin = Math.max( Math.max( Math.min( t1, t2), Math.min( t3, t4)), Math.min( t5, t6));
 			
 			// if tmin > tmax or tmin > ray distance, ray doesn't intersect AABB
-			if( tmin > tmax || tmin > distance ) {
+			if ( tmin > tmax || tmin > distance ) {
 				return false;
 			}
 			
@@ -1932,7 +1932,7 @@
 
 			if ( this.nodesIndices.length > 0 ) {
 				
-				for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+				for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 
 					node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 
@@ -1961,7 +1961,7 @@
 			var i, l,
 				count = this.nodesIndices.length;
 			
-			for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 				
 				count += this.nodesByIndex[ this.nodesIndices[ i ] ].getNodeCountRecursive();
 				
@@ -1978,7 +1978,7 @@
 			
 			objects = ( objects || [] ).concat( this.objects );
 			
-			for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 				
 				node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 				
@@ -1995,7 +1995,7 @@
 			var i, l,
 				count = this.objects.length;
 			
-			for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 				
 				count += this.nodesByIndex[ this.nodesIndices[ i ] ].getObjectCountEnd();
 				
@@ -2010,7 +2010,7 @@
 			var count = this.objects.length,
 				parent = this.parent;
 			
-			while( parent instanceof THREE.OctreeNode ) {
+			while ( parent instanceof THREE.OctreeNode ) {
 				
 				count += parent.objects.length;
 				parent = parent.parent;
@@ -2033,7 +2033,7 @@
 			console.log( ( this.parent ? space + ' ' : ' ' ), '+ objects ( ', this.objects.length, ' ) ', this.objects );
 			console.log( ( this.parent ? space + ' ' : ' ' ), '+ children ( ', this.nodesIndices.length, ' )', this.nodesIndices, this.nodesByIndex );
 			
-			for ( i = 0, l = this.nodesIndices.length; i < l; i++ ) {
+			for ( i = 0, l = this.nodesIndices.length; i < l; i ++ ) {
 				
 				node = this.nodesByIndex[ this.nodesIndices[ i ] ];
 				
@@ -2101,7 +2101,7 @@
 		var i, il,
 			intersects = [];
 		
-		for ( i = 0, il = objects.length; i < il; i++ ) {
+		for ( i = 0, il = objects.length; i < il; i ++ ) {
 			
 			intersects = intersects.concat( this.intersectOctreeObject( objects[ i ], recursive ) );
 		

+ 6 - 6
examples/js/ParametricGeometries.js

@@ -48,9 +48,9 @@ THREE.ParametricGeometries = {
 		var x, y, z;
 
 		var a = 2;
-		x = Math.cos(v) * (a + u * Math.cos(v/2));
-		y = Math.sin(v) * (a + u * Math.cos(v/2));
-		z = u * Math.sin(v/2);
+		x = Math.cos(v) * (a + u * Math.cos(v / 2));
+		y = Math.sin(v) * (a + u * Math.cos(v / 2));
+		z = u * Math.sin(v / 2);
 		return new THREE.Vector3(x, y, z);
 
 	},
@@ -108,9 +108,9 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme
 		binormals = frames.binormals;
 
 		// proxy internals
-		this.tangents = tangents;
-		this.normals = normals;
-		this.binormals = binormals;
+	this.tangents = tangents;
+	this.normals = normals;
+	this.binormals = binormals;
 
 
 

+ 11 - 10
examples/js/ShaderDeferred.js

@@ -147,6 +147,7 @@ THREE.ShaderDeferred = {
 			"uniform float wrapAround;",
 			"uniform float additiveSpecular;",
 
+			THREE.ShaderChunk[ "common" ],
 			THREE.ShaderChunk[ "color_pars_fragment" ],
 			THREE.ShaderChunk[ "map_pars_fragment" ],
 			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
@@ -186,7 +187,8 @@ THREE.ShaderDeferred = {
 
 				"const float opacity = 1.0;",
 
-				"gl_FragColor = vec4( diffuse, opacity );",
+				"vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does
+				"vec4 diffuseColor = vec4( diffuse, opacity );",
 
 				THREE.ShaderChunk[ "map_fragment" ],
 				THREE.ShaderChunk[ "alphatest_fragment" ],
@@ -194,6 +196,8 @@ THREE.ShaderDeferred = {
 				THREE.ShaderChunk[ "lightmap_fragment" ],
 				THREE.ShaderChunk[ "color_fragment" ],
 
+				"outgoingLight = diffuseColor.rgb;",
+
 				"#ifdef USE_ENVMAP",
 
 					"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
@@ -225,23 +229,19 @@ THREE.ShaderDeferred = {
 
 					"#endif",
 
-					"#ifdef GAMMA_INPUT",
-
-						"cubeColor.xyz *= cubeColor.xyz;",
-
-					"#endif",
+					"cubeColor.xyz = inputToLinear( cubeColor.xyz );",
 
 					"if ( combine == 1 ) {",
 
-						"gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );",
+						"outgoingLight = mix( outgoingLight, cubeColor.xyz, specularStrength * reflectivity );",
 
 					"} else if ( combine == 2 ) {",
 
-						"gl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;",
+						"outgoingLight += cubeColor.xyz * specularStrength * reflectivity;",
 
 					"} else {",
 
-						"gl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );",
+						"outgoingLight = mix( outgoingLight, diffuseColor.xyz * cubeColor.xyz, specularStrength * reflectivity );",
 
 					"}",
 
@@ -270,7 +270,7 @@ THREE.ShaderDeferred = {
 
 				// diffuse color
 
-				"gl_FragColor.x = vec3_to_float( compressionScale * gl_FragColor.xyz );",
+				"gl_FragColor.x = vec3_to_float( compressionScale * outgoingLight );",
 
 				// specular color
 
@@ -308,6 +308,7 @@ THREE.ShaderDeferred = {
 
 		vertexShader : [
 
+			THREE.ShaderChunk[ "common" ],
 			THREE.ShaderChunk[ "map_pars_vertex" ],
 			THREE.ShaderChunk[ "lightmap_pars_vertex" ],
 			THREE.ShaderChunk[ "color_pars_vertex" ],

+ 49 - 80
examples/js/ShaderSkin.js

@@ -103,6 +103,7 @@ THREE.ShaderSkin = {
 				"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
 				"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
 				"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
+				"uniform float pointLightDecay[ MAX_POINT_LIGHTS ];",
 
 			"#endif",
 
@@ -158,12 +159,13 @@ THREE.ShaderSkin = {
 
 			"void main() {",
 
-				"gl_FragColor = vec4( vec3( 1.0 ), opacity );",
+				"vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does
+				"vec4 diffuseColor = vec4( diffuse, opacity );",
 
 				"vec4 colDiffuse = texture2D( tDiffuse, vUv );",
 				"colDiffuse.rgb *= colDiffuse.rgb;",
 
-				"gl_FragColor = gl_FragColor * colDiffuse;",
+				"diffuseColor = diffuseColor * colDiffuse;",
 
 				"vec3 normal = normalize( vNormal );",
 				"vec3 viewPosition = normalize( vViewPosition );",
@@ -189,22 +191,18 @@ THREE.ShaderSkin = {
 
 				// point lights
 
-				"vec3 specularTotal = vec3( 0.0 );",
+				"vec3 totalSpecularLight = vec3( 0.0 );",
+				"vec3 totalDiffuseLight = vec3( 0.0 );",
 
 				"#if MAX_POINT_LIGHTS > 0",
 
-					"vec3 pointTotal = vec3( 0.0 );",
-
 					"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 						"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
 
 						"vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
 
-						"float lDistance = 1.0;",
-
-						"if ( pointLightDistance[ i ] > 0.0 )",
-							"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
+						"float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );",
 
 						"lVector = normalize( lVector );",
 
@@ -214,8 +212,8 @@ THREE.ShaderSkin = {
 
 						"float pointSpecularWeight = KS_Skin_Specular( normal, lVector, viewPosition, uRoughness, uSpecularBrightness );",
 
-						"pointTotal    += lDistance * diffuse * pointLightColor[ i ] * pointDiffuseWeight;",
-						"specularTotal += lDistance * specular * pointLightColor[ i ] * pointSpecularWeight * specularStrength;",
+						"totalDiffuseLight += attenuation * pointLightColor[ i ] * pointDiffuseWeight;",
+						"totalSpecularLight += attenuation * specular * pointLightColor[ i ] * pointSpecularWeight * specularStrength;",
 
 					"}",
 
@@ -225,8 +223,6 @@ THREE.ShaderSkin = {
 
 				"#if MAX_DIR_LIGHTS > 0",
 
-					"vec3 dirTotal = vec3( 0.0 );",
-
 					"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
 
 						"vec3 dirVector = transformDirection( directionalLightDirection[ i ], viewMatrix );",
@@ -235,10 +231,10 @@ THREE.ShaderSkin = {
 						"float dirDiffuseWeightHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );",
 						"vec3 dirDiffuseWeight = mix( vec3 ( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), uWrapRGB );",
 
-						"float dirSpecularWeight =  KS_Skin_Specular( normal, dirVector, viewPosition, uRoughness, uSpecularBrightness );",
+						"float dirSpecularWeight = KS_Skin_Specular( normal, dirVector, viewPosition, uRoughness, uSpecularBrightness );",
 
-						"dirTotal 	   += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;",
-						"specularTotal += specular * directionalLightColor[ i ] * dirSpecularWeight * specularStrength;",
+						"totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;",
+						"totalSpecularLight += specular * directionalLightColor[ i ] * dirSpecularWeight * specularStrength;",
 
 					"}",
 
@@ -248,8 +244,6 @@ THREE.ShaderSkin = {
 
 				"#if MAX_HEMI_LIGHTS > 0",
 
-					"vec3 hemiTotal = vec3( 0.0 );",
-
 					"for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
 
 						"vec3 lVector = transformDirection( hemisphereLightDirection[ i ], viewMatrix );",
@@ -257,7 +251,7 @@ THREE.ShaderSkin = {
 						"float dotProduct = dot( normal, lVector );",
 						"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
 
-						"hemiTotal += diffuse * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+						"totalDiffuseLight += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
 
 						// specular (sky light)
 
@@ -269,34 +263,21 @@ THREE.ShaderSkin = {
 						"vec3 lVectorGround = -lVector;",
 						"hemiSpecularWeight += KS_Skin_Specular( normal, lVectorGround, viewPosition, uRoughness, uSpecularBrightness );",
 
-						"specularTotal += specular * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * specularStrength;",
+						"totalSpecularLight += specular * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * specularStrength;",
 
 					"}",
 
 				"#endif",
 
-				// all lights contribution summation
-
-				"vec3 totalLight = vec3( 0.0 );",
-
-				"#if MAX_DIR_LIGHTS > 0",
-					"totalLight += dirTotal;",
-				"#endif",
-
-				"#if MAX_POINT_LIGHTS > 0",
-					"totalLight += pointTotal;",
-				"#endif",
-
-				"#if MAX_HEMI_LIGHTS > 0",
-					"totalLight += hemiTotal;",
-				"#endif",
-
-				"gl_FragColor.xyz = gl_FragColor.xyz * ( totalLight + ambientLightColor * diffuse ) + specularTotal;",
+				"outgoingLight += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor * diffuse ) + totalSpecularLight;",
 
 				THREE.ShaderChunk[ "shadowmap_fragment" ],
 				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
 				THREE.ShaderChunk[ "fog_fragment" ],
 
+				"gl_FragColor = vec4( outgoingLight, diffuseColor.a );",	// TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
+
+
 			"}"
 
 		].join("\n"),
@@ -310,6 +291,7 @@ THREE.ShaderSkin = {
 
 			"varying vec3 vViewPosition;",
 
+			THREE.ShaderChunk[ "common" ],
 			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
 
 			"void main() {",
@@ -469,9 +451,9 @@ THREE.ShaderSkin = {
 
 			"void main() {",
 
-				"gl_FragColor = vec4( 1.0 );",
+				"vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does
+				"vec4 diffuseColor = vec4( diffuse, opacity );",
 
-				"vec4 mColor = vec4( diffuse, opacity );",
 				"vec4 mSpecular = vec4( specular, opacity );",
 
 				"vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
@@ -481,7 +463,7 @@ THREE.ShaderSkin = {
 				"vec4 colDiffuse = texture2D( tDiffuse, vUv );",
 				"colDiffuse *= colDiffuse;",
 
-				"gl_FragColor = gl_FragColor * colDiffuse;",
+				"diffuseColor *= colDiffuse;",
 
 				"mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
 				"vec3 finalNormal = tsb * normalTex;",
@@ -491,12 +473,11 @@ THREE.ShaderSkin = {
 
 				// point lights
 
-				"vec3 specularTotal = vec3( 0.0 );",
+				"vec3 totalDiffuseLight = vec3( 0.0 );",
+				"vec3 totalSpecularLight = vec3( 0.0 );",
 
 				"#if MAX_POINT_LIGHTS > 0",
 
-					"vec4 pointTotal = vec4( vec3( 0.0 ), 1.0 );",
-
 					"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 						"vec3 pointVector = normalize( vPointLight[ i ].xyz );",
@@ -504,10 +485,10 @@ THREE.ShaderSkin = {
 
 						"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
 
-						"pointTotal  += pointDistance * vec4( pointLightColor[ i ], 1.0 ) * ( mColor * pointDiffuseWeight );",
+						"totalDiffuseLight += pointDistance * pointLightColor[ i ] * pointDiffuseWeight;",
 
 						"if ( passID == 1 )",
-							"specularTotal += pointDistance * mSpecular.xyz * pointLightColor[ i ] * KS_Skin_Specular( normal, pointVector, viewPosition, uRoughness, uSpecularBrightness );",
+							"totalSpecularLight += pointDistance * mSpecular.xyz * pointLightColor[ i ] * KS_Skin_Specular( normal, pointVector, viewPosition, uRoughness, uSpecularBrightness );",
 
 					"}",
 
@@ -517,40 +498,27 @@ THREE.ShaderSkin = {
 
 				"#if MAX_DIR_LIGHTS > 0",
 
-					"vec4 dirTotal = vec4( vec3( 0.0 ), 1.0 );",
-
 					"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
 
 						"vec3 dirVector = transformDirection( directionalLightDirection[ i ], viewMatrix );",
 
 						"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
 
-						"dirTotal  += vec4( directionalLightColor[ i ], 1.0 ) * ( mColor * dirDiffuseWeight );",
+						"totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;",
 
 						"if ( passID == 1 )",
-							"specularTotal += mSpecular.xyz * directionalLightColor[ i ] * KS_Skin_Specular( normal, dirVector, viewPosition, uRoughness, uSpecularBrightness );",
+							"totalSpecularLight += mSpecular.xyz * directionalLightColor[ i ] * KS_Skin_Specular( normal, dirVector, viewPosition, uRoughness, uSpecularBrightness );",
 
 					"}",
 
 				"#endif",
 
-				// all lights contribution summation
 
-				"vec4 totalLight = vec4( vec3( 0.0 ), opacity );",
-
-				"#if MAX_DIR_LIGHTS > 0",
-					"totalLight += dirTotal;",
-				"#endif",
-
-				"#if MAX_POINT_LIGHTS > 0",
-					"totalLight += pointTotal;",
-				"#endif",
-
-				"gl_FragColor = gl_FragColor * totalLight;",
+				"outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalSpecularLight );",
 
 				"if ( passID == 0 ) {",
 
-					"gl_FragColor = vec4( sqrt( gl_FragColor.xyz ), gl_FragColor.w );",
+					"outgoingLight = sqrt( outgoingLight );",
 
 				"} else if ( passID == 1 ) {",
 
@@ -558,11 +526,11 @@ THREE.ShaderSkin = {
 
 					"#ifdef VERSION1",
 
-						"vec3 nonblurColor = sqrt( gl_FragColor.xyz );",
+						"vec3 nonblurColor = sqrt(outgoingLight );",
 
 					"#else",
 
-						"vec3 nonblurColor = gl_FragColor.xyz;",
+						"vec3 nonblurColor = outgoingLight;",
 
 					"#endif",
 
@@ -579,20 +547,19 @@ THREE.ShaderSkin = {
 					//"gl_FragColor = vec4( vec3( 0.25, 0.6, 0.8 ) * nonblurColor + vec3( 0.15, 0.25, 0.2 ) * blur1Color + vec3( 0.15, 0.15, 0.0 ) * blur2Color + vec3( 0.45, 0.0, 0.0 ) * blur3Color, gl_FragColor.w );",
 
 
-					"gl_FragColor = vec4( vec3( 0.22,  0.437, 0.635 ) * nonblurColor + ",
+					"outgoingLight = vec3( vec3( 0.22,  0.437, 0.635 ) * nonblurColor + ",
 										 "vec3( 0.101, 0.355, 0.365 ) * blur1Color + ",
 										 "vec3( 0.119, 0.208, 0.0 )   * blur2Color + ",
 										 "vec3( 0.114, 0.0,   0.0 )   * blur3Color + ",
-										 "vec3( 0.444, 0.0,   0.0 )   * blur4Color",
-										 ", gl_FragColor.w );",
+										 "vec3( 0.444, 0.0,   0.0 )   * blur4Color );",
 
-					"gl_FragColor.xyz *= pow( colDiffuse.xyz, vec3( 0.5 ) );",
+					"outgoingLight *= sqrt( colDiffuse.xyz );",
 
-					"gl_FragColor.xyz += ambientLightColor * diffuse * colDiffuse.xyz + specularTotal;",
+					"outgoingLight += ambientLightColor * diffuse * colDiffuse.xyz + totalSpecularLight;",
 
 					"#ifndef VERSION1",
 
-						"gl_FragColor.xyz = sqrt( gl_FragColor.xyz );",
+						"outgoingLight = sqrt( outgoingLight );",
 
 					"#endif",
 
@@ -600,6 +567,8 @@ THREE.ShaderSkin = {
 
 				THREE.ShaderChunk[ "fog_fragment" ],
 
+				"gl_FragColor = vec4( outgoingLight, diffuseColor.a );",	// TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
+
 			"}"
 
 		].join("\n"),
@@ -625,6 +594,7 @@ THREE.ShaderSkin = {
 
 				"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
 				"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
+				"uniform float pointLightDecay[ MAX_POINT_LIGHTS ];",
 
 				"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
 
@@ -632,6 +602,8 @@ THREE.ShaderSkin = {
 
 			"varying vec3 vViewPosition;",
 
+			THREE.ShaderChunk[ "common" ],
+
 			"void main() {",
 
 				"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
@@ -661,14 +633,11 @@ THREE.ShaderSkin = {
 
 						"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
 
-						"float lDistance = 1.0;",
-
-						"if ( pointLightDistance[ i ] > 0.0 )",
-							"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
+						"float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );",
 
 						"lVector = normalize( lVector );",
 
-						"vPointLight[ i ] = vec4( lVector, lDistance );",
+						"vPointLight[ i ] = vec4( lVector, attenuation );",
 
 					"}",
 
@@ -714,6 +683,7 @@ THREE.ShaderSkin = {
 
 				"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
 				"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
+				"uniform float pointLightDecay[ MAX_POINT_LIGHTS ];",
 
 				"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
 
@@ -721,6 +691,8 @@ THREE.ShaderSkin = {
 
 			"varying vec3 vViewPosition;",
 
+			THREE.ShaderChunk[ "common" ],
+
 			"void main() {",
 
 				"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
@@ -750,14 +722,11 @@ THREE.ShaderSkin = {
 
 						"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
 
-						"float lDistance = 1.0;",
-
-						"if ( pointLightDistance[ i ] > 0.0 )",
-							"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
+						"float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );",
 
 						"lVector = normalize( lVector );",
 
-						"vPointLight[ i ] = vec4( lVector, lDistance );",
+						"vPointLight[ i ] = vec4( lVector, attenuation );",
 
 					"}",
 

+ 22 - 52
examples/js/ShaderTerrain.js

@@ -106,6 +106,7 @@ THREE.ShaderTerrain = {
 				"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
 				"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
 				"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
+				"uniform float pointLightDecay[ MAX_POINT_LIGHTS ];",
 
 			"#endif",
 
@@ -117,7 +118,8 @@ THREE.ShaderTerrain = {
 
 			"void main() {",
 
-				"gl_FragColor = vec4( vec3( 1.0 ), opacity );",
+				"vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does
+				"vec4 diffuseColor = vec4( diffuse, opacity );",
 
 				"vec3 specularTex = vec3( 1.0 );",
 
@@ -133,22 +135,18 @@ THREE.ShaderTerrain = {
 					"vec4 colDiffuse1 = texture2D( tDiffuse1, uvOverlay );",
 					"vec4 colDiffuse2 = texture2D( tDiffuse2, uvOverlay );",
 
-					"#ifdef GAMMA_INPUT",
+					"colDiffuse1.xyz = inputToLinear( colDiffuse1.xyz );",
+					"colDiffuse2.xyz = inputToLinear( colDiffuse2.xyz );",
 
-						"colDiffuse1.xyz *= colDiffuse1.xyz;",
-						"colDiffuse2.xyz *= colDiffuse2.xyz;",
-
-					"#endif",
-
-					"gl_FragColor = gl_FragColor * mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
+					"diffuseColor *= mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
 
 				" } else if( enableDiffuse1 ) {",
 
-					"gl_FragColor = gl_FragColor * texture2D( tDiffuse1, uvOverlay );",
+					"diffuseColor *= texture2D( tDiffuse1, uvOverlay );",
 
 				"} else if( enableDiffuse2 ) {",
 
-					"gl_FragColor = gl_FragColor * texture2D( tDiffuse2, uvOverlay );",
+					"diffuseColor *= texture2D( tDiffuse2, uvOverlay );",
 
 				"}",
 
@@ -161,34 +159,31 @@ THREE.ShaderTerrain = {
 				"vec3 normal = normalize( finalNormal );",
 				"vec3 viewPosition = normalize( vViewPosition );",
 
+				"vec3 totalDiffuseLight = vec3( 0.0 );",
+				"vec3 totalSpecularLight = vec3( 0.0 );",
+
 				// point lights
 
 				"#if MAX_POINT_LIGHTS > 0",
 
-					"vec3 pointDiffuse = vec3( 0.0 );",
-					"vec3 pointSpecular = vec3( 0.0 );",
-
 					"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
 
 						"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
 						"vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
 
-						"float lDistance = 1.0;",
-						"if ( pointLightDistance[ i ] > 0.0 )",
-							"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
+						"float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );",
 
 						"lVector = normalize( lVector );",
 
 						"vec3 pointHalfVector = normalize( lVector + viewPosition );",
-						"float pointDistance = lDistance;",
 
 						"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
 						"float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );",
 
 						"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
 
-						"pointDiffuse += pointDistance * pointLightColor[ i ] * diffuse * pointDiffuseWeight;",
-						"pointSpecular += pointDistance * pointLightColor[ i ] * specular * pointSpecularWeight * pointDiffuseWeight;",
+						"totalDiffuseLight += attenuation * pointLightColor[ i ] * pointDiffuseWeight;",
+						"totalSpecularLight += attenuation * pointLightColor[ i ] * specular * pointSpecularWeight * pointDiffuseWeight;",
 
 					"}",
 
@@ -211,8 +206,8 @@ THREE.ShaderTerrain = {
 
 						"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
 
-						"dirDiffuse += directionalLightColor[ i ] * diffuse * dirDiffuseWeight;",
-						"dirSpecular += directionalLightColor[ i ] * specular * dirSpecularWeight * dirDiffuseWeight;",
+						"totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;",
+						"totalSpecularLight += directionalLightColor[ i ] * specular * dirSpecularWeight * dirDiffuseWeight;",
 
 					"}",
 
@@ -223,7 +218,7 @@ THREE.ShaderTerrain = {
 				"#if MAX_HEMI_LIGHTS > 0",
 
 					"vec3 hemiDiffuse  = vec3( 0.0 );",
-					"vec3 hemiSpecular = vec3( 0.0 );" ,
+					"vec3 hemiSpecular = vec3( 0.0 );",
 
 					"for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
 
@@ -234,7 +229,7 @@ THREE.ShaderTerrain = {
 						"float dotProduct = dot( normal, lVector );",
 						"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
 
-						"hemiDiffuse += diffuse * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
+						"totalDiffuseLight += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
 
 						// specular (sky light)
 
@@ -252,45 +247,20 @@ THREE.ShaderTerrain = {
 						"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
 						"hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
 
-						"hemiSpecular += specular * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
+						"totalSpecularLight += specular * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;",
 
 					"}",
 
 				"#endif",
 
-				// all lights contribution summation
-
-				"vec3 totalDiffuse = vec3( 0.0 );",
-				"vec3 totalSpecular = vec3( 0.0 );",
-
-				"#if MAX_DIR_LIGHTS > 0",
-
-					"totalDiffuse += dirDiffuse;",
-					"totalSpecular += dirSpecular;",
-
-				"#endif",
-
-				"#if MAX_HEMI_LIGHTS > 0",
-
-					"totalDiffuse += hemiDiffuse;",
-					"totalSpecular += hemiSpecular;",
-
-				"#endif",
-
-				"#if MAX_POINT_LIGHTS > 0",
-
-					"totalDiffuse += pointDiffuse;",
-					"totalSpecular += pointSpecular;",
-
-				"#endif",
-
-				//"gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * diffuse ) + totalSpecular;",
-				"gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * diffuse + totalSpecular );",
+				"outgoingLight += diffuseColor.xyz * ( totalDiffuseLight + ambientLightColor + totalSpecularLight );",
 
 				THREE.ShaderChunk[ "shadowmap_fragment" ],
 				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
 				THREE.ShaderChunk[ "fog_fragment" ],
 
+				"gl_FragColor = vec4( outgoingLight, diffuseColor.a );",	// TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
+
 			"}"
 
 		].join("\n"),

+ 233 - 233
examples/js/SimplexNoise.js

@@ -13,190 +13,190 @@
  */
 var SimplexNoise = function(r) {
 	if (r == undefined) r = Math;
-  this.grad3 = [[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0], 
-                                 [1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1], 
-                                 [0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]]; 
+	this.grad3 = [[ 1,1,0 ],[ -1,1,0 ],[ 1,-1,0 ],[ -1,-1,0 ], 
+                                 [ 1,0,1 ],[ -1,0,1 ],[ 1,0,-1 ],[ -1,0,-1 ], 
+                                 [ 0,1,1 ],[ 0,-1,1 ],[ 0,1,-1 ],[ 0,-1,-1 ]]; 
 
-  this.grad4 = [[0,1,1,1], [0,1,1,-1], [0,1,-1,1], [0,1,-1,-1],
-	     [0,-1,1,1], [0,-1,1,-1], [0,-1,-1,1], [0,-1,-1,-1],
-	     [1,0,1,1], [1,0,1,-1], [1,0,-1,1], [1,0,-1,-1],
-	     [-1,0,1,1], [-1,0,1,-1], [-1,0,-1,1], [-1,0,-1,-1],
-	     [1,1,0,1], [1,1,0,-1], [1,-1,0,1], [1,-1,0,-1],
-	     [-1,1,0,1], [-1,1,0,-1], [-1,-1,0,1], [-1,-1,0,-1],
-	     [1,1,1,0], [1,1,-1,0], [1,-1,1,0], [1,-1,-1,0],
-	     [-1,1,1,0], [-1,1,-1,0], [-1,-1,1,0], [-1,-1,-1,0]];
+	this.grad4 = [[ 0,1,1,1 ], [ 0,1,1,-1 ], [ 0,1,-1,1 ], [ 0,1,-1,-1 ],
+	     [ 0,-1,1,1 ], [ 0,-1,1,-1 ], [ 0,-1,-1,1 ], [ 0,-1,-1,-1 ],
+	     [ 1,0,1,1 ], [ 1,0,1,-1 ], [ 1,0,-1,1 ], [ 1,0,-1,-1 ],
+	     [ -1,0,1,1 ], [ -1,0,1,-1 ], [ -1,0,-1,1 ], [ -1,0,-1,-1 ],
+	     [ 1,1,0,1 ], [ 1,1,0,-1 ], [ 1,-1,0,1 ], [ 1,-1,0,-1 ],
+	     [ -1,1,0,1 ], [ -1,1,0,-1 ], [ -1,-1,0,1 ], [ -1,-1,0,-1 ],
+	     [ 1,1,1,0 ], [ 1,1,-1,0 ], [ 1,-1,1,0 ], [ 1,-1,-1,0 ],
+	     [ -1,1,1,0 ], [ -1,1,-1,0 ], [ -1,-1,1,0 ], [ -1,-1,-1,0 ]];
 
-  this.p = [];
-  for (var i=0; i<256; i++) {
-	  this.p[i] = Math.floor(r.random()*256);
-  }
+	this.p = [];
+	for (var i = 0; i < 256; i ++) {
+		this.p[i] = Math.floor(r.random() * 256);
+	}
   // To remove the need for index wrapping, double the permutation table length 
-  this.perm = []; 
-  for(var i=0; i<512; i++) {
-		this.perm[i]=this.p[i & 255];
+	this.perm = []; 
+	for (var i = 0; i < 512; i ++) {
+		this.perm[i] = this.p[i & 255];
 	} 
 
   // A lookup table to traverse the simplex around a given point in 4D. 
   // Details can be found where this table is used, in the 4D noise method. 
-  this.simplex = [ 
-    [0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0], 
-    [0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0], 
-    [0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0], 
-    [1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0], 
-    [1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0], 
-    [0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0], 
-    [2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0], 
-    [2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]]; 
+	this.simplex = [ 
+    [ 0,1,2,3 ],[ 0,1,3,2 ],[ 0,0,0,0 ],[ 0,2,3,1 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 1,2,3,0 ], 
+    [ 0,2,1,3 ],[ 0,0,0,0 ],[ 0,3,1,2 ],[ 0,3,2,1 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 1,3,2,0 ], 
+    [ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ], 
+    [ 1,2,0,3 ],[ 0,0,0,0 ],[ 1,3,0,2 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 2,3,0,1 ],[ 2,3,1,0 ], 
+    [ 1,0,2,3 ],[ 1,0,3,2 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 2,0,3,1 ],[ 0,0,0,0 ],[ 2,1,3,0 ], 
+    [ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ], 
+    [ 2,0,1,3 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 3,0,1,2 ],[ 3,0,2,1 ],[ 0,0,0,0 ],[ 3,1,2,0 ], 
+    [ 2,1,0,3 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 0,0,0,0 ],[ 3,1,0,2 ],[ 0,0,0,0 ],[ 3,2,0,1 ],[ 3,2,1,0 ]]; 
 };
 
 SimplexNoise.prototype.dot = function(g, x, y) { 
-	return g[0]*x + g[1]*y;
+	return g[0] * x + g[1] * y;
 };
 
 SimplexNoise.prototype.dot3 = function(g, x, y, z) {
-  return g[0]*x + g[1]*y + g[2]*z; 
+	return g[0] * x + g[1] * y + g[2] * z; 
 }
 
 SimplexNoise.prototype.dot4 = function(g, x, y, z, w) {
-  return g[0]*x + g[1]*y + g[2]*z + g[3]*w;
+	return g[0] * x + g[1] * y + g[2] * z + g[3] * w;
 };
 
 SimplexNoise.prototype.noise = function(xin, yin) { 
-  var n0, n1, n2; // Noise contributions from the three corners 
+	var n0, n1, n2; // Noise contributions from the three corners 
   // Skew the input space to determine which simplex cell we're in 
-  var F2 = 0.5*(Math.sqrt(3.0)-1.0); 
-  var s = (xin+yin)*F2; // Hairy factor for 2D 
-  var i = Math.floor(xin+s); 
-  var j = Math.floor(yin+s); 
-  var G2 = (3.0-Math.sqrt(3.0))/6.0; 
-  var t = (i+j)*G2; 
-  var X0 = i-t; // Unskew the cell origin back to (x,y) space 
-  var Y0 = j-t; 
-  var x0 = xin-X0; // The x,y distances from the cell origin 
-  var y0 = yin-Y0; 
+	var F2 = 0.5 * (Math.sqrt(3.0) - 1.0); 
+	var s = (xin + yin) * F2; // Hairy factor for 2D 
+	var i = Math.floor(xin + s); 
+	var j = Math.floor(yin + s); 
+	var G2 = (3.0 - Math.sqrt(3.0)) / 6.0; 
+	var t = (i + j) * G2; 
+	var X0 = i - t; // Unskew the cell origin back to (x,y) space 
+	var Y0 = j - t; 
+	var x0 = xin - X0; // The x,y distances from the cell origin 
+	var y0 = yin - Y0; 
   // For the 2D case, the simplex shape is an equilateral triangle. 
   // Determine which simplex we are in. 
-  var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords 
-  if(x0>y0) {i1=1; j1=0;} // lower triangle, XY order: (0,0)->(1,0)->(1,1) 
-  else {i1=0; j1=1;}      // upper triangle, YX order: (0,0)->(0,1)->(1,1) 
+	var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords 
+	if (x0 > y0) {i1 = 1; j1 = 0;} // lower triangle, XY order: (0,0)->(1,0)->(1,1) 
+	else {i1 = 0; j1 = 1;}      // upper triangle, YX order: (0,0)->(0,1)->(1,1) 
   // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and 
   // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where 
   // c = (3-sqrt(3))/6 
-  var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords 
-  var y1 = y0 - j1 + G2; 
-  var x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords 
-  var y2 = y0 - 1.0 + 2.0 * G2; 
+	var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords 
+	var y1 = y0 - j1 + G2; 
+	var x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords 
+	var y2 = y0 - 1.0 + 2.0 * G2; 
   // Work out the hashed gradient indices of the three simplex corners 
-  var ii = i & 255; 
-  var jj = j & 255; 
-  var gi0 = this.perm[ii+this.perm[jj]] % 12; 
-  var gi1 = this.perm[ii+i1+this.perm[jj+j1]] % 12; 
-  var gi2 = this.perm[ii+1+this.perm[jj+1]] % 12; 
+	var ii = i & 255; 
+	var jj = j & 255; 
+	var gi0 = this.perm[ii + this.perm[jj]] % 12; 
+	var gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12; 
+	var gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12; 
   // Calculate the contribution from the three corners 
-  var t0 = 0.5 - x0*x0-y0*y0; 
-  if(t0<0) n0 = 0.0; 
-  else { 
-    t0 *= t0; 
-    n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);  // (x,y) of grad3 used for 2D gradient 
-  } 
-  var t1 = 0.5 - x1*x1-y1*y1; 
-  if(t1<0) n1 = 0.0; 
-  else { 
-    t1 *= t1; 
-    n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1); 
-  }
-  var t2 = 0.5 - x2*x2-y2*y2; 
-  if(t2<0) n2 = 0.0; 
-  else { 
-    t2 *= t2; 
-    n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2); 
-  } 
+	var t0 = 0.5 - x0 * x0 - y0 * y0; 
+	if (t0 < 0) n0 = 0.0; 
+	else { 
+		t0 *= t0; 
+		n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);  // (x,y) of grad3 used for 2D gradient 
+	} 
+	var t1 = 0.5 - x1 * x1 - y1 * y1; 
+	if (t1 < 0) n1 = 0.0; 
+	else { 
+		t1 *= t1; 
+		n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1); 
+	}
+	var t2 = 0.5 - x2 * x2 - y2 * y2; 
+	if (t2 < 0) n2 = 0.0; 
+	else { 
+		t2 *= t2; 
+		n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2); 
+	} 
   // Add contributions from each corner to get the final noise value. 
   // The result is scaled to return values in the interval [-1,1]. 
-  return 70.0 * (n0 + n1 + n2); 
+	return 70.0 * (n0 + n1 + n2); 
 };
 
 // 3D simplex noise 
 SimplexNoise.prototype.noise3d = function(xin, yin, zin) { 
-  var n0, n1, n2, n3; // Noise contributions from the four corners 
+	var n0, n1, n2, n3; // Noise contributions from the four corners 
   // Skew the input space to determine which simplex cell we're in 
-  var F3 = 1.0/3.0; 
-  var s = (xin+yin+zin)*F3; // Very nice and simple skew factor for 3D 
-  var i = Math.floor(xin+s); 
-  var j = Math.floor(yin+s); 
-  var k = Math.floor(zin+s); 
-  var G3 = 1.0/6.0; // Very nice and simple unskew factor, too 
-  var t = (i+j+k)*G3; 
-  var X0 = i-t; // Unskew the cell origin back to (x,y,z) space 
-  var Y0 = j-t; 
-  var Z0 = k-t; 
-  var x0 = xin-X0; // The x,y,z distances from the cell origin 
-  var y0 = yin-Y0; 
-  var z0 = zin-Z0; 
+	var F3 = 1.0 / 3.0; 
+	var s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D 
+	var i = Math.floor(xin + s); 
+	var j = Math.floor(yin + s); 
+	var k = Math.floor(zin + s); 
+	var G3 = 1.0 / 6.0; // Very nice and simple unskew factor, too 
+	var t = (i + j + k) * G3; 
+	var X0 = i - t; // Unskew the cell origin back to (x,y,z) space 
+	var Y0 = j - t; 
+	var Z0 = k - t; 
+	var x0 = xin - X0; // The x,y,z distances from the cell origin 
+	var y0 = yin - Y0; 
+	var z0 = zin - Z0; 
   // For the 3D case, the simplex shape is a slightly irregular tetrahedron. 
   // Determine which simplex we are in. 
-  var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords 
-  var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords 
-  if(x0>=y0) { 
-    if(y0>=z0) 
-      { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } // X Y Z order 
-      else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } // X Z Y order 
-      else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } // Z X Y order 
-    } 
-  else { // x0<y0 
-    if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } // Z Y X order 
-    else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } // Y Z X order 
-    else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } // Y X Z order 
-  } 
+	var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords 
+	var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords 
+	if (x0 >= y0) { 
+		if (y0 >= z0) 
+      { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0; } // X Y Z order 
+      else if (x0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; } // X Z Y order 
+		else { i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; } // Z X Y order 
+	} 
+	else { // x0<y0 
+		if (y0 < z0) { i1 = 0; j1 = 0; k1 = 1; i2 = 0; j2 = 1; k2 = 1; } // Z Y X order 
+    else if (x0 < z0) { i1 = 0; j1 = 1; k1 = 0; i2 = 0; j2 = 1; k2 = 1; } // Y Z X order 
+		else { i1 = 0; j1 = 1; k1 = 0; i2 = 1; j2 = 1; k2 = 0; } // Y X Z order 
+	} 
   // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), 
   // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and 
   // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where 
   // c = 1/6.
-  var x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords 
-  var y1 = y0 - j1 + G3; 
-  var z1 = z0 - k1 + G3; 
-  var x2 = x0 - i2 + 2.0*G3; // Offsets for third corner in (x,y,z) coords 
-  var y2 = y0 - j2 + 2.0*G3; 
-  var z2 = z0 - k2 + 2.0*G3; 
-  var x3 = x0 - 1.0 + 3.0*G3; // Offsets for last corner in (x,y,z) coords 
-  var y3 = y0 - 1.0 + 3.0*G3; 
-  var z3 = z0 - 1.0 + 3.0*G3; 
+	var x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords 
+	var y1 = y0 - j1 + G3; 
+	var z1 = z0 - k1 + G3; 
+	var x2 = x0 - i2 + 2.0 * G3; // Offsets for third corner in (x,y,z) coords 
+	var y2 = y0 - j2 + 2.0 * G3; 
+	var z2 = z0 - k2 + 2.0 * G3; 
+	var x3 = x0 - 1.0 + 3.0 * G3; // Offsets for last corner in (x,y,z) coords 
+	var y3 = y0 - 1.0 + 3.0 * G3; 
+	var z3 = z0 - 1.0 + 3.0 * G3; 
   // Work out the hashed gradient indices of the four simplex corners 
-  var ii = i & 255; 
-  var jj = j & 255; 
-  var kk = k & 255; 
-  var gi0 = this.perm[ii+this.perm[jj+this.perm[kk]]] % 12; 
-  var gi1 = this.perm[ii+i1+this.perm[jj+j1+this.perm[kk+k1]]] % 12; 
-  var gi2 = this.perm[ii+i2+this.perm[jj+j2+this.perm[kk+k2]]] % 12; 
-  var gi3 = this.perm[ii+1+this.perm[jj+1+this.perm[kk+1]]] % 12; 
+	var ii = i & 255; 
+	var jj = j & 255; 
+	var kk = k & 255; 
+	var gi0 = this.perm[ii + this.perm[jj + this.perm[kk]]] % 12; 
+	var gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1]]] % 12; 
+	var gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2]]] % 12; 
+	var gi3 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1]]] % 12; 
   // Calculate the contribution from the four corners 
-  var t0 = 0.6 - x0*x0 - y0*y0 - z0*z0; 
-  if(t0<0) n0 = 0.0; 
-  else { 
-    t0 *= t0; 
-    n0 = t0 * t0 * this.dot3(this.grad3[gi0], x0, y0, z0); 
-  }
-  var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1; 
-  if(t1<0) n1 = 0.0; 
-  else { 
-    t1 *= t1; 
-    n1 = t1 * t1 * this.dot3(this.grad3[gi1], x1, y1, z1); 
-  } 
-  var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2; 
-  if(t2<0) n2 = 0.0; 
-  else { 
-    t2 *= t2; 
-    n2 = t2 * t2 * this.dot3(this.grad3[gi2], x2, y2, z2); 
-  } 
-  var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3; 
-  if(t3<0) n3 = 0.0; 
-  else { 
-    t3 *= t3; 
-    n3 = t3 * t3 * this.dot3(this.grad3[gi3], x3, y3, z3); 
-  } 
+	var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0; 
+	if (t0 < 0) n0 = 0.0; 
+	else { 
+		t0 *= t0; 
+		n0 = t0 * t0 * this.dot3(this.grad3[gi0], x0, y0, z0); 
+	}
+	var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1; 
+	if (t1 < 0) n1 = 0.0; 
+	else { 
+		t1 *= t1; 
+		n1 = t1 * t1 * this.dot3(this.grad3[gi1], x1, y1, z1); 
+	} 
+	var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2; 
+	if (t2 < 0) n2 = 0.0; 
+	else { 
+		t2 *= t2; 
+		n2 = t2 * t2 * this.dot3(this.grad3[gi2], x2, y2, z2); 
+	} 
+	var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3; 
+	if (t3 < 0) n3 = 0.0; 
+	else { 
+		t3 *= t3; 
+		n3 = t3 * t3 * this.dot3(this.grad3[gi3], x3, y3, z3); 
+	} 
   // Add contributions from each corner to get the final noise value. 
   // The result is scaled to stay just inside [-1,1] 
-  return 32.0*(n0 + n1 + n2 + n3); 
+	return 32.0 * (n0 + n1 + n2 + n3); 
 };
 
 // 4D simplex noise
@@ -207,24 +207,24 @@ SimplexNoise.prototype.noise4d = function( x, y, z, w ) {
 	var perm = this.perm;
 	
    // The skewing and unskewing factors are hairy again for the 4D case
-   var F4 = (Math.sqrt(5.0)-1.0)/4.0;
-   var G4 = (5.0-Math.sqrt(5.0))/20.0;
-   var n0, n1, n2, n3, n4; // Noise contributions from the five corners
+	var F4 = (Math.sqrt(5.0) - 1.0) / 4.0;
+	var G4 = (5.0 - Math.sqrt(5.0)) / 20.0;
+	var n0, n1, n2, n3, n4; // Noise contributions from the five corners
    // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
-   var s = (x + y + z + w) * F4; // Factor for 4D skewing
-   var i = Math.floor(x + s);
-   var j = Math.floor(y + s);
-   var k = Math.floor(z + s);
-   var l = Math.floor(w + s);
-   var t = (i + j + k + l) * G4; // Factor for 4D unskewing
-   var X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
-   var Y0 = j - t;
-   var Z0 = k - t;
-   var W0 = l - t;
-   var x0 = x - X0;  // The x,y,z,w distances from the cell origin
-   var y0 = y - Y0;
-   var z0 = z - Z0;
-   var w0 = w - W0;
+	var s = (x + y + z + w) * F4; // Factor for 4D skewing
+	var i = Math.floor(x + s);
+	var j = Math.floor(y + s);
+	var k = Math.floor(z + s);
+	var l = Math.floor(w + s);
+	var t = (i + j + k + l) * G4; // Factor for 4D unskewing
+	var X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
+	var Y0 = j - t;
+	var Z0 = k - t;
+	var W0 = l - t;
+	var x0 = x - X0;  // The x,y,z,w distances from the cell origin
+	var y0 = y - Y0;
+	var z0 = z - Z0;
+	var w0 = w - W0;
 
    // For the 4D case, the simplex is a 4D shape I won't even try to describe.
    // To find out which of the 24 possible simplices we're in, we need to
@@ -234,91 +234,91 @@ SimplexNoise.prototype.noise4d = function( x, y, z, w ) {
    // First, six pair-wise comparisons are performed between each possible pair
    // of the four coordinates, and the results are used to add up binary bits
    // for an integer index.
-   var c1 = (x0 > y0) ? 32 : 0;
-   var c2 = (x0 > z0) ? 16 : 0;
-   var c3 = (y0 > z0) ? 8 : 0;
-   var c4 = (x0 > w0) ? 4 : 0;
-   var c5 = (y0 > w0) ? 2 : 0;
-   var c6 = (z0 > w0) ? 1 : 0;
-   var c = c1 + c2 + c3 + c4 + c5 + c6;
-   var i1, j1, k1, l1; // The integer offsets for the second simplex corner
-   var i2, j2, k2, l2; // The integer offsets for the third simplex corner
-   var i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
+	var c1 = (x0 > y0) ? 32 : 0;
+	var c2 = (x0 > z0) ? 16 : 0;
+	var c3 = (y0 > z0) ? 8 : 0;
+	var c4 = (x0 > w0) ? 4 : 0;
+	var c5 = (y0 > w0) ? 2 : 0;
+	var c6 = (z0 > w0) ? 1 : 0;
+	var c = c1 + c2 + c3 + c4 + c5 + c6;
+	var i1, j1, k1, l1; // The integer offsets for the second simplex corner
+	var i2, j2, k2, l2; // The integer offsets for the third simplex corner
+	var i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
    // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order.
    // Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w
    // impossible. Only the 24 indices which have non-zero entries make any sense.
    // We use a thresholding to set the coordinates in turn from the largest magnitude.
    // The number 3 in the "simplex" array is at the position of the largest coordinate.
-   i1 = simplex[c][0]>=3 ? 1 : 0;
-   j1 = simplex[c][1]>=3 ? 1 : 0;
-   k1 = simplex[c][2]>=3 ? 1 : 0;
-   l1 = simplex[c][3]>=3 ? 1 : 0;
+	i1 = simplex[c][0] >= 3 ? 1 : 0;
+	j1 = simplex[c][1] >= 3 ? 1 : 0;
+	k1 = simplex[c][2] >= 3 ? 1 : 0;
+	l1 = simplex[c][3] >= 3 ? 1 : 0;
    // The number 2 in the "simplex" array is at the second largest coordinate.
-   i2 = simplex[c][0]>=2 ? 1 : 0;
-   j2 = simplex[c][1]>=2 ? 1 : 0;    k2 = simplex[c][2]>=2 ? 1 : 0;
-   l2 = simplex[c][3]>=2 ? 1 : 0;
+	i2 = simplex[c][0] >= 2 ? 1 : 0;
+	j2 = simplex[c][1] >= 2 ? 1 : 0;    k2 = simplex[c][2] >= 2 ? 1 : 0;
+	l2 = simplex[c][3] >= 2 ? 1 : 0;
    // The number 1 in the "simplex" array is at the second smallest coordinate.
-   i3 = simplex[c][0]>=1 ? 1 : 0;
-   j3 = simplex[c][1]>=1 ? 1 : 0;
-   k3 = simplex[c][2]>=1 ? 1 : 0;
-   l3 = simplex[c][3]>=1 ? 1 : 0;
+	i3 = simplex[c][0] >= 1 ? 1 : 0;
+	j3 = simplex[c][1] >= 1 ? 1 : 0;
+	k3 = simplex[c][2] >= 1 ? 1 : 0;
+	l3 = simplex[c][3] >= 1 ? 1 : 0;
    // The fifth corner has all coordinate offsets = 1, so no need to look that up.
-   var x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
-   var y1 = y0 - j1 + G4;
-   var z1 = z0 - k1 + G4;
-   var w1 = w0 - l1 + G4;
-   var x2 = x0 - i2 + 2.0*G4; // Offsets for third corner in (x,y,z,w) coords
-   var y2 = y0 - j2 + 2.0*G4;
-   var z2 = z0 - k2 + 2.0*G4;
-   var w2 = w0 - l2 + 2.0*G4;
-   var x3 = x0 - i3 + 3.0*G4; // Offsets for fourth corner in (x,y,z,w) coords
-   var y3 = y0 - j3 + 3.0*G4;
-   var z3 = z0 - k3 + 3.0*G4;
-   var w3 = w0 - l3 + 3.0*G4;
-   var x4 = x0 - 1.0 + 4.0*G4; // Offsets for last corner in (x,y,z,w) coords
-   var y4 = y0 - 1.0 + 4.0*G4;
-   var z4 = z0 - 1.0 + 4.0*G4;
-   var w4 = w0 - 1.0 + 4.0*G4;
+	var x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
+	var y1 = y0 - j1 + G4;
+	var z1 = z0 - k1 + G4;
+	var w1 = w0 - l1 + G4;
+	var x2 = x0 - i2 + 2.0 * G4; // Offsets for third corner in (x,y,z,w) coords
+	var y2 = y0 - j2 + 2.0 * G4;
+	var z2 = z0 - k2 + 2.0 * G4;
+	var w2 = w0 - l2 + 2.0 * G4;
+	var x3 = x0 - i3 + 3.0 * G4; // Offsets for fourth corner in (x,y,z,w) coords
+	var y3 = y0 - j3 + 3.0 * G4;
+	var z3 = z0 - k3 + 3.0 * G4;
+	var w3 = w0 - l3 + 3.0 * G4;
+	var x4 = x0 - 1.0 + 4.0 * G4; // Offsets for last corner in (x,y,z,w) coords
+	var y4 = y0 - 1.0 + 4.0 * G4;
+	var z4 = z0 - 1.0 + 4.0 * G4;
+	var w4 = w0 - 1.0 + 4.0 * G4;
    // Work out the hashed gradient indices of the five simplex corners
-   var ii = i & 255;
-   var jj = j & 255;
-   var kk = k & 255;
-   var ll = l & 255;
-   var gi0 = perm[ii+perm[jj+perm[kk+perm[ll]]]] % 32;
-   var gi1 = perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]] % 32;
-   var gi2 = perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]] % 32;
-   var gi3 = perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]] % 32;
-   var gi4 = perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]] % 32;
+	var ii = i & 255;
+	var jj = j & 255;
+	var kk = k & 255;
+	var ll = l & 255;
+	var gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32;
+	var gi1 = perm[ii + i1 + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]] % 32;
+	var gi2 = perm[ii + i2 + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]] % 32;
+	var gi3 = perm[ii + i3 + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]] % 32;
+	var gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
    // Calculate the contribution from the five corners
-   var t0 = 0.6 - x0*x0 - y0*y0 - z0*z0 - w0*w0;
-   if(t0<0) n0 = 0.0;
-   else {
-     t0 *= t0;
-     n0 = t0 * t0 * this.dot4(grad4[gi0], x0, y0, z0, w0);
-   }
-  var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1 - w1*w1;
-   if(t1<0) n1 = 0.0;
-   else {
-     t1 *= t1;
-     n1 = t1 * t1 * this.dot4(grad4[gi1], x1, y1, z1, w1);
-   }
-  var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2 - w2*w2;
-   if(t2<0) n2 = 0.0;
-   else {
-     t2 *= t2;
-     n2 = t2 * t2 * this.dot4(grad4[gi2], x2, y2, z2, w2);
-   }   var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3 - w3*w3;
-   if(t3<0) n3 = 0.0;
-   else {
-     t3 *= t3;
-     n3 = t3 * t3 * this.dot4(grad4[gi3], x3, y3, z3, w3);
-   }
-  var t4 = 0.6 - x4*x4 - y4*y4 - z4*z4 - w4*w4;
-   if(t4<0) n4 = 0.0;
-   else {
-     t4 *= t4;
-     n4 = t4 * t4 * this.dot4(grad4[gi4], x4, y4, z4, w4);
-   }
+	var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
+	if (t0 < 0) n0 = 0.0;
+	else {
+		t0 *= t0;
+		n0 = t0 * t0 * this.dot4(grad4[gi0], x0, y0, z0, w0);
+	}
+	var t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
+	if (t1 < 0) n1 = 0.0;
+	else {
+		t1 *= t1;
+		n1 = t1 * t1 * this.dot4(grad4[gi1], x1, y1, z1, w1);
+	}
+	var t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
+	if (t2 < 0) n2 = 0.0;
+	else {
+		t2 *= t2;
+		n2 = t2 * t2 * this.dot4(grad4[gi2], x2, y2, z2, w2);
+	}   var t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
+	if (t3 < 0) n3 = 0.0;
+	else {
+		t3 *= t3;
+		n3 = t3 * t3 * this.dot4(grad4[gi3], x3, y3, z3, w3);
+	}
+	var t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
+	if (t4 < 0) n4 = 0.0;
+	else {
+		t4 *= t4;
+		n4 = t4 * t4 * this.dot4(grad4[gi4], x4, y4, z4, w4);
+	}
    // Sum up and scale the result to cover the range [-1,1]
-   return 27.0 * (n0 + n1 + n2 + n3 + n4);
+	return 27.0 * (n0 + n1 + n2 + n3 + n4);
 };

+ 2 - 2
examples/js/SimulationRenderer.js

@@ -19,12 +19,12 @@ function SimulationRenderer(WIDTH, renderer) {
 	// Init RTT stuff
 	gl = renderer.getContext();
 
-	if( !gl.getExtension( "OES_texture_float" )) {
+	if ( !gl.getExtension( "OES_texture_float" )) {
 		alert( "No OES_texture_float support for float textures!" );
 		return;
 	}
 
-	if( gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) == 0) {
+	if ( gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) == 0) {
 		alert( "No support for vertex shader textures!" );
 		return;
 	}

+ 16 - 23
examples/js/SkyShader.js

@@ -1,16 +1,16 @@
 /**
  * @author zz85 / https://github.com/zz85
- * 
- * Based on "A Practical Analytic Model for Daylight" 
+ *
+ * Based on "A Practical Analytic Model for Daylight"
  * aka The Preetham Model, the de facto standard analytic skydome model
  * http://www.cs.utah.edu/~shirley/papers/sunsky/sunsky.pdf
- * 
+ *
  * First implemented by Simon Wallner
  * http://www.simonwallner.at/projects/atmospheric-scattering
- * 
+ *
  * Improved by Martin Upitis
  * http://blenderartists.org/forum/showthread.php?245954-preethams-sky-impementation-HDR
- * 
+ *
  * Three.js integration by zz85 http://twitter.com/blurspline
 */
 
@@ -30,13 +30,11 @@ THREE.ShaderLib['sky'] = {
 	vertexShader: [
 
 		"varying vec3 vWorldPosition;",
-		"varying vec2 vUv;",
 
 		"void main() {",
 
 			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
 			"vWorldPosition = worldPosition.xyz;",
-			"vUv = uv;",
 
 			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 
@@ -46,12 +44,9 @@ THREE.ShaderLib['sky'] = {
 
 	fragmentShader: [
 
-
 		"uniform sampler2D skySampler;",
 		"uniform vec3 sunPosition;",
 		"varying vec3 vWorldPosition;",
-		"varying vec2 vUv;",
-
 
 		"vec3 cameraPos = vec3(0., 0., 0.);",
 		"// uniform sampler2D sDiffuse;",
@@ -67,7 +62,6 @@ THREE.ShaderLib['sky'] = {
 		"uniform float mieCoefficient;",
 		"uniform float mieDirectionalG;",
 
-
 		"vec3 sunDirection = normalize(sunPosition);",
 		"float reileighCoefficient = reileigh;",
 
@@ -165,9 +159,9 @@ THREE.ShaderLib['sky'] = {
 			"// luminance =  1.0 ;// vWorldPosition.y / 450000. + 0.5; //sunPosition.y / 450000. * 1. + 0.5;",
 
 			 "// gl_FragColor = vec4(sunfade, sunfade, sunfade, 1.0);",
-			
+
 			"reileighCoefficient = reileighCoefficient - (1.0* (1.0-sunfade));",
-			
+
 			"float sunE = sunIntensity(dot(sunDirection, up));",
 
 			"// extinction (absorbtion + out scattering) ",
@@ -210,7 +204,7 @@ THREE.ShaderLib['sky'] = {
 			"vec2 uv = vec2(phi, theta) / vec2(2.0*pi, pi) + vec2(0.5, 0.0);",
 			"// vec3 L0 = texture2D(skySampler, uv).rgb+0.1 * Fex;",
 			"vec3 L0 = vec3(0.1) * Fex;",
-			
+
 			"// composition + solar disc",
 			"//if (cosTheta > sunAngularDiameterCos)",
 			"float sundisk = smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);",
@@ -219,25 +213,25 @@ THREE.ShaderLib['sky'] = {
 
 
 			"vec3 whiteScale = 1.0/Uncharted2Tonemap(vec3(W));",
-			
+
 			"vec3 texColor = (Lin+L0);   ",
 			"texColor *= 0.04 ;",
 			"texColor += vec3(0.0,0.001,0.0025)*0.3;",
-			
+
 			"float g_fMaxLuminance = 1.0;",
 			"float fLumScaled = 0.1 / luminance;     ",
 			"float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (g_fMaxLuminance * g_fMaxLuminance)))) / (1.0 + fLumScaled); ",
 
 			"float ExposureBias = fLumCompressed;",
-		   
+
 			"vec3 curr = Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);",
 			"vec3 color = curr*whiteScale;",
 
 			"vec3 retColor = pow(color,vec3(1.0/(1.2+(1.2*sunfade))));",
 
-			
+
 			"gl_FragColor.rgb = retColor;",
-				
+
 			"gl_FragColor.a = 1.0;",
 		"}",
 
@@ -250,9 +244,9 @@ THREE.Sky = function () {
 	var skyShader = THREE.ShaderLib[ "sky" ];
 	var skyUniforms = THREE.UniformsUtils.clone( skyShader.uniforms );
 
-	var skyMat = new THREE.ShaderMaterial( { 
-		fragmentShader: skyShader.fragmentShader, 
-		vertexShader: skyShader.vertexShader, 
+	var skyMat = new THREE.ShaderMaterial( {
+		fragmentShader: skyShader.fragmentShader,
+		vertexShader: skyShader.vertexShader,
 		uniforms: skyUniforms,
 		side: THREE.BackSide
 	} );
@@ -265,5 +259,4 @@ THREE.Sky = function () {
 	this.mesh = skyMesh;
 	this.uniforms = skyUniforms;
 
-
 };

+ 154 - 154
examples/js/Sparks.js

@@ -19,18 +19,18 @@ var SPARKS = {};
 
 SPARKS.Emitter = function (counter) {
 
-    this._counter = counter ? counter : new SPARKS.SteadyCounter(10); // provides number of particles to produce
+	this._counter = counter ? counter : new SPARKS.SteadyCounter(10); // provides number of particles to produce
 
-    this._particles = [];
+	this._particles = [];
 
 
-    this._initializers = []; // use for creation of particles
-    this._actions = [];     // uses action to update particles
-    this._activities = [];  //  not supported yet
+	this._initializers = []; // use for creation of particles
+	this._actions = [];     // uses action to update particles
+	this._activities = [];  //  not supported yet
 
-    this._handlers = [];
+	this._handlers = [];
 
-    this.callbacks = {};
+	this.callbacks = {};
 };
 
 
@@ -77,14 +77,14 @@ SPARKS.Emitter.prototype = {
 				elapsed = maxBlock;
 			}
 
-			while(elapsed >= emitter._TIMESTEP) {
+			while (elapsed >= emitter._TIMESTEP) {
 				emitter.update(emitter._TIMESTEP / 1000);
 				elapsed -= emitter._TIMESTEP;
 			}
 			emitter._lastTime = time - elapsed;
 
 		} else {
-			emitter.update(elapsed/1000);
+			emitter.update(elapsed / 1000);
 			emitter._lastTime = time;
 		}
 
@@ -99,108 +99,108 @@ SPARKS.Emitter.prototype = {
 	// Update particle engine in seconds, not milliseconds
     update: function(time) {
 
-		var i, j;
-        var len = this._counter.updateEmitter( this, time );
+	var i, j;
+	var len = this._counter.updateEmitter( this, time );
 
         // Create particles
-        for( i = 0; i < len; i++ ) {
-            this.createParticle();
-        }
+	for ( i = 0; i < len; i ++ ) {
+		this.createParticle();
+	}
 
         // Update activities
-        len = this._activities.length;
-        for ( i = 0; i < len; i++ )
+	len = this._activities.length;
+	for ( i = 0; i < len; i ++ )
         {
-            this._activities[i].update( this, time );
-        }
+		this._activities[i].update( this, time );
+	}
 
 
-        len = this._actions.length;
+	len = this._actions.length;
 
-		var particle;
-		var action;
-        var len2 = this._particles.length;
+	var particle;
+	var action;
+	var len2 = this._particles.length;
 
-        for( j = 0; j < len; j++ )
+	for ( j = 0; j < len; j ++ )
         {
-            action = this._actions[j];
-            for ( i = 0; i < len2; ++i )
+		action = this._actions[j];
+		for ( i = 0; i < len2; ++ i )
             {
-                particle = this._particles[i];
-                action.update( this, particle, time );
-            }
-        }
+			particle = this._particles[i];
+			action.update( this, particle, time );
+		}
+	}
 
 
         // remove dead particles
-        for ( i = len2; i--; )
+	for ( i = len2; i --; )
         {
-            particle = this._particles[i];
-            if ( particle.isDead )
+		particle = this._particles[i];
+		if ( particle.isDead )
             {
                 //particle =
-				this._particles.splice( i, 1 );
-                this.dispatchEvent("dead", particle);
-				SPARKS.VectorPool.release(particle.position); //
-				SPARKS.VectorPool.release(particle.velocity);
+			this._particles.splice( i, 1 );
+			this.dispatchEvent("dead", particle);
+			SPARKS.VectorPool.release(particle.position); //
+			SPARKS.VectorPool.release(particle.velocity);
 
-            } else {
-                this.dispatchEvent("updated", particle);
-            }
-        }
+		} else {
+			this.dispatchEvent("updated", particle);
+		}
+	}
 
-		this.dispatchEvent("loopUpdated");
+	this.dispatchEvent("loopUpdated");
 
     },
 
     createParticle: function() {
-        var particle = new SPARKS.Particle();
+	var particle = new SPARKS.Particle();
         // In future, use a Particle Factory
-        var len = this._initializers.length, i;
+	var len = this._initializers.length, i;
 
-        for ( i = 0; i < len; i++ ) {
-            this._initializers[i].initialize( this, particle );
-        }
+	for ( i = 0; i < len; i ++ ) {
+		this._initializers[i].initialize( this, particle );
+	}
 
-        this._particles.push( particle );
+	this._particles.push( particle );
 
-        this.dispatchEvent("created", particle); // ParticleCreated
+	this.dispatchEvent("created", particle); // ParticleCreated
 
-        return particle;
+	return particle;
     },
 
     addInitializer: function (initializer) {
-        this._initializers.push(initializer);
+	this._initializers.push(initializer);
     },
 
     addAction: function (action) {
-        this._actions.push(action);
+	this._actions.push(action);
     },
 
     removeInitializer: function (initializer) {
-		var index = this._initializers.indexOf(initializer);
-		if (index > -1) {
-			this._initializers.splice( index, 1 );
-		}
+	var index = this._initializers.indexOf(initializer);
+	if (index > -1) {
+		this._initializers.splice( index, 1 );
+	}
     },
 
     removeAction: function (action) {
-		var index = this._actions.indexOf(action);
-		if (index > -1) {
-			this._actions.splice( index, 1 );
-		}
+	var index = this._actions.indexOf(action);
+	if (index > -1) {
+		this._actions.splice( index, 1 );
+	}
 		//console.log('removeAction', index, this._actions);
     },
 
     addCallback: function(name, callback) {
-        this.callbacks[name] = callback;
+	this.callbacks[name] = callback;
     },
 
     dispatchEvent: function(name, args) {
-        var callback = this.callbacks[name];
-        if (callback) {
-            callback(args);
-        }
+	var callback = this.callbacks[name];
+	if (callback) {
+		callback(args);
+	}
 
     }
 
@@ -227,7 +227,7 @@ SPARKS.EVENT_LOOP_UPDATED = "loopUpdated";
 
 // Number of particles per seconds
 SPARKS.SteadyCounter = function(rate) {
-    this.rate = rate;
+	this.rate = rate;
 
 	// we use a shortfall counter to make up for slow emitters
 	this.leftover = 0;
@@ -277,32 +277,32 @@ SPARKS.Particle = function() {
     /**
      * The lifetime of the particle, in seconds.
      */
-    this.lifetime = 0;
+	this.lifetime = 0;
 
     /**
      * The age of the particle, in seconds.
      */
-    this.age = 0;
+	this.age = 0;
 
     /**
      * The energy of the particle.
      */
-    this.energy = 1;
+	this.energy = 1;
 
     /**
      * Whether the particle is dead and should be removed from the stage.
      */
-    this.isDead = false;
+	this.isDead = false;
 
-    this.target = null; // tag
+	this.target = null; // tag
 
     /**
      * For 3D
      */
 
-     this.position = SPARKS.VectorPool.get().set(0,0,0); //new THREE.Vector3( 0, 0, 0 );
-     this.velocity = SPARKS.VectorPool.get().set(0,0,0); //new THREE.Vector3( 0, 0, 0 );
-	this._oldvelocity = SPARKS.VectorPool.get().set(0,0,0);
+	this.position = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 );
+	this.velocity = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 );
+	this._oldvelocity = SPARKS.VectorPool.get().set(0, 0, 0);
      // rotation vec3
      // angVelocity vec3
      // faceAxis vec3
@@ -317,26 +317,26 @@ SPARKS.Particle = function() {
 *   update function
 *********************************/
 SPARKS.Action = function() {
-    this._priority = 0;
+	this._priority = 0;
 };
 
 
 SPARKS.Age = function(easing) {
-    this._easing = (easing == null) ? TWEEN.Easing.Linear.None : easing;
+	this._easing = (easing == null) ? TWEEN.Easing.Linear.None : easing;
 };
 
 SPARKS.Age.prototype.update = function (emitter, particle, time) {
-    particle.age += time;
-    if( particle.age >= particle.lifetime )
+	particle.age += time;
+	if ( particle.age >= particle.lifetime )
     {
-        particle.energy = 0;
-        particle.isDead = true;
-    }
+		particle.energy = 0;
+		particle.isDead = true;
+	}
     else
-    {
-        var t = this._easing(particle.age / particle.lifetime);
-        particle.energy = -1 * t + 1;
-    }
+	{
+		var t = this._easing(particle.age / particle.lifetime);
+		particle.energy = -1 * t + 1;
+	}
 };
 
 /*
@@ -360,9 +360,9 @@ SPARKS.Move = function() {
 
 SPARKS.Move.prototype.update = function(emitter, particle, time) {
     // attempt verlet velocity updating.
-    var p = particle.position;
+	var p = particle.position;
 	var v = particle.velocity;
-    var old = particle._oldvelocity;
+	var old = particle._oldvelocity;
 
 	if (this._velocityVerlet) {
 		p.x += (v.x + old.x) * 0.5 * time;
@@ -384,12 +384,12 @@ SPARKS.Move.prototype.update = function(emitter, particle, time) {
 
 /* Marks particles found in specified zone dead */
 SPARKS.DeathZone = function(zone) {
-    this.zone = zone;
+	this.zone = zone;
 };
 
 SPARKS.DeathZone.prototype.update = function(emitter, particle, time) {
 
-    if (this.zone.contains(particle.position)) {
+	if (this.zone.contains(particle.position)) {
 		particle.isDead = true;
 	}
 
@@ -400,12 +400,12 @@ SPARKS.DeathZone.prototype.update = function(emitter, particle, time) {
  */
 SPARKS.ActionZone = function(action, zone) {
 	this.action = action;
-    this.zone = zone;
+	this.zone = zone;
 };
 
 SPARKS.ActionZone.prototype.update = function(emitter, particle, time) {
 
-    if (this.zone.contains(particle.position)) {
+	if (this.zone.contains(particle.position)) {
 		this.action.update( emitter, particle, time );
 	}
 
@@ -421,20 +421,20 @@ SPARKS.Accelerate = function(x,y,z) {
 		return;
 	}
 
-    this.acceleration = new THREE.Vector3(x,y,z);
+	this.acceleration = new THREE.Vector3(x,y,z);
 
 };
 
 SPARKS.Accelerate.prototype.update = function(emitter, particle, time) {
-    var acc = this.acceleration;
+	var acc = this.acceleration;
 
-    var v = particle.velocity;
+	var v = particle.velocity;
 
 	particle._oldvelocity.set(v.x, v.y, v.z);
 
-    v.x += acc.x * time;
-    v.y += acc.y * time;
-    v.z += acc.z * time;
+	v.x += acc.x * time;
+	v.y += acc.y * time;
+	v.z += acc.z * time;
 
 };
 
@@ -442,16 +442,16 @@ SPARKS.Accelerate.prototype.update = function(emitter, particle, time) {
  * Accelerate Factor accelerate based on a factor of particle's velocity.
  */
 SPARKS.AccelerateFactor = function(factor) {
-    this.factor = factor;
+	this.factor = factor;
 };
 
 SPARKS.AccelerateFactor.prototype.update = function(emitter, particle, time) {
-    var factor = this.factor;
+	var factor = this.factor;
 
-    var v = particle.velocity;
+	var v = particle.velocity;
 	var len = v.length();
 	var adjFactor;
-    if (len>0) {
+	if (len > 0) {
 
 		adjFactor = factor * time / len;
 		adjFactor += 1;
@@ -475,14 +475,14 @@ SPARKS.AccelerateVelocity = function(factor) {
 };
 
 SPARKS.AccelerateVelocity.prototype.update = function(emitter, particle, time) {
-    var factor = this.factor;
+	var factor = this.factor;
 
-    var v = particle.velocity;
+	var v = particle.velocity;
 
 
-    v.z += - v.x * factor;
-    v.y += v.z * factor;
-    v.x +=  v.y * factor;
+	v.z += - v.x * factor;
+	v.y += v.z * factor;
+	v.x +=  v.y * factor;
 
 };
 
@@ -494,18 +494,18 @@ SPARKS.RandomDrift = function(x,y,z) {
 		return;
 	}
 
-    this.drift = new THREE.Vector3(x,y,z);
+	this.drift = new THREE.Vector3(x,y,z);
 }
 
 
 SPARKS.RandomDrift.prototype.update = function(emitter, particle, time) {
-    var drift = this.drift;
+	var drift = this.drift;
 
-    var v = particle.velocity;
+	var v = particle.velocity;
 
-    v.x += ( Math.random() - 0.5 ) * drift.x * time;
-    v.y += ( Math.random() - 0.5 ) * drift.y * time;
-    v.z += ( Math.random() - 0.5 ) * drift.z * time;
+	v.x += ( Math.random() - 0.5 ) * drift.x * time;
+	v.y += ( Math.random() - 0.5 ) * drift.y * time;
+	v.z += ( Math.random() - 0.5 ) * drift.z * time;
 
 };
 
@@ -521,29 +521,29 @@ SPARKS.Zone = function() {
 // TODO, contains() for Zone
 
 SPARKS.PointZone = function(pos) {
-    this.pos = pos;
+	this.pos = pos;
 };
 
 SPARKS.PointZone.prototype.getLocation = function() {
-    return this.pos;
+	return this.pos;
 };
 
 SPARKS.PointZone = function(pos) {
-    this.pos = pos;
+	this.pos = pos;
 };
 
 SPARKS.PointZone.prototype.getLocation = function() {
-    return this.pos;
+	return this.pos;
 };
 
 SPARKS.LineZone = function(start, end) {
-    this.start = start;
+	this.start = start;
 	this.end = end;
 	this._length = end.clone().sub( start );
 };
 
 SPARKS.LineZone.prototype.getLocation = function() {
-    var len = this._length.clone();
+	var len = this._length.clone();
 
 	len.multiplyScalar( Math.random() );
 	return len.add( this.start );
@@ -552,7 +552,7 @@ SPARKS.LineZone.prototype.getLocation = function() {
 
 // Basically a RectangleZone
 SPARKS.ParallelogramZone = function(corner, side1, side2) {
-    this.corner = corner;
+	this.corner = corner;
 	this.side1 = side1;
 	this.side2 = side2;
 };
@@ -567,7 +567,7 @@ SPARKS.ParallelogramZone.prototype.getLocation = function() {
 };
 
 SPARKS.CubeZone = function(position, x, y, z) {
-    this.position = position;
+	this.position = position;
 	this.x = x;
 	this.y = y;
 	this.z = z;
@@ -595,17 +595,17 @@ SPARKS.CubeZone.prototype.contains = function(position) {
 	var y = this.y; // depth
 	var z = this.z; // height
 
-	if (x<0) {
+	if (x < 0) {
 		startX += x;
 		x = Math.abs(x);
 	}
 
-	if (y<0) {
+	if (y < 0) {
 		startY += y;
 		y = Math.abs(y);
 	}
 
-	if (z<0) {
+	if (z < 0) {
 		startZ += z;
 		z = Math.abs(z);
 	}
@@ -674,29 +674,29 @@ SPARKS.DiscZone.prototype.getLocation = function() {
 */
 
 SPARKS.SphereCapZone = function(x, y, z, minr, maxr, angle) {
-    this.x = x;
-    this.y = y;
-    this.z = z;
-    this.minr = minr;
-    this.maxr = maxr;
-    this.angle = angle;
+	this.x = x;
+	this.y = y;
+	this.z = z;
+	this.minr = minr;
+	this.maxr = maxr;
+	this.angle = angle;
 };
 
 SPARKS.SphereCapZone.prototype.getLocation = function() {
-    var theta = Math.PI *2  * SPARKS.Utils.random();
-    var r = SPARKS.Utils.random();
+	var theta = Math.PI * 2  * SPARKS.Utils.random();
+	var r = SPARKS.Utils.random();
 
     //new THREE.Vector3
-    var v =  SPARKS.VectorPool.get().set(r * Math.cos(theta), -1 / Math.tan(this.angle * SPARKS.Utils.DEGREE_TO_RADIAN), r * Math.sin(theta));
+	var v =  SPARKS.VectorPool.get().set(r * Math.cos(theta), -1 / Math.tan(this.angle * SPARKS.Utils.DEGREE_TO_RADIAN), r * Math.sin(theta));
 
     //v.length = StardustMath.interpolate(0, _minRadius, 1, _maxRadius, Math.random());
 
-    var i = this.minr - ((this.minr-this.maxr) *  Math.random() );
-    v.multiplyScalar(i);
+	var i = this.minr - ((this.minr - this.maxr) *  Math.random() );
+	v.multiplyScalar(i);
 
 	v.__markedForReleased = true;
 
-    return v;
+	return v;
 };
 
 
@@ -709,33 +709,33 @@ SPARKS.SphereCapZone.prototype.getLocation = function() {
 
 // Specifies random life between max and min
 SPARKS.Lifetime = function(min, max) {
-    this._min = min;
+	this._min = min;
 
-    this._max = max ? max : min;
+	this._max = max ? max : min;
 
 };
 
 SPARKS.Lifetime.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
-    particle.lifetime = this._min + SPARKS.Utils.random() * ( this._max - this._min );
+	particle.lifetime = this._min + SPARKS.Utils.random() * ( this._max - this._min );
 };
 
 
 SPARKS.Position = function(zone) {
-    this.zone = zone;
+	this.zone = zone;
 };
 
 SPARKS.Position.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
-    var pos = this.zone.getLocation();
-    particle.position.set(pos.x, pos.y, pos.z);
+	var pos = this.zone.getLocation();
+	particle.position.set(pos.x, pos.y, pos.z);
 };
 
 SPARKS.Velocity = function(zone) {
-    this.zone = zone;
+	this.zone = zone;
 };
 
 SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
-    var pos = this.zone.getLocation();
-    particle.velocity.set(pos.x, pos.y, pos.z);
+	var pos = this.zone.getLocation();
+	particle.velocity.set(pos.x, pos.y, pos.z);
 	if (pos.__markedForReleased) {
 		//console.log("release");
 		SPARKS.VectorPool.release(pos);
@@ -744,17 +744,17 @@ SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*P
 };
 
 SPARKS.Target = function(target, callback) {
-    this.target = target;
-    this.callback = callback;
+	this.target = target;
+	this.callback = callback;
 };
 
 SPARKS.Target.prototype.initialize = function( emitter, particle ) {
 
-    if (this.callback) {
-        particle.target = this.callback();
-    } else {
-        particle.target = this.target;
-    }
+	if (this.callback) {
+		particle.target = this.callback();
+	} else {
+		particle.target = this.target;
+	}
 
 };
 
@@ -769,7 +769,7 @@ SPARKS.VectorPool = {
 
 	// Get a new Vector
 	get: function() {
-		if (this.__pools.length>0) {
+		if (this.__pools.length > 0) {
 			return this.__pools.pop();
 		}
 
@@ -786,7 +786,7 @@ SPARKS.VectorPool = {
 	_addToPool: function() {
 		//console.log("creating some pools");
 
-		for (var i=0, size = 100; i < size; i++) {
+		for (var i = 0, size = 100; i < size; i ++) {
 			this.__pools.push(new THREE.Vector3());
 		}
 
@@ -807,7 +807,7 @@ SPARKS.VectorPool = {
 *********************************/
 SPARKS.Utils = {
     random: function() {
-        return Math.random();
+	return Math.random();
     },
     DEGREE_TO_RADIAN: Math.PI / 180,
 	TWOPI: Math.PI * 2,
@@ -821,7 +821,7 @@ SPARKS.Utils = {
 
 	getPerpendicular: function( v )
 	{
-		if( v.x == 0 )
+		if ( v.x == 0 )
 		{
 			return new THREE.Vector3D( 1, 0, 0 );
 		}

+ 5 - 5
examples/js/TypedArrayUtils.js

@@ -33,8 +33,8 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 		for ( y = 0; y < eleSize; y ++ ) {
 
 			tmp = arr[ a + y ];
-			arr[ a + y ]=arr[ b + y ];
-			arr[ b + y ]=tmp;
+			arr[ a + y ] = arr[ b + y ];
+			arr[ b + y ] = tmp;
 
 		}
 
@@ -46,7 +46,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 
 		if ( right - left <= 25 ) {
 
-			for ( j= left + 1; j <= right; j ++ ) {
+			for ( j = left + 1; j <= right; j ++ ) {
 
 				for ( x = 0; x < eleSize; x ++ ) {
 			
@@ -214,7 +214,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 		
 		median = Math.floor( plength / 2 );
 		
-		node = new self.Node( getPointSet( points, median ) , depth, parent, median + pos );
+		node = new self.Node( getPointSet( points, median ), depth, parent, median + pos );
 		node.left = buildTree( points.subarray( 0, median * eleSize), depth + 1, node, pos );
 		node.right = buildTree( points.subarray( ( median + 1 ) * eleSize, points.length ), depth + 1, node, pos + median + 1 );
 
@@ -226,7 +226,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 		
 	this.getMaxDepth = function () { return maxDepth; };
 	
-	this.nearest = function ( point, maxNodes , maxDistance ) {
+	this.nearest = function ( point, maxNodes, maxDistance ) {
 	
 		 /* point: array of size eleSize 
 			maxNodes: max amount of nodes to return 

+ 1 - 1
examples/js/cameras/CombinedCamera.js

@@ -29,7 +29,7 @@ THREE.CombinedCamera = function ( width, height, fov, near, far, orthoNear, orth
 
 	this.toPerspective();
 
-	var aspect = width/height;
+	var aspect = width / height;
 
 };
 

+ 3 - 3
examples/js/controls/EditorControls.js

@@ -262,7 +262,7 @@ THREE.EditorControls = function ( object, domElement ) {
 			case 1:
 				touches[ 0 ].set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY, 0 );
 				touches[ 1 ].set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY, 0 );
-				scope.rotate( touches[ 0 ].sub( getClosest( touches[ 0 ] ,prevTouches ) ).multiplyScalar( - 0.005 ) );
+				scope.rotate( touches[ 0 ].sub( getClosest( touches[ 0 ], prevTouches ) ).multiplyScalar( - 0.005 ) );
 				break;
 
 			case 2:
@@ -273,8 +273,8 @@ THREE.EditorControls = function ( object, domElement ) {
 				prevDistance = distance;
 
 
-				var offset0 = touches[ 0 ].clone().sub( getClosest( touches[ 0 ] ,prevTouches ) );
-				var offset1 = touches[ 1 ].clone().sub( getClosest( touches[ 1 ] ,prevTouches ) );
+				var offset0 = touches[ 0 ].clone().sub( getClosest( touches[ 0 ], prevTouches ) );
+				var offset1 = touches[ 1 ].clone().sub( getClosest( touches[ 1 ], prevTouches ) );
 				offset0.x = -offset0.x;
 				offset1.x = -offset1.x;
 

+ 2 - 2
examples/js/controls/FirstPersonControls.js

@@ -163,7 +163,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 
 	this.onKeyUp = function ( event ) {
 
-		switch( event.keyCode ) {
+		switch ( event.keyCode ) {
 
 			case 38: /*up*/
 			case 87: /*W*/ this.moveForward = false; break;
@@ -229,7 +229,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 		}
 
 		this.lon += this.mouseX * actualLookSpeed;
-		if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
+		if ( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
 
 		this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
 		this.phi = THREE.Math.degToRad( 90 - this.lat );

+ 1 - 1
examples/js/controls/FlyControls.js

@@ -80,7 +80,7 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	this.keyup = function( event ) {
 
-		switch( event.keyCode ) {
+		switch ( event.keyCode ) {
 
 			case 16: /* shift */ this.movementSpeedMultiplier = 1; break;
 

+ 25 - 25
examples/js/controls/MouseControls.js

@@ -6,50 +6,50 @@
 
 THREE.MouseControls = function ( object ) {
 
-  var scope = this;
-  var PI_2 = Math.PI / 2;
-  var mouseQuat = {
+	var scope = this;
+	var PI_2 = Math.PI / 2;
+	var mouseQuat = {
     x: new THREE.Quaternion(),
     y: new THREE.Quaternion()
   };
-  var object = object;
-  var xVector = new THREE.Vector3( 1, 0, 0 );
-  var yVector = new THREE.Vector3( 0, 1, 0 );
+	var object = object;
+	var xVector = new THREE.Vector3( 1, 0, 0 );
+	var yVector = new THREE.Vector3( 0, 1, 0 );
 
-  var onMouseMove = function ( event ) {
+	var onMouseMove = function ( event ) {
 
-    if ( scope.enabled === false ) return;
+		if ( scope.enabled === false ) return;
 
-    var orientation = scope.orientation;
+		var orientation = scope.orientation;
 
-    var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
-    var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
+		var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
+		var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
 
-    orientation.y += movementX * 0.0025;
-    orientation.x += movementY * 0.0025;
+		orientation.y += movementX * 0.0025;
+		orientation.x += movementY * 0.0025;
 
-    orientation.x = Math.max( - PI_2, Math.min( PI_2, orientation.x ) );
+		orientation.x = Math.max( - PI_2, Math.min( PI_2, orientation.x ) );
 
-  };
+	};
 
-  this.enabled = true;
+	this.enabled = true;
 
-  this.orientation = {
+	this.orientation = {
     x: 0,
     y: 0,
   };
 
-  this.update = function() {
+	this.update = function() {
 
-    if ( this.enabled === false ) return;
+		if ( this.enabled === false ) return;
 
-    mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x );
-    mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y );
-    object.quaternion.copy(mouseQuat.y).multiply(mouseQuat.x)
-    return;
+		mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x );
+		mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y );
+		object.quaternion.copy(mouseQuat.y).multiply(mouseQuat.x)
+		return;
 
-  };
+	};
 
-  document.addEventListener( 'mousemove', onMouseMove, false );
+	document.addEventListener( 'mousemove', onMouseMove, false );
 
 };

+ 47 - 16
examples/js/controls/OrbitControls.js

@@ -14,12 +14,6 @@
 //    Orbit - left mouse / touch: one finger move
 //    Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
 //    Pan - right mouse, or arrow keys / touch: three finter swipe
-//
-// This is a drop-in replacement for (most) TrackballControls used in examples.
-// That is, include this js file and wherever you see:
-//      controls = new THREE.OrbitControls( camera );
-//      controls.target.z = 150;
-// Simple substitute "OrbitControls" and the control should work as-is.
 
 THREE.OrbitControls = function ( object, domElement ) {
 
@@ -43,10 +37,14 @@ THREE.OrbitControls = function ( object, domElement ) {
 	this.noZoom = false;
 	this.zoomSpeed = 1.0;
 
-	// Limits to how far you can dolly in and out
+	// Limits to how far you can dolly in and out ( PerspectiveCamera only )
 	this.minDistance = 0;
 	this.maxDistance = Infinity;
 
+	// Limits to how far you can zoom in and out ( OrthographicCamera only )
+	this.minZoom = 0;
+	this.maxZoom = Infinity;
+
 	// Set to true to disable this control
 	this.noRotate = false;
 	this.rotateSpeed = 1.0;
@@ -118,6 +116,7 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 	this.target0 = this.target.clone();
 	this.position0 = this.object.position.clone();
+	this.zoom0 = this.object.zoom;
 
 	// so camera.up is the orbit axis
 
@@ -127,8 +126,8 @@ THREE.OrbitControls = function ( object, domElement ) {
 	// events
 
 	var changeEvent = { type: 'change' };
-	var startEvent = { type: 'start'};
-	var endEvent = { type: 'end'};
+	var startEvent = { type: 'start' };
+	var endEvent = { type: 'end' };
 
 	this.rotateLeft = function ( angle ) {
 
@@ -186,7 +185,7 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 		var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
 
-		if ( scope.object.fov !== undefined ) {
+		if ( scope.object instanceof THREE.PerspectiveCamera ) {
 
 			// perspective
 			var position = scope.object.position;
@@ -200,7 +199,7 @@ THREE.OrbitControls = function ( object, domElement ) {
 			scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight );
 			scope.panUp( 2 * deltaY * targetDistance / element.clientHeight );
 
-		} else if ( scope.object.top !== undefined ) {
+		} else if ( scope.object instanceof THREE.OrthographicCamera ) {
 
 			// orthographic
 			scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth );
@@ -223,7 +222,21 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 		}
 
-		scale /= dollyScale;
+		if ( scope.object instanceof THREE.PerspectiveCamera ) {
+
+			scale /= dollyScale;
+
+		} else if ( scope.object instanceof THREE.OrthographicCamera ) {
+
+			scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
+			scope.object.updateProjectionMatrix();
+			scope.dispatchEvent( changeEvent );
+
+		} else {
+
+			console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
+
+		}
 
 	};
 
@@ -235,7 +248,21 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 		}
 
-		scale *= dollyScale;
+		if ( scope.object instanceof THREE.PerspectiveCamera ) {
+
+			scale *= dollyScale;
+
+		} else if ( scope.object instanceof THREE.OrthographicCamera ) {
+
+			scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
+			scope.object.updateProjectionMatrix();
+			scope.dispatchEvent( changeEvent );
+
+		} else {
+
+			console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
+
+		}
 
 	};
 
@@ -321,6 +348,10 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 		this.target.copy( this.target0 );
 		this.object.position.copy( this.position0 );
+		this.object.zoom = this.zoom0;
+
+		this.object.updateProjectionMatrix();
+		this.dispatchEvent( changeEvent );
 
 		this.update();
 
@@ -420,7 +451,7 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 				scope.dollyIn();
 
-			} else {
+			} else if ( dollyDelta.y < 0 ) {
 
 				scope.dollyOut();
 
@@ -479,7 +510,7 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 			scope.dollyOut();
 
-		} else {
+		} else if ( delta < 0 ) {
 
 			scope.dollyIn();
 
@@ -612,7 +643,7 @@ THREE.OrbitControls = function ( object, domElement ) {
 
 					scope.dollyOut();
 
-				} else {
+				} else if ( dollyDelta.y < 0 ) {
 
 					scope.dollyIn();
 

+ 5 - 5
examples/js/controls/OrthographicTrackballControls.js

@@ -73,8 +73,8 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 	// events
 
 	var changeEvent = { type: 'change' };
-	var startEvent = { type: 'start'};
-	var endEvent = { type: 'end'};
+	var startEvent = { type: 'start' };
+	var endEvent = { type: 'end' };
 
 
 	// methods
@@ -156,7 +156,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 				if ( length < Math.SQRT1_2 ) {
 
-					mouseOnBall.z = Math.sqrt( 1.0 - length*length );
+					mouseOnBall.z = Math.sqrt( 1.0 - length * length );
 
 				} else {
 
@@ -186,7 +186,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 	}() );
 
-	this.rotateCamera = (function(){
+	this.rotateCamera = (function() {
 
 		var axis = new THREE.Vector3(),
 			quaternion = new THREE.Quaternion();
@@ -264,7 +264,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 	};
 
-	this.panCamera = (function(){
+	this.panCamera = (function() {
 
 		var mouseChange = new THREE.Vector2(),
 			objectUp = new THREE.Vector3(),

+ 66 - 73
examples/js/controls/TrackballControls.js

@@ -1,6 +1,8 @@
 /**
  * @author Eberhard Graether / http://egraether.com/
  * @author Mark Lundin 	/ http://mark-lundin.com
+ * @author Simone Manini / http://daron1337.github.io
+ * @author Luca Antiga 	/ http://lantiga.github.io
  */
 
 THREE.TrackballControls = function ( object, domElement ) {
@@ -24,7 +26,6 @@ THREE.TrackballControls = function ( object, domElement ) {
 	this.noRotate = false;
 	this.noZoom = false;
 	this.noPan = false;
-	this.noRoll = false;
 
 	this.staticMoving = false;
 	this.dynamicDampingFactor = 0.2;
@@ -47,8 +48,11 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 	_eye = new THREE.Vector3(),
 
-	_rotateStart = new THREE.Vector3(),
-	_rotateEnd = new THREE.Vector3(),
+	_movePrev = new THREE.Vector2(),
+	_moveCurr = new THREE.Vector2(),
+
+	_lastAxis = new THREE.Vector3(),
+	_lastAngle = 0,
 
 	_zoomStart = new THREE.Vector2(),
 	_zoomEnd = new THREE.Vector2(),
@@ -68,8 +72,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 	// events
 
 	var changeEvent = { type: 'change' };
-	var startEvent = { type: 'start'};
-	var endEvent = { type: 'end'};
+	var startEvent = { type: 'start' };
+	var endEvent = { type: 'end' };
 
 
 	// methods
@@ -124,106 +128,93 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 	}() );
 
-	var getMouseProjectionOnBall = ( function () {
+	var getMouseOnCircle = ( function () {
 
-		var vector = new THREE.Vector3();
-		var objectUp = new THREE.Vector3();
-		var mouseOnBall = new THREE.Vector3();
+		var vector = new THREE.Vector2();
 
 		return function ( pageX, pageY ) {
 
-			mouseOnBall.set(
-				( pageX - _this.screen.width * 0.5 - _this.screen.left ) / (_this.screen.width*.5),
-				( _this.screen.height * 0.5 + _this.screen.top - pageY ) / (_this.screen.height*.5),
-				0.0
+			vector.set(
+				( ( pageX - _this.screen.width * 0.5 - _this.screen.left ) / ( _this.screen.width * 0.5 ) ),
+				( ( _this.screen.height + 2 * ( _this.screen.top - pageY ) ) / _this.screen.width ) // screen.width intentional
 			);
 
-			var length = mouseOnBall.length();
-
-			if ( _this.noRoll ) {
-
-				if ( length < Math.SQRT1_2 ) {
-
-					mouseOnBall.z = Math.sqrt( 1.0 - length*length );
-
-				} else {
-
-					mouseOnBall.z = .5 / length;
-					
-				}
-
-			} else if ( length > 1.0 ) {
-
-				mouseOnBall.normalize();
-
-			} else {
-
-				mouseOnBall.z = Math.sqrt( 1.0 - length * length );
-
-			}
-
-			_eye.copy( _this.object.position ).sub( _this.target );
-
-			vector.copy( _this.object.up ).setLength( mouseOnBall.y )
-			vector.add( objectUp.copy( _this.object.up ).cross( _eye ).setLength( mouseOnBall.x ) );
-			vector.add( _eye.setLength( mouseOnBall.z ) );
-
 			return vector;
-
 		};
 
 	}() );
 
-	this.rotateCamera = (function(){
+	this.rotateCamera = (function() {
 
 		var axis = new THREE.Vector3(),
-			quaternion = new THREE.Quaternion();
-
+			quaternion = new THREE.Quaternion(),
+			eyeDirection = new THREE.Vector3(),
+			objectUpDirection = new THREE.Vector3(),
+			objectSidewaysDirection = new THREE.Vector3(),
+			moveDirection = new THREE.Vector3(),
+			angle;
 
 		return function () {
 
-			var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() );
+			moveDirection.set( _moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0 );
+			angle = moveDirection.length();
 
 			if ( angle ) {
 
-				axis.crossVectors( _rotateStart, _rotateEnd ).normalize();
+				_eye.copy( _this.object.position ).sub( _this.target );
 
-				angle *= _this.rotateSpeed;
+				eyeDirection.copy( _eye ).normalize();
+				objectUpDirection.copy( _this.object.up ).normalize();
+				objectSidewaysDirection.crossVectors( objectUpDirection, eyeDirection ).normalize();
+
+				objectUpDirection.setLength( _moveCurr.y - _movePrev.y );
+				objectSidewaysDirection.setLength( _moveCurr.x - _movePrev.x );
+
+				moveDirection.copy( objectUpDirection.add( objectSidewaysDirection ) );
+
+				axis.crossVectors( moveDirection, _eye ).normalize();
 
-				quaternion.setFromAxisAngle( axis, -angle );
+				angle *= _this.rotateSpeed;
+				quaternion.setFromAxisAngle( axis, angle );
 
 				_eye.applyQuaternion( quaternion );
 				_this.object.up.applyQuaternion( quaternion );
 
-				_rotateEnd.applyQuaternion( quaternion );
+				_lastAxis.copy( axis );
+				_lastAngle = angle;
 
-				if ( _this.staticMoving ) {
+			}
 
-					_rotateStart.copy( _rotateEnd );
+			else if ( !_this.staticMoving && _lastAngle ) {
 
-				} else {
+				_lastAngle *= Math.sqrt( 1.0 - _this.dynamicDampingFactor );
+				_eye.copy( _this.object.position ).sub( _this.target );
+				quaternion.setFromAxisAngle( _lastAxis, _lastAngle );
+				_eye.applyQuaternion( quaternion );
+				_this.object.up.applyQuaternion( quaternion );
 
-					quaternion.setFromAxisAngle( axis, angle * ( _this.dynamicDampingFactor - 1.0 ) );
-					_rotateStart.applyQuaternion( quaternion );
+			}
 
-				}
+			_movePrev.copy( _moveCurr );
 
-			}
-		}
+		};
 
 	}());
 
+
 	this.zoomCamera = function () {
 
+		var factor;
+
 		if ( _state === STATE.TOUCH_ZOOM_PAN ) {
 
-			var factor = _touchZoomDistanceStart / _touchZoomDistanceEnd;
+			factor = _touchZoomDistanceStart / _touchZoomDistanceEnd;
 			_touchZoomDistanceStart = _touchZoomDistanceEnd;
 			_eye.multiplyScalar( factor );
 
 		} else {
 
-			var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed;
+			factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed;
 
 			if ( factor !== 1.0 && factor > 0.0 ) {
 
@@ -245,7 +236,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 	};
 
-	this.panCamera = (function(){
+	this.panCamera = (function() {
 
 		var mouseChange = new THREE.Vector2(),
 			objectUp = new THREE.Vector3(),
@@ -276,7 +267,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 				}
 
 			}
-		}
+		};
 
 	}());
 
@@ -412,8 +403,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		if ( _state === STATE.ROTATE && !_this.noRotate ) {
 
-			_rotateStart.copy( getMouseProjectionOnBall( event.pageX, event.pageY ) );
-			_rotateEnd.copy( _rotateStart );
+			_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
+			_movePrev.copy(_moveCurr);
 
 		} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
 
@@ -423,7 +414,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 		} else if ( _state === STATE.PAN && !_this.noPan ) {
 
 			_panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
-			_panEnd.copy(_panStart)
+			_panEnd.copy(_panStart);
 
 		}
 
@@ -443,7 +434,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		if ( _state === STATE.ROTATE && !_this.noRotate ) {
 
-			_rotateEnd.copy( getMouseProjectionOnBall( event.pageX, event.pageY ) );
+			_movePrev.copy(_moveCurr);
+			_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
 
 		} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
 
@@ -505,8 +497,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 			case 1:
 				_state = STATE.TOUCH_ROTATE;
-				_rotateStart.copy( getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
-				_rotateEnd.copy( _rotateStart );
+				_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
+				_movePrev.copy(_moveCurr);
 				break;
 
 			case 2:
@@ -540,7 +532,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 		switch ( event.touches.length ) {
 
 			case 1:
-				_rotateEnd.copy( getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
+				_movePrev.copy(_moveCurr);
+				_moveCurr.copy( getMouseOnCircle(  event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
 				break;
 
 			case 2:
@@ -567,8 +560,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 		switch ( event.touches.length ) {
 
 			case 1:
-				_rotateEnd.copy( getMouseProjectionOnBall( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
-				_rotateStart.copy( _rotateEnd );
+				_movePrev.copy(_moveCurr);
+				_moveCurr.copy( getMouseOnCircle(  event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
 				break;
 
 			case 2:

+ 38 - 38
examples/js/controls/TransformControls.js

@@ -30,8 +30,8 @@
 
 			} else {
 
-					this.color.copy( this.oldColor );
-					this.opacity = this.oldOpacity;
+				this.color.copy( this.oldColor );
+				this.opacity = this.oldOpacity;
 
 			}
 
@@ -65,8 +65,8 @@
 
 			} else {
 
-					this.color.copy( this.oldColor );
-					this.opacity = this.oldOpacity;
+				this.color.copy( this.oldColor );
+				this.opacity = this.oldOpacity;
 
 			}
 
@@ -110,8 +110,8 @@
 
 			this.activePlane = planes["XYZE"];
 
-			planes["YZ"].rotation.set( 0, Math.PI/2, 0 );
-			planes["XZ"].rotation.set( -Math.PI/2, 0, 0 );
+			planes["YZ"].rotation.set( 0, Math.PI / 2, 0 );
+			planes["XZ"].rotation.set( -Math.PI / 2, 0, 0 );
 
 			for (var i in planes) {
 				planes[i].name = i;
@@ -126,7 +126,7 @@
 
 				for ( var name in gizmoMap ) {
 
-					for ( i = gizmoMap[name].length; i--;) {
+					for ( i = gizmoMap[name].length; i --;) {
 
 						var object = gizmoMap[name][i][0];
 						var position = gizmoMap[name][i][1];
@@ -183,7 +183,7 @@
 
 		this.highlight = function ( axis ) {
 			this.traverse(function( child ) {
-				if ( child.material && child.material.highlight ){
+				if ( child.material && child.material.highlight ) {
 					if ( child.name == axis ) {
 						child.material.highlight( true );
 					} else {
@@ -236,7 +236,7 @@
 
 		this.handleGizmos = {
 			X: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI/2 ] ],
+				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
 				[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
 			],
 			Y: [
@@ -244,7 +244,7 @@
 				[	new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
 			],
 			Z: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI/2, 0, 0 ] ],
+				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
 				[ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
 			],
 			XYZ: [
@@ -254,22 +254,22 @@
 				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ), [ 0.15, 0.15, 0 ] ]
 			],
 			YZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.15, 0.15 ], [ 0, Math.PI/2, 0 ] ]
+				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ] ]
 			],
 			XZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ -Math.PI/2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ -Math.PI / 2, 0, 0 ] ]
 			]
 		};
 
 		this.pickerGizmos = {
 			X: [
-				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI/2 ] ]
+				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
 			],
 			Y: [
 				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0.6, 0 ] ]
 			],
 			Z: [
-				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0.6 ], [ Math.PI/2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
 			],
 			XYZ: [
 				[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
@@ -278,10 +278,10 @@
 				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ), [ 0.2, 0.2, 0 ] ]
 			],
 			YZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.2, 0.2 ], [ 0, Math.PI/2, 0 ] ]
+				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ] ]
 			],
 			XZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.2, 0, 0.2 ], [ -Math.PI/2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.2, 0, 0.2 ], [ -Math.PI / 2, 0, 0 ] ]
 			]
 		};
 
@@ -295,12 +295,12 @@
 				if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
 			}
 
-			if ( axis == "Y" ){
+			if ( axis == "Y" ) {
 				this.activePlane = this.planes[ "XY" ];
 				if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
 			}
 
-			if ( axis == "Z" ){
+			if ( axis == "Z" ) {
 				this.activePlane = this.planes[ "XZ" ];
 				if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
 			}
@@ -331,15 +331,15 @@
 
 		var CircleGeometry = function ( radius, facing, arc ) {
 
-				var geometry = new THREE.Geometry();
-				arc = arc ? arc : 1;
-				for ( var i = 0; i <= 64 * arc; ++i ) {
-					if ( facing == 'x' ) geometry.vertices.push( new THREE.Vector3( 0, Math.cos( i / 32 * Math.PI ), Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
-					if ( facing == 'y' ) geometry.vertices.push( new THREE.Vector3( Math.cos( i / 32 * Math.PI ), 0, Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
-					if ( facing == 'z' ) geometry.vertices.push( new THREE.Vector3( Math.sin( i / 32 * Math.PI ), Math.cos( i / 32 * Math.PI ), 0 ).multiplyScalar(radius) );
-				}
+			var geometry = new THREE.Geometry();
+			arc = arc ? arc : 1;
+			for ( var i = 0; i <= 64 * arc; ++ i ) {
+				if ( facing == 'x' ) geometry.vertices.push( new THREE.Vector3( 0, Math.cos( i / 32 * Math.PI ), Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
+				if ( facing == 'y' ) geometry.vertices.push( new THREE.Vector3( Math.cos( i / 32 * Math.PI ), 0, Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
+				if ( facing == 'z' ) geometry.vertices.push( new THREE.Vector3( Math.sin( i / 32 * Math.PI ), Math.cos( i / 32 * Math.PI ), 0 ).multiplyScalar(radius) );
+			}
 
-				return geometry;
+			return geometry;
 		};
 
 		this.handleGizmos = {
@@ -362,13 +362,13 @@
 
 		this.pickerGizmos = {
 			X: [
-				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, -Math.PI/2, -Math.PI/2 ] ]
+				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, -Math.PI / 2, -Math.PI / 2 ] ]
 			],
 			Y: [
-				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ Math.PI/2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ] ]
 			],
 			Z: [
-				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, 0, -Math.PI/2 ] ]
+				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
 			],
 			E: [
 				[ new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.12, 2, 24 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ) ]
@@ -474,7 +474,7 @@
 
 		this.handleGizmos = {
 			X: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI/2 ] ],
+				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
 				[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
 			],
 			Y: [
@@ -482,7 +482,7 @@
 				[ new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
 			],
 			Z: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI/2, 0, 0 ] ],
+				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
 				[ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
 			],
 			XYZ: [
@@ -492,13 +492,13 @@
 
 		this.pickerGizmos = {
 			X: [
-				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI/2 ] ]
+				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
 			],
 			Y: [
 				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0.6, 0 ] ]
 			],
 			Z: [
-				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0.6 ], [ Math.PI/2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
 			],
 			XYZ: [
 				[ new THREE.Mesh( new THREE.BoxGeometry( 0.4, 0.4, 0.4 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
@@ -515,12 +515,12 @@
 				if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
 			}
 
-			if ( axis == "Y" ){
+			if ( axis == "Y" ) {
 				this.activePlane = this.planes[ "XY" ];
 				if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
 			}
 
-			if ( axis == "Z" ){
+			if ( axis == "Z" ) {
 				this.activePlane = this.planes[ "XZ" ];
 				if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
 			}
@@ -775,7 +775,7 @@
 
 					scope.gizmo[_mode].setActivePlane( scope.axis, eye );
 
-					var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
+					var planeIntersect = intersectObjects( pointer, [ scope.gizmo[_mode].activePlane ] );
 
 					oldPosition.copy( scope.object.position );
 					oldScale.copy( scope.object.scale );
@@ -803,9 +803,9 @@
 			event.preventDefault();
 			event.stopPropagation();
 
-			var pointer = event.changedTouches? event.changedTouches[0] : event;
+			var pointer = event.changedTouches ? event.changedTouches[0] : event;
 
-			var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
+			var planeIntersect = intersectObjects( pointer, [ scope.gizmo[_mode].activePlane ] );
 
 			point.copy( planeIntersect.point );
 

+ 6 - 6
examples/js/crossfade/scenes.js

@@ -8,7 +8,7 @@ function generateGeometry(objectType, numObjects) {
 
 			var n = ( f instanceof THREE.Face3 ) ? 3 : 4;
 
-			for( var j = 0; j < n; j ++ ) {
+			for ( var j = 0; j < n; j ++ ) {
 
 				f.vertexColors[ j ] = c;
 
@@ -43,13 +43,13 @@ function generateGeometry(objectType, numObjects) {
 			geom = new THREE.BoxGeometry( 1, 1, 1 );
 			scale.y = Math.random() * 200 + 100;
 			scale.z = Math.random() * 200 + 100;
-			color.setRGB( 0, 0, Math.random()+0.1 );
+			color.setRGB( 0, 0, Math.random() + 0.1 );
 		}
 		else if ( objectType == "sphere" )
 		{
 			geom = new THREE.IcosahedronGeometry( 1, 1 )
 			scale.y = scale.z = scale.x;
-			color.setRGB( Math.random()+0.1, 0, 0 );
+			color.setRGB( Math.random() + 0.1, 0, 0 );
 		}
 
 		// give the geom's vertices a random color, to be displayed
@@ -94,9 +94,9 @@ function Scene ( type, numObjects, cameraZ, fov, rotationSpeed, clearColor ) {
 
 	this.render = function( delta, rtt ) {
 
-		this.mesh.rotation.x += delta*this.rotationSpeed.x;
-		this.mesh.rotation.y += delta*this.rotationSpeed.y;
-		this.mesh.rotation.z += delta*this.rotationSpeed.z;
+		this.mesh.rotation.x += delta * this.rotationSpeed.x;
+		this.mesh.rotation.y += delta * this.rotationSpeed.y;
+		this.mesh.rotation.z += delta * this.rotationSpeed.z;
 
 		renderer.setClearColor( this.clearColor );
 

+ 12 - 12
examples/js/crossfade/transition.js

@@ -5,8 +5,8 @@ function Transition ( sceneA, sceneB ) {
 	this.cameraOrtho = new THREE.OrthographicCamera(window.innerWidth / -2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / -2, -10, 10);
 
 	this.textures = [];
-	for (var i=0;i<6;i++)
-		this.textures[i]=new THREE.ImageUtils.loadTexture('textures/transition/transition'+(i+1)+'.png');
+	for (var i = 0; i < 6; i ++)
+		this.textures[i] = new THREE.ImageUtils.loadTexture('textures/transition/transition' + (i + 1) + '.png');
 				
 	this.quadmaterial = new THREE.ShaderMaterial({
 
@@ -101,13 +101,13 @@ function Transition ( sceneA, sceneB ) {
 	
 	this.setTextureThreshold = function ( value ) {
 	
-		this.quadmaterial.uniforms.threshold.value=value;
+		this.quadmaterial.uniforms.threshold.value = value;
 
 	}
 	
 	this.useTexture = function ( value ) {
 	
-		this.quadmaterial.uniforms.useTexture.value = value?1:0;
+		this.quadmaterial.uniforms.useTexture.value = value ? 1 : 0;
 
 	}
 	
@@ -122,32 +122,32 @@ function Transition ( sceneA, sceneB ) {
 		// Transition animation
 		if (transitionParams.animateTransition)
 		{
-			var t=(1+Math.sin(transitionParams.transitionSpeed*clock.getElapsedTime()/Math.PI))/2;
-			transitionParams.transition=THREE.Math.smoothstep(t,0.3,0.7);
+			var t = (1 + Math.sin(transitionParams.transitionSpeed * clock.getElapsedTime() / Math.PI)) / 2;
+			transitionParams.transition = THREE.Math.smoothstep(t, 0.3, 0.7);
 			
 			// Change the current alpha texture after each transition
-			if (transitionParams.loopTexture && (transitionParams.transition==0 || transitionParams.transition==1))
+			if (transitionParams.loopTexture && (transitionParams.transition == 0 || transitionParams.transition == 1))
 			{
 				if (this.needChange)
 				{
-					transitionParams.texture=(transitionParams.texture+1)%this.textures.length;
+					transitionParams.texture = (transitionParams.texture + 1)%this.textures.length;
 					this.quadmaterial.uniforms.tMixTexture.value = this.textures[transitionParams.texture];
-					this.needChange=false;
+					this.needChange = false;
 				}
 			}	
 			else
-				this.needChange=true;
+				this.needChange = true;
 				
 		}
 		
 		this.quadmaterial.uniforms.mixRatio.value = transitionParams.transition;
 
 		// Prevent render both scenes when it's not necessary
-		if (transitionParams.transition==0) {
+		if (transitionParams.transition == 0) {
 			
 			this.sceneB.render( delta, false );
 		
-		} else if (transitionParams.transition==1) {
+		} else if (transitionParams.transition == 1) {
 		
 			this.sceneA.render( delta, false );
 			

+ 1 - 1
examples/js/curves/NURBSCurve.js

@@ -18,7 +18,7 @@ THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints
 	this.degree = degree;
 	this.knots = knots;
 	this.controlPoints = [];
-	for (var i = 0; i < controlPoints.length; ++i) { // ensure Vector4 for control points
+	for (var i = 0; i < controlPoints.length; ++ i) { // ensure Vector4 for control points
 		var point = controlPoints[i];
 		this.controlPoints[i] = new THREE.Vector4(point.x, point.y, point.z, point.w);
 	}

+ 2 - 2
examples/js/curves/NURBSSurface.js

@@ -23,9 +23,9 @@ THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of re
 	var len2 = knots2.length - degree2 - 1;
 
 	// ensure Vector4 for control points
-	for (var i = 0; i < len1; ++i) {
+	for (var i = 0; i < len1; ++ i) {
 		this.controlPoints[i] = []
-		for (var j = 0; j < len2; ++j) {
+		for (var j = 0; j < len2; ++ j) {
 			var point = controlPoints[i][j];
 			this.controlPoints[i][j] = new THREE.Vector4(point.x, point.y, point.z, point.w);
 		}

+ 29 - 29
examples/js/curves/NURBSUtils.js

@@ -68,14 +68,14 @@ THREE.NURBSUtils = {
 		var right = [];
 		N[0] = 1.0;
 
-		for (var j = 1; j <= p; ++j) {
+		for (var j = 1; j <= p; ++ j) {
 	   
 			left[j] = u - U[span + 1 - j];
 			right[j] = U[span + j] - u;
 
 			var saved = 0.0;
 
-			for (var r = 0; r < j; ++r) {
+			for (var r = 0; r < j; ++ r) {
 
 				var rv = right[r + 1];
 				var lv = left[j - r];
@@ -106,7 +106,7 @@ THREE.NURBSUtils = {
 		var N = this.calcBasisFunctions(span, u, p, U);
 		var C = new THREE.Vector4(0, 0, 0, 0);
 
-		for (var j = 0; j <= p; ++j) {
+		for (var j = 0; j <= p; ++ j) {
 			var point = P[span - p + j];
 			var Nj = N[j];
 			var wNj = point.w * Nj;
@@ -134,15 +134,15 @@ THREE.NURBSUtils = {
 	calcBasisFunctionDerivatives: function( span,  u,  p,  n,  U ) {
 
 		var zeroArr = [];
-		for (var i = 0; i <= p; ++i)
+		for (var i = 0; i <= p; ++ i)
 			zeroArr[i] = 0.0;
 
 		var ders = [];
-		for (var i = 0; i <= n; ++i)
+		for (var i = 0; i <= n; ++ i)
 			ders[i] = zeroArr.slice(0);
 
 		var ndu = [];
-		for (var i = 0; i <= p; ++i)
+		for (var i = 0; i <= p; ++ i)
 			ndu[i] = zeroArr.slice(0);
 
 		ndu[0][0] = 1.0;
@@ -150,13 +150,13 @@ THREE.NURBSUtils = {
 		var left = zeroArr.slice(0);
 		var right = zeroArr.slice(0);
 
-		for (var j = 1; j <= p; ++j) {
+		for (var j = 1; j <= p; ++ j) {
 			left[j] = u - U[span + 1 - j];
 			right[j] = U[span + j] - u;
 
 			var saved = 0.0;
 
-			for (var r = 0; r < j; ++r) {
+			for (var r = 0; r < j; ++ r) {
 				var rv = right[r + 1];
 				var lv = left[j - r];
 				ndu[j][r] = rv + lv;
@@ -169,21 +169,21 @@ THREE.NURBSUtils = {
 			ndu[j][j] = saved;
 		}
 
-		for (var j = 0; j <= p; ++j) {
+		for (var j = 0; j <= p; ++ j) {
 			ders[0][j] = ndu[j][p];
 		}
 
-		for (var r = 0; r <= p; ++r) {
+		for (var r = 0; r <= p; ++ r) {
 			var s1 = 0;
 			var s2 = 1;
 
 			var a = [];
-			for (var i = 0; i <= p; ++i) {
+			for (var i = 0; i <= p; ++ i) {
 				a[i] = zeroArr.slice(0);
 			}
 			a[0][0] = 1.0;
 
-			for (var k = 1; k <= n; ++k) {
+			for (var k = 1; k <= n; ++ k) {
 				var d = 0.0;
 				var rk = r - k;
 				var pk = p - k;
@@ -196,7 +196,7 @@ THREE.NURBSUtils = {
 				var j1 = (rk >= -1) ? 1 : -rk;
 				var j2 = (r - 1 <= pk) ? k - 1 :  p - r;
 
-				for (var j = j1; j <= j2; ++j) {
+				for (var j = j1; j <= j2; ++ j) {
 					a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][rk + j];
 					d += a[s2][j] * ndu[rk + j][pk];
 				}
@@ -216,8 +216,8 @@ THREE.NURBSUtils = {
 
 		var r = p;
 
-		for (var k = 1; k <= n; ++k) {
-			for (var j = 0; j <= p; ++j) {
+		for (var k = 1; k <= n; ++ k) {
+			for (var j = 0; j <= p; ++ j) {
 				ders[k][j] *= r;
 			}
 			r *= p - k;
@@ -245,7 +245,7 @@ THREE.NURBSUtils = {
 		var nders = this.calcBasisFunctionDerivatives(span, u, p, du, U);
 		var Pw = [];
 
-		for (var i = 0; i < P.length; ++i) {
+		for (var i = 0; i < P.length; ++ i) {
 			var point = P[i].clone();
 			var w = point.w;
 
@@ -255,17 +255,17 @@ THREE.NURBSUtils = {
 
 			Pw[i] = point;
 		}
-		for (var k = 0; k <= du; ++k) {
+		for (var k = 0; k <= du; ++ k) {
 			var point = Pw[span - p].clone().multiplyScalar(nders[k][0]);
 
-			for (var j = 1; j <= p; ++j) {
+			for (var j = 1; j <= p; ++ j) {
 				point.add(Pw[span - p + j].clone().multiplyScalar(nders[k][j]));
 			}
 
 			CK[k] = point;
 		}
 
-		for (var k = du + 1; k <= nd + 1; ++k) {
+		for (var k = du + 1; k <= nd + 1; ++ k) {
 			CK[k] = new THREE.Vector4(0, 0, 0);
 		}
 
@@ -281,17 +281,17 @@ THREE.NURBSUtils = {
 	calcKoverI: function( k, i ) {
 		var nom = 1;
 
-		for (var j = 2; j <= k; ++j) {
+		for (var j = 2; j <= k; ++ j) {
 			nom *= j;
 		}
 
 		var denom = 1;
 
-		for (var j = 2; j <= i; ++j) {
+		for (var j = 2; j <= i; ++ j) {
 			denom *= j;
 		}
 
-		for (var j = 2; j <= k - i; ++j) {
+		for (var j = 2; j <= k - i; ++ j) {
 			denom *= j;
 		}
 
@@ -311,7 +311,7 @@ THREE.NURBSUtils = {
 		var Aders = [];
 		var wders = [];
 
-		for (var i = 0; i < nd; ++i) {
+		for (var i = 0; i < nd; ++ i) {
 			var point = Pders[i];
 			Aders[i] = new THREE.Vector3(point.x, point.y, point.z);
 			wders[i] = point.w;
@@ -319,11 +319,11 @@ THREE.NURBSUtils = {
 
 		var CK = [];
 
-		for (var k = 0; k < nd; ++k) {
+		for (var k = 0; k < nd; ++ k) {
 			var v = Aders[k].clone();
 
-			for (var i = 1; i <= k; ++i) {
-				v.sub(CK[k - i].clone().multiplyScalar(this.calcKoverI(k,i) * wders[i]));
+			for (var i = 1; i <= k; ++ i) {
+				v.sub(CK[k - i].clone().multiplyScalar(this.calcKoverI(k, i) * wders[i]));
 			}
 
 			CK[k] = v.divideScalar(wders[0]);
@@ -367,9 +367,9 @@ THREE.NURBSUtils = {
 		var Nv = this.calcBasisFunctions(vspan, v, q, V);
 		var temp = [];
 
-		for (var l = 0; l <= q; ++l) {
+		for (var l = 0; l <= q; ++ l) {
 			temp[l] = new THREE.Vector4(0, 0, 0, 0);
-			for (var k = 0; k <= p; ++k) {
+			for (var k = 0; k <= p; ++ k) {
 				var point = P[uspan - p + k][vspan - q + l].clone();
 				var w = point.w;
 				point.x *= w;
@@ -380,7 +380,7 @@ THREE.NURBSUtils = {
 		}
 
 		var Sw = new THREE.Vector4(0, 0, 0, 0);
-		for (var l = 0; l <= q; ++l) {
+		for (var l = 0; l <= q; ++ l) {
 			Sw.add(temp[l].multiplyScalar(Nv[l]));
 		}
 

+ 13 - 13
examples/js/effects/AsciiEffect.js

@@ -96,8 +96,8 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 		var oStyle = oAscii.style;
 		oStyle.display = "inline";
-		oStyle.width = Math.round(iWidth/fResolution*iScale) + "px";
-		oStyle.height = Math.round(iHeight/fResolution*iScale) + "px";
+		oStyle.width = Math.round(iWidth / fResolution * iScale) + "px";
+		oStyle.height = Math.round(iHeight / fResolution * iScale) + "px";
 		oStyle.whiteSpace = "pre";
 		oStyle.margin = "0px";
 		oStyle.padding = "0px";
@@ -144,8 +144,8 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 	// Setup dom
 
-	var fFontSize = (2/fResolution)*iScale;
-	var fLineHeight = (2/fResolution)*iScale;
+	var fFontSize = (2 / fResolution) * iScale;
+	var fLineHeight = (2 / fResolution) * iScale;
 
 	// adjust letter-spacing for all combinations of scale and resolution to get it to fit the image width.
 
@@ -204,9 +204,9 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 		// console.time('rendering');
 
-		for (var y=0;y<iHeight;y+=2) {
-			for (var x=0;x<iWidth;x++) {
-				var iOffset = (y*iWidth + x) * 4;
+		for (var y = 0; y < iHeight; y+=2) {
+			for (var x = 0; x < iWidth; x ++) {
+				var iOffset = (y * iWidth + x) * 4;
 
 				var iRed = oImgData[iOffset];
 				var iGreen = oImgData[iOffset + 1];
@@ -216,7 +216,7 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 				var fBrightness;
 
-				fBrightness = (0.3*iRed + 0.59*iGreen + 0.11*iBlue) / 255;
+				fBrightness = (0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue) / 255;
 				// fBrightness = (0.3*iRed + 0.5*iGreen + 0.3*iBlue) / 255;
 
 				if (iAlpha == 0) {
@@ -226,7 +226,7 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 				}
 
-				iCharIdx = Math.floor((1-fBrightness) * (aCharList.length-1));
+				iCharIdx = Math.floor((1 - fBrightness) * (aCharList.length - 1));
 
 				if (bInvert) {
 					iCharIdx = aCharList.length - iCharIdx - 1;
@@ -238,14 +238,14 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 				var strThisChar = aCharList[iCharIdx];
 
-				if (strThisChar===undefined || strThisChar == " ")
+				if (strThisChar === undefined || strThisChar == " ")
 					strThisChar = "&nbsp;";
 
 				if (bColor) {
 					strChars += "<span style='"
-						+ "color:rgb("+iRed+","+iGreen+","+iBlue+");"
-						+ (bBlock ? "background-color:rgb("+iRed+","+iGreen+","+iBlue+");" : "")
-						+ (bAlpha ? "opacity:" + (iAlpha/255) + ";" : "")
+						+ "color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");"
+						+ (bBlock ? "background-color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");" : "")
+						+ (bAlpha ? "opacity:" + (iAlpha / 255) + ";" : "")
 						+ "'>" + strThisChar + "</span>";
 				} else {
 					strChars += strThisChar;

+ 23 - 23
examples/js/effects/VREffect.js

@@ -43,7 +43,7 @@ THREE.VREffect = function ( renderer, done ) {
 		function gotVRDevices( devices ) {
 			var vrHMD;
 			var error;
-			for ( var i = 0; i < devices.length; ++i ) {
+			for ( var i = 0; i < devices.length; ++ i ) {
 				if ( devices[i] instanceof HMDVRDevice ) {
 					vrHMD = devices[i];
 					self._vrHMD = vrHMD;
@@ -56,7 +56,7 @@ THREE.VREffect = function ( renderer, done ) {
 			}
 			if ( done ) {
 				if ( !vrHMD ) {
-				 error = 'HMD not available';
+					error = 'HMD not available';
 				}
 				done( error );
 			}
@@ -82,8 +82,8 @@ THREE.VREffect = function ( renderer, done ) {
 		var leftEyeTranslation = this.leftEyeTranslation;
 		var rightEyeTranslation = this.rightEyeTranslation;
 		var renderer = this._renderer;
-		var rendererWidth = renderer.domElement.clientWidth;
-		var rendererHeight = renderer.domElement.clientHeight;
+		var rendererWidth = renderer.context.drawingBufferWidth;
+		var rendererHeight = renderer.context.drawingBufferHeight;
 		var eyeDivisionLine = rendererWidth / 2;
 
 		renderer.enableScissorTest( true );
@@ -155,7 +155,7 @@ THREE.VREffect = function ( renderer, done ) {
 		var vrHMD = this._vrHMD;
 		var canvas = renderer.domElement;
 		var fullScreenChange =
-			canvas.mozRequestFullScreen? 'mozfullscreenchange' : 'webkitfullscreenchange';
+			canvas.mozRequestFullScreen ? 'mozfullscreenchange' : 'webkitfullscreenchange';
 
 		document.addEventListener( fullScreenChange, onFullScreenChanged, false );
 		function onFullScreenChanged() {
@@ -165,7 +165,7 @@ THREE.VREffect = function ( renderer, done ) {
 		}
 		if ( canvas.mozRequestFullScreen ) {
 			canvas.mozRequestFullScreen( { vrDisplay: vrHMD } );
-		} else {
+		} else if ( canvas.webkitRequestFullscreen ) {
 			canvas.webkitRequestFullscreen( { vrDisplay: vrHMD } );
 		}
 	};
@@ -175,7 +175,7 @@ THREE.VREffect = function ( renderer, done ) {
 		var pxoffset = (fov.leftTan - fov.rightTan) * pxscale * 0.5;
 		var pyscale = 2.0 / (fov.upTan + fov.downTan);
 		var pyoffset = (fov.upTan - fov.downTan) * pyscale * 0.5;
-		return { scale: [pxscale, pyscale], offset: [pxoffset, pyoffset] };
+		return { scale: [ pxscale, pyscale ], offset: [ pxoffset, pyoffset ] };
 	};
 
 	this.FovPortToProjection = function( fov, rightHanded /* = true */, zNear /* = 0.01 */, zFar /* = 10000.0 */ )
@@ -194,30 +194,30 @@ THREE.VREffect = function ( renderer, done ) {
 		var scaleAndOffset = this.FovToNDCScaleOffset(fov);
 
 		// X result, map clip edges to [-w,+w]
-		m[0*4+0] = scaleAndOffset.scale[0];
-		m[0*4+1] = 0.0;
-		m[0*4+2] = scaleAndOffset.offset[0] * handednessScale;
-		m[0*4+3] = 0.0;
+		m[0 * 4 + 0] = scaleAndOffset.scale[0];
+		m[0 * 4 + 1] = 0.0;
+		m[0 * 4 + 2] = scaleAndOffset.offset[0] * handednessScale;
+		m[0 * 4 + 3] = 0.0;
 
 		// Y result, map clip edges to [-w,+w]
 		// Y offset is negated because this proj matrix transforms from world coords with Y=up,
 		// but the NDC scaling has Y=down (thanks D3D?)
-		m[1*4+0] = 0.0;
-		m[1*4+1] = scaleAndOffset.scale[1];
-		m[1*4+2] = -scaleAndOffset.offset[1] * handednessScale;
-		m[1*4+3] = 0.0;
+		m[1 * 4 + 0] = 0.0;
+		m[1 * 4 + 1] = scaleAndOffset.scale[1];
+		m[1 * 4 + 2] = -scaleAndOffset.offset[1] * handednessScale;
+		m[1 * 4 + 3] = 0.0;
 
 		// Z result (up to the app)
-		m[2*4+0] = 0.0;
-		m[2*4+1] = 0.0;
-		m[2*4+2] = zFar / (zNear - zFar) * -handednessScale;
-		m[2*4+3] = (zFar * zNear) / (zNear - zFar);
+		m[2 * 4 + 0] = 0.0;
+		m[2 * 4 + 1] = 0.0;
+		m[2 * 4 + 2] = zFar / (zNear - zFar) * -handednessScale;
+		m[2 * 4 + 3] = (zFar * zNear) / (zNear - zFar);
 
 		// W result (= Z in)
-		m[3*4+0] = 0.0;
-		m[3*4+1] = 0.0;
-		m[3*4+2] = handednessScale;
-		m[3*4+3] = 0.0;
+		m[3 * 4 + 0] = 0.0;
+		m[3 * 4 + 1] = 0.0;
+		m[3 * 4 + 2] = handednessScale;
+		m[3 * 4 + 3] = 0.0;
 
 		mobj.transpose();
 

+ 16 - 14
examples/js/exporters/SceneExporter.js

@@ -182,7 +182,7 @@ THREE.SceneExporter.prototype = {
 
 		function NumConstantString( c ) {
 
-			var constants = [ "NearestFilter", "NearestMipMapNearestFilter" , "NearestMipMapLinearFilter",
+			var constants = [ "NearestFilter", "NearestMipMapNearestFilter", "NearestMipMapLinearFilter",
 							  "LinearFilter", "LinearMipMapNearestFilter", "LinearMipMapLinearFilter" ];
 
 			for ( var i = 0; i < constants.length; i ++ ) {
@@ -238,11 +238,12 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type"      : "PointLight",',
-				'	"color"     : ' + o.color.getHex() + ',',
-				'	"intensity" : ' + o.intensity + ',',
-				'	"position"  : ' + Vector3String( o.position ) + ',',
-				'	"distance"  : ' + o.distance + ( o.children.length ? ',' : '' )
+				'	"type"           : "PointLight",',
+				'	"color"          : ' + o.color.getHex() + ',',
+				'	"intensity"      : ' + o.intensity + ',',
+				'	"position"       : ' + Vector3String( o.position ) + ',',
+				'	"decay"          : ' + o.decay + ',',
+				'	"distance"       : ' + o.distance + ( o.children.length ? ',' : '' )
 
 				];
 
@@ -251,14 +252,15 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type"      : "SpotLight",',
-				'	"color"     : ' + o.color.getHex() + ',',
-				'	"intensity" : ' + o.intensity + ',',
-				'	"position"  : ' + Vector3String( o.position ) + ',',
-				'	"distance"  : ' + o.distance + ',',
-				'	"angle"     : ' + o.angle + ',',
-				'	"exponent"  : ' + o.exponent + ',',
-				'	"target"    : ' + LabelString( getObjectName( o.target ) ) + ( o.children.length ? ',' : '' )
+				'	"type"           : "SpotLight",',
+				'	"color"          : ' + o.color.getHex() + ',',
+				'	"intensity"      : ' + o.intensity + ',',
+				'	"position"       : ' + Vector3String( o.position ) + ',',
+				'	"distance"       : ' + o.distance + ',',
+				'	"angle"          : ' + o.angle + ',',
+				'	"exponent"       : ' + o.exponent + ',',
+				'	"decay"          : ' + o.decay + ',',
+				'	"target"         : ' + LabelString( getObjectName( o.target ) ) + ( o.children.length ? ',' : '' )
 
 				];
 

+ 14 - 14
examples/js/geometries/ConvexGeometry.js

@@ -23,7 +23,7 @@ THREE.ConvexGeometry = function( vertices ) {
 
 	var faces = [ [ 0, 1, 2 ], [ 0, 2, 1 ] ]; 
 
-	for ( var i = 3; i < vertices.length; i++ ) {
+	for ( var i = 3; i < vertices.length; i ++ ) {
 
 		addPoint( i );
 
@@ -49,13 +49,13 @@ THREE.ConvexGeometry = function( vertices ) {
 			// then we try to add the face's edges into the hole.
 			if ( visible( face, vertex ) ) {
 
-				for ( var e = 0; e < 3; e++ ) {
+				for ( var e = 0; e < 3; e ++ ) {
 
 					var edge = [ face[ e ], face[ ( e + 1 ) % 3 ] ];
 					var boundary = true;
 
 					// remove duplicated edges.
-					for ( var h = 0; h < hole.length; h++ ) {
+					for ( var h = 0; h < hole.length; h ++ ) {
 
 						if ( equalEdge( hole[ h ], edge ) ) {
 
@@ -82,13 +82,13 @@ THREE.ConvexGeometry = function( vertices ) {
 
 			} else { // not visible
 
-				f++;
+				f ++;
 
 			}
 		}
 
 		// construct the new faces formed by the edges of the hole and the vertex
-		for ( var h = 0; h < hole.length; h++ ) {
+		for ( var h = 0; h < hole.length; h ++ ) {
 
 			faces.push( [ 
 				hole[ h ][ 0 ],
@@ -170,27 +170,27 @@ THREE.ConvexGeometry = function( vertices ) {
 	var id = 0;
 	var newId = new Array( vertices.length ); // map from old vertex id to new id
 
-	for ( var i = 0; i < faces.length; i++ ) {
+	for ( var i = 0; i < faces.length; i ++ ) {
 
 		 var face = faces[ i ];
 
-		 for ( var j = 0; j < 3; j++ ) {
+		 for ( var j = 0; j < 3; j ++ ) {
 
-				if ( newId[ face[ j ] ] === undefined ) {
+			if ( newId[ face[ j ] ] === undefined ) {
 
-						newId[ face[ j ] ] = id++;
-						this.vertices.push( vertices[ face[ j ] ] );
+				newId[ face[ j ] ] = id ++;
+				this.vertices.push( vertices[ face[ j ] ] );
 
-				}
+			}
 
-				face[ j ] = newId[ face[ j ] ];
+			face[ j ] = newId[ face[ j ] ];
 
 		 }
 
 	}
 
 	// Convert faces into instances of THREE.Face3
-	for ( var i = 0; i < faces.length; i++ ) {
+	for ( var i = 0; i < faces.length; i ++ ) {
 
 		this.faces.push( new THREE.Face3( 
 				faces[ i ][ 0 ],
@@ -201,7 +201,7 @@ THREE.ConvexGeometry = function( vertices ) {
 	}
 
 	// Compute UVs
-	for ( var i = 0; i < this.faces.length; i++ ) {
+	for ( var i = 0; i < this.faces.length; i ++ ) {
 
 		var face = this.faces[ i ];
 

+ 23 - 23
examples/js/geometries/DecalGeometry.js

@@ -15,7 +15,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 
 	THREE.Geometry.call( this );
 
-	if( check === undefined ) check = null;
+	if ( check === undefined ) check = null;
 	check = check || new THREE.Vector3( 1, 1, 1 );
 
 	this.uvs = [];
@@ -60,10 +60,10 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 
 		}
 
-		if( inVertices.length === 0 ) return [];
+		if ( inVertices.length === 0 ) return [];
 		var outVertices = [];
 
-		for( var j = 0; j < inVertices.length; j += 3 ) {
+		for ( var j = 0; j < inVertices.length; j += 3 ) {
 
 			var v1Out, v2Out, v3Out, total = 0;
 
@@ -75,24 +75,24 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 			v2Out = d2 > 0;
 			v3Out = d3 > 0;
 
-			total = ( v1Out?1:0 ) + ( v2Out?1:0 ) + ( v3Out?1:0 );
+			total = ( v1Out ? 1 : 0 ) + ( v2Out ? 1 : 0 ) + ( v3Out ? 1 : 0 );
 
-			switch( total ) {
-				case 0:{
+			switch ( total ) {
+				case 0: {
 					outVertices.push( inVertices[ j ] );
 					outVertices.push( inVertices[ j + 1 ] );
 					outVertices.push( inVertices[ j + 2 ] );
 					break;
 				}
-				case 1:{
+				case 1: {
 					var nV1, nV2, nV3;
-					if( v1Out ) {
+					if ( v1Out ) {
 						nV1 = inVertices[ j + 1 ]; 
 						nV2 = inVertices[ j + 2 ];
 						nV3 = clip( inVertices[ j ], nV1, plane );
 						nV4 = clip( inVertices[ j ], nV2, plane );
 					}
-					if( v2Out ) { 
+					if ( v2Out ) { 
 						nV1 = inVertices[ j ]; 
 						nV2 = inVertices[ j + 2 ];
 						nV3 = clip( inVertices[ j + 1 ], nV1, plane );
@@ -107,7 +107,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 						outVertices.push( nV4 );
 						break;
 					}
-					if( v3Out ) { 
+					if ( v3Out ) { 
 						nV1 = inVertices[ j ]; 
 						nV2 = inVertices[ j + 1 ];
 						nV3 = clip( inVertices[ j + 2 ], nV1, plane );
@@ -126,7 +126,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 				}
 				case 2: {
 					var nV1, nV2, nV3;
-					if( !v1Out ) { 
+					if ( !v1Out ) { 
 						nV1 = inVertices[ j ].clone();
 						nV2 = clip( nV1, inVertices[ j + 1 ], plane );
 						nV3 = clip( nV1, inVertices[ j + 2 ], plane ); 
@@ -134,7 +134,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 						outVertices.push( nV2 );
 						outVertices.push( nV3 );
 					}
-					if( !v2Out ) { 
+					if ( !v2Out ) { 
 						nV1 = inVertices[ j + 1 ].clone();
 						nV2 = clip( nV1, inVertices[ j + 2 ], plane );
 						nV3 = clip( nV1, inVertices[ j ], plane );
@@ -142,7 +142,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 						outVertices.push( nV2 );
 						outVertices.push( nV3 );
 					}
-					if( !v3Out ) {
+					if ( !v3Out ) {
 						nV1 = inVertices[ j + 2 ].clone();
 						nV2 = clip( nV1, inVertices[ j ], plane );
 						nV3 = clip( nV1, inVertices[ j + 1 ], plane );
@@ -164,7 +164,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 
 	}
 
-	this.pushVertex = function( vertices, id, n ){
+	this.pushVertex = function( vertices, id, n ) {
 
 		var v = mesh.geometry.vertices[ id ].clone();
 		v.applyMatrix4( mesh.matrix );
@@ -177,7 +177,7 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 
 		var finalVertices = [];
 
-		for( var i = 0; i < mesh.geometry.faces.length; i++ ) {
+		for ( var i = 0; i < mesh.geometry.faces.length; i ++ ) {
 
 			var f = mesh.geometry.faces[ i ];
 			var vertices = [];
@@ -186,20 +186,20 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 			this.pushVertex( vertices, f[ this.faceIndices[ 1 ] ], f.vertexNormals[ 1 ] );
 			this.pushVertex( vertices, f[ this.faceIndices[ 2 ] ], f.vertexNormals[ 2 ] );
 
-			if( check.x ) {
+			if ( check.x ) {
 				vertices = this.clipFace( vertices, new THREE.Vector3( 1, 0, 0 ) );
 				vertices = this.clipFace( vertices, new THREE.Vector3( -1, 0, 0 ) );
 			}
-			if( check.y ) {
-			   	vertices = this.clipFace( vertices, new THREE.Vector3( 0, 1, 0 ) );
-			   	vertices = this.clipFace( vertices, new THREE.Vector3( 0, -1, 0 ) );
+			if ( check.y ) {
+				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 1, 0 ) );
+				vertices = this.clipFace( vertices, new THREE.Vector3( 0, -1, 0 ) );
 			}
-			if( check.z ) {
+			if ( check.z ) {
 				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, 1 ) );
 				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, -1 ) );
 			}
 
-			for( var j = 0; j < vertices.length; j++ ) {
+			for ( var j = 0; j < vertices.length; j ++ ) {
 
 				var v = vertices[ j ];
 
@@ -212,13 +212,13 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 
 			}
 
-			if( vertices.length === 0 ) continue;
+			if ( vertices.length === 0 ) continue;
 
 			finalVertices = finalVertices.concat( vertices );
 
 		}
 
-		for( var k = 0; k < finalVertices.length; k += 3 ) {
+		for ( var k = 0; k < finalVertices.length; k += 3 ) {
 			
 			this.vertices.push(
 				finalVertices[ k ].vertex,

+ 1 - 1
examples/js/geometries/hilbert2D.js

@@ -42,7 +42,7 @@ function hilbert2D (center, size, iterations, v0, v1, v2, v3) {
 	];
 
 	// Recurse iterations
-	if (0 <= --iterations) {
+	if (0 <= -- iterations) {
 		var tmp = [];
 
 		Array.prototype.push.apply( tmp, hilbert2D ( vec[ 0 ], half, iterations, v0, v3, v2, v1 ) );

+ 1 - 1
examples/js/geometries/hilbert3D.js

@@ -63,7 +63,7 @@ function hilbert3D(center, size, iterations, v0, v1, v2, v3, v4, v5, v6, v7) {
 	];
 
 	// Recurse iterations
-	if( --iterations >= 0 ) {
+	if ( -- iterations >= 0 ) {
 		var tmp = [];
 
 		Array.prototype.push.apply( tmp, hilbert3D ( vec[ 0 ], half, iterations, v0, v3, v4, v7, v6, v5, v2, v1 ) );

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 348 - 348
examples/js/loaders/AWDLoader.js


+ 27 - 27
examples/js/loaders/AssimpJSONLoader.js

@@ -74,7 +74,7 @@ THREE.AssimpJSONLoader.prototype = {
 
 	parseList : function(json, handler) {
 		var meshes = new Array(json.length);
-		for(var i = 0; i < json.length; ++i) {
+		for (var i = 0; i < json.length; ++ i) {
 			meshes[i] = handler.call(this, json[i]);
 		}
 		return meshes;
@@ -87,13 +87,13 @@ THREE.AssimpJSONLoader.prototype = {
 		geometry = new THREE.Geometry();
 
 		// read vertex positions
-		for(in_data = json.vertices, i = 0, e = in_data.length; i < e; ) {
-			geometry.vertices.push( new THREE.Vector3( in_data[ i++ ], in_data[ i++ ], in_data[ i++ ] ) );
+		for (in_data = json.vertices, i = 0, e = in_data.length; i < e; ) {
+			geometry.vertices.push( new THREE.Vector3( in_data[ i ++ ], in_data[ i ++ ], in_data[ i ++ ] ) );
 		}
 
 		// read faces
 		var cnt = 0;
-		for(in_data = json.faces, i = 0, e = in_data.length; i < e; ++i) {
+		for (in_data = json.faces, i = 0, e = in_data.length; i < e; ++ i) {
 			face = new THREE.Face3();
 			src = in_data[i];
 			face.a = src[0];
@@ -106,12 +106,12 @@ THREE.AssimpJSONLoader.prototype = {
 
 		// read texture coordinates - three.js attaches them to its faces
 		json.texturecoords = json.texturecoords || [];
-		for(i = 0, e = json.texturecoords.length; i < e; ++i) {
+		for (i = 0, e = json.texturecoords.length; i < e; ++ i) {
 
 			function convertTextureCoords(in_uv, out_faces, out_vertex_uvs) {
 				var i, e, face, a, b, c;
 
-				for(i = 0, e = out_faces.length; i < e; ++i) {
+				for (i = 0, e = out_faces.length; i < e; ++ i) {
 					face = out_faces[i];
 					a = face.a * 2;
 					b = face.b * 2;
@@ -128,12 +128,12 @@ THREE.AssimpJSONLoader.prototype = {
 		}
 
 		// read normals - three.js also attaches them to its faces
-		if(json.normals) {
+		if (json.normals) {
 
 			function convertNormals(in_nor, out_faces) {
 				var i, e, face, a, b, c;
 
-				for(i = 0, e = out_faces.length; i < e; ++i) {
+				for (i = 0, e = out_faces.length; i < e; ++ i) {
 					face = out_faces[i];
 					a = face.a * 3;
 					b = face.b * 3;
@@ -150,7 +150,7 @@ THREE.AssimpJSONLoader.prototype = {
 		}
 
 		// read vertex colors - three.js also attaches them to its faces
-		if(json.colors && json.colors[0]) {
+		if (json.colors && json.colors[0]) {
 
 			function convertColors(in_color, out_faces) {
 				var i, e, face, a, b, c;
@@ -162,7 +162,7 @@ THREE.AssimpJSONLoader.prototype = {
 					return col;
 				}
 
-				for(i = 0, e = out_faces.length; i < e; ++i) {
+				for (i = 0, e = out_faces.length; i < e; ++ i) {
 					face = out_faces[i];
 					a = face.a * 4;
 					b = face.b * 4;
@@ -198,7 +198,7 @@ THREE.AssimpJSONLoader.prototype = {
 
 		function toColor(value_arr) {
 			var col = new THREE.Color();
-			col.setRGB(value_arr[0],value_arr[1],value_arr[2]);
+			col.setRGB(value_arr[0], value_arr[1], value_arr[2]);
 			return col;
 		}
 
@@ -212,28 +212,28 @@ THREE.AssimpJSONLoader.prototype = {
 		for (var i in json.properties) {
 			prop = json.properties[i];
 
-			if(prop.key === '$tex.file') {
+			if (prop.key === '$tex.file') {
 				// prop.semantic gives the type of the texture
 				// 1: diffuse
 				// 2: specular mao
 				// 5: height map (bumps)
 				// 6: normal map
 				// more values (i.e. emissive, environment) are known by assimp and may be relevant
-				if(prop.semantic === 1 || prop.semantic === 5 || prop.semantic === 6 || prop.semantic === 2) {
+				if (prop.semantic === 1 || prop.semantic === 5 || prop.semantic === 6 || prop.semantic === 2) {
 					(function(semantic) {
 						var loader = new THREE.TextureLoader(scope.manager),
 						keyname;
 
-						if(semantic === 1) {
+						if (semantic === 1) {
 							keyname = 'map';
 						}
-						else if(semantic === 5) {
+						else if (semantic === 5) {
 							keyname = 'bumpMap';
 						}
-						else if(semantic === 6) {
+						else if (semantic === 6) {
 							keyname = 'normalMap';
 						}
-						else if(semantic === 2) {
+						else if (semantic === 2) {
 							keyname = 'specularMap';
 						}
 
@@ -243,7 +243,7 @@ THREE.AssimpJSONLoader.prototype = {
 						var material_url = scope.texturePath + '/' + prop.value
 						material_url = material_url.replace(/\\/g, '/');
 						loader.load(material_url, function(tex) {
-							if(tex) {
+							if (tex) {
 								// TODO: read texture settings from assimp.
 								// Wrapping is the default, though.
 								tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
@@ -255,19 +255,19 @@ THREE.AssimpJSONLoader.prototype = {
 					})(prop.semantic);
 				}
 			}
-			else if(prop.key === '?mat.name') {
+			else if (prop.key === '?mat.name') {
 				init_props.name = prop.value;
 			}
-			else if(prop.key === '$clr.diffuse') {
+			else if (prop.key === '$clr.diffuse') {
 				init_props.color = toColor(prop.value);
 			}
-			else if(prop.key === '$clr.specular') {
+			else if (prop.key === '$clr.specular') {
 				init_props.specular = toColor(prop.value);
 			}
-			else if(prop.key === '$clr.emissive') {
+			else if (prop.key === '$clr.emissive') {
 				init_props.emissive = toColor(prop.value);
 			}
-			else if(prop.key === '$mat.shadingm') {
+			else if (prop.key === '$mat.shadingm') {
 				// aiShadingMode_Flat
 				if (prop.value === 1) {
 					init_props.shading = THREE.FlatShading;
@@ -281,8 +281,8 @@ THREE.AssimpJSONLoader.prototype = {
 		// note: three.js does not like it when a texture is added after the geometry
 		// has been rendered once, see http://stackoverflow.com/questions/16531759/.
 		// for this reason we fill all slots upfront with default textures
-		if(has_textures.length) {
-			for(i = has_textures.length-1; i >= 0; --i) {
+		if (has_textures.length) {
+			for (i = has_textures.length - 1; i >= 0; -- i) {
 				init_props[has_textures[i]] = defaultTexture();
 			}
 		}
@@ -301,12 +301,12 @@ THREE.AssimpJSONLoader.prototype = {
 		obj.matrix = new THREE.Matrix4().fromArray(node.transformation).transpose();
 		obj.matrix.decompose( obj.position, obj.quaternion, obj.scale );
 
-		for(i = 0; node.meshes && i < node.meshes.length; ++i) {
+		for (i = 0; node.meshes && i < node.meshes.length; ++ i) {
 			idx = node.meshes[i];
 			obj.add(new THREE.Mesh( meshes[idx], materials[json.meshes[idx].materialindex] ));
 		}
 
-		for(i = 0; node.children && i < node.children.length; ++i) {
+		for (i = 0; node.children && i < node.children.length; ++ i) {
 			obj.add(this.parseObject(json, node.children[i], meshes, materials));
 		}
 

+ 56 - 56
examples/js/loaders/BinaryLoader.js

@@ -192,7 +192,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 		start_quad_flat     = start_tri_smooth_uv + len_tri_smooth_uv  + handlePadding( md.ntri_smooth_uv * 2 );
 		start_quad_smooth   = start_quad_flat     + len_quad_flat	   + handlePadding( md.nquad_flat * 2 );
 		start_quad_flat_uv  = start_quad_smooth   + len_quad_smooth    + handlePadding( md.nquad_smooth * 2 );
-		start_quad_smooth_uv= start_quad_flat_uv  + len_quad_flat_uv   + handlePadding( md.nquad_flat_uv * 2 );
+		start_quad_smooth_uv = start_quad_flat_uv  + len_quad_flat_uv   + handlePadding( md.nquad_flat_uv * 2 );
 
 		// have to first process faces with uvs
 		// so that face and uv indices match
@@ -236,18 +236,18 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 				'material_index_bytes'    :parseUChar8( data, offset + 19 ),
 
 				'nvertices'    :parseUInt32( data, offset + 20 ),
-				'nnormals'     :parseUInt32( data, offset + 20 + 4*1 ),
-				'nuvs'         :parseUInt32( data, offset + 20 + 4*2 ),
+				'nnormals'     :parseUInt32( data, offset + 20 + 4 * 1 ),
+				'nuvs'         :parseUInt32( data, offset + 20 + 4 * 2 ),
 
-				'ntri_flat'      :parseUInt32( data, offset + 20 + 4*3 ),
-				'ntri_smooth'    :parseUInt32( data, offset + 20 + 4*4 ),
-				'ntri_flat_uv'   :parseUInt32( data, offset + 20 + 4*5 ),
-				'ntri_smooth_uv' :parseUInt32( data, offset + 20 + 4*6 ),
+				'ntri_flat'      :parseUInt32( data, offset + 20 + 4 * 3 ),
+				'ntri_smooth'    :parseUInt32( data, offset + 20 + 4 * 4 ),
+				'ntri_flat_uv'   :parseUInt32( data, offset + 20 + 4 * 5 ),
+				'ntri_smooth_uv' :parseUInt32( data, offset + 20 + 4 * 6 ),
 
-				'nquad_flat'      :parseUInt32( data, offset + 20 + 4*7 ),
-				'nquad_smooth'    :parseUInt32( data, offset + 20 + 4*8 ),
-				'nquad_flat_uv'   :parseUInt32( data, offset + 20 + 4*9 ),
-				'nquad_smooth_uv' :parseUInt32( data, offset + 20 + 4*10 )
+				'nquad_flat'      :parseUInt32( data, offset + 20 + 4 * 7 ),
+				'nquad_smooth'    :parseUInt32( data, offset + 20 + 4 * 8 ),
+				'nquad_flat_uv'   :parseUInt32( data, offset + 20 + 4 * 9 ),
+				'nquad_smooth_uv' :parseUInt32( data, offset + 20 + 4 * 10 )
 
 			};
 /*
@@ -336,7 +336,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 			var i, x, y, z;
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				x = coordArray[ i * 3 ];
 				y = coordArray[ i * 3 + 1 ];
@@ -360,13 +360,13 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 				var i, x, y, z;
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					x = normalArray[ i * 3 ];
 					y = normalArray[ i * 3 + 1 ];
 					z = normalArray[ i * 3 + 2 ];
 
-					normals.push( x/127, y/127, z/127 );
+					normals.push( x / 127, y / 127, z / 127 );
 
 				}
 
@@ -386,7 +386,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 				var i, u, v;
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					u = uvArray[ i * 2 ];
 					v = uvArray[ i * 2 + 1 ];
@@ -407,20 +407,20 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 			var uvIndexBuffer = new Uint32Array( data, offset, 3 * nElements );
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				uva = uvIndexBuffer[ i * 3 ];
 				uvb = uvIndexBuffer[ i * 3 + 1 ];
 				uvc = uvIndexBuffer[ i * 3 + 2 ];
 
-				u1 = uvs[ uva*2 ];
-				v1 = uvs[ uva*2 + 1 ];
+				u1 = uvs[ uva * 2 ];
+				v1 = uvs[ uva * 2 + 1 ];
 
-				u2 = uvs[ uvb*2 ];
-				v2 = uvs[ uvb*2 + 1 ];
+				u2 = uvs[ uvb * 2 ];
+				v2 = uvs[ uvb * 2 + 1 ];
 
-				u3 = uvs[ uvc*2 ];
-				v3 = uvs[ uvc*2 + 1 ];
+				u3 = uvs[ uvc * 2 ];
+				v3 = uvs[ uvc * 2 + 1 ];
 
 				scope.faceVertexUvs[ 0 ].push( [
 					new THREE.Vector2( u1, v1 ),
@@ -438,24 +438,24 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 			var uvIndexBuffer = new Uint32Array( data, offset, 4 * nElements );
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				uva = uvIndexBuffer[ i * 4 ];
 				uvb = uvIndexBuffer[ i * 4 + 1 ];
 				uvc = uvIndexBuffer[ i * 4 + 2 ];
 				uvd = uvIndexBuffer[ i * 4 + 3 ];
 
-				u1 = uvs[ uva*2 ];
-				v1 = uvs[ uva*2 + 1 ];
+				u1 = uvs[ uva * 2 ];
+				v1 = uvs[ uva * 2 + 1 ];
 
-				u2 = uvs[ uvb*2 ];
-				v2 = uvs[ uvb*2 + 1 ];
+				u2 = uvs[ uvb * 2 ];
+				v2 = uvs[ uvb * 2 + 1 ];
 
-				u3 = uvs[ uvc*2 ];
-				v3 = uvs[ uvc*2 + 1 ];
+				u3 = uvs[ uvc * 2 ];
+				v3 = uvs[ uvc * 2 + 1 ];
 
-				u4 = uvs[ uvd*2 ];
-				v4 = uvs[ uvd*2 + 1 ];
+				u4 = uvs[ uvd * 2 ];
+				v4 = uvs[ uvd * 2 + 1 ];
 
 				scope.faceVertexUvs[ 0 ].push( [
 					new THREE.Vector2( u1, v1 ),
@@ -480,7 +480,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 			var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 3 * nElements );
 			var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				a = vertexIndexBuffer[ i * 3 ];
 				b = vertexIndexBuffer[ i * 3 + 1 ];
@@ -501,7 +501,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 			var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 4 * nElements );
 			var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				a = vertexIndexBuffer[ i * 4 ];
 				b = vertexIndexBuffer[ i * 4 + 1 ];
@@ -526,7 +526,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 			var normalIndexBuffer = new Uint32Array( data, offsetNormals, 3 * nElements );
 			var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				a = vertexIndexBuffer[ i * 3 ];
 				b = vertexIndexBuffer[ i * 3 + 1 ];
@@ -538,17 +538,17 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 				m = materialIndexBuffer[ i ];
 
-				var nax = normals[ na*3     ],
-					nay = normals[ na*3 + 1 ],
-					naz = normals[ na*3 + 2 ],
+				var 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 ],
+					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 ];
+					ncx = normals[ nc * 3     ],
+					ncy = normals[ nc * 3 + 1 ],
+					ncz = normals[ nc * 3 + 2 ];
 
 				scope.faces.push( new THREE.Face3( a, b, c, [
 					new THREE.Vector3( nax, nay, naz ),
@@ -569,7 +569,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 			var normalIndexBuffer = new Uint32Array( data, offsetNormals, 4 * nElements );
 			var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-			for( i = 0; i < nElements; i ++ ) {
+			for ( i = 0; i < nElements; i ++ ) {
 
 				a = vertexIndexBuffer[ i * 4 ];
 				b = vertexIndexBuffer[ i * 4 + 1 ];
@@ -583,21 +583,21 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 				m = materialIndexBuffer[ i ];
 
-				var nax = normals[ na*3     ],
-					nay = normals[ na*3 + 1 ],
-					naz = normals[ na*3 + 2 ],
+				var 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 ],
+					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 ],
+					ncx = normals[ nc * 3     ],
+					ncy = normals[ nc * 3 + 1 ],
+					ncz = normals[ nc * 3 + 2 ],
 
-					ndx = normals[ nd*3     ],
-					ndy = normals[ nd*3 + 1 ],
-					ndz = normals[ nd*3 + 2 ];
+					ndx = normals[ nd * 3     ],
+					ndy = normals[ nd * 3 + 1 ],
+					ndz = normals[ nd * 3 + 2 ];
 
 				scope.faces.push( new THREE.Face3( a, b, d, [
 					new THREE.Vector3( nax, nay, naz ),

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است