diff --git a/cocos/3d/framework/animation-component.ts b/cocos/3d/framework/animation-component.ts
index 9cd59cd4f3..f75562a0da 100644
--- a/cocos/3d/framework/animation-component.ts
+++ b/cocos/3d/framework/animation-component.ts
@@ -27,6 +27,7 @@ import { Component } from '../../components/component';
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
import { ccenum } from '../../core/value-types/enum';
import AnimationClip, { AnimationSampler, AnimationTarget } from '../assets/animation-clip';
+import { clamp01 } from '../../core/vmath';
enum BlendMode {
/**
@@ -144,6 +145,12 @@ class AnimationState {
}
}
+interface IBlendedAnimationState {
+ state: AnimationState | null;
+ blendTime: number;
+ blendDuration: number;
+}
+
/**
* !#en Animation Controller
*
@@ -152,10 +159,7 @@ class AnimationState {
class AnimationCtrl {
private _animationTarget: AnimationTarget | null = null;
private _animationSampler: AnimationSampler | null = null;
- private _current: AnimationState | null = null;
- private _next: AnimationState | null = null;
- private _blendTime = 0.0;
- private _blendDuration = 0.3;
+ private _animations: IBlendedAnimationState[] = [];
/**
* !#en Set up the animation target
@@ -177,17 +181,11 @@ class AnimationCtrl {
* @param duration
*/
public crossFade (to: AnimationState | null, duration: number) {
- if (this._current === to) {
- return;
- }
- if (this._current && duration > 0.0) {
- this._next = to;
- this._blendTime = 0.0;
- this._blendDuration = duration;
- } else {
- this._current = to;
- this._next = null;
- }
+ this._animations.unshift({
+ state: to,
+ blendDuration: duration,
+ blendTime: 0.0,
+ });
}
public tick (deltaTime: number) {
@@ -195,34 +193,28 @@ class AnimationCtrl {
return;
}
- this._animationSampler.reset();
-
- // handle blend
- if (this._current && this._next) {
- const t0 = this._getTime(this._current);
- const t1 = this._getTime(this._next);
-
- const alpha = this._blendTime / this._blendDuration;
-
- this._current.time += deltaTime;
- this._next.time += deltaTime;
- this._blendTime += deltaTime;
-
- if (alpha > 1.0) {
- this._current = this._next;
- this._next = null;
- this._animationSampler.sample(this._current.clip, t1, 1.0);
- } else {
- this._animationSampler.sample(this._current.clip, t0, alpha);
- this._animationSampler.sample(this._next.clip, t1, 1.0 - alpha);
- }
+ if (this._animations.length === 0) {
+ return;
}
- // handle playing
- else if (this._current) {
- const t0 = this._getTime(this._current);
- this._animationSampler.sample(this._current.clip, t0, 1.0);
- this._current.time += deltaTime;
+ this._animationSampler.reset();
+
+ let absoluteWeight = 1.0;
+ for (let i = 0; i < this._animations.length; ++i) {
+ if (absoluteWeight === 0) {
+ this._animations.splice(i);
+ break;
+ }
+ const ba = this._animations[i];
+ ba.blendTime += deltaTime;
+ const relativeWeight = clamp01(ba.blendTime / ba.blendDuration);
+ const weight = relativeWeight * absoluteWeight;
+ absoluteWeight = absoluteWeight * (1.0 - relativeWeight);
+ if (ba.state) {
+ ba.state.time += deltaTime;
+ const t = this._getTime(ba.state);
+ this._animationSampler.sample(ba.state.clip, t, weight);
+ }
}
this._animationSampler.apply();
diff --git a/cocos/animation/CCAnimation.js b/cocos/animation/CCAnimation.js
deleted file mode 100644
index 6314d5d338..0000000000
--- a/cocos/animation/CCAnimation.js
+++ /dev/null
@@ -1,695 +0,0 @@
-/****************************************************************************
- Copyright (c) 2013-2016 Chukong Technologies Inc.
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-const AnimationAnimator = require('./animation-animator');
-const AnimationClip = require('./animation-clip');
-const EventTarget = require('../core/event/event-target');
-const js = require('../core/utils/js');
-
-function equalClips (clip1, clip2) {
- if (clip1 === clip2) {
- return true;
- }
-
- return clip1 && clip2 && (clip1.name === clip2.name || clip1._uuid === clip2._uuid);
-}
-
-/**
- * !#en The event type supported by Animation
- * !#zh Animation 支持的事件类型
- * @class Animation.EventType
- * @static
- * @namespace Animationd
- */
-var EventType = cc.Enum({
- /**
- * !#en Emit when begin playing animation
- * !#zh 开始播放时触发
- * @property {String} PLAY
- * @static
- */
- PLAY: 'play',
- /**
- * !#en Emit when stop playing animation
- * !#zh 停止播放时触发
- * @property {String} STOP
- * @static
- */
- STOP: 'stop',
- /**
- * !#en Emit when pause animation
- * !#zh 暂停播放时触发
- * @property {String} PAUSE
- * @static
- */
- PAUSE: 'pause',
- /**
- * !#en Emit when resume animation
- * !#zh 恢复播放时触发
- * @property {String} RESUME
- * @static
- */
- RESUME: 'resume',
- /**
- * !#en If animation repeat count is larger than 1, emit when animation play to the last frame
- * !#zh 假如动画循环次数大于 1,当动画播放到最后一帧时触发
- * @property {String} LASTFRAME
- * @static
- */
- LASTFRAME: 'lastframe',
- /**
- * !#en Emit when finish playing animation
- * !#zh 动画播放完成时触发
- * @property {String} FINISHED
- * @static
- */
- FINISHED: 'finished'
-})
-
-/**
- * !#en The animation component is used to play back animations.
- *
- * Animation provide several events to register:
- * - play : Emit when begin playing animation
- * - stop : Emit when stop playing animation
- * - pause : Emit when pause animation
- * - resume : Emit when resume animation
- * - lastframe : If animation repeat count is larger than 1, emit when animation play to the last frame
- * - finished : Emit when finish playing animation
- *
- * !#zh Animation 组件用于播放动画。
- *
- * Animation 提供了一系列可注册的事件:
- * - play : 开始播放时
- * - stop : 停止播放时
- * - pause : 暂停播放时
- * - resume : 恢复播放时
- * - lastframe : 假如动画循环次数大于 1,当动画播放到最后一帧时
- * - finished : 动画播放完成时
- *
- * @class Animation
- * @extends Component
- * @uses EventTarget
- */
-var Animation = cc.Class({
- name: 'cc.Animation',
- extends: require('./component'),
- mixins: [EventTarget],
-
- editor: CC_EDITOR && {
- menu: 'i18n:MAIN_MENU.component.others/Animation',
- help: 'i18n:COMPONENT.help_url.animation',
- executeInEditMode: true,
- },
-
- statics: {
- EventType
- },
-
- ctor: function () {
- cc.EventTarget.call(this);
-
- // The actual implement for Animation
- this._animator = null;
-
- this._nameToState = js.createMap(true);
- this._didInit = false;
-
- this._currentClip = null;
- },
-
- properties: {
-
- _defaultClip: {
- default: null,
- type: AnimationClip,
- },
-
- /**
- * !#en Animation will play the default clip when start game.
- * !#zh 在勾选自动播放或调用 play() 时默认播放的动画剪辑。
- * @property defaultClip
- * @type {AnimationClip}
- */
- defaultClip: {
- type: AnimationClip,
- get: function () {
- return this._defaultClip;
- },
- set: function (value) {
- if (!CC_EDITOR || (cc.engine && cc.engine.isPlaying)) {
- return;
- }
-
- this._defaultClip = value;
-
- if (!value) {
- return;
- }
-
- var clips = this._clips;
-
- for (var i = 0, l = clips.length; i < l; i++) {
- if (equalClips(value, clips[i])) {
- return;
- }
- }
-
- this.addClip(value);
- },
- tooltip: CC_DEV && 'i18n:COMPONENT.animation.default_clip'
- },
-
- /**
- * !#en Current played clip.
- * !#zh 当前播放的动画剪辑。
- * @property currentClip
- * @type {AnimationClip}
- */
- currentClip: {
- get: function () {
- return this._currentClip;
- },
- set: function (value) {
- this._currentClip = value;
- },
- type: AnimationClip,
- visible: false
- },
-
- /**
- * !#en All the clips used in this animation.
- * !#zh 通过脚本可以访问并播放的 AnimationClip 列表。
- * @property _clips
- * @type {AnimationClip[]}
- * @private
- */
- _clips: {
- default: [],
- type: [AnimationClip],
- tooltip: CC_DEV && 'i18n:COMPONENT.animation.clips',
- visible: true
- },
-
- /**
- * !#en Whether the animation should auto play the default clip when start game.
- * !#zh 是否在运行游戏后自动播放默认动画剪辑。
- * @property playOnLoad
- * @type {Boolean}
- * @default true
- */
- playOnLoad: {
- default: false,
- tooltip: CC_DEV && 'i18n:COMPONENT.animation.play_on_load'
- }
- },
-
- start: function () {
- if (!CC_EDITOR && this.playOnLoad && this._defaultClip) {
- var isPlaying = this._animator && this._animator.isPlaying;
- if (!isPlaying) {
- var state = this.getAnimationState(this._defaultClip.name);
- this._animator.playState(state);
- }
- }
- },
-
- onEnable: function () {
- if (this._animator) {
- this._animator.resume();
- }
- },
-
- onDisable: function () {
- if (this._animator) {
- this._animator.pause();
- }
- },
-
- onDestroy: function () {
- this.stop();
- },
-
- ///////////////////////////////////////////////////////////////////////////////
- // Public Methods
- ///////////////////////////////////////////////////////////////////////////////
-
- /**
- * !#en Get all the clips used in this animation.
- * !#zh 获取动画组件上的所有动画剪辑。
- * @method getClips
- * @return {AnimationClip[]}
- */
- getClips: function () {
- return this._clips;
- },
-
- /**
- * !#en Plays an animation and stop other animations.
- * !#zh 播放指定的动画,并且停止当前正在播放动画。如果没有指定动画,则播放默认动画。
- * @method play
- * @param {String} [name] - The name of animation to play. If no name is supplied then the default animation will be played.
- * @param {Number} [startTime] - play an animation from startTime
- * @return {AnimationState} - The AnimationState of playing animation. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return null.
- * @example
- * var animCtrl = this.node.getComponent(cc.Animation);
- * animCtrl.play("linear");
- */
- play: function (name, startTime) {
- var state = this.playAdditive(name, startTime);
- this._animator.stopStatesExcept(state);
- return state;
- },
-
- /**
- * !#en
- * Plays an additive animation, it will not stop other animations.
- * If there are other animations playing, then will play several animations at the same time.
- * !#zh 播放指定的动画(将不会停止当前播放的动画)。如果没有指定动画,则播放默认动画。
- * @method playAdditive
- * @param {String} [name] - The name of animation to play. If no name is supplied then the default animation will be played.
- * @param {Number} [startTime] - play an animation from startTime
- * @return {AnimationState} - The AnimationState of playing animation. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return null.
- * @example
- * // linear_1 and linear_2 at the same time playing.
- * var animCtrl = this.node.getComponent(cc.Animation);
- * animCtrl.playAdditive("linear_1");
- * animCtrl.playAdditive("linear_2");
- */
- playAdditive: function (name, startTime) {
- this._init();
- var state = this.getAnimationState(name || (this._defaultClip && this._defaultClip.name));
-
- if (state) {
- this.enabled = true;
-
- var animator = this._animator;
- if (animator.isPlaying && state.isPlaying) {
- if (state.isPaused) {
- animator.resumeState(state);
- }
- else {
- animator.stopState(state);
- animator.playState(state, startTime);
- }
- }
- else {
- animator.playState(state, startTime);
- }
-
- // Animation cannot be played when the component is not enabledInHierarchy.
- // That would cause an error for the animation lost the reference after destroying the node.
- // If users play the animation when the component is not enabledInHierarchy,
- // we pause the animator here so that it will automatically resume the animation when users enable the component.
- if (!this.enabledInHierarchy) {
- animator.pause();
- }
-
- this.currentClip = state.clip;
- }
- return state;
- },
-
- /**
- * !#en Stops an animation named name. If no name is supplied then stops all playing animations that were started with this Animation.
- * Stopping an animation also Rewinds it to the Start.
- * !#zh 停止指定的动画。如果没有指定名字,则停止当前正在播放的动画。
- * @method stop
- * @param {String} [name] - The animation to stop, if not supplied then stops all playing animations.
- */
- stop: function (name) {
- if (!this._didInit) {
- return;
- }
- if (name) {
- var state = this._nameToState[name];
- if (state) {
- this._animator.stopState(state);
- }
- }
- else {
- this._animator.stop();
- }
- },
-
- /**
- * !#en Pauses an animation named name. If no name is supplied then pauses all playing animations that were started with this Animation.
- * !#zh 暂停当前或者指定的动画。如果没有指定名字,则暂停当前正在播放的动画。
- * @method pause
- * @param {String} [name] - The animation to pauses, if not supplied then pauses all playing animations.
- */
- pause: function (name) {
- if (!this._didInit) {
- return;
- }
- if (name) {
- var state = this._nameToState[name];
- if (state) {
- this._animator.pauseState(state);
- }
- }
- else {
- this.enabled = false;
- }
- },
-
- /**
- * !#en Resumes an animation named name. If no name is supplied then resumes all paused animations that were started with this Animation.
- * !#zh 重新播放指定的动画,如果没有指定名字,则重新播放当前正在播放的动画。
- * @method resume
- * @param {String} [name] - The animation to resumes, if not supplied then resumes all paused animations.
- */
- resume: function (name) {
- if (!this._didInit) {
- return;
- }
- if (name) {
- var state = this._nameToState[name];
- if (state) {
- this._animator.resumeState(state);
- }
- }
- else {
- this.enabled = true;
- }
- },
-
- /**
- * !#en Make an animation named name go to the specified time. If no name is supplied then make all animations go to the specified time.
- * !#zh 设置指定动画的播放时间。如果没有指定名字,则设置当前播放动画的播放时间。
- * @method setCurrentTime
- * @param {Number} [time] - The time to go to
- * @param {String} [name] - Specified animation name, if not supplied then make all animations go to the time.
- */
- setCurrentTime: function (time, name) {
- this._init();
- if (name) {
- var state = this._nameToState[name];
- if (state) {
- this._animator.setStateTime(state, time);
- }
- }
- else {
- this._animator.setStateTime(time);
- }
- },
-
- /**
- * !#en Returns the animation state named name. If no animation with the specified name, the function will return null.
- * !#zh 获取当前或者指定的动画状态,如果未找到指定动画剪辑则返回 null。
- * @method getAnimationState
- * @param {String} name
- * @return {AnimationState}
- */
- getAnimationState: function (name) {
- this._init();
- var state = this._nameToState[name];
-
- if (CC_EDITOR && (!state || !cc.js.array.contains(this._clips, state.clip))) {
- this._didInit = false;
-
- if (this.animator) {
- this.animator.stop();
- }
-
- this._init();
- state = this._nameToState[name];
- }
-
- if (state && !state.curveLoaded) {
- this._animator._reloadClip(state);
- }
-
- return state || null;
- },
-
- /**
- * !#en Adds a clip to the animation with name newName. If a clip with that name already exists it will be replaced with the new clip.
- * !#zh 添加动画剪辑,并且可以重新设置该动画剪辑的名称。
- * @method addClip
- * @param {AnimationClip} clip - the clip to add
- * @param {String} [newName]
- * @return {AnimationState} - The AnimationState which gives full control over the animation clip.
- */
- addClip: function (clip, newName) {
- if (!clip) {
- cc.warnID(3900);
- return;
- }
- this._init();
-
- // add clip
- if (!cc.js.array.contains(this._clips, clip)) {
- this._clips.push(clip);
- }
-
- // replace same name clip
- newName = newName || clip.name;
- var oldState = this._nameToState[newName];
- if (oldState) {
- if (oldState.clip === clip) {
- return oldState;
- }
- else {
- var index = this._clips.indexOf(oldState.clip);
- if (index !== -1) {
- this._clips.splice(index, 1);
- }
- }
- }
-
- // replace state
- var newState = new cc.AnimationState(clip, newName);
- this._nameToState[newName] = newState;
- return newState;
- },
-
- /**
- * !#en
- * Remove clip from the animation list. This will remove the clip and any animation states based on it.
- * If there are animation states depand on the clip are playing or clip is defaultClip, it will not delete the clip.
- * But if force is true, then will always remove the clip and any animation states based on it. If clip is defaultClip, defaultClip will be reset to null
- * !#zh
- * 从动画列表中移除指定的动画剪辑,
- * 如果依赖于 clip 的 AnimationState 正在播放或者 clip 是 defaultClip 的话,默认是不会删除 clip 的。
- * 但是如果 force 参数为 true,则会强制停止该动画,然后移除该动画剪辑和相关的动画。这时候如果 clip 是 defaultClip,defaultClip 将会被重置为 null。
- * @method removeClip
- * @param {AnimationClip} clip
- * @param {Boolean} [force=false] - If force is true, then will always remove the clip and any animation states based on it.
- */
- removeClip: function (clip, force) {
- if (!clip) {
- cc.warnID(3901);
- return;
- }
- this._init();
-
- var state;
- for (var name in this._nameToState) {
- state = this._nameToState[name];
- var stateClip = state.clip;
- if (stateClip === clip) {
- break;
- }
- }
-
- if (clip === this._defaultClip) {
- if (force) this._defaultClip = null;
- else {
- if (!CC_TEST) cc.warnID(3902);
- return;
- }
- }
-
- if (state && state.isPlaying) {
- if (force) this.stop(state.name);
- else {
- if (!CC_TEST) cc.warnID(3903);
- return;
- }
- }
-
- this._clips = this._clips.filter(function (item) {
- return item !== clip;
- });
-
- if (state) {
- delete this._nameToState[state.name];
- }
- },
-
- /**
- * !#en
- * Samples animations at the current state.
- * This is useful when you explicitly want to set up some animation state, and sample it once.
- * !#zh 对指定或当前动画进行采样。你可以手动将动画设置到某一个状态,然后采样一次。
- * @method sample
- * @param {String} name
- */
- sample: function (name) {
- this._init();
-
- if (name) {
- var state = this._nameToState[name];
- if (state) {
- state.sample();
- }
- }
- else {
- this._animator.sample();
- }
- },
-
-
- /**
- * !#en
- * Register animation event callback.
- * The event arguments will provide the AnimationState which emit the event.
- * When play an animation, will auto register the event callback to the AnimationState, and unregister the event callback from the AnimationState when animation stopped.
- * !#zh
- * 注册动画事件回调。
- * 回调的事件里将会附上发送事件的 AnimationState。
- * 当播放一个动画时,会自动将事件注册到对应的 AnimationState 上,停止播放时会将事件从这个 AnimationState 上取消注册。
- * @method on
- * @param {String} type - A string representing the event type to listen for.
- * @param {Function} callback - The callback that will be invoked when the event is dispatched.
- * The callback is ignored if it is a duplicate (the callbacks are unique).
- * @param {cc.AnimationState} state
- * @param {Object} [target] - The target (this object) to invoke the callback, can be null
- * @param {Boolean} [useCapture=false] - When set to true, the capture argument prevents callback
- * from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE.
- * When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE.
- * Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.
- *
- * @return {Function} - Just returns the incoming callback so you can save the anonymous function easier.
- * @typescript
- * on(type: string, callback: (event: Event.EventCustom) => void, target?: any, useCapture?: boolean): (event: Event.EventCustom) => void
- * on(type: string, callback: (event: T) => void, target?: any, useCapture?: boolean): (event: T) => void
- * @example
- * onPlay: function (type, state) {
- * // callback
- * }
- *
- * // register event to all animation
- * animation.on('play', this.onPlay, this);
- */
- on: function (type, callback, target, useCapture) {
- this._init();
-
- var ret = this._EventTargetOn(type, callback, target, useCapture);
-
- var array = this._animator._anims.array;
- for (var i = 0; i < array.length; ++i) {
- array[i]._setListeners(this);
- }
-
- return ret;
- },
-
-
- /**
- * !#en
- * Unregister animation event callback.
- * !#zh
- * 取消注册动画事件回调。
- * @method off
- * @param {String} type - A string representing the event type being removed.
- * @param {Function} [callback] - The callback to remove.
- * @param {Object} [target] - The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
- * @param {Boolean} [useCapture=false] - Specifies whether the callback being removed was registered as a capturing callback or not.
- * If not specified, useCapture defaults to false. If a callback was registered twice,
- * one with capture and one without, each must be removed separately. Removal of a capturing callback
- * does not affect a non-capturing version of the same listener, and vice versa.
- *
- * @example
- * // unregister event to all animation
- * animation.off('play', this.onPlay, this);
- */
- off: function (type, callback, target, useCapture) {
- this._init();
-
- this._EventTargetOff(type, callback, target, useCapture);
-
- var nameToState = this._nameToState;
- for (var name in nameToState) {
- var state = nameToState[name];
- state._setListeners(null);
- }
- },
-
- ///////////////////////////////////////////////////////////////////////////////
- // Internal Methods
- ///////////////////////////////////////////////////////////////////////////////
-
- // Dont forget to call _init before every actual process in public methods.
- // Just invoking _init by onLoad is not enough because onLoad is called only if the entity is active.
-
- _init: function () {
- if (this._didInit) {
- return;
- }
- this._didInit = true;
- this._animator = new AnimationAnimator(this.node, this);
- this._createStates();
- },
-
- _createStates: function() {
- this._nameToState = js.createMap(true);
-
- // create animation states
- var state = null;
- var defaultClipState = false;
- for (var i = 0; i < this._clips.length; ++i) {
- var clip = this._clips[i];
- if (clip) {
- state = new cc.AnimationState(clip);
-
- if (CC_EDITOR) {
- this._animator._reloadClip(state);
- }
-
- this._nameToState[state.name] = state;
- if (equalClips(this._defaultClip, clip)) {
- defaultClipState = state;
- }
- }
- }
- if (this._defaultClip && !defaultClipState) {
- state = new cc.AnimationState(this._defaultClip);
-
- if (CC_EDITOR) {
- this._animator._reloadClip(state);
- }
-
- this._nameToState[state.name] = state;
- }
- }
-});
-
-Animation.prototype._EventTargetOn = EventTarget.prototype.on;
-Animation.prototype._EventTargetOff = EventTarget.prototype.off;
-
-cc.Animation = module.exports = Animation;
diff --git a/cocos/animation/animation-animator.js b/cocos/animation/animation-animator.js
deleted file mode 100644
index 1dcf87b3fc..0000000000
--- a/cocos/animation/animation-animator.js
+++ /dev/null
@@ -1,442 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var js = cc.js;
-var Playable = require('./playable');
-var DynamicAnimCurve = require('./animation-curves').DynamicAnimCurve;
-var quickFindIndex = require('./animation-curves').quickFindIndex;
-var sampleMotionPaths = require('./motion-path-helper').sampleMotionPaths;
-var EventAnimCurve = require('./animation-curves').EventAnimCurve;
-var EventInfo = require('./animation-curves').EventInfo;
-var WrapModeMask = require('./types').WrapModeMask;
-var binarySearch = require('../core/utils/binary-search').binarySearchEpsilon;
-
-// The actual animator for Animation Component
-
-function AnimationAnimator (target, animation) {
- Playable.call(this);
- this.target = target;
- this.animation = animation;
-
- this._anims = new js.array.MutableForwardIterator([]);
-}
-js.extend(AnimationAnimator, Playable);
-var p = AnimationAnimator.prototype;
-
-p.playState = function (state, startTime) {
- if (!state.clip) {
- return;
- }
-
- if (!state.curveLoaded) {
- initClipData(this.target, state);
- }
-
- state.animator = this;
- state.play();
-
- if (typeof startTime === 'number') {
- state.setTime(startTime);
- }
-
- this.play();
-};
-
-p.stopStatesExcept = function (state) {
- var iterator = this._anims;
- var array = iterator.array;
- for (iterator.i = 0; iterator.i < array.length; ++iterator.i) {
- var anim = array[iterator.i];
- if (anim === state) {
- continue;
- }
-
- this.stopState(anim);
- }
-};
-
-p.addAnimation = function (anim) {
- var index = this._anims.array.indexOf(anim);
- if (index === -1) {
- this._anims.push(anim);
- }
-
- anim._setListeners(this.animation);
-};
-
-p.removeAnimation = function (anim) {
- var index = this._anims.array.indexOf(anim);
- if (index >= 0) {
- this._anims.fastRemoveAt(index);
-
- if (this._anims.array.length === 0) {
- this.stop();
- }
- }
- else {
- cc.errorID(3908);
- }
-
- anim.animator = null;
-};
-
-p.sample = function () {
- var iterator = this._anims;
- var array = iterator.array;
- for (iterator.i = 0; iterator.i < array.length; ++iterator.i) {
- var anim = array[iterator.i];
- anim.sample();
- }
-};
-
-p.stopState = function (state) {
- if (state) {
- state.stop();
- }
-};
-
-p.pauseState = function (state) {
- if (state) {
- state.pause();
- }
-};
-
-p.resumeState = function (state) {
- if (state) {
- state.resume();
- }
-
- if (this.isPaused) {
- this.resume();
- }
-};
-
-p.setStateTime = function (state, time) {
- if (time !== undefined) {
- if (state) {
- state.setTime(time);
- state.sample();
- }
- }
- else {
- time = state;
-
- var array = this._anims.array;
- for (var i = 0; i < array.length; ++i) {
- var anim = array[i];
- anim.setTime(time);
- anim.sample();
- }
- }
-};
-
-p.onStop = function () {
- var iterator = this._anims;
- var array = iterator.array;
- for (iterator.i = 0; iterator.i < array.length; ++iterator.i) {
- var anim = array[iterator.i];
- anim.stop();
- }
-};
-
-p.onPause = function () {
- var array = this._anims.array;
- for (var i = 0; i < array.length; ++i) {
- var anim = array[i];
- anim.pause();
-
- // need to unbind animator to anim, or it maybe cannot be gc.
- anim.animator = null;
- }
-};
-
-p.onResume = function () {
- var array = this._anims.array;
- for (var i = 0; i < array.length; ++i) {
- var anim = array[i];
-
- // rebind animator to anim
- anim.animator = this;
-
- anim.resume();
- }
-};
-
-p._reloadClip = function (state) {
- initClipData(this.target, state);
-};
-
-// 这个方法应该是 SampledAnimCurve 才能用
-function createBatchedProperty (propPath, firstDotIndex, mainValue, animValue) {
- mainValue = mainValue.clone();
- var nextValue = mainValue;
- var leftIndex = firstDotIndex + 1;
- var rightIndex = propPath.indexOf('.', leftIndex);
-
- // scan property path
- while (rightIndex !== -1) {
- var nextName = propPath.slice(leftIndex, rightIndex);
- nextValue = nextValue[nextName];
- leftIndex = rightIndex + 1;
- rightIndex = propPath.indexOf('.', leftIndex);
- }
- var lastPropName = propPath.slice(leftIndex);
- nextValue[lastPropName] = animValue;
-
- return mainValue;
-}
-
-if (CC_TEST) {
- cc._Test.createBatchedProperty = createBatchedProperty;
-}
-
-function splitPropPath (propPath) {
- var array = propPath.split('.');
- array.shift();
- //array = array.filter(function (item) { return !!item; });
- return array.length > 0 ? array : null;
-}
-
-
-function initClipData (root, state) {
- var clip = state.clip;
-
- var curves = state.curves;
- curves.length = 0;
-
- state.duration = clip.duration;
- state.speed = clip.speed;
- state.wrapMode = clip.wrapMode;
- state.frameRate = clip.sample;
-
- if ((state.wrapMode & WrapModeMask.Loop) === WrapModeMask.Loop) {
- state.repeatCount = Infinity;
- }
- else {
- state.repeatCount = 1;
- }
-
- // create curves
-
- function checkMotionPath(motionPath) {
- if (!Array.isArray(motionPath)) return false;
-
- for (let i = 0, l = motionPath.length; i < l; i++) {
- var controls = motionPath[i];
-
- if (!Array.isArray(controls) || controls.length !== 6) return false;
- }
-
- return true;
- }
-
- function createPropCurve (target, propPath, keyframes) {
- var isMotionPathProp = (target instanceof cc.Node)
- && (propPath === 'position')
- && (keyframes[0] && Array.isArray(keyframes[0].value));
- var motionPaths = [];
-
- var curve = new DynamicAnimCurve();
-
- // 缓存目标对象,所以 Component 必须一开始都创建好并且不能运行时动态替换……
- curve.target = target;
-
- var propName, propValue;
- var dotIndex = propPath.indexOf('.');
- var hasSubProp = dotIndex !== -1;
- if (hasSubProp) {
- propName = propPath.slice(0, dotIndex);
- propValue = target[propName];
-
- // if (!(propValue instanceof cc.ValueType)) {
- // cc.error('Only support sub animation property which is type cc.ValueType');
- // continue;
- // }
- }
- else {
- propName = propPath;
- }
-
- curve.prop = propName;
-
- curve.subProps = splitPropPath(propPath);
-
- // for each keyframes
- for (let i = 0, l = keyframes.length; i < l; i++) {
- var keyframe = keyframes[i];
- var ratio = keyframe.frame / state.duration;
- curve.ratios.push(ratio);
-
- if (isMotionPathProp) {
- var motionPath = keyframe.motionPath;
-
- if (motionPath && !checkMotionPath(motionPath)) {
- cc.errorID(3904, target.name, propPath, i);
- motionPath = null;
- }
-
- motionPaths.push(motionPath);
- }
-
- var curveValue = keyframe.value;
- //if (hasSubProp) {
- // curveValue = createBatchedProperty(propPath, dotIndex, propValue, curveValue);
- //}
- curve.values.push(curveValue);
-
- var curveTypes = keyframe.curve;
- if (curveTypes) {
- if (typeof curveTypes === 'string') {
- curve.types.push(curveTypes);
- continue;
- }
- else if (Array.isArray(curveTypes)) {
- if (curveTypes[0] === curveTypes[1] &&
- curveTypes[2] === curveTypes[3]) {
- curve.types.push(DynamicAnimCurve.Linear);
- }
- else {
- curve.types.push(DynamicAnimCurve.Bezier(curveTypes));
- }
- continue;
- }
- }
- curve.types.push(DynamicAnimCurve.Linear);
- }
-
- if (isMotionPathProp) {
- sampleMotionPaths(motionPaths, curve, clip.duration, clip.sample);
- }
-
- // if every piece of ratios are the same, we can use the quick function to find frame index.
- var ratios = curve.ratios;
- var currRatioDif, lastRatioDif;
- var canOptimize = true;
- var EPSILON = 1e-6;
- for (let i = 1, l = ratios.length; i < l; i++) {
- currRatioDif = ratios[i] - ratios[i-1];
- if (i === 1) {
- lastRatioDif = currRatioDif;
- }
- else if (Math.abs(currRatioDif - lastRatioDif) > EPSILON) {
- canOptimize = false;
- break;
- }
- }
-
- curve._findFrameIndex = canOptimize ? quickFindIndex : binarySearch;
-
- return curve;
- }
-
- function createTargetCurves (target, curveData) {
- var propsData = curveData.props;
- var compsData = curveData.comps;
-
- if (propsData) {
- for (var propPath in propsData) {
- var data = propsData[propPath];
- var curve = createPropCurve(target, propPath, data);
-
- curves.push(curve);
- }
- }
-
- if (compsData) {
- for (var compName in compsData) {
- var comp = target.getComponent(compName);
-
- if (!comp) {
- continue;
- }
-
- var compData = compsData[compName];
- for (var propPath in compData) {
- var data = compData[propPath];
- var curve = createPropCurve(comp, propPath, data);
-
- curves.push(curve);
- }
- }
- }
- }
-
- // property curves
-
- var curveData = clip.curveData;
- var childrenCurveDatas = curveData.paths;
-
- createTargetCurves(root, curveData);
-
- for (var namePath in childrenCurveDatas) {
- var target = cc.find(namePath, root);
-
- if (!target) {
- continue;
- }
-
- var childCurveDatas = childrenCurveDatas[namePath];
- createTargetCurves(target, childCurveDatas);
- }
-
- // events curve
-
- var events = clip.events;
-
- if (!CC_EDITOR && events) {
- var curve;
-
- for (let i = 0, l = events.length; i < l; i++) {
- if (!curve) {
- curve = new EventAnimCurve();
- curve.target = root;
- curves.push(curve);
- }
-
- var eventData = events[i];
- var ratio = eventData.frame / state.duration;
-
- var eventInfo;
- var index = binarySearch(curve.ratios, ratio);
- if (index >= 0) {
- eventInfo = curve.events[index];
- }
- else {
- eventInfo = new EventInfo();
- curve.ratios.push(ratio);
- curve.events.push(eventInfo);
- }
-
- eventInfo.add(eventData.func, eventData.params);
- }
- }
-}
-
-if (CC_TEST) {
- cc._Test.initClipData = initClipData;
-}
-
-
-module.exports = AnimationAnimator;
diff --git a/cocos/animation/animation-clip.js b/cocos/animation/animation-clip.js
deleted file mode 100644
index cb003c71f7..0000000000
--- a/cocos/animation/animation-clip.js
+++ /dev/null
@@ -1,157 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-const WrapMode = require('./types').WrapMode;
-
-/**
- * !#en Class for animation data handling.
- * !#zh 动画剪辑,用于存储动画数据。
- * @class AnimationClip
- * @extends Asset
- */
-var AnimationClip = cc.Class({
- name: 'cc.AnimationClip2',
- extends: cc.Asset,
-
- properties: {
- _duration: {
- default: 0,
- type: 'Float',
- },
-
- /**
- * !#en Duration of this animation.
- * !#zh 动画的持续时间。
- * @property duration
- * @type {Number}
- */
- duration: {
- get: function () { return this._duration; },
- },
-
- /**
- * !#en FrameRate of this animation.
- * !#zh 动画的帧速率。
- * @property sample
- * @type {Number}
- */
- sample: {
- default: 60,
- },
-
- /**
- * !#en Speed of this animation.
- * !#zh 动画的播放速度。
- * @property speed
- * @type {Number}
- */
- speed: {
- default: 1
- },
-
- /**
- * !#en WrapMode of this animation.
- * !#zh 动画的循环模式。
- * @property wrapMode
- * @type {WrapMode}
- */
- wrapMode: {
- default: WrapMode.Normal
- },
-
- /**
- * !#en Curve data.
- * !#zh 曲线数据。
- * @property curveData
- * @type {Object}
- * @example {@link cocos2d/core/animation-clip/curve-data.js}
- */
- curveData: {
- default: {},
- visible: false,
- },
-
- /**
- * !#en Event data.
- * !#zh 事件数据。
- * @property events
- * @type {Object[]}
- * @example {@link cocos2d/core/animation-clip/event-data.js}
- * @typescript events: {frame: number, func: string, params: string[]}[]
- */
- events: {
- default: [],
- visible: false,
- }
- },
-
- statics: {
- /**
- * !#en Crate clip with a set of sprite frames
- * !#zh 使用一组序列帧图片来创建动画剪辑
- * @method createWithSpriteFrames
- * @param {[SpriteFrame]} spriteFrames
- * @param {Number} sample
- * @return {AnimationClip}
- * @static
- * @example
- *
- * var clip = cc.AnimationClip.createWithSpriteFrames(spriteFrames, 10);
- *
- */
- createWithSpriteFrames: function (spriteFrames, sample) {
- if (!Array.isArray(spriteFrames)) {
- cc.errorID(3905);
- return null;
- }
-
- var clip = new AnimationClip();
- clip.sample = sample || clip.sample;
-
- clip._duration = spriteFrames.length / clip.sample;
-
- var frames = [];
- var step = 1 / clip.sample;
-
- for (var i = 0, l = spriteFrames.length; i < l; i++) {
- frames[i] = { frame: (i * step), value: spriteFrames[i] };
- }
-
- clip.curveData = {
- comps: {
- // component
- 'cc.Sprite': {
- // component properties
- 'spriteFrame': frames
- }
- }
- };
-
- return clip;
- }
- }
-});
-
-cc.AnimationClip2 = module.exports = AnimationClip;
diff --git a/cocos/animation/animation-clip.ts b/cocos/animation/animation-clip.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/cocos/animation/animation-curves.js b/cocos/animation/animation-curves.js
deleted file mode 100644
index e883e59052..0000000000
--- a/cocos/animation/animation-curves.js
+++ /dev/null
@@ -1,450 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-
-var bezierByTime = require('./bezier').bezierByTime;
-
-var binarySearch = require('../core/utils/binary-search').binarySearchEpsilon;
-var WrapModeMask = require('./types').WrapModeMask;
-var WrappedInfo = require('./types').WrappedInfo;
-
-/**
- * Compute a new ratio by curve type
- * @param {Number} ratio - The origin ratio
- * @param {Array|String} type - If it's Array, then ratio will be computed with bezierByTime. If it's string, then ratio will be computed with cc.Easing function
- */
-function computeRatioByType (ratio, type) {
- if (typeof type === 'string') {
- var func = cc.Easing[type];
- if (func) {
- ratio = func(ratio);
- }
- else {
- cc.errorID(3906, type);
- }
- }
- else if (Array.isArray(type)) {
- // bezier curve
- ratio = bezierByTime(type, ratio);
- }
-
- return ratio;
-}
-
-//
-// 动画数据类,相当于 AnimationClip。
-// 虽然叫做 AnimCurve,但除了曲线,可以保存任何类型的值。
-//
-// @class AnimCurve
-//
-//
-var AnimCurve = cc.Class({
- name: 'cc.AnimCurve',
-
- //
- // @method sample
- // @param {number} time
- // @param {number} ratio - The normalized time specified as a number between 0.0 and 1.0 inclusive.
- // @param {AnimationState} state
- //
- sample: function (time, ratio, state) {},
-
- onTimeChangedManually: undefined
-});
-
-/**
- * 当每两帧之前的间隔都一样的时候可以使用此函数快速查找 index
- */
-function quickFindIndex (ratios, ratio) {
- var length = ratios.length - 1;
-
- if (length === 0) return 0;
-
- var start = ratios[0];
- if (ratio < start) return 0;
-
- var end = ratios[length];
- if (ratio > end) return length;
-
- ratio = (ratio - start) / (end - start);
-
- var eachLength = 1 / length;
- var index = ratio / eachLength;
- var floorIndex = index | 0;
- var EPSILON = 1e-6;
-
- if ((index - floorIndex) < EPSILON) {
- return floorIndex;
- }
-
- return ~(floorIndex + 1);
-}
-
-//
-//
-// @class DynamicAnimCurve
-//
-// @extends AnimCurve
-//
-var DynamicAnimCurve = cc.Class({
- name: 'cc.DynamicAnimCurve',
- extends: AnimCurve,
-
- properties: {
-
- // The object being animated.
- // @property target
- // @type {object}
- target: null,
-
- // The name of the property being animated.
- // @property prop
- // @type {string}
- prop: '',
-
- // The values of the keyframes. (y)
- // @property values
- // @type {any[]}
- values: [],
-
- // The keyframe ratio of the keyframe specified as a number between 0.0 and 1.0 inclusive. (x)
- // @property ratios
- // @type {number[]}
- ratios: [],
-
- // @property types
- // @param {object[]}
- // Each array item maybe type:
- // - [x, x, x, x]: Four control points for bezier
- // - null: linear
- types: [],
-
- // @property {string[]} subProps - The path of sub property being animated.
- subProps: null
- },
-
- _findFrameIndex: binarySearch,
-
- sample: function (time, ratio, state) {
- var values = this.values;
- var ratios = this.ratios;
- var frameCount = ratios.length;
-
- if (frameCount === 0) {
- return;
- }
-
- // evaluate value
- var value;
- var index = this._findFrameIndex(ratios, ratio);
-
- if (index < 0) {
- index = ~index;
-
- if (index <= 0) {
- value = values[0];
- }
- else if (index >= frameCount) {
- value = values[frameCount - 1];
- }
- else {
- var fromVal = values[index - 1];
-
- var isNumber = typeof fromVal === 'number';
- var canLerp = fromVal && fromVal.lerp;
-
- if (!isNumber && !canLerp) {
- value = fromVal;
- }
- else {
- var fromRatio = ratios[index - 1];
- var toRatio = ratios[index];
- var type = this.types[index - 1];
- var ratioBetweenFrames = (ratio - fromRatio) / (toRatio - fromRatio);
-
- if (type) {
- ratioBetweenFrames = computeRatioByType(ratioBetweenFrames, type);
- }
-
- // calculate value
- var toVal = values[index];
-
- // lerp
- if (isNumber) {
- value = fromVal + (toVal - fromVal) * ratioBetweenFrames;
- }
- else if (canLerp) {
- value = fromVal.lerp(toVal, ratioBetweenFrames);
- }
- }
- }
- }
- else {
- value = values[index];
- }
-
- var subProps = this.subProps;
- if (subProps) {
- // create batched value dynamically
- var mainProp = this.target[this.prop];
- var subProp = mainProp;
-
- for (var i = 0; i < subProps.length - 1; i++) {
- var subPropName = subProps[i];
- if (subProp) {
- subProp = subProp[subPropName];
- }
- else {
- return;
- }
- }
-
- var propName = subProps[subProps.length - 1];
-
- if (subProp) {
- subProp[propName] = value;
- }
- else {
- return;
- }
-
- value = mainProp;
- }
-
- // apply value
- this.target[this.prop] = value;
- }
-});
-
-DynamicAnimCurve.Linear = null;
-DynamicAnimCurve.Bezier = function (controlPoints) {
- return controlPoints;
-};
-
-
-
-/**
- * Event information,
- * @class EventInfo
- *
- */
-var EventInfo = function () {
- this.events = [];
-};
-
-/**
- * @param {Function} [func] event function
- * @param {Object[]} [params] event params
- */
-EventInfo.prototype.add = function (func, params) {
- this.events.push({
- func: func || '',
- params: params || []
- });
-};
-
-
-/**
- *
- * @class EventAnimCurve
- *
- * @extends AnimCurve
- */
-var EventAnimCurve = cc.Class({
- name: 'cc.EventAnimCurve',
- extends: AnimCurve,
-
- properties: {
- /**
- * The object being animated.
- * @property target
- * @type {object}
- */
- target: null,
-
- /** The keyframe ratio of the keyframe specified as a number between 0.0 and 1.0 inclusive. (x)
- * @property ratios
- * @type {number[]}
- */
- ratios: [],
-
- /**
- * @property events
- * @type {EventInfo[]}
- */
- events: [],
-
- _wrappedInfo: {
- default: function () {
- return new WrappedInfo();
- }
- },
-
- _lastWrappedInfo: null,
-
- _ignoreIndex: NaN
- },
-
- _wrapIterations: function (iterations) {
- if (iterations - (iterations | 0) === 0) iterations -= 1;
- return iterations | 0;
- },
-
- sample: function (time, ratio, state) {
- var length = this.ratios.length;
-
- var currentWrappedInfo = state.getWrappedInfo(state.time, this._wrappedInfo);
- var direction = currentWrappedInfo.direction;
- var currentIndex = binarySearch(this.ratios, currentWrappedInfo.ratio);
- if (currentIndex < 0) {
- currentIndex = ~currentIndex - 1;
-
- // if direction is inverse, then increase index
- if (direction < 0) currentIndex += 1;
- }
-
- if (this._ignoreIndex !== currentIndex) {
- this._ignoreIndex = NaN;
- }
-
- currentWrappedInfo.frameIndex = currentIndex;
-
- if (!this._lastWrappedInfo) {
- this._fireEvent(currentIndex);
- this._lastWrappedInfo = new WrappedInfo(currentWrappedInfo);
- return;
- }
-
- var wrapMode = state.wrapMode;
- var currentIterations = this._wrapIterations(currentWrappedInfo.iterations);
-
- var lastWrappedInfo = this._lastWrappedInfo;
- var lastIterations = this._wrapIterations(lastWrappedInfo.iterations);
- var lastIndex = lastWrappedInfo.frameIndex;
- var lastDirection = lastWrappedInfo.direction;
-
- var interationsChanged = lastIterations !== -1 && currentIterations !== lastIterations;
-
- if (lastIndex === currentIndex && interationsChanged && length === 1) {
- this._fireEvent(0);
- }
- else if (lastIndex !== currentIndex || interationsChanged) {
- direction = lastDirection;
-
- do {
- if (lastIndex !== currentIndex) {
- if (direction === -1 && lastIndex === 0 && currentIndex > 0) {
- if ((wrapMode & WrapModeMask.PingPong) === WrapModeMask.PingPong) {
- direction *= -1;
- }
- else {
- lastIndex = length;
- }
-
- lastIterations ++;
- }
- else if (direction === 1 && lastIndex === length - 1 && currentIndex < length - 1) {
- if ((wrapMode & WrapModeMask.PingPong) === WrapModeMask.PingPong) {
- direction *= -1;
- }
- else {
- lastIndex = -1;
- }
-
- lastIterations ++;
- }
-
- if (lastIndex === currentIndex) break;
- if (lastIterations > currentIterations) break;
- }
-
- lastIndex += direction;
-
- cc.director.getAnimationManager().pushDelayEvent(this, '_fireEvent', [lastIndex]);
- } while (lastIndex !== currentIndex && lastIndex > -1 && lastIndex < length);
- }
-
- this._lastWrappedInfo.set(currentWrappedInfo);
- },
-
- _fireEvent: function (index) {
- if (index < 0 || index >= this.events.length || this._ignoreIndex === index) return;
-
- var eventInfo = this.events[index];
- var events = eventInfo.events;
-
- if ( !this.target.isValid ) {
- return;
- }
-
- var components = this.target._components;
-
- for (var i = 0; i < events.length; i++) {
- var event = events[i];
- var funcName = event.func;
-
- for (var j = 0; j < components.length; j++) {
- var component = components[j];
- var func = component[funcName];
-
- if (func) func.apply(component, event.params);
- }
- }
- },
-
- onTimeChangedManually: function (time, state) {
- this._lastWrappedInfo = null;
- this._ignoreIndex = NaN;
-
- var info = state.getWrappedInfo(time, this._wrappedInfo);
- var direction = info.direction;
- var frameIndex = binarySearch(this.ratios, info.ratio);
-
- // only ignore when time not on a frame index
- if (frameIndex < 0) {
- frameIndex = ~frameIndex - 1;
-
- // if direction is inverse, then increase index
- if (direction < 0) frameIndex += 1;
-
- this._ignoreIndex = frameIndex;
- }
- }
-});
-
-
-if (CC_TEST) {
- cc._Test.DynamicAnimCurve = DynamicAnimCurve;
- cc._Test.EventAnimCurve = EventAnimCurve;
-}
-
-module.exports = {
- AnimCurve: AnimCurve,
- DynamicAnimCurve: DynamicAnimCurve,
- EventAnimCurve: EventAnimCurve,
- EventInfo: EventInfo,
- computeRatioByType: computeRatioByType,
- quickFindIndex: quickFindIndex
-};
diff --git a/cocos/animation/animation-manager.js b/cocos/animation/animation-manager.js
deleted file mode 100644
index 1edd4ec9b8..0000000000
--- a/cocos/animation/animation-manager.js
+++ /dev/null
@@ -1,92 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var js = cc.js;
-
-var AnimationManager = cc.Class({
- ctor: function () {
- this._anims = new js.array.MutableForwardIterator([]);
- this._delayEvents = [];
-
- cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
- },
-
- // for manager
-
- update: function (dt) {
- var iterator = this._anims;
- var array = iterator.array;
- for (iterator.i = 0; iterator.i < array.length; ++iterator.i) {
- var anim = array[iterator.i];
- if (anim._isPlaying && !anim._isPaused) {
- anim.update(dt);
- }
- }
-
- var events = this._delayEvents;
- for (let i = 0, l = events.length; i < l; i++) {
- var event = events[i];
- event.target[event.func].apply(event.target, event.args);
- }
- events.length = 0;
- },
-
- destruct: function () {},
-
-
- /**
- * @param {AnimationState} anim
- */
- addAnimation: function (anim) {
- var index = this._anims.array.indexOf(anim);
- if (index === -1) {
- this._anims.push(anim);
- }
- },
-
- /**
- * @param {AnimationState} anim
- */
- removeAnimation: function (anim) {
- var index = this._anims.array.indexOf(anim);
- if (index >= 0) {
- this._anims.fastRemoveAt(index);
- }
- else {
- cc.errorID(3907);
- }
- },
-
- pushDelayEvent: function (target, func, args) {
- this._delayEvents.push({
- target: target,
- func: func,
- args: args
- });
- }
-});
-
-
-cc.AnimationManager = module.exports = AnimationManager;
diff --git a/cocos/animation/animation-state.js b/cocos/animation/animation-state.js
deleted file mode 100644
index 2c2c9135a1..0000000000
--- a/cocos/animation/animation-state.js
+++ /dev/null
@@ -1,522 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-
-var js = cc.js;
-var Playable = require('./playable');
-
-var Types = require('./types');
-var WrappedInfo = Types.WrappedInfo;
-var WrapMode = Types.WrapMode;
-var WrapModeMask = Types.WrapModeMask;
-
-/**
- * !#en
- * The AnimationState gives full control over animation playback process.
- * In most cases the Animation Component is sufficient and easier to use. Use the AnimationState if you need full control.
- * !#zh
- * AnimationState 完全控制动画播放过程。
- * 大多数情况下 动画组件 是足够和易于使用的。如果您需要更多的动画控制接口,请使用 AnimationState。
- * @class AnimationState
- * @extends Playable
- *
- */
-
-/**
- * @method constructor
- * @param {AnimationClip} clip
- * @param {String} [name]
- */
-function AnimationState (clip, name) {
- Playable.call(this);
-
- // Mark whether the current frame is played.
- // When set new time to animation state, we should ensure the frame at the specified time being played at next update.
- this._currentFramePlayed = false;
-
- this._delay = 0;
- this._delayTime = 0;
-
- this._wrappedInfo = new WrappedInfo();
- this._lastWrappedInfo = null;
-
- this._process = process;
-
- this._clip = clip;
- this._name = name || (clip && clip.name);
-
- /**
- * @property animator
- * @type {AnimationAnimator}
- */
- this.animator = null;
-
- /**
- * !#en The curves list.
- * !#zh 曲线列表。
- * @property curves
- * @type {Object[]}
- */
- this.curves = [];
-
- // http://www.w3.org/TR/web-animations/#idl-def-AnimationTiming
-
- /**
- * !#en The start delay which represents the number of seconds from an animation's start time to the start of
- * the active interval.
- * !#zh 延迟多少秒播放。
- *
- * @property delay
- * @type {Number}
- * @default 0
- */
- this.delay = 0;
-
- /**
- * !#en The animation's iteration count property.
- *
- * A real number greater than or equal to zero (including positive infinity) representing the number of times
- * to repeat the animation node.
- *
- * Values less than zero and NaN values are treated as the value 1.0 for the purpose of timing model
- * calculations.
- *
- * !#zh 迭代次数,指动画播放多少次后结束, normalize time。 如 2.5(2次半)
- *
- * @property repeatCount
- * @type {Number}
- * @default 1
- */
- this.repeatCount = 1;
-
- /**
- * !#en The iteration duration of this animation in seconds. (length)
- * !#zh 单次动画的持续时间,秒。
- *
- * @property duration
- * @type {Number}
- * @readOnly
- */
- this.duration = 1;
-
- /**
- * !#en The animation's playback speed. 1 is normal playback speed.
- * !#zh 播放速率。
- * @property speed
- * @type {Number}
- * @default: 1.0
- */
- this.speed = 1;
-
- /**
- * !#en
- * Wrapping mode of the playing animation.
- * Notice : dynamic change wrapMode will reset time and repeatCount property
- * !#zh
- * 动画循环方式。
- * 需要注意的是,动态修改 wrapMode 时,会重置 time 以及 repeatCount
- *
- * @property wrapMode
- * @type {WrapMode}
- * @default: WrapMode.Normal
- */
- this.wrapMode = WrapMode.Normal;
-
- /**
- * !#en The current time of this animation in seconds.
- * !#zh 动画当前的时间,秒。
- * @property time
- * @type {Number}
- * @default 0
- */
- this.time = 0;
-
- // Animation as event target
- this._target = null;
- this._lastframeEventOn = false;
- this.emit = function () {
- var args = new Array(arguments.length);
- for (var i = 0, l = args.length; i < l; i++) {
- args[i] = arguments[i];
- }
- cc.director.getAnimationManager().pushDelayEvent(this, '_emit', args);
- };
-}
-js.extend(AnimationState, Playable);
-
-var proto = AnimationState.prototype;
-
-proto._emit = function (type, state) {
- if (this._target && this._target.isValid) {
- this._target.emit(type, type, state);
- }
-};
-
-proto.on = function (type, callback, target) {
- if (this._target && this._target.isValid) {
- if (type === 'lastframe') {
- this._lastframeEventOn = true;
- }
- return this._target.on(type, callback, target);
- }
- else {
- return null;
- }
-};
-
-proto.once = function (type, callback, target) {
- if (this._target && this._target.isValid) {
- if (type === 'lastframe') {
- this._lastframeEventOn = true;
- }
- let self = this;
- return this._target.once(type, function (event) {
- callback.call(target, event);
- self._lastframeEventOn = false;
- });
- }
- else {
- return null;
- }
-};
-
-proto.off = function (type, callback, target) {
- if (this._target && this._target.isValid) {
- if (type === 'lastframe') {
- if (!this._target.hasEventListener(type)) {
- this._lastframeEventOn = false;
- }
- }
- this._target.off(type, callback, target);
- }
-};
-
-proto._setListeners = function (target) {
- this._target = target;
-};
-
-proto.onPlay = function () {
- // replay
- this.setTime(0);
- this._delayTime = this._delay;
-
- cc.director.getAnimationManager().addAnimation(this);
-
- if (this.animator) {
- this.animator.addAnimation(this);
- }
-
- this.emit('play', this);
-};
-
-proto.onStop = function () {
- if (!this.isPaused) {
- cc.director.getAnimationManager().removeAnimation(this);
- }
-
- if (this.animator) {
- this.animator.removeAnimation(this);
- }
-
- this.emit('stop', this);
-};
-
-proto.onResume = function () {
- cc.director.getAnimationManager().addAnimation(this);
- this.emit('resume', this);
-};
-
-proto.onPause = function () {
- cc.director.getAnimationManager().removeAnimation(this);
- this.emit('pause', this);
-};
-
-proto.setTime = function (time) {
- this._currentFramePlayed = false;
- this.time = time || 0;
-
- var curves = this.curves;
- for (var i = 0, l = curves.length; i < l; i++) {
- var curve = curves[i];
- if (curve.onTimeChangedManually) {
- curve.onTimeChangedManually(time, this);
- }
- }
-};
-
-function process () {
- // sample
- var info = this.sample();
-
- if (this._lastframeEventOn) {
- var lastInfo;
- if (!this._lastWrappedInfo) {
- lastInfo = this._lastWrappedInfo = new WrappedInfo(info);
- } else {
- lastInfo = this._lastWrappedInfo;
- }
-
- if (this.repeatCount > 1 && ((info.iterations | 0) > (lastInfo.iterations | 0))) {
- this.emit('lastframe', this);
- }
-
- lastInfo.set(info);
- }
-
- if (info.stopped) {
- this.stop();
- this.emit('finished', this);
- }
-}
-
-function simpleProcess () {
- var time = this.time;
- var duration = this.duration;
-
- if (time > duration) {
- time = time % duration;
- if (time === 0) time = duration;
- }
- else if (time < 0) {
- time = time % duration;
- if (time !== 0) time += duration;
- }
-
- var ratio = time / duration;
-
- var curves = this.curves;
- for (var i = 0, len = curves.length; i < len; i++) {
- var curve = curves[i];
- curve.sample(time, ratio, this);
- }
-
- if (this._lastframeEventOn) {
- if (this._lastIterations === undefined) {
- this._lastIterations = ratio;
- }
-
- if ((this.time > 0 && this._lastIterations > ratio) || (this.time < 0 && this._lastIterations < ratio)) {
- this.emit('lastframe', this);
- }
-
- this._lastIterations = ratio;
- }
-}
-
-proto.update = function (delta) {
- // calculate delay time
-
- if (this._delayTime > 0) {
- this._delayTime -= delta;
- if (this._delayTime > 0) {
- // still waiting
- return;
- }
- }
-
- // make first frame perfect
-
- //var playPerfectFirstFrame = (this.time === 0);
- if (this._currentFramePlayed) {
- this.time += (delta * this.speed);
- }
- else {
- this._currentFramePlayed = true;
- }
-
- this._process();
-};
-
-proto._needRevers = function (currentIterations) {
- var wrapMode = this.wrapMode;
- var needRevers = false;
-
- if ((wrapMode & WrapModeMask.PingPong) === WrapModeMask.PingPong) {
- var isEnd = currentIterations - (currentIterations | 0) === 0;
- if (isEnd && (currentIterations > 0)) {
- currentIterations -= 1;
- }
-
- var isOddIteration = currentIterations & 1;
- if (isOddIteration) {
- needRevers = !needRevers;
- }
- }
- if ((wrapMode & WrapModeMask.Reverse) === WrapModeMask.Reverse) {
- needRevers = !needRevers;
- }
- return needRevers;
-};
-
-proto.getWrappedInfo = function (time, info) {
- info = info || new WrappedInfo();
-
- var stopped = false;
- var duration = this.duration;
- var repeatCount = this.repeatCount;
-
- var currentIterations = time > 0 ? (time / duration) : -(time / duration);
- if (currentIterations >= repeatCount) {
- currentIterations = repeatCount;
-
- stopped = true;
- var tempRatio = repeatCount - (repeatCount | 0);
- if (tempRatio === 0) {
- tempRatio = 1; // 如果播放过,动画不复位
- }
- time = tempRatio * duration * (time > 0 ? 1 : -1);
- }
-
- if (time > duration) {
- var tempTime = time % duration;
- time = tempTime === 0 ? duration : tempTime;
- }
- else if (time < 0) {
- time = time % duration;
- if (time !== 0 ) time += duration;
- }
-
- var needRevers = false;
- var shouldWrap = this._wrapMode & WrapModeMask.ShouldWrap;
- if (shouldWrap) {
- needRevers = this._needRevers(currentIterations);
- }
-
- var direction = needRevers ? -1 : 1;
- if (this.speed < 0) {
- direction *= -1;
- }
-
- // calculate wrapped time
- if (shouldWrap && needRevers) {
- time = duration - time;
- }
-
- info.ratio = time / duration;
- info.time = time;
- info.direction = direction;
- info.stopped = stopped;
- info.iterations = currentIterations;
-
- return info;
-};
-
-proto.sample = function () {
- var info = this.getWrappedInfo(this.time, this._wrappedInfo);
- var curves = this.curves;
- for (var i = 0, len = curves.length; i < len; i++) {
- var curve = curves[i];
- curve.sample(info.time, info.ratio, this);
- }
-
- return info;
-};
-
-
-/**
- * !#en The clip that is being played by this animation state.
- * !#zh 此动画状态正在播放的剪辑。
- * @property clip
- * @type {AnimationClip}
- * @final
- */
-js.get(proto, 'clip', function () {
- return this._clip;
-});
-
-/**
- * !#en The name of the playing animation.
- * !#zh 动画的名字
- * @property name
- * @type {String}
- * @readOnly
- */
-js.get(proto, 'name', function () {
- return this._name;
-});
-
-js.obsolete(proto, 'AnimationState.length', 'duration');
-
-js.getset(proto, 'curveLoaded',
- function () {
- return this.curves.length > 0;
- },
- function () {
- this.curves.length = 0;
- }
-);
-
-
-js.getset(proto, 'wrapMode',
- function () {
- return this._wrapMode;
- },
- function (value) {
- this._wrapMode = value;
-
- if (CC_EDITOR) return;
-
- // dynamic change wrapMode will need reset time to 0
- this.time = 0;
-
- if (value & WrapModeMask.Loop) {
- this.repeatCount = Infinity;
- }
- else {
- this.repeatCount = 1;
- }
-
- }
-);
-
-js.getset(proto, 'repeatCount',
- function () {
- return this._repeatCount;
- },
- function (value) {
- this._repeatCount = value;
-
- var shouldWrap = this._wrapMode & WrapModeMask.ShouldWrap;
- var reverse = (this.wrapMode & WrapModeMask.Reverse) === WrapModeMask.Reverse;
- if (value === Infinity && !shouldWrap && !reverse) {
- this._process = simpleProcess;
- }
- else {
- this._process = process;
- }
- }
-);
-
-js.getset(proto, 'delay',
- function () {
- return this._delay;
- },
- function (value) {
- this._delayTime = this._delay = value;
- }
-);
-
-
-cc.AnimationState = module.exports = AnimationState;
diff --git a/cocos/animation/bezier.js b/cocos/animation/bezier.js
deleted file mode 100644
index f5dea5176a..0000000000
--- a/cocos/animation/bezier.js
+++ /dev/null
@@ -1,221 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-//var bezier = (function () {
-// function B1 (t) { return (t * t * t); }
-// function B2 (t) { return (3 * t * t * (1 - t)); }
-// function B3 (t) { return (3 * t * (1 - t) * (1 - t)); }
-// function B4 (t) { return ((1 - t) * (1 - t) * (1 - t)); }
-// function bezier (C1, C2, C3, C4, t) {
-// return C1 * B1(t) + C2 * B2(t) + C3 * B3(t) + C4 * B4(t);
-// }
-//
-// //function bezier (C1, C2, C3, C4, t, out) {
-// // out.x = C1.x * B1(t) + C2.x * B2(t) + C3.x * B3(t) + C4.x * B4(t);
-// // out.y = C1.y * B1(t) + C2.y * B2(t) + C3.y * B3(t) + C4.y * B4(t);
-// //}
-//
-// return bezier;
-//})();
-function bezier (C1, C2, C3, C4, t) {
- var t1 = 1 - t;
- return C1 * t1 * t1 * t1 +
- C2 * 3 * t1 * t1 * t +
- C3 * 3 * t1 * t * t +
- C4 * t * t * t;
-}
-//function bezier (c0, c1, c2, c3, t) {
-// var cy = 3.0 * (c1);
-// var by = 3.0 * (c3 - c1) - cy;
-// var ay = 1 - cy - by;
-// return (ay * t * t * t) + (by * t * t) + (cy * t);
-//}
-
-//var sin = Math.sin;
-var cos = Math.cos,
- acos = Math.acos,
- max = Math.max,
- //atan2 = Math.atan2,
- pi = Math.PI,
- tau = 2 * pi,
- sqrt = Math.sqrt;
-
-function crt (v) {
- if (v < 0) {
- return -Math.pow(-v, 1 / 3);
- }
- else {
- return Math.pow(v, 1 / 3);
- }
-}
-
-//function align (curve, line) {
-// var tx = line.p1.x,
-// ty = line.p1.y,
-// a = -atan2(line.p2.y-ty, line.p2.x-tx);
-// curve = [{x:0, y:1}, {x: curve[0], y: 1-curve[1]}, {x: curve[2], y: 1-curve[3]}, {x:1, y:0}];
-// return curve.map(function(v) {
-// return {
-// x: (v.x-tx)*cos(a) - (v.y-ty)*sin(a),
-// y: (v.x-tx)*sin(a) + (v.y-ty)*cos(a)
-// };
-// });
-//}
-
-// Modified from http://jsbin.com/yibipofeqi/1/edit, optimized for animations.
-// The origin Cardano's algorithm is based on http://www.trans4mind.com/personal_development/mathematics/polynomials/cubicAlgebra.htm
-function cardano (curve, x) {
- // align curve with the intersecting line:
- //var line = {p1: {x: x, y: 0}, p2: {x: x, y: 1}};
- //var aligned = align(curve, line);
- //// and rewrite from [a(1-t)^3 + 3bt(1-t)^2 + 3c(1-t)t^2 + dt^3] form
- // pa = aligned[0].y,
- // pb = aligned[1].y,
- // pc = aligned[2].y,
- // pd = aligned[3].y;
- ////// curve = [{x:0, y:1}, {x: curve[0], y: 1-curve[1]}, {x: curve[2], y: 1-curve[3]}, {x:1, y:0}];
- var pa = x - 0;
- var pb = x - curve[0];
- var pc = x - curve[2];
- var pd = x - 1;
-
- // to [t^3 + at^2 + bt + c] form:
- var pa3 = pa * 3;
- var pb3 = pb * 3;
- var pc3 = pc * 3;
- var d = (-pa + pb3 - pc3 + pd),
- rd = 1 / d,
- r3 = 1 / 3,
- a = (pa3 - 6 * pb + pc3) * rd,
- a3 = a * r3,
- b = (-pa3 + pb3) * rd,
- c = pa * rd,
- // then, determine p and q:
- p = (3 * b - a * a) * r3,
- p3 = p * r3,
- q = (2 * a * a * a - 9 * a * b + 27 * c) / 27,
- q2 = q / 2,
- // and determine the discriminant:
- discriminant = q2 * q2 + p3 * p3 * p3,
- // and some reserved variables
- u1, v1, x1, x2, x3;
-
- // If the discriminant is negative, use polar coordinates
- // to get around square roots of negative numbers
- if (discriminant < 0) {
- var mp3 = -p * r3,
- mp33 = mp3 * mp3 * mp3,
- r = sqrt(mp33),
- // compute cosphi corrected for IEEE float rounding:
- t = -q / (2 * r),
- cosphi = t < -1 ? -1 : t > 1 ? 1 : t,
- phi = acos(cosphi),
- crtr = crt(r),
- t1 = 2 * crtr;
- x1 = t1 * cos(phi * r3) - a3;
- x2 = t1 * cos((phi + tau) * r3) - a3;
- x3 = t1 * cos((phi + 2 * tau) * r3) - a3;
-
- // choose best percentage
- if (0 <= x1 && x1 <= 1) {
- if (0 <= x2 && x2 <= 1) {
- if (0 <= x3 && x3 <= 1) {
- return max(x1, x2, x3);
- }
- else {
- return max(x1, x2);
- }
- }
- else if (0 <= x3 && x3 <= 1) {
- return max(x1, x3);
- }
- else {
- return x1;
- }
- }
- else {
- if (0 <= x2 && x2 <= 1) {
- if (0 <= x3 && x3 <= 1) {
- return max(x2, x3);
- }
- else {
- return x2;
- }
- }
- else {
- return x3;
- }
- }
- }
- else if (discriminant === 0) {
- u1 = q2 < 0 ? crt(-q2) : -crt(q2);
- x1 = 2 * u1 - a3;
- x2 = -u1 - a3;
-
- // choose best percentage
- if (0 <= x1 && x1 <= 1) {
- if (0 <= x2 && x2 <= 1) {
- return max(x1, x2);
- }
- else {
- return x1;
- }
- }
- else {
- return x2;
- }
- }
- // one real root, and two imaginary roots
- else {
- var sd = sqrt(discriminant);
- u1 = crt(-q2 + sd);
- v1 = crt(q2 + sd);
- x1 = u1 - v1 - a3;
- return x1;
- }
-}
-
-function bezierByTime (controlPoints, x) {
- var percent = cardano(controlPoints, x); // t
- var p0y = 0; // a
- var p1y = controlPoints[1]; // b
- var p2y = controlPoints[3]; // c
- var p3y = 1; // d
- var t1 = 1 - percent;
- return p0y * t1 * t1 * t1 +
- p1y * 3 * percent * t1 * t1 +
- p2y * 3 * percent * percent * t1 +
- p3y * percent * percent * percent;
-}
-
-if (CC_TEST) {
- cc._Test.bezier = bezier;
- cc._Test.bezierByTime = bezierByTime;
-}
-
-module.exports = {
- bezier: bezier,
- bezierByTime: bezierByTime
-};
diff --git a/cocos/animation/easing.js b/cocos/animation/easing.js
deleted file mode 100644
index f17aadfde4..0000000000
--- a/cocos/animation/easing.js
+++ /dev/null
@@ -1,283 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var Easing = {
- constant: function () { return 0; },
- linear: function (k) { return k; },
-
- // quad
- // Easing equation function for a quadratic (t^2)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- quadIn: function (k) { return k * k; },
- quadOut: function (k) { return k * ( 2 - k ); },
- quadInOut: function (k) {
- if (( k *= 2 ) < 1) {
- return 0.5 * k * k;
- }
- return -0.5 * ( --k * ( k - 2 ) - 1 );
- },
-
- // cubic
- // Easing equation function for a cubic (t^3)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- cubicIn: function (k) { return k * k * k; },
- cubicOut: function (k) { return --k * k * k + 1; },
- cubicInOut: function (k) {
- if (( k *= 2 ) < 1) {
- return 0.5 * k * k * k;
- }
- return 0.5 * ( ( k -= 2 ) * k * k + 2 );
- },
-
- // quart
- // Easing equation function for a quartic (t^4)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- quartIn: function (k) { return k * k * k * k; },
- quartOut: function (k) { return 1 - ( --k * k * k * k ); },
- quartInOut: function (k) {
- if (( k *= 2 ) < 1) {
- return 0.5 * k * k * k * k;
- }
- return -0.5 * ( ( k -= 2 ) * k * k * k - 2 );
- },
-
- // quint
- // Easing equation function for a quintic (t^5)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- quintIn: function (k) { return k * k * k * k * k; },
- quintOut: function (k) { return --k * k * k * k * k + 1; },
- quintInOut: function (k) {
- if (( k *= 2 ) < 1) {
- return 0.5 * k * k * k * k * k;
- }
- return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 );
- },
-
- // sine
- // Easing equation function for a sinusoidal (sin(t))
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- sineIn: function (k) { return 1 - Math.cos(k * Math.PI / 2); },
- sineOut: function (k) { return Math.sin(k * Math.PI / 2); },
- sineInOut: function (k) { return 0.5 * ( 1 - Math.cos(Math.PI * k) ); },
-
- // expo
- // Easing equation function for an exponential (2^t)
- // param t: Current time (in frames or seconds).
- // return: The correct value.
-
- expoIn: function (k) { return k === 0 ? 0 : Math.pow(1024, k - 1); },
- expoOut: function (k) { return k === 1 ? 1 : 1 - Math.pow(2, -10 * k); },
- expoInOut: function (k) {
- if (k === 0) {
- return 0;
- }
- if (k === 1) {
- return 1;
- }
- if (( k *= 2 ) < 1) {
- return 0.5 * Math.pow(1024, k - 1);
- }
- return 0.5 * ( -Math.pow(2, -10 * ( k - 1 )) + 2 );
- },
-
- // circ
- // Easing equation function for a circular (sqrt(1-t^2))
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- circIn: function (k) { return 1 - Math.sqrt(1 - k * k); },
- circOut: function (k) { return Math.sqrt(1 - ( --k * k )); },
- circInOut: function (k) {
- if (( k *= 2 ) < 1) {
- return -0.5 * ( Math.sqrt(1 - k * k) - 1);
- }
- return 0.5 * ( Math.sqrt(1 - ( k -= 2) * k) + 1);
- },
-
- // elastic
- // Easing equation function for an elastic (exponentially decaying sine wave)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
- // recommand value: elastic (t)
-
- elasticIn: function (k) {
- var s, a = 0.1, p = 0.4;
- if (k === 0) {
- return 0;
- }
- if (k === 1) {
- return 1;
- }
- if (!a || a < 1) {
- a = 1;
- s = p / 4;
- }
- else {
- s = p * Math.asin(1 / a) / ( 2 * Math.PI );
- }
- return -( a * Math.pow(2, 10 * ( k -= 1 )) * Math.sin(( k - s ) * ( 2 * Math.PI ) / p) );
- },
- elasticOut: function (k) {
- var s, a = 0.1, p = 0.4;
- if (k === 0) {
- return 0;
- }
- if (k === 1) {
- return 1;
- }
- if (!a || a < 1) {
- a = 1;
- s = p / 4;
- }
- else {
- s = p * Math.asin(1 / a) / ( 2 * Math.PI );
- }
- return ( a * Math.pow(2, -10 * k) * Math.sin(( k - s ) * ( 2 * Math.PI ) / p) + 1 );
- },
- elasticInOut: function (k) {
- var s, a = 0.1, p = 0.4;
- if (k === 0) {
- return 0;
- }
- if (k === 1) {
- return 1;
- }
- if (!a || a < 1) {
- a = 1;
- s = p / 4;
- }
- else {
- s = p * Math.asin(1 / a) / ( 2 * Math.PI );
- }
- if (( k *= 2 ) < 1) {
- return -0.5 *
- ( a * Math.pow(2, 10 * ( k -= 1 )) * Math.sin(( k - s ) * ( 2 * Math.PI ) / p) );
- }
- return a * Math.pow(2, -10 * ( k -= 1 )) * Math.sin(( k - s ) * ( 2 * Math.PI ) / p) * 0.5 + 1;
- },
-
- // back
- // Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- backIn: function (k) {
- var s = 1.70158;
- return k * k * ( ( s + 1 ) * k - s );
- },
- backOut: function (k) {
- var s = 1.70158;
- return --k * k * ( ( s + 1 ) * k + s ) + 1;
- },
- backInOut: function (k) {
- var s = 1.70158 * 1.525;
- if (( k *= 2 ) < 1) {
- return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
- }
- return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
- },
-
- // bounce
- // Easing equation function for a bounce (exponentially decaying parabolic bounce)
- // @param t: Current time (in frames or seconds).
- // @return: The correct value.
-
- bounceOut: function (k) {
- if (k < ( 1 / 2.75 )) {
- return 7.5625 * k * k;
- }
- else if (k < ( 2 / 2.75 )) {
- return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
- }
- else if (k < ( 2.5 / 2.75 )) {
- return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
- }
- else {
- return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
- }
- },
-
- // smooth
- // t<=0: 0 | 0=1: 1
- smooth: function (t) {
- if (t <= 0) {
- return 0;
- }
- if (t >= 1) {
- return 1;
- }
- return t * t * (3 - 2 * t);
- },
-
- // fade
- // t<=0: 0 | 0=1: 1
- fade: function (t) {
- if (t <= 0) {
- return 0;
- }
- if (t >= 1) {
- return 1;
- }
- return t * t * t * (t * (t * 6 - 15) + 10);
- },
-};
-
-function _makeOutIn (fnIn, fnOut) {
- return function (k) {
- if (k < 0.5) {
- return fnOut(k * 2) / 2;
- }
- return fnIn(2 * k - 1) / 2 + 0.5;
- };
-}
-Easing.quadOutIn = _makeOutIn(Easing.quadIn, Easing.quadOut);
-Easing.cubicOutIn = _makeOutIn(Easing.cubicIn, Easing.cubicOut);
-Easing.quartOutIn = _makeOutIn(Easing.quartIn, Easing.quartOut);
-Easing.quintOutIn = _makeOutIn(Easing.quintIn, Easing.quintOut);
-Easing.sineOutIn = _makeOutIn(Easing.sineIn, Easing.sineOut);
-Easing.expoOutIn = _makeOutIn(Easing.expoIn, Easing.expoOut);
-Easing.circOutIn = _makeOutIn(Easing.circIn, Easing.circOut);
-Easing.backOutIn = _makeOutIn(Easing.backIn, Easing.backOut);
-Easing.backOutIn = _makeOutIn(Easing.backIn, Easing.backOut);
-Easing.bounceIn = function (k) { return 1 - Easing.bounceOut(1 - k); };
-Easing.bounceInOut = function (k) {
- if (k < 0.5) {
- return Easing.bounceIn(k * 2) * 0.5;
- }
- return Easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
-};
-Easing.bounceOutIn = _makeOutIn(Easing.bounceIn, Easing.bounceOut);
-
-cc.Easing = module.exports = Easing;
diff --git a/cocos/animation/index.js b/cocos/animation/index.js
deleted file mode 100644
index 224528caaa..0000000000
--- a/cocos/animation/index.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-require('./bezier');
-require('./easing');
-require('./types');
-require('./motion-path-helper');
-require('./animation-curves');
-require('./animation-clip');
-require('./animation-manager');
-require('./animation-state');
-require('./animation-animator');
diff --git a/cocos/animation/motion-path-helper.js b/cocos/animation/motion-path-helper.js
deleted file mode 100644
index 13deab5f6a..0000000000
--- a/cocos/animation/motion-path-helper.js
+++ /dev/null
@@ -1,386 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var DynamicAnimCurve = require('./animation-curves').DynamicAnimCurve;
-var computeRatioByType = require('./animation-curves').computeRatioByType;
-
-var bezier = require('./bezier').bezier;
-var binarySearch = require('../core/utils/binary-search').binarySearchEpsilon;
-
-var v2 = cc.v2;
-
-function Curve (points) {
- this.points = points || [];
- this.beziers = [];
- this.ratios = [];
- this.progresses = [];
-
- this.length = 0;
-
- this.computeBeziers();
-}
-Curve.prototype.computeBeziers = function () {
- this.beziers.length = 0;
- this.ratios.length = 0;
- this.progresses.length = 0;
- this.length = 0;
-
- var bezier;
-
- for (var i = 1; i < this.points.length; i++) {
- var startPoint = this.points[i - 1];
- var endPoint = this.points[i];
- bezier = new Bezier();
- bezier.start = startPoint.pos;
- bezier.startCtrlPoint = startPoint.out;
- bezier.end = endPoint.pos;
- bezier.endCtrlPoint = endPoint.in;
- this.beziers.push(bezier);
-
- this.length += bezier.getLength();
- }
-
- var current = 0;
- for (var i = 0; i < this.beziers.length; i++) {
- bezier = this.beziers[i];
- this.ratios[i] = bezier.getLength() / this.length;
- this.progresses[i] = current = current + this.ratios[i];
- }
-
- return this.beziers;
-};
-
-function Bezier () {
- this.start = v2();
- this.end = v2();
- this.startCtrlPoint = v2(); // cp0, cp1
- this.endCtrlPoint = v2(); // cp2, cp3
-}
-
-// Get point at relative position in curve according to arc length
-// - u [0 .. 1]
-Bezier.prototype.getPointAt = function ( u ) {
- var t = this.getUtoTmapping( u );
- return this.getPoint( t );
-};
-
-
-// Get point at time t
-// - t [0 .. 1]
-Bezier.prototype.getPoint = function ( t ) {
- var x = bezier(this.start.x, this.startCtrlPoint.x, this.endCtrlPoint.x, this.end.x, t);
- var y = bezier(this.start.y, this.startCtrlPoint.y, this.endCtrlPoint.y, this.end.y, t);
-
- return new v2(x, y);
-};
-
-// Get total curve arc length
-Bezier.prototype.getLength = function () {
-
- var lengths = this.getLengths();
- return lengths[ lengths.length - 1 ];
-
-};
-
-// Get list of cumulative segment lengths
-Bezier.prototype.getLengths = function ( divisions ) {
-
- if ( ! divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions): 200;
-
- if ( this.cacheArcLengths
- && ( this.cacheArcLengths.length === divisions + 1 )) {
-
- //console.log( "cached", this.cacheArcLengths );
- return this.cacheArcLengths;
-
- }
-
- var cache = [];
- var current, last = this.getPoint( 0 ), vector = v2();
- var p, sum = 0;
-
- cache.push( 0 );
-
- for ( p = 1; p <= divisions; p ++ ) {
-
- current = this.getPoint ( p / divisions );
- vector.x = last.x - current.x;
- vector.y = last.y - current.y;
- sum += vector.mag();
- cache.push( sum );
- last = current;
-
- }
-
- this.cacheArcLengths = cache;
-
- return cache; // { sums: cache, sum:sum }; Sum is in the last element.
-};
-
-Bezier.prototype.getUtoTmapping = function ( u, distance ) {
-
- var arcLengths = this.getLengths();
-
- var i = 0, il = arcLengths.length;
-
- var targetArcLength; // The targeted u distance value to get
-
- if ( distance ) {
- targetArcLength = distance;
- } else {
- targetArcLength = u * arcLengths[ il - 1 ];
- }
-
- //var time = Date.now();
-
- // binary search for the index with largest value smaller than target u distance
-
- var low = 0, high = il - 1, comparison;
-
- while ( low <= high ) {
-
- i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
-
- comparison = arcLengths[ i ] - targetArcLength;
-
- if ( comparison < 0 ) {
-
- low = i + 1;
- continue;
-
- } else if ( comparison > 0 ) {
-
- high = i - 1;
- continue;
-
- } else {
-
- high = i;
- break;
-
- // DONE
-
- }
-
- }
-
- i = high;
-
- //console.log('b' , i, low, high, Date.now()- time);
-
- if ( arcLengths[ i ] === targetArcLength ) {
-
- var t = i / ( il - 1 );
- return t;
-
- }
-
- // we could get finer grain at lengths, or use simple interpolatation between two points
-
- var lengthBefore = arcLengths[ i ];
- var lengthAfter = arcLengths[ i + 1 ];
-
- var segmentLength = lengthAfter - lengthBefore;
-
- // determine where we are between the 'before' and 'after' points
-
- var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
-
- // add that fractional amount to t
-
- var t = ( i + segmentFraction ) / ( il -1 );
-
- return t;
-};
-
-
-function sampleMotionPaths (motionPaths, data, duration, fps) {
-
- function createControlPoints(array) {
- if (array instanceof cc.Vec2) {
- return {
- in: array,
- pos: array,
- out: array
- };
- }
- else if (Array.isArray(array) && array.length === 6) {
- return {
- in: v2(array[2], array[3]),
- pos: v2(array[0], array[1]),
- out: v2(array[4], array[5])
- };
- }
-
- return {
- in: cc.Vec2.ZERO,
- pos: cc.Vec2.ZERO,
- out: cc.Vec2.ZERO
- };
- }
-
- var values = data.values;
-
- if (motionPaths.length === 0 || values.length === 0) {
- return;
- }
-
- values = values.map(function (value) {
- return v2(value[0], value[1]);
- });
-
- if (values.length === 1) {
- data.values = values;
- return;
- }
-
- var types = data.types;
- var ratios = data.ratios;
-
- var newValues = data.values = [];
- var newTypes = data.types = [];
- var newRatios = data.ratios = [];
-
- function addNewDatas (value, type, ratio) {
- newValues.push(value);
- newTypes.push(type);
- newRatios.push(ratio);
- }
-
- // ensure every ratio section's length is the same
- var startRatioOffset = 0;
-
- var EPSILON = 1e-6;
- var newType = DynamicAnimCurve.Linear;
-
- // do not need to compute last path
- for (var i = 0, l = motionPaths.length; i < l-1; i++) {
- var motionPath = motionPaths[i];
-
- var ratio = ratios[i];
- var nextRatio = ratios[i + 1];
- var betweenRatio = nextRatio - ratio;
-
- var value = values[i];
- var nextValue = values[i + 1];
-
- var type = types[i];
-
- var results = [];
- var progress = startRatioOffset / betweenRatio;
- var speed = 1 / (betweenRatio * duration * fps);
- var finalProgress;
-
- if (motionPath && motionPath.length > 0) {
- var points = [];
- points.push(createControlPoints(value));
-
- for (var j = 0, l2 = motionPath.length; j < l2; j++) {
- var controlPoints = createControlPoints(motionPath[j]);
- points.push(controlPoints);
- }
-
- points.push(createControlPoints(nextValue));
-
- // create Curve to compute beziers
- var curve = new Curve(points);
- curve.computeBeziers();
-
- // sample beziers
- var progresses = curve.progresses;
-
- while ( 1 - progress > EPSILON) {
- finalProgress = progress;
-
- finalProgress = computeRatioByType(finalProgress, type);
-
- var pos, bezier, normal, length;
-
- if (finalProgress < 0) {
- bezier = curve.beziers[0];
- length = (0 - finalProgress) * bezier.getLength();
- normal = bezier.start.sub(bezier.endCtrlPoint).normalize();
- pos = bezier.start.add(normal.mul(length));
- }
- else if (finalProgress > 1) {
- bezier = curve.beziers[curve.beziers.length - 1];
- length = (finalProgress - 1) * bezier.getLength();
- normal = bezier.end.sub(bezier.startCtrlPoint).normalize();
- pos = bezier.end.add(normal.mul(length));
- }
- else {
- var bezierIndex = binarySearch(progresses, finalProgress);
- if (bezierIndex < 0) bezierIndex = ~bezierIndex;
-
- finalProgress -= bezierIndex > 0 ? progresses[bezierIndex - 1] : 0;
- finalProgress = finalProgress / curve.ratios[bezierIndex];
-
- pos = curve.beziers[bezierIndex].getPointAt(finalProgress);
- }
-
- results.push(pos);
- progress += speed;
- }
-
- }
- else {
- while ( 1 - progress > EPSILON) {
- finalProgress = progress;
-
- finalProgress = computeRatioByType(finalProgress, type);
-
- results.push(value.lerp(nextValue, finalProgress));
-
- progress += speed;
- }
- }
-
- newType = type === 'constant' ? type : DynamicAnimCurve.Linear;
-
- for (var j = 0, l2 = results.length; j < l2; j++) {
- var newRatio = ratio + startRatioOffset + speed * j * betweenRatio;
- addNewDatas(results[j], newType, newRatio);
- }
-
- if (Math.abs(progress - 1) > EPSILON) // progress > 1
- startRatioOffset = (progress - 1) * betweenRatio;
- else
- startRatioOffset = 0;
- }
-
- if (ratios[ratios.length - 1] !== newRatios[newRatios.length -1]) {
- addNewDatas(values[values.length - 1], newType, ratios[ratios.length - 1]);
- }
-}
-
-if (CC_TEST) {
- cc._Test.sampleMotionPaths = sampleMotionPaths;
-}
-
-module.exports = {
- sampleMotionPaths: sampleMotionPaths,
- Curve: Curve,
- Bezier: Bezier
-};
diff --git a/cocos/animation/playable.js b/cocos/animation/playable.js
deleted file mode 100644
index 1ea8407cb9..0000000000
--- a/cocos/animation/playable.js
+++ /dev/null
@@ -1,170 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var js = cc.js;
-const debug = require('../core/platform/CCDebug');
-
-/**
- * @class Playable
- *
- */
-function Playable () {
- this._isPlaying = false;
- this._isPaused = false;
- this._stepOnce = false;
-}
-
-var prototype = Playable.prototype;
-
-/**
- * !#en Is playing or paused in play mode?
- * !#zh 当前是否正在播放。
- * @property isPlaying
- * @type {boolean}
- * @default false
- * @readOnly
- */
-js.get(prototype, 'isPlaying', function () {
- return this._isPlaying;
-}, true);
-
-/**
- * !#en Is currently paused? This can be true even if in edit mode(isPlaying == false).
- * !#zh 当前是否正在暂停
- * @property isPaused
- * @type {boolean}
- * @default false
- * @readOnly
- */
-js.get(prototype, 'isPaused', function () {
- return this._isPaused;
-}, true);
-
-// virtual
-
-var virtual = function () {};
-/**
- * @method onPlay
- * @private
- */
-prototype.onPlay = virtual;
-/**
- * @method onPause
- * @private
- */
-prototype.onPause = virtual;
-/**
- * @method onResume
- * @private
- */
-prototype.onResume = virtual;
-/**
- * @method onStop
- * @private
- */
-prototype.onStop = virtual;
-/**
- * @method onError
- * @param {string} errorCode
- * @private
- */
-prototype.onError = virtual;
-
-// public
-
-/**
- * !#en Play this animation.
- * !#zh 播放动画。
- * @method play
- */
-prototype.play = function () {
- if (this._isPlaying) {
- if (this._isPaused) {
- this._isPaused = false;
- this.onResume();
- }
- else {
- this.onError(debug.getError(3912));
- }
- }
- else {
- this._isPlaying = true;
- this.onPlay();
- }
-};
-
-/**
- * !#en Stop this animation.
- * !#zh 停止动画播放。
- * @method stop
- */
-prototype.stop = function () {
- if (this._isPlaying) {
- this._isPlaying = false;
- this.onStop();
-
- // need reset pause flag after onStop
- this._isPaused = false;
- }
-};
-
-/**
- * !#en Pause this animation.
- * !#zh 暂停动画。
- * @method pause
- */
-prototype.pause = function () {
- if (this._isPlaying && !this._isPaused) {
- this._isPaused = true;
- this.onPause();
- }
-};
-
-/**
- * !#en Resume this animation.
- * !#zh 重新播放动画。
- * @method resume
- */
-prototype.resume = function () {
- if (this._isPlaying && this._isPaused) {
- this._isPaused = false;
- this.onResume();
- }
-};
-
-/**
- * !#en Perform a single frame step.
- * !#zh 执行一帧动画。
- * @method step
- */
-prototype.step = function () {
- this.pause();
- this._stepOnce = true;
- if (!this._isPlaying) {
- this.play();
- }
-};
-
-module.exports = Playable;
diff --git a/cocos/animation/types.js b/cocos/animation/types.js
deleted file mode 100644
index a4866e312d..0000000000
--- a/cocos/animation/types.js
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var WrapModeMask = {
- Loop: 1 << 1,
- ShouldWrap: 1 << 2,
- // Reserved: 1 << 3,
- PingPong: 1 << 4 | 1 << 1 | 1 << 2, // Loop, ShouldWrap
- Reverse: 1 << 5 | 1 << 2, // ShouldWrap
-};
-
-/**
- * !#en Specifies how time is treated when it is outside of the keyframe range of an Animation.
- * !#zh 动画使用的循环模式。
- * @enum WrapMode
- * @memberof cc
- */
-var WrapMode = cc.Enum({
-
- /**
- * !#en Reads the default wrap mode set higher up.
- * !#zh 向 Animation Component 或者 AnimationClip 查找 wrapMode
- * @property {Number} Default
- */
- Default: 0,
-
- /**
- * !#en All iterations are played as specified.
- * !#zh 动画只播放一遍
- * @property {Number} Normal
- */
- Normal: 1,
-
- /**
- * !#en All iterations are played in the reverse direction from the way they are specified.
- * !#zh 从最后一帧或结束位置开始反向播放,到第一帧或开始位置停止
- * @property {Number} Reverse
- */
- Reverse: WrapModeMask.Reverse,
-
- /**
- * !#en When time reaches the end of the animation, time will continue at the beginning.
- * !#zh 循环播放
- * @property {Number} Loop
- */
- Loop: WrapModeMask.Loop,
-
- /**
- * !#en All iterations are played in the reverse direction from the way they are specified.
- * And when time reaches the start of the animation, time will continue at the ending.
- * !#zh 反向循环播放
- * @property {Number} LoopReverse
- */
- LoopReverse: WrapModeMask.Loop | WrapModeMask.Reverse,
-
- /**
- * !#en Even iterations are played as specified, odd iterations are played in the reverse direction from the way they
- * are specified.
- * !#zh 从第一帧播放到最后一帧,然后反向播放回第一帧,到第一帧后再正向播放,如此循环
- * @property {Number} PingPong
- */
- PingPong: WrapModeMask.PingPong,
-
- /**
- * !#en Even iterations are played in the reverse direction from the way they are specified, odd iterations are played
- * as specified.
- * !#zh 从最后一帧开始反向播放,其他同 PingPong
- * @property {Number} PingPongReverse
- */
- PingPongReverse: WrapModeMask.PingPong | WrapModeMask.Reverse
-});
-
-cc.WrapMode = WrapMode;
-
-// For internal
-function WrappedInfo (info) {
- if (info) {
- this.set(info);
- return;
- }
-
- this.ratio = 0;
- this.time = 0;
- this.direction = 1;
- this.stopped = true;
- this.iterations = 0;
- this.frameIndex = undefined;
-}
-
-WrappedInfo.prototype.set = function (info) {
- this.ratio = info.ratio;
- this.time = info.time;
- this.direction = info.direction;
- this.stopped = info.stopped;
- this.iterations = info.iterations;
- this.frameIndex = info.frameIndex;
-};
-
-module.exports = {
- WrapModeMask,
- WrapMode,
- WrappedInfo
-};
diff --git a/cocos/animation/types.ts b/cocos/animation/types.ts
new file mode 100644
index 0000000000..c3cde1b735
--- /dev/null
+++ b/cocos/animation/types.ts
@@ -0,0 +1,64 @@
+
+import { ccenum } from '../core/value-types/enum';
+
+enum WrapModeMask {
+ Loop = 1 << 1,
+ ShouldWrap = 1 << 2,
+ // Reserved: 1 << 3,
+ PingPong = 1 << 4 | 1 << 1 | 1 << 2, // Loop, ShouldWrap
+ Reverse = 1 << 5 | 1 << 2, // ShouldWrap
+}
+
+/**
+ * !#en Specifies how time is treated when it is outside of the keyframe range of an Animation.
+ * !#zh 动画使用的循环模式。
+ */
+export enum WrapMode {
+ /**
+ * !#en Reads the default wrap mode set higher up.
+ * !#zh 向 Animation Component 或者 AnimationClip 查找 wrapMode
+ */
+ Default = 0,
+
+ /**
+ * !#en All iterations are played as specified.
+ * !#zh 动画只播放一遍
+ */
+ Normal = 1,
+
+ /**
+ * !#en All iterations are played in the reverse direction from the way they are specified.
+ * !#zh 从最后一帧或结束位置开始反向播放,到第一帧或开始位置停止
+ */
+ Reverse = WrapModeMask.Reverse,
+
+ /**
+ * !#en When time reaches the end of the animation, time will continue at the beginning.
+ * !#zh 循环播放
+ */
+ Loop = WrapModeMask.Loop,
+
+ /**
+ * !#en All iterations are played in the reverse direction from the way they are specified.
+ * And when time reaches the start of the animation, time will continue at the ending.
+ * !#zh 反向循环播放
+ */
+ LoopReverse = WrapModeMask.Loop | WrapModeMask.Reverse,
+
+ /**
+ * !#en Even iterations are played as specified, odd iterations are played in the reverse direction from the way they
+ * are specified.
+ * !#zh 从第一帧播放到最后一帧,然后反向播放回第一帧,到第一帧后再正向播放,如此循环
+ */
+ PingPong = WrapModeMask.PingPong,
+
+ /**
+ * !#en Even iterations are played in the reverse direction from the way they are specified, odd iterations are played
+ * as specified.
+ * !#zh 从最后一帧开始反向播放,其他同 PingPong
+ */
+ PingPongReverse = WrapModeMask.PingPong | WrapModeMask.Reverse,
+}
+
+ccenum(WrapMode);
+cc.WrapMode = WrapMode;
diff --git a/cocos/pipeline/define.ts b/cocos/pipeline/define.ts
index d423056a86..b53e9ec484 100644
--- a/cocos/pipeline/define.ts
+++ b/cocos/pipeline/define.ts
@@ -149,13 +149,13 @@ localBindingsDesc.set(UBOForwardLight.BLOCK.name, {
export class UBOSkinning {
public static MAT_JOINT_OFFSET: number = 0;
- public static JOINTS_TEXTURE_SIZE_OFFSET: number = UBOSkinning.MAT_JOINT_OFFSET + 128 * 16;
+ public static JOINTS_TEXTURE_SIZE_OFFSET: number = UBOSkinning.MAT_JOINT_OFFSET + 128 * 12;
public static COUNT: number = UBOSkinning.JOINTS_TEXTURE_SIZE_OFFSET + 4;
public static SIZE: number = UBOSkinning.COUNT * 4;
public static BLOCK: GFXUniformBlock = {
binding: UniformBinding.UBO_SKINNING, name: 'CCSkinning', members: [
- { name: 'cc_matJoint', type: GFXType.MAT4, count: 128 },
+ { name: 'cc_matJoint', type: GFXType.FLOAT4, count: 128 * 3 }, // mat 4 * 3
{ name: 'cc_jointsTextureSize', type: GFXType.FLOAT4, count: 1 },
],
};
diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts
index 9572557da7..5b32c99e21 100644
--- a/cocos/renderer/models/skinning-model.ts
+++ b/cocos/renderer/models/skinning-model.ts
@@ -66,7 +66,7 @@ export class SkinningModel extends Model {
} as IJointTextureStorage;
} else {
this._jointStorage = {
- nativeData: new Float32Array(skeleton.joints.length * 16),
+ nativeData: new Float32Array(skeleton.joints.length * 12),
} as IJointUniformsStorage;
}
}
@@ -75,7 +75,7 @@ export class SkinningModel extends Model {
if (!this._jointStorage) {
return;
}
- _setJointMatrix(this._jointStorage.nativeData, iMatrix, matrix);
+ _setJointMatrix(this._jointStorage.nativeData, iMatrix, matrix, isUniformStorage(this._jointStorage));
}
public commitJointMatrices () {
@@ -115,23 +115,25 @@ export class SkinningModel extends Model {
}
}
-function _setJointMatrix (out: Float32Array, iMatrix: number, matrix: mat4) {
- out[16 * iMatrix + 0] = matrix.m00;
- out[16 * iMatrix + 1] = matrix.m01;
- out[16 * iMatrix + 2] = matrix.m02;
- out[16 * iMatrix + 3] = matrix.m03;
- out[16 * iMatrix + 4] = matrix.m04;
- out[16 * iMatrix + 5] = matrix.m05;
- out[16 * iMatrix + 6] = matrix.m06;
- out[16 * iMatrix + 7] = matrix.m07;
- out[16 * iMatrix + 8] = matrix.m08;
- out[16 * iMatrix + 9] = matrix.m09;
- out[16 * iMatrix + 10] = matrix.m10;
- out[16 * iMatrix + 11] = matrix.m11;
- out[16 * iMatrix + 12] = matrix.m12;
- out[16 * iMatrix + 13] = matrix.m13;
- out[16 * iMatrix + 14] = matrix.m14;
- out[16 * iMatrix + 15] = matrix.m15;
+function _setJointMatrix (out: Float32Array, iMatrix: number, matrix: mat4, isUniform: boolean) {
+ const base = 12 * iMatrix;
+ if (isUniform) {
+ // Discard the last row
+ out[base + 0] = matrix.m00;
+ out[base + 1] = matrix.m01;
+ out[base + 2] = matrix.m02;
+ out[base + 3] = matrix.m04;
+ out[base + 4] = matrix.m05;
+ out[base + 5] = matrix.m06;
+ out[base + 6] = matrix.m08;
+ out[base + 7] = matrix.m09;
+ out[base + 8] = matrix.m10;
+ out[base + 9] = matrix.m12;
+ out[base + 10] = matrix.m13;
+ out[base + 11] = matrix.m14;
+ } else {
+ mat4.array(out, matrix, base);
+ }
}
const jointTextureCapacityTable = ((maxCapacity: number) => {
diff --git a/cocos/scene-graph/base-node.ts b/cocos/scene-graph/base-node.ts
index cb0d72fe3d..fdfa0d77c4 100644
--- a/cocos/scene-graph/base-node.ts
+++ b/cocos/scene-graph/base-node.ts
@@ -494,6 +494,9 @@ export class BaseNode extends CCObject {
* var child = node.getChildByPath("Test Node");
*/
public getChildByPath (path: string) {
+ if (path.length === 0) {
+ return this;
+ }
const segments = path.split('/');
let lastNode: this = this;
for (const segment of segments) {