XrTeamCameraAnimation.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import XrFrame from 'XrFrame';
  2. const xrFrameSystem = wx.getXrFrameSystem();
  3. interface IXrTeamCameraAnimtionData {
  4. targets: {
  5. hikari: XrFrame.Vector3;
  6. roam: XrFrame.Vector3;
  7. xinyi: XrFrame.Vector3;
  8. final: XrFrame.Vector3;
  9. [key: string]: XrFrame.Vector3;
  10. },
  11. startY: number;
  12. finalY: number;
  13. }
  14. interface IXrTeamCameraAnimationOptions {
  15. }
  16. export default class XrTeamCameraAnimation extends xrFrameSystem.Animation<
  17. IXrTeamCameraAnimtionData,
  18. IXrTeamCameraAnimationOptions
  19. > {
  20. private _camera: XrFrame.Transform | undefined;
  21. private _target: XrFrame.Transform | undefined;
  22. private _targets: IXrTeamCameraAnimtionData['targets'] | undefined;
  23. private _startY: number | undefined;
  24. private _finalY: number | undefined;
  25. private _startC: XrFrame.Vector3 = new xrFrameSystem.Vector3();
  26. private _endC: XrFrame.Vector3 = new xrFrameSystem.Vector3();
  27. private _startT: XrFrame.Vector3 = new xrFrameSystem.Vector3();
  28. private _endT: XrFrame.Vector3 = new xrFrameSystem.Vector3();
  29. public onInit(data: IXrTeamCameraAnimtionData) {
  30. console.log('anim data', data);
  31. this._targets = data.targets;
  32. this._startY = data.startY;
  33. this._finalY = data.finalY;
  34. this.clipNames = [
  35. 'hikari',
  36. 'roam',
  37. 'xinyi',
  38. 'final'
  39. ];
  40. }
  41. public onPlay(el: XrFrame.Element, clipName: string, options: IXrTeamCameraAnimationOptions): {
  42. duration: number,
  43. loop?: number,
  44. delay?: number,
  45. direction?: XrFrame.TDirection
  46. } {
  47. const isFinal = clipName === 'final';
  48. this._camera = this._camera || el.getComponent(xrFrameSystem.Transform);
  49. this._target = el.getComponent(xrFrameSystem.Camera).target;
  50. this._startT.set(this._target.position);
  51. this._endT.setValue(this._targets![clipName].x, isFinal ? this._finalY! : this._startY!, this._targets![clipName].z);
  52. this._startC.set(this._camera.position);
  53. this._endC.set(this._endT);
  54. this._endC.z += isFinal ? 3 : 1;
  55. return {duration: isFinal ? 4 : 2};
  56. }
  57. /**
  58. * @param progress 0~1
  59. */
  60. public onUpdate(el: XrFrame.Element, progress: number, reverse: boolean) {
  61. progress = xrFrameSystem.noneParamsEaseFuncs['ease-in-out'](progress);
  62. this._startT?.lerp(this._endT, progress, this._target?.position);
  63. this._startC?.lerp(this._endC, progress, this._camera?.position);
  64. }
  65. public onPause(el: XrFrame.Element) {
  66. }
  67. public onResume(el: XrFrame.Element) {
  68. }
  69. public onStop(el: XrFrame.Element) {
  70. }
  71. }