TweenPosition.re.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import * as RE from 'rogue-engine'
  2. import * as THREE from 'three'
  3. import Tween from '../Lib/Tween'
  4. import EASINGS from '../Lib/Easings'
  5. export default class TweenPosition extends RE.Component {
  6. @RE.props.button() run = this.addMoveTween.bind(this)
  7. @RE.props.vector3() targetPosition: THREE.Vector3 = new THREE.Vector3(-3, 3, -10)
  8. @RE.props.num() durationMillis: number = 2000
  9. @RE.props.select() easing = 8;
  10. easingOptions = ["Linear", "Quadratic", "Cubic", "Quartic", "Quintic", "Sinusoidal", "Exponential", "Circular", "Elastic", "Back", "Bounce"];
  11. @RE.props.select() easingDirection = 2;
  12. easingDirectionOptions = ["EaseNone", "EaseIn", "EaseOut", "EaseInOut"];
  13. firstPosition = new THREE.Vector3(-3, 3, 0)
  14. secondPosition = new THREE.Vector3(-3, 3, -10)
  15. awake() {
  16. this.targetPosition = this.secondPosition.clone()
  17. }
  18. start() {
  19. }
  20. update() {
  21. }
  22. addMoveTween() {
  23. Tween.create(this.object3d.position, this.targetPosition, this.durationMillis, EASINGS[this.easingOptions[this.easing]][this.easingDirectionOptions[this.easingDirection]], this.onCompleted.bind(this))
  24. }
  25. onCompleted() {
  26. if (this.targetPosition.equals(this.firstPosition)) {
  27. this.targetPosition = this.secondPosition.clone()
  28. } else {
  29. this.targetPosition = this.firstPosition.clone()
  30. }
  31. }
  32. }
  33. RE.registerComponent(TweenPosition);