diff --git a/docs/api/extras/core/Curve.html b/docs/api/extras/core/Curve.html
index 495eda41fb983ea36019afdfe84028b517b46475..7c8dc65e0df030711c0b2b2c02316efee2e47495 100644
--- a/docs/api/extras/core/Curve.html
+++ b/docs/api/extras/core/Curve.html
@@ -11,14 +11,10 @@
- An abstract base class for creating a curve object that contains methods for interpolation.
- For an array of Curves see [page:CurvePath].
+ An abstract base class for creating a [name] object that contains methods for interpolation.
+ For an array of [name]s see [page:CurvePath].
- This value determines the amount of divisions when calculating the cumulative segment lengths of a curve via [page:.getLengths].
+ To ensure precision when using methods like [page:.getSpacedPoints], it is recommended to increase [page:.arcLengthDivisions] if the curve is very large. Default is 200.
Returns a vector for point t of the curve where t is between 0 and 1. Must be implemented in the extending class.
+ Returns a vector for point t of the curve where t is between 0 and 1. Must be implemented in the extending curve.
-
Returns a vector for point at a relative position in curve according to arc length.
u is in the range [0, 1].
-
divisions -- number of pieces to divide the curve into. Default is *5*.
Returns a set of divisions + 1 points using getPoint( t ).
-
divisions -- number of pieces to divide the curve into. Default is *5*.
@@ -56,33 +57,33 @@
[method:Float getLength]()
Get total curve arc length.
-
[method:Array getLengths]( divisions )
+
[method:Array getLengths]( [page:Integer divisions] )
Get list of cumulative segment lengths.
[method:null updateArcLengths]()
Update the cumlative segment distance cache.
-
[method:Float getUtoTmapping]( [page:Number u], distance )
+
[method:Float getUtoTmapping]( [page:Float u], [page:Float distance] )
- Given u in the range ( 0 .. 1 ), returns [page:Number t] also in the range ( 0 .. 1 ).
+ Given u in the range ( 0 .. 1 ), returns [page:Float t] also in the range ( 0 .. 1 ).
u and t can then be used to give you points which are equidistant from the ends of the curve,
using [page:.getPoint].
-
[method:Vector getTangent]( [page:Number t] )
+
[method:Vector getTangent]( [page:Float t] )
- Returns a unit vector tangent at t. If the subclassed curve do not implement its
- tangent derivation, 2 points a small delta apart will be used to find its gradient
- which seems to give a reasonable approximation
+ Returns a unit vector tangent at t. If the derived curve does not implement its
+ tangent derivation, two points a small delta apart will be used to find its gradient
+ which seems to give a reasonable approximation.
-
[method:Vector getTangentAt]( [page:Number u] )
+
[method:Vector getTangentAt]( [page:Float u] )
Returns tangent at a point which is equidistant to the ends of the curve from the
point given in [page:.getTangent].
-
[method:Object computeFrenetFrames]( segments, closed )
+
[method:Object computeFrenetFrames]( [page:Integer segments], [page:Boolean closed] )
Generates the Frenet Frames. Used in geometries like [page:TubeGeometry] or [page:ExtrudeGeometry].
diff --git a/examples/js/CurveExtras.js b/examples/js/CurveExtras.js
index c36cee847e7712ecec229b0d5708e867c297a1a2..ff7a0292b1c24fb974eaadf2dbaa819ee2594971 100644
--- a/examples/js/CurveExtras.js
+++ b/examples/js/CurveExtras.js
@@ -15,7 +15,11 @@
// GrannyKnot
- function GrannyKnot() {}
+ function GrannyKnot() {
+
+ THREE.Curve.call( this );
+
+ }
GrannyKnot.prototype = Object.create( THREE.Curve.prototype );
GrannyKnot.prototype.constructor = GrannyKnot;
@@ -36,6 +40,8 @@
function HeartCurve( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 5 : s;
}
@@ -59,6 +65,8 @@
function VivianiCurve( radius ) {
+ THREE.Curve.call( this );
+
this.radius = radius;
}
@@ -81,7 +89,11 @@
// KnotCurve
- function KnotCurve() {}
+ function KnotCurve() {
+
+ THREE.Curve.call( this );
+
+ }
KnotCurve.prototype = Object.create( THREE.Curve.prototype );
KnotCurve.prototype.constructor = KnotCurve;
@@ -103,7 +115,11 @@
// HelixCurve
- function HelixCurve() {}
+ function HelixCurve() {
+
+ THREE.Curve.call( this );
+
+ }
HelixCurve.prototype = Object.create( THREE.Curve.prototype );
HelixCurve.prototype.constructor = HelixCurve;
@@ -127,6 +143,8 @@
function TrefoilKnot( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 10 : s;
}
@@ -150,6 +168,8 @@
function TorusKnot( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 10 : s;
}
@@ -176,6 +196,8 @@
function CinquefoilKnot( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 10 : s;
}
@@ -202,6 +224,8 @@
function TrefoilPolynomialKnot( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 10 : s;
}
@@ -232,6 +256,8 @@
function FigureEightPolynomialKnot( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 1 : s;
}
@@ -255,6 +281,8 @@
function DecoratedTorusKnot4a( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 40 : s;
}
@@ -278,6 +306,8 @@
function DecoratedTorusKnot4b( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 40 : s;
}
@@ -301,6 +331,8 @@
function DecoratedTorusKnot5a( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 40 : s;
}
@@ -324,6 +356,8 @@
function DecoratedTorusKnot5c( s ) {
+ THREE.Curve.call( this );
+
this.scale = ( s === undefined ) ? 40 : s;
}
diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js
index cffaed59f90af9e4365cdeb53fb435d94f0ecc44..0b45aeb9f8b4fa47f14ddd4393c38fbfece5e13a 100644
--- a/src/Three.Legacy.js
+++ b/src/Three.Legacy.js
@@ -776,6 +776,23 @@ Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
} );
+Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
+
+ get: function () {
+
+ console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
+ return this.arcLengthDivisions;
+
+ },
+ set: function ( value ) {
+
+ console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
+ this.arcLengthDivisions = value;
+
+ }
+
+} );
+
//
PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
diff --git a/src/extras/core/Curve.js b/src/extras/core/Curve.js
index 25508b2c1e451cbbfd5c79d54fbdf4696997d753..8ca25863b87870d5b7e6cca8c651d2aeb9ab2b10 100644
--- a/src/extras/core/Curve.js
+++ b/src/extras/core/Curve.js
@@ -6,30 +6,30 @@ import { Matrix4 } from '../../math/Matrix4';
* @author zz85 / http://www.lab4games.net/zz85/blog
* Extensible curve object
*
- * Some common of Curve methods
+ * Some common of curve methods:
* .getPoint(t), getTangent(t)
* .getPointAt(u), getTangentAt(u)
* .getPoints(), .getSpacedPoints()
* .getLength()
* .updateArcLengths()
*
- * This following classes subclasses THREE.Curve:
+ * This following curves inherit from THREE.Curve:
*
- * -- 2d classes --
+ * -- 2D curves --
+ * THREE.ArcCurve
+ * THREE.CubicBezierCurve
+ * THREE.EllipseCurve
* THREE.LineCurve
* THREE.QuadraticBezierCurve
- * THREE.CubicBezierCurve
* THREE.SplineCurve
- * THREE.ArcCurve
- * THREE.EllipseCurve
*
- * -- 3d classes --
+ * -- 3D curves --
+ * THREE.CatmullRomCurve3
+ * THREE.CubicBezierCurve3
* THREE.LineCurve3
* THREE.QuadraticBezierCurve3
- * THREE.CubicBezierCurve3
- * THREE.CatmullRomCurve3
*
- * A series of curves can be represented as a THREE.CurvePath
+ * A series of curves can be represented as a THREE.CurvePath.
*
**/
@@ -37,7 +37,11 @@ import { Matrix4 } from '../../math/Matrix4';
* Abstract Curve base class
**************************************************************/
-function Curve() {}
+function Curve() {
+
+ this.arcLengthDivisions = 200;
+
+}
Object.assign( Curve.prototype, {
@@ -46,7 +50,7 @@ Object.assign( Curve.prototype, {
getPoint: function () {
- console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
+ console.warn( 'THREE.Curve: .getPoint() not implemented.' );
return null;
},
@@ -110,13 +114,12 @@ Object.assign( Curve.prototype, {
getLengths: function ( divisions ) {
- if ( divisions === undefined ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
+ if ( divisions === undefined ) divisions = this.arcLengthDivisions;
- if ( this.cacheArcLengths
- && ( this.cacheArcLengths.length === divisions + 1 )
- && ! this.needsUpdate ) {
+ if ( this.cacheArcLengths &&
+ ( this.cacheArcLengths.length === divisions + 1 ) &&
+ ! this.needsUpdate ) {
- //console.log( "cached", this.cacheArcLengths );
return this.cacheArcLengths;
}
@@ -140,7 +143,7 @@ Object.assign( Curve.prototype, {
this.cacheArcLengths = cache;
- return cache; // { sums: cache, sum:sum }; Sum is in the last element.
+ return cache; // { sums: cache, sum: sum }; Sum is in the last element.
},
@@ -171,8 +174,6 @@ Object.assign( Curve.prototype, {
}
- //var time = Date.now();
-
// binary search for the index with largest value smaller than target u distance
var low = 0, high = il - 1, comparison;
@@ -204,12 +205,9 @@ Object.assign( Curve.prototype, {
i = high;
- //console.log('b' , i, low, high, Date.now()- time);
-
if ( arcLengths[ i ] === targetArcLength ) {
- var t = i / ( il - 1 );
- return t;
+ return i / ( il - 1 );
}
diff --git a/src/extras/core/CurvePath.js b/src/extras/core/CurvePath.js
index 303df623b0dbb3b58cb3d8daed1c7e994dc7e436..476da51bebd771543e26631903b60d4bca340dfa 100644
--- a/src/extras/core/CurvePath.js
+++ b/src/extras/core/CurvePath.js
@@ -15,6 +15,8 @@ import { LineCurve } from '../curves/LineCurve';
function CurvePath() {
+ Curve.call( this );
+
this.curves = [];
this.autoClose = false; // Automatically closes the path
@@ -102,7 +104,7 @@ CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
this.needsUpdate = true;
this.cacheLengths = null;
- this.getLengths();
+ this.getCurveLengths();
},
diff --git a/src/extras/curves/CatmullRomCurve3.js b/src/extras/curves/CatmullRomCurve3.js
index 85b7b3fb6b89f083066ed8d74e450d59bb085635..40b3406f806df54d9e0f6c8b80d380b92ad8bc7a 100644
--- a/src/extras/curves/CatmullRomCurve3.js
+++ b/src/extras/curves/CatmullRomCurve3.js
@@ -85,6 +85,8 @@ var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
function CatmullRomCurve3( p /* array of Vector3 */ ) {
+ Curve.call( this );
+
this.points = p || [];
this.closed = false;
diff --git a/src/extras/curves/CubicBezierCurve.js b/src/extras/curves/CubicBezierCurve.js
index e86e82b7d9417b507e81e35c17b877e4b9a2f27e..84c1c00416d3e6890296d6ddbb2688fcff49624b 100644
--- a/src/extras/curves/CubicBezierCurve.js
+++ b/src/extras/curves/CubicBezierCurve.js
@@ -5,6 +5,8 @@ import { Vector2 } from '../../math/Vector2';
function CubicBezierCurve( v0, v1, v2, v3 ) {
+ Curve.call( this );
+
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
diff --git a/src/extras/curves/CubicBezierCurve3.js b/src/extras/curves/CubicBezierCurve3.js
index a60d3cef3a062882eb50c259529a5aef35113866..1436c094a82b084353282ee3f0f3b5eda0a60cc9 100644
--- a/src/extras/curves/CubicBezierCurve3.js
+++ b/src/extras/curves/CubicBezierCurve3.js
@@ -5,6 +5,8 @@ import { Vector3 } from '../../math/Vector3';
function CubicBezierCurve3( v0, v1, v2, v3 ) {
+ Curve.call( this );
+
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
diff --git a/src/extras/curves/EllipseCurve.js b/src/extras/curves/EllipseCurve.js
index 8bffc9afc9049657d8c7009a43b287a586490ef0..b15a3dcbc191980422bd82b4ece417f907b8fb32 100644
--- a/src/extras/curves/EllipseCurve.js
+++ b/src/extras/curves/EllipseCurve.js
@@ -4,6 +4,8 @@ import { Vector2 } from '../../math/Vector2';
function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
+ Curve.call( this );
+
this.aX = aX;
this.aY = aY;
diff --git a/src/extras/curves/LineCurve.js b/src/extras/curves/LineCurve.js
index c8a332547b806a55c0059f35b38c2d3395f0be10..4e58369215f1ccb2136a8882be3149e745e32981 100644
--- a/src/extras/curves/LineCurve.js
+++ b/src/extras/curves/LineCurve.js
@@ -3,6 +3,8 @@ import { Curve } from '../core/Curve';
function LineCurve( v1, v2 ) {
+ Curve.call( this );
+
this.v1 = v1;
this.v2 = v2;
diff --git a/src/extras/curves/LineCurve3.js b/src/extras/curves/LineCurve3.js
index 41f425f6b32847127320609a86924fa6f096ff20..577ba78a3d4e60299da989253d0ac8fc66f021d3 100644
--- a/src/extras/curves/LineCurve3.js
+++ b/src/extras/curves/LineCurve3.js
@@ -4,6 +4,8 @@ import { Curve } from '../core/Curve';
function LineCurve3( v1, v2 ) {
+ Curve.call( this );
+
this.v1 = v1;
this.v2 = v2;
diff --git a/src/extras/curves/QuadraticBezierCurve.js b/src/extras/curves/QuadraticBezierCurve.js
index bfefc1330b15e0a94be46eee40965ea38e28c77b..72a16475640d361a4774779c7ecc9119850facda 100644
--- a/src/extras/curves/QuadraticBezierCurve.js
+++ b/src/extras/curves/QuadraticBezierCurve.js
@@ -5,6 +5,8 @@ import { Vector2 } from '../../math/Vector2';
function QuadraticBezierCurve( v0, v1, v2 ) {
+ Curve.call( this );
+
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
diff --git a/src/extras/curves/QuadraticBezierCurve3.js b/src/extras/curves/QuadraticBezierCurve3.js
index c7dd46176ca72a78b954111f323aaca10ff2a536..51c9469cbbd577122422ad927aff5d0be76208ad 100644
--- a/src/extras/curves/QuadraticBezierCurve3.js
+++ b/src/extras/curves/QuadraticBezierCurve3.js
@@ -5,6 +5,8 @@ import { Vector3 } from '../../math/Vector3';
function QuadraticBezierCurve3( v0, v1, v2 ) {
+ Curve.call( this );
+
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
diff --git a/src/extras/curves/SplineCurve.js b/src/extras/curves/SplineCurve.js
index 56f8d116988e50c3adf4c1c811f7a54132f9030a..fd879eea7e78405c664d481c8502bb3cffc81ffd 100644
--- a/src/extras/curves/SplineCurve.js
+++ b/src/extras/curves/SplineCurve.js
@@ -5,6 +5,8 @@ import { Vector2 } from '../../math/Vector2';
function SplineCurve( points /* array of Vector2 */ ) {
+ Curve.call( this );
+
this.points = ( points === undefined ) ? [] : points;
}