From 9b65c2d75af06ffe74ea9bab6fb2f56305143f74 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Tue, 16 Jul 2019 18:32:23 +0800 Subject: [PATCH] revert code --- cocos/animation/animation-blend-state.ts | 49 +++++++------------- cocos/animation/animation-curve.ts | 4 +- cocos/animation/animation-state.ts | 57 +++++------------------- 3 files changed, 28 insertions(+), 82 deletions(-) diff --git a/cocos/animation/animation-blend-state.ts b/cocos/animation/animation-blend-state.ts index af61704348..fc31eac084 100644 --- a/cocos/animation/animation-blend-state.ts +++ b/cocos/animation/animation-blend-state.ts @@ -4,13 +4,11 @@ import { Node } from '../scene-graph'; import { CurveTarget } from './animation-curve'; -import { AnimCurveProperty } from './animation-state'; // tslint:disable:interface-over-type-literal export type PropertyBlendState = { - // name: string; - property: AnimCurveProperty; + name: string; weight: number; value?: T; refCount: number; @@ -24,7 +22,7 @@ interface ITargetState { export class AnimationBlendState { private _blendTargets: ITargetState[] = []; - public refPropertyBlendTarget (target: CurveTarget, property: AnimCurveProperty) { + public refPropertyBlendTarget (target: CurveTarget, property: string) { let targetState = this._blendTargets.find((x) => x.target === target); if (!targetState) { targetState = { target, properties: [] }; @@ -32,16 +30,16 @@ export class AnimationBlendState { } const propertyStates = targetState.properties; - let propertyState = propertyStates.find((p) => p.property === property); + let propertyState = propertyStates.find((p) => p.name === property); if (!propertyState) { - propertyState = { property, weight: 0, value: undefined, refCount: 0 }; + propertyState = { name, weight: 0, value: undefined, refCount: 0 }; propertyStates.push(propertyState); } ++propertyState.refCount; return propertyState; } - public derefPropertyBlendTarget (target: CurveTarget, property: AnimCurveProperty) { + public derefPropertyBlendTarget (target: CurveTarget, property: string) { const iTargetState = this._blendTargets.findIndex((x) => x.target === target); if (iTargetState < 0) { return; @@ -49,7 +47,7 @@ export class AnimationBlendState { const targetState = this._blendTargets[iTargetState]; const propertyStates = targetState.properties; - const iPropertyState = propertyStates.findIndex((p) => p.property === property); + const iPropertyState = propertyStates.findIndex((p) => p.name === property); if (iPropertyState < 0) { return; } @@ -73,33 +71,16 @@ export class AnimationBlendState { const propertyStates = targetState.properties; for (const p of propertyStates) { if (p.weight !== 0) { - target[p.property] = p.value; - - switch (p.property) { - case AnimCurveProperty.POSITION: { - if (target instanceof Node) { - target.setPosition(p.value); - } else { - (target as any).position = p.value; - } - break; - } - case AnimCurveProperty.ROTATION: { - if (target instanceof Node) { - target.setRotation(p.value); - } else { - (target as any).rotation = p.value; - } - break; - } - case AnimCurveProperty.SCALE: { - if (target instanceof Node) { - target.setScale(p.value); - } else { - (target as any).scale = p.value; - } - break; + if (target instanceof Node) { + if (p.name === 'position') { + target.setPosition(p.value); + } else if (p.name === 'rotation') { + target.setRotation(p.value); + } else { + target.setScale(p.value); } + } else { + target[p.name] = p.value; } } } diff --git a/cocos/animation/animation-curve.ts b/cocos/animation/animation-curve.ts index fdaf3712d6..ed072d82bd 100644 --- a/cocos/animation/animation-curve.ts +++ b/cocos/animation/animation-curve.ts @@ -2,13 +2,11 @@ * @category animation */ -import { Component } from '../components'; import { ccclass, property } from '../core/data/class-decorator'; import { binarySearchEpsilon as binarySearch } from '../core/data/utils/binary-search'; import { errorID } from '../core/platform/CCDebug'; import { ValueType } from '../core/value-types'; import * as vmath from '../core/vmath'; -import { Node } from '../scene-graph'; import { PropertyBlendState } from './animation-blend-state'; import { bezierByTime, BezierControlPoints } from './bezier'; import * as blending from './blending'; @@ -24,7 +22,7 @@ export type CurveValue = any; /** * 表示曲线的目标对象。 */ -export type CurveTarget = Node | Component; +export type CurveTarget = Record; /** * If propertyBlendState.weight equals to zero, the propertyBlendState.value is dirty. diff --git a/cocos/animation/animation-state.ts b/cocos/animation/animation-state.ts index 009dd17636..8ac4f55d45 100644 --- a/cocos/animation/animation-state.ts +++ b/cocos/animation/animation-state.ts @@ -11,17 +11,10 @@ import { AnimCurve, CurveTarget, RatioSampler } from './animation-curve'; import { Playable } from './playable'; import { WrapMode, WrapModeMask, WrappedInfo } from './types'; -export enum AnimCurveProperty { - UNKNOWN, - POSITION, - ROTATION, - SCALE, -} - interface ICurveInstance { curve: AnimCurve; target: CurveTarget; - property: AnimCurveProperty; + property: string; blendTarget: PropertyBlendState | null; cached?: any[]; } @@ -267,7 +260,7 @@ export class AnimationState extends Playable { continue; } - let target: CurveTarget = targetNode; + let target: Node | Component = targetNode; if (propertyCurve.component) { const targetComponent = targetNode.getComponent(propertyCurve.component); if (!targetComponent) { @@ -281,20 +274,9 @@ export class AnimationState extends Playable { this._samplerSharedGroups.push(samplerSharedGroup); } - let property: AnimCurveProperty; - if (propertyCurve.propertyName === 'position') { - property = AnimCurveProperty.POSITION; - } else if (propertyCurve.propertyName === 'rotation') { - property = AnimCurveProperty.ROTATION; - } else if (propertyCurve.propertyName === 'scale') { - property = AnimCurveProperty.SCALE; - } else { - property = AnimCurveProperty.UNKNOWN; - } - samplerSharedGroup.curves.push({ target, - property, + property : propertyCurve.propertyName, curve: propertyCurve.curve, blendTarget: null, }); @@ -646,31 +628,16 @@ export class AnimationState extends Playable { samplerResultCache.toRatio); } if (!curveInstace.curve._blendFunction || !curveInstace.blendTarget || curveInstace.blendTarget.refCount <= 1) { - switch (curveInstace.property) { - case AnimCurveProperty.POSITION: { - if (curveInstace.target instanceof Node) { - curveInstace.target.setPosition(value); - } else { - (curveInstace.target as any).position = value; - } - break; - } - case AnimCurveProperty.ROTATION: { - if (curveInstace.target instanceof Node) { - curveInstace.target.setRotation(value); - } else { - (curveInstace.target as any).rotation = value; - } - break; - } - case AnimCurveProperty.SCALE: { - if (curveInstace.target instanceof Node) { - curveInstace.target.setScale(value); - } else { - (curveInstace.target as any).scale = value; - } - break; + if (curveInstace.target instanceof Node) { + if (curveInstace.property === 'position') { + curveInstace.target.setPosition(value); + } else if (curveInstace.property === 'rotation') { + curveInstace.target.setRotation(value); + } else { + curveInstace.target.setScale(value); } + } else { + curveInstace.target[curveInstace.property] = value; } } else { curveInstace.blendTarget.value = curveInstace.curve._blendFunction(value, this.weight, curveInstace.blendTarget);