* pause and stop

* anim struct opt
This commit is contained in:
Leslie Leigh
2019-04-23 16:31:34 +08:00
committed by Weiliang Wang
parent 0aa8aa73cc
commit ac28e13c4b
9 changed files with 72 additions and 68 deletions
@@ -167,7 +167,7 @@ export class SkinningModelComponent extends ModelComponent {
// 3. because it has been in world space, just cancel this mesh's original local-world transform
const bindpose = skeleton.bindposes[index];
const jointMatrix = _m4_tmp;
mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix(_m4_tmp));
mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.worldMatrix);
mat4.multiply(jointMatrix, jointMatrix, bindpose);
skinningModel.updateJointMatrix(index, jointMatrix);
});
+32 -29
View File
@@ -7,6 +7,7 @@ import Vec3, { v3 } from '../core/value-types/vec3';
import { lerp } from '../core/vmath';
import { find, Node } from '../scene-graph';
import { CurveValue, DynamicAnimCurve, EasingMethodName, ICurveTarget, RatioSampler } from './animation-curve';
import { AnimationState } from './animation-state';
import * as blending from './blending';
import { MotionPath, sampleMotionPaths } from './motion-path-helper';
import { ILerpable, isLerpable, WrapMode } from './types';
@@ -20,7 +21,6 @@ interface IAnimationEvent {
type EasingMethod = EasingMethodName | number[];
interface IPropertyCurveDataDetail {
blending?: keyof(typeof blending) | null;
keys: number;
values: CurveValue[];
easingMethod?: EasingMethod;
@@ -39,9 +39,6 @@ interface ICurveData {
[propertyName: string]: PropertyCurveData;
};
};
paths?: {
[path: string]: ICurveData;
};
}
@ccclass('cc.AnimationClip')
@@ -80,14 +77,16 @@ export class AnimationClip extends Asset {
values[i] = spriteFrames[i];
}
clip._keys = [keys];
clip.curveData = {
comps: {
// component
'cc.Sprite': {
// component properties
spriteFrame: {
keys: 0,
values,
clip.curveDatas = {
'/': {
comps: {
// component
'cc.Sprite': {
// component properties
spriteFrame: {
keys: 0,
values,
},
},
},
},
@@ -123,7 +122,7 @@ export class AnimationClip extends Asset {
* @example {@link cocos2d/core/animation-clip/curve-data.js}
*/
@property({visible: false})
public curveData: ICurveData = {};
public curveDatas: { [path: string]: ICurveData; } = {};
/**
* !#en Event data.
@@ -209,8 +208,18 @@ export class AnimationClip extends Asset {
}
// Setup the blend function.
if (typeof propertyCurveData.blending === 'string') {
curve._blendFunction = blending[propertyCurveData.blending];
if (target instanceof Node) {
switch (propPath) {
case 'position':
curve._blendFunction = blending.additive3D;
break;
case 'scale':
curve._blendFunction = blending.additive3D;
break;
case 'rotation':
curve._blendFunction = blending.additiveQuat;
break;
}
}
return curve;
@@ -243,25 +252,19 @@ export class AnimationClip extends Asset {
}
}
public createCurves (state: any, root: Node) {
public createCurves (state: AnimationState, root: Node) {
this._ratioSamplers = this._keys.map(
(keys) => new RatioSampler(
keys.map(
(key) => key / this._duration)));
const curveData = this.curveData;
const childrenCurveDatas = curveData.paths;
const curves = [];
this.createTargetCurves(root, curveData, curves);
if (childrenCurveDatas) {
for (const namePath of Object.keys(childrenCurveDatas)) {
const target = find(namePath, root);
if (!target) {
continue;
}
const childCurveDatas = childrenCurveDatas[namePath];
this.createTargetCurves(target, childCurveDatas, curves);
const curves: DynamicAnimCurve[] = [];
for (const path of Object.keys(this.curveDatas)) {
const target = find(path, root);
if (!target) {
continue;
}
const curveData = this.curveDatas[path];
this.createTargetCurves(target, curveData, curves);
}
return curves;
+1
View File
@@ -490,6 +490,7 @@ export class AnimationState extends Playable {
}
protected onStop () {
this.setTime(0);
if (!this.isPaused) {
cc.director.getAnimationManager().removeAnimation(this);
}
+7
View File
@@ -19,6 +19,11 @@ export function additive3D (value: Vec3, weight: number, propertyBlendState: Pro
if (propertyBlendState.weight === 0) {
vec3.zero(propertyBlendState.value);
}
if (weight === 0) {
return propertyBlendState.value;
} else if (weight === 1) {
return vec3.copy(propertyBlendState.value, value);
}
return vec3.scaleAndAdd(propertyBlendState.value, propertyBlendState.value, value, weight);
}
@@ -31,6 +36,8 @@ export function additiveQuat (value: Quat, weight: number, propertyBlendState: P
}
if (weight === 0) {
return propertyBlendState.value;
} else if (weight === 1) {
return quat.copy(propertyBlendState.value, value);
}
const t = weight / (propertyBlendState.weight + weight);
return quat.slerp(propertyBlendState.value, propertyBlendState.value, value, t);
+15 -3
View File
@@ -63,6 +63,13 @@ export class CrossFade extends Playable {
}
}
public sample () {
const currentFading = this._fadings[0];
if (currentFading.state) {
currentFading.state.sample();
}
}
public onPause () {
super.onPause();
for (const fading of this._fadings) {
@@ -83,13 +90,18 @@ export class CrossFade extends Playable {
public onStop () {
super.onStop();
const currentFading = this._fadings[0];
if (currentFading.state) {
currentFading.state.weight = 1;
}
for (const fading of this._fadings) {
if (fading.state) {
this._directStopState(fading.state);
}
}
this._fadings.length = 0;
this._unshiftDefault();
this._fadings.splice(1, this._fadings.length - 1);
// this._fadings.length = 0;
// this._unshiftDefault();
}
private _unshiftDefault () {
@@ -101,7 +113,7 @@ export class CrossFade extends Playable {
}
private _directStopState (state: AnimationState) {
state.weight = 0;
// state.weight = 0;
state.stop();
}
+3 -2
View File
@@ -87,10 +87,11 @@ export class AnimationComponent extends EventTargetFactory(Component) {
if (value) {
cc.engine.animatingInEditMode = true;
this.crossFade(this._defaultClip.name);
this._crossFade!.resume();
this._crossFade!.play();
} else {
cc.engine.animatingInEditMode = false;
this._crossFade!.pause();
this._crossFade!.stop();
this._crossFade!.sample();
}
}
+1
View File
@@ -183,6 +183,7 @@ export function _resetDebugSetting (mode: DebugMode) {
if (!condition) {
const errorText = formatString(message, ...optionalParams);
if (CC_DEV) {
// tslint:disable:no-debugger
debugger;
}
else {
+6
View File
@@ -498,6 +498,12 @@ export class BaseNode extends CCObject {
return this;
}
const segments = path.split('/');
// Starts with /
if (segments.length !== 0 && segments[0].length === 0) {
segments.shift();
}
let lastNode: this = this;
for (const segment of segments) {
const next = lastNode.children.find((childNode) => childNode.name === segment);
+6 -33
View File
@@ -23,6 +23,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
import { warnID } from '../core/platform/CCDebug';
import { Node } from './node';
/**
@@ -32,51 +33,23 @@ import { Node } from './node';
* It is recommended to not use this function every frame instead cache the result at startup.
*/
export function find (path: string, referenceNode?: Node): Node | null {
if (path == null) {
cc.errorID(5600);
return null;
}
if (!referenceNode) {
const scene = cc.director.getScene();
if (!scene) {
if (CC_DEV) {
cc.warnID(5601);
warnID(5601);
}
return null;
}
else if (CC_DEV && !scene.isValid) {
cc.warnID(5602);
} else if (CC_DEV && !scene.isValid) {
warnID(5602);
return null;
}
referenceNode = scene;
} else if (CC_DEV && !referenceNode.isValid) {
cc.warnID(5603);
warnID(5603);
return null;
}
let match = referenceNode!;
const startIndex = (path[0] !== '/') ? 0 : 1; // skip first '/'
const nameList = path.split('/');
// parse path
for (let n = startIndex; n < nameList.length; n++) {
const name = nameList[n];
const children = match.children;
let found = false;
for (let t = 0, len = children.length; t < len; ++t) {
const subChild = children[t];
if (subChild.name === name) {
match = subChild;
found = true;
break;
}
}
if (!found) {
return null;
}
}
return match;
return referenceNode!.getChildByPath(path);
}
cc.find = find;