three
Version:
JavaScript 3D library
39 lines (25 loc) • 1.16 kB
JavaScript
/**************************************************************
* Spline 3D curve
**************************************************************/
THREE.SplineCurve3 = THREE.Curve.create(
function ( points /* array of Vector3 */ ) {
console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
this.points = ( points == undefined ) ? [] : points;
},
function ( t ) {
var points = this.points;
var point = ( points.length - 1 ) * t;
var intPoint = Math.floor( point );
var weight = point - intPoint;
var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
var point1 = points[ intPoint ];
var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
var interpolate = THREE.CurveUtils.interpolate;
return new THREE.Vector3(
interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
interpolate( point0.z, point1.z, point2.z, point3.z, weight )
);
}
);