QuadraticBezierCurve3.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Curve } from '../core/Curve.js';
  2. import { QuadraticBezier } from '../core/Interpolations.js';
  3. import { Vector3 } from '../../math/Vector3.js';
  4. class QuadraticBezierCurve3 extends Curve {
  5. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  6. super();
  7. this.type = 'QuadraticBezierCurve3';
  8. this.v0 = v0;
  9. this.v1 = v1;
  10. this.v2 = v2;
  11. }
  12. getPoint( t, optionalTarget = new Vector3() ) {
  13. const point = optionalTarget;
  14. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  15. point.set(
  16. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  17. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  18. QuadraticBezier( t, v0.z, v1.z, v2.z )
  19. );
  20. return point;
  21. }
  22. copy( source ) {
  23. super.copy( source );
  24. this.v0.copy( source.v0 );
  25. this.v1.copy( source.v1 );
  26. this.v2.copy( source.v2 );
  27. return this;
  28. }
  29. toJSON() {
  30. const data = super.toJSON();
  31. data.v0 = this.v0.toArray();
  32. data.v1 = this.v1.toArray();
  33. data.v2 = this.v2.toArray();
  34. return data;
  35. }
  36. fromJSON( json ) {
  37. super.fromJSON( json );
  38. this.v0.fromArray( json.v0 );
  39. this.v1.fromArray( json.v1 );
  40. this.v2.fromArray( json.v2 );
  41. return this;
  42. }
  43. }
  44. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  45. export { QuadraticBezierCurve3 };