Explorar o código

Plane: Removed normalize() from setFromNormalAndCoplanarPoint and added it back to setFromCoplanarPoints. As suggested in 5c6b5746592e61054d8d50a7bcf905f3c5fff15c.

Mr.doob %!s(int64=12) %!d(string=hai) anos
pai
achega
8b6dd1a479
Modificáronse 4 ficheiros con 8 adicións e 7 borrados
  1. 2 2
      build/three.js
  2. 1 1
      build/three.min.js
  3. 2 2
      src/math/Plane.js
  4. 3 2
      test/unit/math/Plane.js

+ 2 - 2
build/three.js

@@ -4536,7 +4536,7 @@ THREE.Plane.prototype = {
 
 	setFromNormalAndCoplanarPoint: function ( normal, point ) {
 
-		this.normal.copy( normal ).normalize();
+		this.normal.copy( normal );
 		this.constant = - point.dot( this.normal );	// must be this.normal, not normal, as this.normal is normalized
 
 		return this;
@@ -4545,7 +4545,7 @@ THREE.Plane.prototype = {
 
 	setFromCoplanarPoints: function ( a, b, c ) {
 
-		var normal = THREE.Plane.__v1.subVectors( c, b ).cross( THREE.Plane.__v2.subVectors( a, b ) );
+		var normal = THREE.Plane.__v1.subVectors( c, b ).cross( THREE.Plane.__v2.subVectors( a, b ) ).normalize();
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 

+ 1 - 1
build/three.min.js

@@ -96,7 +96,7 @@ this.radius*=a.getMaxScaleOnAxis();return this},translate:function(a){this.cente
 THREE.Frustum.prototype={set:function(a,b,c,d,e,f){var g=this.planes;g[0].copy(a);g[1].copy(b);g[2].copy(c);g[3].copy(d);g[4].copy(e);g[5].copy(f);return this},copy:function(a){for(var b=this.planes,c=0;6>c;c++)b[c].copy(a.planes[c]);return this},setFromMatrix:function(a){var b=this.planes,c=a.elements,a=c[0],d=c[1],e=c[2],f=c[3],g=c[4],i=c[5],h=c[6],k=c[7],m=c[8],p=c[9],n=c[10],s=c[11],q=c[12],l=c[13],r=c[14],c=c[15];b[0].setComponents(f-a,k-g,s-m,c-q).normalize();b[1].setComponents(f+a,k+g,s+m,
 c+q).normalize();b[2].setComponents(f+d,k+i,s+p,c+l).normalize();b[3].setComponents(f-d,k-i,s-p,c-l).normalize();b[4].setComponents(f-e,k-h,s-n,c-r).normalize();b[5].setComponents(f+e,k+h,s+n,c+r).normalize();return this},intersectsObject:function(a){for(var b=a.matrixWorld,c=this.planes,d=b.getPosition(),a=-a.geometry.boundingSphere.radius*b.getMaxScaleOnAxis(),b=0;6>b;b++)if(c[b].distanceToPoint(d)<a)return!1;return!0},intersectsSphere:function(a){for(var b=this.planes,c=a.center,a=-a.radius,d=
 0;6>d;d++)if(b[d].distanceToPoint(c)<a)return!1;return!0},containsPoint:function(a){for(var b=this.planes,c=0;6>c;c++)if(0>b[c].distanceToPoint(a))return!1;return!0},clone:function(){return(new THREE.Frustum).copy(this)}};THREE.Plane=function(a,b){this.normal=void 0!==a?a:new THREE.Vector3(1,0,0);this.constant=void 0!==b?b:0};
-THREE.Plane.prototype={constructor:THREE.Plane,set:function(a,b){this.normal.copy(a);this.constant=b;return this},setComponents:function(a,b,c,d){this.normal.set(a,b,c);this.constant=d;return this},setFromNormalAndCoplanarPoint:function(a,b){this.normal.copy(a).normalize();this.constant=-b.dot(this.normal);return this},setFromCoplanarPoints:function(a,b,c){b=THREE.Plane.__v1.subVectors(c,b).cross(THREE.Plane.__v2.subVectors(a,b));this.setFromNormalAndCoplanarPoint(b,a);return this},copy:function(a){this.normal.copy(a.normal);
+THREE.Plane.prototype={constructor:THREE.Plane,set:function(a,b){this.normal.copy(a);this.constant=b;return this},setComponents:function(a,b,c,d){this.normal.set(a,b,c);this.constant=d;return this},setFromNormalAndCoplanarPoint:function(a,b){this.normal.copy(a);this.constant=-b.dot(this.normal);return this},setFromCoplanarPoints:function(a,b,c){b=THREE.Plane.__v1.subVectors(c,b).cross(THREE.Plane.__v2.subVectors(a,b)).normalize();this.setFromNormalAndCoplanarPoint(b,a);return this},copy:function(a){this.normal.copy(a.normal);
 this.constant=a.constant;return this},normalize:function(){var a=1/this.normal.length();this.normal.multiplyScalar(a);this.constant*=a;return this},negate:function(){this.constant*=-1;this.normal.negate();return this},distanceToPoint:function(a){return this.normal.dot(a)+this.constant},distanceToSphere:function(a){return this.distanceToPoint(a.center)-a.radius},projectPoint:function(a,b){return this.orthoPoint(a,b).sub(a).negate()},orthoPoint:function(a,b){var c=this.distanceToPoint(a);return(b||
 new THREE.Vector3).copy(this.normal).multiplyScalar(c)},isIntersectionLine:function(a,b){var c=this.distanceToPoint(a),d=this.distanceToPoint(b);return 0>c&&0<d||0>d&&0<c},intersectLine:function(a,b,c){var c=c||new THREE.Vector3,b=THREE.Plane.__v1.subVectors(b,a),d=this.normal.dot(b);if(0==d){if(0==this.distanceToPoint(a))return c.copy(a)}else return d=-(a.dot(this.normal)+this.constant)/d,0>d||1<d?void 0:c.copy(b).multiplyScalar(d).add(a)},coplanarPoint:function(a){return(a||new THREE.Vector3).copy(this.normal).multiplyScalar(-this.constant)},
 transform:function(a,b){var b=b||(new THREE.Matrix3).getInverse(a).transpose(),c=THREE.Plane.__v1.copy(this.normal).applyMatrix3(b),d=this.coplanarPoint(THREE.Plane.__v2);d.applyMatrix4(a);this.setFromNormalAndCoplanarPoint(c,d);return this},translate:function(a){this.constant-=a.dot(this.normal);return this},equals:function(a){return a.normal.equals(this.normal)&&a.constant==this.constant},clone:function(){return(new THREE.Plane).copy(this)}};THREE.Plane.__vZero=new THREE.Vector3(0,0,0);

+ 2 - 2
src/math/Plane.js

@@ -33,7 +33,7 @@ THREE.Plane.prototype = {
 
 	setFromNormalAndCoplanarPoint: function ( normal, point ) {
 
-		this.normal.copy( normal ).normalize();
+		this.normal.copy( normal );
 		this.constant = - point.dot( this.normal );	// must be this.normal, not normal, as this.normal is normalized
 
 		return this;
@@ -42,7 +42,7 @@ THREE.Plane.prototype = {
 
 	setFromCoplanarPoints: function ( a, b, c ) {
 
-		var normal = THREE.Plane.__v1.subVectors( c, b ).cross( THREE.Plane.__v2.subVectors( a, b ) );
+		var normal = THREE.Plane.__v1.subVectors( c, b ).cross( THREE.Plane.__v2.subVectors( a, b ) ).normalize();
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 

+ 3 - 2
test/unit/math/Plane.js

@@ -79,9 +79,10 @@ test( "setComponents", function() {
 });
 
 test( "setFromNormalAndCoplanarPoint", function() {
-	var a = new THREE.Plane().setFromNormalAndCoplanarPoint( one3, zero3 );
+	var normal = one3.clone().normalize();
+	var a = new THREE.Plane().setFromNormalAndCoplanarPoint( normal, zero3 );
 	
-	ok( a.normal.equals( one3.clone().normalize() ), "Passed!" );
+	ok( a.normal.equals( normal ), "Passed!" );
 	ok( a.constant == 0, "Passed!" );
 });