SplineCurve.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**************************************************************
  2. * Spline curve
  3. **************************************************************/
  4. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  5. this.points = ( points == undefined ) ? [] : points;
  6. };
  7. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  8. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  9. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  10. var points = this.points;
  11. var point = ( points.length - 1 ) * t;
  12. var intPoint = Math.floor( point );
  13. var weight = point - intPoint;
  14. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ]
  15. var point1 = points[ intPoint ]
  16. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ]
  17. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ]
  18. var vector = new THREE.Vector2();
  19. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  20. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  21. return vector;
  22. };