|
@@ -6,30 +6,30 @@ import { Matrix4 } from '../../math/Matrix4';
|
|
* @author zz85 / http://www.lab4games.net/zz85/blog
|
|
* @author zz85 / http://www.lab4games.net/zz85/blog
|
|
* Extensible curve object
|
|
* Extensible curve object
|
|
*
|
|
*
|
|
- * Some common of Curve methods
|
|
|
|
|
|
+ * Some common of curve methods:
|
|
* .getPoint(t), getTangent(t)
|
|
* .getPoint(t), getTangent(t)
|
|
* .getPointAt(u), getTangentAt(u)
|
|
* .getPointAt(u), getTangentAt(u)
|
|
* .getPoints(), .getSpacedPoints()
|
|
* .getPoints(), .getSpacedPoints()
|
|
* .getLength()
|
|
* .getLength()
|
|
* .updateArcLengths()
|
|
* .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.LineCurve
|
|
* THREE.QuadraticBezierCurve
|
|
* THREE.QuadraticBezierCurve
|
|
- * THREE.CubicBezierCurve
|
|
|
|
* THREE.SplineCurve
|
|
* THREE.SplineCurve
|
|
- * THREE.ArcCurve
|
|
|
|
- * THREE.EllipseCurve
|
|
|
|
*
|
|
*
|
|
- * -- 3d classes --
|
|
|
|
|
|
+ * -- 3D curves --
|
|
|
|
+ * THREE.CatmullRomCurve3
|
|
|
|
+ * THREE.CubicBezierCurve3
|
|
* THREE.LineCurve3
|
|
* THREE.LineCurve3
|
|
* THREE.QuadraticBezierCurve3
|
|
* 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
|
|
* Abstract Curve base class
|
|
**************************************************************/
|
|
**************************************************************/
|
|
|
|
|
|
-function Curve() {}
|
|
|
|
|
|
+function Curve() {
|
|
|
|
+
|
|
|
|
+ this.arcLengthDivisions = 200;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
Object.assign( Curve.prototype, {
|
|
Object.assign( Curve.prototype, {
|
|
|
|
|
|
@@ -46,7 +50,7 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
getPoint: function () {
|
|
getPoint: function () {
|
|
|
|
|
|
- console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
|
|
|
|
|
|
+ console.warn( 'THREE.Curve: .getPoint() not implemented.' );
|
|
return null;
|
|
return null;
|
|
|
|
|
|
},
|
|
},
|
|
@@ -110,13 +114,12 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
getLengths: function ( divisions ) {
|
|
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;
|
|
return this.cacheArcLengths;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -140,7 +143,7 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
this.cacheArcLengths = cache;
|
|
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
|
|
// binary search for the index with largest value smaller than target u distance
|
|
|
|
|
|
var low = 0, high = il - 1, comparison;
|
|
var low = 0, high = il - 1, comparison;
|
|
@@ -204,12 +205,9 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
i = high;
|
|
i = high;
|
|
|
|
|
|
- //console.log('b' , i, low, high, Date.now()- time);
|
|
|
|
-
|
|
|
|
if ( arcLengths[ i ] === targetArcLength ) {
|
|
if ( arcLengths[ i ] === targetArcLength ) {
|
|
|
|
|
|
- var t = i / ( il - 1 );
|
|
|
|
- return t;
|
|
|
|
|
|
+ return i / ( il - 1 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|