zhouenguang 3 anni fa
parent
commit
ff4a5ce865
2 ha cambiato i file con 27 aggiunte e 24 eliminazioni
  1. 19 16
      src/XAnimationController.js
  2. 8 8
      src/XAvatarManager.js

+ 19 - 16
src/XAnimationController.js

@@ -36,10 +36,11 @@ export default class XAnimationController {
         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"));
+        this._avatar.avatarManager.loadAnimation(this._avatar.avatarType, animationName).then(animationGroup => {
+            if (!animationGroup) return reject(new AvatarAnimationError("animation group does not exist"));
 
-            const skeleton = this._mappingSkeleton(animation);
+            // 实际上skeleton还是AnimationGroup类型
+            const skeleton = this._mappingSkeleton(animationGroup);
             if (!skeleton) return reject(new AvatarAnimationError("mapping animation failed"))
             
             if (skeleton && this._isAnimationValid(skeleton))
@@ -185,23 +186,23 @@ export default class XAnimationController {
     getAnimation(e, i) {
         return avatarLoader.animations.get(getAnimationKey(i, e))
     }
-    _mappingSkeleton(animation) {
-        if (animation) {
-            const skeleton = animation.clone(animation.name, o=>{
-                const name = o.name.split(" ").length > 2 ? o.name.split(" ")[2] : o.name;
+    _mappingSkeleton(animationGroup) {
+        if (animationGroup) {
+            const animationGroupClone = animationGroup.clone(animationGroup.name, boneOld => {
+                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 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
+                    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,
+                        this._boneMap.set(name, bone)
+                    )
+                    return bone
                 }
             });
-            return skeleton._parentContainer = animation._parentContainer,
-            skeleton
+            animationGroupClone._parentContainer = animationGroup._parentContainer
+            return animationGroupClone
         } else
             return
     }
@@ -257,10 +258,12 @@ export default class XAnimationController {
     }
     _playAnimation(e=0) {
         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

+ 8 - 8
src/XAvatarManager.js

@@ -565,19 +565,19 @@ export default class XAvatarManager {
         return new Promise((resolve, reject)=>
             avatarLoader.loadAnimRes(this.sceneManager, animationName, avatarType).then(o=>{
                 if (o) {
-                    let a;
+                    let group;
                     const avatarAnimations = this.avatarLoader.animations;
-                    return o.animationGroups.forEach(animation=>{
-                        animation.stop(),
-                        animation.name === animationName && (
-                            a = animation,
-                            a.pContainer = o
+                    return o.animationGroups.forEach(animationGroup=>{
+                        animationGroup.stop(),
+                        animationGroup.name === animationName && (
+                            group = animationGroup,
+                            group.pContainer = o
                         ),
-                        avatarAnimations.set(getAnimationKey(animation.name, avatarType), animation)
+                        avatarAnimations.set(getAnimationKey(animationGroup.name, avatarType), animationGroup)
                     }),
                     this._clipContainerRes(o),
                     o.xReferenceCount++,
-                    resolve(a)
+                    resolve(group)
                 } else
                     return reject(new ContainerLoadingFailedError("[Engine] container failed instanciates failed"))
             }