TweenCameraFlyover.re.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 TweenCameraFlyover 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. @RE.props.object3d() cameraTarget: THREE.Object3D
  14. firstPosition = new THREE.Vector3(-11.627, 6.991, -16.249)
  15. secondPosition = new THREE.Vector3(6, 20, -12)
  16. awake() {
  17. this.targetPosition = this.secondPosition.clone()
  18. }
  19. start() {
  20. }
  21. update() {
  22. if(this.cameraTarget) {
  23. this.object3d.lookAt(this.cameraTarget.position)
  24. } else {
  25. RE.Debug.logWarning("Camera has no look-at target set!")
  26. }
  27. }
  28. addMoveTween() {
  29. Tween.create(this.object3d.position, this.targetPosition, this.durationMillis, EASINGS[this.easingOptions[this.easing]][this.easingDirectionOptions[this.easingDirection]], this.onCompleted.bind(this))
  30. }
  31. onCompleted() {
  32. if (this.targetPosition.equals(this.firstPosition)) {
  33. this.targetPosition = this.secondPosition.clone()
  34. } else {
  35. this.targetPosition = this.firstPosition.clone()
  36. }
  37. }
  38. }
  39. RE.registerComponent(TweenCameraFlyover);