TweenScale.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 TweenScale extends RE.Component {
  6. @RE.props.button() run = this.addScaleTween.bind(this)
  7. @RE.props.vector3() targetScale: THREE.Vector3 = new THREE.Vector3(2, 2, 2)
  8. @RE.props.num() durationMillis: number = 2000
  9. @RE.props.select() easing = 10;
  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. firstScale = new THREE.Vector3(1, 1, 1)
  14. secondScale = new THREE.Vector3(2, 2, 2)
  15. awake() {
  16. this.targetScale = this.secondScale.clone()
  17. }
  18. start() {
  19. }
  20. update() {
  21. }
  22. addScaleTween() {
  23. Tween.create(this.object3d.scale, this.targetScale, this.durationMillis, EASINGS[this.easingOptions[this.easing]][this.easingDirectionOptions[this.easingDirection]], this.onCompleted.bind(this))
  24. }
  25. onCompleted() {
  26. if (this.targetScale.equals(this.firstScale)) {
  27. this.targetScale = this.secondScale.clone()
  28. } else {
  29. this.targetScale = this.firstScale.clone()
  30. }
  31. }
  32. }
  33. RE.registerComponent(TweenScale);