TweenCameraTruck.re copy.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 TweenCameraPan extends RE.Component {
  6. @RE.props.button() run = this.addMoveTween.bind(this)
  7. @RE.props.vector3() targetFocusPosition: THREE.Vector3 = new THREE.Vector3(-3, 3, -10)
  8. @RE.props.num() durationMillis: number = 2000
  9. @RE.props.select() easing = 5;
  10. easingOptions = ["Linear", "Quadratic", "Cubic", "Quartic", "Quintic", "Sinusoidal", "Exponential", "Circular", "Elastic", "Back", "Bounce"];
  11. @RE.props.select() easingDirection = 3;
  12. easingDirectionOptions = ["EaseNone", "EaseIn", "EaseOut", "EaseInOut"];
  13. @RE.props.object3d() cameraTarget: THREE.Object3D
  14. firstFocusPosition = new THREE.Vector3(0, 0, 0)
  15. secondFocusPosition = new THREE.Vector3(17.627, 0, 4.249)
  16. awake() {
  17. this.targetFocusPosition = this.secondFocusPosition.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.cameraTarget.position, this.targetFocusPosition, this.durationMillis, EASINGS[this.easingOptions[this.easing]][this.easingDirectionOptions[this.easingDirection]], this.onCompleted.bind(this))
  30. }
  31. onCompleted() {
  32. if (this.targetFocusPosition.equals(this.firstFocusPosition)) {
  33. this.targetFocusPosition = this.secondFocusPosition.clone()
  34. } else {
  35. this.targetFocusPosition = this.firstFocusPosition.clone()
  36. }
  37. }
  38. }
  39. RE.registerComponent(TweenCameraPan);