|
@@ -33,39 +33,39 @@ import { Matrix4 } from '../../math/Matrix4.js';
|
|
*
|
|
*
|
|
**/
|
|
**/
|
|
|
|
|
|
-function Curve() {
|
|
|
|
|
|
+class Curve {
|
|
|
|
|
|
- this.type = 'Curve';
|
|
|
|
|
|
+ constructor() {
|
|
|
|
|
|
- this.arcLengthDivisions = 200;
|
|
|
|
|
|
+ this.type = 'Curve';
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ this.arcLengthDivisions = 200;
|
|
|
|
|
|
-Object.assign( Curve.prototype, {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Virtual base class method to overwrite and implement in subclasses
|
|
// Virtual base class method to overwrite and implement in subclasses
|
|
// - t [0 .. 1]
|
|
// - t [0 .. 1]
|
|
|
|
|
|
- getPoint: function ( /* t, optionalTarget */ ) {
|
|
|
|
|
|
+ getPoint( /* t, optionalTarget */ ) {
|
|
|
|
|
|
console.warn( 'THREE.Curve: .getPoint() not implemented.' );
|
|
console.warn( 'THREE.Curve: .getPoint() not implemented.' );
|
|
return null;
|
|
return null;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Get point at relative position in curve according to arc length
|
|
// Get point at relative position in curve according to arc length
|
|
// - u [0 .. 1]
|
|
// - u [0 .. 1]
|
|
|
|
|
|
- getPointAt: function ( u, optionalTarget ) {
|
|
|
|
|
|
+ getPointAt( u, optionalTarget ) {
|
|
|
|
|
|
const t = this.getUtoTmapping( u );
|
|
const t = this.getUtoTmapping( u );
|
|
return this.getPoint( t, optionalTarget );
|
|
return this.getPoint( t, optionalTarget );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Get sequence of points using getPoint( t )
|
|
// Get sequence of points using getPoint( t )
|
|
|
|
|
|
- getPoints: function ( divisions = 5 ) {
|
|
|
|
|
|
+ getPoints( divisions = 5 ) {
|
|
|
|
|
|
const points = [];
|
|
const points = [];
|
|
|
|
|
|
@@ -77,11 +77,11 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
return points;
|
|
return points;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Get sequence of points using getPointAt( u )
|
|
// Get sequence of points using getPointAt( u )
|
|
|
|
|
|
- getSpacedPoints: function ( divisions = 5 ) {
|
|
|
|
|
|
+ getSpacedPoints( divisions = 5 ) {
|
|
|
|
|
|
const points = [];
|
|
const points = [];
|
|
|
|
|
|
@@ -93,20 +93,20 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
return points;
|
|
return points;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Get total curve arc length
|
|
// Get total curve arc length
|
|
|
|
|
|
- getLength: function () {
|
|
|
|
|
|
+ getLength() {
|
|
|
|
|
|
const lengths = this.getLengths();
|
|
const lengths = this.getLengths();
|
|
return lengths[ lengths.length - 1 ];
|
|
return lengths[ lengths.length - 1 ];
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Get list of cumulative segment lengths
|
|
// Get list of cumulative segment lengths
|
|
|
|
|
|
- getLengths: function ( divisions ) {
|
|
|
|
|
|
+ getLengths( divisions ) {
|
|
|
|
|
|
if ( divisions === undefined ) divisions = this.arcLengthDivisions;
|
|
if ( divisions === undefined ) divisions = this.arcLengthDivisions;
|
|
|
|
|
|
@@ -139,18 +139,18 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
return cache; // { sums: cache, sum: sum }; Sum is in the last element.
|
|
return cache; // { sums: cache, sum: sum }; Sum is in the last element.
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- updateArcLengths: function () {
|
|
|
|
|
|
+ updateArcLengths() {
|
|
|
|
|
|
this.needsUpdate = true;
|
|
this.needsUpdate = true;
|
|
this.getLengths();
|
|
this.getLengths();
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
|
|
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
|
|
|
|
|
|
- getUtoTmapping: function ( u, distance ) {
|
|
|
|
|
|
+ getUtoTmapping( u, distance ) {
|
|
|
|
|
|
const arcLengths = this.getLengths();
|
|
const arcLengths = this.getLengths();
|
|
|
|
|
|
@@ -223,14 +223,14 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
return t;
|
|
return t;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
// Returns a unit vector tangent at t
|
|
// Returns a unit vector tangent at t
|
|
// In case any sub curve does not implement its tangent derivation,
|
|
// In case any sub curve does not implement its tangent derivation,
|
|
// 2 points a small delta apart will be used to find its gradient
|
|
// 2 points a small delta apart will be used to find its gradient
|
|
// which seems to give a reasonable approximation
|
|
// which seems to give a reasonable approximation
|
|
|
|
|
|
- getTangent: function ( t, optionalTarget ) {
|
|
|
|
|
|
+ getTangent( t, optionalTarget ) {
|
|
|
|
|
|
const delta = 0.0001;
|
|
const delta = 0.0001;
|
|
let t1 = t - delta;
|
|
let t1 = t - delta;
|
|
@@ -250,16 +250,16 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
return tangent;
|
|
return tangent;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- getTangentAt: function ( u, optionalTarget ) {
|
|
|
|
|
|
+ getTangentAt( u, optionalTarget ) {
|
|
|
|
|
|
const t = this.getUtoTmapping( u );
|
|
const t = this.getUtoTmapping( u );
|
|
return this.getTangent( t, optionalTarget );
|
|
return this.getTangent( t, optionalTarget );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- computeFrenetFrames: function ( segments, closed ) {
|
|
|
|
|
|
+ computeFrenetFrames( segments, closed ) {
|
|
|
|
|
|
// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
|
|
// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
|
|
|
|
|
|
@@ -372,23 +372,23 @@ Object.assign( Curve.prototype, {
|
|
binormals: binormals
|
|
binormals: binormals
|
|
};
|
|
};
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- clone: function () {
|
|
|
|
|
|
+ clone() {
|
|
|
|
|
|
return new this.constructor().copy( this );
|
|
return new this.constructor().copy( this );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( source ) {
|
|
|
|
|
|
+ copy( source ) {
|
|
|
|
|
|
this.arcLengthDivisions = source.arcLengthDivisions;
|
|
this.arcLengthDivisions = source.arcLengthDivisions;
|
|
|
|
|
|
return this;
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- toJSON: function () {
|
|
|
|
|
|
+ toJSON() {
|
|
|
|
|
|
const data = {
|
|
const data = {
|
|
metadata: {
|
|
metadata: {
|
|
@@ -403,9 +403,9 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
return data;
|
|
return data;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- fromJSON: function ( json ) {
|
|
|
|
|
|
+ fromJSON( json ) {
|
|
|
|
|
|
this.arcLengthDivisions = json.arcLengthDivisions;
|
|
this.arcLengthDivisions = json.arcLengthDivisions;
|
|
|
|
|
|
@@ -413,7 +413,7 @@ Object.assign( Curve.prototype, {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-} );
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
export { Curve };
|
|
export { Curve };
|