"use strict";exports.__esModule=!0,exports.default=void 0;var _three=require("three"),_animation=require("../core/animation"),_tween=require("@tweenjs/tween.js");class ModelAnimation{constructor(a){this.model=void 0,this.model=a}rotation(a,b={}){const c=this.model.position.clone(),d=new _three.Matrix4;d.lookAt(c,a,this.model.up),d.multiply(new _three.Matrix4().makeRotationFromEuler(new _three.Euler(0,Math.PI/2,0)));const e=new _three.Quaternion().setFromRotationMatrix(d),f=(0,_animation.createAnimationFromTween)(new _tween.Tween(new _three.Quaternion()).to(e,b.duration||800).easing(b.easing||_tween.Easing.Linear.None).onUpdate(()=>{this.model.quaternion.slerp(e,b.slerp||.05)}));return f.once(_animation.AnimationEventType.complete,()=>{this.model.quaternion.set(e.x,e.y,e.z,e.w)}),f.start(),f}moveTo(a,b={}){let c=[],d=!1,e=0;const f=a=>{const b=[];if(Array.isArray(a)&&Array.isArray(a[0]))a.forEach(a=>{let[c,d,e]=a;b.push(new _three.Vector3(c,d,e))});else{let[c,d,e]=a;b.push(new _three.Vector3(c,d,e))}return b},g=(a,f=!0)=>{if(d)return;const i=this.model.position.clone();if(f&&b.rotation)return void this.rotation(a,b.rotation).once(_animation.AnimationEventType.complete,()=>{g(a,!1)});const j=b.duration||40*(1e3*(i.distanceTo(a)/(b.speed||100))),k=(0,_animation.createAnimationFromTween)(new _tween.Tween(i).to(a,j).easing(b.easing||_tween.Easing.Linear.None).onUpdate(a=>{!0==d?k.stop():this.model.position.set(a.x,a.y,a.z)}));k.once(_animation.AnimationEventType.complete,()=>{b.process&&b.process.call(h,c.indexOf(a));(e!=c.length-1||b.mode)&&(e==c.length-1?("reverse"===b.mode&&c.reverse(),e=0):e++,g(c[e]))}),k.start()};c=f(a),g(c[e],!0);const h={clear:()=>{c=[],e=0},insert:(a,b)=>{const d=f(a);"number"==typeof b?c.splice(b,0,...d):c=c.concat(d)},remove:(a,b=1)=>{c.splice(a,b)},continue(){!1==d||(d=!1,e<c.length&&g(c[e],!0))},pause:()=>{d=!0},stop:()=>{d=!0}};return h}breath(a=.8,b=300,c=1e6,d=!0){let e=new _three.Object3D;this.model.traverse(a=>{a.isSprite&&(e=a)});let f=d?e.scale.clone():this.model.scale.clone();const g={x:e.scale.x,y:e.scale.y,z:e.scale.z},h={x:e.scale.x*a,y:e.scale.y*a,z:e.scale.z*a},i=(0,_animation.createAnimationFromTween)(new _tween.Tween(g).to(h,b).easing(_tween.Easing.Bounce.InOut).onUpdate(()=>{d?e.scale.set(g.x,g.y,g.z):this.model.scale.set(g.x,g.y,g.z)}).yoyo(!0).repeat(c));return i.once("complete",()=>{d?e.scale.set(f.x,f.y,f.z):this.model.scale.set(f.x,f.y,f.z)}),i.start(),()=>{i.stop()}}bounce(a=.2,b=300,c=1e6,d=!0){let e=new _three.Object3D;this.model.traverse(a=>{a.isSprite&&(e=a)});let f=d?e.position.y:this.model.position.y;const g={y:f},h={y:f-a},i=(0,_animation.createAnimationFromTween)(new _tween.Tween(g).to(h,b).easing(_tween.Easing.Bounce.InOut).onUpdate(()=>{d?e.position.set(e.position.x,g.y,e.position.z):this.model.position.set(this.model.position.x,g.y,this.model.position.z)}).yoyo(!0).repeat(c));return i.once("complete",()=>{d?e.position.set(e.position.x,f,e.position.z):this.model.position.set(this.model.position.x,f,this.model.position.z)}),i.start(),()=>{i.stop()}}}exports.default=ModelAnimation;