|
@@ -36,11 +36,11 @@ export default class XAnimationController {
|
|
|
return resolve(null);
|
|
|
|
|
|
this._prerocess(animationName, isLoop),
|
|
|
- this._avatar.avatarManager.loadAnimation(this._avatar.avatarType, animationName).then(animationGroup => {
|
|
|
- if (!animationGroup) return reject(new AvatarAnimationError("animation group does not exist"));
|
|
|
+ this._avatar.avatarManager.loadAnimation(this._avatar.avatarType, animationName).then(skeleton => {
|
|
|
+ if (!skeleton) return reject(new AvatarAnimationError("animation group does not exist"));
|
|
|
|
|
|
- // 实际上skeleton还是AnimationGroup类型
|
|
|
- const skeleton = this._mappingSkeleton(animationGroup);
|
|
|
+ // skeleton是AnimationGroup类型
|
|
|
+ skeleton = this._mappingSkeleton(skeleton);
|
|
|
if (!skeleton) return reject(new AvatarAnimationError("mapping animation failed"))
|
|
|
|
|
|
if (skeleton && this._isAnimationValid(skeleton))
|
|
@@ -48,11 +48,12 @@ export default class XAnimationController {
|
|
|
reject(new AvatarAnimationError("mapping animation failed"));
|
|
|
|
|
|
this.enableSkLod && this.skeletonMask(skeleton, aniType)
|
|
|
- this.detachAnimation(aniType)
|
|
|
- aniType == 0 ? this.iBodyAnim.animGroup = skeleton : aniType == 1 && (this.iFaceAnim.animGroup = skeleton)
|
|
|
+ this.detachAnimation(aniType) // 停止当前动画
|
|
|
+ aniType == 0 && (this.iBodyAnim.animGroup = skeleton)
|
|
|
+ aniType == 1 && (this.iFaceAnim.animGroup = skeleton)
|
|
|
|
|
|
- if (!this._playAnimation(aniType))
|
|
|
- return reject(new AvatarAnimationError("[Engine] play animation failed, animtion resource does not match current character"));
|
|
|
+ if (!this._playAnimation(aniType)) return reject(
|
|
|
+ new AvatarAnimationError("[Engine] play animation failed, animtion resource does not match current character"));
|
|
|
|
|
|
this._playEffect(),
|
|
|
this.postObserver = skeleton.onAnimationEndObservable.addOnce(()=>(
|
|
@@ -144,41 +145,52 @@ export default class XAnimationController {
|
|
|
for (const d of (c = this.iFaceAnim) == null ? void 0 : c.animGroup.targetedAnimations)
|
|
|
d.animation.enableBlending = !1
|
|
|
}
|
|
|
- skeletonMask(e, i=0) {
|
|
|
- if (i == 0) {
|
|
|
+ skeletonMask(e, aniType=0) {
|
|
|
+ if (aniType == 0) {
|
|
|
const o = this._lodMask.get(this._avatar.distLevel);
|
|
|
if (o)
|
|
|
for (let s = 0; s < e.targetedAnimations.length; ++s)
|
|
|
- o.includes(e.targetedAnimations[s].target.name) || (e.targetedAnimations.splice(s, 1),
|
|
|
- s--);
|
|
|
+ o.includes(e.targetedAnimations[s].target.name) || (
|
|
|
+ e.targetedAnimations.splice(s, 1),
|
|
|
+ s--
|
|
|
+ );
|
|
|
return !0
|
|
|
}
|
|
|
return !1
|
|
|
}
|
|
|
- detachAnimation(e=2) {
|
|
|
- var i, o;
|
|
|
- switch (e) {
|
|
|
+ detachAnimation(aniType=2) {
|
|
|
+ switch (aniType) {
|
|
|
case 0:
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && (this.iBodyAnim.animGroup._parentContainer.xReferenceCount && this.iBodyAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
- this.iBodyAnim.animGroup.stop(),
|
|
|
- this.iBodyAnim.animGroup.dispose(),
|
|
|
- this.iBodyAnim.animGroup = void 0);
|
|
|
+ // 身体动画
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && (
|
|
|
+ this.iBodyAnim.animGroup._parentContainer.xReferenceCount && this.iBodyAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
+ this.iBodyAnim.animGroup.stop(),
|
|
|
+ this.iBodyAnim.animGroup.dispose(),
|
|
|
+ this.iBodyAnim.animGroup = void 0
|
|
|
+ );
|
|
|
break;
|
|
|
case 1:
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && (this.iFaceAnim.animGroup._parentContainer.xReferenceCount && this.iFaceAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
- this.iFaceAnim.animGroup.stop(),
|
|
|
- this.iFaceAnim.animGroup.dispose(),
|
|
|
- this.iFaceAnim.animGroup = void 0);
|
|
|
+ // 脸部动画
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && (
|
|
|
+ this.iFaceAnim.animGroup._parentContainer.xReferenceCount && this.iFaceAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
+ this.iFaceAnim.animGroup.stop(),
|
|
|
+ this.iFaceAnim.animGroup.dispose(),
|
|
|
+ this.iFaceAnim.animGroup = void 0
|
|
|
+ );
|
|
|
break;
|
|
|
case 2:
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && (this.iBodyAnim.animGroup._parentContainer.xReferenceCount && this.iBodyAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
- (i = this.iBodyAnim) == null || i.animGroup.stop(),
|
|
|
- (o = this.iBodyAnim) == null || o.animGroup.dispose(),
|
|
|
- this.iBodyAnim.animGroup = void 0),
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && (this.iFaceAnim.animGroup._parentContainer.xReferenceCount && this.iFaceAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
- this.iFaceAnim.animGroup.stop(),
|
|
|
- this.iFaceAnim.animGroup.dispose(),
|
|
|
- this.iFaceAnim.animGroup = void 0);
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && (
|
|
|
+ this.iBodyAnim.animGroup._parentContainer.xReferenceCount && this.iBodyAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
+ this.iBodyAnim.animGroup.stop(),
|
|
|
+ this.iBodyAnim.animGroup.dispose(),
|
|
|
+ this.iBodyAnim.animGroup = void 0
|
|
|
+ ),
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && (
|
|
|
+ this.iFaceAnim.animGroup._parentContainer.xReferenceCount && this.iFaceAnim.animGroup._parentContainer.xReferenceCount--,
|
|
|
+ this.iFaceAnim.animGroup.stop(),
|
|
|
+ this.iFaceAnim.animGroup.dispose(),
|
|
|
+ this.iFaceAnim.animGroup = void 0
|
|
|
+ );
|
|
|
break
|
|
|
}
|
|
|
}
|
|
@@ -192,7 +204,8 @@ export default class XAnimationController {
|
|
|
const name = boneOld.name.split(" ").length > 2 ? boneOld.name.split(" ")[2] : boneOld.name;
|
|
|
if (this._boneMap.size === (this._avatar.skeleton && this._avatar.skeleton.bones.length)) return this._boneMap.get(name);
|
|
|
{
|
|
|
- let bone0 = this._avatar.skeleton && this._avatar.skeleton.bones.find(bone => bone.name === boneOld.name || bone.name === boneOld.name.split(" ")[2])
|
|
|
+ let bone0 = this._avatar.skeleton &&
|
|
|
+ this._avatar.skeleton.bones.find(bone => bone.name === boneOld.name || bone.name === boneOld.name.split(" ")[2])
|
|
|
const bone = bone0 && bone0.getTransformNode();
|
|
|
bone && (
|
|
|
bone.name = name,
|
|
@@ -245,9 +258,9 @@ export default class XAnimationController {
|
|
|
var e;
|
|
|
return !(!this._avatar.isRender || !this._avatar.skeleton || ((e = this._avatar.rootNode) == null ? void 0 : e.getChildMeshes().length) == 0)
|
|
|
}
|
|
|
- _prerocess(e, i) {
|
|
|
- this._avatar.isRayCastEnable && this._setPosition(e, i),
|
|
|
- this._avatar.priority === 0 && logger.info(`start play animation: ${e} on avatar ${this._avatar.id}`)
|
|
|
+ _prerocess(animationName, isLoop) {
|
|
|
+ this._avatar.isRayCastEnable && this._setPosition(animationName, isLoop),
|
|
|
+ this._avatar.priority === 0 && logger.info(`start play animation: ${animationName} on avatar ${this._avatar.id}`)
|
|
|
}
|
|
|
_playEffect() {
|
|
|
this.animationExtras.indexOf(this.iBodyAnim.name) != -1 && action.Cheering.attachPair.forEach(i=>{
|
|
@@ -256,13 +269,13 @@ export default class XAnimationController {
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
- _playAnimation(e=0) {
|
|
|
- return e == 0 && this.iBodyAnim && this.iBodyAnim.animGroup ? (
|
|
|
+ _playAnimation(aniType=0) {
|
|
|
+ return aniType == 0 && this.iBodyAnim && this.iBodyAnim.animGroup ? (
|
|
|
// 身体动画
|
|
|
this.onPlayObservable.notifyObservers(this._scene),
|
|
|
this.iBodyAnim.animGroup.start(this.loop, this.iBodyAnim.playSpeed, this.iBodyAnim.startFrame, this.iBodyAnim.endFrame, !1),
|
|
|
!0
|
|
|
- ) : e == 1 && this.iFaceAnim && this.iFaceAnim.animGroup ? (
|
|
|
+ ) : aniType == 1 && this.iFaceAnim && this.iFaceAnim.animGroup ? (
|
|
|
// 脸部动画
|
|
|
this.iFaceAnim.animGroup.start(this.loop, this.iFaceAnim.playSpeed, this.iFaceAnim.startFrame, this.iFaceAnim.endFrame, !1),
|
|
|
!0
|
|
@@ -274,9 +287,9 @@ export default class XAnimationController {
|
|
|
e == 0 ? i = (o = this.iBodyAnim) == null ? void 0 : o.name : e == 1 && (i = (s = this.iFaceAnim) == null ? void 0 : s.name),
|
|
|
i === action.Cheering.animName && this._avatar.disposeExtra()
|
|
|
}
|
|
|
- _isAnimationValid(e) {
|
|
|
- for (let i = 0; i < e.targetedAnimations.length; ++i)
|
|
|
- if (e.targetedAnimations[i].target)
|
|
|
+ _isAnimationValid(skeleton) {
|
|
|
+ for (let i = 0; i < skeleton.targetedAnimations.length; ++i)
|
|
|
+ if (skeleton.targetedAnimations[i].target)
|
|
|
return !1;
|
|
|
return !0
|
|
|
}
|