Bläddra i källkod

Reverted Box2.addPoint. CanvasRenderer now using Box2.setFromPoints.

Mr.doob 12 år sedan
förälder
incheckning
f5c0132448
3 ändrade filer med 22 tillägg och 31 borttagningar
  1. 1 1
      examples/canvas_interactive_voxelpainter.html
  2. 18 21
      src/math/Box2.js
  3. 3 9
      src/renderers/CanvasRenderer.js

+ 1 - 1
examples/canvas_interactive_voxelpainter.html

@@ -82,7 +82,7 @@
 				scene.add( plane );
 
 				mouse2D = new THREE.Vector3( 0, 10000, 0.5 );
-				raycaster = new THREE.Raycaster( camera.position, null );
+				raycaster = new THREE.Raycaster( camera.position );
 
 				// Lights
 

+ 18 - 21
src/math/Box2.js

@@ -32,44 +32,41 @@ THREE.Box2.prototype = {
 		this.max.copy( max );
 
 		return this;
-	},
-
-	addPoint: function ( point ) {
 
-		if ( point.x < this.min.x ) {
+	},
 
-			this.min.x = point.x;
+	setFromPoints: function ( points ) {
 
-		} else if ( point.x > this.max.x ) {
+		if ( points.length > 0 ) {
 
-			this.max.x = point.x;
+			var point = points[ 0 ];
 
-		}
+			this.min.copy( point );
+			this.max.copy( point );
 
-		if ( point.y < this.min.y ) {
+			for ( var i = 1, il = points.length; i < il; i ++ ) {
 
-			this.min.y = point.y;
+				point = points[ i ];
 
-		} else if ( point.y > this.max.y ) {
+				if ( point.x < this.min.x ) {
 
-			this.max.y = point.y;
+					this.min.x = point.x;
 
-		}
+				} else if ( point.x > this.max.x ) {
 
-	},
+					this.max.x = point.x;
 
-	setFromPoints: function ( points ) {
+				}
 
-		if ( points.length > 0 ) {
+				if ( point.y < this.min.y ) {
 
-			var p = points[ 0 ];
+					this.min.y = point.y;
 
-			this.min.copy( p );
-			this.max.copy( p );
+				} else if ( point.y > this.max.y ) {
 
-			for ( var i = 1, il = points.length; i < il; i ++ ) {
+					this.max.y = point.y;
 
-				this.addPoint( points[ i ] );
+				}
 
 			}
 

+ 3 - 9
src/renderers/CanvasRenderer.js

@@ -245,8 +245,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 				_v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
 				_v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
 
-				_elemBox2.addPoint( _v1.positionScreen );
-				_elemBox2.addPoint( _v2.positionScreen );
+				_elemBox2.setFromPoints( [ _v1.positionScreen, _v2.positionScreen ] );
 
 				if ( _clipBox2.isIntersection( _elemBox2 ) === true ) {
 
@@ -271,9 +270,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				}
 
-				_elemBox2.addPoint( _v1.positionScreen );
-				_elemBox2.addPoint( _v2.positionScreen );
-				_elemBox2.addPoint( _v3.positionScreen );
+				_elemBox2.setFromPoints( [ _v1.positionScreen, _v2.positionScreen, _v3.positionScreen ] );
 
 				if ( _clipBox2.isIntersection( _elemBox2 ) === true ) {
 
@@ -304,10 +301,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 				}
 
-				_elemBox2.addPoint( _v1.positionScreen );
-				_elemBox2.addPoint( _v2.positionScreen );
-				_elemBox2.addPoint( _v3.positionScreen );
-				_elemBox2.addPoint( _v4.positionScreen );
+				_elemBox2.setFromPoints( [ _v1.positionScreen, _v2.positionScreen, _v3.positionScreen, _v4.positionScreen ] );
 
 				if ( _clipBox2.isIntersection( _elemBox2 ) === true ) {