Tween.js 756 B

1234567891011121314151617181920212223242526
  1. import * as THREE from "../../../../libs/three.js/build/three.module.js";
  2. class Tween {
  3. constructor(times, values) {
  4. this.times = times || []
  5. this.values = values || []
  6. }
  7. lerp(t) {
  8. if(this.times.length == 0) return
  9. let i = 0, n = this.times.length
  10. while(i < n && t > this.times[i]) i++
  11. if(i == 0) return this.values[0]
  12. if(i == n) return this.values[n-1]
  13. const ratio = (t - this.times[i-1]) / (this.times[i] - this.times[i-1])
  14. if(this.values[0] instanceof THREE.Vector3) {
  15. return this.values[i-1].clone().lerp(this.values[i], ratio)
  16. } else {
  17. return this.values[i-1] + ratio * (this.values[i] - this.values[i-1])
  18. }
  19. }
  20. }
  21. export default Tween