|
@@ -1,4 +1,5 @@
|
|
|
import { MathUtils } from '../../math/MathUtils.js';
|
|
|
+import { Vector2 } from '../../math/Vector2.js';
|
|
|
import { Vector3 } from '../../math/Vector3.js';
|
|
|
import { Matrix4 } from '../../math/Matrix4.js';
|
|
|
|
|
@@ -7,8 +8,8 @@ import { Matrix4 } from '../../math/Matrix4.js';
|
|
|
* Extensible curve object
|
|
|
*
|
|
|
* Some common of curve methods:
|
|
|
- * .getPoint( t, optionalTarget ), .getTangent( t )
|
|
|
- * .getPointAt( u, optionalTarget ), .getTangentAt( u )
|
|
|
+ * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
|
|
|
+ * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
|
|
|
* .getPoints(), .getSpacedPoints()
|
|
|
* .getLength()
|
|
|
* .updateArcLengths()
|
|
@@ -237,7 +238,7 @@ Object.assign( Curve.prototype, {
|
|
|
// 2 points a small delta apart will be used to find its gradient
|
|
|
// which seems to give a reasonable approximation
|
|
|
|
|
|
- getTangent: function ( t ) {
|
|
|
+ getTangent: function ( t, optionalTarget ) {
|
|
|
|
|
|
var delta = 0.0001;
|
|
|
var t1 = t - delta;
|
|
@@ -251,15 +252,18 @@ Object.assign( Curve.prototype, {
|
|
|
var pt1 = this.getPoint( t1 );
|
|
|
var pt2 = this.getPoint( t2 );
|
|
|
|
|
|
- var vec = pt2.clone().sub( pt1 );
|
|
|
- return vec.normalize();
|
|
|
+ var tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
|
|
|
+
|
|
|
+ tangent.copy( pt2 ).sub( pt1 ).normalize();
|
|
|
+
|
|
|
+ return tangent;
|
|
|
|
|
|
},
|
|
|
|
|
|
- getTangentAt: function ( u ) {
|
|
|
+ getTangentAt: function ( u, optionalTarget ) {
|
|
|
|
|
|
var t = this.getUtoTmapping( u );
|
|
|
- return this.getTangent( t );
|
|
|
+ return this.getTangent( t, optionalTarget );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -284,7 +288,7 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
u = i / segments;
|
|
|
|
|
|
- tangents[ i ] = this.getTangentAt( u );
|
|
|
+ tangents[ i ] = this.getTangentAt( u, new Vector3() );
|
|
|
tangents[ i ].normalize();
|
|
|
|
|
|
}
|