diff --git a/cocos/3d/framework/skinning-model-component.ts b/cocos/3d/framework/skinning-model-component.ts index 751daf0859..1701da74e1 100644 --- a/cocos/3d/framework/skinning-model-component.ts +++ b/cocos/3d/framework/skinning-model-component.ts @@ -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); }); diff --git a/cocos/animation/animation-clip.ts b/cocos/animation/animation-clip.ts index 5fc1bf1de6..6e638db8b5 100644 --- a/cocos/animation/animation-clip.ts +++ b/cocos/animation/animation-clip.ts @@ -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; diff --git a/cocos/animation/animation-state.ts b/cocos/animation/animation-state.ts index fa339a7ebf..7b525c64d6 100644 --- a/cocos/animation/animation-state.ts +++ b/cocos/animation/animation-state.ts @@ -490,6 +490,7 @@ export class AnimationState extends Playable { } protected onStop () { + this.setTime(0); if (!this.isPaused) { cc.director.getAnimationManager().removeAnimation(this); } diff --git a/cocos/animation/blending.ts b/cocos/animation/blending.ts index ec2116e8fe..a2ad66fb6c 100644 --- a/cocos/animation/blending.ts +++ b/cocos/animation/blending.ts @@ -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); diff --git a/cocos/animation/cross-fade.ts b/cocos/animation/cross-fade.ts index 338e7e4d64..344989b5a7 100644 --- a/cocos/animation/cross-fade.ts +++ b/cocos/animation/cross-fade.ts @@ -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(); } diff --git a/cocos/components/animation-component.ts b/cocos/components/animation-component.ts index 94123526da..38d4755140 100644 --- a/cocos/components/animation-component.ts +++ b/cocos/components/animation-component.ts @@ -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(); } } diff --git a/cocos/core/platform/CCDebug.ts b/cocos/core/platform/CCDebug.ts index a522c10063..9e50e7aa45 100644 --- a/cocos/core/platform/CCDebug.ts +++ b/cocos/core/platform/CCDebug.ts @@ -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 { diff --git a/cocos/scene-graph/base-node.ts b/cocos/scene-graph/base-node.ts index 46f90a2a8b..88f6a32fff 100644 --- a/cocos/scene-graph/base-node.ts +++ b/cocos/scene-graph/base-node.ts @@ -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); diff --git a/cocos/scene-graph/find.ts b/cocos/scene-graph/find.ts index 6347fbc4b5..22105dd96c 100644 --- a/cocos/scene-graph/find.ts +++ b/cocos/scene-graph/find.ts @@ -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;