Jelajahi Sumber

修改贴地,在setPosition里

xushiting 3 tahun lalu
induk
melakukan
9b06e52980
6 mengubah file dengan 516 tambahan dan 778 penghapusan
  1. 136 139
      src/XAnimationController.js
  2. 13 9
      src/XAvatar.js
  3. 103 88
      src/XAvatarComopnent.js
  4. 264 229
      src/XAvatarLoader.js
  5. 0 222
      src/XSequence.js
  6. 0 91
      src/XverseEffect.js

+ 136 - 139
src/XAnimationController.js

@@ -5,148 +5,145 @@ import Logger from "./Logger.js"
 const logger = new Logger('AnimationController')
 export default class XAnimationController {
     constructor(e) {
-        E(this, "iBodyAnim");
-        E(this, "animations", []);
-        E(this, "defaultAnimation", "Idle");
-        E(this, "onPlay", "Idle");
-        E(this, "loop", !0);
-        E(this, "animationExtras", []);
-        E(this, "enableBlend", !1);
-        E(this, "enableSkLod", !1);
-        E(this, "_boneMap", new Map);
-        E(this, "_lodMask", new Map);
-        E(this, "activeFaceAnimation");
-        E(this, "iFaceAnim");
-        E(this, "_scene");
-        E(this, "_avatar");
-        E(this, "onPlayObservable", new Observable);
-        E(this, "postObserver");
-        E(this, "playAnimation", (e,t,r=0,n,o,a)=>new Promise((s,l)=>{
-            if (this._isPlaying(e, r) || (this._registerAnimInfo(e, t, r, n, o, a),
+        this.iBodyAnim = void 0,
+        this.animations = [],
+        this.defaultAnimation = "Idle",
+        this.onPlay = "Idle",
+        this.loop = !0,
+        this.animationExtras = [],
+        this.enableBlend = !1,
+        this.enableSkLod = !1,
+        this._boneMap = new Map,
+        this._lodMask = new Map,
+        this.activeFaceAnimation = void 0,
+        this.iFaceAnim = void 0,
+        this.onPlayObservable = new Observable,
+        this.playAnimation = (i,o,s=0,c,d,_)=>new Promise((b,k)=>{
+            if (this._isPlaying(i, s) || (this._registerAnimInfo(i, o, s, c, d, _),
             !this._isAnimate()))
-                return s(null);
-            this._prerocess(e, t),
-            this._avatar.avatarManager.loadAnimation(this._avatar.avatarType, e).then(u=>{
-                if (!u)
-                    return l(new AvatarAnimationError("animation group does not exist"));
-                const c = this._mappingSkeleton(u);
-                if (!c)
-                    return l(new AvatarAnimationError("mapping animation failed"));
-                if (c && this._isAnimationValid(c))
-                    return c.dispose(),
-                    l(new AvatarAnimationError("mapping animation failed"));
-                if (this.enableSkLod && this.skeletonMask(c, r),
-                this.detachAnimation(r),
-                r == 0 ? this.iBodyAnim.animGroup = c : r == 1 && (this.iFaceAnim.animGroup = c),
-                !this._playAnimation(r))
-                    return l(new AvatarAnimationError("[Engine] play animation failed, animtion resource does not match current character"));
+                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 = c.onAnimationEndObservable.addOnce(()=>(this._postprocess(r),
-                s(null)))
+                this.postObserver = skeleton.onAnimationEndObservable.addOnce(()=>(this._postprocess(s),
+                b(null)))
             }
             )
         }
-        ));
-        E(this, "stopAnimation", (e=0)=>{
-            var t, r, n, o;
-            switch (e) {
+        ),
+        this.stopAnimation = (i=0)=>{
+            var o, s, c, d;
+            switch (i) {
             case 0:
-                this.iBodyAnim && this.iBodyAnim.animGroup && ((t = this.iBodyAnim) == null || t.animGroup.stop());
+                this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.stop());
                 break;
             case 1:
-                this.iFaceAnim && this.iFaceAnim.animGroup && ((r = this.iFaceAnim) == null || r.animGroup.stop());
+                this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.stop());
                 break;
             case 2:
-                this.iBodyAnim && this.iBodyAnim.animGroup && ((n = this.iBodyAnim) == null || n.animGroup.stop()),
-                this.iFaceAnim && this.iFaceAnim.animGroup && ((o = this.iFaceAnim) == null || o.animGroup.stop());
+                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
             }
         }
-        );
-        E(this, "pauseAnimation", (e=0)=>{
-            var t, r, n, o;
-            switch (e) {
+        ,
+        this.pauseAnimation = (i=0)=>{
+            var o, s, c, d;
+            switch (i) {
             case 0:
-                this.iBodyAnim && this.iBodyAnim.animGroup && ((t = this.iBodyAnim) == null || t.animGroup.pause());
+                this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.pause());
                 break;
             case 1:
-                this.iFaceAnim && this.iFaceAnim.animGroup && ((r = this.iFaceAnim) == null || r.animGroup.pause());
+                this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.pause());
                 break;
             case 2:
-                this.iBodyAnim && this.iBodyAnim.animGroup && ((n = this.iBodyAnim) == null || n.animGroup.pause()),
-                this.iFaceAnim && this.iFaceAnim.animGroup && ((o = this.iFaceAnim) == null || o.animGroup.pause());
+                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
             }
         }
-        );
-        E(this, "resetAnimation", (e=0)=>{
-            var t, r, n, o;
-            switch (e) {
+        ,
+        this.resetAnimation = (i=0)=>{
+            var o, s, c, d;
+            switch (i) {
             case 0:
-                this.iBodyAnim && this.iBodyAnim.animGroup && ((t = this.iBodyAnim) == null || t.animGroup.reset());
+                this.iBodyAnim && this.iBodyAnim.animGroup && ((o = this.iBodyAnim) == null || o.animGroup.reset());
                 break;
             case 1:
-                this.iFaceAnim && this.iFaceAnim.animGroup && ((r = this.iFaceAnim) == null || r.animGroup.reset());
+                this.iFaceAnim && this.iFaceAnim.animGroup && ((s = this.iFaceAnim) == null || s.animGroup.reset());
                 break;
             case 2:
-                this.iBodyAnim && this.iBodyAnim.animGroup && ((n = this.iBodyAnim) == null || n.animGroup.reset()),
-                this.iFaceAnim && this.iFaceAnim.animGroup && ((o = this.iFaceAnim) == null || o.animGroup.reset());
+                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, t) {
-        return t == 0 && this.iBodyAnim != null && this.iBodyAnim.animGroup && e == this.iBodyAnim.name ? !0 : !!(t == 1 && this.iFaceAnim != null && this.iFaceAnim.animGroup && e == this.iFaceAnim.name)
+    _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)
     }
     activeAnimation(e=0) {
-        var t, r;
+        var i, o;
         switch (e) {
         case 0:
-            return (t = this.iBodyAnim) == null ? void 0 : t.animGroup;
+            return (i = this.iBodyAnim) == null ? void 0 : i.animGroup;
         case 1:
-            return (r = this.iFaceAnim) == null ? void 0 : r.animGroup;
+            return (o = this.iFaceAnim) == null ? void 0 : o.animGroup;
         default:
             return
         }
     }
-    enableAnimationBlend(e=.1, t=0) {
-        var r, n, o, a;
-        if (t == 0 && ((r = this.iBodyAnim) == null ? void 0 : r.animGroup))
-            for (const s of (n = this.iBodyAnim) == null ? void 0 : n.animGroup.targetedAnimations)
-                s.animation.enableBlending = !0,
-                s.animation.blendingSpeed = e;
-        else if (t == 0 && ((o = this.iFaceAnim) == null ? void 0 : o.animGroup))
-            for (const s of (a = this.iFaceAnim) == null ? void 0 : a.animGroup.targetedAnimations)
-                s.animation.enableBlending = !0,
-                s.animation.blendingSpeed = e
+    enableAnimationBlend(e=.1, i=0) {
+        var o, s, c, d;
+        if (i == 0 && ((o = this.iBodyAnim) == null ? void 0 : o.animGroup))
+            for (const _ of (s = this.iBodyAnim) == null ? void 0 : s.animGroup.targetedAnimations)
+                _.animation.enableBlending = !0,
+                _.animation.blendingSpeed = e;
+        else if (i == 0 && ((c = this.iFaceAnim) == null ? void 0 : c.animGroup))
+            for (const _ of (d = this.iFaceAnim) == null ? void 0 : d.animGroup.targetedAnimations)
+                _.animation.enableBlending = !0,
+                _.animation.blendingSpeed = e
     }
     disableAnimationBlend(e=0) {
-        var t, r, n, o;
-        if (e == 0 && ((t = this.iBodyAnim) == null ? void 0 : t.animGroup))
-            for (const a of (r = this.iBodyAnim) == null ? void 0 : r.animGroup.targetedAnimations)
-                a.animation.enableBlending = !1;
-        else if (e == 0 && ((n = this.iFaceAnim) == null ? void 0 : n.animGroup))
-            for (const a of (o = this.iFaceAnim) == null ? void 0 : o.animGroup.targetedAnimations)
-                a.animation.enableBlending = !1
+        var i, o, s, c;
+        if (e == 0 && ((i = this.iBodyAnim) == null ? void 0 : i.animGroup))
+            for (const d of (o = this.iBodyAnim) == null ? void 0 : o.animGroup.targetedAnimations)
+                d.animation.enableBlending = !1;
+        else if (e == 0 && ((s = this.iFaceAnim) == null ? void 0 : s.animGroup))
+            for (const d of (c = this.iFaceAnim) == null ? void 0 : c.animGroup.targetedAnimations)
+                d.animation.enableBlending = !1
     }
-    skeletonMask(e, t=0) {
-        if (t == 0) {
-            const r = this._lodMask.get(this._avatar.distLevel);
-            if (r)
-                for (let n = 0; n < e.targetedAnimations.length; ++n)
-                    r.includes(e.targetedAnimations[n].target.name) || (e.targetedAnimations.splice(n, 1),
-                    n--);
+    skeletonMask(e, i=0) {
+        if (i == 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--);
             return !0
         }
         return !1
     }
     detachAnimation(e=2) {
-        var t, r;
+        var i, o;
         switch (e) {
         case 0:
             this.iBodyAnim && this.iBodyAnim.animGroup && (this.iBodyAnim.animGroup._parentContainer.xReferenceCount && this.iBodyAnim.animGroup._parentContainer.xReferenceCount--,
@@ -162,8 +159,8 @@ export default class XAnimationController {
             break;
         case 2:
             this.iBodyAnim && this.iBodyAnim.animGroup && (this.iBodyAnim.animGroup._parentContainer.xReferenceCount && this.iBodyAnim.animGroup._parentContainer.xReferenceCount--,
-            (t = this.iBodyAnim) == null || t.animGroup.stop(),
-            (r = this.iBodyAnim) == null || r.animGroup.dispose(),
+            (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(),
@@ -173,95 +170,95 @@ export default class XAnimationController {
         }
     }
     blendAnimation() {}
-    getAnimation(e, t) {
-        return avatarLoader.animations.get(getAnimationKey(t, e))
+    getAnimation(e, i) {
+        return avatarLoader.animations.get(getAnimationKey(i, e))
     }
     _mappingSkeleton(e) {
         if (e) {
-            const t = e.clone(e.name, r=>{
-                var o, a, s;
-                const n = r.name.split(" ").length > 2 ? r.name.split(" ")[2] : r.name;
-                if (this._boneMap.size === ((o = this._avatar.skeleton) == null ? void 0 : o.bones.length))
-                    return this._boneMap.get(n);
+            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);
                 {
-                    const l = (s = (a = this._avatar.skeleton) == null ? void 0 : a.bones.find(u=>u.name === r.name || u.name === r.name.split(" ")[2])) == null ? void 0 : s.getTransformNode();
-                    return l && (l.name = n,
-                    this._boneMap.set(n, l)),
-                    l
+                    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)),
+                    b
                 }
             }
             );
-            return t._parentContainer = e._parentContainer,
-            t
+            return i._parentContainer = e._parentContainer,
+            i
         } else
             return
     }
     removeAnimation(e) {
-        const t = avatarLoader.containers.get(e.name);
-        t && (t.dispose(),
+        const i = avatarLoader.containers.get(e.name);
+        i && (i.dispose(),
         avatarLoader.containers.delete(e.name),
         avatarLoader.animations.delete(getAnimationKey(e.name, e.skType)))
     }
-    _setPosition(e, t) {
+    _setPosition(e, i) {
         this._avatar.priority === 0 && this._avatar.isRender && e === this.defaultAnimation && e != this.onPlay && !this._avatar.isSelected && this._avatar.setPosition(this._avatar.position, !0)
     }
-    _registerAnimInfo(e, t, r=0, n, o, a) {
-        const s = {
+    _registerAnimInfo(e, i, o=0, s, c, d) {
+        const _ = {
             name: e,
             skType: this._avatar.avatarType,
-            loop: t,
-            playSpeed: n,
+            loop: i,
+            playSpeed: s,
             currentFrame: 0,
-            startFrame: o,
-            endFrame: a
+            startFrame: c,
+            endFrame: d
         };
-        r == 0 ? this.iBodyAnim == null ? this.iBodyAnim = s : (this.iBodyAnim.name = e,
+        o == 0 ? this.iBodyAnim == null ? this.iBodyAnim = _ : (this.iBodyAnim.name = e,
         this.iBodyAnim.skType = this._avatar.avatarType,
-        this.iBodyAnim.loop = t,
-        this.iBodyAnim.playSpeed = n,
+        this.iBodyAnim.loop = i,
+        this.iBodyAnim.playSpeed = s,
         this.iBodyAnim.currentFrame = 0,
-        this.iBodyAnim.startFrame = o,
-        this.iBodyAnim.endFrame = a) : r == 1 && (this.iFaceAnim == null ? this.iFaceAnim = s : (this.iFaceAnim.name = e,
+        this.iBodyAnim.startFrame = c,
+        this.iBodyAnim.endFrame = d) : o == 1 && (this.iFaceAnim == null ? this.iFaceAnim = _ : (this.iFaceAnim.name = e,
         this.iFaceAnim.skType = this._avatar.avatarType,
-        this.iFaceAnim.loop = t,
-        this.iFaceAnim.playSpeed = n,
+        this.iFaceAnim.loop = i,
+        this.iFaceAnim.playSpeed = s,
         this.iFaceAnim.currentFrame = 0,
-        this.iFaceAnim.startFrame = o,
-        this.iFaceAnim.endFrame = a)),
+        this.iFaceAnim.startFrame = c,
+        this.iFaceAnim.endFrame = d)),
         this.onPlay = e,
-        this.loop = t
+        this.loop = i
     }
     _isAnimate() {
         var e;
         return !(!this._avatar.isRender || !this._avatar.skeleton || ((e = this._avatar.rootNode) == null ? void 0 : e.getChildMeshes().length) == 0)
     }
-    _prerocess(e, t) {
-        this._avatar.isRayCastEnable && this._setPosition(e, t),
+    _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}`)
     }
     _playEffect() {
-        this.animationExtras.indexOf(this.iBodyAnim.name) != -1 && action.Cheering.attachPair.forEach(t=>{
-            this._avatar.attachExtraProp(t.obj, t.bone, new BABYLON.Vector3(t.offset.x,t.offset.y,t.offset.z), new BABYLON.Vector3(t.rotate.x,t.rotate.y,t.rotate.z)),
-            this._avatar.showExtra(t.obj)
+        this.animationExtras.indexOf(this.iBodyAnim.name) != -1 && action.Cheering.attachPair.forEach(i=>{
+            this._avatar.attachExtraProp(i.obj, i.bone, new Vector3(i.offset.x,i.offset.y,i.offset.z), new Vector3(i.rotate.x,i.rotate.y,i.rotate.z)),
+            this._avatar.showExtra(i.obj)
         }
         )
     }
     _playAnimation(e=0) {
-        var t, r;
-        return e == 0 && this.iBodyAnim && ((t = this.iBodyAnim) == null ? void 0 : t.animGroup) ? (this.onPlayObservable.notifyObservers(this._scene),
+        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 && ((r = this.iFaceAnim) == null ? void 0 : r.animGroup) ? (this.iFaceAnim.animGroup.start(this.loop, this.iFaceAnim.playSpeed, this.iFaceAnim.startFrame, this.iFaceAnim.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
     }
     _postprocess(e) {
-        var r, n;
-        let t;
-        e == 0 ? t = (r = this.iBodyAnim) == null ? void 0 : r.name : e == 1 && (t = (n = this.iFaceAnim) == null ? void 0 : n.name),
-        t === action.Cheering.animName && this._avatar.disposeExtra()
+        var o, s;
+        let i;
+        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 t = 0; t < e.targetedAnimations.length; ++t)
-            if (e.targetedAnimations[t].target)
+        for (let i = 0; i < e.targetedAnimations.length; ++i)
+            if (e.targetedAnimations[i].target)
                 return !1;
         return !0
     }

+ 13 - 9
src/XAvatar.js

@@ -231,21 +231,25 @@ export default class XAvatar {
         const e = avatarLoader.avaliableAnimation.get(this.avatarType);
         return e || []
     }
-    setPosition(e, i=!1) {
-        if (this._avatarPosition = e,
-        this.rootNode) {
+    //i用于控制是否接触地面
+    setPosition(e, i=!0) {
+        this._avatarPosition = e;
+        if (this.rootNode) {
             const o = ue4Position2Xverse(this._avatarPosition);
             let s = !1;
-            this.avatarManager.getMainAvatar() && (this.id != this.avatarManager.getMainAvatar().id || (Math.abs(o.y - this._previousReceivedPosition.y) > castRayOffsetY && (s = !0),
-            o.subtract(this._previousReceivedPosition).length() > castRayTeleportationOffset && (s = !0))),
+            if(this.avatarManager.getMainAvatar() ){
+                if(this.id == this.avatarManager.getMainAvatar().id){
+                    Math.abs(o.y - this._previousReceivedPosition.y) > castRayOffsetY && (s = !0);
+                    o.subtract(this._previousReceivedPosition).length() > castRayTeleportationOffset && (s = !0)
+                }
+            }
             this._isRayCastEnable ? s || i ? this._castRay(e).then(c=>{
-                this.rootNode.position = o,
-                this.rootNode.position.y -= c
+                this.rootNode.position = o;
+                this.rootNode.position.y -= c;
             }
             ).catch(c=>{
                 Promise.reject(c)
-            }
-            ) : (this.rootNode.position.x = o.x,
+            }) : (this.rootNode.position.x = o.x,
             this.rootNode.position.z = o.z) : this.rootNode.position = o,
             this._previousReceivedPosition = o.clone()
         }

+ 103 - 88
src/XAvatarComopnent.js

@@ -5,63 +5,61 @@ const logger = new Logger('XAvatarComopnent')
 
 export default class XAvatarComopnent {
     constructor() {
-        E(this, "resourceIdList", []);
-        E(this, "skeleton");
-        E(this, "extraProp");
-        E(this, "extras", []);
-        E(this, "body")
+        this.resourceIdList = [],
+        this.skeleton = void 0,
+        this.extraProp = void 0,
+        this.extras = [],
+        this.body = void 0,
+        this.accessories = new Map
     }
-    addBodyComp(e, t) {
-        // console.error(this, e, t)
-        return !e.rootNode || t.root.getChildMeshes().length === 0 ? (t.isRender = !1,
-        !1) : (this.body = t,
+    addBodyComp(e, i) {
+        return !e.rootNode || i.root.getChildMeshes().length === 0 ? (i.isRender = !1,
+        !1) : (this.body = i,
         this.body.root.parent = e.rootNode,
-        t.isRender = !0,
+        i.isRender = !0,
         this.body.root.getChildMeshes()[0] && (this.body.root.getChildMeshes()[0].xtype = EMeshType.XAvatar,
         this.body.root.getChildMeshes()[0].xid = e.id),
-        this.skeleton = t.skeleton,
+        this.skeleton = i.skeleton,
         !0)
     }
-    addClothesComp(e, t) {
-        // console.error(t.root.name)
-        // console.error(this, e, t)
-        return !e.rootNode || !this.skeleton || !t.root ? (t.isRender = !1,
-        !1) : (t.root.xtype = EMeshType.XAvatar,
-        t.root.xid = e.id,
-        t.isRender = !0,
-        t.root.parent = e.rootNode.getChildMeshes()[0],
-        this.resourceIdList.push(t),
-        t.root.skeleton = this.skeleton,
-        t.root.getChildMeshes().forEach(r=>{
-            r.skeleton = this.skeleton
+    addClothesComp(e, i) {
+        return !e.rootNode || !this.skeleton || !i.root ? (i.isRender = !1,
+        !1) : (i.root.xtype = EMeshType.XAvatar,
+        i.root.xid = e.id,
+        i.isRender = !0,
+        i.root.parent = e.rootNode.getChildMeshes()[0],
+        this.resourceIdList.push(i),
+        i.root.skeleton = this.skeleton,
+        i.root.getChildMeshes().forEach(o=>{
+            o.skeleton = this.skeleton
         }
         ),
         !0)
     }
     clearClothesComp(e) {
-        e.root.getChildMeshes().forEach(t=>{
-            t.skeleton = null,
-            t.dispose(),
-            t.xid = void 0
+        e.root.getChildMeshes().forEach(i=>{
+            i.skeleton = null,
+            i.dispose(),
+            i.xid = void 0
         }
         ),
         e.root.dispose(),
-        this.resourceIdList = this.resourceIdList.filter(t=>t.uId != e.uId)
+        this.resourceIdList = this.resourceIdList.filter(i=>i.uId != e.uId)
     }
     clearAllClothesComps() {
         this.resourceIdList.forEach(e=>{
-            var t;
+            var i;
             e.root.parent = null,
             e.root._parentContainer.xReferenceCount && (e.root._parentContainer.xReferenceCount--,
             e.root._parentContainer = null),
             e.isRender = !1,
             e.isSelected = !1,
-            e.root.getChildMeshes().forEach(r=>{
-                r.skeleton = null,
-                r.dispose()
+            e.root.getChildMeshes().forEach(o=>{
+                o.skeleton = null,
+                o.dispose()
             }
             ),
-            (t = e.root.skeleton) == null || t.dispose(),
+            (i = e.root.skeleton) == null || i.dispose(),
             e.root.dispose()
         }
         ),
@@ -77,92 +75,109 @@ export default class XAvatarComopnent {
         this.body.root.dispose(),
         this.body = void 0,
         this.skeleton && (this.skeleton.dispose(),
-        this.skeleton = void 0)) : logger.warn("[Engine] no body to dispose")
+        this.skeleton = void 0)) : log$I.warn("[Engine] no body to dispose")
+    }
+    async attachPendant(e, i) {
+        return Promise.resolve(avatarLoader.pullAndLoadXObject(e.avatarManager.sceneManager, i).then(o=>{
+            const s = o
+              , c = this.accessories.get(s.pointId);
+            return c ? (c.dispose(),
+            this.accessories.set(s.pointId, s),
+            log$I.warn("[Engine] \u8BE5\u6302\u70B9\u5F53\u524D\u88AB\u5360\u7528\uFF0C\u5DF2\u66FF\u6362\u8BE5\u6302\u70B9")) : this.accessories.set(s.pointId, s),
+            s.attachTo(e),
+            s
+        }
+        ))
+    }
+    detachPendant(e, i=!0) {
+        const o = this.accessories.get(e);
+        o && (o.dispose(),
+        this.accessories.delete(e))
     }
-    changeClothesComp(e, t, r, n, o) {
-        return new Promise(a=>{
-            if (r === "pendant" || this.resourceIdList.some(s=>s.name === t))
-                return a();
+    changeClothesComp(e, i, o, s, c) {
+        return new Promise(d=>{
+            if (this.resourceIdList.some(_=>_.name === i))
+                return d();
             if (e.isHide || !e.isRender)
-                o.concat(r).forEach(l=>{
-                    e.clothesList = e.clothesList.filter(c=>c.type != l);
-                    const u = {
-                        type: r,
-                        id: t,
-                        url: n,
+                c.concat(o).forEach(b=>{
+                    e.clothesList = e.clothesList.filter(j=>j.type != b);
+                    const k = {
+                        type: o,
+                        id: i,
+                        url: s,
                         lod: 0
                     };
-                    e.clothesList.push(u)
+                    e.clothesList.push(k)
                 }
                 ),
-                a();
+                d();
             else {
-                const s = o.concat(r);
-                e.avatarManager.loadDecoration(r, t, 0).then(l=>{
-                    if (l) {
-                        e.attachDecoration(l);
-                        const u = {
-                            type: r,
-                            id: t,
-                            url: n
+                const _ = c.concat(o);
+                e.avatarManager.loadDecoration(o, i, 0).then(b=>{
+                    if (b) {
+                        e.attachDecoration(b);
+                        const k = {
+                            type: o,
+                            id: i,
+                            url: s
                         };
-                        e.clothesList.push(u),
-                        l.root.setEnabled(!0),
-                        s.forEach(c=>{
-                            const h = this.resourceIdList.filter(f=>f.type === c);
-                            if (h.length > 1) {
-                                const f = h.filter(d=>d.name === t);
-                                if (f.length > 1)
-                                    for (let d = 1; d < f.length; ++d) {
-                                        e.detachDecoration(f[d]),
-                                        e.clothesList = e.clothesList.filter(g=>g.id != f[d].name);
-                                        const _ = {
-                                            type: r,
-                                            id: t,
-                                            url: n
+                        e.clothesList.push(k),
+                        b.root.setEnabled(!0),
+                        _.forEach(j=>{
+                            const $ = this.resourceIdList.filter(_e=>_e.type === j);
+                            if ($.length > 1) {
+                                const _e = $.filter(et=>et.name === i);
+                                if (_e.length > 1)
+                                    for (let et = 1; et < _e.length; ++et) {
+                                        e.detachDecoration(_e[et]),
+                                        e.clothesList = e.clothesList.filter(rt=>rt.id != _e[et].name);
+                                        const tt = {
+                                            type: o,
+                                            id: i,
+                                            url: s
                                         };
-                                        e.clothesList.push(_)
+                                        e.clothesList.push(tt)
                                     }
                             }
-                            h[0] && h[0].name != t && this._readyToDetach(e, r) && (e.detachDecoration(h[0]),
-                            e.clothesList = e.clothesList.filter(f=>f.id != h[0].name))
+                            $[0] && $[0].name != i && this._readyToDetach(e, o) && (e.detachDecoration($[0]),
+                            e.clothesList = e.clothesList.filter(_e=>_e.id != $[0].name))
                         }
                         )
                     }
-                    return a()
+                    return d()
                 }
                 )
             }
         }
         )
     }
-    _readyToDetach(e, t) {
-        return !((t == "clothes" || t == "pants") && e.clothesList.filter(n=>n.type === "suit").length == 1 && (!e.clothesList.some(n=>n.type === "pants") || !e.clothesList.some(n=>n.type === "clothes")))
+    _readyToDetach(e, i) {
+        return !((i == "clothes" || i == "pants") && e.clothesList.filter(s=>s.type === "suit").length == 1 && (!e.clothesList.some(s=>s.type === "pants") || !e.clothesList.some(s=>s.type === "clothes")))
     }
-    addDecoComp(e, t, r, n, o) {
+    addDecoComp(e, i, o, s, c) {
         if (e.isRender) {
-            const a = e.avatarManager.extraComps.get(t)
-              , s = a == null ? void 0 : a.clone(t, void 0);
-            if (!a) {
-                logger.error("\u6CA1\u6709\u5BF9\u5E94\u7684\u7EC4\u4EF6");
+            const d = e.avatarManager.extraComps.get(i)
+              , _ = d == null ? void 0 : d.clone(i, void 0);
+            if (!d) {
+                log$I.error("\u6CA1\u6709\u5BF9\u5E94\u7684\u7EC4\u4EF6");
                 return
             }
-            this.extras.push(s);
-            const l = this.skeleton.bones.find(u=>u.name === r);
-            s.position = n,
-            s.rotation = o,
-            s.attachToBone(l, e.rootNode.getChildMeshes()[0])
+            this.extras.push(_);
+            const b = this.skeleton.bones.find(k=>k.name === o);
+            _.position = s,
+            _.rotation = c,
+            _.attachToBone(b, e.rootNode.getChildMeshes()[0])
         }
     }
     showExtra(e) {
-        this.extras.forEach(t=>{
-            t.name.indexOf(e) > 0 && t.setEnabled(!0)
+        this.extras.forEach(i=>{
+            i.name.indexOf(e) > 0 && i.setEnabled(!0)
         }
         )
     }
     hideExtra(e) {
-        this.extras.forEach(t=>{
-            t.name.indexOf(e) > 0 && t.setEnabled(!1)
+        this.extras.forEach(i=>{
+            i.name.indexOf(e) > 0 && i.setEnabled(!1)
         }
         )
     }

+ 264 - 229
src/XAvatarLoader.js

@@ -1,120 +1,158 @@
+import Logger from "./Logger.js"
+
+const logger = new Logger('XAvatarLoader')
+
 export default class XAvatarLoader {
     constructor() {
-        E(this, "containers", new Map);
-        E(this, "meshes", new Map);
-        E(this, "animations", new Map);
-        E(this, "aniPath", new Map);
-        E(this, "binPath", new Map);
-        E(this, "texPath", new Map);
-        E(this, "matPath", new Map);
-        E(this, "mshPath", new Map);
-        E(this, "rootPath", new Map);
-        E(this, "meshTexList", new Map);
-        E(this, "_enableIdb", !0);
-        E(this, "_mappings", new Map);
-        E(this, "_sharedTex", new Map);
-        E(this, "avaliableAnimation", new Map);
-        E(this, "enableShareTexture", !0);
-        E(this, "enableShareAnimation", !0);
-        E(this, "fillEmptyLod", !0);
+        this.containers = new Map,
+        this.meshes = new Map,
+        this.animations = new Map,
+        this.aniPath = new Map,
+        this.binPath = new Map,
+        this.texPath = new Map,
+        this.matPath = new Map,
+        this.mshPath = new Map,
+        this.rootPath = new Map,
+        this.meshTexList = new Map,
+        this._enableIdb = !0,
+        this._mappings = new Map,
+        this._sharedTex = new Map,
+        this.avaliableAnimation = new Map,
+        this.enableShareTexture = !0,
+        this.enableShareAnimation = !0,
+        this.fillEmptyLod = !0,
+        this.pendantMap = new Map;
         const e = new BABYLON.GLTFFileLoader;
         BABYLON.SceneLoader.RegisterPlugin(e),
-        e.preprocessUrlAsync = function(t) {
-            const r = avatarLoader._mappings.get(t);
-            return r ? Promise.resolve(r) : Promise.resolve(t)
+        e.preprocessUrlAsync = function(i) {
+            const o = avatarLoader._mappings.get(i);
+            return o ? Promise.resolve(o) : Promise.resolve(i)
+        }
+    }
+    _parsePendant(e, i) {
+        if (!e || !i) {
+            logger.error("[Engine] invalid id or url when loading pendant");
+            return
+        }
+        const o = ".zip"
+          , s = i.replace(o, "/");
+        this.pendantMap.set(e, s)
+    }
+    pullAndLoadXObject(e, i) {
+        const o = avatarLoader.pendantMap.get(i);
+        return Tools.LoadFileAsync(o + `${i}.json`, !1).then(s=>{
+            if (!(s instanceof ArrayBuffer))
+                return LoadXObject(o, s).then(c=>c)
         }
+        )
     }
-    getParsedUrl(e, t, r, n="") {
-        return new Promise((o,a)=>{
-            if (!r || r.indexOf(".zip") === -1)
-                return o(r);
-            const s = this.rootPath.get(r);
-            if (s)
-                return o(s);
+    getParsedUrl(e, i, o, s="") {
+        return new Promise((c,d)=>{
+            if (!o || o.indexOf(".zip") === -1)
+                return c(o);
+            const _ = this.rootPath.get(o);
+            if (_)
+                return c(_);
             {
-                const l = ".zip"
-                  , u = r.replace(l, "") + COMPONENT_LIST_PREFIX;
-                e.urlTransformer(u, !0).then(c=>{
-                    if (!c)
-                        return a("Loading Failed");
-                    new Response(c).json().then(h=>{
-                        var _, g, m, v, y, b, T;
-                        const f = r.replace(l, "")
-                          , d = f + ((_ = h == null ? void 0 : h.components) == null ? void 0 : _.url.replace("./", ""));
-                        if (this.rootPath.set(r, d),
-                        h.components ? (h.components.url && this.mshPath.set(t, f + "/" + ((g = h == null ? void 0 : h.components) == null ? void 0 : g.url.replace("./", ""))),
-                        h.components.url_lod2 && this.mshPath.set(t + "_" + avatarSetting.lod[1].level, f + "/" + ((m = h == null ? void 0 : h.components) == null ? void 0 : m.url_lod2.replace("./", ""))),
-                        h.components.url_lod4 && this.mshPath.set(t + "_" + avatarSetting.lod[2].level, f + "/" + ((v = h == null ? void 0 : h.components) == null ? void 0 : v.url_lod4.replace("./", "")))) : (h.meshes.url && this.mshPath.set(t, f + "/" + ((y = h == null ? void 0 : h.meshes) == null ? void 0 : y.url.replace("./", ""))),
-                        h.meshes.url_lod2 && this.mshPath.set(t + "_" + avatarSetting.lod[1].level, f + "/" + ((b = h == null ? void 0 : h.meshes) == null ? void 0 : b.url_lod2.replace("./", ""))),
-                        h.meshes.url_lod4 && this.mshPath.set(t + "_" + avatarSetting.lod[2].level, f + "/" + ((T = h == null ? void 0 : h.meshes) == null ? void 0 : T.url_lod4.replace("./", "")))),
-                        h.materials && h.materials.forEach(C=>{
-                            const A = f + "/" + C.url;
-                            this.matPath.set(C.name, A)
+                const b = ".zip"
+                  , k = o.replace(b, "") + COMPONENT_LIST_PREFIX;
+                e.urlTransformer(k, !0).then(j=>{
+                    if (!j)
+                        return d("Loading Failed");
+                    new Response(j).json().then($=>{
+                        var tt, rt, it, nt, ot, at, st;
+                        const _e = o.replace(b, "")
+                          , et = _e + ((tt = $ == null ? void 0 : $.components) == null ? void 0 : tt.url.replace("./", ""));
+                        if (this.rootPath.set(o, et),
+                        $.components ? ($.components.url && this.mshPath.set(i, _e + "/" + ((rt = $ == null ? void 0 : $.components) == null ? void 0 : rt.url.replace("./", ""))),
+                        $.components.url_lod2 && this.mshPath.set(i + "_" + avatarSetting.lod[1].level, _e + "/" + ((it = $ == null ? void 0 : $.components) == null ? void 0 : it.url_lod2.replace("./", ""))),
+                        $.components.url_lod4 && this.mshPath.set(i + "_" + avatarSetting.lod[2].level, _e + "/" + ((nt = $ == null ? void 0 : $.components) == null ? void 0 : nt.url_lod4.replace("./", "")))) : ($.meshes.url && this.mshPath.set(i, _e + "/" + ((ot = $ == null ? void 0 : $.meshes) == null ? void 0 : ot.url.replace("./", ""))),
+                        $.meshes.url_lod2 && this.mshPath.set(i + "_" + avatarSetting.lod[1].level, _e + "/" + ((at = $ == null ? void 0 : $.meshes) == null ? void 0 : at.url_lod2.replace("./", ""))),
+                        $.meshes.url_lod4 && this.mshPath.set(i + "_" + avatarSetting.lod[2].level, _e + "/" + ((st = $ == null ? void 0 : $.meshes) == null ? void 0 : st.url_lod4.replace("./", "")))),
+                        $.materials && $.materials.forEach(ut=>{
+                            const ct = _e + "/" + ut.url;
+                            this.matPath.set(ut.name, ct)
                         }
                         ),
-                        h.bin) {
-                            const C = f + "/" + h.bin.url;
-                            this.binPath.set(t, C);
-                            const A = f + "/" + h.bin.url_lod2;
-                            this.binPath.set(t + "_" + avatarSetting.lod[1].level, A);
-                            const S = f + "/" + h.bin.url_lod4;
-                            this.binPath.set(t + "_" + avatarSetting.lod[2].level, S)
+                        $.bin) {
+                            const ut = _e + "/" + $.bin.url;
+                            this.binPath.set(i, ut);
+                            const ct = _e + "/" + $.bin.url_lod2;
+                            this.binPath.set(i + "_" + avatarSetting.lod[1].level, ct);
+                            const lt = _e + "/" + $.bin.url_lod4;
+                            this.binPath.set(i + "_" + avatarSetting.lod[2].level, lt)
                         }
-                        return h.textures && h.textures.forEach(C=>{
-                            const A = f + "/" + C.url;
-                            this.texPath.set(C.url, A);
-                            const S = this.meshTexList.get(h.components.url);
-                            C.type === "png" && (S ? S.find(P=>P === C.name) || S.push(C.url) : this.meshTexList.set(t, [C.name]))
+                        return $.textures && $.textures.forEach(ut=>{
+                            const ct = _e + "/" + ut.url;
+                            this.texPath.set(ut.url, ct);
+                            const lt = this.meshTexList.get($.components.url);
+                            ut.type === "png" && (lt ? lt.find(ft=>ft === ut.name) || lt.push(ut.url) : this.meshTexList.set(i, [ut.name]))
                         }
                         ),
-                        o(d)
+                        c(et)
                     }
-                    ).catch(h=>{
-                        logger.error(`[Engine] parse json file error,${h}`)
+                    ).catch($=>{
+                        d(`[Engine] parse json file error,${$}`)
                     }
                     )
                 }
-                ).catch(c=>{
-                    logger.error(`[Engine] ulrtransform error, cannot find resource in db,${c}`)
+                ).catch(j=>{
+                    d(`[Engine] ulrtransform error, cannot find resource in db,${j}`)
                 }
                 )
             }
         }
         )
     }
-    async parse(e, t) {
-        const r = [];
-        t.forEach(n=>{
-            this._setAnimationList(n.id, n.animations),
-            r.push(this.getParsedUrl(e, n.id, n.url)),
-            n.components.forEach(o=>{
-                o.units.forEach(a=>{
-                    r.push(this.getParsedUrl(e, a.name, a.url))
+    async parse(e, i) {
+        const o = [];
+        i.forEach(s=>{
+            this._setAnimationList(s.id, s.animations),
+            o.push(this.getParsedUrl(e, s.id, s.url)),
+            s.components.forEach(c=>{
+                c.name === "pendant" ? c.units.forEach(d=>{
+                    this._parsePendant(d.id, d.url)
+                }
+                ) : c.units.forEach(d=>{
+                    o.push(this.getParsedUrl(e, d.name, d.url))
                 }
                 )
             }
             )
         }
         ),
-        await Promise.all(r)
+        await Promise.all(o)
     }
-    _setAnimationList(e, t) {
-        t ? t.forEach(r=>{
-            this.aniPath.set(e + "_" + r.name, r.url)
+    _setAnimationList(e, i) {
+        i ? i.forEach(o=>{
+            this.aniPath.set(e + "_" + o.name, o.url)
         }
         ) : logger.error("[Engine] no animation list exist, please check config for details")
     }
     disposeContainer() {
-        this.containers.forEach((e,t)=>{
-            e.xReferenceCount < 1 && (this.enableShareTexture && e.textures.length > 0 && e.textures[0].xReferenceCount != null && (e.textures[0].xReferenceCount--,
-            e.textures = []),
-            e.dispose(),
-            this.containers.delete(t))
+        const e = [];
+        this.containers.forEach((i,o)=>{
+            if (i.xReferenceCount < 1) {
+                if (this.enableShareTexture && i.textures.length > 0) {
+                    for (let s = 0; s < i.textures.length; ++s)
+                        i.textures[s].xReferenceCount != null ? i.textures[s].xReferenceCount-- : i.textures[s].xReferenceCount = 0,
+                        i.textures[s]._parentContainer = null;
+                    i.textures = []
+                }
+                e.push(o)
+            }
         }
         ),
-        this._sharedTex.forEach((e,t)=>{
-            e.xReferenceCount == 0 && (e.dispose(),
-            this._sharedTex.delete(t))
+        e.forEach(i=>{
+            var o, s;
+            (o = this.containers.get(i)) == null || o.removeAllFromScene(),
+            (s = this.containers.get(i)) == null || s.dispose(),
+            this.containers.delete(i)
+        }
+        ),
+        this._sharedTex.forEach((i,o)=>{
+            i.xReferenceCount == 0 && (i.dispose(),
+            this._sharedTex.delete(o))
         }
         )
     }
@@ -133,175 +171,172 @@ export default class XAvatarLoader {
     getMeshUrl(e) {
         return this.mshPath.get(e)
     }
-    _getSourceKey(e, t) {
-        return t && avatarSetting.lod[t] ? e + avatarSetting.lod[t].fileName.split(".")[0] : e
+    _getSourceKey(e, i) {
+        return i && avatarSetting.lod[i] ? e + avatarSetting.lod[i].fileName.split(".")[0] : e
     }
-    _getAnimPath(e, t) {
-        let r = this.aniPath.get(t + "_animations_" + t.split("_")[1]);
-        return r || (r = this.aniPath.get(t + "_" + e)),
-        r
+    _getAnimPath(e, i) {
+        let o = this.aniPath.get(i + "_animations_" + i.split("_")[1]);
+        return o || (o = this.aniPath.get(i + "_" + e)),
+        o
     }
-    load(e, t, r, n) {
-        return new Promise((o,a)=>{
-            this.loadGlb(e, t, r).then(s=>s ? o(s) : a("[Engine] container load failed")).catch(()=>a("[Engine] container load failed"))
-        }
-        )
+    load(e, i, o, s) {
+        return this.loadGlb(e, i, o).then(c=>c || Promise.reject("[Engine] container load failed")).catch(()=>Promise.reject("[Engine] container load failed"))
     }
-    _searchAnimation(e, t) {
-        let r;
-        return this.containers.forEach((n,o)=>{
-            const a = t.split("_")[0];
-            o.indexOf(a) != -1 && o.indexOf(e) != -1 && (r = n)
+    _searchAnimation(e, i) {
+        let o;
+        return this.containers.forEach((s,c)=>{
+            const d = i.split("_")[0];
+            c.indexOf(d) != -1 && c.indexOf(e) != -1 && (o = s)
         }
         ),
-        r
+        o
     }
-    loadAnimRes(e, t, r) {
-        return new Promise((n,o)=>{
-            const a = this._getAnimPath(t, r)
-              , s = getAnimationKey(t, r);
-            if (a && this.containers.get(a))
-                return n(this.containers.get(a));
-            if (a)
-                this._loadGlbFromBlob(e, s, a).then(l=>l.animationGroups.length == 0 ? (this.containers.delete(s),
-                l.dispose(),
-                Promise.reject("container does not contains animation data")) : n(l));
-            else
-                return o("no such url")
-        }
-        )
+    loadAnimRes(e, i, o) {
+        const s = this._getAnimPath(i, o)
+          , c = getAnimationKey(i, o);
+        return s && this.containers.get(s) ? Promise.resolve(this.containers.get(s)) : s ? this._loadGlbFromBlob(e, c, s).then(d=>d.animationGroups.length == 0 ? (this.containers.delete(c),
+        d.dispose(),
+        Promise.reject("container does not contains animation data")) : d) : Promise.reject("no such url")
     }
-    loadGlb(e, t, r) {
-        let n = this.getMeshUrl(this._getSourceKey(t, r));
-        return !n && this.fillEmptyLod && (r = 0,
-        n = this.getMeshUrl(this._getSourceKey(t, r))),
-        n && this.containers.get(n) ? Promise.resolve(this.containers.get(n)) : n ? this._enableIdb ? Promise.resolve(this._loadGlbFromBlob(e, this._getSourceKey(t, r), n)) : Promise.resolve(this._loadGlbFromUrl(e, this._getSourceKey(t, r), n)) : Promise.reject("no such url")
+    loadGlb(e, i, o) {
+        let s = this.getMeshUrl(this._getSourceKey(i, o));
+        return !s && this.fillEmptyLod && (o = 0,
+        s = this.getMeshUrl(this._getSourceKey(i, o))),
+        s && this.containers.get(s) ? Promise.resolve(this.containers.get(s)) : s ? this._enableIdb ? this._loadGlbFromBlob(e, this._getSourceKey(i, o), s) : this._loadGlbFromUrl(e, this._getSourceKey(i, o), s) : Promise.reject("no such url")
     }
-    loadGltf(e, t, r, n) {
-        const o = this._getSourceKey(t, r || 0);
-        let a = this.getGltfPath(o);
-        return !a && this.fillEmptyLod && (a = this.getGltfPath(t)),
-        a && this.containers.get(a) ? Promise.resolve(this.containers.get(a)) : this._enableIdb ? this._loadGltfFromBlob(e, t, r, n) : a ? this._loadGltfFromUrl(e, t, a.replace(t + ".gltf", "")) : Promise.reject()
+    loadGltf(e, i, o, s) {
+        const c = this._getSourceKey(i, o || 0);
+        let d = this.getGltfPath(c);
+        return !d && this.fillEmptyLod && (d = this.getGltfPath(i)),
+        d && this.containers.get(d) ? Promise.resolve(this.containers.get(d)) : this._enableIdb ? this._loadGltfFromBlob(e, i, o, s) : d ? this._loadGltfFromUrl(e, i, d.replace(i + ".gltf", "")) : Promise.reject()
     }
     loadSubsequence() {}
     loadVAT() {}
     getResourceName(e) {
         return this.meshTexList.get(e)
     }
-    _loadGltfFromUrl(e, t, r) {
-        return BABYLON.SceneLoader.LoadAssetContainerAsync(r, t + ".gltf", e.Scene, null, ".gltf")
+    _loadGltfFromUrl(e, i, o) {
+        return BABYLON.SceneLoader.LoadAssetContainerAsync(o, i + ".gltf", e.Scene, null, ".gltf")
     }
-    _loadGlbFromBlob(e, t, r) {
-        return new Promise((n,o)=>{
-            e.urlTransformer(r).then(a=>{
-                BABYLON.SceneLoader.LoadAssetContainerAsync("", a, e.Scene, null, ".glb").then(s=>{
-                    if (s) {
-                        if (this.enableShareTexture && s.textures.length > 0) {
-                            const l = t.indexOf("_lod") != -1 ? t.slice(0, -5) : t
-                              , u = this._sharedTex.get(l);
-                            u ? (s.meshes[1].material._albedoTexture = u,
-                            s.textures.forEach(c=>{
-                                c.dispose()
+    _loadGlbFromBlob(e, i, o) {
+        return e.urlTransformer(o).then(s=>BABYLON.SceneLoader.LoadAssetContainerAsync("", s, e.Scene, null, ".glb").then(c=>{
+            if (c) {
+                if (this.containers.get(o))
+                    return c.dispose(),
+                    this.containers.get(o);
+                if (c.addAllToScene(),
+                this.enableShareTexture && c.textures.length > 0) {
+                    const d = [];
+                    let _ = !1;
+                    c.meshes.forEach(b=>{
+                        if (b.material) {
+                            const k = b.material._albedoTexture;
+                            if (k) {
+                                let j = k.name;
+                                j = j.replace(" (Base Color)", "").split(".")[0];
+                                const $ = this._sharedTex.get(j);
+                                $ ? (_ = !0,
+                                b.material._albedoTexture = $,
+                                d.push($),
+                                $._parentContainer = c,
+                                $.xReferenceCount++) : (this._sharedTex.set(j, k),
+                                c.textures[0].xReferenceCount = 1)
                             }
-                            ),
-                            s.textures = [u],
-                            u.xReferenceCount++) : (this._sharedTex.set(l, s.textures[0]),
-                            s.textures[0].xReferenceCount = 1)
-                        }
-                        return s.addAllToScene(),
-                        s.xReferenceCount = 0,
-                        s.meshes.forEach(l=>{
-                            l.setEnabled(!1)
                         }
-                        ),
-                        this.containers.set(r, s),
-                        n(s)
-                    } else
-                        o("glb file load failed")
-                }
-                )
-            }
-            )
-        }
-        )
-    }
-    _loadGlbFromUrl(e, t, r) {
-        return new Promise((n,o)=>{
-            BABYLON.SceneLoader.LoadAssetContainerAsync("", r, e.Scene, null, ".glb").then(a=>{
-                if (a) {
-                    if (a.addAllToScene(),
-                    a.meshes.forEach(s=>{
-                        s.setEnabled(!1)
                     }
                     ),
-                    this.enableShareTexture && a.textures.length > 0) {
-                        const s = t.indexOf("_lod") != -1 ? t.slice(0, -5) : t
-                          , l = this._sharedTex.get(s);
-                        l ? (a.meshes[1].material._albedoTexture = l,
-                        a.textures.forEach(u=>{
-                            u.dispose()
-                        }
-                        ),
-                        a.textures = [l],
-                        l.xReferenceCount++) : (this._sharedTex.set(s, a.textures[0]),
-                        a.textures[0].xReferenceCount = 1)
+                    _ && (c.textures.forEach(b=>{
+                        e.Scene.removeTexture(b),
+                        b.dispose()
                     }
-                    return a.xReferenceCount = 0,
-                    this.containers.set(r, a),
-                    n(a)
-                } else
-                    o("glb file load failed")
+                    ),
+                    c.textures = d)
+                }
+                return c.xReferenceCount = 0,
+                c.meshes.forEach(d=>{
+                    d.setEnabled(!1)
+                }
+                ),
+                this.containers.set(o, c),
+                Promise.resolve(c)
+            } else
+                return Promise.reject("glb file load failed")
+        }
+        ))
+    }
+    _loadGlbFromUrl(e, i, o) {
+        return BABYLON.SceneLoader.LoadAssetContainerAsync("", o, e.Scene, null, ".glb").then(s=>s ? (s.addAllToScene(),
+        s.meshes.forEach(c=>{
+            c.setEnabled(!1)
+        }
+        ),
+        this.enableShareTexture && s.textures.length > 0 ? (s.meshes.forEach(c=>{
+            if (c.material) {
+                const d = c.material._albedoTexture;
+                if (d) {
+                    let _ = d.name;
+                    _ = _.replace(" (Base Color)", "").split(".")[0];
+                    const b = this._sharedTex.get(_);
+                    b ? (c.material._albedoTexture = b,
+                    b.xReferenceCount++) : (this._sharedTex.set(_, d),
+                    s.textures[0].xReferenceCount = 1)
+                }
             }
-            )
         }
-        )
+        ),
+        s.xReferenceCount = 0,
+        this.containers.set(o, s),
+        Promise.resolve(s)) : Promise.reject("glb file load failed"),
+        s.xReferenceCount = 0,
+        this.containers.set(o, s),
+        Promise.resolve(s)) : Promise.reject("glb file load failed"))
     }
-    _loadGltfFromBlob(e, t, r, n) {
-        return new Promise((o,a)=>{
-            const s = [];
-            let l = this._getSourceKey(t, r)
-              , u = this.getGltfPath(l);
-            if (!u && this.fillEmptyLod && (r = 0,
-            l = this._getSourceKey(t, r),
-            u = this.getGltfPath(l)),
-            !u)
-                return a(`[Engine] gltf path incorrect ${l},cancel.`);
-            const c = this.mshPath.get(l + ".gltf");
-            if (!c)
-                return a("cannot find asset mshPath");
-            const h = this.binPath.get(l + ".bin");
-            if (!h)
-                return a("cannot find asset binPath");
-            if (!n) {
-                const _ = this.meshTexList.get(t);
-                if (!_ || _.length == 0)
-                    return a("cannot find texture");
-                n = _[0]
+    _loadGltfFromBlob(e, i, o, s) {
+        return new Promise((c,d)=>{
+            const _ = [];
+            let b = this._getSourceKey(i, o)
+              , k = this.getGltfPath(b);
+            if (!k && this.fillEmptyLod && (o = 0,
+            b = this._getSourceKey(i, o),
+            k = this.getGltfPath(b)),
+            !k)
+                return d(`[Engine] gltf path incorrect ${b},cancel.`);
+            const j = this.mshPath.get(b + ".gltf");
+            if (!j)
+                return d("cannot find asset mshPath");
+            const $ = this.binPath.get(b + ".bin");
+            if (!$)
+                return d("cannot find asset binPath");
+            if (!s) {
+                const tt = this.meshTexList.get(i);
+                if (!tt || tt.length == 0)
+                    return d("cannot find texture");
+                s = tt[0]
             }
-            const f = this.texPath.get(n + ".png");
-            if (!f)
-                return a();
-            const d = this.texPath.get(n + "-astc.ktx");
-            if (!d)
-                return a();
-            s.push(this._blobMapping(e, c)),
-            s.push(this._blobMapping(e, h)),
-            s.push(this._blobMapping(e, f)),
-            s.push(this._blobMapping(e, d)),
-            Promise.all(s).then(()=>{
-                const _ = u.replace(l + ".gltf", "");
-                BABYLON.SceneLoader.LoadAssetContainerAsync(_, l + ".gltf", e.Scene, null, ".gltf").then(g=>{
-                    var v;
-                    this.containers.set(u, g),
-                    g.addAllToScene(),
-                    g.meshes.forEach(y=>{
-                        y.setEnabled(!1)
+            const _e = this.texPath.get(s + ".png");
+            if (!_e)
+                return d();
+            const et = this.texPath.get(s + "-astc.ktx");
+            if (!et)
+                return d();
+            _.push(this._blobMapping(e, j)),
+            _.push(this._blobMapping(e, $)),
+            _.push(this._blobMapping(e, _e)),
+            _.push(this._blobMapping(e, et)),
+            Promise.all(_).then(()=>{
+                const tt = k.replace(b + ".gltf", "");
+                BABYLON.SceneLoader.LoadAssetContainerAsync(tt, b + ".gltf", e.Scene, null, ".gltf").then(rt=>{
+                    var nt;
+                    this.containers.set(k, rt),
+                    rt.addAllToScene(),
+                    rt.meshes.forEach(ot=>{
+                        ot.setEnabled(!1)
                     }
                     );
-                    const m = this._sharedTex.get(t);
-                    m ? ((v = g.meshes[1].material._albedoTexture) == null || v.dispose(),
-                    g.meshes[1].material._albedoTexture = m) : this._sharedTex.set(t, g.meshes[1].material._albedoTexture),
-                    o(g)
+                    const it = this._sharedTex.get(i);
+                    it ? ((nt = rt.meshes[1].material._albedoTexture) == null || nt.dispose(),
+                    rt.meshes[1].material._albedoTexture = it) : this._sharedTex.set(i, rt.meshes[1].material._albedoTexture),
+                    c(rt)
                 }
                 )
             }
@@ -309,10 +344,10 @@ export default class XAvatarLoader {
         }
         )
     }
-    _blobMapping(e, t) {
-        return new Promise((r,n)=>{
-            e.urlTransformer(t).then(o=>o ? (this._mappings.set(t, o),
-            r(t)) : n(`[Engine] url urlTransformer parse error ${t}`))
+    _blobMapping(e, i) {
+        return new Promise((o,s)=>{
+            e.urlTransformer(i).then(c=>c ? (this._mappings.set(i, c),
+            o(i)) : s(`[Engine] url urlTransformer parse error ${i}`))
         }
         )
     }

+ 0 - 222
src/XSequence.js

@@ -1,222 +0,0 @@
-import {http2} from "./Http2.js"
-import XSubSequence from "./XSubSequence.js"
-
-const DefaultUrlTransformer = async i=>typeof i != "string" ? (console.warn("url transformer error", i),
-i) : i.startsWith("blob:") ? i : http2.get({
-    url: i,
-    useIndexedDb: !0,
-    key: "url"
-});
-
-export default class XSequence {
-    constructor(e, t, r="test", n=DefaultUrlTransformer) {
-        E(this, "_scene");
-        E(this, "_name");
-        E(this, "_subSeqs");
-        E(this, "_animGroup");
-        E(this, "_targetSubSeqs");
-        E(this, "_abosoluteUrl");
-        E(this, "_rootDir");
-        E(this, "urlTransformer");
-        E(this, "init", async()=>new Promise(e=>{
-            this.urlTransformer(this._abosoluteUrl).then(t=>{
-                const r = new XMLHttpRequest;
-                r.open("get", t),
-                r.send(null),
-                r.onload = ()=>{
-                    if (r.status == 200) {
-                        const n = JSON.parse(r.responseText);
-                        this.load(n).then(()=>{
-                            e()
-                        }
-                        )
-                    }
-                }
-            }
-            )
-        }
-        ));
-        E(this, "getRootOfSubSeqs", ()=>{
-            const e = new Array;
-            return this._subSeqs.forEach(t=>{
-                e.push(t.root)
-            }
-            ),
-            e
-        }
-        );
-        E(this, "play", async(e=!0)=>new Promise(t=>{
-            this._animGroup.play(e),
-            e ? this._animGroup.onAnimationGroupLoopObservable.addOnce(()=>{
-                t()
-            }
-            ) : this._animGroup.onAnimationGroupEndObservable.addOnce(()=>{
-                t()
-            }
-            )
-        }
-        ));
-        E(this, "goToFrame", e=>{
-            this._animGroup.goToFrame(e)
-        }
-        );
-        E(this, "hide", ()=>{
-            this._subSeqs.forEach(e=>{
-                e.hide()
-            }
-            )
-        }
-        );
-        E(this, "show", ()=>{
-            this._subSeqs.forEach(e=>{
-                e.show()
-            }
-            )
-        }
-        );
-        E(this, "pause", ()=>{
-            this._animGroup.pause()
-        }
-        );
-        E(this, "reset", ()=>{
-            this._animGroup.reset()
-        }
-        );
-        this._scene = e,
-        this._abosoluteUrl = t,
-        this._rootDir = t.split("/").slice(0, -1).join("/") + "/",
-        this._name = r,
-        this._subSeqs = new Map,
-        this._animGroup = new BABYLON.AnimationGroup("Seq_" + r,e),
-        this._targetSubSeqs = new Map,
-        this._animGroup.onAnimationGroupPlayObservable.add(()=>{
-            this._subSeqs.forEach(o=>{
-                o.show()
-            }
-            )
-        }
-        ),
-        this._animGroup.onAnimationGroupEndObservable.add(()=>{
-            this._subSeqs.forEach(o=>{
-                o.hide()
-            }
-            )
-        }
-        ),
-        this.urlTransformer = n
-    }
-    get animGroup() {
-        return this._animGroup
-    }
-    serialize() {
-        const e = {};
-        return e.SubSequence = new Array,
-        e.TimeLine = new Array,
-        this._subSeqs.forEach(t=>{
-            const r = {
-                name: t.name,
-                uri: t.path
-            };
-            e.SubSequence.push(r);
-            const n = this._targetSubSeqs.get(t);
-            n && e.TimeLine.push({
-                frame: n == null ? void 0 : n.frame,
-                position: n.position,
-                rotation: n.rotation,
-                scaling: n.scaling,
-                name: t.name
-            })
-        }
-        ),
-        e
-    }
-    get isPlaying() {
-        return this._animGroup.isPlaying
-    }
-    get isStarted() {
-        return this._animGroup.isStarted
-    }
-    get loaded() {
-        let e = !0;
-        return this._subSeqs.forEach(t=>{
-            e = e && t.loaded
-        }
-        ),
-        e
-    }
-    dispose() {
-        this._subSeqs.forEach(e=>{
-            e.dispose()
-        }
-        ),
-        this.animGroup.dispose()
-    }
-    setFrame(e, t) {
-        const r = this._subSeqs.get(e);
-        if (r) {
-            const n = this._targetSubSeqs.get(r);
-            n && (n.frame = t),
-            n && this.update(r, n)
-        }
-    }
-    get name() {
-        return this._name
-    }
-    update(e, t) {
-        if (t) {
-            const r = {
-                frame: t.frame,
-                scaling: new BABYLON.Vector3(t.scaling[0],t.scaling[1],t.scaling[2]),
-                position: new BABYLON.Vector3(t.position[0],t.position[1],t.position[2]),
-                rotation: new BABYLON.Vector3(t.rotation[0] / 180 * Math.PI,t.rotation[1] / 180 * Math.PI,t.rotation[2] / 180 * Math.PI),
-                name: t.name
-            }
-              , n = this._subSeqs.get(r.name);
-            n && (n.setPositionVector(r.position),
-            n.setRotationVector(r.rotation),
-            n.setScalingVector(r.scaling),
-            n.setStartFrame(r.frame),
-            this._targetSubSeqs.set(n, t),
-            n.onSubSequenceTransformationChangeObservable.add(()=>{
-                const o = this._targetSubSeqs.get(n);
-                o && (o.position = [n.pos.x, n.pos.y, n.pos.z]),
-                o && (o.rotation = [n.rot.x, n.rot.y, n.rot.z]),
-                o && (o.scaling = [n.scal.x, n.scal.y, n.scal.z])
-            }
-            ))
-        }
-    }
-    load(e) {
-        return new Promise((t,r)=>{
-            const n = new Array
-              , o = e.SubSequence
-              , a = e.TimeLine;
-            for (const s of o) {
-                s.uri.indexOf("./") == 0 && (s.uri = s.uri.slice(2));
-                const l = new XSubSequence(this._scene,this._rootDir + s.uri,this.urlTransformer);
-                this._subSeqs.set(s.name, l),
-                n.push(l.init())
-            }
-            Promise.all(n).then(()=>{
-                a.forEach(s=>{
-                    const l = this._subSeqs.get(s.name);
-                    l && this.update(l, s)
-                }
-                ),
-                this._subSeqs.forEach(s=>{
-                    s.animGroup.targetedAnimations.forEach(l=>{
-                        this._animGroup.addTargetedAnimation(l.animation, l.target)
-                    }
-                    )
-                }
-                ),
-                t()
-            }
-            , ()=>{
-                r()
-            }
-            )
-        }
-        )
-    }
-}

+ 0 - 91
src/XverseEffect.js

@@ -1,91 +0,0 @@
-//const log$8 = new Logger("effectManager");
-import TimeoutError from "./error/TimeoutError.js"
-
-export default class XverseEffect extends EventEmitter {
-    constructor({id: e, jsonPath: t, type: r, room: n, scale: o=1}) {
-        super();
-        E(this, "_id");
-        E(this, "type");
-        E(this, "effect");
-        E(this, "avatarEffect");
-        E(this, "_room");
-        E(this, "_isLoading", !0);
-        E(this, "_failed", !1);
-        E(this, "_scale", 1);
-        this._room = n,
-        this._id = e,
-        this.type = r,
-        this._scale = o,
-        this.effect = e === "Rain" || e === "Boom" ? new XRain(this._room.scene,t,urlTransformer) : r === IEffectType.Sequence ? new XSequence(this._room.scene,t,"",urlTransformer) : new XSubSequence(this._room.scene,t,urlTransformer),
-        this.avatarEffect = new XSubSequence(this._room.scene,t,urlTransformer)
-    }
-    get failed() {
-        return this._failed
-    }
-    get position() {
-        if (this.type !== IEffectType.Sequence)
-            return this.effect.position
-    }
-    get rotation() {
-        if (this.type !== IEffectType.Sequence)
-            return this.effect.rotation
-    }
-    get isLoading() {
-        return this._isLoading
-    }
-    get id() {
-        return this._id
-    }
-    get name() {
-        return this.effect.name
-    }
-    get isPlaying() {
-        var e;
-        return !!((e = this.effect) != null && e.isPlaying)
-    }
-    async init() {
-        try {
-            await this.effect.init()._timeout(1e4, new TimeoutError("effect init timeout(10s)")),
-            this._isLoading = !1,
-            this._failed = !1
-        } catch (e) {
-            throw this._isLoading = !1,
-            this._failed = !0,
-            log$8.error(`effect: ${this.id} init error`, e),
-            e
-        }
-    }
-    play(e=!1) {
-        return new Promise((t,r)=>{
-            this.effect.play(e),
-            this.isPlaying ? t() : r(`play effect: ${this.name} failed`)
-        }
-        )
-    }
-    hide() {
-        return this.effect.hide()
-    }
-    show() {
-        return this.effect.show()
-    }
-    setRotation(e) {
-        var t;
-        return this.type === IEffectType.Sequence ? Promise.reject("setRotation failed, sequence unSuported") : (t = this.effect) == null ? void 0 : t.setRotation(e)
-    }
-    setPosition(e) {
-        var t;
-        return this.type === IEffectType.Sequence ? Promise.reject("setPosition failed, sequence unSuported") : (t = this.effect) == null ? void 0 : t.setPosition(e)
-    }
-    setScaling(e) {
-        var t;
-        return this.type === IEffectType.Sequence ? Promise.reject("setScaling failed, sequence unSuported") : (this._scale = e,
-        (t = this.effect) == null ? void 0 : t.setScaling({
-            x: e,
-            y: e,
-            z: e
-        }))
-    }
-    dispose() {
-        this.effect.dispose()
-    }
-}