var easing = {}; //渐变曲线函数,反应加速度的变化 easing.linearTween = function(e, t, i, n) { return i * e / n + t } , easing.easeInQuad = function(e, t, i, n) { return e /= n, i * e * e + t } , easing.easeOutQuad = function(e, t, i, n) { return e /= n, -i * e * (e - 2) + t } , easing.easeInOutQuad = function(e, t, i, n) { return e /= n / 2, e < 1 ? i / 2 * e * e + t : (e--, -i / 2 * (e * (e - 2) - 1) + t) } , easing.easeInCubic = function(e, t, i, n) { return e /= n, i * e * e * e + t } , easing.easeOutCubic = function(e, t, i, n) { return e /= n, e--, i * (e * e * e + 1) + t } , easing.easeInOutCubic = function(e, t, i, n) { return e /= n / 2, e < 1 ? i / 2 * e * e * e + t : (e -= 2, i / 2 * (e * e * e + 2) + t) } , easing.easeInQuart = function(e, t, i, n) { return e /= n, i * e * e * e * e + t } , easing.easeOutQuart = function(e, t, i, n) { return e /= n, e--, -i * (e * e * e * e - 1) + t } , easing.easeInOutQuart = function(e, t, i, n) { return e /= n / 2, e < 1 ? i / 2 * e * e * e * e + t : (e -= 2, -i / 2 * (e * e * e * e - 2) + t) } , easing.easeInQuint = function(e, t, i, n) { return e /= n, i * e * e * e * e * e + t } , easing.easeOutQuint = function(e, t, i, n) { return e /= n, e--, i * (e * e * e * e * e + 1) + t } , easing.easeInOutQuint = function(e, t, i, n) { return e /= n / 2, e < 1 ? i / 2 * e * e * e * e * e + t : (e -= 2, i / 2 * (e * e * e * e * e + 2) + t) } , easing.easeInSine = function(e, t, i, n) { return -i * Math.cos(e / n * (Math.PI / 2)) + i + t } , easing.easeOutSine = function(e, t, i, n) { return i * Math.sin(e / n * (Math.PI / 2)) + t } , easing.easeInOutSine = function(e, t, i, n) { return -i / 2 * (Math.cos(Math.PI * e / n) - 1) + t } , easing.easeInExpo = function(e, t, i, n) { return i * Math.pow(2, 10 * (e / n - 1)) + t } , easing.easeOutExpo = function(e, t, i, n) { return i * (-Math.pow(2, -10 * e / n) + 1) + t } , easing.easeInOutExpo = function(e, t, i, n) { return e /= n / 2, e < 1 ? i / 2 * Math.pow(2, 10 * (e - 1)) + t : (e--, i / 2 * (-Math.pow(2, -10 * e) + 2) + t) } , easing.easeInCirc = function(e, t, i, n) { return e /= n, -i * (Math.sqrt(1 - e * e) - 1) + t } , easing.easeOutCirc = function(e, t, i, n) { return e /= n, e--, i * Math.sqrt(1 - e * e) + t } , easing.easeInOutCirc = function(e, t, i, n) { return e /= n / 2, e < 1 ? -i / 2 * (Math.sqrt(1 - e * e) - 1) + t : (e -= 2, i / 2 * (Math.sqrt(1 - e * e) + 1) + t) } , easing.easeInElastic = function(e, t, i, n) { var r = 1.70158 , o = 0 , a = i; return 0 === e ? t : 1 === (e /= n) ? t + i : (o || (o = .3 * n), a < Math.abs(i) ? (a = i, r = o / 4) : r = o / (2 * Math.PI) * Math.asin(i / a), -(a * Math.pow(2, 10 * (e -= 1)) * Math.sin((e * n - r) * (2 * Math.PI) / o)) + t) } , easing.easeOutElastic = function(e, t, i, n) { var r = 1.70158 , o = 0 , a = i; return 0 === e ? t : 1 === (e /= n) ? t + i : (o || (o = .3 * n), a < Math.abs(i) ? (a = i, r = o / 4) : r = o / (2 * Math.PI) * Math.asin(i / a), a * Math.pow(2, -10 * e) * Math.sin((e * n - r) * (2 * Math.PI) / o) + i + t) } , easing.easeInOutElastic = function(e, t, i, n) { var r = 1.70158 , o = 0 , a = i; return 0 === e ? t : 2 === (e /= n / 2) ? t + i : (o || (o = n * (.3 * 1.5)), a < Math.abs(i) ? (a = i, r = o / 4) : r = o / (2 * Math.PI) * Math.asin(i / a), e < 1 ? -.5 * (a * Math.pow(2, 10 * (e -= 1)) * Math.sin((e * n - r) * (2 * Math.PI) / o)) + t : a * Math.pow(2, -10 * (e -= 1)) * Math.sin((e * n - r) * (2 * Math.PI) / o) * .5 + i + t) } , easing.easeInBack = function(e, t, i, n, r) { return void 0 === r && (r = 1.70158), i * (e /= n) * e * ((r + 1) * e - r) + t } , easing.easeOutBack = function(e, t, i, n, r) { return void 0 === r && (r = 1.70158), i * ((e = e / n - 1) * e * ((r + 1) * e + r) + 1) + t } , easing.easeInOutBack = function(e, t, i, n, r) { return void 0 === r && (r = 1.70158), (e /= n / 2) < 1 ? i / 2 * (e * e * (((r *= 1.525) + 1) * e - r)) + t : i / 2 * ((e -= 2) * e * (((r *= 1.525) + 1) * e + r) + 2) + t } , easing.easeOutBounce = function(e, t, i, n) { return (e /= n) < 1 / 2.75 ? i * (7.5625 * e * e) + t : e < 2 / 2.75 ? i * (7.5625 * (e -= 1.5 / 2.75) * e + .75) + t : e < 2.5 / 2.75 ? i * (7.5625 * (e -= 2.25 / 2.75) * e + .9375) + t : i * (7.5625 * (e -= 2.625 / 2.75) * e + .984375) + t } , easing.easeInBounce = function(e, t, i, r) { return i - easing.easeOutBounce(r - e, 0, i, r) + t } , easing.easeInOutBounce = function(e, t, i, r) { return e < r / 2 ? .5 * easing.easeInBounce(2 * e, 0, i, r) + t : .5 * easing.easeOutBounce(x, 2 * e - r, 0, i, r) + .5 * i + t } var lerp = { vector: function(e, t, f) {//xzw change, add f var i = e.clone(); return t = t.clone(), function(n) { e.set(i.x * (1 - n) + t.x * n, i.y * (1 - n) + t.y * n, i.z * (1 - n) + t.z * n) f && f(e,n); } }, quaternion: function(e, t, f) {//xzw change, add f var i = e.clone(); return function(n) { e.copy(i).slerp(t, n); f && f(e,n); } }, property: function(e, t, i, n) { var r = e[t]; return function(o) { e[t] = r * (1 - o) + i * o, n && n(e[t]) } }, uniform: function(e, t, i) { var n = e.material.uniforms[t].value; return function(r) { try{ e.material.uniforms[t] && (e.material.uniforms[t].value = n * (1 - r) + i * r) }catch(e){ console.log(1) } } }, matrix4: function(e, t) { var i = e.clone(); return function(n) { for (var r = e.elements, o = i.elements, a = t.elements, s = 0; s < 16; s++) r[s] = o[s] * (1 - n) + a[s] * n } }, allUniforms: function(e, t, i) { var n = e.map(function(e) { return this.uniform(e, t, i) } .bind(this)); return function(e) { n.forEach(function(t) { t(e) }) } } }; /* 渐变 */ var transitions = { globalDone: null, funcs: [], counter: 0, uniqueID: 0, start: function(e, t, i, r, o, a, s, cancelFun) { return r = r || 0, this.funcs.push({ func: e, current: -r * Math.abs(t), //当前时间 duration: (1 - Math.max(r, 0)) * Math.abs(t), //总时长 done: i, easing: o || easing.linearTween, //渐变曲线 cycling: t < 0, running: !0, debug: r < 0, name: a || "T" + this.counter, id: void 0 === s ? this.counter : s, paused: !1, cancelFun : cancelFun, //取消时执行的函数 }), e(0, 16), this.counter += 1, e }, trigger: function(e) { var t = void 0 === e.delayRatio ? 0 : e.delayRatio , i = e.func || function() {} , r = void 0 === e.duration ? 0 : e.duration; void 0 !== e.cycling && e.cycling && (r = -Math.abs(r)); var o = e.done || null , a = e.easing || easing.linearTween , s = e.name || "R" + this.counter , l = void 0 === e.id ? this.counter : e.id; return this.start(i, r, o, t, a, s, l) }, setTimeout: function(e, t, i) { var n = void 0 === i ? this.counter : i; return this.trigger({ done: e, duration: void 0 === t ? 0 : t, name: "O" + this.counter, id: n }) }, pause: function() { this.paused = !0 }, resume: function() { this.paused = !1 }, update: function(e) { this.funcs.forEach(function(t) { if (!(t.paused || (t.current += 1e3 * e, t.current < 0))) if (t.current >= t.duration && !t.cycling) { var i = t.easing(1, 0, 1, 1); t.func(i, 1e3 * e), t.done && t.done(), t.running = !1 } else { var n = t.easing(t.current % t.duration / t.duration, 0, 1, 1) , r = t.func(n, 1e3 * e) || !1; r && (t.done && t.done(), t.running = !1) } }); var t = this.funcs.length; this.funcs = this.funcs.filter(function(e) { return e.running }); var i = this.funcs.length; if (t > 0 && 0 === i && this.globalDone) { var n = this.globalDone; this.globalDone = null, n() } }, adjustSpeed: function(e, t) { for (var i = this.getById(e), n = 0; n < i.length; n++) { var r = i[n]; r.duration /= t, r.current /= t } }, getById: function(e) { return this.funcs.filter(function(t) { return e === t.id }) }, get: function(e) { for (var t = 0; t < this.funcs.length; t += 1) if (this.funcs[t].func === e) return this.funcs[t]; return null }, isRunning: function(e) { var t = this.get(e); return null !== t && t.running }, countActive: function() { for (var e = 0, t = 0; t < this.funcs.length; t += 1) e += this.funcs[t].running; return e }, listActive: function() { for (var e = [], t = 0; t < this.funcs.length; t += 1) this.funcs[t].running && e.push(this.funcs[t].name); return e }, done: function(e) { this.globalDone = e }, cancelById: function(e, dealCancelFun) { //xzw add dealDone var t = void 0 === e ? 0 : e; this.funcs = this.funcs.filter(function(e) { var is = e.id == t; if(is && dealCancelFun){ e.cancelFun && e.cancelFun() } return !is }) }, cancel: function(e) { this.funcs = this.funcs.filter(function(t) { return t.func !== e }) }, getUniqueId: function() { return this.uniqueID -= 1, this.uniqueID } }; export {transitions, lerp, easing}