TweenCameraTruck.re.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 TweenCameraTruck extends RE.Component {
  6. @RE.props.button() run = this.addMoveTween.bind(this)
  7. @RE.props.vector3() targetCameraPosition: THREE.Vector3 = new THREE.Vector3(-3, 3, -10)
  8. @RE.props.vector3() targetFocusPosition: THREE.Vector3 = new THREE.Vector3(-3, 3, -10)
  9. @RE.props.num() durationMillis: number = 2000
  10. @RE.props.select() easing = 1;
  11. easingOptions = ["Linear", "Quadratic", "Cubic", "Quartic", "Quintic", "Sinusoidal", "Exponential", "Circular", "Elastic", "Back", "Bounce"];
  12. @RE.props.select() easingDirection = 3;
  13. easingDirectionOptions = ["EaseNone", "EaseIn", "EaseOut", "EaseInOut"];
  14. @RE.props.object3d() cameraTarget: THREE.Object3D
  15. firstCameraPosition = new THREE.Vector3(-11.627, 6.991, -16.249)
  16. secondCameraPosition = new THREE.Vector3(6, 6.991, -12)
  17. firstFocusPosition = new THREE.Vector3(0, 0, 0)
  18. secondFocusPosition = new THREE.Vector3(17.627, 0, 4.249)
  19. awake() {
  20. this.targetCameraPosition = this.secondCameraPosition.clone()
  21. this.targetFocusPosition = this.secondFocusPosition.clone()
  22. }
  23. start() {
  24. }
  25. update() {
  26. if(this.cameraTarget) {
  27. this.object3d.lookAt(this.cameraTarget.position)
  28. } else {
  29. RE.Debug.logWarning("Camera has no look-at target set!")
  30. }
  31. }
  32. addMoveTween() {
  33. Tween.create(this.object3d.position, this.targetCameraPosition, this.durationMillis, EASINGS[this.easingOptions[this.easing]][this.easingDirectionOptions[this.easingDirection]], this.onCompleted.bind(this))
  34. Tween.create(this.cameraTarget.position, this.targetFocusPosition, this.durationMillis, EASINGS[this.easingOptions[this.easing]][this.easingDirectionOptions[this.easingDirection]])
  35. }
  36. onCompleted() {
  37. if (this.targetCameraPosition.equals(this.firstCameraPosition)) {
  38. this.targetCameraPosition = this.secondCameraPosition.clone()
  39. this.targetFocusPosition = this.secondFocusPosition.clone()
  40. } else {
  41. this.targetCameraPosition = this.firstCameraPosition.clone()
  42. this.targetFocusPosition = this.firstFocusPosition.clone()
  43. }
  44. }
  45. }
  46. RE.registerComponent(TweenCameraTruck);