|
@@ -4,7 +4,7 @@ import Logger from "./Logger.js"
|
|
|
|
|
|
const logger = new Logger('AnimationController')
|
|
const logger = new Logger('AnimationController')
|
|
export default class XAnimationController {
|
|
export default class XAnimationController {
|
|
- constructor(e) {
|
|
|
|
|
|
+ constructor(avatar) {
|
|
this.iBodyAnim = void 0,
|
|
this.iBodyAnim = void 0,
|
|
this.animations = [],
|
|
this.animations = [],
|
|
this.defaultAnimation = "Idle",
|
|
this.defaultAnimation = "Idle",
|
|
@@ -18,87 +18,97 @@ export default class XAnimationController {
|
|
this.activeFaceAnimation = void 0,
|
|
this.activeFaceAnimation = void 0,
|
|
this.iFaceAnim = void 0,
|
|
this.iFaceAnim = void 0,
|
|
this.onPlayObservable = new Observable,
|
|
this.onPlayObservable = new Observable,
|
|
- this.playAnimation = (i,o,s=0,c,d,_)=>new Promise((b,k)=>{
|
|
|
|
- // zeg 传入i为任意动画名即可播放该动画,比如"GiftClap"
|
|
|
|
- // window.room.avatarManager.avatars.get(window.room.userId).playAnimation({"animationName": "GiftClap", "loop":true})
|
|
|
|
- if (this._isPlaying(i, s) || (this._registerAnimInfo(i, o, s, c, d, _),
|
|
|
|
- !this._isAnimate()))
|
|
|
|
- return b(null);
|
|
|
|
- this._prerocess(i, o),
|
|
|
|
- this._avatar.avatarManager.loadAnimation(this._avatar.avatarType, i).then(j=>{
|
|
|
|
- if (!j)
|
|
|
|
- return k(new AvatarAnimationError("animation group does not exist"));
|
|
|
|
- const skeleton = this._mappingSkeleton(j);
|
|
|
|
- if (!skeleton)
|
|
|
|
- return k(new AvatarAnimationError("mapping animation failed"));
|
|
|
|
- if (skeleton && this._isAnimationValid(skeleton))
|
|
|
|
- return skeleton.dispose(),
|
|
|
|
- k(new AvatarAnimationError("mapping animation failed"));
|
|
|
|
- if (this.enableSkLod && this.skeletonMask(skeleton, s),
|
|
|
|
- this.detachAnimation(s),
|
|
|
|
- s == 0 ? this.iBodyAnim.animGroup = skeleton : s == 1 && (this.iFaceAnim.animGroup = skeleton),
|
|
|
|
- !this._playAnimation(s))
|
|
|
|
- return k(new AvatarAnimationError("[Engine] play animation failed, animtion resource does not match current character"));
|
|
|
|
- this._playEffect(),
|
|
|
|
- this.postObserver = skeleton.onAnimationEndObservable.addOnce(()=>(this._postprocess(s),
|
|
|
|
- b(null)))
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- ),
|
|
|
|
- this.stopAnimation = (i=0)=>{
|
|
|
|
- var o, s, c, d;
|
|
|
|
- switch (i) {
|
|
|
|
- case 0:
|
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.stop());
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.stop());
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && ((c = this.iBodyAnim) == null || c.animGroup.stop()),
|
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && ((d = this.iFaceAnim) == null || d.animGroup.stop());
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ this._avatar = avatar,
|
|
|
|
+ this._scene = avatar.avatarManager.scene,
|
|
|
|
+ this.animationExtras.push(action.Cheering.animName),
|
|
|
|
+ this._boneMap = new Map
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // s: :0 身体动画 :1 脸部动画
|
|
|
|
+ playAnimation = (animationName, isLoop, s=0, c, d, _)=>new Promise((resolve, reject)=>{
|
|
|
|
+ // zeg 传入i为任意动画名即可播放该动画,比如"GiftClap"
|
|
|
|
+ // window.room.avatarManager.avatars.get(window.room.userId).playAnimation({"animationName": "GiftClap", "loop":true})
|
|
|
|
+ if (
|
|
|
|
+ this._isPlaying(animationName, s) ||
|
|
|
|
+ (this._registerAnimInfo(animationName, isLoop, s, c, d, _), !this._isAnimate())
|
|
|
|
+ )
|
|
|
|
+ return resolve(null);
|
|
|
|
+
|
|
|
|
+ this._prerocess(animationName, isLoop),
|
|
|
|
+ this._avatar.avatarManager.loadAnimation(this._avatar.avatarType, animationName).then(animation => {
|
|
|
|
+ if (!animation) return reject(new AvatarAnimationError("animation group does not exist"));
|
|
|
|
+
|
|
|
|
+ const skeleton = this._mappingSkeleton(animation);
|
|
|
|
+ if (!skeleton) return reject(new AvatarAnimationError("mapping animation failed"))
|
|
|
|
+
|
|
|
|
+ if (skeleton && this._isAnimationValid(skeleton))
|
|
|
|
+ return skeleton.dispose(),
|
|
|
|
+ reject(new AvatarAnimationError("mapping animation failed"));
|
|
|
|
+
|
|
|
|
+ this.enableSkLod && this.skeletonMask(skeleton, s)
|
|
|
|
+ this.detachAnimation(s)
|
|
|
|
+ s == 0 ? this.iBodyAnim.animGroup = skeleton : s == 1 && (this.iFaceAnim.animGroup = skeleton)
|
|
|
|
+
|
|
|
|
+ if (!this._playAnimation(s))
|
|
|
|
+ return reject(new AvatarAnimationError("[Engine] play animation failed, animtion resource does not match current character"));
|
|
|
|
+
|
|
|
|
+ this._playEffect(),
|
|
|
|
+ this.postObserver = skeleton.onAnimationEndObservable.addOnce(()=>(
|
|
|
|
+ this._postprocess(s),
|
|
|
|
+ resolve(null)
|
|
|
|
+ ))
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ stopAnimation = (i=0)=>{
|
|
|
|
+ var o, s, c, d;
|
|
|
|
+ switch (i) {
|
|
|
|
+ case 0:
|
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.stop());
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.stop());
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && ((c = this.iBodyAnim) == null || c.animGroup.stop()),
|
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && ((d = this.iFaceAnim) == null || d.animGroup.stop());
|
|
|
|
+ break
|
|
}
|
|
}
|
|
- ,
|
|
|
|
- this.pauseAnimation = (i=0)=>{
|
|
|
|
- var o, s, c, d;
|
|
|
|
- switch (i) {
|
|
|
|
- case 0:
|
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.pause());
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.pause());
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && ((c = this.iBodyAnim) == null || c.animGroup.pause()),
|
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && ((d = this.iFaceAnim) == null || d.animGroup.pause());
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pauseAnimation = (i=0)=>{
|
|
|
|
+ var o, s, c, d;
|
|
|
|
+ switch (i) {
|
|
|
|
+ case 0:
|
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.pause());
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.pause());
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && ((c = this.iBodyAnim) == null || c.animGroup.pause()),
|
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && ((d = this.iFaceAnim) == null || d.animGroup.pause());
|
|
|
|
+ break
|
|
}
|
|
}
|
|
- ,
|
|
|
|
- this.resetAnimation = (i=0)=>{
|
|
|
|
- var o, s, c, d;
|
|
|
|
- switch (i) {
|
|
|
|
- case 0:
|
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.reset());
|
|
|
|
- break;
|
|
|
|
- case 1:
|
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.reset());
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- this.iBodyAnim && this.iBodyAnim.animGroup && ((c = this.iBodyAnim) == null || c.animGroup.reset()),
|
|
|
|
- this.iFaceAnim && this.iFaceAnim.animGroup && ((d = this.iFaceAnim) == null || d.animGroup.reset());
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resetAnimation = (i=0)=>{
|
|
|
|
+ var o, s, c, d;
|
|
|
|
+ switch (i) {
|
|
|
|
+ case 0:
|
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.reset());
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.reset());
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ this.iBodyAnim && this.iBodyAnim.animGroup && ((c = this.iBodyAnim) == null || c.animGroup.reset()),
|
|
|
|
+ this.iFaceAnim && this.iFaceAnim.animGroup && ((d = this.iFaceAnim) == null || d.animGroup.reset());
|
|
|
|
+ break
|
|
}
|
|
}
|
|
- ,
|
|
|
|
- this._avatar = e,
|
|
|
|
- this._scene = e.avatarManager.scene,
|
|
|
|
- this.animationExtras.push(action.Cheering.animName),
|
|
|
|
- this._boneMap = new Map
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
_isPlaying(e, i) {
|
|
_isPlaying(e, i) {
|
|
return i == 0 && this.iBodyAnim != null && this.iBodyAnim.animGroup && e == this.iBodyAnim.name ? !0 : !!(i == 1 && this.iFaceAnim != null && this.iFaceAnim.animGroup && e == this.iFaceAnim.name)
|
|
return i == 0 && this.iBodyAnim != null && this.iBodyAnim.animGroup && e == this.iBodyAnim.name ? !0 : !!(i == 1 && this.iFaceAnim != null && this.iFaceAnim.animGroup && e == this.iFaceAnim.name)
|
|
}
|
|
}
|
|
@@ -175,23 +185,23 @@ export default class XAnimationController {
|
|
getAnimation(e, i) {
|
|
getAnimation(e, i) {
|
|
return avatarLoader.animations.get(getAnimationKey(i, e))
|
|
return avatarLoader.animations.get(getAnimationKey(i, e))
|
|
}
|
|
}
|
|
- _mappingSkeleton(e) {
|
|
|
|
- if (e) {
|
|
|
|
- const i = e.clone(e.name, o=>{
|
|
|
|
- var c, d, _;
|
|
|
|
- const s = o.name.split(" ").length > 2 ? o.name.split(" ")[2] : o.name;
|
|
|
|
- if (this._boneMap.size === ((c = this._avatar.skeleton) == null ? void 0 : c.bones.length))
|
|
|
|
- return this._boneMap.get(s);
|
|
|
|
|
|
+ _mappingSkeleton(animation) {
|
|
|
|
+ if (animation) {
|
|
|
|
+ const skeleton = animation.clone(animation.name, o=>{
|
|
|
|
+ const name = o.name.split(" ").length > 2 ? o.name.split(" ")[2] : o.name;
|
|
|
|
+ if (this._boneMap.size === (this._avatar.skeleton && this._avatar.skeleton.bones.length)) return this._boneMap.get(name);
|
|
{
|
|
{
|
|
- const b = (_ = (d = this._avatar.skeleton) == null ? void 0 : d.bones.find(k=>k.name === o.name || k.name === o.name.split(" ")[2])) == null ? void 0 : _.getTransformNode();
|
|
|
|
- return b && (b.name = s,
|
|
|
|
- this._boneMap.set(s, b)),
|
|
|
|
|
|
+ let bone = this._avatar.skeleton && this._avatar.skeleton.bones.find(bone => bone.name === o.name || bone.name === o.name.split(" ")[2])
|
|
|
|
+ const b = bone && bone.getTransformNode();
|
|
|
|
+ return b && (
|
|
|
|
+ b.name = name,
|
|
|
|
+ this._boneMap.set(name, b)
|
|
|
|
+ ),
|
|
b
|
|
b
|
|
}
|
|
}
|
|
- }
|
|
|
|
- );
|
|
|
|
- return i._parentContainer = e._parentContainer,
|
|
|
|
- i
|
|
|
|
|
|
+ });
|
|
|
|
+ return skeleton._parentContainer = animation._parentContainer,
|
|
|
|
+ skeleton
|
|
} else
|
|
} else
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -246,11 +256,14 @@ export default class XAnimationController {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
_playAnimation(e=0) {
|
|
_playAnimation(e=0) {
|
|
- var i, o;
|
|
|
|
- return e == 0 && this.iBodyAnim && ((i = this.iBodyAnim) == null ? void 0 : i.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 && ((o = this.iFaceAnim) == null ? void 0 : o.animGroup) ? (this.iFaceAnim.animGroup.start(this.loop, this.iFaceAnim.playSpeed, this.iFaceAnim.startFrame, this.iFaceAnim.endFrame, !1),
|
|
|
|
- !0) : !1
|
|
|
|
|
|
+ return e == 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 ? (
|
|
|
|
+ this.iFaceAnim.animGroup.start(this.loop, this.iFaceAnim.playSpeed, this.iFaceAnim.startFrame, this.iFaceAnim.endFrame, !1),
|
|
|
|
+ !0
|
|
|
|
+ ) : !1
|
|
}
|
|
}
|
|
_postprocess(e) {
|
|
_postprocess(e) {
|
|
var o, s;
|
|
var o, s;
|