1 | /**************************************************************
|
---|
2 | * Closed Spline 3D curve
|
---|
3 | **************************************************************/
|
---|
4 |
|
---|
5 |
|
---|
6 | THREE.ClosedSplineCurve3 = THREE.Curve.create(
|
---|
7 |
|
---|
8 | function ( points /* array of Vector3 */) {
|
---|
9 |
|
---|
10 | this.points = (points == undefined) ? [] : points;
|
---|
11 |
|
---|
12 | },
|
---|
13 |
|
---|
14 | function ( t ) {
|
---|
15 |
|
---|
16 | var v = new THREE.Vector3();
|
---|
17 | var c = [];
|
---|
18 | var points = this.points, point, intPoint, weight;
|
---|
19 | point = ( points.length - 0 ) * t;
|
---|
20 | // This needs to be from 0-length +1
|
---|
21 |
|
---|
22 | intPoint = Math.floor( point );
|
---|
23 | weight = point - intPoint;
|
---|
24 |
|
---|
25 | intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
|
---|
26 | c[ 0 ] = ( intPoint - 1 ) % points.length;
|
---|
27 | c[ 1 ] = ( intPoint ) % points.length;
|
---|
28 | c[ 2 ] = ( intPoint + 1 ) % points.length;
|
---|
29 | c[ 3 ] = ( intPoint + 2 ) % points.length;
|
---|
30 |
|
---|
31 | v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
|
---|
32 | v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
|
---|
33 | v.z = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].z, points[ c[ 1 ] ].z, points[ c[ 2 ] ].z, points[ c[ 3 ] ].z, weight );
|
---|
34 |
|
---|
35 | return v;
|
---|
36 |
|
---|
37 | }
|
---|
38 |
|
---|
39 | ); |
---|