瀏覽代碼

add error

zhouenguang 3 年之前
父節點
當前提交
b40b910bdb

+ 2 - 0
src/ActionsHandler.js

@@ -5,6 +5,8 @@ import Person from "./enum/Person.js"
 import ClickType from "./enum/ClickType.js"
 import Logger from "./Logger.js"
 import MessageHandleType from "./enum/MessageHandleType.js"
+import FrequencyLimitError from "./error/FrequencyLimitError.js"
+import ParamError from "./error/ParamError.js"
 
 const logger = new Logger('actions-handler')
 const QueueActions = [Actions.Transfer, Actions.ChangeSkin, Actions.GetOnVehicle, Actions.GetOffVehicle];

+ 10 - 17
src/Camera.js

@@ -72,37 +72,30 @@ export default class Camera extends EventEmitter {
     */
 
     handleRenderInfo(e) {
-        const {cameraStateType: cameraStateType} = e.renderInfo;
+        const {cameraStateType} = e.renderInfo;
         const sceneManager = this._room.sceneManager;
 
-        if(cameraStateType !== this._state){
+        if(cameraStateType !== this._state) {
             this._state = cameraStateType;
             logger.debug("camera._state changed to", CameraStates[cameraStateType]);
-            if(cameraStateType === CameraStates.CGView){
+            
+            if(cameraStateType === CameraStates.CGView) {
                 sceneManager.cameraComponent.switchToCgCamera();
                 sceneManager.staticmeshComponent.getCgMesh().show();
-            }
-            else{
+            } else {
                 sceneManager.cameraComponent.switchToMainCamera();
                 sceneManager.staticmeshComponent.getCgMesh().hide();
             }
 
-            this.emit("stateChanged", {
-                state: cameraStateType
-            })
+            this.emit("stateChanged", { state: cameraStateType })
         }
         
-        if(this._room.isHost)
-        {
-            return;
-        }
+        if(this._room.isHost) return;
 
-        const {isFollowHost: isFollowHost} = e.playerState;
-        if(!!isFollowHost !== this._cameraFollowing){
+        const {isFollowHost} = e.playerState;
+        if(!!isFollowHost !== this._cameraFollowing) {
             this._cameraFollowing = !!isFollowHost;
-            this.emit("cameraFollowingChanged", {
-                cameraFollowing: !!isFollowHost
-            })
+            this.emit("cameraFollowingChanged", { cameraFollowing: !!isFollowHost })
         }
     }
     /*

+ 2 - 1
src/EventsManager.js

@@ -2,6 +2,7 @@ import Actions from "./enum/Actions.js"
 import Codes from "./enum/Codes.js"
 import util from "./util.js"
 import Logger from "./Logger.js"
+import ActionResponseTimeoutError from "./error/ActionResponseTimeoutError.js"
 
 const logger = new Logger('events')
 export default class EventsManager extends EventEmitter {
@@ -84,7 +85,7 @@ export default class EventsManager extends EventEmitter {
             {
                 if (c && clearTimeout(c), !this.events.get(traceId)) return;
 
-                const error = new ActionResponseTimeoutError(`${s} timeout in ${d}ms`);
+                const error = new ActionResponseTimeoutError(`${s} timeout in ${time}ms`);
                 this.emit("actionResponseTimeout", { error, event: e, tag }),
                 reject(error),
                 this.events.delete(traceId),

+ 1 - 0
src/ModelManager.js

@@ -1,6 +1,7 @@
 import {http1} from "./Http1.js"
 import util from "./util.js"
 import Logger from "./Logger.js"
+import ParamError from "./error/ParamError.js"
 
 const logger = new Logger('model-manager')
 export default class ModelManager{

+ 2 - 0
src/Preload.js

@@ -5,6 +5,8 @@ import {http1} from "./Http1.js"
 import InternalError from "./error/InternalError.js"
 import axios from "axios";
 import Logger from "./Logger.js"
+import PreloadCanceledError from "./error/PreloadCanceledError.js"
+import ParamError from "./error/ParamError.js"
 
 const logger = new Logger('preload')
 export default class Preload {

+ 2 - 1
src/Signal.js

@@ -131,13 +131,14 @@ export default class Signal {
                 this._room.pathManager.currentAttitude = attitude, 
                 this._room._userAvatar && (this._room._userAvatar.motionType = attitude)
             }
-            // 更新相机数据
+            // 更新相机数据(只更新position和angle,cameraCenter不使用)
             this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano 
             && !this._room.isPano 
             && mainUserState.playerState.camera 
             && !this._room.panorama.isLoading 
             && this._room.camera.setCameraPose(mainUserState.playerState.camera)
         }
+        // 切换相机 main/cg
         mainUserState != null && mainUserState.renderInfo && this._room.camera.handleRenderInfo(mainUserState);
 
         const time6 = Date.now();

+ 54 - 41
src/XAnimationController.js

@@ -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
     }

+ 19 - 5
src/XAvatarLoader.js

@@ -209,15 +209,29 @@ export default class XAvatarLoader {
     }
     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")
+        !s && this.fillEmptyLod && (
+            o = 0,
+            s = this.getMeshUrl(this._getSourceKey(i, o))
+        )
+        return 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, 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()
+        !d && this.fillEmptyLod && (d = this.getGltfPath(i))
+        return 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() {}

+ 6 - 2
src/XAvatarManager.js

@@ -3,6 +3,11 @@ import BillboardStatus from "./enum/BillboardStatus.js"
 import {avatarLoader} from "./XAvatarLoader.js"
 import XAvatar from "./XAvatar.js"
 import Logger from "./Logger.js"
+import ExceedMaxAvatarNumError from "./Error/ExceedMaxAvatarNumError"
+import DuplicateAvatarIDError from "./Error/DuplicateAvatarIDError"
+import AvatarAssetLoadingError from "./Error/AvatarAssetLoadingError"
+import ContainerLoadingFailedError from "./Error/ContainerLoadingFailedError"
+import AvatarAnimationError from "./error/AvatarAnimationError"
 
 const logger = new Logger('AvatarManager')
 export default class XAvatarManager {
@@ -167,8 +172,7 @@ export default class XAvatarManager {
             if (this.getAvatarById(id))
                 return reject(new DuplicateAvatarIDError(`[Engine] cannot init avatar with the same id = ${e}`));
             if (this.getAvatarNums() > this.maxAvatarNum)
-                return reject(`[Engine] \u8D85\u51FA\u6700\u5927\u89D2\u8272\u9650\u5236 ${this.maxAvatarNum}`);
-                // return reject(new ExceedMaxAvatarNumError(`[Engine] \u8D85\u51FA\u6700\u5927\u89D2\u8272\u9650\u5236 ${this.maxAvatarNum}`));
+                return reject(new ExceedMaxAvatarNumError(`[Engine] \u8D85\u51FA\u6700\u5927\u89D2\u8272\u9650\u5236 ${this.maxAvatarNum}`));
 
             const avatar = new XAvatar({ id, avatarType, priority, avatarManager, assets, status });
             this.registerAvatar(avatar);

+ 1 - 0
src/XBreathPointManager.js

@@ -2,6 +2,7 @@ import XStaticMesh from "./XStaticMesh.js"
 import EMeshType from "./enum/EMeshType.js"
 import BreathPoint from "./BreathPoint.js"
 import Logger from "./Logger.js"
+import XBreathPointError from "./Error/XBreathPointError.js"
 
 const logger = new Logger('XBreathPointManager')
 export default class XBreathPointManager {

+ 1 - 0
src/XMaterialComponent.js

@@ -1,5 +1,6 @@
 import XVideoRawYUV from "./XVideoRawYUV";
 import Logger from "./Logger.js";
+import XMaterialError from "./Error/XMaterialError";
 
 const logger = new Logger("XMaterial");
 export default class XMaterialComponent {

+ 1 - 0
src/XStaticMeshComponent.js

@@ -3,6 +3,7 @@ import EMeshType from "./enum/EMeshType.js"
 import XStaticMeshFromOneGltf from "./XStaticMeshFromOneGltf.js"
 import XLowpolyModelError from "./error/XLowpolyModelError.js"
 import Logger from "./Logger.js"
+import XLowpolyJsonError from "./Error/XLowpolyJsonError.js"
 
 const logger = new Logger('XStaticMeshComponent')
 export default class XStaticMeshComponent{