Browse Source

Merged remote branch 'upstream/master' (original mrdoob's version)

alteredq 15 years ago
parent
commit
ce000d482f

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


File diff suppressed because it is too large
+ 0 - 0
build/ThreeDebug.js


+ 1 - 1
examples/camera_free.html

@@ -150,7 +150,6 @@
 
 				// Lights
 
-
 				var ambientLight = new THREE.AmbientLight( Math.random() * 0x202020 );
 				scene.addLight( ambientLight );
 
@@ -164,6 +163,7 @@
 				var pointLight = new THREE.PointLight( 0xff0000, 1 );
 				scene.addLight( pointLight );
 
+
 				renderer = new THREE.CanvasRenderer();
 				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
 

+ 136 - 49
src/renderers/CanvasRenderer.js

@@ -14,6 +14,7 @@ THREE.CanvasRenderer = function () {
 	_clearRect = new THREE.Rectangle(),
 	_bboxRect = new THREE.Rectangle(),
 
+	_enableLighting = false,
 	_color = new THREE.Color( 0xffffffff ),
 	_light = new THREE.Color( 0xffffffff ),
 	_ambientLight = new THREE.Color( 0xffffffff ),
@@ -81,7 +82,13 @@ THREE.CanvasRenderer = function () {
 		_context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() );
 		*/
 
-		calculateAmbientLight( scene, _ambientLight );
+		_enableLighting = scene.lights.length > 0;
+
+		if ( _enableLighting ) {
+
+			calculateAmbientLight( scene, _ambientLight );
+
+		}
 
 		for ( e = 0, el = _renderList.length; e < el; e++ ) {
 
@@ -99,11 +106,19 @@ THREE.CanvasRenderer = function () {
 
 					if ( material instanceof THREE.ParticleCircleMaterial ) {
 
-						_light.copyRGB( _ambientLight );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+
+							_color.copyRGBA( material.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
+
+						} else {
 
-						_color.copyRGBA( material.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+							_color = material.color;
+
+						}
 
 						width = element.scale.x * _widthHalf;
 						height = element.scale.y * _heightHalf;
@@ -205,11 +220,19 @@ THREE.CanvasRenderer = function () {
 
 					if ( material instanceof THREE.LineColorMaterial ) {
 
-						_light.copyRGB( _ambientLight );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+
+							_color.copyRGBA( material.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
 
-						_color.copyRGBA( material.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+						} else {
+
+							_color = material.color;
+
+						}
 
 						_context.lineWidth = material.lineWidth;
 						_context.lineJoin = "round";
@@ -258,12 +281,20 @@ THREE.CanvasRenderer = function () {
 
 					if ( material instanceof THREE.MeshColorFillMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
 
-						_color.copyRGBA( material.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( material.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
+
+						} else {
+
+							_color = material.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -277,12 +308,20 @@ THREE.CanvasRenderer = function () {
 
 					} else if ( material instanceof THREE.MeshColorStrokeMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( material.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
 
-						_color.copyRGBA( material.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+						} else {
+
+							_color = material.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -302,12 +341,20 @@ THREE.CanvasRenderer = function () {
 
 					} else if ( material instanceof THREE.MeshFaceColorFillMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( element.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
+
+						} else {
 
-						_color.copyRGBA( element.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+							_color = element.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -321,12 +368,20 @@ THREE.CanvasRenderer = function () {
 
 					} else if ( material instanceof THREE.MeshFaceColorStrokeMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( element.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
 
-						_color.copyRGBA( element.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+						} else {
+
+							_color = element.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -433,12 +488,20 @@ THREE.CanvasRenderer = function () {
 
 					if ( material instanceof THREE.MeshColorFillMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
 
-						_color.copyRGBA( material.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( material.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
+
+						} else {
+
+							_color = material.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -454,12 +517,20 @@ THREE.CanvasRenderer = function () {
 
 					} else if ( material instanceof THREE.MeshColorStrokeMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( material.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
 
-						_color.copyRGBA( material.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+						} else {
+
+							_color = material.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -480,12 +551,20 @@ THREE.CanvasRenderer = function () {
 
 					} else if ( material instanceof THREE.MeshFaceColorFillMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
 
-						_color.copyRGBA( element.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+							_color.copyRGBA( element.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
+
+						} else {
+
+							_color = element.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );
@@ -500,12 +579,20 @@ THREE.CanvasRenderer = function () {
 
 					} else if ( material instanceof THREE.MeshFaceColorStrokeMaterial ) {
 
-						_light.copyRGB( _ambientLight );
-						addLights( scene, element, _light );
+						if ( _enableLighting ) {
+
+							_light.copyRGB( _ambientLight );
+							addLights( scene, element, _light );
+
+							_color.copyRGBA( element.color );
+							_color.multiplySelfRGB( _light );
+							_color.updateStyleString();
 
-						_color.copyRGBA( element.color );
-						_color.multiplySelfRGB( _light );
-						_color.updateStyleString();
+						} else {
+
+							_color = element.color;
+
+						}
 
 						_context.beginPath();
 						_context.moveTo( v1x, v1y );

+ 1 - 7
src/renderers/Projector.js

@@ -225,16 +225,10 @@ THREE.Projector = function() {
 
 		}
 
-		_renderList.sort( painterSort );
+		_renderList.sort( function ( a, b ) { return b.z - a.z; } );
 
 		return _renderList;
 
 	};
 
-	function painterSort( a, b ) {
-
-		return b.z - a.z;
-
-	}
-
 };

+ 60 - 21
src/renderers/SVGRenderer.js

@@ -11,6 +11,7 @@ THREE.SVGRenderer = function () {
 	_clipRect = new THREE.Rectangle(),
 	_bboxRect = new THREE.Rectangle(),
 
+	_enableLighting = false,
 	_color = new THREE.Color( 0xffffffff ),
 	_light = new THREE.Color( 0xffffffff ),
 	_ambientLight = new THREE.Color( 0xffffffff ),
@@ -72,7 +73,13 @@ THREE.SVGRenderer = function () {
 
 		_renderList = _projector.projectScene( scene, camera );
 
-		calculateAmbientLight( scene, _ambientLight );
+		_enableLighting = scene.lights.length > 0;
+
+		if ( _enableLighting ) {
+
+			calculateAmbientLight( scene, _ambientLight );
+
+		}
 
 		for ( e = 0, el = _renderList.length; e < el; e++ ) {
 
@@ -149,45 +156,77 @@ THREE.SVGRenderer = function () {
 
 				if ( material instanceof THREE.MeshColorFillMaterial ) {
 
-					_light.copyRGB( _ambientLight );
-					addLights( scene, element, _light );
+					if ( _enableLighting ) {
+
+						_light.copyRGB( _ambientLight );
+						addLights( scene, element, _light );
+
+						_color.copyRGBA( material.color );
+						_color.multiplySelfRGB( _light );
+						_color.updateStyleString();
 
-					_color.copyRGBA( material.color );
-					_color.multiplySelfRGB( _light );
-					_color.updateStyleString();
+					} else {
+
+							_color = material.color;
+
+					}
 
 					svgNode.setAttribute( 'style', 'fill: ' + _color.__styleString );
 
 				} else if ( material instanceof THREE.MeshFaceColorFillMaterial ) {
 
-					_light.copyRGB( _ambientLight );
-					addLights( scene, element, _light );
+					if ( _enableLighting ) {
+
+						_light.copyRGB( _ambientLight );
+						addLights( scene, element, _light );
+
+						_color.copyRGBA( element.color );
+						_color.multiplySelfRGB( _light );
+						_color.updateStyleString();
+
+					} else {
 
-					_color.copyRGBA( element.color );
-					_color.multiplySelfRGB( _light );
-					_color.updateStyleString();
+							_color = element.color;
+
+					}
 
 					svgNode.setAttribute( 'style', 'fill: ' + _color.__styleString );
 
 				} else if ( material instanceof THREE.MeshColorStrokeMaterial ) {
 
-					_light.copyRGB( _ambientLight );
-					addLights( scene, element, _light );
+					if ( _enableLighting ) {
+
+						_light.copyRGB( _ambientLight );
+						addLights( scene, element, _light );
+
+						_color.copyRGBA( material.color );
+						_color.multiplySelfRGB( _light );
+						_color.updateStyleString();
+
+					} else {
+
+							_color = material.color;
 
-					_color.copyRGBA( material.color );
-					_color.multiplySelfRGB( _light );
-					_color.updateStyleString();
+					}
 
 					svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.__styleString + '; stroke-width: ' + material.lineWidth + '; stroke-linecap: round; stroke-linejoin: round' );
 
 				} else if ( material instanceof THREE.MeshFaceColorStrokeMaterial ) {
 
-					_light.copyRGB( _ambientLight );
-					addLights( scene, element, _light );
+					if ( _enableLighting ) {
+
+						_light.copyRGB( _ambientLight );
+						addLights( scene, element, _light );
+
+						_color.copyRGBA( element.color );
+						_color.multiplySelfRGB( _light );
+						_color.updateStyleString();
 
-					_color.copyRGBA( element.color );
-					_color.multiplySelfRGB( _light );
-					_color.updateStyleString();
+					} else {
+
+						_color = element.color;
+
+					}
 
 					svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.__styleString + '; stroke-width: ' + material.lineWidth + '; stroke-linecap: round; stroke-linejoin: round' );
 

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