revert code

This commit is contained in:
jerrywwl
2019-07-16 18:32:23 +08:00
parent 7d83b8d34c
commit 9b65c2d75a
3 changed files with 28 additions and 82 deletions
+15 -34
View File
@@ -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<T = any> = {
// 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;
}
}
}
+1 -3
View File
@@ -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<string, any>;
/**
* If propertyBlendState.weight equals to zero, the propertyBlendState.value is dirty.
+12 -45
View File
@@ -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);