zhouenguang 3 年之前
父节点
当前提交
03408ccd55
共有 10 个文件被更改,包括 164 次插入206 次删除
  1. 18 15
      dist/index.html
  2. 2 2
      src/EventsManager.js
  3. 0 5
      src/XAvatar.js
  4. 5 7
      src/XAvatarManager.js
  5. 129 133
      src/XCameraComponent.js
  6. 0 8
      src/XMaterialComponent.js
  7. 1 19
      src/XSceneManager.js
  8. 1 7
      src/XverseAvatar.js
  9. 6 8
      src/XverseAvatarManager.js
  10. 2 2
      src/main.js

+ 18 - 15
dist/index.html

@@ -260,21 +260,24 @@
 
     var E = (i,e,t)=>(Se(i, typeof e != "symbol" ? e + "" : e, t),t);
 
-    Promise.prototype._timeout = function(i, e) {
-        let t;
-        return new Promise((r,n)=>(t = window.setTimeout(()=>{
-            n(e)
-        }
-        , i),
-        this.then(o=>{
-            clearTimeout(t),
-            r(o)
-        }
-        , o=>{
-            clearTimeout(t),
-            n(o)
-        }
-        )))
+    // 自定义Promise超时
+    Promise.prototype._timeout = function(timeLimit, e) {
+        let handle;
+        return new Promise((resolve, reject) => (
+            handle = window.setTimeout(()=>{
+                reject(e)
+            }, timeLimit),
+            this.then(
+                o=>{
+                    clearTimeout(handle),
+                    resolve(o)
+                }, 
+                o=>{
+                    clearTimeout(handle),
+                    reject(o)
+                }
+            )
+        ))
     };
 
     function toast(i, e) {

+ 2 - 2
src/EventsManager.js

@@ -7,8 +7,8 @@ const logger = new Logger('events')
 export default class EventsManager extends EventEmitter {
     constructor() {
         super(...arguments);
-        E(this, "events", new Map);
-        E(this, "specialEvents", new Map)
+        this.events = new Map
+        this.specialEvents = new Map
     }
 
     remove(traceId, code, signal, needDelete) 

+ 0 - 5
src/XAvatar.js

@@ -12,24 +12,19 @@ const castRayTeleportationOffset = 10;
 
 export default class XAvatar {
     constructor({id, avatarType, priority, avatarManager, assets, status}) {
-        this.id = "-1",
-        this.priority = 0,
         this.isRender = !1,
         this.distLevel = 0,
         this.isInLoadingList = !1,
         this.isHide = !1,
-        this.clothesList = [],
         this.isSelected = !1,
         this.pendingLod = !1,
         this._previousReceivedPosition = new BABYLON.Vector3(0,1e4,0),
-        this.rootNode = void 0,
         this.distToCam = 1e11,
         this.enableNickname = !0,
         this.distance = 1e11,
         this.isCulling = !1,
         this.reslevel = 0,
         this.isInLoadingQueue = !1,
-        this._scene = void 0,
         this._transparent = 0,
 
 

+ 5 - 7
src/XAvatarManager.js

@@ -6,7 +6,7 @@ import Logger from "./Logger.js"
 
 const logger = new Logger('AvatarManager')
 export default class XAvatarManager {
-    constructor(e) {
+    constructor(sceneManager) {
         this.characterMap = new Map
         this.curAnimList = []
         this.extraComps = new Map
@@ -35,8 +35,8 @@ export default class XAvatarManager {
         this._tickDispose = 0
         this._disposeTime = 100
         this.avatarLoader = avatarLoader
-        this._scene = e.mainScene;
-        this._sceneManager = e;
+        this._scene = sceneManager.mainScene;
+        this._sceneManager = sceneManager;
         this.initAvatarMap();
         this._initSettings();
         this._maxDistRange = this._distLevels[this._distLevels.length - 1],
@@ -45,10 +45,8 @@ export default class XAvatarManager {
         let t = 0;
         this._tickObserver = this._scene.onAfterRenderObservable.add(()=>{
             t += 1,
-            t == this._tickInterval && (this.tick(),
-            t = 0)
-        }
-        )
+            t == this._tickInterval && (this.tick(), t = 0)
+        })
     }
     tick() {
         this.bboxMeshPool.clean(0)

+ 129 - 133
src/XCameraComponent.js

@@ -1,142 +1,138 @@
 export default class XCameraComponent {
-    constructor(e, t, r) {
-        E(this, "maincameraRotLimitObserver", null);
-        E(this, "mainCamera");
-        E(this, "cgCamera");
-        E(this, "saveCameraPose");
-        E(this, "_cameraPose");
-        E(this, "scene");
-        E(this, "canvas");
-        E(this, "yuvInfo");
-        E(this, "forceKeepVertical", !1);
-        E(this, "initCamera", e=>{
-            const {maxZ: t=1e4, minZ: r=.1, angularSensibility: n=2e3} = e;
-            this.mainCamera = new BABYLON.FreeCamera("camera_main",new BABYLON.Vector3(0,0,1),this.scene),
-            this.mainCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
-            this.mainCamera.speed = .1,
-            this.mainCamera.angularSensibility = n,
-            this.mainCamera.setTarget(new BABYLON.Vector3(0,0,0)),
-            this.mainCamera.minZ = r,
-            this.mainCamera.fov = Math.PI * this.yuvInfo.fov / 180,
-            this.mainCamera.maxZ = t,
-            this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
-            this.cgCamera = new BABYLON.FreeCamera("camera_temp",new BABYLON.Vector3(0,1e3,0),this.scene),
-            this.cgCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
-            this.cgCamera.speed = .1,
-            this.cgCamera.setTarget(new BABYLON.Vector3(0,1010,0)),
-            this.cgCamera.maxZ = t,
-            this.cgCamera.minZ = r,
-            this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
-            this.cameraFovChange(this.yuvInfo)
-        }
-        );
-        E(this, "cameraFovChange", e=>{
-            this.yuvInfo = e;
-            const t = e.width
-              , r = e.height
-              , n = this.canvas.width
-              , o = this.canvas.height
-              , a = e.fov;
-            if (this.forceKeepVertical == !0) {
-                const s = t / (2 * Math.tan(Math.PI * a / 360))
-                  , l = 2 * Math.atan(r / (2 * s));
-                this.mainCamera.fov = l,
-                this.cgCamera.fov = l,
-                this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED,
-                this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED
-            } else if (this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
-            this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
-            n / o < t / r && this.mainCamera.fov) {
-                const s = o
-                  , l = n
-                  , u = s * t / r / (2 * Math.tan(a * Math.PI / 360))
-                  , c = 2 * Math.atan(l / (2 * u));
-                this.mainCamera.fov = c,
-                this.cgCamera.fov = c
-            } else
-                this.mainCamera.fov = Math.PI * a / 180,
-                this.cgCamera.fov = Math.PI * a / 180
-        }
-        );
-        E(this, "setCameraPose", e=>{
-            var n;
-            const t = ue4Position2Xverse(e.position);
-            let r = null;
-            e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)),
-            this._cameraPose = {
-                position: t
-            },
-            r != null && (this._cameraPose.rotation = r),
-            this.scene.activeCamera === this.mainCamera && !((n = this.mainCamera) != null && n.isDisposed()) && this._setCamPositionRotation(this.mainCamera, this._cameraPose)
-        }
-        );
-        E(this, "_setCamPositionRotation", (e,t)=>{
-            var r, n;
-            t.position && (e.position = (r = t.position) == null ? void 0 : r.clone()),
-            t.rotation && (e.rotation = (n = t.rotation) == null ? void 0 : n.clone())
-        }
-        );
-        E(this, "switchCamera", e=>{
-            var t;
-            (t = this.scene.activeCamera) == null || t.detachControl(this.canvas),
-            this.scene.activeCamera = e
-        }
-        );
-        E(this, "reCalXYZRot", (e,t)=>(e = e % (2 * Math.PI),
+    constructor(canvas, scene, r) {
+        this.maincameraRotLimitObserver = null
+        this.mainCamera
+        this.cgCamera
+        this.saveCameraPose
+        this._cameraPose
+        this.forceKeepVertical = !1
+
+        this.scene = scene,
+        this.canvas = canvas,
+        this.yuvInfo = r.yuvInfo,
+        r.forceKeepVertical != null && (this.forceKeepVertical = r.forceKeepVertical),
+        this.initCamera(r.cameraParam)
+    }
+    
+    initCamera = cameraParam=>{
+        const {maxZ: t=1e4, minZ: r=.1, angularSensibility: n=2e3} = cameraParam;
+        this.mainCamera = new BABYLON.FreeCamera("camera_main",new BABYLON.Vector3(0,0,1),this.scene),
+        this.mainCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
+        this.mainCamera.speed = .1,
+        this.mainCamera.angularSensibility = n,
+        this.mainCamera.setTarget(new BABYLON.Vector3(0,0,0)),
+        this.mainCamera.minZ = r,
+        this.mainCamera.fov = Math.PI * this.yuvInfo.fov / 180,
+        this.mainCamera.maxZ = t,
+        this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
+        this.cgCamera = new BABYLON.FreeCamera("camera_temp",new BABYLON.Vector3(0,1e3,0),this.scene),
+        this.cgCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
+        this.cgCamera.speed = .1,
+        this.cgCamera.setTarget(new BABYLON.Vector3(0,1010,0)),
+        this.cgCamera.maxZ = t,
+        this.cgCamera.minZ = r,
+        this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
+        this.cameraFovChange(this.yuvInfo)
+    }
+    cameraFovChange = e=>{
+        this.yuvInfo = e;
+        const t = e.width
+          , r = e.height
+          , n = this.canvas.width
+          , o = this.canvas.height
+          , a = e.fov;
+        if (this.forceKeepVertical == !0) {
+            const s = t / (2 * Math.tan(Math.PI * a / 360))
+              , l = 2 * Math.atan(r / (2 * s));
+            this.mainCamera.fov = l,
+            this.cgCamera.fov = l,
+            this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED,
+            this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED
+        } else if (this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
+        this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
+        n / o < t / r && this.mainCamera.fov) {
+            const s = o
+              , l = n
+              , u = s * t / r / (2 * Math.tan(a * Math.PI / 360))
+              , c = 2 * Math.atan(l / (2 * u));
+            this.mainCamera.fov = c,
+            this.cgCamera.fov = c
+        } else
+            this.mainCamera.fov = Math.PI * a / 180,
+            this.cgCamera.fov = Math.PI * a / 180
+    }
+    setCameraPose = e=>{
+        var n;
+        const t = ue4Position2Xverse(e.position);
+        let r = null;
+        e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)),
+        this._cameraPose = {
+            position: t
+        },
+        r != null && (this._cameraPose.rotation = r),
+        this.scene.activeCamera === this.mainCamera && !((n = this.mainCamera) != null && n.isDisposed()) && this._setCamPositionRotation(this.mainCamera, this._cameraPose)
+    }
+    _setCamPositionRotation = (e,t)=>{
+        var r, n;
+        t.position && (e.position = (r = t.position) == null ? void 0 : r.clone()),
+        t.rotation && (e.rotation = (n = t.rotation) == null ? void 0 : n.clone())
+    }
+    switchCamera = e=>{
+        var t;
+        (t = this.scene.activeCamera) == null || t.detachControl(this.canvas),
+        this.scene.activeCamera = e
+    }
+    reCalXYZRot = (e,t)=>(
+        e = e % (2 * Math.PI),
         Math.abs(t - e) >= Math.PI && (e = e - 2 * Math.PI),
-        e));
-        E(this, "_moveCam", (e,t,r,n,o,a,s,l)=>{
-            const u = (v,y,b)=>(v.x = this.reCalXYZRot(v.x, y.x),
-            v.y = this.reCalXYZRot(v.y, y.y),
-            v.z = this.reCalXYZRot(v.z, y.z),
-            new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z))
-              , c = function(v, y, b) {
-                return new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z)
-            }
-              , h = new Animation("myAnimation1","position",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
-            let f = []
-              , d = t
-              , _ = r;
-            for (let v = 0; v < a; ++v)
-                f.push({
-                    frame: v,
-                    value: c(d, _, v / a)
-                });
+        e
+    )
+    _moveCam = (e,t,r,n,o,a,s,l)=>{
+        const u = (v,y,b)=>(v.x = this.reCalXYZRot(v.x, y.x),
+        v.y = this.reCalXYZRot(v.y, y.y),
+        v.z = this.reCalXYZRot(v.z, y.z),
+        new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z))
+          , c = function(v, y, b) {
+            return new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z)
+        }
+          , h = new Animation("myAnimation1","position",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
+        let f = []
+          , d = t
+          , _ = r;
+        for (let v = 0; v < a; ++v)
             f.push({
-                frame: f.length,
-                value: c(d, _, 1)
-            }),
-            h.setKeys(f);
-            const g = new Animation("myAnimation2","rotation",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
-            f = [],
-            d = n,
-            _ = o;
-            for (let v = 0; v < a; ++v)
-                f.push({
-                    frame: v,
-                    value: u(d, _, v / a)
-                });
+                frame: v,
+                value: c(d, _, v / a)
+            });
+        f.push({
+            frame: f.length,
+            value: c(d, _, 1)
+        }),
+        h.setKeys(f);
+        const g = new Animation("myAnimation2","rotation",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
+        f = [],
+        d = n,
+        _ = o;
+        for (let v = 0; v < a; ++v)
             f.push({
-                frame: f.length,
-                value: u(d, _, 1)
-            }),
-            g.setKeys(f),
-            e.animations.push(g),
-            e.animations.push(h);
-            const m = this.scene.beginAnimation(e, 0, a, !1);
-            m.onAnimationEnd = ()=>{
-                l(),
-                m.stop(),
-                m.animationStarted = !1
-            }
+                frame: v,
+                value: u(d, _, v / a)
+            });
+        f.push({
+            frame: f.length,
+            value: u(d, _, 1)
+        }),
+        g.setKeys(f),
+        e.animations.push(g),
+        e.animations.push(h);
+        const m = this.scene.beginAnimation(e, 0, a, !1);
+        m.onAnimationEnd = ()=>{
+            l(),
+            m.stop(),
+            m.animationStarted = !1
         }
-        );
-        this.scene = t,
-        this.canvas = e,
-        this.yuvInfo = r.yuvInfo,
-        r.forceKeepVertical != null && (this.forceKeepVertical = r.forceKeepVertical),
-        this.initCamera(r.cameraParam)
     }
+
     get MainCamera() {
         return this.mainCamera
     }

+ 0 - 8
src/XMaterialComponent.js

@@ -4,23 +4,15 @@ import Logger from "./Logger.js";
 const logger = new Logger("XMaterial");
 export default class XMaterialComponent {
   constructor(sceneManager, t) {
-    this.scene
-    this.engine
     this.yuvInfo
-    this.shaderMode
     this._panoInfo
     this._dynamic_size
-    this._dynamic_babylonpose
-    this._dynamic_textures
-    this._dynamic_shaders
-    this._scenemanager
     this._videoTexture
     this._videoElement
     this._lowModelShader
     this._defaultShader
     this._inputYUV420 = !0
     this._inputPanoYUV420 = !0
-    this._videoRawYUVTexArray
     this._isUpdateYUV = !0
 
     this._scenemanager = sceneManager

+ 1 - 19
src/XSceneManager.js

@@ -32,36 +32,18 @@ const getAlphaWidthMap = (i,e)=>{
 
 export default class XSceneManager {
     constructor(canvas, t) {
-        this.scene
-        this.engine
-        this.canvas
-        this.gl
-        this._yuvInfo
         this.cameraParam
         this.shaderMode
         this.panoInfo
-        this._initEngineScaleNumber
         this._forceKeepVertical = !1
         this._currentShader
-        this._currentPanoId
         this._renderStatusCheckCount = 0
         this._renderStatusNotChecktCount = 0
         this._nonlinearCanvasResize = !1
         this._bChangeEngineSize = !0
-        this._cameraManager
-        this._lowpolyManager
-        this._materialManager
-        this._statisticManager
-        this._breathPointManager
         this._skytv
         this._mv = []
-        this._decalManager
-        this._lightManager
-        this._avatarManager
-        this.urlTransformer
-        this._billboardManager
         this._backgroundImg
-        this.engineRunTimeStats
 
         this.engine = new BABYLON.Engine(canvas, !0, {
             preserveDrawingBuffer: !0,
@@ -81,7 +63,7 @@ export default class XSceneManager {
 
         this.urlTransformer = t.urlTransformer || (s=>Promise.resolve(s)),
         t.logger && defaultLog.setLogger(t.logger),
-        
+
         this.gl = canvas.getContext("webgl2", { preserveDrawingBuffer: !0 }) 
         || canvas.getContext("webgl", { preserveDrawingBuffer: !0 }) 
         || canvas.getContext("experimental-webgl", { preserveDrawingBuffer: !0 }),

+ 1 - 7
src/XverseAvatar.js

@@ -12,11 +12,6 @@ export default class XverseAvatar extends EventEmitter {
     constructor({userId, isHost, room, avatarId, isSelf, group=AvatarGroup.Npc}) {
         super();
         this.xAvatar
-        this._isHost = !1
-        this._room
-        this._withModel = !1
-        this._userId
-        this.group = AvatarGroup.User
         this.state = "idle"
         this.isLoading = !0
         this._isMoving = !1
@@ -28,7 +23,6 @@ export default class XverseAvatar extends EventEmitter {
         this.priority = EAvatarRelationRank.Stranger
         this._avatarModel
         this._motionType = MotionType.Walk
-        this.isSelf = !1
         this._lastAnimTraceId = ""
         this.statusSyncQueue = new Queue
         this.extraInfo = {}
@@ -42,7 +36,7 @@ export default class XverseAvatar extends EventEmitter {
         this._isHost = isHost || !1,
         this._avatarId = avatarId,
         this.group = group,
-        
+
         this._room.modelManager.getAvatarModelList().then(avatarModelList=>{
             const l = avatarModelList.find(u=>u.id === avatarId);
             l && (this._avatarModel = l)

+ 6 - 8
src/XverseAvatarManager.js

@@ -14,21 +14,19 @@ import QueueType from "./enum/QueueType.js"
 
 const logger = new Logger('xverse-avatar-manager')
 export default class XverseAvatarManager extends EventEmitter {
-    constructor(e) {
+    constructor(room) {
         super();
         this.xAvatarManager = null
         this.avatars = new Map
         this.syncAvatarsLength = 0
-        this._room = e;
+        this._room = room;
         this._usersStatistics();
         this.broadcast = this.setupBroadcast();
-        e.on("skinChanged", ()=>{
+        room.on("skinChanged", ()=>{
             this.avatars.forEach(t=>{
-                t.disconnected && this.removeAvatar(t.userId, !0)
-            }
-            )
-        }
-        )
+                avatar.disconnected && this.removeAvatar(avatar.userId, !0)
+            })
+        })
     }
     setupBroadcast() {
         return new Broadcast(this._room,async e=>{

+ 2 - 2
src/main.js

@@ -34,9 +34,9 @@ const l = async()=>{
             avatarId: 'KGe_Boy',
             roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
             userId: nickname,
-            // wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
+            wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
             // wsServerUrl: "ws://localhost:6688/ws",
-            wsServerUrl: "wss://meta-socket.4dage.com/ws",
+            // wsServerUrl: "wss://meta-socket.4dage.com/ws",
             appId: "10016",
             token: " ",
             nickname: nickname,