提交 a8bcfb1b 编写于 作者: W WestLangley

Remove optionalTarget

上级 fd423827
......@@ -51,10 +51,10 @@
<h3>[method:Float area]()</h3>
<div>Return the area of the triangle.</div>
<h3>[method:Vector3 barycoordFromPoint]( [param:Vector3 point], [param:Vector3 optionalTarget] )</h3>
<h3>[method:Vector3 barycoordFromPoint]( [param:Vector3 point], [param:Vector3 target] )</h3>
<div>
[page:Vector3 point] - [page:Vector3] <br />
[page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.<br /><br />
[page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
Return a [link:https://en.wikipedia.org/wiki/Barycentric_coordinate_system barycentric coordinate]
from the given vector. <br/><br/>
......@@ -67,10 +67,10 @@
Returns a new triangle with the same [page:.a a], [page:.b b] and [page:.c c] properties as this one.
</div>
<h3>[method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 optionalTarget] )</h3>
<h3>[method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 target] )</h3>
<div>
point - [page:Vector3] <br />
[page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.<br /><br />
[page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
Returns the closest point on the triangle to [page:Vector3 point].
</div>
......@@ -100,23 +100,23 @@
Determines whether or not this triangle intersects [page:Box3 box].
</div>
<h3>[method:Vector3 midpoint]( [param:Vector3 optionalTarget] )</h3>
<h3>[method:Vector3 midpoint]( [param:Vector3 target] )</h3>
<div>
[page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.<br /><br />
[page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
Calculate the midpoint of the triangle.
</div>
<h3>[method:Vector3 normal]( [param:Vector3 optionalTarget] )</h3>
<h3>[method:Vector3 normal]( [param:Vector3 target] )</h3>
<div>
[page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.<br /><br />
[page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
Calculate the [link:https://en.wikipedia.org/wiki/Normal_(geometry) normal vector] of the triangle.
</div>
<h3>[method:Plane plane]( [param:Plane optionalTarget] )</h3>
<h3>[method:Plane plane]( [param:Plane target] )</h3>
<div>
[page:Plane optionalTarget] - (optional) if specified, the result will be copied into this [page:Plane], otherwise a new [page:Plane] will be created.<br /><br />
[page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
Create a [page:Plane plane] based on the triangle. .
</div>
......
......@@ -21,22 +21,27 @@ Object.assign( Triangle, {
var v0 = new Vector3();
return function normal( a, b, c, optionalTarget ) {
return function normal( a, b, c, target ) {
var result = optionalTarget || new Vector3();
if ( target === undefined ) {
result.subVectors( c, b );
console.warn( 'THREE.Triangle: .normal() target is now required' );
target = new Vector3();
}
target.subVectors( c, b );
v0.subVectors( a, b );
result.cross( v0 );
target.cross( v0 );
var resultLengthSq = result.lengthSq();
if ( resultLengthSq > 0 ) {
var targetLengthSq = target.lengthSq();
if ( targetLengthSq > 0 ) {
return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
}
return result.set( 0, 0, 0 );
return target.set( 0, 0, 0 );
};
......@@ -50,7 +55,7 @@ Object.assign( Triangle, {
var v1 = new Vector3();
var v2 = new Vector3();
return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
return function barycoordFromPoint( point, a, b, c, target ) {
v0.subVectors( c, a );
v1.subVectors( b, a );
......@@ -64,14 +69,19 @@ Object.assign( Triangle, {
var denom = ( dot00 * dot11 - dot01 * dot01 );
var result = optionalTarget || new Vector3();
if ( target === undefined ) {
console.warn( 'THREE.Triangle: .barycoordFromPoint() target is now required' );
target = new Vector3();
}
// collinear or singular triangle
if ( denom === 0 ) {
// arbitrary location outside of triangle?
// not sure if this is the best idea, maybe should be returning undefined
return result.set( - 2, - 1, - 1 );
return target.set( - 2, - 1, - 1 );
}
......@@ -80,7 +90,7 @@ Object.assign( Triangle, {
var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
// barycentric coordinates must always sum to 1
return result.set( 1 - u - v, v, u );
return target.set( 1 - u - v, v, u );
};
......@@ -92,9 +102,9 @@ Object.assign( Triangle, {
return function containsPoint( point, a, b, c ) {
var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
Triangle.barycoordFromPoint( point, a, b, c, v1 );
return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
};
......@@ -156,30 +166,41 @@ Object.assign( Triangle.prototype, {
}(),
midpoint: function ( optionalTarget ) {
midpoint: function ( target ) {
if ( target === undefined ) {
var result = optionalTarget || new Vector3();
return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
console.warn( 'THREE.Triangle: .midpoint() target is now required' );
target = new Vector3();
}
return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
},
normal: function ( optionalTarget ) {
normal: function ( target ) {
return Triangle.normal( this.a, this.b, this.c, optionalTarget );
return Triangle.normal( this.a, this.b, this.c, target );
},
plane: function ( optionalTarget ) {
plane: function ( target ) {
if ( target === undefined ) {
var result = optionalTarget || new Plane();
console.warn( 'THREE.Triangle: .plane() target is now required' );
target = new Vector3();
}
return result.setFromCoplanarPoints( this.a, this.b, this.c );
return target.setFromCoplanarPoints( this.a, this.b, this.c );
},
barycoordFromPoint: function ( point, optionalTarget ) {
barycoordFromPoint: function ( point, target ) {
return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, target );
},
......@@ -202,9 +223,15 @@ Object.assign( Triangle.prototype, {
var projectedPoint = new Vector3();
var closestPoint = new Vector3();
return function closestPointToPoint( point, optionalTarget ) {
return function closestPointToPoint( point, target ) {
if ( target === undefined ) {
console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
target = new Vector3();
}
var result = optionalTarget || new Vector3();
var minDistance = Infinity;
// project the point onto the plane of the triangle
......@@ -218,11 +245,11 @@ Object.assign( Triangle.prototype, {
// if so, this is the closest point
result.copy( projectedPoint );
target.copy( projectedPoint );
} else {
// if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
// if not, the point falls outside the triangle. the target is the closest point to the triangle's edges or vertices
edgeList[ 0 ].set( this.a, this.b );
edgeList[ 1 ].set( this.b, this.c );
......@@ -238,7 +265,7 @@ Object.assign( Triangle.prototype, {
minDistance = distance;
result.copy( closestPoint );
target.copy( closestPoint );
}
......@@ -246,7 +273,7 @@ Object.assign( Triangle.prototype, {
}
return result;
return target;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册